LitigationService.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package cn.cslg.pas.service.novelty;
  2. import cn.cslg.pas.common.model.novelty.LitigationDTO;
  3. import cn.cslg.pas.common.model.novelty.LitigationReVO;
  4. import cn.cslg.pas.common.model.novelty.LitigationVO;
  5. import cn.cslg.pas.domain.business.CourtOrder;
  6. import cn.cslg.pas.domain.business.ReportAffair;
  7. import cn.cslg.pas.exception.ExceptionEnum;
  8. import cn.cslg.pas.exception.XiaoShiException;
  9. import cn.cslg.pas.service.business.CourtOrderService;
  10. import cn.cslg.pas.service.business.ReportAffairService;
  11. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import cn.cslg.pas.domain.business.novelty.Litigation;
  14. import cn.cslg.pas.mapper.novelty.LitigationMapper;
  15. import lombok.RequiredArgsConstructor;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.stereotype.Service;
  18. import java.util.ArrayList;
  19. import java.util.Arrays;
  20. import java.util.List;
  21. import java.util.stream.Collectors;
  22. /**
  23. * @author admin
  24. * @description 针对表【litigation(行政诉讼表)】的数据库操作Service实现
  25. * @createDate 2025-02-27 10:49:21
  26. */
  27. @Service
  28. @RequiredArgsConstructor
  29. public class LitigationService extends ServiceImpl<LitigationMapper, Litigation> {
  30. private final ReportAffairService reportAffairService;
  31. private final CourtOrderService courtOrderService;
  32. public Litigation addLitigation(LitigationDTO litigationDTO) {
  33. Litigation litigation = new Litigation();
  34. BeanUtils.copyProperties(litigationDTO, litigation);
  35. litigation.insert();
  36. return litigation;
  37. }
  38. public Litigation updateLitigation(LitigationDTO litigationDTO, Litigation litigation) {
  39. Litigation litigation1 = new Litigation();
  40. BeanUtils.copyProperties(litigationDTO, litigation1);
  41. litigation1.setCreateId(litigation.getCreateId());
  42. litigation1.setCreateTime(litigation.getCreateTime());
  43. litigation1.setId(litigation.getId());
  44. litigation1.updateById();
  45. return litigation;
  46. }
  47. public Litigation addOrUpdateLitigation(LitigationDTO litigationDTO) {
  48. Integer projectId = litigationDTO.getProjectId();
  49. Integer type = litigationDTO.getType();
  50. if (projectId == null || type == null) {
  51. throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "未传入必要参数");
  52. }
  53. LambdaQueryWrapper<Litigation> queryWrapper = new LambdaQueryWrapper<>();
  54. queryWrapper.eq(Litigation::getProjectId, projectId)
  55. .eq(Litigation::getType, type);
  56. Litigation litigation = this.getOne(queryWrapper, false);
  57. if (litigation == null) {
  58. return this.addLitigation(litigationDTO);
  59. } else {
  60. return this.updateLitigation(litigationDTO, litigation);
  61. }
  62. }
  63. public LitigationReVO queryLitigation(LitigationDTO litigationDTO) {
  64. LitigationReVO litigationReVO = new LitigationReVO();
  65. Integer projectId = litigationDTO.getProjectId();
  66. LambdaQueryWrapper<Litigation> queryWrapper = new LambdaQueryWrapper<>();
  67. queryWrapper.eq(Litigation::getProjectId, projectId);
  68. List<Litigation> list = this.list(queryWrapper);
  69. litigationReVO = this.loadLitigation(list, projectId);
  70. return litigationReVO;
  71. }
  72. public LitigationReVO loadLitigation(List<Litigation> list, Integer projectId) {
  73. LitigationReVO litigationReVO = new LitigationReVO();
  74. if (list.size() == 0) {
  75. return litigationReVO;
  76. }
  77. List<LitigationVO> litigationVOS = new ArrayList<>();
  78. list.forEach(item -> {
  79. LitigationVO litigationVO = new LitigationVO();
  80. BeanUtils.copyProperties(item, litigationVO);
  81. litigationVOS.add(litigationVO);
  82. });
  83. this.loadResultByAffair(projectId, litigationVOS);
  84. litigationVOS.forEach(item -> {
  85. if (item.getType().equals(1)) {
  86. litigationReVO.setLitigationVO1(item);
  87. } else {
  88. litigationReVO.setLitigationVO2(item);
  89. }
  90. });
  91. return litigationReVO;
  92. }
  93. public List<LitigationVO> loadResultByAffair(Integer projectId, List<LitigationVO> list) {
  94. if (list.size() == 0) {
  95. return list;
  96. }
  97. Integer litigationType1 = 16;
  98. Integer litigationType2 = 26;
  99. LambdaQueryWrapper<ReportAffair> queryWrapper = new LambdaQueryWrapper<>();
  100. queryWrapper.eq(ReportAffair::getProjectId, projectId)
  101. .in(ReportAffair::getAssoCasePhaseId, Arrays.asList(litigationType1, litigationType2));
  102. List<ReportAffair> reportAffairs = reportAffairService.list(queryWrapper);
  103. if (reportAffairs == null || reportAffairs.size() == 0) {
  104. return list;
  105. }
  106. List<Integer> reportAffairIds = reportAffairs.stream().map(ReportAffair::getId).collect(Collectors.toList());
  107. List<CourtOrder> courtOrders = new ArrayList<>();
  108. if (reportAffairIds.size() > 0) {
  109. LambdaQueryWrapper<CourtOrder> queryWrapper1 = new LambdaQueryWrapper<>();
  110. queryWrapper1.in(CourtOrder::getReportAffairId, reportAffairIds);
  111. courtOrders = courtOrderService.list(queryWrapper1);
  112. }
  113. if (courtOrders.size() == 0) {
  114. return list;
  115. }
  116. List<CourtOrder> finalCourtOrders = courtOrders;
  117. list.forEach(item -> {
  118. Integer affairType = litigationType1;
  119. if (item.getType().equals(1)) {
  120. affairType = litigationType1;
  121. } else {
  122. affairType = litigationType2;
  123. }
  124. Integer finalType = affairType;
  125. ReportAffair reportAffair = reportAffairs.stream().filter(tem -> finalType.equals(tem.getAssoCasePhaseId())).findFirst().orElse(null);
  126. if (reportAffair != null) {
  127. Integer temAffairId = reportAffair.getId();
  128. CourtOrder courtOrder = finalCourtOrders.stream().filter(tem -> tem.getReportAffairId().equals(temAffairId)).findFirst().orElse(null);
  129. if (courtOrder != null) {
  130. item.setConclusion(courtOrder.getConclusion());
  131. }
  132. }
  133. });
  134. return list;
  135. }
  136. }