ProofGroupService.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package cn.cslg.pas.service.business;
  2. import cn.cslg.pas.common.dto.DomainFieldDTO;
  3. import cn.cslg.pas.common.dto.invalidDTO.AddProofGroupDTO;
  4. import cn.cslg.pas.common.dto.invalidDTO.GetProofGroupDTO;
  5. import cn.cslg.pas.common.dto.invalidDTO.UpdateMessageDTO;
  6. import cn.cslg.pas.common.dto.stabilityReport.AddCompareRecordGroupDTO;
  7. import cn.cslg.pas.common.model.cronModel.PersonnelVO;
  8. import cn.cslg.pas.common.utils.GenerateObjectUtil;
  9. import cn.cslg.pas.common.vo.invalidVO.ProofGroupVO;
  10. import cn.cslg.pas.domain.business.AssoGroupFeature;
  11. import cn.cslg.pas.domain.business.AssoGroupReason;
  12. import cn.cslg.pas.domain.business.InvalidStatutes;
  13. import cn.cslg.pas.domain.business.ProofGroup;
  14. import cn.cslg.pas.exception.XiaoShiException;
  15. import cn.cslg.pas.mapper.ProofGroupMapper;
  16. import cn.cslg.pas.service.business.stabilityReport.AssoGroupReasonService;
  17. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  18. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  19. import lombok.extern.slf4j.Slf4j;
  20. import org.springframework.beans.BeanUtils;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23. import org.springframework.web.bind.annotation.RequestBody;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26. import java.util.stream.Collectors;
  27. /**
  28. * 无效证据Service
  29. *
  30. * @Author xiexiang
  31. * @Date 2023/12/25
  32. */
  33. @Service
  34. @Slf4j
  35. public class ProofGroupService extends ServiceImpl<ProofGroupMapper, ProofGroup> {
  36. @Autowired
  37. private InvalidStatutesService invalidStatutesService;
  38. @Autowired
  39. private AssoGroupReasonService assoGroupReasonService;
  40. /**
  41. * 添加or修改证据组合
  42. *
  43. * @param addProofGroupDTO
  44. * @return
  45. */
  46. public List<Integer> addProofGroup(AddProofGroupDTO addProofGroupDTO) {
  47. List<Integer> proofGroupIds = new ArrayList<>();
  48. if (addProofGroupDTO != null) {
  49. Integer id = addProofGroupDTO.getId();
  50. List<String> descriptions = addProofGroupDTO.getDescriptions();
  51. Integer projectId = addProofGroupDTO.getProjectId();
  52. Integer claimId = addProofGroupDTO.getClaimId();
  53. Integer statutesId = addProofGroupDTO.getStatutesId();
  54. if (projectId == null) {
  55. throw new XiaoShiException("projectId不能为空");
  56. }
  57. if (statutesId == null) {
  58. throw new XiaoShiException("invalidStatutesId不能为空");
  59. }
  60. LambdaQueryWrapper<InvalidStatutes> queryWrapper = new LambdaQueryWrapper<>();
  61. queryWrapper.eq(InvalidStatutes::getStatutesId, statutesId)
  62. .eq(InvalidStatutes::getProjectId, projectId);
  63. if (claimId != null) {
  64. queryWrapper.eq(InvalidStatutes::getClaimId, claimId);
  65. }
  66. InvalidStatutes invalidStatutes = invalidStatutesService.getOne(queryWrapper, false);
  67. if (invalidStatutes == null) {
  68. throw new XiaoShiException("查询无效法条错误");
  69. }
  70. Integer invalidStatutesId = invalidStatutes.getId();
  71. List<ProofGroup> proofGroups = new ArrayList<>();
  72. if (id != null) {
  73. //单个更新
  74. ProofGroup proofGroup = this.getById(id);
  75. proofGroup.setInvalidStatutesId(invalidStatutesId);
  76. if (!descriptions.isEmpty() && descriptions.size() == 1) {
  77. proofGroup.setDescription(descriptions.get(0));
  78. } else {
  79. proofGroup.setDescription(null);
  80. }
  81. proofGroup.updateById();
  82. proofGroupIds.add(proofGroup.getId());
  83. } else {
  84. //批量新增
  85. //如果证据组合说明不为空
  86. if (!descriptions.isEmpty()) {
  87. descriptions.forEach(item -> {
  88. ProofGroup proofGroup = new ProofGroup();
  89. proofGroup.setInvalidStatutesId(invalidStatutesId);
  90. proofGroup.setDescription(item);
  91. proofGroups.add(proofGroup);
  92. });
  93. } else {
  94. ProofGroup proofGroup = new ProofGroup();
  95. proofGroup.setInvalidStatutesId(invalidStatutesId);
  96. proofGroups.add(proofGroup);
  97. }
  98. this.saveBatch(proofGroups);
  99. }
  100. proofGroupIds = proofGroups.stream().map(ProofGroup::getId).collect(Collectors.toList());
  101. } else {
  102. throw new XiaoShiException("参数不能为空");
  103. }
  104. return proofGroupIds;
  105. }
  106. /**
  107. * 查询证据组合
  108. *
  109. * @param invalidStatutesId
  110. * @return
  111. */
  112. public List<ProofGroupVO> queryProofGroup(Integer invalidStatutesId) {
  113. List<ProofGroupVO> proofGroupVOS = new ArrayList<>();
  114. if (invalidStatutesId == null) {
  115. throw new XiaoShiException("invalidStatutesId不能为空");
  116. }
  117. InvalidStatutes invalidStatutes = invalidStatutesService.getById(invalidStatutesId);
  118. if (invalidStatutes == null) {
  119. throw new XiaoShiException("查询invalidStatutes错误");
  120. }
  121. LambdaQueryWrapper<ProofGroup> queryWrapper = new LambdaQueryWrapper<>();
  122. queryWrapper.eq(ProofGroup::getInvalidStatutesId, invalidStatutesId);
  123. List<ProofGroup> proofGroups = this.list(queryWrapper);
  124. if (!proofGroups.isEmpty()) {
  125. proofGroups.forEach(item -> {
  126. ProofGroupVO proofGroupVO = new ProofGroupVO();
  127. proofGroupVO.setId(item.getId());
  128. proofGroupVO.setInvalidStatutesId(invalidStatutesId);
  129. proofGroupVO.setStatutesId(invalidStatutes.getStatutesId());
  130. proofGroupVO.setClaimId(invalidStatutes.getClaimId());
  131. proofGroupVO.setProjectId(invalidStatutes.getProjectId());
  132. proofGroupVO.setDescription(item.getDescription());
  133. proofGroupVOS.add(proofGroupVO);
  134. });
  135. }
  136. return proofGroupVOS;
  137. }
  138. /**
  139. * 更新信息
  140. *
  141. * @param updateMessageDTO
  142. * @return
  143. */
  144. public Boolean updateMessage(@RequestBody UpdateMessageDTO updateMessageDTO) {
  145. List<Integer> ids = updateMessageDTO.getIds();
  146. List<DomainFieldDTO> domainFieldDTOS = updateMessageDTO.getFieldList();
  147. for(Integer id:ids) {
  148. ProofGroup proofGroup = this.getById(id);
  149. if (proofGroup == null) {
  150. throw new XiaoShiException("证据不存在");
  151. }
  152. if (domainFieldDTOS == null || domainFieldDTOS.size() == 0) {
  153. throw new XiaoShiException("请输入值");
  154. }
  155. domainFieldDTOS.forEach(item -> {
  156. try {
  157. if (item.getValue() != null) {
  158. GenerateObjectUtil.setObjectProperty(proofGroup, item.getField(), item.getValue());
  159. }
  160. } catch (Exception e) {
  161. throw new XiaoShiException("装载失败");
  162. }
  163. });
  164. proofGroup.updateById();
  165. }
  166. return true;
  167. }
  168. /**
  169. * 查询详情
  170. *
  171. * @param getProofGroupDTO
  172. * @return
  173. */
  174. public ProofGroupVO queryProofGroupDetail(GetProofGroupDTO getProofGroupDTO) {
  175. Integer proofId = getProofGroupDTO.getProofGroupId();
  176. if (proofId == null) {
  177. throw new XiaoShiException("请输入id");
  178. }
  179. ProofGroup proofGroup = this.getById(proofId);
  180. if (proofGroup == null) {
  181. throw new XiaoShiException("证据组合不存在");
  182. }
  183. ProofGroupVO proofGroupVO = new ProofGroupVO();
  184. BeanUtils.copyProperties(proofGroup, proofGroupVO);
  185. return proofGroupVO;
  186. }
  187. /**
  188. * 查询详情
  189. *
  190. * @param ids
  191. * @return
  192. */
  193. public Boolean removeProofGroup(List<Integer> ids) {
  194. if(ids==null||ids.size()==0){
  195. throw new XiaoShiException("请至少选择一个组合");
  196. }
  197. this.removeBatchByIds(ids);
  198. return true;
  199. }
  200. public Boolean addCompareRecordGroup(AddCompareRecordGroupDTO addCompareRecordGroupDTO){
  201. List<Integer> groupReasonIds =addCompareRecordGroupDTO.getGroupReasonIds();
  202. //添加对比方案
  203. PersonnelVO personnelVO =new PersonnelVO();
  204. personnelVO.setId("1");
  205. ProofGroup proofGroup =new ProofGroup();
  206. proofGroup.setCommon1(addCompareRecordGroupDTO.getCommon());
  207. proofGroup.setProjectId(addCompareRecordGroupDTO.getProjectId());
  208. proofGroup.setClaimSort(addCompareRecordGroupDTO.getClaimSort());
  209. proofGroup.insert();
  210. //遍历特征和无效理由关联
  211. groupReasonIds.forEach(item->{
  212. AssoGroupReason assoGroupReason= assoGroupReasonService.getById(item);
  213. assoGroupReason.setGroupId(proofGroup.getId());
  214. assoGroupReason.insert();
  215. });
  216. return true;
  217. }
  218. }