|
@@ -0,0 +1,340 @@
|
|
|
+package com.jeeplus.modules.ruralprojectrecords.service;
|
|
|
+
|
|
|
+import com.google.common.collect.Lists;
|
|
|
+import com.jeeplus.common.config.Global;
|
|
|
+import com.jeeplus.common.oss.OSSClientUtil;
|
|
|
+import com.jeeplus.common.utils.StringUtils;
|
|
|
+import com.jeeplus.modules.projectcontentinfo.entity.ProjectReportData;
|
|
|
+import com.jeeplus.modules.projectcontentinfo.service.ProjectReportDataService;
|
|
|
+import com.jeeplus.modules.ruralprojectrecords.entity.RuralProjectRecords;
|
|
|
+import com.jeeplus.modules.sys.entity.User;
|
|
|
+import com.jeeplus.modules.sys.service.WorkattachmentService;
|
|
|
+import com.jeeplus.modules.sys.utils.UserUtils;
|
|
|
+import com.jeeplus.modules.tools.utils.SignaturePostUtil;
|
|
|
+import com.jeeplus.modules.utils.SftpClientUtil;
|
|
|
+import com.jeeplus.modules.workclientinfo.entity.WorkClientAttachment;
|
|
|
+import org.activiti.engine.HistoryService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 项目签章老数据信息文件下载上传阿里临时功能
|
|
|
+ * @author 徐滕
|
|
|
+ * @version 2021-11-04
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Transactional(readOnly = true)
|
|
|
+public class RuralProjectSignatureOldMessageDisposeService {
|
|
|
+
|
|
|
+
|
|
|
+ private final static String directory = Global.getConfig("remoteServer.directory");
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RuralProjectRecordsService projectRecordsService;
|
|
|
+ @Autowired
|
|
|
+ private ProjectReportDataService projectReportDataService;
|
|
|
+ @Autowired
|
|
|
+ protected HistoryService historyService;
|
|
|
+ @Autowired
|
|
|
+ private WorkattachmentService workattachmentService;
|
|
|
+
|
|
|
+
|
|
|
+ private static final String HTTPTOP = Global.getConfig("signature_http_top");
|
|
|
+
|
|
|
+ private final static String apptoken = Global.getConfig("apptoken");
|
|
|
+ private final static String appsecret = Global.getConfig("appsecret");
|
|
|
+ private final static String signature = Global.getConfig("signature");
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 签章文件处理
|
|
|
+ * @param type 1:审定单;2:报告签章;
|
|
|
+ * @param count
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public Map<String,Object> ossUploading(Integer type,Integer count){
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ List<String> projectNumber = Lists.newArrayList();
|
|
|
+ switch (type){
|
|
|
+ case 1:
|
|
|
+ map.put("success",true);
|
|
|
+ map.put("type",type);
|
|
|
+ //查询审定单签章没有对应url下载路径的信息
|
|
|
+ // count为处理的项目信息条数
|
|
|
+ List<ProjectReportData> projectReportDataList = projectReportDataService.getProjectReportDataSignatureByCount(count);
|
|
|
+ for (ProjectReportData info: projectReportDataList) {
|
|
|
+ try {
|
|
|
+ downLoadApprovalAttach(info.getSignatureContractId());
|
|
|
+ projectNumber.add(info.getNumber());
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }finally {
|
|
|
+ //修改签章对应信息文件
|
|
|
+ info.setSignatureUrlFlag(1);
|
|
|
+ projectReportDataService.updateSignatureInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(projectNumber.size()>0){
|
|
|
+ String numbersStr = String.join(",", projectNumber);
|
|
|
+ map.put("reportNumber","审定单签章已处理" + projectNumber.size() + " 条。项目报告号为:" +numbersStr);
|
|
|
+ }else{
|
|
|
+ map.put("reportNumber","这次没有处理审定单签章信息");
|
|
|
+ }
|
|
|
+ //查询剩余未处理的项目数量
|
|
|
+ Integer approvalCount = projectReportDataService.approvalSignaturesCount();
|
|
|
+ map.put("remainingCount","审定单签章未处理的项目还有:" +approvalCount + " 条");
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ map.put("success",true);
|
|
|
+ map.put("type",type);
|
|
|
+ //查询报告签章没有对应url下载路径的信息
|
|
|
+ // count为处理的项目信息条数
|
|
|
+ List<RuralProjectRecords> ruralProjectRecordsList = projectRecordsService.getProjectRecordsSignatureByCount(count);
|
|
|
+ for (RuralProjectRecords info: ruralProjectRecordsList) {
|
|
|
+ //进行文件处理
|
|
|
+ try {
|
|
|
+ downLoadReportAttach(info.getReportSignatureContractId());
|
|
|
+ projectNumber.add(info.getProjectReportNumber());
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }finally {
|
|
|
+ info.setReportSignatureUrlFlag(1);
|
|
|
+ //修改签章对应信息文件
|
|
|
+ projectReportDataService.updateReportSignatureInfo(info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(projectNumber.size()>0){
|
|
|
+ String numbersStr = String.join(",", projectNumber);
|
|
|
+ map.put("reportNumber","报告签章已处理" + projectNumber.size() + " 条。项目报告号为:" +numbersStr);
|
|
|
+ }else{
|
|
|
+ map.put("reportNumber","这次没有处理报告签章信息");
|
|
|
+ }
|
|
|
+ //查询剩余未处理的项目数量
|
|
|
+ Integer recordsCount = projectRecordsService.recordSignaturesCount();
|
|
|
+ map.put("remainingCount","报告签章未处理的项目还有:" +recordsCount + " 条。");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载审定单附件
|
|
|
+ */
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public void downLoadApprovalAttach(String contractId) {
|
|
|
+ //根据contractId查询对应的报告信息
|
|
|
+ ProjectReportData projectReportData = projectReportDataService.getProjectReportDataByContractId(contractId);
|
|
|
+ //根据contractId查询对应的报告信息
|
|
|
+ RuralProjectRecords ruralProjectRecords = projectRecordsService.get(projectReportData.getProject().getId());
|
|
|
+ if(null == projectReportData || StringUtils.isBlank(projectReportData.getSignatureContractId())){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //根据contractId将文件下载下来 并上传到阿里云服务种
|
|
|
+ //添加请求头
|
|
|
+ Map<String,String> requestHeaderMap = new HashMap<>();
|
|
|
+ requestHeaderMap.put("x-qys-accesstoken", apptoken);
|
|
|
+ requestHeaderMap.put("x-qys-signature", signature);
|
|
|
+ requestHeaderMap.put("x-qys-timestamp", "0");
|
|
|
+ Map<String, Object> map = SignaturePostUtil.downloadZipDesignated(HTTPTOP + "/contract/download?contractId="+contractId,requestHeaderMap,projectReportData.getSignatureFileName()+".zip","");
|
|
|
+ //获取处理结果,若为true 则进行文件上传阿里云操作并写入数据库,否则不进行处理
|
|
|
+ Boolean bool = (Boolean) map.get("success");
|
|
|
+ if(bool){
|
|
|
+ //将文件上传到阿里云中
|
|
|
+ String fileName = (String) map.get("fileName");
|
|
|
+ String filePath = (String) map.get("filePath");
|
|
|
+ Map<String, Object> loadMap = oosLoad(filePath + fileName, "approval");
|
|
|
+ //判定是否上传成功
|
|
|
+ Boolean loadBool = (Boolean) loadMap.get("success");
|
|
|
+ if(loadBool){
|
|
|
+ //签章完成则进行数据的保存
|
|
|
+ String loadFilePath = (String) loadMap.get("filePath");
|
|
|
+ String fileLength = (String) loadMap.get("fileLength");
|
|
|
+ projectReportData.setSignatureUrl(loadFilePath);
|
|
|
+
|
|
|
+ //将文件存储到对应的档案信息中的“咨询报告书正文”中
|
|
|
+ WorkClientAttachment attchment = new WorkClientAttachment();
|
|
|
+ attchment.setProjectId(ruralProjectRecords.getId());
|
|
|
+ attchment.setAttachmentId("058ef76b128a4d629acb039017f19161");
|
|
|
+ attchment.setDivIdType("signature");
|
|
|
+ //删除原有的数据信息
|
|
|
+ workattachmentService.deleteByAttachIdAndProject(attchment);
|
|
|
+ //查询原有文件的数据量
|
|
|
+ Integer fileCount = workattachmentService.getAttachmentCountByAttachmentIdAndProjectId(attchment);
|
|
|
+ if( null == fileCount){
|
|
|
+ fileCount = 0;
|
|
|
+ }
|
|
|
+ fileCount = fileCount + 1;
|
|
|
+ String fileSuffix = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
|
|
|
+ attchment.setFileSize(fileLength);
|
|
|
+ User user = UserUtils.get(ruralProjectRecords.getCreateBy().getId());
|
|
|
+ attchment.setCreateBy(user);
|
|
|
+ attchment.setUpdateBy(user);
|
|
|
+ attchment.setUrl(loadFilePath);
|
|
|
+ attchment.setType(fileSuffix);
|
|
|
+ attchment.setAttachmentUser(ruralProjectRecords.getCreateBy().getId());
|
|
|
+ attchment.setAttachmentName(fileName);
|
|
|
+ attchment.setAttachmentFlag("100");
|
|
|
+ attchment.setSort(fileCount.toString());
|
|
|
+ workattachmentService.insertOnWorkClientAttachment(attchment);
|
|
|
+ //修改签章对应信息文件
|
|
|
+ projectReportDataService.updateSignatureInfo(projectReportData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载报告附件
|
|
|
+ */
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public void downLoadReportAttach(String contractId) {
|
|
|
+ //根据contractId查询对应的报告信息
|
|
|
+ RuralProjectRecords ruralProjectRecords = projectRecordsService.getProjectRecordsByContractId(contractId);
|
|
|
+ if(null == ruralProjectRecords || StringUtils.isBlank(ruralProjectRecords.getReportSignatureContractId())){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //根据contractId将文件下载下来 并上传到阿里云服务种
|
|
|
+ //添加请求头
|
|
|
+ Map<String,String> requestHeaderMap = new HashMap<>();
|
|
|
+ requestHeaderMap.put("x-qys-accesstoken", apptoken);
|
|
|
+ requestHeaderMap.put("x-qys-signature", signature);
|
|
|
+ requestHeaderMap.put("x-qys-timestamp", "0");
|
|
|
+ Map<String, Object> map = SignaturePostUtil.downloadZipDesignated(HTTPTOP + "/contract/download?contractId=" + contractId, requestHeaderMap, ruralProjectRecords.getReportSignatureFileName() + ".zip", "");
|
|
|
+ //获取处理结果,若为true 则进行文件上传阿里云操作并写入数据库,否则不进行处理
|
|
|
+ Boolean bool = (Boolean) map.get("success");
|
|
|
+ if(bool){
|
|
|
+ //将文件上传到阿里云中
|
|
|
+ String fileName = (String) map.get("fileName");
|
|
|
+ String filePath = (String) map.get("filePath");
|
|
|
+ Map<String, Object> loadMap = oosLoad(filePath + fileName, "report");
|
|
|
+ //判定是否上传成功
|
|
|
+ Boolean loadBool = (Boolean) loadMap.get("success");
|
|
|
+ if(loadBool){
|
|
|
+ //签章完成则进行数据的保存
|
|
|
+ String loadFilePath = (String) loadMap.get("filePath");
|
|
|
+ String fileLength = (String) loadMap.get("fileLength");
|
|
|
+ ruralProjectRecords.setReportSignatureUrl(loadFilePath);
|
|
|
+
|
|
|
+ //将文件存储到对应的档案信息中的“咨询报告书正文”中
|
|
|
+ WorkClientAttachment attchment = new WorkClientAttachment();
|
|
|
+ attchment.setProjectId(ruralProjectRecords.getId());
|
|
|
+ attchment.setAttachmentId("6c68d29ea00e4cdb8cf17fb54ee30f0f");
|
|
|
+ attchment.setDivIdType("signature");
|
|
|
+ //删除原有的数据信息
|
|
|
+ workattachmentService.deleteByAttachIdAndProject(attchment);
|
|
|
+ //查询原有文件的数据量
|
|
|
+ Integer fileCount = workattachmentService.getAttachmentCountByAttachmentIdAndProjectId(attchment);
|
|
|
+ if( null == fileCount){
|
|
|
+ fileCount = 0;
|
|
|
+ }
|
|
|
+ fileCount = fileCount + 1;
|
|
|
+ String fileSuffix = fileName.substring(fileName.lastIndexOf(".")+1,fileName.length());
|
|
|
+ attchment.setFileSize(fileLength);
|
|
|
+ User user = UserUtils.get(ruralProjectRecords.getCreateBy().getId());
|
|
|
+ attchment.setCreateBy(user);
|
|
|
+ attchment.setUpdateBy(user);
|
|
|
+ attchment.setUrl(loadFilePath);
|
|
|
+ attchment.setType(fileSuffix);
|
|
|
+ attchment.setAttachmentUser(ruralProjectRecords.getCreateBy().getId());
|
|
|
+ attchment.setAttachmentName(fileName);
|
|
|
+ attchment.setAttachmentFlag("100");
|
|
|
+ attchment.setSort(fileCount.toString());
|
|
|
+ workattachmentService.insertOnWorkClientAttachment(attchment);
|
|
|
+ //修改签章对应信息文件
|
|
|
+ projectReportDataService.updateReportSignatureInfo(ruralProjectRecords);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 文件上传阿里云
|
|
|
+ * @param filePath 文件路径
|
|
|
+ * @param storeAs 存储文件夹名称
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public Map<String,Object> oosLoad(String filePath,String storeAs){
|
|
|
+
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ map.put("success",false);
|
|
|
+ File mfile = new File(filePath);
|
|
|
+ SftpClientUtil sftpClientUtil = new SftpClientUtil();
|
|
|
+ //File转MultipartFile文件
|
|
|
+ MultipartFile file = sftpClientUtil.transformFile(mfile);
|
|
|
+ try {
|
|
|
+ String filepath = "";
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ // 文件保存路径
|
|
|
+
|
|
|
+ String realPath =directory.replace("/","")+datePath()+"/signature/"+storeAs+"/";
|
|
|
+ OSSClientUtil ossUtil = new OSSClientUtil();
|
|
|
+ String newName = file.getName();
|
|
|
+
|
|
|
+ try {
|
|
|
+ ossUtil.uploadFile2OSS(file.getInputStream(),realPath,newName);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ filepath = "/" + realPath + newName;
|
|
|
+ map.put("filePath",filepath);
|
|
|
+ long length = mfile.length();
|
|
|
+ map.put("fileLength", String.valueOf(length));
|
|
|
+ map.put("success",true);
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }finally {
|
|
|
+ mfile.delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String datePath(){
|
|
|
+
|
|
|
+ Calendar date = Calendar.getInstance();
|
|
|
+ String year = String.valueOf(date.get(Calendar.YEAR));
|
|
|
+ String month = String.valueOf(date.get(Calendar.MONTH)+1);
|
|
|
+ String day = String.valueOf(date.get(Calendar.DAY_OF_MONTH));
|
|
|
+ String path = "/"+year+"/"+month+"/"+day;
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载审定内附件
|
|
|
+ */
|
|
|
+ @Transactional(readOnly = false)
|
|
|
+ public void downLoadJudgementAttach(String contractId) {
|
|
|
+ //根据contractId查询对应的报告信息
|
|
|
+ RuralProjectRecords ruralProjectRecords = projectRecordsService.getJudgementProjectRecordsByContractId(contractId);
|
|
|
+ if(null == ruralProjectRecords || StringUtils.isBlank(ruralProjectRecords.getQualitySignatureContractId())){
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ //根据contractId将文件下载下来 并上传到阿里云服务种
|
|
|
+ //添加请求头
|
|
|
+ Map<String,String> requestHeaderMap = new HashMap<>();
|
|
|
+ requestHeaderMap.put("x-qys-accesstoken", apptoken);
|
|
|
+ requestHeaderMap.put("x-qys-signature", signature);
|
|
|
+ requestHeaderMap.put("x-qys-timestamp", "0");
|
|
|
+ Map<String, Object> map = SignaturePostUtil.downloadZipDesignated(HTTPTOP + "/contract/download?contractId="+contractId,requestHeaderMap,ruralProjectRecords.getQualitySignatureFileName()+".zip","");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|