销售发票红冲接口-代码优化及开票申请的交易类型赋值调整

This commit is contained in:
mzr 2025-04-18 10:43:29 +08:00
parent 15535254f6
commit 3985795952
1 changed files with 81 additions and 60 deletions

View File

@ -102,8 +102,7 @@ public class IAPISaleInvMaitainImpl {
: ResultMessageUtil.exceptionToJSON(new NullPointerException("未知异常")); : ResultMessageUtil.exceptionToJSON(new NullPointerException("未知异常"));
} }
String[] ids = {content}; String[] ids = {content};
SaleInvoiceVO[] saleInvoiceVO = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) SaleInvoiceVO[] saleInvoiceVO = querySaleInvoiceByIds(ids);
.queryVOByIDs(ids);
SaleInvoiceVO saleInvoiceVO22 = saleInvoiceVO[0]; SaleInvoiceVO saleInvoiceVO22 = saleInvoiceVO[0];
SaleInvoiceHVO saleInvoiceHVO = saleInvoiceVO22.getParentVO(); SaleInvoiceHVO saleInvoiceHVO = saleInvoiceVO22.getParentVO();
// 销售发票审核开始 // 销售发票审核开始
@ -156,23 +155,28 @@ public class IAPISaleInvMaitainImpl {
String csaleinvoiceid = bject.getString("vdef40"); String csaleinvoiceid = bject.getString("vdef40");
// 根据销售发票主实体id查询销售发票 // 根据销售发票主实体id查询销售发票
String[] ids = {csaleinvoiceid}; String[] ids = {csaleinvoiceid};
SaleInvoiceVO[] saleInvoiceVOs = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class) SaleInvoiceVO[] saleInvoiceVOs = querySaleInvoiceByIds(ids);
.queryVOByIDs(ids);
if (saleInvoiceVOs == null || saleInvoiceVOs.length <= 0) { if (saleInvoiceVOs == null || saleInvoiceVOs.length <= 0) {
return ResultMessageUtil.exceptionToJSON(new NullPointerException("未在系统中查询到对应的销售发票")); return ResultMessageUtil.exceptionToJSON(new NullPointerException("未在系统中查询到对应的销售发票"));
} }
// 调用函数根据原销售发票组装新红冲发票 // 调用函数根据原销售发票组装新红冲发票
SaleInvoiceVO saleInvoiceRedRushVO = makeNewRedRushSaleInvoice(saleInvoiceVOs[0], bject); SaleInvoiceVO saleInvoiceRedRushVO = makeNewRedRushSaleInvoice(saleInvoiceVOs[0], bject);
// 生成红冲发票 // 生成红冲发票
Logger.error("====================inv-red-save-start===============");
ICloudScriptPFlowService flowService = NCLocator.getInstance().lookup(ICloudScriptPFlowService.class); ICloudScriptPFlowService flowService = NCLocator.getInstance().lookup(ICloudScriptPFlowService.class);
CloudPFlowContext context = new CloudPFlowContext(); CloudPFlowContext context = new CloudPFlowContext();
context.setBillType("32"); context.setBillType("32");
context.setBillVos(new SaleInvoiceVO[]{saleInvoiceRedRushVO}); context.setBillVos(new SaleInvoiceVO[]{saleInvoiceRedRushVO});
context.setActionName("WRITE"); context.setActionName("WRITE");
SaleInvoiceVO[] returnSaveSaleInvoiceVOs = (SaleInvoiceVO[]) flowService.exeScriptPFlow(context); SaleInvoiceVO[] returnSaveSaleInvoiceVOs = (SaleInvoiceVO[]) flowService.exeScriptPFlow(context);
Logger.error("=========================inv-save============== "); if (returnSaveSaleInvoiceVOs == null || returnSaveSaleInvoiceVOs.length <= 0) {
if (returnSaveSaleInvoiceVOs != null && returnSaveSaleInvoiceVOs.length > 0) { Exception e = new Exception("销售红冲发票保存失败");
Logger.error("inv-save = " + JSONArray.toJSONString(returnSaveSaleInvoiceVOs)); return ResultMessageUtil.exceptionToJSON(e);
}
Logger.error("inv-red-save = " + JSONArray.toJSONString(returnSaveSaleInvoiceVOs));
Logger.error("=====================inv-red-save-end===============");
Logger.error("=====================inv-red-audit-start===============");
// 生成红冲发票成功后执行销售发票审批动作 // 生成红冲发票成功后执行销售发票审批动作
context.setBillType("32"); context.setBillType("32");
context.setBillVos(returnSaveSaleInvoiceVOs); context.setBillVos(returnSaveSaleInvoiceVOs);
@ -181,8 +185,15 @@ public class IAPISaleInvMaitainImpl {
if (returnApproveSaleInvoiceVOs == null || returnApproveSaleInvoiceVOs.length <= 0) { if (returnApproveSaleInvoiceVOs == null || returnApproveSaleInvoiceVOs.length <= 0) {
throw new BusinessException("生成销售发票审核失败"); throw new BusinessException("生成销售发票审核失败");
} }
Logger.error("=========================inv-audit============== "); Logger.error("inv-red-audit = " + JSONArray.toJSONString(returnApproveSaleInvoiceVOs));
Logger.error("inv-audit = " + JSONArray.toJSONString(returnApproveSaleInvoiceVOs)); Logger.error("=====================inv-red-audit-end===============");
// 查询新生成红冲发票的信息
String newPk = returnApproveSaleInvoiceVOs[0].getParentVO().getCsaleinvoiceid();
String[] idsNew = {newPk};
// String[] idsNew = {"1001A11000000FREYYLE"};
SaleInvoiceVO[] redVos = querySaleInvoiceByIds(idsNew);
/** /**
* 开票申请红冲逻辑 * 开票申请红冲逻辑
* 1.根据销售发票号查询下游开票申请 * 1.根据销售发票号查询下游开票申请
@ -196,23 +207,27 @@ public class IAPISaleInvMaitainImpl {
// 开票申请单子表 // 开票申请单子表
IVApplicationBodyVO[] iVApplicationBodyVOs = (IVApplicationBodyVO[]) dmo.queryByWhereClause(IVApplicationBodyVO.class, "pk_ivapplication='" + pk_ivapplication + "' and dr=0 "); IVApplicationBodyVO[] iVApplicationBodyVOs = (IVApplicationBodyVO[]) dmo.queryByWhereClause(IVApplicationBodyVO.class, "pk_ivapplication='" + pk_ivapplication + "' and dr=0 ");
// 调用函数封装开票申请红冲VO // 调用函数封装开票申请红冲VO
IVApplicationAggVO iVApplicationAggVO = makeNewRedRushIVApplicationAggVO(iVApplicationHeadVO[0], iVApplicationBodyVOs, bject, returnApproveSaleInvoiceVOs); IVApplicationAggVO iVApplicationAggVO = makeNewRedRushIVApplicationAggVO(iVApplicationHeadVO[0], iVApplicationBodyVOs, bject, redVos);
// 生成红冲的开票申请 // 生成红冲的开票申请
IVApplicationServiceImpl serviceImpl = new IVApplicationServiceImpl(); IVApplicationServiceImpl serviceImpl = new IVApplicationServiceImpl();
IVApplicationAggVO returnSaveIVApplicationAggVO = serviceImpl.save(iVApplicationAggVO); IVApplicationAggVO returnSaveIVApplicationAggVO = serviceImpl.save(iVApplicationAggVO);
if (returnSaveIVApplicationAggVO != null) { if (returnSaveIVApplicationAggVO != null) {
return ResultMessageUtil.toJSON(returnApproveSaleInvoiceVOs, "接口调用成功"); // 查询红冲发票信息返回给调用方
return ResultMessageUtil.toJSON(redVos, "接口调用成功");
} else { } else {
Exception e = new Exception("接口调用失败"); Exception e = new Exception("销售红冲发票保存审核成功,开票申请保存失败");
return ResultMessageUtil.exceptionToJSON(e);
}
} else {
Exception e = new Exception("接口调用失败");
return ResultMessageUtil.exceptionToJSON(e); return ResultMessageUtil.exceptionToJSON(e);
} }
} }
public static JSONObject jsonObjectAss(JSONObject originalJson) throws Exception { /**
* 蓝字发票封装给交换平台的传参
*
* @param originalJson
* @return
* @throws Exception
*/
public JSONObject jsonObjectAss(JSONObject originalJson) throws Exception {
try { try {
// 构建目标 JSON 格式 // 构建目标 JSON 格式
JSONObject resultJson = new JSONObject(); JSONObject resultJson = new JSONObject();
@ -384,7 +399,7 @@ public class IAPISaleInvMaitainImpl {
} }
} }
private static String getTaxcode(String taxrateStr) throws BusinessException { private String getTaxcode(String taxrateStr) throws BusinessException {
IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
String sql = " select code FROM bd_taxrate tt inner join bd_taxcode tc on tt.pk_taxcode=tc.pk_taxcode where taxrate='" String sql = " select code FROM bd_taxrate tt inner join bd_taxcode tc on tt.pk_taxcode=tc.pk_taxcode where taxrate='"
+ taxrateStr + "' AND ROWNUM = 1 "; + taxrateStr + "' AND ROWNUM = 1 ";
@ -392,7 +407,7 @@ public class IAPISaleInvMaitainImpl {
return taxcodeStr; return taxcodeStr;
} }
private static Map<String, Object> getSaleorderVo(String csourcebillbidStr) throws BusinessException { private Map<String, Object> getSaleorderVo(String csourcebillbidStr) throws BusinessException {
IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," + String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," +
" sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate,sb.vchangerate," + " sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate,sb.vchangerate," +
@ -405,14 +420,14 @@ public class IAPISaleInvMaitainImpl {
return value2; return value2;
} }
private static String getString_TrimAsNull(Object value) { private String getString_TrimAsNull(Object value) {
if ((value == null) || (value.toString().trim().isEmpty())) { if ((value == null) || (value.toString().trim().isEmpty())) {
return ""; return "";
} }
return value.toString().trim(); return value.toString().trim();
} }
private static UFDouble getUFDouble_NullAsZero(Object value) { private UFDouble getUFDouble_NullAsZero(Object value) {
if ((value == null) || (value.toString().trim().isEmpty()) || (value.toString().trim().equals("~"))) if ((value == null) || (value.toString().trim().isEmpty()) || (value.toString().trim().equals("~")))
return UFDouble.ONE_DBL; return UFDouble.ONE_DBL;
if ((value instanceof UFDouble)) if ((value instanceof UFDouble))
@ -423,6 +438,17 @@ public class IAPISaleInvMaitainImpl {
return new UFDouble(value.toString().trim()); return new UFDouble(value.toString().trim());
} }
/**
* 根据主键查询销售发票
*
* @param ids
* @return
* @throws BusinessException
*/
private SaleInvoiceVO[] querySaleInvoiceByIds(String[] ids) throws BusinessException {
return NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class).queryVOByIDs(ids);
}
/** /**
* 构造红冲发票VO * 构造红冲发票VO
* *
@ -431,7 +457,7 @@ public class IAPISaleInvMaitainImpl {
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static SaleInvoiceVO makeNewRedRushSaleInvoice(SaleInvoiceVO originalVO, JSONObject bject) throws Exception { public SaleInvoiceVO makeNewRedRushSaleInvoice(SaleInvoiceVO originalVO, JSONObject bject) throws Exception {
try { try {
SaleInvoiceVO saleInvoiceVO = new SaleInvoiceVO(); SaleInvoiceVO saleInvoiceVO = new SaleInvoiceVO();
// 发票主实体 // 发票主实体
@ -558,21 +584,17 @@ public class IAPISaleInvMaitainImpl {
* @param applyHeadVO 原开票申请主实体 * @param applyHeadVO 原开票申请主实体
* @param ivApplicationBodyVOS 原开票申请子实体 * @param ivApplicationBodyVOS 原开票申请子实体
* @param bject bip参数 * @param bject bip参数
* @param returnApproveSaleInvoiceVOs 新生成的红冲销售发票实体 * @param redVos 新生成的红冲销售发票实体
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static IVApplicationAggVO makeNewRedRushIVApplicationAggVO(IVApplicationHeadVO applyHeadVO, IVApplicationBodyVO[] ivApplicationBodyVOS, JSONObject bject, SaleInvoiceVO[] returnApproveSaleInvoiceVOs) throws Exception { public IVApplicationAggVO makeNewRedRushIVApplicationAggVO(IVApplicationHeadVO applyHeadVO, IVApplicationBodyVO[] ivApplicationBodyVOS, JSONObject bject, SaleInvoiceVO[] redVos) throws Exception {
try { try {
IVApplicationAggVO applicationAggVO = new IVApplicationAggVO(); IVApplicationAggVO applicationAggVO = new IVApplicationAggVO();
IVApplicationHeadVO newivApplicationHeadVO = new IVApplicationHeadVO(); // 新主实体 IVApplicationHeadVO newivApplicationHeadVO = new IVApplicationHeadVO(); // 新主实体
// 取新生成红冲发票的主实体数据 // 取新生成红冲发票的主实体数据
String csaleinvoiceid = returnApproveSaleInvoiceVOs[0].getParentVO().getCsaleinvoiceid(); SaleInvoiceHVO rpSaleInvoiceHVO = redVos[0].getParentVO();
String[] ids = {csaleinvoiceid};
SaleInvoiceVO[] rpSaleInvoiceVOs = NCLocator.getInstance().lookup(ISaleinvoiceQueryAPI.class)
.queryVOByIDs(ids);
SaleInvoiceHVO rpSaleInvoiceHVO = rpSaleInvoiceVOs[0].getParentVO();
// 主实体属性赋值 // 主实体属性赋值
// 克隆取值原子表开票申请 // 克隆取值原子表开票申请
@ -608,7 +630,6 @@ public class IAPISaleInvMaitainImpl {
} }
JSONObject bipBvoJson = newBvoArr.get(0); // 参数子表 JSONObject bipBvoJson = newBvoArr.get(0); // 参数子表
IVApplicationBodyVO newivApplicationBodyVO = new IVApplicationBodyVO(); IVApplicationBodyVO newivApplicationBodyVO = new IVApplicationBodyVO();
// BeanUtil.copyProperties(ivApplicationBodyVO,newivApplicationBodyVO, CopyOptions.create().setIgnoreNullValue(true));
// 克隆取值原子表开票申请 // 克隆取值原子表开票申请
newivApplicationBodyVO = (IVApplicationBodyVO) getCloneTool().deepClone(ivApplicationBodyVO); newivApplicationBodyVO = (IVApplicationBodyVO) getCloneTool().deepClone(ivApplicationBodyVO);
// 赋值之后修改子实体红冲时字段 // 赋值之后修改子实体红冲时字段
@ -636,9 +657,9 @@ public class IAPISaleInvMaitainImpl {
newivApplicationHeadVO.setHjse(sumSe); // 合计税额 newivApplicationHeadVO.setHjse(sumSe); // 合计税额
newivApplicationHeadVO.setBchcje(sumBchcje); // 本次红冲金额 newivApplicationHeadVO.setBchcje(sumBchcje); // 本次红冲金额
newivApplicationHeadVO.setHzfp(UFBoolean.TRUE); // 红字发票 newivApplicationHeadVO.setHzfp(UFBoolean.TRUE); // 红字发票
newivApplicationHeadVO.setTranstypecode("SSCIVA-kpsq"); // 交易类型编码-填充默认值
newivApplicationHeadVO.setSrc_billtype(SOBillType.Invoice.getCode()); // 来源单据类型 newivApplicationHeadVO.setSrc_billtype(SOBillType.Invoice.getCode()); // 来源单据类型
newivApplicationHeadVO.setSrc_tradetype(rpSaleInvoiceHVO.getCtrantypeid()); // 来源交易类型 newivApplicationHeadVO.setSrc_tradetype(rpSaleInvoiceHVO.getCtrantypeid()); // 来源交易类型
newivApplicationHeadVO.setTranstypecode(rpSaleInvoiceHVO.getVtrantypecode()); // 来源交易类型编码
newivApplicationHeadVO.setSrc_pkbusibill(rpSaleInvoiceHVO.getCsaleinvoiceid()); // 来源单据id newivApplicationHeadVO.setSrc_pkbusibill(rpSaleInvoiceHVO.getCsaleinvoiceid()); // 来源单据id
newivApplicationHeadVO.setSrc_billno(rpSaleInvoiceHVO.getVbillcode()); // 来源单据编号 newivApplicationHeadVO.setSrc_billno(rpSaleInvoiceHVO.getVbillcode()); // 来源单据编号
newivApplicationHeadVO.setHcyy("2"); // 红冲原因2开票有误 newivApplicationHeadVO.setHcyy("2"); // 红冲原因2开票有误
@ -652,7 +673,7 @@ public class IAPISaleInvMaitainImpl {
} }
} }
private static Map<String, Object> getSaleOrderInfo(String csaleorderbid) throws BusinessException { private Map<String, Object> getSaleOrderInfo(String csaleorderbid) throws BusinessException {
IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class); IUAPQueryBS queryBS = NCLocator.getInstance().lookup(IUAPQueryBS.class);
String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," + String sql = " select s.vbillcode,s.csaleorderid, s.corigcurrencyid," +
" sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate," + " sb.csaleorderbid,sb.crowno,sb.blargessflag,sb.nexchangerate," +