package cn.cslg.pas.service.novelty; import cn.cslg.pas.common.model.novelty.LitigationDTO; import cn.cslg.pas.common.model.novelty.LitigationReVO; import cn.cslg.pas.common.model.novelty.LitigationVO; import cn.cslg.pas.domain.business.CourtOrder; import cn.cslg.pas.domain.business.ReportAffair; import cn.cslg.pas.exception.ExceptionEnum; import cn.cslg.pas.exception.XiaoShiException; import cn.cslg.pas.service.business.CourtOrderService; import cn.cslg.pas.service.business.ReportAffairService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import cn.cslg.pas.domain.business.novelty.Litigation; import cn.cslg.pas.mapper.novelty.LitigationMapper; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; /** * @author admin * @description 针对表【litigation(行政诉讼表)】的数据库操作Service实现 * @createDate 2025-02-27 10:49:21 */ @Service @RequiredArgsConstructor public class LitigationService extends ServiceImpl { private final ReportAffairService reportAffairService; private final CourtOrderService courtOrderService; public Litigation addLitigation(LitigationDTO litigationDTO) { Litigation litigation = new Litigation(); BeanUtils.copyProperties(litigationDTO, litigation); litigation.insert(); return litigation; } public Litigation updateLitigation(LitigationDTO litigationDTO, Litigation litigation) { Litigation litigation1 = new Litigation(); BeanUtils.copyProperties(litigationDTO, litigation1); litigation1.setCreateId(litigation.getCreateId()); litigation1.setCreateTime(litigation.getCreateTime()); litigation1.setId(litigation.getId()); litigation1.updateById(); return litigation; } public Litigation addOrUpdateLitigation(LitigationDTO litigationDTO) { Integer projectId = litigationDTO.getProjectId(); Integer type = litigationDTO.getType(); if (projectId == null || type == null) { throw new XiaoShiException(ExceptionEnum.BUSINESS_ERROR, "未传入必要参数"); } LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Litigation::getProjectId, projectId) .eq(Litigation::getType, type); Litigation litigation = this.getOne(queryWrapper, false); if (litigation == null) { return this.addLitigation(litigationDTO); } else { return this.updateLitigation(litigationDTO, litigation); } } public LitigationReVO queryLitigation(LitigationDTO litigationDTO) { LitigationReVO litigationReVO = new LitigationReVO(); Integer projectId = litigationDTO.getProjectId(); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(Litigation::getProjectId, projectId); List list = this.list(queryWrapper); litigationReVO = this.loadLitigation(list, projectId); return litigationReVO; } public LitigationReVO loadLitigation(List list, Integer projectId) { LitigationReVO litigationReVO = new LitigationReVO(); if (list.size() == 0) { return litigationReVO; } List litigationVOS = new ArrayList<>(); list.forEach(item -> { LitigationVO litigationVO = new LitigationVO(); BeanUtils.copyProperties(item, litigationVO); litigationVOS.add(litigationVO); }); this.loadResultByAffair(projectId, litigationVOS); litigationVOS.forEach(item -> { if (item.getType().equals(1)) { litigationReVO.setLitigationVO1(item); } else { litigationReVO.setLitigationVO2(item); } }); return litigationReVO; } public List loadResultByAffair(Integer projectId, List list) { if (list.size() == 0) { return list; } Integer litigationType1 = 16; Integer litigationType2 = 26; LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(ReportAffair::getProjectId, projectId) .in(ReportAffair::getAssoCasePhaseId, Arrays.asList(litigationType1, litigationType2)); List reportAffairs = reportAffairService.list(queryWrapper); if (reportAffairs == null || reportAffairs.size() == 0) { return list; } List reportAffairIds = reportAffairs.stream().map(ReportAffair::getId).collect(Collectors.toList()); List courtOrders = new ArrayList<>(); if (reportAffairIds.size() > 0) { LambdaQueryWrapper queryWrapper1 = new LambdaQueryWrapper<>(); queryWrapper1.in(CourtOrder::getReportAffairId, reportAffairIds); courtOrders = courtOrderService.list(queryWrapper1); } if (courtOrders.size() == 0) { return list; } List finalCourtOrders = courtOrders; list.forEach(item -> { Integer affairType = litigationType1; if (item.getType().equals(1)) { affairType = litigationType1; } else { affairType = litigationType2; } Integer finalType = affairType; ReportAffair reportAffair = reportAffairs.stream().filter(tem -> finalType.equals(tem.getAssoCasePhaseId())).findFirst().orElse(null); if (reportAffair != null) { Integer temAffairId = reportAffair.getId(); CourtOrder courtOrder = finalCourtOrders.stream().filter(tem -> tem.getReportAffairId().equals(temAffairId)).findFirst().orElse(null); if (courtOrder != null) { item.setConclusion(courtOrder.getConclusion()); } } }); return list; } }