智能仲裁后端服务

FixSelectFlowDetailUtils.java 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. }else {
  243. deptIdentify1.setIdentifyStatus(2);
  244. deptIdentifyMapper.updateDeptIdentify(deptIdentify1);
  245. }
  246. }
  247. }
  248. }
  249. }
  250. /**
  251. * 定时查询企业认证状态
  252. *
  253. * @throws Exception
  254. */
  255. @Scheduled(cron = "*/30 * * * * *")
  256. @Transactional
  257. public void fixExecuteSelectDeptIndentify() throws Exception {
  258. Gson gson = new Gson();
  259. DeptIdentify deptIdentify = new DeptIdentify();
  260. deptIdentify.setIdentifyStatus(2);
  261. List<DeptIdentify> deptIdentifysnew = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
  262. if (deptIdentifysnew != null && deptIdentifysnew.size() > 0) {
  263. for (int i = 0; i < deptIdentifysnew.size(); i++) {
  264. DeptIdentify deptIdentify1 = deptIdentifysnew.get(i);
  265. String authFlowId = deptIdentify1.getAuthFlowId();
  266. if (authFlowId != null) {
  267. EsignHttpResponse identifyInfo = SignAward.getDeptIdentifyInfo(deptIdentify1);
  268. JsonObject identifyInfoJsonObject = gson.fromJson(identifyInfo.getBody(), JsonObject.class);
  269. int code = identifyInfoJsonObject.get("code").getAsInt();
  270. if (code == 0) {
  271. JsonObject identifyInfoData = identifyInfoJsonObject.getAsJsonObject("data");
  272. int realnameStatus = identifyInfoData.get("realnameStatus").getAsInt();
  273. if (realnameStatus == 1) {
  274. String orgId = identifyInfoData.get("orgId").getAsString();
  275. //查询企业内部印章
  276. EsignHttpResponse response = SignAward.deptIdentifySealList(orgId);
  277. JsonObject jsonObject = gson.fromJson(response.getBody(), JsonObject.class);
  278. int code1 = jsonObject.get("code").getAsInt();
  279. if (code1 == 0) {
  280. JsonObject data = jsonObject.getAsJsonObject("data");
  281. JsonArray seals = data.get("seals").getAsJsonArray();
  282. if (seals.size() > 0) {
  283. for (int j = 0; j < seals.size(); j++) {
  284. //保存印章信息到数据库
  285. JsonObject asJsonObject = seals.get(j).getAsJsonObject();
  286. SealManage sealManage = new SealManage();
  287. String sealName = asJsonObject.get("sealName").toString();
  288. String sealId = asJsonObject.get("sealId").toString();
  289. String url = asJsonObject.get("sealImageDownloadUrl").toString();
  290. LocalDate now = LocalDate.now();
  291. String year = Integer.toString(now.getYear());
  292. String month = String.format("%02d", now.getMonthValue());
  293. String day = String.format("%02d", now.getDayOfMonth());
  294. String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
  295. String fileName = UUID.randomUUID().toString().replace("-", "") + ".jpg";
  296. String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
  297. String savePath = "/home/ruoyi/uploadPath/upload/";
  298. // 创建日期目录
  299. File saveFolder = new File(saveFolderPath);
  300. if (!saveFolder.exists()) {
  301. saveFolder.mkdirs();
  302. }
  303. String resultFilePath = saveFolderPath + "/" + fileName;
  304. File resultFilePathFile = new File(resultFilePath);
  305. if (!resultFilePathFile.exists()) {
  306. resultFilePathFile.createNewFile();
  307. }
  308. String fileDownloadUrlnew = url.substring(1, url.length() - 1);
  309. boolean downLoadFile = FileTransformation.downLoadFileByUrl(fileDownloadUrlnew, resultFilePath);
  310. if (downLoadFile) {
  311. CaseAttach caseAttach = new CaseAttach();
  312. caseAttach.setAnnexType(10); //10代表印章图片
  313. caseAttach.setAnnexPath(savePath);
  314. caseAttach.setAnnexName(saveName);
  315. int i1 = caseAttachMapper.save(caseAttach);
  316. if (i1 > 0) {
  317. //将印章信息保存到公章管理表里
  318. String sealName1 = sealName.substring(1, sealName.length() - 1);
  319. String sealId1 = sealId.substring(1, sealId.length() - 1);
  320. Integer annexId1 = caseAttach.getAnnexId();
  321. sealManage.setAnnexId(annexId1);
  322. sealManage.setSealId(sealId1);
  323. sealManage.setSealName(sealName1);
  324. sealManage.setIdentifyId(deptIdentify1.getId());
  325. sealManage.setSealStatus(1);
  326. sealManage.setIsUse(1);
  327. sealManageMapper.insertSealManage(sealManage);
  328. }
  329. }
  330. }
  331. }
  332. }
  333. //将orgId保存到数据库里
  334. deptIdentify1.setOrgId(orgId);
  335. deptIdentify1.setIdentifyStatus(1);
  336. deptIdentify1.setIsUse(0); //默认机构为未启用
  337. int row = deptIdentifyMapper.updateDeptIdentify(deptIdentify1);
  338. }
  339. }else {
  340. deptIdentify1.setIdentifyStatus(2);
  341. deptIdentifyMapper.updateDeptIdentify(deptIdentify1);
  342. }
  343. }
  344. }
  345. }
  346. }
  347. /**
  348. * 定时查询印章审核状态
  349. */
  350. @Scheduled(cron = "0/30 * * * * ?")
  351. @Transactional
  352. public void searchForInstitutionalSeal() {
  353. try {
  354. SealManage sealManage = new SealManage();
  355. sealManage.setSealStatus(0);
  356. List<SealManage> sealManageList = sealManageMapper.selectSealList(sealManage);
  357. if (sealManageList != null && sealManageList.size() > 0) {
  358. for (SealManage sealManage1 : sealManageList) {
  359. //查询企业内部印章
  360. Integer annexId = sealManage1.getAnnexId();
  361. String sealId = sealManage1.getSealId();
  362. DeptIdentify deptIdentify = new DeptIdentify();
  363. deptIdentify.setId(sealManage1.getIdentifyId());
  364. List<DeptIdentify> deptIdentifies = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
  365. if (deptIdentifies != null && deptIdentifies.size() > 0) {
  366. DeptIdentify deptIdentify1 = deptIdentifies.get(0);
  367. String orgId = deptIdentify1.getOrgId();
  368. if (orgId == null) {
  369. continue;
  370. }
  371. if (annexId == null) {
  372. //说明之前没有下载过
  373. EsignHttpResponse response = SignAward.getOrgSeal(orgId, sealId);
  374. JSONObject jsonObject = JSONObject.parseObject(response.getBody());
  375. int code = jsonObject.getIntValue("code");
  376. if (code == 0) {
  377. JSONObject data = jsonObject.getJSONObject("data");
  378. int sealStatus = data.getIntValue("sealStatus");
  379. if (sealStatus == 1) {//印章状态 1已启用,2待审核,3审核不通过,4 挂起
  380. //已启用证明审核通过,下载到数据库
  381. String sealImageDownloadUrl = data.getString("sealImageDownloadUrl");
  382. LocalDate now = LocalDate.now();
  383. String year = Integer.toString(now.getYear());
  384. String month = String.format("%02d", now.getMonthValue());
  385. String day = String.format("%02d", now.getDayOfMonth());
  386. String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
  387. String fileName = UUID.randomUUID().toString().replace("-", "") + ".pdf";
  388. String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
  389. String savePath = "/home/ruoyi/uploadPath/upload/";
  390. // 创建日期目录
  391. File saveFolder = new File(saveFolderPath);
  392. if (!saveFolder.exists()) {
  393. saveFolder.mkdirs();
  394. }
  395. String resultFilePath = saveFolderPath + "/" + fileName;
  396. File resultFilePathFile = new File(resultFilePath);
  397. if (!resultFilePathFile.exists()) {
  398. resultFilePathFile.createNewFile();
  399. }
  400. boolean downLoadFile = FileTransformation.downLoadFileByUrl(sealImageDownloadUrl, resultFilePath);
  401. if (downLoadFile) {
  402. CaseAttach caseAttach = new CaseAttach();
  403. caseAttach.setAnnexType(10); //10代表印章图片
  404. caseAttach.setAnnexPath(savePath);
  405. caseAttach.setAnnexName(saveName);
  406. int i1 = caseAttachMapper.save(caseAttach);
  407. if (i1 > 0) {
  408. //将附件id保存到公章管理表里
  409. Integer annexId1 = caseAttach.getAnnexId();
  410. sealManage1.setAnnexId(annexId1);
  411. sealManage1.setSealStatus(1);
  412. sealManage1.setIsUse(1); //默认使用状态都是未启用
  413. sealManageMapper.updateSealManage(sealManage1);
  414. }
  415. }
  416. }
  417. }
  418. }
  419. }
  420. }
  421. }
  422. } catch (EsignDemoException e) {
  423. e.printStackTrace();
  424. } catch (IOException e) {
  425. e.printStackTrace();
  426. }
  427. }
  428. }