package cn.cslg.pas.service.business; import cn.cslg.pas.common.dto.business.ReportAffairDTO; import cn.cslg.pas.common.dto.invalidDTO.AddOralTrailDTO; import cn.cslg.pas.common.dto.invalidDTO.UpdateOralTrailDTO; import cn.cslg.pas.common.model.report.ExtraEmailDTO; import cn.cslg.pas.common.model.report.MailMessageDTO; import cn.cslg.pas.common.vo.invalidVO.InvalidRequestFileVO; import cn.cslg.pas.common.vo.invalidVO.OralTrailVO; import cn.cslg.pas.domain.business.AssoReportAffairFile; import cn.cslg.pas.domain.business.InvalidRequestFile; import cn.cslg.pas.domain.business.OralTrail; import cn.cslg.pas.domain.business.ReportAffair; import cn.cslg.pas.exception.XiaoShiException; import cn.cslg.pas.mapper.OralTrailMapper; 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.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.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.web.bind.annotation.RequestBody; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; /** * 口审记录Service * @Author xiexiang * @Date 2023/12/28 */ @Slf4j @Service public class OralTrailService extends ServiceImpl { @Autowired private ReportAffairService reportAffairService; @Autowired private AssoReportAffairFileService assoReportAffairFileService; @Autowired private SendReportMailService sendReportMailService; @Autowired private MailSendService mailSendService; public Integer add(AddOralTrailDTO addOralTrailDTO){ if (addOralTrailDTO == null) { throw new XiaoShiException("入参为空"); } Integer projectId = addOralTrailDTO.getProjectId(); if (projectId == null) { throw new XiaoShiException("报告id为空"); } if (ObjectUtils.isEmpty(addOralTrailDTO.getAssoCasePhaseId())) { throw new XiaoShiException("案件流程阶段id为空"); } //1. 首先上传报告事务,拿到报告事务id ReportAffairDTO reportAffairDTO = new ReportAffairDTO(); reportAffairDTO.setProjectId(projectId); //发生时间是口审时间 reportAffairDTO.setOccurredTime(addOralTrailDTO.getOralTrailTime()); //备注 reportAffairDTO.setDescription(addOralTrailDTO.getDescription()); reportAffairDTO.setAssoCasePhaseId(addOralTrailDTO.getAssoCasePhaseId()); Integer reportAffairId = reportAffairService.addReportAffair(reportAffairDTO); if (reportAffairId == null) { throw new XiaoShiException("上传报告事务失败"); } //2. 上传口审记录 OralTrail oralTrail = new OralTrail(); oralTrail.setParticipator(addOralTrailDTO.getParticipator()); oralTrail.setPosition(addOralTrailDTO.getPosition()); oralTrail.setDescription(addOralTrailDTO.getRecordDescription()); oralTrail.setReportAffairId(reportAffairId); oralTrail.insert(); //3. 添加报告事务与文件关联 List fileGuids = addOralTrailDTO.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 (addOralTrailDTO.getIfSendEmail()) { sendReportMailService.finalSendEmail(projectId, fileGuids, addOralTrailDTO.getExtraEmailDTOS()); } return reportAffairId; } public OralTrailVO getOralTrailVO(Integer reportAffairId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(OralTrail::getReportAffairId, reportAffairId); OralTrail oralTrail = this.getOne(queryWrapper, false); OralTrailVO oralTrailVO = new OralTrailVO(); if (oralTrail != null) { BeanUtils.copyProperties(oralTrail, oralTrailVO); oralTrailVO.setOralTrailId(oralTrail.getId()); oralTrailVO.setRecordDescription(oralTrail.getDescription()); } ReportAffair reportAffair = reportAffairService.getById(reportAffairId); oralTrailVO.setOralTrailTime(reportAffair.getOccurredTime()); return oralTrailVO; } /** * 更新口审记录 * @param updateOralTrailDTO * @return */ public Integer update(UpdateOralTrailDTO updateOralTrailDTO){ if (updateOralTrailDTO == null) { throw new XiaoShiException("入参为空"); } Integer projectId = updateOralTrailDTO.getProjectId(); Integer id = updateOralTrailDTO.getOralTrailId(); if (id == null) { throw new XiaoShiException("id为空"); } if (projectId == null) { throw new XiaoShiException("报告id为空"); } if (ObjectUtils.isEmpty(updateOralTrailDTO.getAssoCasePhaseId())) { throw new XiaoShiException("案件流程阶段id为空"); } //1. 根据id查出口审记录 OralTrail oralTrail = this.getById(id); if (oralTrail == null) { throw new XiaoShiException("oralTrail查询错误"); } BeanUtils.copyProperties(updateOralTrailDTO, oralTrail); oralTrail.setDescription(updateOralTrailDTO.getRecordDescription()); oralTrail.updateById(); Integer reportAffairId = oralTrail.getReportAffairId(); //2. 拿到报告事务id,获取报告事务 ReportAffair reportAffair = reportAffairService.getById(reportAffairId); reportAffair.setProjectId(projectId); //发生时间是无效请求日 reportAffair.setOccurredTime(updateOralTrailDTO.getOralTrailTime()); //备注 reportAffair.setDescription(updateOralTrailDTO.getDescription()); reportAffair.setAssoCasePhaseId(updateOralTrailDTO.getAssoCasePhaseId()); reportAffair.updateById(); //3. 更新报告事务与文件关联 List fileGuids = updateOralTrailDTO.getFileGuids(); assoReportAffairFileService.updateAffairFile(reportAffairId, fileGuids); if (updateOralTrailDTO.getIfSendEmail()) { sendReportMailService.finalSendEmail(projectId, fileGuids, updateOralTrailDTO.getExtraEmailDTOS()); } return reportAffairId; } }