智能仲裁后端服务

FixSelectFlowDetailUtils.java 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package com.ruoyi.wisdomarbitrate.utils;
  2. import com.google.gson.Gson;
  3. import com.google.gson.JsonArray;
  4. import com.google.gson.JsonObject;
  5. import com.ruoyi.common.constant.CaseApplicationConstants;
  6. import com.ruoyi.common.constant.FileTransformation;
  7. import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
  8. import com.ruoyi.common.exception.EsignDemoException;
  9. import com.ruoyi.common.utils.file.SaaSAPIFileUtils;
  10. import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
  11. import com.ruoyi.wisdomarbitrate.domain.CaseAttach;
  12. import com.ruoyi.wisdomarbitrate.domain.DeptIdentify;
  13. import com.ruoyi.wisdomarbitrate.domain.SealSignRecord;
  14. import com.ruoyi.wisdomarbitrate.mapper.CaseApplicationMapper;
  15. import com.ruoyi.wisdomarbitrate.mapper.CaseAttachMapper;
  16. import com.ruoyi.wisdomarbitrate.mapper.DeptIdentifyMapper;
  17. import com.ruoyi.wisdomarbitrate.mapper.SealSignRecordMapper;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.scheduling.annotation.Scheduled;
  20. import org.springframework.stereotype.Component;
  21. import org.springframework.transaction.annotation.Transactional;
  22. import java.io.File;
  23. import java.io.IOException;
  24. import java.time.LocalDate;
  25. import java.util.List;
  26. import java.util.UUID;
  27. @Component
  28. public class FixSelectFlowDetailUtils {
  29. @Autowired
  30. private CaseApplicationMapper caseApplicationMapper;
  31. @Autowired
  32. private SealSignRecordMapper sealSignRecordMapper;
  33. @Autowired
  34. private CaseAttachMapper caseAttachMapper;
  35. @Autowired
  36. private DeptIdentifyMapper deptIdentifyMapper;
  37. @Scheduled(cron = "0/10 * * * * ?")
  38. // @Scheduled(cron = "0/30 * * * * ?")
  39. @Transactional
  40. public void fixExecuteSelectFlowDetailUtils(){
  41. Gson gson = new Gson();
  42. SealSignRecord sealSignRecordselect = new SealSignRecord();
  43. // sealSignRecordselect.setSignFlowStatus(1);
  44. List<SealSignRecord> sealSignRecords = sealSignRecordMapper.selectSealSignRecordbyStat(sealSignRecordselect);
  45. try {
  46. if(sealSignRecords!=null&&sealSignRecords.size()>0){
  47. for (int i = 0; i < sealSignRecords.size(); i++) {
  48. SealSignRecord sealSignRecord = sealSignRecords.get(i);
  49. EsignHttpResponse signFlowDetail = SignAward.signFlowDetail(sealSignRecord);
  50. JsonObject signFlowDetailJsonObject = gson.fromJson(signFlowDetail.getBody(),JsonObject.class);
  51. JsonObject flowDetailData = signFlowDetailJsonObject.getAsJsonObject("data");
  52. JsonArray signersArray = flowDetailData.get("signers").getAsJsonArray();
  53. Integer psnsignStatus = null;
  54. Integer orgsignStatus = null;
  55. for (int j = 0; j < signersArray.size(); j++) {
  56. JsonObject signerObject = (JsonObject)signersArray.get(j);
  57. if(!(signerObject.get("psnSigner").toString()).equals("null")){
  58. JsonObject psnSignerData = signerObject.getAsJsonObject("psnSigner");
  59. if(psnSignerData!=null){
  60. psnsignStatus = signerObject.get("signStatus").getAsInt();
  61. }
  62. }
  63. if(!(signerObject.get("orgSigner").toString()).equals("null")){
  64. JsonObject orgSignerData = signerObject.getAsJsonObject("orgSigner");
  65. if(orgSignerData!=null){
  66. orgsignStatus = signerObject.get("signStatus").getAsInt();
  67. }
  68. }
  69. }
  70. if((psnsignStatus.intValue()==2)&&(orgsignStatus.intValue()==1)){
  71. //更新立案申请状态为待用印
  72. CaseApplication caseApplication = new CaseApplication();
  73. caseApplication.setId(sealSignRecord.getCaseAppliId());
  74. CaseApplication caseApplicationselect = caseApplicationMapper.selectCaseApplication(caseApplication);
  75. if(caseApplicationselect!=null){
  76. if((caseApplicationselect.getCaseStatus()!=null)&&(caseApplicationselect.getCaseStatus().intValue()==CaseApplicationConstants.SIGN_ARBITRATION)){
  77. caseApplication.setCaseStatus(CaseApplicationConstants.ARBITRATED_SEAL);
  78. caseApplicationMapper.submitCaseApplication(caseApplication);
  79. //修改"签署用印记录表"的状态为待用印
  80. sealSignRecord.setSignFlowStatus(2);
  81. sealSignRecordMapper.updataSealSignRecord(sealSignRecord);
  82. }
  83. }
  84. }
  85. if((psnsignStatus.intValue()==2)&&(orgsignStatus.intValue()==2)){
  86. //更新立案申请状态为待送达
  87. CaseApplication caseApplication = new CaseApplication();
  88. caseApplication.setId(sealSignRecord.getCaseAppliId());
  89. CaseApplication caseApplicationselect = caseApplicationMapper.selectCaseApplication(caseApplication);
  90. if(caseApplicationselect!=null){
  91. if((caseApplicationselect.getCaseStatus()!=null)&&(caseApplicationselect.getCaseStatus().intValue()==CaseApplicationConstants.ARBITRATED_SEAL)){
  92. caseApplication.setCaseStatus(CaseApplicationConstants.ARBITRATION_DELIVERY);
  93. //下载审核完成的裁决书,
  94. String signFlowId = sealSignRecord.getSignFlowid();
  95. EsignHttpResponse fileDownload = SaaSAPIFileUtils.fileDownloadUrl(signFlowId);
  96. JsonObject fileDownloadJsonObject = gson.fromJson(fileDownload.getBody(),JsonObject.class);
  97. JsonObject fileDownloadData = fileDownloadJsonObject.getAsJsonObject("data");
  98. JsonArray filesArray = fileDownloadData.get("files").getAsJsonArray();
  99. if(filesArray!=null&&filesArray.size()>0){
  100. JsonObject fileObject = (JsonObject)filesArray.get(0);
  101. String fileDownloadUrl = fileObject.get("downloadUrl").toString();
  102. //修改"签署用印记录表"的状态为签署完成
  103. sealSignRecord.setSignFlowStatus(3);
  104. sealSignRecord.setFileDownloadUrl(fileDownloadUrl.substring(1,fileDownloadUrl.length()-1));
  105. sealSignRecordMapper.updataSealSignRecord(sealSignRecord);
  106. String filearbitraUrl = fileDownloadUrl.substring(1,fileDownloadUrl.length()-1);
  107. caseApplication.setFilearbitraUrl(filearbitraUrl);
  108. caseApplicationMapper.submitCaseApplication(caseApplication);
  109. LocalDate now = LocalDate.now();
  110. String year = Integer.toString(now.getYear());
  111. String month = String.format("%02d", now.getMonthValue());
  112. String day = String.format("%02d", now.getDayOfMonth());
  113. String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
  114. String fileName = UUID.randomUUID().toString().replace("-", "") + ".pdf";
  115. String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
  116. String savePath = "/home/ruoyi/uploadPath/upload/";
  117. // 创建日期目录
  118. File saveFolder = new File(saveFolderPath);
  119. if (!saveFolder.exists()) {
  120. saveFolder.mkdirs();
  121. }
  122. String resultFilePath = saveFolderPath + "/" + fileName;
  123. File resultFilePathFile = new File(resultFilePath);
  124. if (!resultFilePathFile.exists()) {
  125. resultFilePathFile.createNewFile();
  126. }
  127. String fileDownloadUrlnew = fileDownloadUrl.substring(1,fileDownloadUrl.length()-1);
  128. boolean downLoadFile = FileTransformation.downLoadFileByUrl(fileDownloadUrlnew, resultFilePath);
  129. if(downLoadFile) {
  130. Long caseAppliId = sealSignRecord.getCaseAppliId();
  131. CaseAttach caseAttach = new CaseAttach();
  132. caseAttach.setCaseAppliId(caseAppliId);
  133. caseAttach.setAnnexType(3);
  134. caseAttach.setAnnexPath(savePath);
  135. caseAttach.setAnnexName(saveName);
  136. caseAttachMapper.updateCaseAttachBycaseid(caseAttach);
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. } catch (EsignDemoException e) {
  145. e.printStackTrace();
  146. }catch (IOException e) {
  147. e.printStackTrace();
  148. }
  149. }
  150. @Scheduled(cron = "0/30 * * * * ?")
  151. @Transactional
  152. public void fixExecuteSelectDeptIndentifyUtils() throws EsignDemoException {
  153. Gson gson = new Gson();
  154. DeptIdentify deptIdentify = new DeptIdentify();
  155. deptIdentify.setIdentifyStatus(0);
  156. List<DeptIdentify> deptIdentifysnew = deptIdentifyMapper.selectDeptIdentifylist(deptIdentify);
  157. if(deptIdentifysnew!=null&&deptIdentifysnew.size()>0){
  158. for (int i = 0; i < deptIdentifysnew.size(); i++) {
  159. EsignHttpResponse identifyInfo = SignAward.getDeptIdentifyInfo(deptIdentifysnew.get(i));
  160. JsonObject identifyInfoJsonObject = gson.fromJson(identifyInfo.getBody(), JsonObject.class);
  161. JsonObject identifyInfoData = identifyInfoJsonObject.getAsJsonObject("data");
  162. int realnameStatus = identifyInfoData.get("realnameStatus").getAsInt();
  163. String orgId = identifyInfoData.get("orgId").getAsString();
  164. if(realnameStatus==1){
  165. EsignHttpResponse identifyInfo1 = SignAward.deptIdentifySealList(orgId);
  166. JsonObject identifyInfoJsonObject1 = gson.fromJson(identifyInfo1.getBody(), JsonObject.class);
  167. JsonObject identifyInfoData1 = identifyInfoJsonObject1.getAsJsonObject("data");
  168. JsonArray sealArray = identifyInfoData1.get("seals").getAsJsonArray();
  169. String sealNames = "";
  170. if(sealArray.size()>0){
  171. for (int j = 0; j < sealArray.size(); j++) {
  172. JsonObject sealObject = (JsonObject)sealArray.get(j);
  173. String sealName = sealObject.get("sealName").toString();
  174. String sealNamenew = sealName.substring(1,sealName.length()-1);
  175. sealNames += sealNamenew +",";
  176. }
  177. }
  178. String sealName = sealNames.substring(0,sealNames.length()-1);
  179. DeptIdentify deptIdentifynew = deptIdentifysnew.get(i);
  180. deptIdentifynew.setIdentifyStatus(1);
  181. deptIdentifynew.setSealName(sealName);
  182. int row = deptIdentifyMapper.updateDeptIdentify(deptIdentifynew);
  183. }
  184. }
  185. }
  186. }
  187. }