| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- package com.ruoyi.wisdomarbitrate.utils;
-
- import cn.hutool.core.bean.BeanUtil;
- import com.alibaba.fastjson.JSONObject;
- import com.google.gson.Gson;
- import com.google.gson.JsonArray;
- import com.google.gson.JsonObject;
- import com.ruoyi.common.constant.FileTransformation;
- import com.ruoyi.common.core.domain.entity.EsignHttpResponse;
- import com.ruoyi.common.enums.AnnexTypeEnum;
- import com.ruoyi.common.exception.EsignDemoException;
- import com.ruoyi.common.utils.file.SaaSAPIFileUtils;
- import com.ruoyi.system.domain.entity.flow.MsCaseFlow;
- import com.ruoyi.system.mapper.flow.MsCaseFlowMapper;
- import com.ruoyi.wisdomarbitrate.domain.dto.dept.DeptIdentify;
- import com.ruoyi.wisdomarbitrate.domain.dto.dept.SealManage;
- import com.ruoyi.wisdomarbitrate.domain.dto.mscase.SealSignRecord;
- import com.ruoyi.wisdomarbitrate.domain.entity.dept.MsSealSignRecord;
- import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseApplication;
- import com.ruoyi.wisdomarbitrate.domain.entity.mscase.MsCaseAttach;
- import com.ruoyi.wisdomarbitrate.mapper.dept.DeptIdentifyMapper;
- import com.ruoyi.wisdomarbitrate.mapper.dept.MsSealSignRecordMapper;
- import com.ruoyi.wisdomarbitrate.mapper.dept.SealManageMapper;
- import com.ruoyi.wisdomarbitrate.mapper.mscase.MsCaseApplicationMapper;
- import com.ruoyi.wisdomarbitrate.mapper.mscase.MsCaseAttachMapper;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.scheduling.annotation.Scheduled;
- import org.springframework.stereotype.Component;
- import org.springframework.transaction.annotation.Transactional;
-
- import java.io.File;
- import java.io.IOException;
- import java.time.LocalDate;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.UUID;
- import java.util.stream.Collectors;
-
- @Component
- public class FixSelectFlowDetailUtils {
- @Autowired
- private MsCaseAttachMapper caseAttachMapper;
- @Autowired
- private DeptIdentifyMapper deptIdentifyMapper;
- @Autowired
- private SealManageMapper sealManageMapper;
- @Autowired
- private MsSealSignRecordMapper sealSignRecordMapper;
- @Autowired
- MsCaseApplicationMapper msCaseApplicationMapper;
- @Autowired
- MsCaseFlowMapper caseFlowMapper;
- @Autowired
- private MsCaseApplicationMapper caseApplicationMapper;
-
-
-
- /**
- * 定时查询企业认证状态
- *
- * @throws Exception
- */
- @Scheduled(cron = "*/30 * * * * *")
- @Transactional
- public void fixExecuteSelectDeptIndentifyUtils() throws Exception {
- Gson gson = new Gson();
- DeptIdentify deptIdentify = new DeptIdentify();
- List<DeptIdentify> deptIdentifysnew = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
- if (deptIdentifysnew != null && deptIdentifysnew.size() > 0) {
- for (int i = 0; i < deptIdentifysnew.size(); i++) {
- DeptIdentify deptIdentify1 = deptIdentifysnew.get(i);
- Integer identifyStatus = deptIdentify1.getIdentifyStatus();
- if (identifyStatus!=1){
- String authFlowId = deptIdentify1.getAuthFlowId();
- if (authFlowId != null) {
- EsignHttpResponse identifyInfo = SignAward.getDeptIdentifyInfo(deptIdentify1);
- JsonObject identifyInfoJsonObject = gson.fromJson(identifyInfo.getBody(), JsonObject.class);
- int code = identifyInfoJsonObject.get("code").getAsInt();
- if (code == 0) {
- JsonObject identifyInfoData = identifyInfoJsonObject.getAsJsonObject("data");
- int realnameStatus = identifyInfoData.get("realnameStatus").getAsInt();
- if (realnameStatus == 1) {
- String orgId = identifyInfoData.get("orgId").getAsString();
- //查询企业内部印章
- EsignHttpResponse response = SignAward.deptIdentifySealList(orgId);
- JsonObject jsonObject = gson.fromJson(response.getBody(), JsonObject.class);
- int code1 = jsonObject.get("code").getAsInt();
- if (code1 == 0) {
- JsonObject data = jsonObject.getAsJsonObject("data");
- JsonArray seals = data.get("seals").getAsJsonArray();
- if (seals.size() > 0) {
- for (int j = 0; j < seals.size(); j++) {
- //保存印章信息到数据库
- JsonObject asJsonObject = seals.get(j).getAsJsonObject();
- SealManage sealManage = new SealManage();
- String sealName = asJsonObject.get("sealName").toString();
- String sealId = asJsonObject.get("sealId").toString();
- String url = asJsonObject.get("sealImageDownloadUrl").toString();
- LocalDate now = LocalDate.now();
- String year = Integer.toString(now.getYear());
- String month = String.format("%02d", now.getMonthValue());
- String day = String.format("%02d", now.getDayOfMonth());
- String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
- String fileName = UUID.randomUUID().toString().replace("-", "") + ".jpg";
- String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
- String savePath = "/home/ruoyi/uploadPath/upload/";
- // 创建日期目录
- File saveFolder = new File(saveFolderPath);
- if (!saveFolder.exists()) {
- saveFolder.mkdirs();
- }
- String resultFilePath = saveFolderPath + "/" + fileName;
- File resultFilePathFile = new File(resultFilePath);
- if (!resultFilePathFile.exists()) {
- resultFilePathFile.createNewFile();
- }
- String fileDownloadUrlnew = url.substring(1, url.length() - 1);
- boolean downLoadFile = FileTransformation.downLoadFileByUrl(fileDownloadUrlnew, resultFilePath);
- if (downLoadFile) {
- MsCaseAttach caseAttach = new MsCaseAttach();
- caseAttach.setAnnexType(AnnexTypeEnum.SEAL_PICTURE.getCode()); //10代表印章图片
- caseAttach.setAnnexPath(savePath);
- caseAttach.setAnnexName(saveName);
- int i1 = caseAttachMapper.save(caseAttach);
- if (i1 > 0) {
- //将印章信息保存到公章管理表里
- String sealName1 = sealName.substring(1, sealName.length() - 1);
- String sealId1 = sealId.substring(1, sealId.length() - 1);
- Long annexId1 = caseAttach.getAnnexId();
- sealManage.setAnnexId(annexId1);
- sealManage.setSealId(sealId1);
- sealManage.setSealName(sealName1);
- sealManage.setIdentifyId(deptIdentify1.getId());
- sealManage.setSealStatus(1);
- sealManage.setIsUse(1);
- sealManageMapper.insertSealManage(sealManage);
- }
- }
- }
- }
-
- }
- //将orgId保存到数据库里
- deptIdentify1.setOrgId(orgId);
- deptIdentify1.setIdentifyStatus(1);
- deptIdentify1.setIsUse(0); //默认机构为未启用
- int row = deptIdentifyMapper.updateDeptIdentify(deptIdentify1);
- }
- }else {
- deptIdentify1.setIdentifyStatus(2);
- deptIdentifyMapper.updateDeptIdentify(deptIdentify1);
- }
- }
- }
- }
- }
- }
-
-
- /**
- * 定时查询印章审核状态
- */
- @Scheduled(cron = "0/30 * * * * ?")
- @Transactional
- public void searchForInstitutionalSeal() {
- try {
- SealManage sealManage = new SealManage();
- sealManage.setSealStatus(0);
- List<SealManage> sealManageList = sealManageMapper.selectSealList(sealManage);
- if (sealManageList != null && sealManageList.size() > 0) {
- for (SealManage sealManage1 : sealManageList) {
- //查询企业内部印章
- Long annexId = sealManage1.getAnnexId();
- String sealId = sealManage1.getSealId();
- DeptIdentify deptIdentify = new DeptIdentify();
- deptIdentify.setId(sealManage1.getIdentifyId());
- List<DeptIdentify> deptIdentifies = deptIdentifyMapper.selectDeptIdentify(deptIdentify);
- if (deptIdentifies != null && deptIdentifies.size() > 0) {
- DeptIdentify deptIdentify1 = deptIdentifies.get(0);
- String orgId = deptIdentify1.getOrgId();
- if (orgId == null) {
- continue;
- }
- if (annexId == null) {
- //说明之前没有下载过
- EsignHttpResponse response = SignAward.getOrgSeal(orgId, sealId);
- JSONObject jsonObject = JSONObject.parseObject(response.getBody());
- int code = jsonObject.getIntValue("code");
- if (code == 0) {
- JSONObject data = jsonObject.getJSONObject("data");
- int sealStatus = data.getIntValue("sealStatus");
- if (sealStatus == 1) {//印章状态 1已启用,2待审核,3审核不通过,4 挂起
- //已启用证明审核通过,下载到数据库
- String sealImageDownloadUrl = data.getString("sealImageDownloadUrl");
- LocalDate now = LocalDate.now();
- String year = Integer.toString(now.getYear());
- String month = String.format("%02d", now.getMonthValue());
- String day = String.format("%02d", now.getDayOfMonth());
- String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
- String fileName = UUID.randomUUID().toString().replace("-", "") + ".jpg";
- String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
- String savePath = "/home/ruoyi/uploadPath/upload/";
- // 创建日期目录
- File saveFolder = new File(saveFolderPath);
- if (!saveFolder.exists()) {
- saveFolder.mkdirs();
- }
- String resultFilePath = saveFolderPath + "/" + fileName;
- File resultFilePathFile = new File(resultFilePath);
- if (!resultFilePathFile.exists()) {
- resultFilePathFile.createNewFile();
- }
- boolean downLoadFile = FileTransformation.downLoadFileByUrl(sealImageDownloadUrl, resultFilePath);
- if (downLoadFile) {
- MsCaseAttach caseAttach = new MsCaseAttach();
- caseAttach.setAnnexType(AnnexTypeEnum.SEAL_PICTURE.getCode()); //10代表印章图片
- caseAttach.setAnnexPath(savePath);
- caseAttach.setAnnexName(saveName);
- int i1 = caseAttachMapper.save(caseAttach);
- if (i1 > 0) {
- //将附件id保存到公章管理表里
- Long annexId1 = caseAttach.getAnnexId();
- sealManage1.setAnnexId(annexId1);
- sealManage1.setSealStatus(1);
- sealManage1.setIsUse(0);
- sealManageMapper.updateSealManage(sealManage1);
- }
- }
- }
- }
- }
- }
-
- }
- }
- } catch (EsignDemoException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- /*
- 定时查询签署流程详情
- */
- // @Scheduled(cron = "0/10 * * * * ?")
- @Transactional
- public void fixExecuteSelectFlowDetailUtils() {
- Gson gson = new Gson();
-
- List<MsSealSignRecord> sealSignRecords = sealSignRecordMapper.selectSealSignRecordbyStat();
-
- try {
- if (sealSignRecords != null && sealSignRecords.size() > 0) {
- for (int i = 0; i < sealSignRecords.size(); i++) {
- MsSealSignRecord mssealSignRecord = sealSignRecords.get(i);
- SealSignRecord sealSignRecord = new SealSignRecord();
- BeanUtil.copyProperties(mssealSignRecord, sealSignRecord);
- sealSignRecord.setSignFlowid(mssealSignRecord.getSignFlowId());
- EsignHttpResponse signFlowDetail = SignAward.signFlowDetail(sealSignRecord);
- JsonObject signFlowDetailJsonObject = gson.fromJson(signFlowDetail.getBody(), JsonObject.class);
- JsonObject flowDetailData = signFlowDetailJsonObject.getAsJsonObject("data");
- JsonArray signersArray = flowDetailData.get("signers").getAsJsonArray();
- List<Integer> psnsignStatusList = new ArrayList<>();
- Integer psnsignStatus = null;
- Integer orgsignStatus = null;
- for (int j = 0; j < signersArray.size(); j++) {
- JsonObject signerObject = (JsonObject) signersArray.get(j);
-
- if (!(signerObject.get("psnSigner").toString()).equals("null")) {
- JsonObject psnSignerData = signerObject.getAsJsonObject("psnSigner");
- if (psnSignerData != null) {
- psnsignStatus = signerObject.get("signStatus").getAsInt();
- psnsignStatusList.add(psnsignStatus);
- }
- }
- if (!(signerObject.get("orgSigner").toString()).equals("null")) {
- JsonObject orgSignerData = signerObject.getAsJsonObject("orgSigner");
- if (orgSignerData != null) {
- orgsignStatus = signerObject.get("signStatus").getAsInt();
- }
- }
-
- }
-
- List<Integer> psnsignStatusListnew = psnsignStatusList.stream().distinct().collect(Collectors.toList());
-
- MsCaseApplication caseApplicationselect = msCaseApplicationMapper.selectByPrimaryKey(sealSignRecord.getCaseAppliId());
- // Integer isReconci = caseApplicationselect.getIsReconci();
- Integer mediaResult = caseApplicationselect.getMediaResult();
- if(mediaResult!=null){
- if(mediaResult.intValue()==5){
- if (( psnsignStatusListnew.size()==1 && (psnsignStatusListnew.get(0).intValue() == 2))) {
- //更新立案申请状态为待送达
- // MsCaseApplication caseApplicationselect = msCaseApplicationMapper.selectByPrimaryKey(sealSignRecord.getCaseAppliId());
- if ((mssealSignRecord.getSignFlowStatus() != null) && (mssealSignRecord.getSignFlowStatus().intValue() == 1)) {
- MsCaseFlow nextFlow = caseFlowMapper.nextFlow1(caseApplicationselect.getCaseFlowId().intValue());
- MsCaseApplication application = new MsCaseApplication();
- application.setId(caseApplicationselect.getId());
- application.setCaseFlowId(nextFlow.getId());
- application.setCaseStatusName(nextFlow.getCaseStatusName());
- caseApplicationMapper.updateByPrimaryKeySelective(application);
-
- //修改"签署用印记录表"的状态为完成
- mssealSignRecord.setSignFlowStatus(3);
- sealSignRecordMapper.updateByPrimaryKeySelective(mssealSignRecord);
-
- //下载审核完成的调解书
- String signFlowId = sealSignRecord.getSignFlowid();
- EsignHttpResponse fileDownload = SaaSAPIFileUtils.fileDownloadUrl(signFlowId);
- JsonObject fileDownloadJsonObject = gson.fromJson(fileDownload.getBody(), JsonObject.class);
- JsonObject fileDownloadData = fileDownloadJsonObject.getAsJsonObject("data");
- JsonArray filesArray = fileDownloadData.get("files").getAsJsonArray();
- if (filesArray != null && filesArray.size() > 0) {
- JsonObject fileObject = (JsonObject) filesArray.get(0);
- String fileDownloadUrl = fileObject.get("downloadUrl").toString();
- LocalDate now = LocalDate.now();
- String year = Integer.toString(now.getYear());
- String month = String.format("%02d", now.getMonthValue());
- String day = String.format("%02d", now.getDayOfMonth());
- String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
- String fileName = UUID.randomUUID().toString().replace("-", "") + ".pdf";
- // String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
- // String savePath = "/home/ruoyi/uploadPath/upload/";
- String saveName = fileName;
- String savePath = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
-
- // 创建日期目录
- File saveFolder = new File(saveFolderPath);
- if (!saveFolder.exists()) {
- saveFolder.mkdirs();
- }
- String resultFilePath = saveFolderPath + "/" + fileName;
- File resultFilePathFile = new File(resultFilePath);
- if (!resultFilePathFile.exists()) {
- resultFilePathFile.createNewFile();
- }
-
- String fileDownloadUrlnew = fileDownloadUrl.substring(1, fileDownloadUrl.length() - 1);
- boolean downLoadFile = FileTransformation.downLoadFileByUrl(fileDownloadUrlnew, resultFilePath);
- if (downLoadFile) {
- Long caseAppliId = sealSignRecord.getCaseAppliId();
- MsCaseAttach caseAttach = new MsCaseAttach();
- caseAttach.setCaseAppliId(caseAppliId);
- caseAttach.setAnnexType(7);
- caseAttach.setAnnexPath(savePath);
- caseAttach.setAnnexName(saveName);
- caseAttachMapper.updateCaseAttachBycaseid(caseAttach);
- }
-
- }
- }
- }
- }else if(mediaResult.intValue()==1){
- if (( psnsignStatusListnew.size()==1 && (psnsignStatusListnew.get(0).intValue() == 2)) && (orgsignStatus.intValue() == 1)) {
- //更新立案申请状态为待用印
- // MsCaseApplication caseApplicationselect = msCaseApplicationMapper.selectByPrimaryKey(sealSignRecord.getCaseAppliId());
- if ((mssealSignRecord.getSignFlowStatus() != null) && (mssealSignRecord.getSignFlowStatus().intValue() == 1)) {
- // 根据流程id查找下一个流程节点
- MsCaseFlow nextFlow = caseFlowMapper.nextFlow(caseApplicationselect.getCaseFlowId().intValue());
- MsCaseApplication application = new MsCaseApplication();
- application.setId(caseApplicationselect.getId());
- application.setCaseFlowId(nextFlow.getId());
- application.setCaseStatusName(nextFlow.getCaseStatusName());
- caseApplicationMapper.updateByPrimaryKeySelective(application);
-
- //修改"签署用印记录表"的状态为待用印
- mssealSignRecord.setSignFlowStatus(2);
- sealSignRecordMapper.updateByPrimaryKeySelective(mssealSignRecord);
- }
- }
- if (( psnsignStatusListnew.size()==1 && (psnsignStatusListnew.get(0).intValue() == 2)) && (orgsignStatus.intValue() == 2)) {
- //更新立案申请状态为待送达
- // MsCaseApplication caseApplicationselect = msCaseApplicationMapper.selectByPrimaryKey(sealSignRecord.getCaseAppliId());
-
- if ((mssealSignRecord.getSignFlowStatus() != null) && (mssealSignRecord.getSignFlowStatus().intValue() == 2)) {
- //修改"签署用印记录表"的状态为签署完成
- mssealSignRecord.setSignFlowStatus(3);
- sealSignRecordMapper.updateByPrimaryKeySelective(mssealSignRecord);
-
- // 根据流程id查找下一个流程节点
- MsCaseFlow nextFlow = caseFlowMapper.nextFlow(caseApplicationselect.getCaseFlowId().intValue());
- MsCaseApplication application = new MsCaseApplication();
- application.setId(caseApplicationselect.getId());
- application.setCaseFlowId(nextFlow.getId());
- application.setCaseStatusName(nextFlow.getCaseStatusName());
- caseApplicationMapper.updateByPrimaryKeySelective(application);
-
- //下载审核完成的调解书
- String signFlowId = sealSignRecord.getSignFlowid();
- EsignHttpResponse fileDownload = SaaSAPIFileUtils.fileDownloadUrl(signFlowId);
- JsonObject fileDownloadJsonObject = gson.fromJson(fileDownload.getBody(), JsonObject.class);
- JsonObject fileDownloadData = fileDownloadJsonObject.getAsJsonObject("data");
- JsonArray filesArray = fileDownloadData.get("files").getAsJsonArray();
- if (filesArray != null && filesArray.size() > 0) {
- JsonObject fileObject = (JsonObject) filesArray.get(0);
- String fileDownloadUrl = fileObject.get("downloadUrl").toString();
- LocalDate now = LocalDate.now();
- String year = Integer.toString(now.getYear());
- String month = String.format("%02d", now.getMonthValue());
- String day = String.format("%02d", now.getDayOfMonth());
- String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
- String fileName = UUID.randomUUID().toString().replace("-", "") + ".pdf";
- // String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
- // String savePath = "/home/ruoyi/uploadPath/upload/";
- String saveName = fileName;
- String savePath = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
-
- // 创建日期目录
- File saveFolder = new File(saveFolderPath);
- if (!saveFolder.exists()) {
- saveFolder.mkdirs();
- }
- String resultFilePath = saveFolderPath + "/" + fileName;
- File resultFilePathFile = new File(resultFilePath);
- if (!resultFilePathFile.exists()) {
- resultFilePathFile.createNewFile();
- }
-
- String fileDownloadUrlnew = fileDownloadUrl.substring(1, fileDownloadUrl.length() - 1);
- boolean downLoadFile = FileTransformation.downLoadFileByUrl(fileDownloadUrlnew, resultFilePath);
- if (downLoadFile) {
- Long caseAppliId = sealSignRecord.getCaseAppliId();
- MsCaseAttach caseAttach = new MsCaseAttach();
- caseAttach.setCaseAppliId(caseAppliId);
- caseAttach.setAnnexType(7);
- caseAttach.setAnnexPath(savePath);
- caseAttach.setAnnexName(saveName);
- caseAttachMapper.updateCaseAttachBycaseid(caseAttach);
- }
-
- }
- }
- }
-
- }
- }
- }
-
- }
- } catch (EsignDemoException | IOException e) {
- e.printStackTrace();
- }
-
- }
-
-
-
-
-
- }
-
|