AdminProceedService.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. package cn.cslg.pas.service.business;
  2. import cn.cslg.pas.common.dto.business.ReportAffairDTO;
  3. import cn.cslg.pas.common.dto.invalidDTO.AddAdminProceedDTO;
  4. import cn.cslg.pas.common.dto.invalidDTO.AddJudgmentDTO;
  5. import cn.cslg.pas.common.dto.invalidDTO.UpdateAdminProceedDTO;
  6. import cn.cslg.pas.common.dto.invalidDTO.UpdateJudgmentDTO;
  7. import cn.cslg.pas.common.model.report.ExtraEmailDTO;
  8. import cn.cslg.pas.common.model.report.MailMessageDTO;
  9. import cn.cslg.pas.common.vo.invalidVO.AdminProceedVO;
  10. import cn.cslg.pas.common.vo.invalidVO.JudgementVO;
  11. import cn.cslg.pas.common.vo.invalidVO.OralTrailVO;
  12. import cn.cslg.pas.domain.BaseEntity;
  13. import cn.cslg.pas.domain.business.*;
  14. import cn.cslg.pas.exception.XiaoShiException;
  15. import cn.cslg.pas.mapper.AdminProceedMapper;
  16. import cn.cslg.pas.service.MailSendService;
  17. import cn.cslg.pas.service.report.SendReportMailService;
  18. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  19. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  20. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.apache.commons.lang3.ObjectUtils;
  23. import org.apache.commons.lang3.StringUtils;
  24. import org.springframework.beans.BeanUtils;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27. import org.springframework.util.CollectionUtils;
  28. import java.util.ArrayList;
  29. import java.util.List;
  30. import java.util.stream.Collectors;
  31. /**
  32. * @Author xiexiang
  33. * @Date 2023/12/28
  34. */
  35. @Slf4j
  36. @Service
  37. public class AdminProceedService extends ServiceImpl<AdminProceedMapper, AdminProceed> {
  38. @Autowired
  39. private ReportAffairService reportAffairService;
  40. @Autowired
  41. private AssoReportAffairFileService assoReportAffairFileService;
  42. @Autowired
  43. private CourtOrderService courtOrderService;
  44. @Autowired
  45. private SendReportMailService sendReportMailService;
  46. @Autowired
  47. private MailSendService mailSendService;
  48. /**
  49. * 上传行政诉讼书
  50. * @param addDto
  51. * @return
  52. */
  53. public Integer add(AddAdminProceedDTO addDto){
  54. if (addDto == null) {
  55. throw new XiaoShiException("入参为空");
  56. }
  57. Integer projectId = addDto.getProjectId();
  58. if (projectId == null) {
  59. throw new XiaoShiException("报告id为空");
  60. }
  61. if (ObjectUtils.isEmpty(addDto.getAssoCasePhaseId())) {
  62. throw new XiaoShiException("案件流程阶段id为空");
  63. }
  64. //1. 首先上传报告事务,拿到报告事务id
  65. ReportAffairDTO reportAffairDTO = new ReportAffairDTO();
  66. reportAffairDTO.setProjectId(projectId);
  67. //发生时间是口审时间
  68. reportAffairDTO.setOccurredTime(addDto.getProceedingTime());
  69. //备注
  70. reportAffairDTO.setDescription(addDto.getDescription());
  71. reportAffairDTO.setAssoCasePhaseId(addDto.getAssoCasePhaseId());
  72. Integer reportAffairId = reportAffairService.addReportAffair(reportAffairDTO);
  73. if (reportAffairId == null) {
  74. throw new XiaoShiException("上传报告事务失败");
  75. }
  76. //2. 上传行政诉讼
  77. AdminProceed adminLitigation = new AdminProceed();
  78. adminLitigation.setConclusion(addDto.getConclusion());
  79. adminLitigation.setReportAffairId(reportAffairId);
  80. adminLitigation.insert();
  81. //3. 添加报告事务与文件关联
  82. List<String> fileGuids = addDto.getFileGuids();
  83. if (fileGuids != null && !fileGuids.isEmpty()) {
  84. List<AssoReportAffairFile> assoReportAffairFiles = new ArrayList<>();
  85. fileGuids.forEach(item -> {
  86. AssoReportAffairFile assoReportAffairFile = new AssoReportAffairFile();
  87. assoReportAffairFile.setReportAffairId(reportAffairId);
  88. assoReportAffairFile.setFileGuid(item);
  89. assoReportAffairFiles.add(assoReportAffairFile);
  90. });
  91. assoReportAffairFileService.saveBatch(assoReportAffairFiles);
  92. }
  93. if (addDto.getIfSendEmail()) {
  94. sendReportMailService.finalSendEmail(projectId, fileGuids, addDto.getExtraEmailDTOS());
  95. }
  96. return reportAffairId;
  97. }
  98. /**
  99. * 查询
  100. * @param reportAffairId
  101. * @return
  102. */
  103. public AdminProceedVO getAdminProceed(Integer reportAffairId) {
  104. LambdaQueryWrapper<AdminProceed> queryWrapper = new LambdaQueryWrapper<>();
  105. queryWrapper.eq(AdminProceed::getReportAffairId, reportAffairId);
  106. AdminProceed adminProceed = this.getOne(queryWrapper, false);
  107. AdminProceedVO adminProceedVO = new AdminProceedVO();
  108. if (adminProceed != null) {
  109. BeanUtils.copyProperties(adminProceed, adminProceedVO);
  110. adminProceedVO.setProceedingId(adminProceed.getId());
  111. }
  112. ReportAffair reportAffair = reportAffairService.getById(reportAffairId);
  113. adminProceedVO.setProceedingTime(reportAffair.getOccurredTime());
  114. return adminProceedVO;
  115. }
  116. /**
  117. * 更新行政诉讼书
  118. * @param updateDTO
  119. * @return
  120. */
  121. public Integer update(UpdateAdminProceedDTO updateDTO){
  122. if (updateDTO == null) {
  123. throw new XiaoShiException("入参为空");
  124. }
  125. Integer projectId = updateDTO.getProjectId();
  126. Integer id = updateDTO.getProceedingId();
  127. if (id == null) {
  128. throw new XiaoShiException("id为空");
  129. }
  130. if (projectId == null) {
  131. throw new XiaoShiException("报告id为空");
  132. }
  133. if (ObjectUtils.isEmpty(updateDTO.getAssoCasePhaseId())) {
  134. throw new XiaoShiException("案件流程阶段id为空");
  135. }
  136. //1. 根据id查出行政记录
  137. AdminProceed al = this.getById(id);
  138. if (al == null) {
  139. throw new XiaoShiException("oralTrail查询错误");
  140. }
  141. BeanUtils.copyProperties(updateDTO, al);
  142. al.updateById();
  143. Integer reportAffairId = al.getReportAffairId();
  144. //2. 拿到报告事务id,获取报告事务
  145. ReportAffair reportAffair = reportAffairService.getById(reportAffairId);
  146. reportAffair.setProjectId(projectId);
  147. //发生时间是无效请求日
  148. reportAffair.setOccurredTime(updateDTO.getProceedingTime());
  149. //备注
  150. reportAffair.setDescription(updateDTO.getDescription());
  151. reportAffair.setAssoCasePhaseId(updateDTO.getAssoCasePhaseId());
  152. reportAffair.updateById();
  153. //3. 更新报告事务与文件关联
  154. List<String> fileGuids = updateDTO.getFileGuids();
  155. assoReportAffairFileService.updateAffairFile(reportAffairId, fileGuids);
  156. if (updateDTO.getIfSendEmail()) {
  157. sendReportMailService.finalSendEmail(projectId, fileGuids, updateDTO.getExtraEmailDTOS());
  158. }
  159. return reportAffairId;
  160. }
  161. /**
  162. * 上传行政诉讼判决书
  163. * @param addJudgmentDTO
  164. * @return
  165. */
  166. public Integer addJudgment(AddJudgmentDTO addJudgmentDTO){
  167. if (addJudgmentDTO == null) {
  168. throw new XiaoShiException("入参为空");
  169. }
  170. Integer projectId = addJudgmentDTO.getProjectId();
  171. if (projectId == null) {
  172. throw new XiaoShiException("报告id为空");
  173. }
  174. if (ObjectUtils.isEmpty(addJudgmentDTO.getAssoCasePhaseId())) {
  175. throw new XiaoShiException("案件流程阶段id为空");
  176. }
  177. //1. 首先上传报告事务,拿到报告事务id
  178. ReportAffairDTO reportAffairDTO = new ReportAffairDTO();
  179. reportAffairDTO.setProjectId(projectId);
  180. //发生时间是口审时间
  181. reportAffairDTO.setOccurredTime(addJudgmentDTO.getJudgmentTime());
  182. //备注
  183. reportAffairDTO.setDescription(addJudgmentDTO.getDescription());
  184. reportAffairDTO.setAssoCasePhaseId(addJudgmentDTO.getAssoCasePhaseId());
  185. Integer reportAffairId = reportAffairService.addReportAffair(reportAffairDTO);
  186. if (reportAffairId == null) {
  187. throw new XiaoShiException("上传报告事务失败");
  188. }
  189. //2.创建法院判决书
  190. CourtOrder courtOrder = new CourtOrder();
  191. courtOrder.setConclusion(addJudgmentDTO.getConclusion());
  192. courtOrder.setReportAffairId(reportAffairId);
  193. courtOrder.insert();
  194. //3. 添加报告事务与文件关联
  195. List<String> fileGuids = addJudgmentDTO.getFileGuids();
  196. if (fileGuids != null && !fileGuids.isEmpty()) {
  197. List<AssoReportAffairFile> assoReportAffairFiles = new ArrayList<>();
  198. fileGuids.forEach(item -> {
  199. AssoReportAffairFile assoReportAffairFile = new AssoReportAffairFile();
  200. assoReportAffairFile.setReportAffairId(reportAffairId);
  201. assoReportAffairFile.setFileGuid(item);
  202. assoReportAffairFiles.add(assoReportAffairFile);
  203. });
  204. assoReportAffairFileService.saveBatch(assoReportAffairFiles);
  205. }
  206. if (addJudgmentDTO.getIfSendEmail()) {
  207. sendReportMailService.finalSendEmail(projectId, fileGuids, addJudgmentDTO.getExtraEmailDTOS());
  208. }
  209. return reportAffairId;
  210. }
  211. /**
  212. * 更新行政诉讼判决书
  213. * @param updateJudgmentDTO
  214. * @return
  215. */
  216. public Integer updateJudgment(UpdateJudgmentDTO updateJudgmentDTO){
  217. if (updateJudgmentDTO == null) {
  218. throw new XiaoShiException("入参为空");
  219. }
  220. Integer projectId = updateJudgmentDTO.getProjectId();
  221. Integer reportAffairId = updateJudgmentDTO.getJudgmentId();
  222. if (reportAffairId == null) {
  223. throw new XiaoShiException("id为空");
  224. }
  225. if (projectId == null) {
  226. throw new XiaoShiException("报告id为空");
  227. }
  228. if (ObjectUtils.isEmpty(updateJudgmentDTO.getAssoCasePhaseId())) {
  229. throw new XiaoShiException("案件流程阶段id为空");
  230. }
  231. //1.拿到报告事务id,获取法院判别书,并更新
  232. List<CourtOrder> courtOrders = courtOrderService.list(new LambdaQueryWrapper<CourtOrder>()
  233. .eq(CourtOrder::getReportAffairId, reportAffairId)
  234. .orderByDesc(BaseEntity::getId));
  235. if (!CollectionUtils.isEmpty(courtOrders)) {
  236. CourtOrder courtOrder = courtOrders.get(0);
  237. CourtOrder court = courtOrderService.getById(courtOrder.getId());
  238. court.setConclusion(updateJudgmentDTO.getConclusion());
  239. court.updateById();
  240. }
  241. //2. 拿到报告事务id,获取报告事务
  242. ReportAffair reportAffair = reportAffairService.getById(reportAffairId);
  243. reportAffair.setProjectId(projectId);
  244. //发生时间是无效请求日
  245. reportAffair.setOccurredTime(updateJudgmentDTO.getJudgmentTime());
  246. //备注
  247. reportAffair.setDescription(updateJudgmentDTO.getDescription());
  248. reportAffair.setAssoCasePhaseId(updateJudgmentDTO.getAssoCasePhaseId());
  249. reportAffair.updateById();
  250. //3. 更新报告事务与文件关联
  251. List<String> fileGuids = updateJudgmentDTO.getFileGuids();
  252. assoReportAffairFileService.updateAffairFile(reportAffairId, fileGuids);
  253. if (updateJudgmentDTO.getIfSendEmail()) {
  254. sendReportMailService.finalSendEmail(projectId, fileGuids, updateJudgmentDTO.getExtraEmailDTOS());
  255. }
  256. return reportAffairId;
  257. }
  258. /**
  259. * 查询行政诉讼判决书
  260. * @param reportAffairId
  261. * @return
  262. */
  263. public JudgementVO getJudgment(Integer reportAffairId) {
  264. ReportAffair reportAffair = reportAffairService.getById(reportAffairId);
  265. JudgementVO judgementVO = new JudgementVO();
  266. if (reportAffair != null) {
  267. BeanUtils.copyProperties(reportAffair, judgementVO);
  268. judgementVO.setJudgmentId(reportAffair.getId());
  269. judgementVO.setJudgmentTime(reportAffair.getOccurredTime());
  270. }
  271. return judgementVO;
  272. }
  273. }