| | |
| | | package com.sinata.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.sinata.common.entity.PageDTO; |
| | | import com.sinata.common.exception.ServiceException; |
| | | import com.sinata.common.utils.BeanUtils; |
| | | import com.sinata.common.utils.StringUtils; |
| | | import com.sinata.system.domain.MwStaff; |
| | | import com.sinata.system.domain.SysDepartment; |
| | | import com.sinata.system.domain.dto.MwStaffDTO; |
| | | import com.sinata.system.domain.query.MwStaffQuery; |
| | | import com.sinata.system.domain.vo.MwStaffVO; |
| | | import com.sinata.system.mapper.MwStaffMapper; |
| | | import com.sinata.system.service.MwStaffService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.sinata.system.service.SysDepartmentService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | * @since 2024-12-02 |
| | | */ |
| | | @Service |
| | | @RequiredArgsConstructor |
| | | public class MwStaffServiceImpl extends ServiceImpl<MwStaffMapper, MwStaff> implements MwStaffService { |
| | | private final SysDepartmentService sysDepartmentService; |
| | | |
| | | /** |
| | | * 分页列表 |
| | | * |
| | | * @param query |
| | | * @return |
| | | */ |
| | | @Override |
| | | public PageDTO<MwStaffVO> pageList(MwStaffQuery query) { |
| | | String treeCode = sysDepartmentService.getTreeCodeByDepartmentId(query.getDepartmentId()); |
| | | if (StringUtils.isBlank(treeCode)) { |
| | | return PageDTO.empty(0L, 0L); |
| | | } |
| | | Page<MwStaffVO> page = baseMapper.pageList(new Page<>(query.getPageCurr(), query.getPageSize()), query, treeCode); |
| | | return PageDTO.of(page); |
| | | } |
| | | |
| | | /** |
| | | * 详情 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @Override |
| | | public MwStaffVO detail(Long id) { |
| | | MwStaff staff = getById(id); |
| | | MwStaffVO mwStaffVO = BeanUtils.copyBean(staff, MwStaffVO.class); |
| | | if (Objects.nonNull(mwStaffVO)) { |
| | | SysDepartment department = sysDepartmentService.getById(mwStaffVO.getDepartmentId()); |
| | | if (Objects.nonNull(department)) { |
| | | mwStaffVO.setDepartmentName(department.getDepartmentName()); |
| | | } |
| | | } |
| | | return mwStaffVO; |
| | | } |
| | | |
| | | /** |
| | | * 新增 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void add(MwStaffDTO dto) { |
| | | MwStaff mwStaff = BeanUtils.copyBean(dto, MwStaff.class); |
| | | Long count = this.lambdaQuery().eq(MwStaff::getPhone, mwStaff.getPhone()).count(); |
| | | if (count > 0) { |
| | | throw new ServiceException("手机号码已存在"); |
| | | } |
| | | save(mwStaff); |
| | | } |
| | | |
| | | /** |
| | | * 编辑 |
| | | * |
| | | * @param dto |
| | | * @return |
| | | */ |
| | | @Override |
| | | public void edit(MwStaffDTO dto) { |
| | | if (Objects.isNull(dto.getId())) { |
| | | throw new ServiceException("职工id不能为空"); |
| | | } |
| | | MwStaff mwStaff = BeanUtils.copyBean(dto, MwStaff.class); |
| | | Long count = this.lambdaQuery().eq(MwStaff::getPhone, mwStaff.getPhone()).ne(MwStaff::getId, dto.getId()).count(); |
| | | if (count > 0) { |
| | | throw new ServiceException("手机号码已存在"); |
| | | } |
| | | updateById(mwStaff); |
| | | } |
| | | |
| | | /** |
| | | * 职工列表 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<MwStaffVO> queryList() { |
| | | return baseMapper.queryList(); |
| | | } |
| | | } |