package com.dk.mdm.service.mst; import com.dk.common.infrastructure.annotaiton.Pagination; import com.dk.common.infrastructure.constant.Constant; import com.dk.common.model.pojo.PageList; import com.dk.common.model.pojo.mst.StaffPurview; import com.dk.common.model.pojo.mst.StaffRight; import com.dk.common.response.ResponseCodeEnum; import com.dk.common.response.ResponseResultUtil; import com.dk.common.response.ResponseResultVO; import com.dk.mdm.feign.CompanyFeign; import com.dk.mdm.infrastructure.convert.mst.StaffConvert; import com.dk.mdm.infrastructure.util.AuthUtils; import com.dk.mdm.model.pojo.mst.*; import com.dk.mdm.mapper.mst.StaffMapper; import com.dk.common.service.BaseService; import com.dk.common.mapper.BaseMapper; import com.dk.mdm.model.query.mst.StaffQuery; import com.dk.common.model.response.mst.StaffResponse; import com.dk.common.model.vo.mst.StaffVO; import com.dk.mdm.service.common.CommonService; import org.springframework.stereotype.Service; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import javax.annotation.Resource; import java.util.HashMap; import java.util.List; import java.util.Map; /** * @author : 姜永辉 * @desc : 员工API接口 * @date : 2023/1/4 9:25 */ @Service public class StaffService extends BaseService { @Resource private CompanyFeign companyFeign; @Override public BaseMapper getRepository() { return staffMapper; } /** * @desc : 重写主键 * @author : 姜永辉 * @date : 2023/1/9 10:39 */ @Override public String getPrimaryKey() { return "staff_id"; } @Autowired private StaffMapper staffMapper; @Autowired private StaffConvert staffConvert; @Autowired private StaffRightService staffRightService; @Autowired private StaffPurviewService staffPurviewService; @Autowired private CommonService commonService; @Autowired private AuthUtils authUtils; /** * @desc : 条件查询 * @author : 姜永辉 * @date : 2023/1/9 10:40 */ @Pagination public ResponseResultVO> selectByCond(StaffQuery staffQuery) { return super.mergeListWithCount(staffQuery, staffMapper.selectByCond(staffQuery), staffMapper.countByCond(staffQuery)); } /** * @desc : 保存方法 * @author : 姜永辉 * @date : 2023/1/9 10:49 */ @Transactional( rollbackFor = {Exception.class} ) public ResponseResultVO insert(StaffVO staffVO) { // 转化实体 Staff staff = staffConvert.convertToPo(staffVO); // 校验同一个公司的电话不能重复 StaffQuery staffQuery = new StaffQuery(); staffQuery.setCpId(staff.getCpId()); staffQuery.setStaffPhone(staff.getStaffPhone()); List staffResponses = staffMapper.selectByCond(staffQuery); if (staffResponses != null && staffResponses.size() > 0) { return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST); } // 获取编码和主键UuId Map codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), true); staff.setStaffId(codeMap.get("outId").toString()); staff.setStaffCode(codeMap.get("outNote").toString()); super.insert(staff); return ResponseResultUtil.success(staff); } /** * @desc : 保存方法 * @author : 姜永辉 * @date : 2023/1/9 10:49 */ @Transactional( rollbackFor = {Exception.class} ) public ResponseResultVO insertFeignStaff(StaffVO staffVO) { // 转化实体 Staff staff = staffConvert.convertToPo(staffVO); // 校验同一个公司的电话不能重复 StaffQuery staffQuery = new StaffQuery(); staffQuery.setCpId(staff.getCpId()); staffQuery.setStaffPhone(staff.getStaffPhone()); List staffResponses = staffMapper.selectByCond(staffQuery); if (staffResponses != null && staffResponses.size() > 0) { return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST); } // 获取编码和主键UuId Map codeMap = commonService.getUniqueNoteCode( Constant.docNameConstant.STAFF.getName(), staff.getCpId(), true); staff.setStaffId(codeMap.get("outId").toString()); staff.setStaffCode(codeMap.get("outNote").toString()); super.insert(staff); return ResponseResultUtil.success(staff); } /** * @desc : 保存方法-邀请员工的确定 * @author : 姜永辉 * @date : 2023/1/9 10:49 */ @Transactional(rollbackFor = {Exception.class}) public ResponseResultVO insertRequestStaff(StaffVO staffVO) { // 转化实体 Staff staff = staffConvert.convertToPo(staffVO); // 校验同一个公司的电话不能重复 StaffQuery staffQuery = new StaffQuery(); staffQuery.setCpId(staff.getCpId()); staffQuery.setStaffPhone(staff.getStaffPhone()); List staffResponses = staffMapper.selectByCond(staffQuery); if (staffResponses != null && staffResponses.size() > 0) { return ResponseResultUtil.error(ResponseCodeEnum.ERROR_STAFF_PHONE_EXIST); } // 获取编码和主键UuId Map codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), true); staff.setStaffId(codeMap.get("outId").toString()); staff.setStaffCode(codeMap.get("outNote").toString()); // 更新 被邀人员的cpid if (staff.getWxUserId() != null) { // 更新 被邀请人员的微信用户的cpid 加入公司 Map collectQuery = new HashMap<>(); collectQuery.put("cpId", staff.getCpId()); collectQuery.put("userId", staff.getWxUserId()); companyFeign.updateWxUserCompany(collectQuery); } // 插入员工 super.insert(staff); return ResponseResultUtil.success(staff); } /** * @desc : 编辑方法 * @author : 姜永辉 * @date : 2023/1/9 10:49 */ @Transactional( rollbackFor = {Exception.class} ) public ResponseResultVO update(StaffVO staffVO) { // 转化实体 Staff staff = staffConvert.convertToPo(staffVO); return super.updateByUuid(staff); } /** * @desc : 保存权限方法 * @author : 姜永辉 * @date : 2023/1/9 10:49 */ @Transactional( rollbackFor = {Exception.class} ) public ResponseResultVO saveStaffRight(StaffVO staffVO) { // 转化实体 Staff staff = staffConvert.convertToPo(staffVO); staffRightService.delete(staffVO.getStaffId()); for (StaffRight staffRight : staffVO.getStaffRightList()) { staffRight.setStaffId(staff.getStaffId()); staffRight.setRightType(1); staffRight.setCpId(staff.getCpId()); } staffRightService.saveStaffRight(staffVO.getStaffRightList()); return ResponseResultUtil.success(); } /** * @desc : 保存权限方法 * @author : 姜永辉 * @date : 2023/1/9 10:49 */ @Transactional( rollbackFor = {Exception.class} ) public ResponseResultVO saveStaffPurview(StaffVO staffVO) { // 转化实体 Staff staff = staffConvert.convertToPo(staffVO); for (StaffPurview staffRight : staffVO.getStaffPurviewList()) { staffRight.setStaffId(staff.getStaffId()); staffRight.setCpId(staff.getCpId()); } staffPurviewService.saveStaffPurview(staffVO.getStaffPurviewList()); return ResponseResultUtil.success(); } /** * @desc : 员工离职 * @author : 姜永辉 * @date : 2023/2/13 13:45 */ @Transactional( rollbackFor = {Exception.class} ) public ResponseResultVO dimission(StaffVO staffVO) { return ResponseResultUtil.success(); } /** * @desc : 导入员工 * @author : 姜永辉 * @date : 2023/3/1 14:40 */ @Transactional( rollbackFor = {Exception.class} ) public ResponseResultVO importStaffList(List list) { if (CollectionUtils.isEmpty(list) || list.size() == 0) { return ResponseResultUtil.error(ResponseCodeEnum.INSERT_FAIL); } return ResponseResultUtil.success(); } }