From ab4d45cac1422672a0b463d5812a1f2985c795ef Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Tue, 15 Aug 2023 17:15:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B8=E5=BF=83=E4=B8=9A=E5=8A=A1=20?= =?UTF-8?q?=E5=8F=91=E7=BA=BF=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ningdatech/pmapi/common/constant/BizConst.java | 2 + .../pmapi/irs/manage/ProjectIrsManage.java | 82 ++++++++++++++++++++++ .../controller/DeclaredProjectController.java | 22 +----- .../manage/DeclaredProjectManage.java | 48 +++++++++++++ .../pmapi/wps/manage/WpsConvertManage.java | 68 +++++++++++------- pmapi/src/main/resources/application-dev.yml | 5 ++ pmapi/src/main/resources/application-pre.yml | 5 ++ pmapi/src/main/resources/application-prod.yml | 5 ++ pmapi/src/test/resources/application-dev.yml | 5 ++ pmapi/src/test/resources/application-pre.yml | 5 ++ pmapi/src/test/resources/application-prod.yml | 5 ++ 11 files changed, 205 insertions(+), 47 deletions(-) create mode 100644 pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/ProjectIrsManage.java diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BizConst.java b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BizConst.java index 4cc394b..3378b10 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BizConst.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/common/constant/BizConst.java @@ -90,4 +90,6 @@ public interface BizConst { String ORG_CODE = "organizationCode"; String DEV = "dev"; + String PRE = "pre"; + String PROD = "prod"; } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/ProjectIrsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/ProjectIrsManage.java new file mode 100644 index 0000000..c4d4b6a --- /dev/null +++ b/pmapi/src/main/java/com/ningdatech/pmapi/irs/manage/ProjectIrsManage.java @@ -0,0 +1,82 @@ +package com.ningdatech.pmapi.irs.manage; + +import com.alibaba.fastjson.JSONObject; +import com.ningdatech.irs.service.IRefreshTokenService; +import com.ningdatech.pmapi.common.util.CryptUtils; +import com.ningdatech.pmapi.common.util.HttpUtil; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; +import javax.annotation.Resource; +import java.security.NoSuchAlgorithmException; +import java.util.Objects; + +/** + * @Classname ProjectIrsManage + * @Description + * @Date 2023/8/15 11:43 + * @Author PoffyZhang + */ +@Component +@Slf4j +@RequiredArgsConstructor +public class ProjectIrsManage { + + @Value("${irs.core-biz.appKey}") + private String appKey; + + @Value("${irs.core-biz.appScret}") + private String appSecret; + + @Value("${irs.core-biz.url}") + private String coreBizUrl; + + @Value("${irs.core-biz.interfaceName}") + private String interfaceName; + @Resource + private IRefreshTokenService refreshTokenService; + + @Value("${irs.interface-refresh.request-token-url}") + private String govRequestTokenUrl; + @Value("${irs.interface-refresh.refresh-token-url}") + private String govRefreshTokenUrl; + + /** + * 查询核心业务 + * + * @param businessName + * @return + * @throws NoSuchAlgorithmException + */ + public JSONObject searchCoreBiz(String businessName,String orgCode) { + long timestamp = System.currentTimeMillis(); + String secret = refreshTokenService.refreshToken(appKey, appSecret, govRequestTokenUrl, govRefreshTokenUrl, + interfaceName, HttpMethod.POST.name()); + String sign = null; + try{ + sign = CryptUtils.MD5Encode(appKey + secret + timestamp); + }catch (Exception e){ + log.error(e.getMessage()); + } + HttpComponentsClientHttpRequestFactory factory = HttpUtil.generateHttpRequestFactory(); + RestTemplate restTemplate; + if(Objects.nonNull(factory)){ + restTemplate = new RestTemplate(factory); + }else{ + restTemplate = new RestTemplate(); + } + + String url = coreBizUrl + "?" + + "dingCode=" + orgCode + "&matterName=" + businessName + "&oid=&useState=1&limit=10&page=1" + + "&appKey=" + appKey + "&sign=" + sign + "&requestTime=" + timestamp; + + ResponseEntity forEntity = restTemplate.getForEntity(url, JSONObject.class); + log.info("body :{}",forEntity.getBody()); + return forEntity.getBody(); + } +} diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/DeclaredProjectController.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/DeclaredProjectController.java index afe69b1..ee5eccf 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/DeclaredProjectController.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/controller/DeclaredProjectController.java @@ -1,19 +1,13 @@ package com.ningdatech.pmapi.projectdeclared.controller; -import java.util.Iterator; - import javax.servlet.http.HttpServletResponse; import com.ningdatech.log.annotation.WebLog; -import org.apache.commons.lang3.StringUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; - -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ningdatech.basic.model.PageVo; import com.ningdatech.pmapi.common.util.ExcelDownUtil; -import com.ningdatech.pmapi.projectdeclared.contants.DeclaredProjectContant; import com.ningdatech.pmapi.projectdeclared.manage.DeclaredProjectManage; import com.ningdatech.pmapi.projectdeclared.manage.ProjectAdjustmentManage; import com.ningdatech.pmapi.projectdeclared.model.dto.DeclaredProjectListParamDTO; @@ -54,21 +48,7 @@ public class DeclaredProjectController { @ApiOperation(value = "核心业务列表", notes = "核心业务列表") @GetMapping("/core-biz") public JSONObject bizList(@RequestParam(required = false) String businessName) { - JSONObject jsonObject = JSONObject.parseObject(DeclaredProjectContant.Biz.CORE_BIZ); - if(StringUtils.isNotBlank(businessName)){ - JSONArray dataArray = JSONArray.parseArray(jsonObject.getString("data")); - Iterator iter = dataArray.stream().iterator(); - JSONArray dataArrayRes = new JSONArray(); - while (iter.hasNext()) { - JSONObject value = (JSONObject) iter.next(); - String businessValue = value.getString("matterName"); - if(StringUtils.isNotBlank(businessValue) && businessValue.contains(businessName)){ - dataArrayRes.add(value); - } - } - jsonObject.put("data",dataArrayRes); - } - return jsonObject; + return declaredProjectManage.bizList(businessName); } @ApiOperation(value = "申报项目草稿箱列表", notes = "申报项目草稿箱列表") diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DeclaredProjectManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DeclaredProjectManage.java index cb5c8d3..cfda31a 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DeclaredProjectManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectdeclared/manage/DeclaredProjectManage.java @@ -3,6 +3,8 @@ package com.ningdatech.pmapi.projectdeclared.manage; import cn.hutool.core.collection.CollUtil; import com.alibaba.excel.EasyExcel; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -19,6 +21,8 @@ import com.ningdatech.pmapi.common.helper.RegionCacheHelper; import com.ningdatech.pmapi.common.helper.UserInfoHelper; import com.ningdatech.pmapi.common.util.ExcelDownUtil; import com.ningdatech.pmapi.common.util.ExcelExportStyle; +import com.ningdatech.pmapi.irs.manage.ProjectIrsManage; +import com.ningdatech.pmapi.projectdeclared.contants.DeclaredProjectContant; import com.ningdatech.pmapi.projectdeclared.model.dto.*; import com.ningdatech.pmapi.projectdeclared.model.entity.ProjectDraft; import com.ningdatech.pmapi.projectdeclared.model.vo.ProjectDraftVO; @@ -37,6 +41,7 @@ import com.ningdatech.pmapi.staging.enums.MsgTypeEnum; import com.ningdatech.pmapi.sys.manage.NoticeManage; import com.ningdatech.pmapi.todocenter.constant.WorkNoticeConstant; import com.ningdatech.pmapi.user.security.auth.model.UserFullInfoDTO; +import com.ningdatech.pmapi.user.security.auth.model.UserInfoDetails; import com.ningdatech.pmapi.user.util.LoginUserUtil; import com.wflow.bean.entity.WflowModels; import com.wflow.exception.BusinessException; @@ -48,6 +53,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -87,6 +93,11 @@ public class DeclaredProjectManage { private final RegionCacheHelper regionCacheHelper; + private final ProjectIrsManage projectIrsManage; + + @Value("${spring.profiles.active}") + private String active; + /** * 新项目 启动实例 * @@ -414,4 +425,41 @@ public class DeclaredProjectManage { throw new RuntimeException(e); } } + + /** + * 查询 核心业务 + * @param businessName + * @return + */ + public JSONObject bizList(String businessName) { + JSONObject jsonObject = new JSONObject(); + UserInfoDetails user = LoginUserUtil.loginUserDetail(); + if(BizConst.DEV.equals(active)){ + jsonObject = JSONObject.parseObject(DeclaredProjectContant.Biz.CORE_BIZ); + if(StringUtils.isNotBlank(businessName)){ + JSONArray dataArray = JSONArray.parseArray(jsonObject.getString("data")); + if(CollUtil.isEmpty(dataArray)){ + return new JSONObject(); + } + Iterator iter = dataArray.stream().iterator(); + JSONArray dataArrayRes = new JSONArray(); + while (iter.hasNext()) { + JSONObject value = (JSONObject) iter.next(); + String businessValue = value.getString("matterName"); + if(StringUtils.isNotBlank(businessValue) && businessValue.contains(businessName)){ + dataArrayRes.add(value); + } + } + jsonObject.put("data",dataArrayRes); + } + }else if(BizConst.PRE.equals(active) || + BizConst.PROD.equals(active)){ + jsonObject = projectIrsManage.searchCoreBiz(businessName,user.getEmpPosUnitCode()); + } + if(CollUtil.isEmpty(jsonObject)){ + return jsonObject; + } + + return jsonObject; + } } diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/wps/manage/WpsConvertManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/wps/manage/WpsConvertManage.java index e8fc4ea..42b7401 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/wps/manage/WpsConvertManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/wps/manage/WpsConvertManage.java @@ -7,10 +7,12 @@ import com.aliyun.oss.model.OSSObject; import com.aliyun.oss.model.ObjectMetadata; import com.ningdatech.file.properties.FileServerProperties; import com.ningdatech.file.service.FileService; +import com.ningdatech.pmapi.common.constant.BizConst; import com.ningdatech.pmapi.wps.contants.WpsContant; import com.suwell.ofd.custom.agent.AtomAgent; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.stereotype.Component; @@ -39,6 +41,9 @@ public class WpsConvertManage { private final FileServerProperties fileServerProperties; + @Value("${spring.profiles.active}") + private String active; + // HTTPAgent ha = new HTTPAgent("http://127.0.0.1:8090"); //2、定义方法实现 多个文件合并转为1个pdf文件 public String offs2Pdf() { @@ -95,37 +100,48 @@ public class WpsConvertManage { OSS oss = new OSSClientBuilder().build(fileServerProperties.getAli().getEndpoint(), fileServerProperties.getAli().getAccessKeyId(), fileServerProperties.getAli().getAccessKeySecret()); AtomAgent ha = new AtomAgent(WpsContant.WPS_CONVERT_URL_ONLINE); try (OSSObject ossObject = oss.getObject(file.getBucket(), file.getPath()); - InputStream stream = ossObject.getObjectContent(); + InputStream stream = ossObject.getObjectContent(); ServletOutputStream outputStream = response.getOutputStream()) { - String filePath = WpsContant.FIX_FILE_PATH + file.getOriginalFileName(); - convert(stream,filePath); - //转换PDF - List fileList =new ArrayList(); - //2)、定义转换后的pdf文件输出流 - OutputStream out = null; - //3)、添加原文件到集合 - fileList.add(new File(filePath)); - //4)、赋值转换后的pdf文件输出流 - File pdfFile = new File(WpsContant.PDF_PATH); - out = new FileOutputStream(pdfFile); - //5)、调用方法,执行将多个文件转为pdf文件 - ha.OFDToPDF(fileList, out); - FileInputStream fileInputStream = new FileInputStream(pdfFile); - - ObjectMetadata metadata = ossObject.getObjectMetadata(); - response.setContentType(WpsContant.PDF_CONTENT_TYPE); - String fileName = URLEncoder.encode(WpsContant.PDF_NAME, CharsetUtil.UTF_8); - response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + fileName); + String fileName = null; byte[] bytes = new byte[4096]; int read; - while ((read = fileInputStream.read(bytes)) != -1) { - outputStream.write(bytes, 0, read); + //测试环境 转不了PDF 请求不了 WPS转换服务器 + if(BizConst.DEV.equals(active)){ + ObjectMetadata metadata = ossObject.getObjectMetadata(); + response.setContentType(metadata.getContentType()); + fileName = URLEncoder.encode(file.getOriginalFileName(), CharsetUtil.UTF_8); + response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + fileName); + while ((read = stream.read(bytes)) != -1) { + outputStream.write(bytes, 0, read); + } + }else if(BizConst.PRE.equals(active) || + BizConst.PROD.equals(active)){ + String filePath = WpsContant.FIX_FILE_PATH + file.getOriginalFileName(); + convert(stream,filePath); + //转换PDF + List fileList =new ArrayList(); + //2)、定义转换后的pdf文件输出流 + OutputStream out = null; + //3)、添加原文件到集合 + fileList.add(new File(filePath)); + //4)、赋值转换后的pdf文件输出流 + File pdfFile = new File(WpsContant.PDF_PATH); + out = new FileOutputStream(pdfFile); + //5)、调用方法,执行将多个文件转为pdf文件 + ha.OFDToPDF(fileList, out); + FileInputStream fileInputStream = new FileInputStream(pdfFile); + response.setContentType(WpsContant.PDF_CONTENT_TYPE); + fileName = URLEncoder.encode(WpsContant.PDF_NAME, CharsetUtil.UTF_8); + response.setHeader("Content-Disposition", "attachment;filename*=utf-8''" + fileName); + while ((read = fileInputStream.read(bytes)) != -1) { + outputStream.write(bytes, 0, read); + } + for(File f : fileList){ + //用完就删 + f.deleteOnExit(); + } } outputStream.flush(); - for(File f : fileList){ - //用完就删 - f.deleteOnExit(); - } }catch (Exception e){ log.error(e.getMessage()); }finally { diff --git a/pmapi/src/main/resources/application-dev.yml b/pmapi/src/main/resources/application-dev.yml index 99c66e3..d43b29f 100644 --- a/pmapi/src/main/resources/application-dev.yml +++ b/pmapi/src/main/resources/application-dev.yml @@ -240,6 +240,11 @@ irs: interfaceName: 3XN9R93Pva6db7sf appSecret: 496f0f2a19994f76b4fd9dae087366c7 appKey: A331101453557202109017383 + core-biz: + url: https://interface.zjzwfw.gov.cn/gateway/api/001008012012001/dataSharing/Fc3re2cq7r64Qfa7.htm + interfaceName: Fc3re2cq7r64Qfa7 + appSecret: 496f0f2a19994f76b4fd9dae087366c7 + appKey: A331101453557202109017383 interface-refresh: method: POST request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} diff --git a/pmapi/src/main/resources/application-pre.yml b/pmapi/src/main/resources/application-pre.yml index 203a5ec..7e4ffee 100644 --- a/pmapi/src/main/resources/application-pre.yml +++ b/pmapi/src/main/resources/application-pre.yml @@ -243,6 +243,11 @@ irs: interfaceName: 3XN9R93Pva6db7sf appSecret: 496f0f2a19994f76b4fd9dae087366c7 appKey: A331101453557202109017383 + core-biz: + url: https://interface.zjzwfw.gov.cn/gateway/api/001008012012001/dataSharing/Fc3re2cq7r64Qfa7.htm + interfaceName: Fc3re2cq7r64Qfa7 + appSecret: 496f0f2a19994f76b4fd9dae087366c7 + appKey: A331101453557202109017383 interface-refresh: method: POST request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} diff --git a/pmapi/src/main/resources/application-prod.yml b/pmapi/src/main/resources/application-prod.yml index b2ab273..10998a7 100644 --- a/pmapi/src/main/resources/application-prod.yml +++ b/pmapi/src/main/resources/application-prod.yml @@ -243,6 +243,11 @@ irs: interfaceName: 3XN9R93Pva6db7sf appSecret: 496f0f2a19994f76b4fd9dae087366c7 appKey: A331101453557202109017383 + core-biz: + url: https://interface.zjzwfw.gov.cn/gateway/api/001008012012001/dataSharing/Fc3re2cq7r64Qfa7.htm + interfaceName: Fc3re2cq7r64Qfa7 + appSecret: 496f0f2a19994f76b4fd9dae087366c7 + appKey: A331101453557202109017383 interface-refresh: method: POST request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} diff --git a/pmapi/src/test/resources/application-dev.yml b/pmapi/src/test/resources/application-dev.yml index 1576bb9..80810b2 100644 --- a/pmapi/src/test/resources/application-dev.yml +++ b/pmapi/src/test/resources/application-dev.yml @@ -240,6 +240,11 @@ irs: interfaceName: 3XN9R93Pva6db7sf appSecret: 496f0f2a19994f76b4fd9dae087366c7 appKey: A331101453557202109017383 + core-biz: + url: https://interface.zjzwfw.gov.cn/gateway/api/001008012012001/dataSharing/Fc3re2cq7r64Qfa7.htm + interfaceName: Fc3re2cq7r64Qfa7 + appSecret: 496f0f2a19994f76b4fd9dae087366c7 + appKey: A331101453557202109017383 interface-refresh: method: POST request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} diff --git a/pmapi/src/test/resources/application-pre.yml b/pmapi/src/test/resources/application-pre.yml index 9f449f4..6319487 100644 --- a/pmapi/src/test/resources/application-pre.yml +++ b/pmapi/src/test/resources/application-pre.yml @@ -243,6 +243,11 @@ irs: interfaceName: 3XN9R93Pva6db7sf appSecret: 496f0f2a19994f76b4fd9dae087366c7 appKey: A331101453557202109017383 + core-biz: + url: https://interface.zjzwfw.gov.cn/gateway/api/001008012012001/dataSharing/Fc3re2cq7r64Qfa7.htm + interfaceName: Fc3re2cq7r64Qfa7 + appSecret: 496f0f2a19994f76b4fd9dae087366c7 + appKey: A331101453557202109017383 interface-refresh: method: POST request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign} diff --git a/pmapi/src/test/resources/application-prod.yml b/pmapi/src/test/resources/application-prod.yml index b777187..17f34d4 100644 --- a/pmapi/src/test/resources/application-prod.yml +++ b/pmapi/src/test/resources/application-prod.yml @@ -238,6 +238,11 @@ irs: interfaceName: 3XN9R93Pva6db7sf appSecret: 496f0f2a19994f76b4fd9dae087366c7 appKey: A331101453557202109017383 + core-biz: + url: https://interface.zjzwfw.gov.cn/gateway/api/001008012012001/dataSharing/Fc3re2cq7r64Qfa7.htm + interfaceName: Fc3re2cq7r64Qfa7 + appSecret: 496f0f2a19994f76b4fd9dae087366c7 + appKey: A331101453557202109017383 interface-refresh: method: POST request-token-url: https://interface.zjzwfw.gov.cn/gateway/app/refreshTokenByKey.htm?appKey={appKey}&requestTime={requestTime}&sign={sign}