diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/dao/IInvoiceDistributeDao.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/dao/IInvoiceDistributeDao.java index 1cad301f..12023065 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/dao/IInvoiceDistributeDao.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/dao/IInvoiceDistributeDao.java @@ -9,4 +9,7 @@ import java.util.List; public interface IInvoiceDistributeDao extends IBaseDao { + int updataStatus(InvoiceDistributeEntity invoiceDistributeEntity); + + List queryOrgerManber(InvoiceDistributeEntity applyPerson); } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/dao/impl/InvoiceDistributeDaoImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/dao/impl/InvoiceDistributeDaoImpl.java index 8f44a410..6fade588 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/dao/impl/InvoiceDistributeDaoImpl.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/dao/impl/InvoiceDistributeDaoImpl.java @@ -1,12 +1,26 @@ package com.hzya.frame.plugin.ht.dao.impl; +import com.baomidou.dynamic.datasource.annotation.DS; import com.hzya.frame.basedao.dao.MybatisGenericDao; import com.hzya.frame.plugin.ht.dao.IInvoiceDistributeDao; import com.hzya.frame.plugin.ht.entity.InvoiceDistributeEntity; +import com.hzya.frame.seeyon.invoice.entity.InvoiceEntity; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository(value = "invoiceDistributeDaoImpl") public class InvoiceDistributeDaoImpl extends MybatisGenericDao implements IInvoiceDistributeDao { + @DS("#entity.dataSourceCode") + @Override + public int updataStatus(InvoiceDistributeEntity entity) { + return super.update(getSqlIdPrifx()+"updataStatus",entity); + } + @DS("#entity.dataSourceCode") + @Override + public List queryOrgerManber(InvoiceDistributeEntity entity) { + return super.query(getSqlIdPrifx()+"queryOrgerManber",entity); + } } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/entity/InvoiceDistributeEntity.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/entity/InvoiceDistributeEntity.java index a651be6d..8b2decbe 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/entity/InvoiceDistributeEntity.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/entity/InvoiceDistributeEntity.java @@ -4,5 +4,42 @@ import com.hzya.frame.web.entity.BaseEntity; public class InvoiceDistributeEntity extends BaseEntity { + private String id; + private String field0206;//推送标识 + private String field0215;//开票结果 + private String name; + @Override + public String getId() { + return id; + } + + @Override + public void setId(String id) { + this.id = id; + } + + public String getField0206() { + return field0206; + } + + public void setField0206(String field0206) { + this.field0206 = field0206; + } + + public String getField0215() { + return field0215; + } + + public void setField0215(String field0215) { + this.field0215 = field0215; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/entity/InvoiceDistributeEntity.xml b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/entity/InvoiceDistributeEntity.xml index 002d5eb1..91a688ed 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/entity/InvoiceDistributeEntity.xml +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/entity/InvoiceDistributeEntity.xml @@ -2,6 +2,22 @@ + + update formmain_0331 set + + field0206 = #{field0206}, + field0215 = #{field0215}, + + where id=#{id} + - + diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/plugin/InvoiceDistributePluginInitializer.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/plugin/InvoiceDistributePluginInitializer.java index ce693250..00ea4dad 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/plugin/InvoiceDistributePluginInitializer.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/plugin/InvoiceDistributePluginInitializer.java @@ -1249,7 +1249,7 @@ public class InvoiceDistributePluginInitializer extends PluginBaseEntity { */ private void updateOAForm(JsonResultEntity jsonResultEntity, JSONObject data) { try { - logger.info("d准备更新开票结果到OA单ata_id:{}",data.getString("data_id")); + logger.info("准备更新开票结果到OA单data_id:{}",data.getString("data_id")); if (null != jsonResultEntity && null != data && StrUtil.isNotEmpty(data.getString("data_id"))){ String data_id = data.getString("data_id"); String attrStr = jsonResultEntity.getAttribute().toString(); diff --git a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/service/impl/InvoiceDistributeServiceImpl.java b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/service/impl/InvoiceDistributeServiceImpl.java index d7e1f359..90127d1c 100644 --- a/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/service/impl/InvoiceDistributeServiceImpl.java +++ b/base-buildpackage/src/main/java/com/hzya/frame/plugin/ht/service/impl/InvoiceDistributeServiceImpl.java @@ -14,6 +14,9 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.List; +import java.util.stream.Collectors; @Service(value = "invoiceDistributeServiceImpl") @@ -52,31 +55,89 @@ public class InvoiceDistributeServiceImpl extends BaseService apply_person = iInvoiceDistributeDao.queryOrgerManber(applyPerson); + if(apply_person != null && apply_person.size() > 0){ + parent.put("applyPerson", apply_person.get(0).getName()); + } + parent.put("applyEmailNotice", "0"); + parent.put("buyerEmailNotice", "0"); + parent.put("workcode", ""); + parent.put("otherEmail", stringAgg(formson_0700)); + parent.put("buyerContact", ""); + parent.put("buyerMobile", ""); + parent.put("buyerRecvAddress", mainData.getString("field0126")); + parent.put("applicationRemark", ""); + parent.put("attachments", ""); + parent.put("notifyUrl", ""); + parent.put("specialInvoiceMark", mainData.getString("field0167")); + parent.put("sellerName", mainData.getString("field0108")); + parent.put("sellerAddrPhone", ""); + parent.put("sellerBankAccount", ""); + JSONObject extFieldJSONObject = new JSONObject(); + extFieldJSONObject.put("SystemOrg","OA"); + parent.put("extFieldJSONObject",extFieldJSONObject); + JSONObject extendFieldsObj = new JSONObject(); + extendFieldsObj.put("SystemOrg","OA"); + parent.put("extendFields",extendFieldsObj); + JSONObject applicationForm = new JSONObject(); + if(mainData.getString("field0109") != null){ + if("-5467259512157286597".equals(mainData.getString("field0109"))){ + applicationForm.put("invoiceType", "10"); + }else if ("8203933372392623007".equals(mainData.getString("field0109"))){ + applicationForm.put("invoiceType", "0"); + }else if ("586969999836335692".equals(mainData.getString("field0109"))){ + applicationForm.put("invoiceType", "21"); + }else if ("-9065195408118165505".equals(mainData.getString("field0109"))){ + applicationForm.put("invoiceType", "22"); + }else { + applicationForm.put("invoiceType", null); + } + } + applicationForm.put("isPerson", ""); + applicationForm.put("levyTaxType", "0"); + applicationForm.put("deduction", ""); + applicationForm.put("remark", mainData.getString("field0092")); + if (formson_0332 != null && formson_0332.size() > 0) { + for (int i = 0; i < formson_0332.size(); i++) { + JSONObject detaildata1 = formson_0332.getJSONObject(i); + JSONObject details = new JSONObject(); + details.put("itemNo", ""); + details.put("itemName", detaildata1.getString("field0080")); + details.put("taxCateCode", detaildata1.getString("field0153")); + details.put("spec", detaildata1.getString("field0083")); + details.put("unit", detaildata1.getString("field0219")); + details.put("quantity", detaildata1.getOrDefault("field0122",0)); + details.put("unitPrice", detaildata1.getOrDefault("field0085",0)); + // 如果数量是0,则单价也传0 + if(null == detaildata1.getString("field0122")){ + details.put("unitPrice", null); + } + details.put("price", detaildata1.getString("field0087")); + details.put("taxRate", detaildata1.getString("field0224")); + details.put("zeroFlag", ""); + details.put("includeTaxTag", "0"); + details.put("detailType", "0"); + details.put("enjoyPreferentialFlag", "0"); + details.put("preferentialPolicyType", ""); + childrens.add(details); + } + } + applicationForm.put("detailList", childrens); + JSONObject specialIndustryDTO = new JSONObject(); + if ("03".equals(mainData.getString("field0167"))) { + specialIndustryDTO.put("place", mainData.getString("field0210")); + specialIndustryDTO.put("placeOfDetail", mainData.getString("field0211")); + specialIndustryDTO.put("constructionProjectName", mainData.getString("field0212")); + specialIndustryDTO.put("productNo", mainData.getString("field0186")); + specialIndustryDTO.put("crossDistinctCityFlag", mainData.getString("field0187")); + if("是".equals(mainData.getString("field0187"))){ + specialIndustryDTO.put("kqysssxbgglbm", mainData.getString("field0185")); + } + } + if ("06".equals(mainData.getString("field0167"))) { + specialIndustryDTO.put("place", mainData.getString("field0210")); + specialIndustryDTO.put("placeOfDetail", mainData.getString("field0211")); + specialIndustryDTO.put("crossDistinctCityFlag", mainData.getString("field0187")); + specialIndustryDTO.put("certificateOfTitle", mainData.getString("field0213")); + specialIndustryDTO.put("areaUnit", mainData.getString("field0214")); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + if(mainData.getString("field0208") != null){ + specialIndustryDTO.put("startDate", sdf.format(mainData.getDate("field0208"))); + } + if(mainData.getString("field0209") != null){ + specialIndustryDTO.put("endDate", sdf.format(mainData.getDate("field0209"))); + } + } + parent.put("applicationForm", applicationForm); + parent.put("specialIndustryDTO", specialIndustryDTO); + returnObject.put("bodys", parent.toJSONString()); + return returnObject; + } + public String stringAgg( JSONArray jsonArray) { + // 防御空输入:若JSONArray为null或空,直接返回空字符串 + if (jsonArray == null || jsonArray.isEmpty()) { + return ""; + } + + StringBuilder sb = new StringBuilder(); + // 遍历JSONArray中的每个JSONObject(对应一条formson_0700数据) + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jsonObj = jsonArray.getJSONObject(i); + if (jsonObj == null) { + continue; // 跳过空对象 + } + + // 提取field0217:若字段不存在或为null,视为空值 + String fieldVal = jsonObj.getString("field0217"); + // 过滤无效值(null、纯空格字符串) + if (fieldVal == null || fieldVal.trim().isEmpty()) { + continue; + } + + // 拼接逻辑:非第一个有效值时,先加';'分隔符 + if (sb.length() > 0) { + sb.append(";"); + } + sb.append(fieldVal); + } + + return sb.toString(); + } + /** + * @param mainData + * @param formson_0700 + * @param formson_0332 + * @return JSONObject + * @Author lvleigang + * @Description 红字信息表申请单申请 组装数据 + * @Date 6:12 下午 2025/6/27 + **/ + private JSONObject gethzxxbsqdsqSendData(JSONObject mainData, JSONArray formson_0700,JSONArray formson_0332) throws ParseException { + JSONObject returnObject = new JSONObject(); + JSONArray childrens = new JSONArray(); + JSONObject parent = new JSONObject(); + parent.put("serialNumber", mainData.getString("id")); + parent.put("companyCode", ""); + parent.put("sellerTaxNo", mainData.getString("field0163")); + parent.put("templateId", "MB20250623LJ"); + parent.put("businessNo", mainData.getString("field0117")); + parent.put("originalSellerName", mainData.getString("field0108")); + parent.put("originalSellerTaxNo", mainData.getString("field0163")); + parent.put("buyerName", mainData.getString("field0106")); + parent.put("buyerTaxNo", mainData.getString("field0105")); + InvoiceDistributeEntity applyPerson = new InvoiceDistributeEntity(); + applyPerson.setId(mainData.getString("field0115")); + applyPerson.setDataSourceCode("HT-OA"); + List apply_person = iInvoiceDistributeDao.queryOrgerManber(applyPerson); + if(apply_person != null && apply_person.size() > 0){ + parent.put("applyPerson", apply_person.get(0).getName()); + } + parent.put("applyEmailNotice", "0"); + parent.put("buyerEmailNotice", "0"); + parent.put("otherEmail", stringAgg(formson_0700)); + parent.put("applicationRemark", ""); + parent.put("attachments", ""); + parent.put("notifyUrl",""); + JSONObject extFieldJSONObject = new JSONObject(); + extFieldJSONObject.put("SystemOrg","OA"); + parent.put("extFieldJSONObject",extFieldJSONObject); + JSONObject extendFieldsObj = new JSONObject(); + extendFieldsObj.put("SystemOrg","OA"); + parent.put("extendFields",extendFieldsObj); + JSONArray applicationForm = new JSONArray(); + JSONObject applicationFormJson = new JSONObject(); + if(mainData.getString("field0109") != null){ + if("-5467259512157286597".equals(mainData.getString("field0109"))){ + applicationFormJson.put("invoiceType", "10"); + }else if ("8203933372392623007".equals(mainData.getString("field0109"))){ + applicationFormJson.put("invoiceType", "0"); + }else if ("586969999836335692".equals(mainData.getString("field0109"))){ + applicationFormJson.put("invoiceType", "21"); + }else if ("-9065195408118165505".equals(mainData.getString("field0109"))){ + applicationFormJson.put("invoiceType", "22"); + }else { + applicationFormJson.put("invoiceType", null); + } + } + if ("-1414365591115381033".equals(mainData.getString("field0165"))) { //销方 + applicationFormJson.put("applicant", "2"); + } + if ("3075360049544777325".equals(mainData.getString("field0165"))) { //购方 + applicationFormJson.put("applicant", "1"); + } + applicationFormJson.put("deductionStatus", ""); + applicationFormJson.put("originalInvoiceCode", mainData.getString("field0157")); + applicationFormJson.put("originalInvoiceNumber", mainData.getString("field0158")); + applicationFormJson.put("originalInvoiceDate", mainData.getString("field0159")); + applicationFormJson.put("originalInvoicePrice", mainData.getString("field0160")); + //3320815801687101195 8075623800107716290 销货退回 + //-8544387146720065507 8075623800107716290 开票有误 + //3435351219724830575 8075623800107716290 服务中止 + //-1893846937353040038 8075623800107716290 销售折让 + if (mainData.getString("field0164") != null) { + if ("3320815801687101195".equals(mainData.getString("field0164"))) { + applicationFormJson.put("redFlushReason", "1"); + }else if ("-8544387146720065507".equals(mainData.getString("field0164"))) { + applicationFormJson.put("redFlushReason", "2"); + }else if ("3435351219724830575".equals(mainData.getString("field0164"))) { + applicationFormJson.put("redFlushReason", "3"); + }else if ("-1893846937353040038".equals(mainData.getString("field0164"))) { + applicationFormJson.put("redFlushReason", "4"); + }else { + applicationFormJson.put("redFlushReason", null); + } + }else { + applicationFormJson.put("redFlushReason", null); + } + applicationFormJson.put("specialInvoiceMark", mainData.getString("field0167")); + applicationFormJson.put("redFlushType", "0"); + applicationForm.add(applicationFormJson); + parent.put("applicationForm", applicationForm); + returnObject.put("bodys", parent.toJSONString()); + return returnObject; + } + + /** + * @param mainData + * @param formson_0700 + * @param formson_0332 + * @return JSONObject + * @Author lvleigang + * @Description 红字发票申请单申请 组装数据 + * @Date 6:12 下午 2025/6/27 + **/ + private JSONObject gethzfpsqdsqSendData(JSONObject mainData, JSONArray formson_0700,JSONArray formson_0332) throws ParseException { + com.alibaba.fastjson.JSONObject returnObject = new com.alibaba.fastjson.JSONObject(); + com.alibaba.fastjson.JSONObject parent = new com.alibaba.fastjson.JSONObject(); + parent.put("serialNumber", mainData.getString("id")); + parent.put("companyCode", "0"); + parent.put("sellerTaxNo", mainData.getString("field0163")); + parent.put("templateId", "MB20250623F"); + parent.put("businessNo", mainData.getString("field0117")); + parent.put("originalSuperiorBusinessNo", mainData.getString("field0156")); + parent.put("buyerName", mainData.getString("field0106")); + parent.put("buyerTaxNo", mainData.getString("field0105")); + parent.put("buyerAddrPhone", mainData.getOrDefault("field0100","") +" "+ mainData.getOrDefault("field0101","")); + String buyerBankAccount = (mainData.getString("field0103") == null ? "" : mainData.getString("field0103")).replaceAll(" ", "") + " " + (mainData.getString("field0102") == null ? "" : mainData.getString("field0102")).replaceAll(" ", ""); + parent.put("buyerBankAccount", buyerBankAccount); + InvoiceDistributeEntity applyPerson = new InvoiceDistributeEntity(); + applyPerson.setId(mainData.getString("field0115")); + applyPerson.setDataSourceCode("HT-OA"); + List apply_person = iInvoiceDistributeDao.queryOrgerManber(applyPerson); + if(apply_person != null && apply_person.size() > 0){ + parent.put("applyPerson", apply_person.get(0).getName()); + } + parent.put("applyEmailNotice", "0"); + parent.put("buyerEmailNotice", "0"); + parent.put("otherEmail", stringAgg(formson_0700)); + parent.put("buyerContact", ""); + parent.put("buyerMobile", ""); + parent.put("buyerRecvAddress", mainData.getString("field0126")); + parent.put("applicationRemark", ""); + parent.put("attachments", ""); + parent.put("notifyUrl", ""); + parent.put("specialInvoiceMark", mainData.getString("field0167")); + parent.put("sellerName", mainData.getString("field0108")); + parent.put("sellerAddrPhone", ""); + parent.put("sellerBankAccount", ""); + com.alibaba.fastjson.JSONObject extFieldJSONObject = new com.alibaba.fastjson.JSONObject(); + extFieldJSONObject.put("SystemOrg","OA"); + parent.put("extFieldJSONObject",extFieldJSONObject); + com.alibaba.fastjson.JSONObject extendFieldsObj = new com.alibaba.fastjson.JSONObject(); + extendFieldsObj.put("SystemOrg","OA"); + parent.put("extendFields",extendFieldsObj); + com.alibaba.fastjson.JSONArray applicationForm = new com.alibaba.fastjson.JSONArray(); + com.alibaba.fastjson.JSONObject applicationFormJson = new com.alibaba.fastjson.JSONObject(); + if(mainData.getString("field0109") != null){ + if("-5467259512157286597".equals(mainData.getString("field0109"))){ + applicationFormJson.put("invoiceType", "10"); + }else if ("8203933372392623007".equals(mainData.getString("field0109"))){ + applicationFormJson.put("invoiceType", "0"); + }else if ("586969999836335692".equals(mainData.getString("field0109"))){ + applicationFormJson.put("invoiceType", "21"); + }else if ("-9065195408118165505".equals(mainData.getString("field0109"))){ + applicationFormJson.put("invoiceType", "22"); + }else { + applicationFormJson.put("invoiceType", null); + } + } + applicationFormJson.put("originalInvoiceCode", mainData.getString("field0157")); + applicationFormJson.put("originalInvoiceNumber", mainData.getString("field0158")); + applicationFormJson.put("originalInvoiceDate", mainData.getString("field0159")); + applicationFormJson.put("originalInvoicePrice", mainData.getString("field0160")); + applicationFormJson.put("originalInvoiceCheckCode", null); + applicationFormJson.put("redLetterInfoSheetNo", mainData.getString("field0161")); + applicationFormJson.put("remark", mainData.getString("field0092")); + applicationForm.add(applicationFormJson); + parent.put("applicationForm", applicationForm); + returnObject.put("bodys", parent.toJSONString()); + return returnObject; } }