diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/config/BeanConfig.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/config/BeanConfig.java index 1dc5890..f176489 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/config/BeanConfig.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/config/BeanConfig.java @@ -17,12 +17,14 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.web.client.RestTemplate; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; /** @@ -106,4 +108,15 @@ public class BeanConfig { .setRetryHandler(new DefaultHttpRequestRetryHandler(2, true)) .build(); } + + @Bean + public ThreadPoolTaskExecutor getThreadPoolTaskExecutor(){ + ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); + threadPoolTaskExecutor.setCorePoolSize(5); + threadPoolTaskExecutor.setKeepAliveSeconds(200); + threadPoolTaskExecutor.setMaxPoolSize(10); + threadPoolTaskExecutor.setQueueCapacity(20); + threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); + return threadPoolTaskExecutor; + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java index a8e2e63..9c3d6ae 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/gov/manage/GovProjectCollectionManage.java @@ -34,15 +34,21 @@ import com.ningdatech.pmapi.wps.manage.WpsConvertManage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.lang.reflect.Field; import java.time.LocalDateTime; import java.util.*; @@ -80,6 +86,8 @@ public class GovProjectCollectionManage { private final WpsConvertManage wpsConvertManage; + private final ThreadPoolTaskExecutor threadPoolTaskExecutor; + @Value("${project.push-url}") private String pushUrl; @@ -89,6 +97,9 @@ public class GovProjectCollectionManage { @Value("${project.delete-all-url}") private String deleteAllUrl; + @Value("${spring.profiles.active}") + private String active; + public List dictionary(String type) { List dictionaries = dictionaryService.list(Wrappers.lambdaQuery(GovProjectDictionary.class) @@ -430,7 +441,7 @@ public class GovProjectCollectionManage { saveApply.setUpdateBy(user.getUsername()); saveApply.setUpdateOn(LocalDateTime.now()); if(projectApplyService.saveOrUpdate(saveApply)){ - uploadFileToProvincialOss(apply,oldApply,saveApply); + threadPoolTaskExecutor.execute(() -> uploadFileToProvincialOssApply(apply,oldApply,saveApply)); } } @@ -454,7 +465,9 @@ public class GovProjectCollectionManage { saveApprove.setAreaCode(RegionConst.RC_LS); saveApprove.setUpdateBy(user.getUsername()); saveApprove.setUpdateOn(LocalDateTime.now()); - approveService.saveOrUpdate(saveApprove); + if(approveService.saveOrUpdate(saveApprove)){ + threadPoolTaskExecutor.execute(() -> uploadFileToProvincialOssApprove(approve,oldApprove,saveApprove)); + } } // 4.保存 建设项目 实施信息 @@ -478,7 +491,9 @@ public class GovProjectCollectionManage { saveCimplement.setBizTime(LocalDateTime.now()); saveCimplement.setUpdateBy(user.getUsername()); saveCimplement.setUpdateOn(LocalDateTime.now()); - cimplementService.saveOrUpdate(saveCimplement); + if(cimplementService.saveOrUpdate(saveCimplement)){ + threadPoolTaskExecutor.execute(() -> uploadFileToProvincialOssCimplement(cimplement,oldCimplement,saveCimplement)); + } } // 5.保存 运维项目 实施信息 @@ -793,45 +808,93 @@ public class GovProjectCollectionManage { * @param apply * @param oldApply */ - private void uploadFileToProvincialOss(GovBizProjectApplyDTO apply, + private void uploadFileToProvincialOssApply(GovBizProjectApplyDTO apply, GovBizProjectApply oldApply,GovBizProjectApply saveApply) { if(checkFieldHas(apply.getBaseProjBasisFile(),oldApply,"baseProjBasisFile")){ - String[] baseProjBasisFileArr = apply.getBaseProjBasisFile().split(";"); - StringJoiner sj = new StringJoiner(";"); - for(String baseProjBasisFile : baseProjBasisFileArr){ - JSONArray fileArray = JSON.parseArray(baseProjBasisFile); - fileArray.forEach(j -> { - JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(j)); - byte[] btyes = wpsConvertManage.downloadToPdfStream(jsonObject.getLong("id")); - String suffix = jsonObject.getString("suffix"); - String originalFileName = jsonObject.getString("originalFileName"); - String pdfName = originalFileName.replace(StrPool.DOT + suffix, ".pdf"); - String oss = ProvincialManage.uploadToOss(btyes, pdfName); - sj.add(oss); - }); - } + StringJoiner sj = convertAndUpload(apply.getBaseProjBasisFile()); saveApply.setBaseProjBasisFilePdf(sj.toString()); } + if(checkFieldHas(apply.getBaseProjApplyFile(),oldApply,"baseProjApplyFile")){ + StringJoiner sj = convertAndUpload(apply.getBaseProjApplyFile()); + saveApply.setBaseProjApplyFilePdf(sj.toString()); + } + if(checkFieldHas(apply.getBaseOperatMaintenFile(),oldApply,"baseOperatMaintenFile")){ + StringJoiner sj = convertAndUpload(apply.getBaseOperatMaintenFile()); + saveApply.setBaseOperatMaintenFilePdf(sj.toString()); + } + if(checkFieldHas(apply.getBaseResearchReportFile(),oldApply,"baseResearchReportFile")){ + StringJoiner sj = convertAndUpload(apply.getBaseResearchReportFile()); + saveApply.setBaseResearchReportFilePdf(sj.toString()); + } + if(checkFieldHas(apply.getBaseProjOtherFile(),oldApply,"baseProjOtherFile")){ + StringJoiner sj = convertAndUpload(apply.getBaseProjOtherFile()); + saveApply.setBaseProjOtherFilePdf(sj.toString()); + } projectApplyService.updateById(saveApply); } - private Boolean checkFieldHas(String field,GovBizProjectApply oldApply,String fieldName){ + private void uploadFileToProvincialOssApprove(GovBizProjectApproveDTO approve, GovBizProjectApprove oldApprove, GovBizProjectApprove saveApprove) { + if(checkFieldHas(approve.getApprovalFile(),oldApprove,"approvalFile")){ + StringJoiner sj = convertAndUpload(approve.getApprovalFile()); + saveApprove.setApprovalFilePdf(sj.toString()); + } + if(checkFieldHas(approve.getBaseReviewCommentsFile(),oldApprove,"baseReviewCommentsFile")){ + StringJoiner sj = convertAndUpload(approve.getBaseReviewCommentsFile()); + saveApprove.setBaseReviewCommentsFilePdf(sj.toString()); + } + if(checkFieldHas(approve.getPreliminaryDesignFile(),oldApprove,"preliminaryDesignFile")){ + StringJoiner sj = convertAndUpload(approve.getPreliminaryDesignFile()); + saveApprove.setPreliminaryDesignFilePdf(sj.toString()); + } + approveService.updateById(saveApprove); + } + + private void uploadFileToProvincialOssCimplement(GovBizProjectCimplementDTO cimplement, GovBizProjectCimplement oldCimplement, GovBizProjectCimplement saveCimplement) { + if(checkFieldHas(cimplement.getBaseChanFile(),oldCimplement,"baseChanFile")){ + StringJoiner sj = convertAndUpload(cimplement.getBaseChanFile()); + saveCimplement.setBaseChanFilePdf(sj.toString()); + } + cimplementService.updateById(saveCimplement); + } + + private StringJoiner convertAndUpload(String baseProjBasisFile) { + String[] baseProjBasisFileArr = baseProjBasisFile.split(";"); + StringJoiner sj = new StringJoiner(";"); + for(String bpb : baseProjBasisFileArr){ + JSONArray fileArray = JSON.parseArray(bpb); + fileArray.forEach(j -> { + JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(j)); + byte[] btyes = wpsConvertManage.downloadToPdfStream(jsonObject.getLong("id")); + String suffix = jsonObject.getString("suffix"); + String originalFileName = jsonObject.getString("originalFileName"); + if(!BizConst.DEV.equals(active)){ + originalFileName = originalFileName.replace(StrPool.DOT + suffix, ".pdf"); + } +// upload(btyes,"/temp",originalFileName); + String oss = ProvincialManage.uploadToOss(btyes, originalFileName); + sj.add(oss); + }); + } + return sj; + } + + private Boolean checkFieldHas(String field, Object record, String fieldName){ if(StringUtils.isBlank(field)){ return Boolean.FALSE; } //如果没有老值 - if(Objects.isNull(oldApply)){ + if(Objects.isNull(record)){ return Boolean.TRUE; } //和老值做个对比 不一样则true - Class clazz = oldApply.getClass(); + Class clazz = record.getClass(); String oldFiled = StringUtils.EMPTY; try { Field fieldDeclared = clazz.getDeclaredField(fieldName); fieldDeclared.setAccessible(Boolean.TRUE); - oldFiled = Objects.nonNull(fieldDeclared.get(oldApply)) ? String.valueOf(fieldDeclared.get(oldApply)) : null; + oldFiled = Objects.nonNull(fieldDeclared.get(record)) ? String.valueOf(fieldDeclared.get(record)) : null; } catch (NoSuchFieldException e) { log.error("转换PDF文件出错" + e); } catch (IllegalAccessException e) { @@ -844,4 +907,24 @@ public class GovProjectCollectionManage { return Boolean.FALSE; } + + /** + * @param bytes byte数组 + * @param fileRoute 文件路径 + * @param fileName 文件名 + */ + public static void upload(byte[] bytes,String fileRoute,String fileName) { + try { + File directory=new File(fileRoute); + if (!directory.exists()){ + directory.mkdirs(); + } + File file = new File(directory, fileName); + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); + bos.write(bytes); + bos.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectApply.java b/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectApply.java index b5ec5d6..e2fc162 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectApply.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectApply.java @@ -152,4 +152,17 @@ public class GovBizProjectApply implements Serializable { @ApiModelProperty("立项依据材料PDF版") private String baseProjBasisFilePdf; + + @ApiModelProperty("项目申报书PDF版") + private String baseProjApplyFilePdf; + + @ApiModelProperty("运维方案PDF版") + private String baseOperatMaintenFilePdf; + + @ApiModelProperty("可研报告PDF版") + private String baseResearchReportFilePdf; + + @ApiModelProperty("其它文件PDF版") + private String baseProjOtherFilePdf; + } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectApprove.java b/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectApprove.java index 4542fb7..6230edb 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectApprove.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectApprove.java @@ -36,7 +36,7 @@ public class GovBizProjectApprove implements Serializable { @ApiModelProperty("基本项目名称") private String baseProjName; - @ApiModelProperty("'发改项目代码'") + @ApiModelProperty("发改项目代码") private String baseDevelopCode; @ApiModelProperty("'财政项目代码'") @@ -54,7 +54,7 @@ public class GovBizProjectApprove implements Serializable { @ApiModelProperty("建议总投资") private BigDecimal baseExpertTotalMoney; - @ApiModelProperty("'建议年度预算'") + @ApiModelProperty("建议年度预算") private BigDecimal baseExpertYearMoney; @ApiModelProperty("立项批复文件") @@ -99,4 +99,13 @@ public class GovBizProjectApprove implements Serializable { @ApiModelProperty("最后修改人") private String updateBy; + + @ApiModelProperty("立项批复文件") + private String approvalFilePdf; + + @ApiModelProperty("评审意见附件PDF") + private String baseReviewCommentsFilePdf; + + @ApiModelProperty("初步设计方案批复函PDF") + private String preliminaryDesignFilePdf; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectCimplement.java b/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectCimplement.java index 6154c1f..428011e 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectCimplement.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/gov/model/entity/GovBizProjectCimplement.java @@ -115,4 +115,7 @@ public class GovBizProjectCimplement implements Serializable { @ApiModelProperty("最后修改人") private String updateBy; + + @ApiModelProperty("生产批复文件PDF") + private String baseChanFilePdf; }