诺诺发票
This commit is contained in:
parent
ef4c20645e
commit
1f35e82be3
|
@ -4,7 +4,10 @@ package com.hzya.frame.seeyon.dao;
|
|||
import com.hzya.frame.basedao.dao.IBaseDao;
|
||||
import com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface INuoNuoCallbackDao extends IBaseDao<NuoNuoCallbackEntity, String> {
|
||||
|
||||
List<NuoNuoCallbackEntity> queryOaData(NuoNuoCallbackEntity queryData);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,21 @@
|
|||
package com.hzya.frame.seeyon.dao.impl;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.hzya.frame.basedao.dao.MybatisGenericDao;
|
||||
import com.hzya.frame.seeyon.dao.INuoNuoCallbackDao;
|
||||
import com.hzya.frame.seeyon.entity.CtpAttachmentEntity;
|
||||
import com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository(value = "NuoNuoCallbackDaoImpl")
|
||||
public class NuoNuoCallbackDaoImpl extends MybatisGenericDao<NuoNuoCallbackEntity, String> implements INuoNuoCallbackDao {
|
||||
|
||||
@DS("#entity.dataSourceCode")
|
||||
@Override
|
||||
public List<NuoNuoCallbackEntity> queryOaData(NuoNuoCallbackEntity entity) {
|
||||
return (List<NuoNuoCallbackEntity>) super.selectList(getSqlIdPrifx()+"queryOaData",entity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,5 +4,71 @@ import com.hzya.frame.web.entity.BaseEntity;
|
|||
|
||||
public class NuoNuoCallbackEntity extends BaseEntity {
|
||||
|
||||
private String id;
|
||||
private String field0001;//单据号
|
||||
private String field0150;//发票号码
|
||||
private String field0151;//开票日期
|
||||
private String field0188;//发票代码
|
||||
private String field0152;//开票结果
|
||||
private String field0153;//电子发票
|
||||
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getField0001() {
|
||||
return field0001;
|
||||
}
|
||||
|
||||
public void setField0001(String field0001) {
|
||||
this.field0001 = field0001;
|
||||
}
|
||||
|
||||
public String getField0150() {
|
||||
return field0150;
|
||||
}
|
||||
|
||||
public void setField0150(String field0150) {
|
||||
this.field0150 = field0150;
|
||||
}
|
||||
|
||||
public String getField0151() {
|
||||
return field0151;
|
||||
}
|
||||
|
||||
public void setField0151(String field0151) {
|
||||
this.field0151 = field0151;
|
||||
}
|
||||
|
||||
public String getField0188() {
|
||||
return field0188;
|
||||
}
|
||||
|
||||
public void setField0188(String field0188) {
|
||||
this.field0188 = field0188;
|
||||
}
|
||||
|
||||
public String getField0152() {
|
||||
return field0152;
|
||||
}
|
||||
|
||||
public void setField0152(String field0152) {
|
||||
this.field0152 = field0152;
|
||||
}
|
||||
|
||||
public String getField0153() {
|
||||
return field0153;
|
||||
}
|
||||
|
||||
public void setField0153(String field0153) {
|
||||
this.field0153 = field0153;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,5 +2,18 @@
|
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- 查询 采用==查询 -->
|
||||
<select id="queryOaData" resultType="com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity" parameterType="com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity">
|
||||
select
|
||||
id
|
||||
from formmain_11951
|
||||
<trim prefix="where" prefixOverrides="and">
|
||||
<if test="field00001 != null and field00001 !='' ">field00001 = #{field00001} </if>
|
||||
</trim>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
|
|
|
@ -1,16 +1,45 @@
|
|||
package com.hzya.frame.seeyon.service.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hzya.frame.seeyon.dao.INuoNuoCallbackDao;
|
||||
import com.hzya.frame.seeyon.entity.NuoNuoCallbackEntity;
|
||||
import com.hzya.frame.seeyon.service.INuoNuoCallbackService;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.quartz.simpl.SystemPropertyInstanceIdGenerator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
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.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
@Service(value = "nuoNuoCallbackService")
|
||||
public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService {
|
||||
Logger logger = LogManager.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
private INuoNuoCallbackDao nuoNuoCallbackDao;
|
||||
|
||||
/**
|
||||
* @param jsonObject
|
||||
|
@ -55,6 +84,43 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService {
|
|||
}
|
||||
}
|
||||
//查找单据,上传附件
|
||||
NuoNuoCallbackEntity queryData = new NuoNuoCallbackEntity();
|
||||
queryData.setDataSourceCode("");//todo
|
||||
queryData.setField0001(orderNo);
|
||||
List<NuoNuoCallbackEntity> entityList = nuoNuoCallbackDao.queryOaData(queryData);
|
||||
if(entityList == null || entityList.size() == 0){
|
||||
JSONObject returnData = new JSONObject();
|
||||
returnData.put("code","9999");
|
||||
returnData.put("message","根据订单编号查找不到单据");
|
||||
return returnData;
|
||||
}
|
||||
if( entityList.size() > 1){
|
||||
JSONObject returnData = new JSONObject();
|
||||
returnData.put("code","9999");
|
||||
returnData.put("message","根据订单编号查找到多条单据");
|
||||
return returnData;
|
||||
}
|
||||
NuoNuoCallbackEntity nuoNuoCallbackEntity = entityList.get(0);
|
||||
nuoNuoCallbackEntity.setDataSourceCode("");//todo
|
||||
|
||||
//private String field0153;//电子发票
|
||||
nuoNuoCallbackEntity.setField0001(orderNo);//单据号
|
||||
nuoNuoCallbackEntity.setField0150(invoiceNumber);//发票号码
|
||||
nuoNuoCallbackEntity.setField0151(invoiceTime);//开票日期
|
||||
nuoNuoCallbackEntity.setField0188(invoiceCode);//发票代码
|
||||
nuoNuoCallbackEntity.setField0152(errorMessage);//开票结果
|
||||
|
||||
if(pdfUrl != null){
|
||||
String urlData = sendFileUpload(pdfUrl);
|
||||
if(urlData != null){
|
||||
//保存关联表
|
||||
String urluuid = String.valueOf(UUID.randomUUID().getLeastSignificantBits());
|
||||
nuoNuoCallbackEntity.setField0153(urluuid);//发票文件
|
||||
ctpAttachmentService.saveAttachment(urlData,nuoNuoCallbackEntity.getId(),urluuid,nuoNuoCallbackEntity.getDataSourceCode());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//修改单据信息
|
||||
|
||||
|
@ -67,4 +133,126 @@ public class NuoNuoCallbackServiceImpl implements INuoNuoCallbackService {
|
|||
returnData.put("message","业务方接收同步成功");
|
||||
return returnData;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private String sendFileUpload(String fileurl) {
|
||||
try {
|
||||
// 获取文件字节数据
|
||||
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);
|
||||
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
|
||||
fos.write(fileBytes);
|
||||
}
|
||||
|
||||
JSONObject data = fileUpload(tempFile);
|
||||
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) {
|
||||
if (null != file) {
|
||||
try {
|
||||
HashMap<String, Object> paramMap = new HashMap<>();
|
||||
String loginName = "hzya";
|
||||
paramMap.put("file", file);
|
||||
String url = "/seeyon/rest/attachment?token=@token@";//如果后面加上applicationCategory=1&extensions=&firstSave=true,附件业务自动生成一条记录
|
||||
//url = url.replaceAll("@token@", getOAToken(loginName));
|
||||
String result = HttpUtil.post("http://60.204.152.210" + 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue