@@ -17,12 +17,14 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | |||||
import org.springframework.http.converter.HttpMessageConverter; | import org.springframework.http.converter.HttpMessageConverter; | ||||
import org.springframework.http.converter.StringHttpMessageConverter; | import org.springframework.http.converter.StringHttpMessageConverter; | ||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; | ||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |||||
import org.springframework.web.client.RestTemplate; | import org.springframework.web.client.RestTemplate; | ||||
import java.nio.charset.StandardCharsets; | import java.nio.charset.StandardCharsets; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.concurrent.ThreadPoolExecutor; | |||||
import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||
/** | /** | ||||
@@ -106,4 +108,15 @@ public class BeanConfig { | |||||
.setRetryHandler(new DefaultHttpRequestRetryHandler(2, true)) | .setRetryHandler(new DefaultHttpRequestRetryHandler(2, true)) | ||||
.build(); | .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; | |||||
} | |||||
} | } |
@@ -84,6 +84,11 @@ public class DingInfoPullController { | |||||
organizationBatchGetTask.batchGetOrganizationTask(); | organizationBatchGetTask.batchGetOrganizationTask(); | ||||
} | } | ||||
@GetMapping("/organization/{orgCode}") | |||||
public void organizationGetSubs(@PathVariable String orgCode) { | |||||
organizationBatchGetTask.organizationGetSubs(orgCode); | |||||
} | |||||
@GetMapping("/employeeByRegionCode/{regionCode}") | @GetMapping("/employeeByRegionCode/{regionCode}") | ||||
public void employeeBatchGetByRegionCode(@PathVariable String regionCode) { | public void employeeBatchGetByRegionCode(@PathVariable String regionCode) { | ||||
employeeBatchGetTask.batchGetEmployeeTaskByRegionCode(regionCode); | employeeBatchGetTask.batchGetEmployeeTaskByRegionCode(regionCode); | ||||
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; | |||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers; | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | ||||
import com.google.common.collect.Lists; | import com.google.common.collect.Lists; | ||||
import com.ningdatech.basic.model.GenericResult; | import com.ningdatech.basic.model.GenericResult; | ||||
import com.ningdatech.pmapi.common.constant.BizConst; | |||||
import com.ningdatech.pmapi.ding.model.DingOrgInfoTreeDTO; | import com.ningdatech.pmapi.ding.model.DingOrgInfoTreeDTO; | ||||
import com.ningdatech.pmapi.organization.model.entity.DingOrganization; | import com.ningdatech.pmapi.organization.model.entity.DingOrganization; | ||||
import com.ningdatech.pmapi.organization.service.IDingOrganizationService; | import com.ningdatech.pmapi.organization.service.IDingOrganizationService; | ||||
@@ -21,6 +22,7 @@ import org.springframework.scheduling.annotation.Scheduled; | |||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
import java.time.LocalDateTime; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
import java.util.Objects; | import java.util.Objects; | ||||
@@ -103,6 +105,50 @@ public class OrganizationBatchGetTask { | |||||
} | } | ||||
} | } | ||||
/** | |||||
* 更新 其 子单位 | |||||
* @param orgCode | |||||
*/ | |||||
public void organizationGetSubs(String orgCode) { | |||||
log.info("----拉取浙政钉组织子单位开始---,顶级code:" + orgCode); | |||||
DingOrganization topOrg = iDingOrganizationService.getOne(Wrappers.lambdaQuery(DingOrganization.class) | |||||
.eq(DingOrganization::getOrganizationCode, orgCode) | |||||
.last(BizConst.LIMIT_1)); | |||||
// 顶级组织code | |||||
List<String> topOrgCodes = Lists.newArrayList(orgCode); | |||||
GenericResult<List<DingOrgInfoDTO>> listGenericResult = zwddClient.listOrganizationsByCodes(topOrgCodes); | |||||
log.info("listGenericResult: {}" + JSON.toJSONString(listGenericResult)); | |||||
List<DingOrgInfoDTO> dingOrgInfoDtos = listGenericResult.getData(); | |||||
for(DingOrgInfoDTO dingOrgInfo : dingOrgInfoDtos){ | |||||
DingOrganization old = iDingOrganizationService.getOne(Wrappers.lambdaQuery(DingOrganization.class) | |||||
.eq(DingOrganization::getOrganizationCode, dingOrgInfo.getOrganizationCode()) | |||||
.last(BizConst.LIMIT_1)); | |||||
if(Objects.nonNull(old)){ | |||||
log.info("该单位已经存在 :{}",old.getOrganizationName()); | |||||
continue; | |||||
} | |||||
DingOrganization organization = new DingOrganization(); | |||||
organization.setOrganizationCode(dingOrgInfo.getOrganizationCode()); | |||||
organization.setOrganizationName(dingOrgInfo.getOrganizationName()); | |||||
//和顶级单位一个区域 | |||||
organization.setDivisionCode(topOrg.getDivisionCode()); | |||||
organization.setParentCode(dingOrgInfo.getParentCode()); | |||||
organization.setTypeName(dingOrgInfo.getTypeName()); | |||||
organization.setAddress(dingOrgInfo.getAddress()); | |||||
organization.setBusinessStripCodes(dingOrgInfo.getBusinessStripCodes()); | |||||
organization.setDisplayOrder(dingOrgInfo.getDisplayOrder()); | |||||
organization.setGmtCreate(LocalDateTime.now()); | |||||
organization.setInstitutionLevelCode(dingOrgInfo.getInstitutionLevelCode()); | |||||
organization.setParentName(dingOrgInfo.getParentName()); | |||||
iDingOrganizationService.save(organization); | |||||
} | |||||
log.info("----拉取浙政钉组织子单位结束---,顶级code:" + orgCode); | |||||
} | |||||
private void buildSaveRecordList(List<DingOrgInfoTreeDTO> treeDTOList, List<DingOrganization> saveRecordList) { | private void buildSaveRecordList(List<DingOrgInfoTreeDTO> treeDTOList, List<DingOrganization> saveRecordList) { | ||||
if (CollectionUtils.isEmpty(treeDTOList)) { | if (CollectionUtils.isEmpty(treeDTOList)) { | ||||
return; | return; | ||||
@@ -167,7 +213,6 @@ public class OrganizationBatchGetTask { | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
@@ -34,15 +34,21 @@ import com.ningdatech.pmapi.wps.manage.WpsConvertManage; | |||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
import org.apache.poi.ss.formula.functions.T; | |||||
import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
import org.springframework.http.HttpEntity; | import org.springframework.http.HttpEntity; | ||||
import org.springframework.http.HttpHeaders; | import org.springframework.http.HttpHeaders; | ||||
import org.springframework.http.MediaType; | import org.springframework.http.MediaType; | ||||
import org.springframework.http.ResponseEntity; | import org.springframework.http.ResponseEntity; | ||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | |||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
import org.springframework.web.client.RestTemplate; | 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.lang.reflect.Field; | ||||
import java.time.LocalDateTime; | import java.time.LocalDateTime; | ||||
import java.util.*; | import java.util.*; | ||||
@@ -80,6 +86,8 @@ public class GovProjectCollectionManage { | |||||
private final WpsConvertManage wpsConvertManage; | private final WpsConvertManage wpsConvertManage; | ||||
private final ThreadPoolTaskExecutor threadPoolTaskExecutor; | |||||
@Value("${project.push-url}") | @Value("${project.push-url}") | ||||
private String pushUrl; | private String pushUrl; | ||||
@@ -89,6 +97,9 @@ public class GovProjectCollectionManage { | |||||
@Value("${project.delete-all-url}") | @Value("${project.delete-all-url}") | ||||
private String deleteAllUrl; | private String deleteAllUrl; | ||||
@Value("${spring.profiles.active}") | |||||
private String active; | |||||
public List<GovProjectDictionaryVO> dictionary(String type) { | public List<GovProjectDictionaryVO> dictionary(String type) { | ||||
List<GovProjectDictionary> dictionaries = dictionaryService.list(Wrappers.lambdaQuery(GovProjectDictionary.class) | List<GovProjectDictionary> dictionaries = dictionaryService.list(Wrappers.lambdaQuery(GovProjectDictionary.class) | ||||
@@ -430,7 +441,7 @@ public class GovProjectCollectionManage { | |||||
saveApply.setUpdateBy(user.getUsername()); | saveApply.setUpdateBy(user.getUsername()); | ||||
saveApply.setUpdateOn(LocalDateTime.now()); | saveApply.setUpdateOn(LocalDateTime.now()); | ||||
if(projectApplyService.saveOrUpdate(saveApply)){ | 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.setAreaCode(RegionConst.RC_LS); | ||||
saveApprove.setUpdateBy(user.getUsername()); | saveApprove.setUpdateBy(user.getUsername()); | ||||
saveApprove.setUpdateOn(LocalDateTime.now()); | saveApprove.setUpdateOn(LocalDateTime.now()); | ||||
approveService.saveOrUpdate(saveApprove); | |||||
if(approveService.saveOrUpdate(saveApprove)){ | |||||
threadPoolTaskExecutor.execute(() -> uploadFileToProvincialOssApprove(approve,oldApprove,saveApprove)); | |||||
} | |||||
} | } | ||||
// 4.保存 建设项目 实施信息 | // 4.保存 建设项目 实施信息 | ||||
@@ -478,7 +491,9 @@ public class GovProjectCollectionManage { | |||||
saveCimplement.setBizTime(LocalDateTime.now()); | saveCimplement.setBizTime(LocalDateTime.now()); | ||||
saveCimplement.setUpdateBy(user.getUsername()); | saveCimplement.setUpdateBy(user.getUsername()); | ||||
saveCimplement.setUpdateOn(LocalDateTime.now()); | saveCimplement.setUpdateOn(LocalDateTime.now()); | ||||
cimplementService.saveOrUpdate(saveCimplement); | |||||
if(cimplementService.saveOrUpdate(saveCimplement)){ | |||||
threadPoolTaskExecutor.execute(() -> uploadFileToProvincialOssCimplement(cimplement,oldCimplement,saveCimplement)); | |||||
} | |||||
} | } | ||||
// 5.保存 运维项目 实施信息 | // 5.保存 运维项目 实施信息 | ||||
@@ -793,39 +808,93 @@ public class GovProjectCollectionManage { | |||||
* @param apply | * @param apply | ||||
* @param oldApply | * @param oldApply | ||||
*/ | */ | ||||
private void uploadFileToProvincialOss(GovBizProjectApplyDTO apply, | |||||
private void uploadFileToProvincialOssApply(GovBizProjectApplyDTO apply, | |||||
GovBizProjectApply oldApply,GovBizProjectApply saveApply) { | GovBizProjectApply oldApply,GovBizProjectApply saveApply) { | ||||
if(checkFieldHas(apply.getBaseProjBasisFile(),oldApply,"baseProjBasisFile")){ | if(checkFieldHas(apply.getBaseProjBasisFile(),oldApply,"baseProjBasisFile")){ | ||||
JSONArray fileArray = JSON.parseArray(apply.getBaseProjBasisFile()); | |||||
StringJoiner sj = new StringJoiner(";"); | |||||
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 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 -> { | fileArray.forEach(j -> { | ||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(j)); | JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(j)); | ||||
byte[] btyes = wpsConvertManage.downloadToPdfStream(jsonObject.getLong("id")); | byte[] btyes = wpsConvertManage.downloadToPdfStream(jsonObject.getLong("id")); | ||||
String oss = ProvincialManage.uploadToOss(btyes, jsonObject.getString("originalFileName")); | |||||
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); | sj.add(oss); | ||||
}); | }); | ||||
saveApply.setBaseProjBasisFilePdf(sj.toString()); | |||||
} | } | ||||
projectApplyService.updateById(saveApply); | |||||
return sj; | |||||
} | } | ||||
private Boolean checkFieldHas(String field,GovBizProjectApply oldApply,String fieldName){ | |||||
private Boolean checkFieldHas(String field, Object record, String fieldName){ | |||||
if(StringUtils.isBlank(field)){ | if(StringUtils.isBlank(field)){ | ||||
return Boolean.FALSE; | return Boolean.FALSE; | ||||
} | } | ||||
//如果没有老值 | //如果没有老值 | ||||
if(Objects.isNull(oldApply)){ | |||||
if(Objects.isNull(record)){ | |||||
return Boolean.TRUE; | return Boolean.TRUE; | ||||
} | } | ||||
//和老值做个对比 不一样则true | //和老值做个对比 不一样则true | ||||
Class<?> clazz = oldApply.getClass(); | |||||
Class<?> clazz = record.getClass(); | |||||
String oldFiled = StringUtils.EMPTY; | String oldFiled = StringUtils.EMPTY; | ||||
try { | try { | ||||
Field fieldDeclared = clazz.getDeclaredField(fieldName); | Field fieldDeclared = clazz.getDeclaredField(fieldName); | ||||
fieldDeclared.setAccessible(Boolean.TRUE); | 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) { | } catch (NoSuchFieldException e) { | ||||
log.error("转换PDF文件出错" + e); | log.error("转换PDF文件出错" + e); | ||||
} catch (IllegalAccessException e) { | } catch (IllegalAccessException e) { | ||||
@@ -838,4 +907,24 @@ public class GovProjectCollectionManage { | |||||
return Boolean.FALSE; | 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(); | |||||
} | |||||
} | |||||
} | } |
@@ -152,4 +152,17 @@ public class GovBizProjectApply implements Serializable { | |||||
@ApiModelProperty("立项依据材料PDF版") | @ApiModelProperty("立项依据材料PDF版") | ||||
private String baseProjBasisFilePdf; | private String baseProjBasisFilePdf; | ||||
@ApiModelProperty("项目申报书PDF版") | |||||
private String baseProjApplyFilePdf; | |||||
@ApiModelProperty("运维方案PDF版") | |||||
private String baseOperatMaintenFilePdf; | |||||
@ApiModelProperty("可研报告PDF版") | |||||
private String baseResearchReportFilePdf; | |||||
@ApiModelProperty("其它文件PDF版") | |||||
private String baseProjOtherFilePdf; | |||||
} | } |
@@ -36,7 +36,7 @@ public class GovBizProjectApprove implements Serializable { | |||||
@ApiModelProperty("基本项目名称") | @ApiModelProperty("基本项目名称") | ||||
private String baseProjName; | private String baseProjName; | ||||
@ApiModelProperty("'发改项目代码'") | |||||
@ApiModelProperty("发改项目代码") | |||||
private String baseDevelopCode; | private String baseDevelopCode; | ||||
@ApiModelProperty("'财政项目代码'") | @ApiModelProperty("'财政项目代码'") | ||||
@@ -54,7 +54,7 @@ public class GovBizProjectApprove implements Serializable { | |||||
@ApiModelProperty("建议总投资") | @ApiModelProperty("建议总投资") | ||||
private BigDecimal baseExpertTotalMoney; | private BigDecimal baseExpertTotalMoney; | ||||
@ApiModelProperty("'建议年度预算'") | |||||
@ApiModelProperty("建议年度预算") | |||||
private BigDecimal baseExpertYearMoney; | private BigDecimal baseExpertYearMoney; | ||||
@ApiModelProperty("立项批复文件") | @ApiModelProperty("立项批复文件") | ||||
@@ -99,4 +99,13 @@ public class GovBizProjectApprove implements Serializable { | |||||
@ApiModelProperty("最后修改人") | @ApiModelProperty("最后修改人") | ||||
private String updateBy; | private String updateBy; | ||||
@ApiModelProperty("立项批复文件") | |||||
private String approvalFilePdf; | |||||
@ApiModelProperty("评审意见附件PDF") | |||||
private String baseReviewCommentsFilePdf; | |||||
@ApiModelProperty("初步设计方案批复函PDF") | |||||
private String preliminaryDesignFilePdf; | |||||
} | } |
@@ -115,4 +115,7 @@ public class GovBizProjectCimplement implements Serializable { | |||||
@ApiModelProperty("最后修改人") | @ApiModelProperty("最后修改人") | ||||
private String updateBy; | private String updateBy; | ||||
@ApiModelProperty("生产批复文件PDF") | |||||
private String baseChanFilePdf; | |||||
} | } |
@@ -13,15 +13,12 @@ import com.suwell.ofd.custom.agent.AtomAgent; | |||||
import lombok.RequiredArgsConstructor; | import lombok.RequiredArgsConstructor; | ||||
import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | |||||
import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||
import javax.annotation.Resource; | import javax.annotation.Resource; | ||||
import javax.servlet.ServletOutputStream; | import javax.servlet.ServletOutputStream; | ||||
import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
import java.io.*; | import java.io.*; | ||||
import java.net.URLEncoder; | import java.net.URLEncoder; | ||||
import java.nio.file.Path; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.List; | import java.util.List; | ||||
@@ -44,13 +41,11 @@ public class WpsConvertManage { | |||||
@Value("${spring.profiles.active}") | @Value("${spring.profiles.active}") | ||||
private String active; | private String active; | ||||
// HTTPAgent ha = new HTTPAgent("http://127.0.0.1:8090"); | |||||
//2、定义方法实现 多个文件合并转为1个pdf文件 | //2、定义方法实现 多个文件合并转为1个pdf文件 | ||||
public String offs2Pdf() { | public String offs2Pdf() { | ||||
AtomAgent ha = new AtomAgent("http://10.53.157.47"); | |||||
AtomAgent ha = new AtomAgent(WpsContant.WPS_CONVERT_URL_ONLINE); | |||||
try { | try { | ||||
//2-1、传参文件对象转换输出PDF文件 | //2-1、传参文件对象转换输出PDF文件 | ||||
//1)、定义集合,存储待转换的原文件 | //1)、定义集合,存储待转换的原文件 | ||||
List<File> fileList =new ArrayList<File>(); | List<File> fileList =new ArrayList<File>(); | ||||
@@ -58,25 +53,10 @@ public class WpsConvertManage { | |||||
OutputStream out = null; | OutputStream out = null; | ||||
//3)、添加原文件到集合 | //3)、添加原文件到集合 | ||||
fileList.add(new File("/temp/111.xlsx")); | fileList.add(new File("/temp/111.xlsx")); | ||||
// fileList.add(new File("D:/cs.doc")); | |||||
// fileList.add(new File("D:/a.pdf")); | |||||
// fileList.add(new File("D:\\555.ofd")); | |||||
//4)、赋值转换后的pdf文件输出流 | //4)、赋值转换后的pdf文件输出流 | ||||
out=new FileOutputStream(new File("/temp/offices2_pdf.pdf")); | out=new FileOutputStream(new File("/temp/offices2_pdf.pdf")); | ||||
//5)、调用方法,执行将多个文件转为pdf文件 | //5)、调用方法,执行将多个文件转为pdf文件 | ||||
ha.OFDToPDF(fileList, out); | ha.OFDToPDF(fileList, out); | ||||
//2-2、传参文件流转换输出PDF文件(与2-1二选一即可) | |||||
//1)、定义集合,存储待转换的原文件(支持传文件流) | |||||
// Param[] params = new Param[] { | |||||
// new Param(PackEntry.wrap(new FileInputStream("D:\\temp\\111.ofd")), "ofd"), | |||||
// new Param(PackEntry.wrap(new FileInputStream("D:\\2.ofd")), "ofd"), | |||||
// new Param(PackEntry.wrap(new FileInputStream("D:\\T3.txt")), "txt") | |||||
// }; | |||||
//2)、赋值转换后的pdf文件输出流 | |||||
// out=new FileOutputStream(new File("D:/convert/offices_pdf.pdf")); | |||||
//3)、调用方法,执行将多个文件转为pdf文件 | |||||
// ha.OFDToPDF(params,out); | |||||
return "转换成功"; | return "转换成功"; | ||||
} catch (Exception e) { | } catch (Exception e) { | ||||
log.error(e.getMessage()); | log.error(e.getMessage()); | ||||
@@ -164,8 +144,6 @@ public class WpsConvertManage { | |||||
AtomAgent ha = new AtomAgent(WpsContant.WPS_CONVERT_URL_ONLINE); | AtomAgent ha = new AtomAgent(WpsContant.WPS_CONVERT_URL_ONLINE); | ||||
try (OSSObject ossObject = oss.getObject(file.getBucket(), file.getPath()); | try (OSSObject ossObject = oss.getObject(file.getBucket(), file.getPath()); | ||||
InputStream stream = ossObject.getObjectContent();) { | InputStream stream = ossObject.getObjectContent();) { | ||||
String fileName = null; | |||||
byte[] bytes = new byte[4096]; | |||||
int read; | int read; | ||||
//测试环境 转不了PDF 请求不了 WPS转换服务器 | //测试环境 转不了PDF 请求不了 WPS转换服务器 | ||||
if(BizConst.DEV.equals(active)){ | if(BizConst.DEV.equals(active)){ | ||||
@@ -188,7 +166,6 @@ public class WpsConvertManage { | |||||
//5)、调用方法,执行将多个文件转为pdf文件 | //5)、调用方法,执行将多个文件转为pdf文件 | ||||
ha.OFDToPDF(fileList, out); | ha.OFDToPDF(fileList, out); | ||||
FileInputStream fileInputStream = new FileInputStream(pdfFile); | FileInputStream fileInputStream = new FileInputStream(pdfFile); | ||||
fileName = URLEncoder.encode(WpsContant.PDF_NAME, CharsetUtil.UTF_8); | |||||
for(File f : fileList){ | for(File f : fileList){ | ||||
//用完就删 | //用完就删 | ||||
f.deleteOnExit(); | f.deleteOnExit(); | ||||