OralTrailService.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. package cn.cslg.pas.service.business;
  2. import cn.cslg.pas.common.dto.business.ReportAffairDTO;
  3. import cn.cslg.pas.common.dto.invalidDTO.AddOralTrailDTO;
  4. import cn.cslg.pas.common.dto.invalidDTO.UpdateOralTrailDTO;
  5. import cn.cslg.pas.common.vo.invalidVO.InvalidRequestFileVO;
  6. import cn.cslg.pas.common.vo.invalidVO.OralTrailVO;
  7. import cn.cslg.pas.domain.business.AssoReportAffairFile;
  8. import cn.cslg.pas.domain.business.InvalidRequestFile;
  9. import cn.cslg.pas.domain.business.OralTrail;
  10. import cn.cslg.pas.domain.business.ReportAffair;
  11. import cn.cslg.pas.exception.XiaoShiException;
  12. import cn.cslg.pas.mapper.OralTrailMapper;
  13. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  14. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.springframework.beans.BeanUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.context.annotation.Lazy;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.web.bind.annotation.RequestBody;
  21. import java.util.ArrayList;
  22. import java.util.List;
  23. /**
  24. * 口审记录Service
  25. * @Author xiexiang
  26. * @Date 2023/12/28
  27. */
  28. @Slf4j
  29. @Service
  30. public class OralTrailService extends ServiceImpl<OralTrailMapper, OralTrail> {
  31. @Autowired
  32. private ReportAffairService reportAffairService;
  33. @Autowired
  34. private AssoReportAffairFileService assoReportAffairFileService;
  35. public Integer add(AddOralTrailDTO addOralTrailDTO){
  36. if (addOralTrailDTO == null) {
  37. throw new XiaoShiException("入参为空");
  38. }
  39. Integer projectId = addOralTrailDTO.getProjectId();
  40. if (projectId == null) {
  41. throw new XiaoShiException("报告id为空");
  42. }
  43. //1. 首先上传报告事务,拿到报告事务id
  44. ReportAffairDTO reportAffairDTO = new ReportAffairDTO();
  45. reportAffairDTO.setProjectId(projectId);
  46. //口审记录 0
  47. reportAffairDTO.setAffairType(0);
  48. //发生时间是口审时间
  49. reportAffairDTO.setOccurredTime(addOralTrailDTO.getOralTrailTime());
  50. //备注
  51. reportAffairDTO.setDescription(addOralTrailDTO.getRemark());
  52. Integer reportAffairId = reportAffairService.addReportAffair(reportAffairDTO);
  53. if (reportAffairId == null) {
  54. throw new XiaoShiException("上传报告事务失败");
  55. }
  56. //2. 上传口审记录
  57. OralTrail oralTrail = new OralTrail();
  58. oralTrail.setParticipator(addOralTrailDTO.getParticipator());
  59. oralTrail.setPosition(addOralTrailDTO.getPosition());
  60. oralTrail.setDescription(addOralTrailDTO.getDescription());
  61. oralTrail.setReportAffairId(reportAffairId);
  62. oralTrail.insert();
  63. //3. 添加报告事务与文件关联
  64. List<String> fileGuids = addOralTrailDTO.getFileGuids();
  65. if (fileGuids != null && !fileGuids.isEmpty()) {
  66. List<AssoReportAffairFile> assoReportAffairFiles = new ArrayList<>();
  67. fileGuids.forEach(item -> {
  68. AssoReportAffairFile assoReportAffairFile = new AssoReportAffairFile();
  69. assoReportAffairFile.setReportAffairId(reportAffairId);
  70. assoReportAffairFile.setFileGuid(item);
  71. assoReportAffairFiles.add(assoReportAffairFile);
  72. });
  73. assoReportAffairFileService.saveBatch(assoReportAffairFiles);
  74. }
  75. return reportAffairId;
  76. }
  77. public OralTrailVO getOralTrailVO(Integer reportAffairId) {
  78. LambdaQueryWrapper<OralTrail> queryWrapper = new LambdaQueryWrapper<>();
  79. queryWrapper.eq(OralTrail::getReportAffairId, reportAffairId);
  80. OralTrail oralTrail = this.getOne(queryWrapper, false);
  81. OralTrailVO oralTrailVO = new OralTrailVO();
  82. if (oralTrail != null) {
  83. BeanUtils.copyProperties(oralTrail, oralTrailVO);
  84. oralTrailVO.setOralTrailId(oralTrail.getId());
  85. }
  86. ReportAffair reportAffair = reportAffairService.getById(reportAffairId);
  87. oralTrailVO.setOralTrailTime(reportAffair.getOccurredTime());
  88. return oralTrailVO;
  89. }
  90. /**
  91. * 更新口审记录
  92. * @param updateOralTrailDTO
  93. * @return
  94. */
  95. public Integer update(UpdateOralTrailDTO updateOralTrailDTO){
  96. if (updateOralTrailDTO == null) {
  97. throw new XiaoShiException("入参为空");
  98. }
  99. Integer projectId = updateOralTrailDTO.getProjectId();
  100. Integer id = updateOralTrailDTO.getOralTrailId();
  101. if (id == null) {
  102. throw new XiaoShiException("id为空");
  103. }
  104. if (projectId == null) {
  105. throw new XiaoShiException("报告id为空");
  106. }
  107. //1. 根据id查出口审记录
  108. OralTrail oralTrail = this.getById(id);
  109. if (oralTrail == null) {
  110. throw new XiaoShiException("oralTrail查询错误");
  111. }
  112. BeanUtils.copyProperties(updateOralTrailDTO, oralTrail);
  113. oralTrail.updateById();
  114. Integer reportAffairId = oralTrail.getReportAffairId();
  115. //2. 拿到报告事务id,获取报告事务
  116. ReportAffair reportAffair = reportAffairService.getById(reportAffairId);
  117. reportAffair.setProjectId(projectId);
  118. //发生时间是无效请求日
  119. reportAffair.setOccurredTime(updateOralTrailDTO.getOralTrailTime());
  120. //备注
  121. reportAffair.setDescription(updateOralTrailDTO.getRemark());
  122. reportAffair.updateById();
  123. //3. 更新报告事务与文件关联
  124. List<String> fileGuids = updateOralTrailDTO.getFileGuids();
  125. if (fileGuids != null && !fileGuids.isEmpty()) {
  126. LambdaQueryWrapper<AssoReportAffairFile> queryWrapper = new LambdaQueryWrapper<>();
  127. queryWrapper.eq(AssoReportAffairFile::getReportAffairId, reportAffairId);
  128. assoReportAffairFileService.remove(queryWrapper);
  129. List<AssoReportAffairFile> assoReportAffairFiles = new ArrayList<>();
  130. fileGuids.forEach(item -> {
  131. AssoReportAffairFile assoReportAffairFile = new AssoReportAffairFile();
  132. assoReportAffairFile.setReportAffairId(reportAffairId);
  133. assoReportAffairFile.setFileGuid(item);
  134. assoReportAffairFiles.add(assoReportAffairFile);
  135. });
  136. assoReportAffairFileService.saveBatch(assoReportAffairFiles);
  137. }
  138. return reportAffairId;
  139. }
  140. }