智能仲裁后端服务

FixSelectFlowDetailUtils.java 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. package com.ruoyi.wisdomarbitrate.utils;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONObject;
  4. import com.google.gson.Gson;
  5. import com.google.gson.JsonArray;
  6. import com.google.gson.JsonElement;
  7. import com.google.gson.JsonObject;
  8. import com.ruoyi.common.constant.CaseApplicationConstants;
  9. import com.ruoyi.common.constant.FileTransformation;
  10. import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
  11. import com.ruoyi.common.exception.EsignDemoException;
  12. import com.ruoyi.common.utils.SealUtil;
  13. import com.ruoyi.common.utils.file.SaaSAPIFileUtils;
  14. import com.ruoyi.wisdomarbitrate.domain.*;
  15. import com.ruoyi.wisdomarbitrate.mapper.*;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.scheduling.annotation.Scheduled;
  18. import org.springframework.stereotype.Component;
  19. import org.springframework.transaction.annotation.Transactional;
  20. import java.io.File;
  21. import java.io.IOException;
  22. import java.time.LocalDate;
  23. import java.util.Date;
  24. import java.util.List;
  25. import java.util.UUID;
  26. @Component
  27. public class FixSelectFlowDetailUtils {
  28. @Autowired
  29. private CaseApplicationMapper caseApplicationMapper;
  30. @Autowired
  31. private SealSignRecordMapper sealSignRecordMapper;
  32. @Autowired
  33. private CaseAttachMapper caseAttachMapper;
  34. @Autowired
  35. private DeptIdentifyMapper deptIdentifyMapper;
  36. @Autowired
  37. private SealManageMapper sealManageMapper;
  38. /*
  39. 定时查询签署流程详情
  40. */
  41. //@Scheduled(cron = "0/10 * * * * ?")
  42. @Transactional
  43. public void fixExecuteSelectFlowDetailUtils() {
  44. Gson gson = new Gson();
  45. SealSignRecord sealSignRecordselect = new SealSignRecord();
  46. // sealSignRecordselect.setSignFlowStatus(1);
  47. List<SealSignRecord> sealSignRecords = sealSignRecordMapper.selectSealSignRecordbyStat(sealSignRecordselect);
  48. try {
  49. if (sealSignRecords != null && sealSignRecords.size() > 0) {
  50. for (int i = 0; i < sealSignRecords.size(); i++) {
  51. SealSignRecord sealSignRecord = sealSignRecords.get(i);
  52. EsignHttpResponse signFlowDetail = SignAward.signFlowDetail(sealSignRecord);
  53. JsonObject signFlowDetailJsonObject = gson.fromJson(signFlowDetail.getBody(), JsonObject.class);
  54. JsonObject flowDetailData = signFlowDetailJsonObject.getAsJsonObject("data");
  55. JsonArray signersArray = flowDetailData.get("signers").getAsJsonArray();
  56. Integer psnsignStatus = null;
  57. Integer orgsignStatus = null;
  58. for (int j = 0; j < signersArray.size(); j++) {
  59. JsonObject signerObject = (JsonObject) signersArray.get(j);
  60. if (!(signerObject.get("psnSigner").toString()).equals("null")) {
  61. JsonObject psnSignerData = signerObject.getAsJsonObject("psnSigner");
  62. if (psnSignerData != null) {
  63. psnsignStatus = signerObject.get("signStatus").getAsInt();
  64. }
  65. }
  66. if (!(signerObject.get("orgSigner").toString()).equals("null")) {
  67. JsonObject orgSignerData = signerObject.getAsJsonObject("orgSigner");
  68. if (orgSignerData != null) {
  69. orgsignStatus = signerObject.get("signStatus").getAsInt();
  70. }
  71. }
  72. }
  73. if ((psnsignStatus.intValue() == 2) && (orgsignStatus.intValue() == 1)) {
  74. //更新立案申请状态为待用印
  75. CaseApplication caseApplication = new CaseApplication();
  76. caseApplication.setId(sealSignRecord.getCaseAppliId());
  77. CaseApplication caseApplicationselect = caseApplicationMapper.selectCaseApplication(caseApplication);
  78. if (caseApplicationselect != null) {
  79. if ((caseApplicationselect.getCaseStatus() != null) && (caseApplicationselect.getCaseStatus().intValue() == CaseApplicationConstants.SIGN_ARBITRATION)) {
  80. caseApplication.setCaseStatus(CaseApplicationConstants.ARBITRATED_SEAL);
  81. caseApplicationMapper.submitCaseApplication(caseApplication);
  82. //修改"签署用印记录表"的状态为待用印
  83. sealSignRecord.setSignFlowStatus(2);
  84. sealSignRecordMapper.updataSealSignRecord(sealSignRecord);
  85. }
  86. }
  87. }
  88. if ((psnsignStatus.intValue() == 2) && (orgsignStatus.intValue() == 2)) {
  89. //更新立案申请状态为待送达
  90. CaseApplication caseApplication = new CaseApplication();
  91. caseApplication.setId(sealSignRecord.getCaseAppliId());
  92. CaseApplication caseApplicationselect = caseApplicationMapper.selectCaseApplication(caseApplication);
  93. if (caseApplicationselect != null) {
  94. if ((caseApplicationselect.getCaseStatus() != null) && (caseApplicationselect.getCaseStatus().intValue() == CaseApplicationConstants.ARBITRATED_SEAL)) {
  95. caseApplication.setCaseStatus(CaseApplicationConstants.ARBITRATION_DELIVERY);
  96. //下载审核完成的裁决书,
  97. String signFlowId = sealSignRecord.getSignFlowid();
  98. EsignHttpResponse fileDownload = SaaSAPIFileUtils.fileDownloadUrl(signFlowId);
  99. JsonObject fileDownloadJsonObject = gson.fromJson(fileDownload.getBody(), JsonObject.class);
  100. JsonObject fileDownloadData = fileDownloadJsonObject.getAsJsonObject("data");
  101. JsonArray filesArray = fileDownloadData.get("files").getAsJsonArray();
  102. if (filesArray != null && filesArray.size() > 0) {
  103. JsonObject fileObject = (JsonObject) filesArray.get(0);
  104. String fileDownloadUrl = fileObject.get("downloadUrl").toString();
  105. //修改"签署用印记录表"的状态为签署完成
  106. sealSignRecord.setSignFlowStatus(3);
  107. sealSignRecord.setFileDownloadUrl(fileDownloadUrl.substring(1, fileDownloadUrl.length() - 1));
  108. sealSignRecordMapper.updataSealSignRecord(sealSignRecord);
  109. String filearbitraUrl = fileDownloadUrl.substring(1, fileDownloadUrl.length() - 1);
  110. caseApplication.setFilearbitraUrl(filearbitraUrl);
  111. caseApplicationMapper.submitCaseApplication(caseApplication);
  112. LocalDate now = LocalDate.now();
  113. String year = Integer.toString(now.getYear());
  114. String month = String.format("%02d", now.getMonthValue());
  115. String day = String.format("%02d", now.getDayOfMonth());
  116. String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
  117. String fileName = UUID.randomUUID().toString().replace("-", "") + ".pdf";
  118. String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
  119. String savePath = "/home/ruoyi/uploadPath/upload/";
  120. // 创建日期目录
  121. File saveFolder = new File(saveFolderPath);
  122. if (!saveFolder.exists()) {
  123. saveFolder.mkdirs();
  124. }
  125. String resultFilePath = saveFolderPath + "/" + fileName;
  126. File resultFilePathFile = new File(resultFilePath);
  127. if (!resultFilePathFile.exists()) {
  128. resultFilePathFile.createNewFile();
  129. }
  130. String fileDownloadUrlnew = fileDownloadUrl.substring(1, fileDownloadUrl.length() - 1);
  131. boolean downLoadFile = FileTransformation.downLoadFileByUrl(fileDownloadUrlnew, resultFilePath);
  132. if (downLoadFile) {
  133. Long caseAppliId = sealSignRecord.getCaseAppliId();
  134. CaseAttach caseAttach = new CaseAttach();
  135. caseAttach.setCaseAppliId(caseAppliId);
  136. caseAttach.setAnnexType(3);
  137. caseAttach.setAnnexPath(savePath);
  138. caseAttach.setAnnexName(saveName);
  139. caseAttachMapper.updateCaseAttachBycaseid(caseAttach);
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. } catch (EsignDemoException e) {
  148. e.printStackTrace();
  149. } catch (IOException e) {
  150. e.printStackTrace();
  151. }
  152. }
  153. /**
  154. * 定时查询企业认证状态
  155. *
  156. * @throws Exception
  157. */
  158. //@Scheduled(cron = "*/30 * * * * *")
  159. @Transactional
  160. public void fixExecuteSelectDeptIndentifyUtils() throws Exception {
  161. Gson gson = new Gson();
  162. DeptIdentify deptIdentify = new DeptIdentify();
  163. deptIdentify.setIdentifyStatus(0);
  164. List<DeptIdentify> deptIdentifysnew = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
  165. if (deptIdentifysnew != null && deptIdentifysnew.size() > 0) {
  166. for (int i = 0; i < deptIdentifysnew.size(); i++) {
  167. DeptIdentify deptIdentify1 = deptIdentifysnew.get(i);
  168. String authFlowId = deptIdentify1.getAuthFlowId();
  169. if (authFlowId != null) {
  170. EsignHttpResponse identifyInfo = SignAward.getDeptIdentifyInfo(deptIdentify1);
  171. JsonObject identifyInfoJsonObject = gson.fromJson(identifyInfo.getBody(), JsonObject.class);
  172. int code = identifyInfoJsonObject.get("code").getAsInt();
  173. if (code == 0) {
  174. JsonObject identifyInfoData = identifyInfoJsonObject.getAsJsonObject("data");
  175. int realnameStatus = identifyInfoData.get("realnameStatus").getAsInt();
  176. if (realnameStatus == 1) {
  177. String orgId = identifyInfoData.get("orgId").getAsString();
  178. //查询企业内部印章
  179. EsignHttpResponse response = SignAward.deptIdentifySealList(orgId);
  180. JsonObject jsonObject = gson.fromJson(response.getBody(), JsonObject.class);
  181. int code1 = jsonObject.get("code").getAsInt();
  182. if (code1 == 0) {
  183. JsonObject data = jsonObject.getAsJsonObject("data");
  184. JsonArray seals = data.get("seals").getAsJsonArray();
  185. if (seals.size() > 0) {
  186. for (int j = 0; j < seals.size(); j++) {
  187. //保存印章信息到数据库
  188. JsonObject asJsonObject = seals.get(j).getAsJsonObject();
  189. SealManage sealManage = new SealManage();
  190. String sealName = asJsonObject.get("sealName").toString();
  191. String sealId = asJsonObject.get("sealId").toString();
  192. String url = asJsonObject.get("sealImageDownloadUrl").toString();
  193. LocalDate now = LocalDate.now();
  194. String year = Integer.toString(now.getYear());
  195. String month = String.format("%02d", now.getMonthValue());
  196. String day = String.format("%02d", now.getDayOfMonth());
  197. String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
  198. String fileName = UUID.randomUUID().toString().replace("-", "") + ".jpg";
  199. String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
  200. String savePath = "/home/ruoyi/uploadPath/upload/";
  201. // 创建日期目录
  202. File saveFolder = new File(saveFolderPath);
  203. if (!saveFolder.exists()) {
  204. saveFolder.mkdirs();
  205. }
  206. String resultFilePath = saveFolderPath + "/" + fileName;
  207. File resultFilePathFile = new File(resultFilePath);
  208. if (!resultFilePathFile.exists()) {
  209. resultFilePathFile.createNewFile();
  210. }
  211. String fileDownloadUrlnew = url.substring(1, url.length() - 1);
  212. boolean downLoadFile = FileTransformation.downLoadFileByUrl(fileDownloadUrlnew, resultFilePath);
  213. if (downLoadFile) {
  214. CaseAttach caseAttach = new CaseAttach();
  215. caseAttach.setAnnexType(10); //10代表印章图片
  216. caseAttach.setAnnexPath(savePath);
  217. caseAttach.setAnnexName(saveName);
  218. int i1 = caseAttachMapper.save(caseAttach);
  219. if (i1 > 0) {
  220. //将印章信息保存到公章管理表里
  221. String sealName1 = sealName.substring(1, sealName.length() - 1);
  222. String sealId1 = sealId.substring(1, sealId.length() - 1);
  223. Integer annexId1 = caseAttach.getAnnexId();
  224. sealManage.setAnnexId(annexId1);
  225. sealManage.setSealId(sealId1);
  226. sealManage.setSealName(sealName1);
  227. sealManage.setIdentifyId(deptIdentify1.getId());
  228. sealManage.setSealStatus(1);
  229. sealManage.setIsUse(1);
  230. sealManageMapper.insertSealManage(sealManage);
  231. }
  232. }
  233. }
  234. }
  235. }
  236. //将orgId保存到数据库里
  237. deptIdentify1.setOrgId(orgId);
  238. deptIdentify1.setIdentifyStatus(1);
  239. deptIdentify1.setIsUse(0); //默认机构为未启用
  240. int row = deptIdentifyMapper.updateDeptIdentify(deptIdentify1);
  241. }
  242. }
  243. }
  244. }
  245. }
  246. }
  247. /**
  248. * 定时查询印章审核状态
  249. */
  250. @Scheduled(cron = "0/30 * * * * ?")
  251. @Transactional
  252. public void searchForInstitutionalSeal() {
  253. try {
  254. SealManage sealManage = new SealManage();
  255. sealManage.setSealStatus(0);
  256. List<SealManage> sealManageList = sealManageMapper.selectSealList(sealManage);
  257. if (sealManageList != null && sealManageList.size() > 0) {
  258. for (SealManage sealManage1 : sealManageList) {
  259. //查询企业内部印章
  260. Integer annexId = sealManage1.getAnnexId();
  261. String sealId = sealManage1.getSealId();
  262. DeptIdentify deptIdentify = new DeptIdentify();
  263. deptIdentify.setId(sealManage1.getIdentifyId());
  264. List<DeptIdentify> deptIdentifies = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
  265. if (deptIdentifies != null && deptIdentifies.size() > 0) {
  266. DeptIdentify deptIdentify1 = deptIdentifies.get(0);
  267. String orgId = deptIdentify1.getOrgId();
  268. if (orgId == null) {
  269. continue;
  270. }
  271. if (annexId == null) {
  272. //说明之前没有下载过
  273. EsignHttpResponse response = SignAward.getOrgSeal(orgId, sealId);
  274. JSONObject jsonObject = JSONObject.parseObject(response.getBody());
  275. int code = jsonObject.getIntValue("code");
  276. if (code == 0) {
  277. JSONObject data = jsonObject.getJSONObject("data");
  278. int sealStatus = data.getIntValue("sealStatus");
  279. if (sealStatus == 1) {//印章状态 1已启用,2待审核,3审核不通过,4 挂起
  280. //已启用证明审核通过,下载到数据库
  281. String sealImageDownloadUrl = data.getString("sealImageDownloadUrl");
  282. LocalDate now = LocalDate.now();
  283. String year = Integer.toString(now.getYear());
  284. String month = String.format("%02d", now.getMonthValue());
  285. String day = String.format("%02d", now.getDayOfMonth());
  286. String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
  287. String fileName = UUID.randomUUID().toString().replace("-", "") + ".pdf";
  288. String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
  289. String savePath = "/home/ruoyi/uploadPath/upload/";
  290. // 创建日期目录
  291. File saveFolder = new File(saveFolderPath);
  292. if (!saveFolder.exists()) {
  293. saveFolder.mkdirs();
  294. }
  295. String resultFilePath = saveFolderPath + "/" + fileName;
  296. File resultFilePathFile = new File(resultFilePath);
  297. if (!resultFilePathFile.exists()) {
  298. resultFilePathFile.createNewFile();
  299. }
  300. boolean downLoadFile = FileTransformation.downLoadFileByUrl(sealImageDownloadUrl, resultFilePath);
  301. if (downLoadFile) {
  302. CaseAttach caseAttach = new CaseAttach();
  303. caseAttach.setAnnexType(10); //10代表印章图片
  304. caseAttach.setAnnexPath(savePath);
  305. caseAttach.setAnnexName(saveName);
  306. int i1 = caseAttachMapper.save(caseAttach);
  307. if (i1 > 0) {
  308. //将附件id保存到公章管理表里
  309. Integer annexId1 = caseAttach.getAnnexId();
  310. sealManage1.setAnnexId(annexId1);
  311. sealManage1.setSealStatus(1);
  312. sealManage1.setIsUse(1); //默认使用状态都是未启用
  313. sealManageMapper.updateSealManage(sealManage1);
  314. }
  315. }
  316. }
  317. }
  318. }
  319. }
  320. }
  321. }
  322. } catch (EsignDemoException e) {
  323. e.printStackTrace();
  324. } catch (IOException e) {
  325. e.printStackTrace();
  326. }
  327. }
  328. }