中信下发和有度开票结果查询

This commit is contained in:
hecan 2025-04-28 11:07:48 +08:00
parent 8ab88a9acb
commit 915317d4c7
7 changed files with 314 additions and 163 deletions

View File

@ -1092,26 +1092,6 @@ public class InvoiceDistributePluginInitializer extends PluginBaseEntity {
headers.putAll(header);
}
if (SysEnum.NEED_LOGIN.getValue().equals(apiEntity.getNeedLogin())) {
/* logger.info("=========正常开票申请单申请数据新增开始执行登录接口==============");
//找到登陆接口
SysApplicationApiEntity loginApi = sysApplicationApiDao.get(apiEntity.getAuthenticationPort());
if (null == loginApi) {
saveMdmModuleSendLogEntity(mainCode,mdmModuleDistributeEntities.get(i1).getId(),"2","发送错误,认证接口不存在",mainDb,objects.get(i).getString("id"),sysApplicationEntity.getName(),sysApplicationEntity.getId(),apiEntity.getApiName(),apiEntity.getId(),doObjects.get(i).toJSONString(),"1");
continue;
}
String rzquerys = getQuery(loginApi,null,null);
Map<String, String> headersa = new HashMap<>();
headersa.put("publicKey", "ZJYAWb7lhAUTYqekPkU+uHJv1/ObJxb7dT7sD8HPRDGAgyhCe7eDIk+3zDUT+v578prj");
headersa.put("secretKey", "fviZnLBsQUAGF8w8FSOdJi7XlIm/XAZclMxRagDLfTyJFlvnIBF3w66Hrpfzs8cYj3JzOP8MtA1LSGvL+2BWG8c/o7DKi92S4mr3zcGearA=");
headersa.put("appId", sysApplicationEntity.getAppId().toString());
headersa.put("apiCode", loginApi.getApiCode().toString());
Map<String, String> rzheaders = getHeaders(loginApi,headersa,null);
String rzbodys = getBodys(loginApi,null,null);
JsonResultEntity rzjsonResultEntity = sendData(loginApi,rzheaders,rzbodys,rzquerys);
if (!rzjsonResultEntity.isFlag()) {
saveMdmModuleSendLogEntity(mainCode,mdmModuleDistributeEntities.get(i1).getId(),"2","发送错误,认证接口错误",mainDb,objects.get(i).getString("id"),sysApplicationEntity.getName(),sysApplicationEntity.getId(),apiEntity.getApiName(),apiEntity.getId(),doObjects.get(i).toJSONString(),"1");
continue;
}*/
JSONObject jsonObject=new JSONObject();
jsonObject.put("accessKey","6X3B526P5HqE6ums");
jsonObject.put("accessSecret","34e5fc32ac894a2ba2ade8c3852c7a0a");
@ -1168,11 +1148,27 @@ public class InvoiceDistributePluginInitializer extends PluginBaseEntity {
mdmModuleDistributeTripartiteEntity.setAppId(sysApplicationEntity.getId());
mdmModuleDistributeTripartiteEntity.setTripartiteId(backJsonResultEntity.getString("tripartiteId"));
mdmModuleDistributeTripartiteDao.save(mdmModuleDistributeTripartiteEntity);
//修改下发状态
logger.info("===开票申请单申请正常下发时候完毕更新新增状态为1=======");
Map<String, Object> updateMap = new HashMap<>();
updateMap.put("tableName",mainDb);
//updateMap.put("dataStatus", "Y");
updateMap.put("addStatus", "1");
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
}
}
} catch (Exception e) {
logger.error("开票申请单申请下发新增返回脚本解析保存三方id错误"+jsonResultEntity.getAttribute());
saveMdmModuleSendLogEntity(mainCode,mdmModuleDistributeEntities.get(i1).getId(),"2","新增返回脚本解析保存三方id错误",mainDb,objects.get(i).getString("id"),sysApplicationEntity.getName(),sysApplicationEntity.getId(),apiEntity.getApiName(),apiEntity.getId(),doObjects.get(i).toJSONString(),"1");
//修改下发状态
logger.info("===开票申请单申请正常下发时候完毕更新新增状态为2=======");
Map<String, Object> updateMap = new HashMap<>();
updateMap.put("tableName",mainDb);
//updateMap.put("dataStatus", "Y");
updateMap.put("addStatus", "2");
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
continue;
}
}
@ -1186,12 +1182,20 @@ public class InvoiceDistributePluginInitializer extends PluginBaseEntity {
saveMdmModuleSendLogEntity(mainCode,mdmModuleDistributeEntities.get(i1).getId(),"2","转发失败:"+jsonResultEntity.getAttribute(),mainDb,objects.get(i).getString("id"),sysApplicationEntity.getName(),sysApplicationEntity.getId(),apiEntity.getApiName(),apiEntity.getId(),doObjects.get(i).toJSONString(),"1");
objects.get(i).put("sendsanfzt123",false);
logger.info("========开票申请单申请数据新增下发完成,日志保存为失败============");
//修改下发状态
logger.info("===开票申请单申请正常下发时候完毕更新新增状态为2=======");
Map<String, Object> updateMap = new HashMap<>();
updateMap.put("tableName",mainDb);
//updateMap.put("dataStatus", "Y");
updateMap.put("addStatus", "2");
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
continue;
}
}
}
//所有下发发送完成修改数据状态
/* //所有下发发送完成修改数据状态
for (int i = 0; i < objects.size(); i++) {
if(objects.get(i).getBoolean("sendsanfzt123")){
Map<String, Object> updateMap = new HashMap<>();
@ -1201,7 +1205,7 @@ public class InvoiceDistributePluginInitializer extends PluginBaseEntity {
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
}
}
}*/
}
private void saveMdmModuleSendLogEntity(Long mdmCode,String distributeId,String dataType,String remark,String dbname,String formmain_id, String target_app, String appId, String target_api,String apiID, String source_data, String option_type) throws Exception {

View File

@ -826,7 +826,7 @@ public class ZxBankDistributePluginInitializer extends PluginBaseEntity {
/** body */
String bodys = doObjects.get(i).toJSONString();
if(scriptEntity != null && scriptEntity.getId() != null ){
logger.info("=========开始执行正常主数据修改下发脚本,第一次==============");
logger.info("=========开始执行正常中信司库付款单修改下发脚本,第一次==============");
groovy.put("code",scriptEntity.getScriptCode());
groovy.put("className",scriptEntity.getClassName());
groovy.put("name",scriptEntity.getScriptName());
@ -854,7 +854,7 @@ public class ZxBankDistributePluginInitializer extends PluginBaseEntity {
headers.putAll(header);
}
if (SysEnum.NEED_LOGIN.getValue().equals(apiEntity.getNeedLogin())) {
logger.info("=========正常主数据修改开始执行登录接口==============");
logger.info("=========正常中信司库付款单修改开始执行登录接口==============");
//找到登陆接口
SysApplicationApiEntity loginApi = sysApplicationApiDao.get(apiEntity.getAuthenticationPort());
if (null == loginApi) {
@ -875,28 +875,42 @@ public class ZxBankDistributePluginInitializer extends PluginBaseEntity {
continue;
}
JSONObject attritube = JSONObject.parseObject(rzjsonResultEntity.getAttribute().toString());
logger.info("=======主数据正常修改下发登录返回数据:{}========",attritube.toJSONString());
logger.info("=======中信司库付款单正常修改下发登录返回数据:{}========",attritube.toJSONString());
querys = getQuery(apiEntity,querys,attritube);
headers = getHeaders(apiEntity,headers,attritube);
bodys = getBodys(apiEntity,bodys,attritube);
}
//组装数据发送
logger.info("=========开始执行主业务修改数据下发脚本,第二次==============");
logger.info("=========开始执行中信司库付款单修改数据下发脚本,第二次==============");
JsonResultEntity jsonResultEntity = sendData(apiEntity,headers,bodys,querys);
logger.info("=====主数据修改下发返回结果为:{}",JSONObject.parseObject(jsonResultEntity.getAttribute().toString()).toJSONString());
logger.info("=====中信司库付款单修改下发返回结果为:{}",JSONObject.parseObject(jsonResultEntity.getAttribute().toString()).toJSONString());
if(jsonResultEntity.isFlag()){
//保存日志
saveMdmModuleSendLogEntity(mainCode,mdmModuleDistributeEntities.get(i1).getId(),"1","发送成功",mainDb,objects.get(i).getString("id"),sysApplicationEntity.getName(),sysApplicationEntity.getId(),apiEntity.getApiName(),apiEntity.getId(),doObjects.get(i).toJSONString(),"2");
//修改下发状态
logger.info("===中信司库付款单正常下发时候完毕更新新增状态为1=======");
Map<String, Object> updateMap = new HashMap<>();
updateMap.put("tableName",mainDb);
//updateMap.put("dataStatus", "F");
updateMap.put("updateStatus", "1");
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
continue;
}else {
//保存日志
saveMdmModuleSendLogEntity(mainCode,mdmModuleDistributeEntities.get(i1).getId(),"2","转发失败:"+jsonResultEntity.getAttribute(),mainDb,objects.get(i).getString("id"),sysApplicationEntity.getName(),sysApplicationEntity.getId(),apiEntity.getApiName(),apiEntity.getId(),doObjects.get(i).toJSONString(),"2");
Map<String, Object> updateMap = new HashMap<>();
updateMap.put("tableName",mainDb);
//updateMap.put("dataStatus", "F");
updateMap.put("updateStatus", "2");
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
continue;
}
}
}
//所有下发发送完成修改数据状态
/*//所有下发发送完成修改数据状态
for (int i = 0; i < objects.size(); i++) {
Map<String, Object> updateMap = new HashMap<>();
updateMap.put("tableName",mainDb);
@ -904,7 +918,7 @@ public class ZxBankDistributePluginInitializer extends PluginBaseEntity {
updateMap.put("updateStatus", "1");
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
}
}*/
}
/**
@ -1083,19 +1097,19 @@ public class ZxBankDistributePluginInitializer extends PluginBaseEntity {
continue;
}
JSONObject attritube = JSONObject.parseObject(rzjsonResultEntity.getAttribute().toString());
logger.info("=======数据正常新增下发登录返回数据:{}========",attritube.toJSONString());
logger.info("=======中信司库付款单数据正常新增下发登录返回数据:{}========",attritube.toJSONString());
querys = getQuery(apiEntity,querys,attritube);
headers = getHeaders(apiEntity,headers,attritube);
bodys = getBodys(apiEntity,bodys,attritube);
}
//组装数据发送
logger.info("=========开始执行主业务新增数据下发脚本,第二次==============");
logger.info("=========开始执行中信司库付款单新增数据下发脚本,第二次==============");
JsonResultEntity jsonResultEntity = sendData(apiEntity,headers,bodys,querys);
logger.info("=====主数据新增下发返回结果为:{}",JSONObject.parseObject(jsonResultEntity.getAttribute().toString()).toJSONString());
logger.info("=====中信司库付款单新增下发返回结果为:{}",JSONObject.parseObject(jsonResultEntity.getAttribute().toString()).toJSONString());
if(jsonResultEntity.isFlag()){
if (scriptEntity != null && scriptEntity.getId() != null && scriptEntity.getBackScriptData() != null ) {
logger.info("=========开始执行主数据新增返回脚本==============");
logger.info("=========开始执行中信司库付款单新增返回脚本==============");
JSONObject backScriptJson = new JSONObject();
backScriptJson.put("data", jsonResultEntity.getAttribute());
groovy.put("code", scriptEntity.getScriptCode()+"back");
@ -1124,30 +1138,54 @@ public class ZxBankDistributePluginInitializer extends PluginBaseEntity {
mdmModuleDistributeTripartiteEntity.setAppId(sysApplicationEntity.getId());
mdmModuleDistributeTripartiteEntity.setTripartiteId(backJsonResultEntity.getString("tripartiteId"));
mdmModuleDistributeTripartiteDao.save(mdmModuleDistributeTripartiteEntity);
//修改下发状态
logger.info("===中信司库付款单正常下发时候完毕更新新增状态为1=======");
Map<String, Object> updateMap = new HashMap<>();
updateMap.put("tableName",mainDb);
//updateMap.put("dataStatus", "Y");
updateMap.put("addStatus", "1");
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
}
}
} catch (Exception e) {
logger.error("新增返回脚本解析保存三方id错误"+jsonResultEntity.getAttribute());
logger.error("中信司库付款单新增返回脚本解析保存三方id错误"+jsonResultEntity.getAttribute());
saveMdmModuleSendLogEntity(mainCode,mdmModuleDistributeEntities.get(i1).getId(),"2","新增返回脚本解析保存三方id错误",mainDb,objects.get(i).getString("id"),sysApplicationEntity.getName(),sysApplicationEntity.getId(),apiEntity.getApiName(),apiEntity.getId(),doObjects.get(i).toJSONString(),"1");
//修改下发状态
logger.info("===中信司库付款单正常下发时候完毕更新新增状态为2=======");
Map<String, Object> updateMap = new HashMap<>();
updateMap.put("tableName",mainDb);
//updateMap.put("dataStatus", "Y");
updateMap.put("addStatus", "2");
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
continue;
}
}
//保存日志
saveMdmModuleSendLogEntity(mainCode,mdmModuleDistributeEntities.get(i1).getId(),"1","发送成功",mainDb,objects.get(i).getString("id"),sysApplicationEntity.getName(),sysApplicationEntity.getId(),apiEntity.getApiName(),apiEntity.getId(),doObjects.get(i).toJSONString(),"1");
objects.get(i).put("sendsanfzt123",true);
logger.info("========主数据新增下发完成,日志保存为成功============");
logger.info("========中信司库付款单新增下发完成,日志保存为成功============");
continue;
}else {
//保存日志
saveMdmModuleSendLogEntity(mainCode,mdmModuleDistributeEntities.get(i1).getId(),"2","转发失败:"+jsonResultEntity.getAttribute(),mainDb,objects.get(i).getString("id"),sysApplicationEntity.getName(),sysApplicationEntity.getId(),apiEntity.getApiName(),apiEntity.getId(),doObjects.get(i).toJSONString(),"1");
objects.get(i).put("sendsanfzt123",false);
logger.info("========主数据新增下发完成,日志保存为失败============");
logger.info("========中信司库付款单新增下发完成,日志保存为失败============");
//修改下发状态
logger.info("===中信司库付款单正常下发时候完毕更新新增状态为2=======");
Map<String, Object> updateMap = new HashMap<>();
updateMap.put("tableName",mainDb);
//updateMap.put("dataStatus", "Y");
updateMap.put("addStatus", "2");
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
continue;
}
}
}
//所有下发发送完成修改数据状态
/* //所有下发发送完成修改数据状态
for (int i = 0; i < objects.size(); i++) {
if(objects.get(i).getBoolean("sendsanfzt123")){
Map<String, Object> updateMap = new HashMap<>();
@ -1157,7 +1195,7 @@ public class ZxBankDistributePluginInitializer extends PluginBaseEntity {
updateMap.put("id", objects.get(i).getString("id"));
mdmModuleDao.updateMdmSTs(updateMap);
}
}
}*/
}
private void saveMdmModuleSendLogEntity(Long mdmCode,String distributeId,String dataType,String remark,String dbname,String formmain_id, String target_app, String appId, String target_api,String apiID, String source_data, String option_type) throws Exception {

View File

@ -3,10 +3,21 @@ package com.hzya.frame.seeyon.dao;
import com.hzya.frame.basedao.dao.IBaseDao;
import com.hzya.frame.seeyon.entity.CtpFileEntity;
import java.util.List;
/**
* @Description seeyon 附件对象
* @Author xiangerlin
* @Date 2024/6/17 15:21
**/
public interface ICtpFileDao extends IBaseDao<CtpFileEntity,String> {
/**
*
* @content 根据附件id查询附加信息
* @Param
* @Return
* @Author hecan
* @Date 2025-04-27 18:03
* **/
List<CtpFileEntity> queryCtpFileById(CtpFileEntity ctpFileEntity);
}

View File

@ -1,12 +1,13 @@
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.ICtpAttachmentDao;
import com.hzya.frame.seeyon.dao.ICtpFileDao;
import com.hzya.frame.seeyon.entity.CtpAttachmentEntity;
import com.hzya.frame.seeyon.entity.CtpFileEntity;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* @Description
* @Author xiangerlin
@ -14,4 +15,9 @@ import org.springframework.stereotype.Repository;
**/
@Repository()
public class CtpFileDaoImpl extends MybatisGenericDao<CtpFileEntity,String> implements ICtpFileDao {
@DS("#ctpFileEntity.dataSourceCode")
@Override
public List<CtpFileEntity> queryCtpFileById(CtpFileEntity ctpFileEntity) {
return (List<CtpFileEntity>) super.selectList("queryCtpFileById",ctpFileEntity);
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!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.CtpFileEntity">
<mapper namespace="com.hzya.frame.seeyon.dao.impl.CtpFileDaoImpl">
<resultMap id="get-CtpFileEntity-result" type="com.hzya.frame.seeyon.entity.CtpFileEntity">
<!--主键 -->
<result property="id" column="id" />
@ -45,5 +45,17 @@
</trim>
</select>
<!-- 查询 采用==查询 -->
<select id="queryCtpFileById" resultMap="get-CtpFileEntity-result" parameterType="com.hzya.frame.seeyon.entity.CtpFileEntity">
select
<include refid="CtpFileEntity_sql"/>
from
ctp_file
<trim prefix="where" prefixOverrides="and">
<if test="id != null and id != ''">id = #{id}</if>
<if test="filename != null and filename != ''">and filename = #{filename}</if>
</trim>
</select>
</mapper>

View File

@ -95,7 +95,7 @@
<!--通过主键修改方法-->
<update id="updateInvoiceUrl" parameterType = "com.hzya.frame.seeyon.invoice.entity.InvoiceEntity" >
update ${tabName} set ${url_field} =#{url} where id=#{id}
update formmain_0331 set ${url_field} =#{url} where id=#{id}
</update>
<!--通过主键修改方法-->
@ -105,7 +105,7 @@
<!--通过主键修改方法-->
<update id="updateInvoiceResult" parameterType = "com.hzya.frame.seeyon.invoice.entity.InvoiceEntity" >
update ${tabName} set
update formmain_0331 set
<trim suffix="" suffixOverrides=",">
<if test="input_result_status != null and input_result_status != ''"> ${input_result_status_filed} = #{input_result_status},</if>
<if test="invoice_code != null and invoice_code != ''"> ${invoice_code_field} = #{invoice_code},</if>

View File

@ -1,6 +1,8 @@
package com.hzya.frame.seeyon.invoice.service.impl;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
@ -8,7 +10,9 @@ import com.hzya.frame.basedao.service.impl.BaseService;
import com.hzya.frame.mdm.mdmModuleSource.dao.impl.MdmModuleSourceDaoImpl;
import com.hzya.frame.mdm.mdmModuleSource.entity.MdmModuleSourceEntity;
import com.hzya.frame.seeyon.dao.ICtpAttachmentDao;
import com.hzya.frame.seeyon.dao.ICtpFileDao;
import com.hzya.frame.seeyon.entity.CtpAttachmentEntity;
import com.hzya.frame.seeyon.entity.CtpFileEntity;
import com.hzya.frame.seeyon.invoice.dao.IInvoiceDao;
import com.hzya.frame.seeyon.invoice.dao.IInvoiceDetailsDao;
import com.hzya.frame.seeyon.invoice.entity.InvoiceEntity;
@ -31,11 +35,16 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.cert.X509Certificate;
import java.util.*;
@Service(value = "InvoiceServiceImpl")
@ -54,6 +63,9 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
private ComparisonServiceImpl comparisonServiceimpl;
@Autowired
private ICtpAttachmentDao ctpAttachmentDao;
@Autowired
private ICtpFileDao ctpFileDao;
@Value("${zt.url}")
private String url;
@ -152,17 +164,9 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
return BaseResult.getSuccessMessageEntity("查询成功");
}
for (InvoiceEntity entity : invoiceEntities) {
long timestamp = System.currentTimeMillis();
Map<String, Object> parametersMap = new HashMap<>();
parametersMap.put("accessKey","6X3B526P5HqE6ums");
parametersMap.put("timestamp",timestamp);
String sign = YzfSignUtil.signRequest(parametersMap,"34e5fc32ac894a2ba2ade8c3852c7a0a");
JSONObject jsonObject=new JSONObject();
jsonObject.put("serialNumber",entity.getId());
jsonObject.put("accessKey","6X3B526P5HqE6ums");
jsonObject.put("sign",sign);
jsonObject.put("timestamp",timestamp);
logger.info("=======调用杭泰税务查询申请单详情的请求参数为:{}=======",jsonObject.toJSONString());
entity.setDataSourceCode("HT-OA");
JSONObject jsonObject = new JSONObject();
jsonObject.put("serialNumber", entity.getSerial_number());
//发送数据
String result = HttpRequest.post(url).
header("appId", "800060").
@ -172,17 +176,17 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
body(jsonObject.toJSONString()).
execute().
body();
logger.info("=====调用杭泰税务查询申请单详情的返回参数为:{}===========",result);
logger.info("=====调用杭泰税务查询申请单详情的返回参数为:{}===========", result);
JSONObject resultJson = JSONObject.parseObject(result);
if (!resultJson.getBoolean("flag")) {
saveTaskLivingDetails(entity.getId(), entity.getBusiness_no(), jsonObject.toJSONString(), resultJson.toJSONString(), false,"");
saveTaskLivingDetails(entity.getId(), entity.getBusiness_no(), jsonObject.toJSONString(), resultJson.toJSONString(), false, "");
} else {
JSONObject attribute = resultJson.getJSONObject("attribute");
if("0".equals(attribute.getString("code"))){
JSONObject jsonResult=JSONObject.parseObject(attribute.getString("result"));
if(null !=jsonResult){
if ("0".equals(attribute.getString("code"))) {
JSONObject jsonResult = JSONObject.parseObject(attribute.getString("result"));
if (null != jsonResult && jsonResult.getString("serialNumber").equals(entity.getSerial_number())) {
JSONArray jsonArray = jsonResult.getJSONArray("invoiceInfoVOList");
if(CollectionUtils.isNotEmpty(jsonArray)){
if (CollectionUtils.isNotEmpty(jsonArray)) {
for (int i = 0; i < jsonArray.size(); i++) {
//表单的附件字段=ctpAttachment的Sub_reference表单的Summary_id=ctpAttachment的att_reference
String sub_reference = String.valueOf(UUIDLong.longUUID());
@ -194,29 +198,35 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
entity.setInvoice_code(invoiceCode);
entity.setInvoice_number(invoiceNumber);
entity.setResult_status(resultStatus);
entity.setId(entity.getSerial_number());
//将开票结果发票号码发票代码回写OA
logger.info("=======开始将开票结果发票号码发票代码回写OA======");
invoiceDao.updateInvoiceResult(entity);
logger.info("=======将开票结果发票号码发票代码回写OA完毕======");
if (null != invoiceInfo.getString("url") || null != invoiceInfo.getString("ofdUrl")) {
String pdfUrl = invoiceInfo.getString("url");//pdf文件
String ofdUrl = invoiceInfo.getString("ofdUrl");//ofd文件
String xmlUrl = invoiceInfo.getString("xmlUrl");//xml文件
//获取pdf文件到本地 并为pdf取名否则会报无法访问错误
logger.info("========开始将pdf文件保存到本地========");
String pdfFileName = generateFileName(pdfUrl, "pdf");
String pdfFileName = generateFileName(pdfUrl, "PDF");
String pdfSavePath = invoicePdfUrl + pdfFileName;
downloadPdf(pdfUrl, pdfSavePath);
logger.info("========pdf文件保存到本地完成========");
File filePdf = new File(pdfSavePath);
if(null !=filePdf){
logger.info("========开始将pdf文件上传OA========");
ManyfileUpload(filePdf, entity, sub_reference, att_reference, jsonObject);
logger.info("========pdf文件上传OA完成========");
}
//获取ofd文件到本地
logger.info("========开始将ofd文件保存到本地========");
String ofdFileName = generateFileName(ofdUrl, "ofd");
String ofdSavePath = ofdUrl + ofdFileName;
String ofdFileName = generateFileName(ofdUrl, "OFD");
String ofdSavePath = invoiceOfdUrl + ofdFileName;
downloadPdf(ofdUrl, ofdSavePath);
logger.info("========ofd文件保存到本地完成========");
File fileOfd = new File(ofdSavePath);
if(null !=fileOfd){
logger.info("========开始将ofd文件上传OA========");
ManyfileUpload(fileOfd, entity, sub_reference, att_reference, jsonObject);
logger.info("========ofd文件上传OA完成========");
@ -226,10 +236,10 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
}
}
}
}
}
}catch (Exception e){
logger.info("======查询杭泰税务申请单详情失败====",e.getMessage());
logger.info("======查询杭泰税务申请单详情失败:{}====",e.getMessage());
e.printStackTrace();
}
return null;
@ -248,17 +258,9 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
return BaseResult.getSuccessMessageEntity("查询成功");
}
for (InvoiceEntity entity : invoiceEntities) {
long timestamp = System.currentTimeMillis();
Map<String, Object> parametersMap = new HashMap<>();
parametersMap.put("accessKey","6X3B526P5HqE6ums");
parametersMap.put("timestamp",timestamp);
String sign = YzfSignUtil.signRequest(parametersMap,"34e5fc32ac894a2ba2ade8c3852c7a0a");
entity.setDataSourceCode("HT-OA");
JSONObject jsonObject=new JSONObject();
jsonObject.put("serialNumber",entity.getId());
jsonObject.put("accessKey","6X3B526P5HqE6ums");
jsonObject.put("sign",sign);
jsonObject.put("timestamp",timestamp);
logger.info("=======调用杭泰税务查询发票批量录入结果的请求参数为:{}=======",jsonObject.toJSONString());
//发送数据
String result = HttpRequest.post(url).
header("appId", "800060").
@ -293,18 +295,29 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
}
}
}catch (Exception e){
logger.info("======查询杭泰税务发票批量录入结果失败====",e.getMessage());
logger.info("======查询杭泰税务发票批量录入结果失败:{}====",e.getMessage());
e.printStackTrace();
}
return null;
}
private void ManyfileUpload(File file,InvoiceEntity entity,String sub_reference,String att_reference,JSONObject jsonObject){
JSONObject jsonObjectOfd = OARestUtil.fileUpload(file,"8000590003","8000590001");
logger.info("=======文件名称为:{}=====",file.getName());
if(null !=file) {
JSONObject jsonObjectOfd = fileUploadPdfAndOfd(file);
if (jsonObjectOfd.getString("fileUrl") != null) {
entity.setUrl(sub_reference);
entity.setDataSourceCode("HT-OA");
logger.info("===========查询开票详情开始将附件id更新OA==========");
invoiceDao.updateInvoiceUrl(entity);
logger.info("===========查询开票详情将附件id更新OA完毕==========");
//根据附件id查询附件信息
CtpFileEntity ctpFileEntity=new CtpFileEntity();
ctpFileEntity.setId(jsonObjectOfd.getString("fileUrl"));
ctpFileEntity.setDataSourceCode("HT-OA");
List<CtpFileEntity> query = ctpFileDao.queryCtpFileById(ctpFileEntity);
if(CollectionUtils.isNotEmpty(query)) {
CtpFileEntity ctpFile = query.get(0);
//根据附件id查询附件业务数据
String file_url = jsonObjectOfd.getString("fileUrl");
CtpAttachmentEntity ctpAttachmentEntity = new CtpAttachmentEntity();
@ -315,11 +328,11 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
List<CtpAttachmentEntity> ctpAttachmentEntities = ctpAttachmentDao.queryCtpAttachment(ctpAttachmentEntity);
//如果没有查询到数据就新增附件业务否则更新
if (ctpAttachmentEntities.size() == 0) {
String category = jsonObject.getString("category");
String type = jsonObject.getString("type");
String filename = jsonObject.getString("filename");
String mime_type = jsonObject.getString("mimeType");
String attachment_size = jsonObject.getString("size");
String category =ctpFile.getCategory();
String type =ctpFile.getType();
String filename =ctpFile.getFilename();
String mime_type =ctpFile.getMime_type();
String attachment_size =ctpFile.getFile_size();
String id = String.valueOf(UUIDLong.longUUID());
ctpAttachmentEntity.setCategory(category);
ctpAttachmentEntity.setFilename(filename);
@ -339,15 +352,68 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
ctpAttachmentDao.updateCtpAttachment(ctpAttachmentEntity);
}
logger.info("=====电子回单执行完毕=======");
}else{
logger.info("========根据附件id:{}没有查询到附件信息======",jsonObjectOfd.getString("fileUrl"));
}
}
file.delete();
}else{
logger.info("==========本地没有文件==============");
}
}
public JSONObject fileUploadPdfAndOfd(File file) {
if (null != file) {
try {
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("file", file);
String url = "/seeyon/rest/attachment?token=@token@";//如果后面加上applicationCategory=1&extensions=&firstSave=true附件业务自动生成一条记录
url = url.replaceAll("@token@", getToken());
String result = HttpUtil.post("http://60.204.152.210" + url, paramMap);
if (StrUtil.isNotBlank(result)) {
logger.info("附件上传结果"+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 getToken() {
//获取oatoken
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("userName", "hzyaRest");
hashMap.put("password", "a5ce21b8-91db-4cec-b3e3-3e44719655fd");
hashMap.put("loginName","bdmanager");
String result = HttpUtil.post("http://60.204.152.210" + "/seeyon/rest/token", JSON.toJSONString(hashMap));
JSONObject jsonObject = JSONObject.parseObject(result);
if (null != jsonObject) {
logger.info(result);
logger.info("======token{}======" + jsonObject.getString("id"));
return jsonObject.getString("id");
}
return null;
}
private void downloadPdf(String pdfUrl, String savePath) {
try {
URL url = new URL(pdfUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("Post");
// 处理 HTTPS 证书测试环境忽略验证生产环境需移除
if (pdfUrl.startsWith("https")) {
trustAllCertificates((HttpsURLConnection) connection);
}
connection.setRequestMethod("GET");
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream inputStream = connection.getInputStream();
@ -371,6 +437,20 @@ public class InvoiceServiceImpl extends BaseService<InvoiceEntity, String> imple
}
}
private static void trustAllCertificates(HttpsURLConnection conn) throws Exception {
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
@Override public void checkClientTrusted(X509Certificate[] chain, String authType) {}
@Override public void checkServerTrusted(X509Certificate[] chain, String authType) {}
@Override public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
}
};
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
conn.setSSLSocketFactory(sslContext.getSocketFactory());
conn.setHostnameVerifier((hostname, session) -> true); // 忽略主机名验证
}
private String generateFileName(String url, String extension) {
// 这里简单根据 URL 的参数生成文件名你可以根据实际需求调整
String[] parts = url.split("&");