PmAuditDeptRefServiceImpl.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package com.ozs.pm.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.ozs.common.core.domain.entity.SysDept;
  5. import com.ozs.common.core.domain.entity.SysProcurementStandard;
  6. import com.ozs.common.exception.ServiceException;
  7. import com.ozs.common.exception.base.BaseException;
  8. import com.ozs.plan.mapper.PlanYearsMapper;
  9. import com.ozs.pm.mapper.PmAuditDeptRefMapper;
  10. import com.ozs.pm.doman.PmAuditDeptRef;
  11. import com.ozs.pm.service.PmAuditDeptRefService;
  12. import com.ozs.system.mapper.SysDeptMapper;
  13. import com.ozs.system.mapper.SysProcurementStandardMapper;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import org.springframework.util.ObjectUtils;
  17. import javax.annotation.Resource;
  18. import java.math.BigDecimal;
  19. import java.util.Arrays;
  20. import java.util.Date;
  21. import java.util.List;
  22. /**
  23. * 审核关联表(PmAuditDeptRef)表服务实现类
  24. *
  25. * @author makejava
  26. * @since 2023-02-22 22:10:08
  27. */
  28. @Service
  29. public class PmAuditDeptRefServiceImpl extends ServiceImpl<PmAuditDeptRefMapper, PmAuditDeptRef> implements PmAuditDeptRefService {
  30. @Resource
  31. PlanYearsMapper planYearsMapper;
  32. @Resource
  33. private SysDeptMapper deptMapper;
  34. @Resource
  35. private SysProcurementStandardMapper sysProcurementStandardMapper;
  36. @Resource
  37. private PmAuditDeptRefService pmAuditDeptRefService;
  38. @Override
  39. @Transactional
  40. public Boolean insertPmAuditDeptRefs(Long refId, String refType, Long deptId, BigDecimal evaluation, Long userId, String projectType) {
  41. Date now = new Date();
  42. SysDept sysDept = deptMapper.selectDeptById(deptId);
  43. String[] ancestors = sysDept.getAncestors().split(",");
  44. //当前用户的部门,是否允许提交(不在规定等级范围不可提交)
  45. //查询当前用户的部门是否有上级,是否需要上级及祖级进行审核
  46. Long cdeptId = null;
  47. Long bdeptId = null;
  48. String deptLevel = null;
  49. if (ancestors.length < 5) {
  50. if (ancestors.length == 2) { //C级
  51. deptLevel = "C";
  52. } else if (ancestors.length == 3) { //B级
  53. deptLevel = "B";
  54. cdeptId = Long.valueOf(ancestors[2]);
  55. } else if (ancestors.length == 4) { //A级
  56. deptLevel = "A";
  57. cdeptId = Long.valueOf(ancestors[2]);
  58. bdeptId = Long.valueOf(ancestors[3]);
  59. }
  60. } else if (ancestors.length >= 5) {
  61. deptLevel = "A";
  62. bdeptId = Long.valueOf(ancestors[ancestors.length - 1]);
  63. cdeptId = Long.valueOf(ancestors[ancestors.length - 2]);
  64. }
  65. if (!Arrays.asList("A", "B", "C").contains(deptLevel)) {
  66. throw new BaseException("管理员无权限提交需求。");
  67. }
  68. //判断每个级别是否允许审核,并插入审核关联表
  69. PmAuditDeptRef refA = new PmAuditDeptRef(null, refId, refType, deptId,
  70. "A", 0, userId + "", now,
  71. userId + "", now);
  72. PmAuditDeptRef refB = new PmAuditDeptRef(null, refId, refType, bdeptId,
  73. "B", 0, userId + "",
  74. now, userId + "", now);
  75. PmAuditDeptRef refC = null;
  76. //审核关联表--PmAuditDeptRef
  77. switch (deptLevel) {
  78. case "A":
  79. // A的判断 最少插入1条。最多插入3条
  80. //获取各个项目类型设定的概算金额阈值
  81. LambdaQueryWrapper<SysProcurementStandard> queryWrapperA = new LambdaQueryWrapper<>();
  82. queryWrapperA.eq(SysProcurementStandard::getDeptId, deptId);
  83. queryWrapperA.eq(SysProcurementStandard::getCategory, projectType.equals("2") ? "1" : projectType.equals("1") ? "2" : projectType);
  84. List<SysProcurementStandard> sysProcurementStandardsListA = sysProcurementStandardMapper.selectList(queryWrapperA);
  85. if (ObjectUtils.isEmpty(sysProcurementStandardsListA)) {
  86. throw new ServiceException("部门id为" + deptId + "的部门采购标准未进行初始化!");
  87. }
  88. //A不限额就自己审核
  89. SysProcurementStandard sA = sysProcurementStandardsListA.get(0);
  90. if (!sA.getState().equals(Integer.valueOf(0))) {
  91. //refA采用初始化数据
  92. //A限额了判断是否超额,超额未超额都自己先审。超额了追加上级
  93. BigDecimal maximum = sA.getMaximum();
  94. if (maximum.compareTo(evaluation) != 1) {
  95. //refA采用初始化数据
  96. //A限额了,找B
  97. // (3月23逻辑更改):本单位超限额的记录由本单位先进行审核,随后交由上级审核。(超额未超额都自己先审)
  98. LambdaQueryWrapper<SysProcurementStandard> queryWrapperB = new LambdaQueryWrapper<>();
  99. queryWrapperB.eq(SysProcurementStandard::getDeptId, bdeptId);
  100. queryWrapperB.eq(SysProcurementStandard::getCategory, projectType.equals("2") ? "1" : projectType.equals("1") ? "2" : projectType);
  101. List<SysProcurementStandard> sysProcurementStandardsListB = sysProcurementStandardMapper.selectList(queryWrapperB);
  102. //B不限额,B审
  103. if (ObjectUtils.isEmpty(sysProcurementStandardsListB)) {
  104. throw new ServiceException("部门id为" + bdeptId + "的部门采购标准未进行初始化!");
  105. }
  106. SysProcurementStandard sB = sysProcurementStandardsListB.get(0);
  107. if (sB.getState().equals(Integer.valueOf(0))) {
  108. //refB采用初始化数据
  109. pmAuditDeptRefService.save(refB);
  110. } else {
  111. //B限额了判断是否超额,不超额就自己审。超额了追加C级
  112. BigDecimal maximumB = sB.getMaximum();
  113. //B超额
  114. if (maximumB.compareTo(evaluation) == -1) {
  115. //C不限额,
  116. refC = new PmAuditDeptRef(null, refId, refType, cdeptId, "C", 0, userId + "", now, userId + "", now);
  117. pmAuditDeptRefService.save(refC);
  118. }
  119. //refB采用初始化数据
  120. pmAuditDeptRefService.save(refB);
  121. }
  122. }
  123. }
  124. if (!ObjectUtils.isEmpty(refA)) {
  125. pmAuditDeptRefService.save(refA);
  126. }
  127. break;
  128. case "B":
  129. // B的判断 最少插入1条。最多插入2条
  130. LambdaQueryWrapper<SysProcurementStandard> queryWrapperB = new LambdaQueryWrapper<>();
  131. queryWrapperB.eq(SysProcurementStandard::getDeptId, deptId);
  132. queryWrapperB.eq(SysProcurementStandard::getCategory, projectType.equals("2") ? "1" : projectType.equals("1") ? "2" : projectType);
  133. List<SysProcurementStandard> sysProcurementStandardsListB = sysProcurementStandardMapper.selectList(queryWrapperB);
  134. //B不限额,B审
  135. if (ObjectUtils.isEmpty(sysProcurementStandardsListB)) {
  136. throw new ServiceException("部门id为" + deptId + "的部门采购标准未进行初始化!");
  137. }
  138. SysProcurementStandard sB = sysProcurementStandardsListB.get(0);
  139. refB = new PmAuditDeptRef(null, refId, refType, deptId, "B", 0, userId + "", now, userId + "", now);
  140. if (sB.getState() == 1) {
  141. //B限额了判断是否超额,不超额就自己审。超额了追加C级
  142. BigDecimal maximumB = sB.getMaximum();
  143. //B不超额B审
  144. if (maximumB.compareTo(evaluation) == 1) {
  145. refB = new PmAuditDeptRef(null, refId, refType, deptId, "B", 0, userId + "", now, userId + "", now);
  146. } else {
  147. //C不限额C审,(B先自己审核)
  148. refB = new PmAuditDeptRef(null, refId, refType, deptId, "B", 0, userId + "", now, userId + "", now);
  149. refC = new PmAuditDeptRef(null, refId, refType, cdeptId, "C", 0, userId + "", now, userId + "", now);
  150. pmAuditDeptRefService.save(refC);
  151. }
  152. }
  153. pmAuditDeptRefService.save(refB);
  154. break;
  155. default:
  156. //C不限额C审,
  157. // 插入1条
  158. refC = new PmAuditDeptRef(null, refId, refType, deptId, "C", 0, userId + "", now, userId + "", now);
  159. pmAuditDeptRefService.save(refC);
  160. }
  161. return true;
  162. }
  163. }