diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/dao/IC4ProjectDao.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/dao/IC4ProjectDao.java index abbf3dd1..3e4fb43e 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/dao/IC4ProjectDao.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/dao/IC4ProjectDao.java @@ -43,4 +43,6 @@ public interface IC4ProjectDao extends IBaseDao { int saveXmDetail(C4ProjectXmDetailEntity c4ProjectXmDetailEntity); List queryUser(C4ProjectXmEntity c4ProjectXmEntity); + + List queryFileList(LexmisC4ProjectEntity fileEntity); } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/dao/impl/C4ProjectDaoImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/dao/impl/C4ProjectDaoImpl.java index 9e2fb6df..e2fda913 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/dao/impl/C4ProjectDaoImpl.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/dao/impl/C4ProjectDaoImpl.java @@ -62,4 +62,10 @@ public class C4ProjectDaoImpl extends MybatisGenericDao return (List) super.selectList(getSqlIdPrifx()+"queryUser",entity); } + @DS("#entity.dataSourceCode") + @Override + public List queryFileList(LexmisC4ProjectEntity entity) { + return (List) super.selectList(getSqlIdPrifx()+"queryFileList",entity); + + } } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/entity/C4ProjectEntity.xml b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/entity/C4ProjectEntity.xml index 4b60516b..18065496 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/entity/C4ProjectEntity.xml +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/entity/C4ProjectEntity.xml @@ -491,6 +491,17 @@ id = #{CA_MANAGER} + diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/entity/LexmisC4ProjectEntity.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/entity/LexmisC4ProjectEntity.java index 27f8948f..e4ebf79c 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/entity/LexmisC4ProjectEntity.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/entity/LexmisC4ProjectEntity.java @@ -9,6 +9,7 @@ public class LexmisC4ProjectEntity extends BaseEntity { private String noname; private String nodename; + private String filename; public String getAffairId() { return affairId; @@ -43,5 +44,13 @@ public class LexmisC4ProjectEntity extends BaseEntity { public void setNodename(String nodename) { this.nodename = nodename; } + + public String getFilename() { + return filename; + } + + public void setFilename(String filename) { + this.filename = filename; + } } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/plugin/LexmisC4ProjectPluginInitializer.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/plugin/LexmisC4ProjectPluginInitializer.java index 84bbbcd5..212d7612 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/plugin/LexmisC4ProjectPluginInitializer.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/c4project/plugin/LexmisC4ProjectPluginInitializer.java @@ -2,6 +2,7 @@ package com.hzya.frame.plugin.c4project.plugin; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpUtil; import cn.hutool.json.JSONUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; @@ -12,6 +13,7 @@ import com.hzya.frame.plugin.c4project.entity.C4ProjectXmDetailEntity; import com.hzya.frame.plugin.c4project.entity.C4ProjectXmEntity; import com.hzya.frame.plugin.c4project.entity.LexmisC4ProjectEntity; import com.hzya.frame.seeyon.entity.CollAttachmentResDTO; +import com.hzya.frame.seeyon.service.ICtpAttachmentService; import com.hzya.frame.sysnew.application.api.entity.SysApplicationApiEntity; import com.hzya.frame.sysnew.application.api.service.ISysApplicationApiService; import com.hzya.frame.web.entity.BaseResult; @@ -22,7 +24,28 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLDecoder; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.HashMap; import java.util.List; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * 诺诺发票 @@ -36,6 +59,8 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ private IC4ProjectDao ic4ProjectDao; @Autowired private ISysApplicationApiService sysApplicationApiService; + @Autowired + private ICtpAttachmentService ctpAttachmentService; @Value("${zt.url}") private String url; @Override @@ -275,21 +300,33 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ return BaseResult.getFailureMessageEntity("获取OA token失败"); } JSONObject sendData = null; - + //查询是否有附件 + String urluuid = null; + List files = null; + if(mainData.getString("field0040") != null && !"".equals(mainData.getString("field0040"))){ + LexmisC4ProjectEntity fileEntity = new LexmisC4ProjectEntity(); + fileEntity.setDataSourceCode("SW-OA"); + fileEntity.setId(mainData.getString("field0040")); + files = ic4ProjectDao.queryFileList(fileEntity); + if(files != null && files.size() > 0){ + urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits()); + } + } if(mainData.getString("field0052") != null && "7045878877534307194".equals(mainData.getString("field0052"))){//三维通信股份有限公司 - sendData = getSwtxData(mainData,detailArray,type); + sendData = getSwtxData(mainData,detailArray,type,urluuid); }else if(mainData.getString("field0052") != null && "-5302246194420562875".equals(mainData.getString("field0052"))){//浙江三维通信科技有限公司 - sendData = getSwtxkjData(mainData,detailArray,type); + sendData = getSwtxkjData(mainData,detailArray,type,urluuid); }else if(mainData.getString("field0052") != null && "-6504696439968085996".equals(mainData.getString("field0052"))){//浙江三维利普维网络有限公司 - sendData = getlwpData(mainData,detailArray,type); + sendData = getlwpData(mainData,detailArray,type,urluuid); }else if(mainData.getString("field0052") != null && "-8106884040682618016".equals(mainData.getString("field0052"))){//浙江三维通信研究院有限公司 - sendData = gettxyjyData(mainData,detailArray,type); + sendData = gettxyjyData(mainData,detailArray,type,urluuid); }else { return BaseResult.getSuccessMessageEntity("该公司不需要生成"+jdmz); } + logger.error("同步"+jdmz+"单据发送参数:" + sendData.toJSONString()); String sendResult = HttpRequest.post(url). header("appId", "800051"). - header("apiCode", ""). + header("apiCode", "8000510001"). header("token", token). header("publicKey", "ZJYAM2YFEIsIaI1e4wMagkS2Q7SFgGk0RvsPhEES45m/OVFCe7eDIk+3zDUT+v578prj"). header("secretKey", "lR6+uf94mvNMclAB43oIwmhJSMDzQaViTkfXLeNvmGdpLfbFiUvbgbU+p43zO25Zj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA="). @@ -299,36 +336,145 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ logger.error("同步"+jdmz+"单据发送返回:" + sendResult); JSONObject sendJson = JSONObject.parseObject(sendResult); if (sendJson.getBoolean("flag")) { - String attType = "0"; - String url = "/seeyon/rest/coll/attachments/@SummaryID@/@attType@"; - url = url.replaceAll("@SummaryID@",businessDataStr.getString("SummaryID")).replaceAll("@attType@",attType); - String body = HttpRequest.get(url).header("token", token).execute().body(); - if (StrUtil.isNotEmpty(body) && JSONUtil.isTypeJSON(body)){ - List list = JSON.parseArray(body,CollAttachmentResDTO.class); - - + String summaryId = null; + if(sendJson.containsKey("attribute")){ + JSONObject attribute = sendJson.getJSONObject("attribute"); + if(attribute.containsKey("data")){ + JSONObject data = attribute.getJSONObject("data"); + if(data.containsKey("app_bussiness_data")){ + JSONObject app_bussiness_data = data.getJSONObject("app_bussiness_data"); + if(app_bussiness_data.containsKey("summaryId")){ + summaryId = app_bussiness_data.getString("summaryId"); + } + } + } } - - + if(summaryId != null){ + //下载附件保存附件,保存对照 + if(files != null&& files.size() > 0){ + for (int i = 0; i < files.size(); i++) { + try { + String encodedFileName = URLEncoder.encode(files.get(i).getFilename(), StandardCharsets.UTF_8.name()); + String pdfUrl = "https://swoa.sunwave.com.cn:9999/seeyon/rest/attachment/file/"+files.get(i).getId()+"?fileName="+encodedFileName+"&token="+token; + logger.error("预算编制附件的url"+pdfUrl); + String urlData = sendFileUpload(pdfUrl,token,files.get(i).getFilename()); + ctpAttachmentService.saveAttachment(urlData,summaryId,urluuid,"SW-OA"); + } catch (Exception e) { + logger.error("同步"+jdmz+"单据附件错误:"+e.getMessage()); + e.printStackTrace(); + } + } + } + } return BaseResult.getSuccessMessageEntity("同步"+jdmz+"发送成功"); } else { return BaseResult.getFailureMessageEntity("同步"+jdmz+"发送错误:"+sendJson.getString("msg")); } } - private SysApplicationApiEntity getByCode(String api_code){ - if (StrUtil.isNotEmpty(api_code)){ - SysApplicationApiEntity sysApp = new SysApplicationApiEntity(); - sysApp.setApiCode(Long.valueOf(api_code)); - sysApp = sysApplicationApiService.queryOne(sysApp); - if (null != sysApp && StrUtil.isNotEmpty(sysApp.getId())){ - sysApp = sysApplicationApiService.get(sysApp.getId()); - if (null != sysApp){ - return sysApp; + private String sendFileUpload(String fileurl,String token,String filename) { + try { + // 获取文件字节数据 + byte[] fileBytes = null; + + // 创建信任所有证书的TrustManager + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public X509Certificate[] getAcceptedIssuers() { + return null; + } + public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException { + } + public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException { + } + } + }; + + // 安装信任管理器 + SSLContext sc = SSLContext.getInstance("TLS"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); + + // 创建允许所有主机名的验证器 + HostnameVerifier allHostsValid = (hostname, session) -> true; + HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); + + + + URL url = new URL(fileurl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + + try (InputStream inputStream = connection.getInputStream(); + ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { + byte[] buffer = new byte[4096]; + int bytesRead; + while ((bytesRead = inputStream.read(buffer)) != -1) { + outputStream.write(buffer, 0, bytesRead); } + fileBytes = outputStream.toByteArray(); } - }else { - throw new BaseSystemException("api_code不能为空"); + + + if (fileBytes != null) { + // 模拟一个文件 + File tempFile = new File(filename); + try (FileOutputStream fos = new FileOutputStream(tempFile)) { + fos.write(fileBytes); + } + + JSONObject data = fileUpload(tempFile,token); + String fileUrl = null; + if(data != null && data.getString("fileUrl") != null && !"".equals(data.getString("fileUrl")) ){ + fileUrl = data.getString("fileUrl"); + } + // 操作完成后删除临时文件 + tempFile.delete(); + return fileUrl; + } + } catch (Exception e) { + logger.error(e.getMessage()); + } + return null; + } + public JSONObject fileUpload(File file,String token) { + + if (null != file) { + try { + HashMap paramMap = new HashMap<>(); + paramMap.put("file", file); + String url = "/seeyon/rest/attachment?token=@token@";//如果后面加上applicationCategory=1&extensions=&firstSave=true,附件业务自动生成一条记录 + url = url.replaceAll("@token@", token); + String result = HttpUtil.post("https://swoa.sunwave.com.cn:9999" + url, paramMap); + if (StrUtil.isNotBlank(result)) { + JSONObject jsonObject = JSONObject.parseObject(result); + String atts = jsonObject.get("atts").toString(); + if (StrUtil.isNotEmpty(atts)) { + JSONArray jsonArray = JSONArray.parseArray(atts); + JSONObject res = (JSONObject) jsonArray.get(0); + String fileUrl = res.getString("fileUrl"); + logger.info("附件id:" + fileUrl); + return res; + } + } + }catch (Exception e){ + logger.error("附件上传失败"+e.getMessage()); + } + } + return null; + } + private String extractFileNameFromContentDisposition(String contentDisposition) { + // 处理Content-Disposition头中的filename + try { + Pattern pattern = Pattern.compile("filename=\"?([^\"]+)\"?"); + Matcher matcher = pattern.matcher(contentDisposition); + if (matcher.find()) { + String filename = matcher.group(1); + String a = URLDecoder.decode(filename, "UTF-8"); + return a; + } + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); } return null; } @@ -341,7 +487,7 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ * @param type * @return com.alibaba.fastjson.JSONObject **/ - private JSONObject gettxyjyData(JSONObject mainData, JSONArray detailArray, String type) { + private JSONObject gettxyjyData(JSONObject mainData, JSONArray detailArray, String type, String urluuid) { if("1".equals(type)){//预算编制 JSONObject sendData = new JSONObject(); JSONObject data = new JSONObject(); @@ -352,6 +498,7 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ zb.put("C4预算方案",mainData.getString("field0093")); zb.put("发起部门",mainData.getString("field0069")); zb.put("C4年度",mainData.getString("field0099")); + zb.put("项目任务书及其他附件",urluuid); JSONArray mxList = new JSONArray(); for (int i = 0; i < detailArray.size(); i++) { @@ -409,7 +556,7 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ * @param type * @return com.alibaba.fastjson.JSONObject **/ - private JSONObject getlwpData(JSONObject mainData, JSONArray detailArray, String type) { + private JSONObject getlwpData(JSONObject mainData, JSONArray detailArray, String type, String urluuid) { if("1".equals(type)){//预算编制 JSONObject sendData = new JSONObject(); JSONObject data = new JSONObject(); @@ -420,6 +567,7 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ zb.put("C4预算方案",mainData.getString("field0093")); zb.put("发起部门",mainData.getString("field0069")); zb.put("C4年度",mainData.getString("field0099")); + zb.put("项目任务书及其他附件",urluuid); JSONArray mxList = new JSONArray(); for (int i = 0; i < detailArray.size(); i++) { @@ -477,7 +625,7 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ * @param type * @return com.alibaba.fastjson.JSONObject **/ - private JSONObject getSwtxkjData(JSONObject mainData, JSONArray detailArray, String type) { + private JSONObject getSwtxkjData(JSONObject mainData, JSONArray detailArray, String type, String urluuid) { if("1".equals(type)){//预算编制 JSONObject sendData = new JSONObject(); JSONObject data = new JSONObject(); @@ -488,6 +636,7 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ zb.put("C4预算方案",mainData.getString("field0093")); zb.put("发起部门",mainData.getString("field0069")); zb.put("C4年度",mainData.getString("field0099")); + zb.put("项目任务书及其他附件",urluuid); JSONArray mxList = new JSONArray(); for (int i = 0; i < detailArray.size(); i++) { @@ -544,7 +693,7 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ * @param detailArray * @return com.alibaba.fastjson.JSONObject **/ - private JSONObject getSwtxData(JSONObject mainData, JSONArray detailArray,String type) { + private JSONObject getSwtxData(JSONObject mainData, JSONArray detailArray,String type,String urluuid) { if("1".equals(type)){//预算编制 JSONObject sendData = new JSONObject(); JSONObject data = new JSONObject(); @@ -555,6 +704,7 @@ public class LexmisC4ProjectPluginInitializer extends PluginBaseEntity{ zb.put("C4预算方案",mainData.getString("field0093")); zb.put("发起部门",mainData.getString("field0069")); zb.put("C4年度",mainData.getString("field0099")); + zb.put("项目任务书及其他附件",urluuid); JSONArray mxList = new JSONArray(); for (int i = 0; i < detailArray.size(); i++) { JSONObject mx = new JSONObject(); diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/complianceSupplier/entity/ComplianceSupplierEntity.xml b/base-buildpackage/src/main/java/com/hzya/frame/plugin/complianceSupplier/entity/ComplianceSupplierEntity.xml index 12c8f76c..687814cf 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/complianceSupplier/entity/ComplianceSupplierEntity.xml +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/complianceSupplier/entity/ComplianceSupplierEntity.xml @@ -29,9 +29,9 @@ id as id, ${sqjgField} as sqjg, ${dhField} as dh, - #{tableName} as #{tableName}, - #{sqjgField} as #{sqjgField}, - #{cljgField} as #{cljgField} + #{tableName} as tableName, + #{sqjgField} as sqjgField, + #{cljgField} as cljgField from ${tableName} where ${sqjgField} is not null and ${cljgField} is null diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/complianceSupplier/service/impl/ComplianceSupplierServiceImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/complianceSupplier/service/impl/ComplianceSupplierServiceImpl.java index b916243a..d24e1bc1 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/complianceSupplier/service/impl/ComplianceSupplierServiceImpl.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/complianceSupplier/service/impl/ComplianceSupplierServiceImpl.java @@ -13,6 +13,7 @@ import com.hzya.frame.web.entity.JsonResultEntity; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import java.net.URI; import java.util.List; public class ComplianceSupplierServiceImpl extends BaseService implements IComplianceSupplierService { @@ -103,7 +104,7 @@ public class ComplianceSupplierServiceImpl extends BaseService get11208 = getQueryData("formmain_11208", "field0172", "field0173", ""); + List get11208 = getQueryData("formmain_11208", "field0172", "field0173", "id"); if (get11208 != null && get11208.size() > 0) { for (int i = 0; i < get11208.size(); i++) { sendAndSetData(get11208.get(i), token); } } - List get7220 = getQueryData("formmain_7220", "field0058", "field0059", ""); + List get7220 = getQueryData("formmain_7220", "field0058", "field0059", "id"); if (get7220 != null && get7220.size() > 0) { for (int i = 0; i < get7220.size(); i++) { sendAndSetData(get7220.get(i), token); } } - List get8694 = getQueryData("formmain_8694", "field0157", "field0158", ""); + List get8694 = getQueryData("formmain_8694", "field0157", "field0158", "id"); if (get8694 != null && get8694.size() > 0) { for (int i = 0; i < get8694.size(); i++) { sendAndSetData(get8694.get(i), token); @@ -387,8 +388,11 @@ public class ComplianceSupplierServiceImpl extends BaseService