This commit is contained in:
xiang2lin 2025-06-16 18:45:05 +08:00
commit 9a91d156e6
6 changed files with 236 additions and 50 deletions

View File

@ -9,8 +9,8 @@ import com.hzya.frame.web.entity.BaseEntity;
public class IncomeInvoiceEntity extends BaseEntity {
//发票字段
private Integer dataId;
private Integer formmainId;
private String dataId;
private String formmainId;
private String field0127;
private String field0128;
private String field0129;
@ -28,6 +28,7 @@ public class IncomeInvoiceEntity extends BaseEntity {
private String iufoVer;
public String getAloneId() {
return aloneId;
}
@ -68,19 +69,19 @@ public class IncomeInvoiceEntity extends BaseEntity {
this.iufoVer = iufoVer;
}
public Integer getDataId() {
public String getDataId() {
return dataId;
}
public void setDataId(Integer dataId) {
public void setDataId(String dataId) {
this.dataId = dataId;
}
public Integer getFormmainId() {
public String getFormmainId() {
return formmainId;
}
public void setFormmainId(Integer formmainId) {
public void setFormmainId(String formmainId) {
this.formmainId = formmainId;
}

View File

@ -194,6 +194,7 @@
from formson_0702
<trim prefix="where" prefixOverrides="and">
<if test="field0128 != null and field0128 != ''"> and field0128 = #{field0128} </if>
<if test="formmainId != null and formmainId != ''"> and formmain_id = #{formmainId} </if>
</trim>
</select>

View File

@ -1,6 +1,7 @@
package com.hzya.frame.plugin.incomeInvoiceData.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
@ -40,15 +41,24 @@ import com.hzya.frame.basedao.service.impl.BaseService;
import org.springframework.core.task.TaskExecutor;
import javax.annotation.Resource;
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.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -58,6 +68,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author makejava
@ -183,15 +195,17 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
saveData.put("kpr",content.getString("kpr"));
saveData.put("skr",content.getString("skr"));
saveData.put("fhr",content.getString("fhr"));
saveData.put("url",content.getString("pdfUrl"));
saveData.put("ofdurl",content.getString("ofdUrl"));
saveData.put("xmlurl",content.getString("xmlUrl"));
saveData.put("url",jsonObject.getString("pdfUrl"));
saveData.put("ofdurl",jsonObject.getString("ofdUrl"));
saveData.put("xmlurl",jsonObject.getString("xmlUrl"));
//saveData.put("url",content.getOrDefault("url","http://prd-cabinet-1257122416.cos.ap-shanghai.myqcloud.com/recv-open-input-1313818348185971712-1362629996254053632.pdf"));
//saveData.put("ofdurl",content.getOrDefault("ofdUrl","http://prd-cabinet-1257122416.cos.ap-shanghai.myqcloud.com/recv-open-input-1313818348185971712-1362629996254053632.pdf"));
//saveData.put("xmlurl",content.getOrDefault("xmlUrl","http://prd-cabinet-1257122416.cos.ap-shanghai.myqcloud.com/recv-open-input-1313818348185971712-1362630000427386112.xml"));
saveData.put("htbh",content.getString("documentNumber"));
saveData.put("htbh",jsonObject.getString("documentNumber"));
//if(saveData.getString("htbh") == null || "".equals(saveData.getString("htbh"))){
// continue;
//}
JSONArray detaildata = content.getJSONArray("items");
if(detaildata != null && detaildata.size() > 0){
for (int i1 = 0; i1 < detaildata.size(); i1++) {
@ -239,6 +253,7 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
controlsLogEntity.setOrg_id("0");
controlsLogEntity.setRemark("插件新增");
controlsLogDaoimpl.saveControlsLog(saveData.getString("id"), "数智中台", "800004", jsonObject.toJSONString(), "接口新增", "数智中台", "mdm_fp_option_log", "1");
}
}
return BaseResult.getSuccessMessageEntity("处理成功");
@ -505,10 +520,60 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
return null;
}
private String sendFileUpload(String url,String filename) {
private String sendFileUpload(String fileurl) {
try {
// 获取文件字节数据
byte[] fileBytes = downloadFileBytes(url);
byte[] fileBytes = null;
String filename = 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");
// 从响应头获取Content-Disposition
String contentDisposition = connection.getHeaderField("Content-Disposition");
// 尝试从Content-Disposition中提取文件名
if (contentDisposition != null) {
filename = extractFileNameFromContentDisposition(contentDisposition);
}else {
// 提取结果为 "recv-open-input-1364609961183034880-1377757054294396417.ofd"
filename = fileurl.substring(fileurl.lastIndexOf("/") + 1);
}
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();
}
if (fileBytes != null) {
// 模拟一个文件
File tempFile = new File(filename);
@ -522,19 +587,53 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
fileUrl = data.getString("fileUrl");
}
// 操作完成后删除临时文件
tempFile.deleteOnExit();
boolean asd = tempFile.delete();
return fileUrl;
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
logger.error(e.getMessage());
}
return null;
}
public byte[] downloadFileBytes(String fileUrl) throws IOException {
public byte[] downloadFileBytes(String fileUrl) throws Exception {
// 创建信任所有证书的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");
// 从响应头获取Content-Disposition
String contentDisposition = connection.getHeaderField("Content-Disposition");
String fileName = null;
// 尝试从Content-Disposition中提取文件名
if (contentDisposition != null) {
fileName = extractFileNameFromContentDisposition(contentDisposition);
}
try (InputStream inputStream = connection.getInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
byte[] buffer = new byte[4096];
@ -545,6 +644,22 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
return outputStream.toByteArray();
}
}
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;
}
/**
* seeyon流程事件监听后置方法绑定修改文件
@ -554,97 +669,156 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
*/
@Override
public void setDataCallBack(SysMessageManageLogEntity entity) throws Exception {
logger.error("999999发送后返回");
try {
JSONObject datas = JSONObject.parseObject(entity.getSourceData());
logger.error("999999发送后返回data"+datas.toJSONString());
String bodys = datas.getString("body");
logger.error("999999发送后返回bodys"+bodys);
JSONObject jsonObject = JSONObject.parseObject(bodys);
logger.error("999999发送后返回jsonObject"+jsonObject.toJSONString());
String urlData = null;
String ofdurlData = null;
String xmlurlData = null;
logger.error("999999发送后返回url");
if(jsonObject.getString("url") != null){
urlData = sendFileUpload(jsonObject.getString("url"),jsonObject.getString("fphm")+"url");
urlData = sendFileUpload(jsonObject.getString("url"));
}
logger.error("999999发送后返回ofdurl");
if(jsonObject.getString("ofdurl") != null){
ofdurlData = sendFileUpload(jsonObject.getString("ofdurl"),jsonObject.getString("fphm")+"ofdurl");
ofdurlData = sendFileUpload(jsonObject.getString("ofdurl"));
}
logger.error("999999发送后返回xmlurl");
if(jsonObject.getString("xmlurl") != null){
xmlurlData = sendFileUpload(jsonObject.getString("xmlurl"),jsonObject.getString("fphm")+"xmlurl");
xmlurlData = sendFileUpload(jsonObject.getString("xmlurl"));
}
//urlData = "7908556313791579509";
//ofdurlData = "7908556313791579509";
//xmlurlData = "7908556313791579509";
logger.error("999999发送后返回fphm");
if(jsonObject.getString("fphm") != null){
IncomeInvoiceEntity incomeInvoiceEntity = new IncomeInvoiceEntity();
incomeInvoiceEntity.setDataSourceCode("HT-OA");
incomeInvoiceEntity.setField0128(jsonObject.getString("fphm"));//发票号码
incomeInvoiceEntity.setField0130(urlData);//发票文件
incomeInvoiceEntity.setField0138(ofdurlData);//发票文件
incomeInvoiceEntity.setField0139(xmlurlData);//发票文件
List<IncomeInvoiceEntity> list = incomeInvoiceDao.queryOaFp(incomeInvoiceEntity);
logger.error("999999查询formmain_0705"+list.size() );
if(list != null && list.size() == 1){
incomeInvoiceEntity.setDataId(list.get(0).getDataId());
logger.error("999999保存关联表url"+list.get(0).getDataId());
if(urlData != null){
//保存关联表
String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
incomeInvoiceEntity.setField0130(urluuid);//发票文件
ctpAttachmentService.saveAttachment(urlData,list.get(0).getDataId().toString(),urluuid,incomeInvoiceEntity.getDataSourceCode());
}
logger.error("999999保存关联表ofdurlData"+list.get(0).getDataId());
if(ofdurlData != null){
//保存关联表
String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
incomeInvoiceEntity.setField0138(urluuid);//发票文件
ctpAttachmentService.saveAttachment(ofdurlData,list.get(0).getDataId().toString(),urluuid,incomeInvoiceEntity.getDataSourceCode());
}
logger.error("999999保存关联表xmlurlData"+list.get(0).getDataId());
if(xmlurlData != null){
//保存关联表
String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
incomeInvoiceEntity.setField0139(urluuid);//发票文件
ctpAttachmentService.saveAttachment(xmlurlData,list.get(0).getDataId().toString(),urluuid,incomeInvoiceEntity.getDataSourceCode());
}
logger.error("999999修改发票开始");
incomeInvoiceDao.updateFP(incomeInvoiceEntity);
logger.error("999999修改发票结束");
}
}
//修改明细表
logger.error("999999修改合同开始");
if(jsonObject.getString("htbh") != null){
logger.error("999999修改合同开始1");
IncomeInvoiceEntity incomeInvoiceEntity = new IncomeInvoiceEntity();
incomeInvoiceEntity.setDataSourceCode("HT-OA");
incomeInvoiceEntity.setField0003(jsonObject.getString("htbh"));//合同号
incomeInvoiceEntity.setField0127(jsonObject.getString("fpdm"));//发票代码
incomeInvoiceEntity.setField0128(jsonObject.getString("fphm"));//发票号码
incomeInvoiceEntity.setField0129(jsonObject.getString("jshj"));//发票总额
incomeInvoiceEntity.setField0130(urlData);//发票文件
incomeInvoiceEntity.setField0138(ofdurlData);//发票文件
incomeInvoiceEntity.setField0139(xmlurlData);//发票文件
logger.error("999999查询合同明细");
List<IncomeInvoiceEntity> list = incomeInvoiceDao.queryOaZb(incomeInvoiceEntity);
logger.error("999999查询合同明细"+list.size());
if(list != null && list.size() == 1){
incomeInvoiceEntity.setFormmainId(list.get(0).getDataId());
if(urlData != null){
//保存关联表
String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
ctpAttachmentService.saveAttachment(urlData,list.get(0).getDataId().toString(),urluuid,incomeInvoiceEntity.getDataSourceCode());
}
if(ofdurlData != null){
//保存关联表
String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
ctpAttachmentService.saveAttachment(ofdurlData,list.get(0).getDataId().toString(),urluuid,incomeInvoiceEntity.getDataSourceCode());
}
if(xmlurlData != null){
//保存关联表
String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
ctpAttachmentService.saveAttachment(xmlurlData,list.get(0).getDataId().toString(),urluuid,incomeInvoiceEntity.getDataSourceCode());
}
//logger.error("999999保存合同附件"+list.get(0).getDataId());
//
//if(urlData != null){
// //保存关联表
// String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
//incomeInvoiceEntity.setField0130(urluuid);//发票文件
// ctpAttachmentService.saveAttachment(urlData,list.get(0).getDataId().toString(),urluuid,incomeInvoiceEntity.getDataSourceCode());
//}
//logger.error("999999保存合同附件ofdurlData"+list.get(0).getDataId());
//
//if(ofdurlData != null){
// //保存关联表
// String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
//incomeInvoiceEntity.setField0138(urluuid);//发票文件
// ctpAttachmentService.saveAttachment(ofdurlData,list.get(0).getDataId().toString(),urluuid,incomeInvoiceEntity.getDataSourceCode());
//}
//logger.error("999999保存合同附件xmlurlData"+list.get(0).getDataId());
//
//if(xmlurlData != null){
// //保存关联表
// String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
//incomeInvoiceEntity.setField0138(urluuid);//发票文件
// ctpAttachmentService.saveAttachment(xmlurlData,list.get(0).getDataId().toString(),urluuid,incomeInvoiceEntity.getDataSourceCode());
//}
logger.error("999999查询合同明细"+list.get(0).getDataId());
List<IncomeInvoiceEntity> mxlist = incomeInvoiceDao.queryOaMx(incomeInvoiceEntity);
logger.error("999999查询合同明细结果"+mxlist.size());
if(mxlist != null && mxlist.size() == 1){
logger.error("999999修改合同明细结果"+mxlist.get(0).getDataId());
incomeInvoiceEntity.setDataId(mxlist.get(0).getDataId());
incomeInvoiceDao.updateMx(incomeInvoiceEntity);
logger.error("999999修改合同明细结果完成");
}
if(mxlist == null || mxlist.size() == 0){
incomeInvoiceEntity.setDataId(1);
incomeInvoiceEntity.setDataId(String.valueOf(UUIDLong.longUUID()));
logger.error("999999保存合同明细结果"+incomeInvoiceEntity.getDataId());
incomeInvoiceDao.saveMx(incomeInvoiceEntity);
logger.error("999999保存合同明细结果完成");
}
}
}
logger.error("999999结束");
} catch (Exception e) {
logger.error(e.getMessage());
logger.error("999999"+e.getMessage());
}
}
@ -769,7 +943,7 @@ public class IncomeInvoiceServiceImpl extends BaseService<IncomeInvoiceEntity, S
stringBuffer.append("</value>").append("</column>");
stringBuffer.append("<column name=\"合同编号\">").append("<value>");
stringBuffer.append(jsonObject.getString("htbm") != null?"<![CDATA["+jsonObject.getString("htbm")+"]]>":"");
stringBuffer.append(jsonObject.getString("htbh") != null?"<![CDATA["+jsonObject.getString("htbh")+"]]>":"");
stringBuffer.append("</value>").append("</column>");
stringBuffer.append("<column name=\"发票文件1\">").append("<value>");

View File

@ -27,6 +27,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@ -224,4 +225,13 @@ public class EntranceController {
}
@RequestMapping(value = "/option1")
@ResponseBody
public JsonResultEntity option1(ServletRequest servletRequest, ServletResponse servletResponse) throws Exception {
HttpServletRequest request = (HttpServletRequest) servletRequest;
String queryString = request.getQueryString();
return BaseResult.getSuccessMessageEntity("成功");
}
}

View File

@ -11,8 +11,8 @@ import com.hzya.frame.seeyon.entity.CtpAttachmentEntity;
public interface ICtpAttachmentService extends IBaseService<CtpAttachmentEntity, String> {
/**
* 保存附件关系表
* @param fileUrl ctp_file id
* @param col_summary_id col_summary id
* @param fileUrl ctp_file id fileUrl
* @param col_summary_id col_summary id oa表单id
* @param sub_reference 随机uuid
* @return
*/

View File

@ -61,7 +61,7 @@ public class CtpAttachmentServiceImpl extends BaseService<CtpAttachmentEntity, S
ctpAttachmentEntity.setFile_url(ctpFile.getId());//ctp_file表的id
ctpAttachmentEntity.setAtt_reference(col_summary_id);//业务表单的id
ctpAttachmentEntity.setSub_reference(sub_reference);//这个字段要保存到业务表附件到字段上
ctpAttachmentEntity.setCategory(ctpFile.getCategory());//这里写66 才可以显示图片
ctpAttachmentEntity.setCategory("66");//这里写66 才可以显示图片
ctpAttachmentEntity.setFilename(ctpFile.getFilename());
ctpAttachmentEntity.setType(ctpFile.getType());
ctpAttachmentEntity.setMime_type(ctpFile.getMime_type());