package cn.cslg.pas.service.business; import cn.cslg.pas.common.dto.business.ReportAffairDTO; import cn.cslg.pas.common.dto.invalidDTO.AddAdminProceedDTO; import cn.cslg.pas.common.dto.invalidDTO.AddJudgmentDTO; import cn.cslg.pas.common.dto.invalidDTO.UpdateAdminProceedDTO; import cn.cslg.pas.common.dto.invalidDTO.UpdateJudgmentDTO; import cn.cslg.pas.common.model.report.ExtraEmailDTO; import cn.cslg.pas.common.model.report.MailMessageDTO; import cn.cslg.pas.common.vo.invalidVO.AdminProceedVO; import cn.cslg.pas.common.vo.invalidVO.JudgementVO; import cn.cslg.pas.common.vo.invalidVO.OralTrailVO; import cn.cslg.pas.domain.BaseEntity; import cn.cslg.pas.domain.business.*; import cn.cslg.pas.exception.XiaoShiException; import cn.cslg.pas.mapper.AdminProceedMapper; import cn.cslg.pas.service.MailSendService; import cn.cslg.pas.service.report.SendReportMailService; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /** * @Author xiexiang * @Date 2023/12/28 */ @Slf4j @Service public class AdminProceedService extends ServiceImpl { @Autowired private ReportAffairService reportAffairService; @Autowired private AssoReportAffairFileService assoReportAffairFileService; @Autowired private CourtOrderService courtOrderService; @Autowired private SendReportMailService sendReportMailService; @Autowired private MailSendService mailSendService; /** * 上传行政诉讼书 * @param addDto * @return */ public Integer add(AddAdminProceedDTO addDto){ if (addDto == null) { throw new XiaoShiException("入参为空"); } Integer projectId = addDto.getProjectId(); if (projectId == null) { throw new XiaoShiException("报告id为空"); } if (ObjectUtils.isEmpty(addDto.getAssoCasePhaseId())) { throw new XiaoShiException("案件流程阶段id为空"); } //1. 首先上传报告事务,拿到报告事务id ReportAffairDTO reportAffairDTO = new ReportAffairDTO(); reportAffairDTO.setProjectId(projectId); //发生时间是口审时间 reportAffairDTO.setOccurredTime(addDto.getProceedingTime()); //备注 reportAffairDTO.setDescription(addDto.getDescription()); reportAffairDTO.setAssoCasePhaseId(addDto.getAssoCasePhaseId()); Integer reportAffairId = reportAffairService.addReportAffair(reportAffairDTO); if (reportAffairId == null) { throw new XiaoShiException("上传报告事务失败"); } //2. 上传行政诉讼 AdminProceed adminLitigation = new AdminProceed(); adminLitigation.setConclusion(addDto.getConclusion()); adminLitigation.setReportAffairId(reportAffairId); adminLitigation.insert(); //3. 添加报告事务与文件关联 List fileGuids = addDto.getFileGuids(); if (fileGuids != null && !fileGuids.isEmpty()) { List assoReportAffairFiles = new ArrayList<>(); fileGuids.forEach(item -> { AssoReportAffairFile assoReportAffairFile = new AssoReportAffairFile(); assoReportAffairFile.setReportAffairId(reportAffairId); assoReportAffairFile.setFileGuid(item); assoReportAffairFiles.add(assoReportAffairFile); }); assoReportAffairFileService.saveBatch(assoReportAffairFiles); } if (addDto.getIfSendEmail()) { sendReportMailService.finalSendEmail(projectId, fileGuids, addDto.getExtraEmailDTOS()); } return reportAffairId; } /** * 查询 * @param reportAffairId * @return */ public AdminProceedVO getAdminProceed(Integer reportAffairId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(AdminProceed::getReportAffairId, reportAffairId); AdminProceed adminProceed = this.getOne(queryWrapper, false); AdminProceedVO adminProceedVO = new AdminProceedVO(); if (adminProceed != null) { BeanUtils.copyProperties(adminProceed, adminProceedVO); adminProceedVO.setProceedingId(adminProceed.getId()); } ReportAffair reportAffair = reportAffairService.getById(reportAffairId); adminProceedVO.setProceedingTime(reportAffair.getOccurredTime()); return adminProceedVO; } /** * 更新行政诉讼书 * @param updateDTO * @return */ public Integer update(UpdateAdminProceedDTO updateDTO){ if (updateDTO == null) { throw new XiaoShiException("入参为空"); } Integer projectId = updateDTO.getProjectId(); Integer id = updateDTO.getProceedingId(); if (id == null) { throw new XiaoShiException("id为空"); } if (projectId == null) { throw new XiaoShiException("报告id为空"); } if (ObjectUtils.isEmpty(updateDTO.getAssoCasePhaseId())) { throw new XiaoShiException("案件流程阶段id为空"); } //1. 根据id查出行政记录 AdminProceed al = this.getById(id); if (al == null) { throw new XiaoShiException("oralTrail查询错误"); } BeanUtils.copyProperties(updateDTO, al); al.updateById(); Integer reportAffairId = al.getReportAffairId(); //2. 拿到报告事务id,获取报告事务 ReportAffair reportAffair = reportAffairService.getById(reportAffairId); reportAffair.setProjectId(projectId); //发生时间是无效请求日 reportAffair.setOccurredTime(updateDTO.getProceedingTime()); //备注 reportAffair.setDescription(updateDTO.getDescription()); reportAffair.setAssoCasePhaseId(updateDTO.getAssoCasePhaseId()); reportAffair.updateById(); //3. 更新报告事务与文件关联 List fileGuids = updateDTO.getFileGuids(); assoReportAffairFileService.updateAffairFile(reportAffairId, fileGuids); if (updateDTO.getIfSendEmail()) { sendReportMailService.finalSendEmail(projectId, fileGuids, updateDTO.getExtraEmailDTOS()); } return reportAffairId; } /** * 上传行政诉讼判决书 * @param addJudgmentDTO * @return */ public Integer addJudgment(AddJudgmentDTO addJudgmentDTO){ if (addJudgmentDTO == null) { throw new XiaoShiException("入参为空"); } Integer projectId = addJudgmentDTO.getProjectId(); if (projectId == null) { throw new XiaoShiException("报告id为空"); } if (ObjectUtils.isEmpty(addJudgmentDTO.getAssoCasePhaseId())) { throw new XiaoShiException("案件流程阶段id为空"); } //1. 首先上传报告事务,拿到报告事务id ReportAffairDTO reportAffairDTO = new ReportAffairDTO(); reportAffairDTO.setProjectId(projectId); //发生时间是口审时间 reportAffairDTO.setOccurredTime(addJudgmentDTO.getJudgmentTime()); //备注 reportAffairDTO.setDescription(addJudgmentDTO.getDescription()); reportAffairDTO.setAssoCasePhaseId(addJudgmentDTO.getAssoCasePhaseId()); Integer reportAffairId = reportAffairService.addReportAffair(reportAffairDTO); if (reportAffairId == null) { throw new XiaoShiException("上传报告事务失败"); } //2.创建法院判决书 CourtOrder courtOrder = new CourtOrder(); courtOrder.setConclusion(addJudgmentDTO.getConclusion()); courtOrder.setReportAffairId(reportAffairId); courtOrder.insert(); //3. 添加报告事务与文件关联 List fileGuids = addJudgmentDTO.getFileGuids(); if (fileGuids != null && !fileGuids.isEmpty()) { List assoReportAffairFiles = new ArrayList<>(); fileGuids.forEach(item -> { AssoReportAffairFile assoReportAffairFile = new AssoReportAffairFile(); assoReportAffairFile.setReportAffairId(reportAffairId); assoReportAffairFile.setFileGuid(item); assoReportAffairFiles.add(assoReportAffairFile); }); assoReportAffairFileService.saveBatch(assoReportAffairFiles); } if (addJudgmentDTO.getIfSendEmail()) { sendReportMailService.finalSendEmail(projectId, fileGuids, addJudgmentDTO.getExtraEmailDTOS()); } return reportAffairId; } /** * 更新行政诉讼判决书 * @param updateJudgmentDTO * @return */ public Integer updateJudgment(UpdateJudgmentDTO updateJudgmentDTO){ if (updateJudgmentDTO == null) { throw new XiaoShiException("入参为空"); } Integer projectId = updateJudgmentDTO.getProjectId(); Integer reportAffairId = updateJudgmentDTO.getJudgmentId(); if (reportAffairId == null) { throw new XiaoShiException("id为空"); } if (projectId == null) { throw new XiaoShiException("报告id为空"); } if (ObjectUtils.isEmpty(updateJudgmentDTO.getAssoCasePhaseId())) { throw new XiaoShiException("案件流程阶段id为空"); } //1.拿到报告事务id,获取法院判别书,并更新 List courtOrders = courtOrderService.list(new LambdaQueryWrapper() .eq(CourtOrder::getReportAffairId, reportAffairId) .orderByDesc(BaseEntity::getId)); if (!CollectionUtils.isEmpty(courtOrders)) { CourtOrder courtOrder = courtOrders.get(0); CourtOrder court = courtOrderService.getById(courtOrder.getId()); court.setConclusion(updateJudgmentDTO.getConclusion()); court.updateById(); } //2. 拿到报告事务id,获取报告事务 ReportAffair reportAffair = reportAffairService.getById(reportAffairId); reportAffair.setProjectId(projectId); //发生时间是无效请求日 reportAffair.setOccurredTime(updateJudgmentDTO.getJudgmentTime()); //备注 reportAffair.setDescription(updateJudgmentDTO.getDescription()); reportAffair.setAssoCasePhaseId(updateJudgmentDTO.getAssoCasePhaseId()); reportAffair.updateById(); //3. 更新报告事务与文件关联 List fileGuids = updateJudgmentDTO.getFileGuids(); assoReportAffairFileService.updateAffairFile(reportAffairId, fileGuids); if (updateJudgmentDTO.getIfSendEmail()) { sendReportMailService.finalSendEmail(projectId, fileGuids, updateJudgmentDTO.getExtraEmailDTOS()); } return reportAffairId; } /** * 查询行政诉讼判决书 * @param reportAffairId * @return */ public JudgementVO getJudgment(Integer reportAffairId) { ReportAffair reportAffair = reportAffairService.getById(reportAffairId); JudgementVO judgementVO = new JudgementVO(); if (reportAffair != null) { BeanUtils.copyProperties(reportAffair, judgementVO); judgementVO.setJudgmentId(reportAffair.getId()); judgementVO.setJudgmentTime(reportAffair.getOccurredTime()); } return judgementVO; } }