StaffService.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package com.dk.mdm.service.mst;
  2. import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
  3. import com.dk.common.infrastructure.annotaiton.Pagination;
  4. import com.dk.common.infrastructure.constant.Constant;
  5. import com.dk.common.model.pojo.PageList;
  6. import com.dk.common.response.ResponseCodeEnum;
  7. import com.dk.common.response.ResponseResultUtil;
  8. import com.dk.common.response.ResponseResultVO;
  9. import com.dk.mdm.infrastructure.convert.mst.StaffConvert;
  10. import com.dk.mdm.model.pojo.mst.*;
  11. import com.dk.mdm.mapper.mst.StaffMapper;
  12. import com.dk.common.service.BaseService;
  13. import com.dk.common.mapper.BaseMapper;
  14. import com.dk.mdm.model.query.mst.StaffQuery;
  15. import com.dk.mdm.model.response.mst.StaffResponse;
  16. import com.dk.mdm.model.vo.mst.StaffVO;
  17. import com.dk.mdm.service.common.CommonService;
  18. import org.springframework.stereotype.Service;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.transaction.annotation.Transactional;
  21. import org.springframework.util.CollectionUtils;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Random;
  25. import java.util.UUID;
  26. /**
  27. * @author : 姜永辉
  28. * @desc : 员工API接口
  29. * @date : 2023/1/4 9:25
  30. */
  31. @Service
  32. public class StaffService extends BaseService<Staff> {
  33. @Override
  34. public BaseMapper<Staff> getRepository() {
  35. return staffMapper;
  36. }
  37. /**
  38. * @desc : 重写主键
  39. * @author : 姜永辉
  40. * @date : 2023/1/9 10:39
  41. */
  42. @Override
  43. public String getPrimaryKey() {
  44. return "staff_id";
  45. }
  46. @Autowired
  47. private StaffMapper staffMapper;
  48. @Autowired
  49. private StaffConvert staffConvert;
  50. @Autowired
  51. private StaffRightService staffRightService;
  52. @Autowired
  53. private StaffPurviewService staffPurviewService;
  54. @Autowired
  55. private CommonService commonService;
  56. /**
  57. * @desc : 条件查询
  58. * @author : 姜永辉
  59. * @date : 2023/1/9 10:40
  60. */
  61. @Pagination
  62. public ResponseResultVO<PageList<StaffResponse>> selectByCond(StaffQuery staffQuery) {
  63. return super.mergeListWithCount(staffQuery, staffMapper.selectByCond(staffQuery),
  64. staffMapper.countByCond(staffQuery));
  65. }
  66. /**
  67. * @desc : 保存方法
  68. * @author : 姜永辉
  69. * @date : 2023/1/9 10:49
  70. */
  71. @Transactional(
  72. rollbackFor = {Exception.class}
  73. )
  74. public ResponseResultVO<?> insert(StaffVO staffVO) {
  75. // 转化实体
  76. Staff staff = staffConvert.convertToPo(staffVO);
  77. // 获取编码和主键UuId
  78. Map<String, Object> codeMap = commonService.getUniqueNoteCode(Constant.docNameConstant.STAFF.getName(), true);
  79. staff.setStaffId(codeMap.get("outId").toString());
  80. staff.setStaffCode(codeMap.get("outNote").toString());
  81. return super.insert(staff);
  82. }
  83. /**
  84. * @desc : 编辑方法
  85. * @author : 姜永辉
  86. * @date : 2023/1/9 10:49
  87. */
  88. @Transactional(
  89. rollbackFor = {Exception.class}
  90. )
  91. public ResponseResultVO<Boolean> update(StaffVO staffVO) {
  92. // 转化实体
  93. Staff staff = staffConvert.convertToPo(staffVO);
  94. return super.updateByUuid(staff);
  95. }
  96. /**
  97. * @desc : 保存权限方法
  98. * @author : 姜永辉
  99. * @date : 2023/1/9 10:49
  100. */
  101. @Transactional(
  102. rollbackFor = {Exception.class}
  103. )
  104. public ResponseResultVO<?> saveStaffRight(StaffVO staffVO) {
  105. // 转化实体
  106. Staff staff = staffConvert.convertToPo(staffVO);
  107. staffRightService.delete(staffVO.getStaffId());
  108. for (StaffRight staffRight : staffVO.getStaffRightList()) {
  109. staffRight.setStaffId(staff.getStaffId());
  110. staffRight.setRightType(1);
  111. staffRight.setCpId(staff.getCpId());
  112. }
  113. staffRightService.saveStaffRight(staffVO.getStaffRightList());
  114. return ResponseResultUtil.success();
  115. }
  116. /**
  117. * @desc : 保存权限方法
  118. * @author : 姜永辉
  119. * @date : 2023/1/9 10:49
  120. */
  121. @Transactional(
  122. rollbackFor = {Exception.class}
  123. )
  124. public ResponseResultVO<?> saveStaffPurview(StaffVO staffVO) {
  125. // 转化实体
  126. Staff staff = staffConvert.convertToPo(staffVO);
  127. for (StaffPurview staffRight : staffVO.getStaffPurviewList()) {
  128. staffRight.setStaffId(staff.getStaffId());
  129. staffRight.setCpId(staff.getCpId());
  130. }
  131. staffPurviewService.saveStaffPurview(staffVO.getStaffPurviewList());
  132. return ResponseResultUtil.success();
  133. }
  134. /**
  135. * @desc : 员工离职
  136. * @author : 姜永辉
  137. * @date : 2023/2/13 13:45
  138. */
  139. @Transactional(
  140. rollbackFor = {Exception.class}
  141. )
  142. public ResponseResultVO<Boolean> dimission(StaffVO staffVO) {
  143. return ResponseResultUtil.success();
  144. }
  145. /**
  146. * @desc : 导入员工
  147. * @author : 姜永辉
  148. * @date : 2023/3/1 14:40
  149. */
  150. @Transactional(
  151. rollbackFor = {Exception.class}
  152. )
  153. public ResponseResultVO<Boolean> importStaffList(List<StaffVO> list) {
  154. if (CollectionUtils.isEmpty(list) || list.size() == 0) {
  155. return ResponseResultUtil.error(ResponseCodeEnum.INSERT_FAIL);
  156. }
  157. return ResponseResultUtil.success();
  158. }
  159. }