diff --git a/mhd_bms/src/main/java/com/mhd/bms/application/server/billManage/BillManageApplicationService.java b/mhd_bms/src/main/java/com/mhd/bms/application/server/billManage/BillManageApplicationService.java index 3d90a5b76..3de55f4d1 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/application/server/billManage/BillManageApplicationService.java +++ b/mhd_bms/src/main/java/com/mhd/bms/application/server/billManage/BillManageApplicationService.java @@ -7,6 +7,7 @@ import com.mhd.bms.application.server.receiptManage.ReceiptManageApplicationServ import com.mhd.bms.domain.billManage.entity.BillDetail; import com.mhd.bms.domain.billManage.entity.BillManage; import com.mhd.bms.domain.billManage.repository.facade.IBillDetailService; +import com.mhd.bms.domain.billManage.repository.facade.IBillManageService; import com.mhd.bms.domain.billManage.repository.mapper.BillDetailMapper; import com.mhd.bms.domain.billManage.repository.po.BillDetailPO; import com.mhd.bms.domain.billManage.repository.po.BillManagePO; @@ -78,6 +79,8 @@ public class BillManageApplicationService { private BillDetailMapper billDetailMapper; @Autowired private NcLogMapper ncLogMapper; + @Autowired + private IBillManageService billManageService; /** @@ -445,6 +448,7 @@ public class BillManageApplicationService { billManageDO.setReconciliationStatus(1); billManageDO.setCreateTime(new Date()); billManageDO.setCreateBy(loginUser.getUserid()); + billManageDO.setSalesmanId(String.valueOf(loginUser.getUserid())); billManageDO.setCreateByName(loginUser.getUserPo().getUserName()); billManageDO.setUpdateTime(new Date()); billManageDO.setUpdateBy(loginUser.getUserid()); @@ -466,6 +470,16 @@ public class BillManageApplicationService { for (BillDetailDTO billDetailDTO : billDetailDTOListNoBillingStatementId) { BillingStatementDTO billingStatementDTO = new BillingStatementDTO(); BeanUtils.copyProperties(billDetailDTO, billingStatementDTO); + + String firstSubjectCode = billDetailDTO.getFirstSubjectCode(); + Double taxRate = billDetailMapper.getTaxRate(firstSubjectCode); + BigDecimal amount = billingStatementDTO.getBillingAmount(); + BigDecimal taxAmount = amount.divide(BigDecimal.ONE.add(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))),10, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal taxFreeFee = amount.subtract(taxAmount); + billingStatementDTO.setTaxAmount(taxAmount); + billingStatementDTO.setTaxFreeFee(taxFreeFee); + billingStatementDTO.setTaxRate(taxRate); + billingStatementDTO.setBillingAmount(amount); billingStatementDTO.setAccountExpenseType(billDetailDTO.getBillType()); billingStatementDTO.setBillManageId(billManageDO.getBillManageId()); billingStatementDTO.setBillingState(3); @@ -495,6 +509,31 @@ public class BillManageApplicationService { billingStatementApplicationService.update(billingStatementDO); } //保存账单明细 + double allTaxRate = 0.0d; + BigDecimal allTaxAmount = BigDecimal.ZERO; + BigDecimal allTaxFreeFee = BigDecimal.ZERO; + for (BillDetailDTO item : billDetailDTOList) { + String firstSubjectCode = item.getFirstSubjectCode(); + Double taxRate = billDetailMapper.getTaxRate(firstSubjectCode); + BigDecimal amount = item.getBillingAmount(); + BigDecimal taxAmount = amount.divide(BigDecimal.ONE.add(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))),10, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal taxFreeFee = amount.subtract(taxAmount); + item.setTaxAmount(taxAmount); + item.setTaxFreeFee(taxFreeFee); + item.setTaxRate(taxRate); + allTaxRate += taxRate; + allTaxAmount = allTaxAmount.add(taxAmount); + allTaxFreeFee = allTaxFreeFee.add(taxFreeFee); + } + + BillManage billManage = billManageService.getById(billManageDO.getBillManageId()); + if (billManage != null) { + billManage.setTaxRate(allTaxRate); + billManage.setTaxAmount(allTaxAmount); + billManage.setTaxFreeFee(allTaxFreeFee); + billManage.setSalesmanId(String.valueOf(loginUser.getUserid())); + billManageService.updateById(billManage); + } Boolean flagTwo = billDetailDomainService.saveBatch(billDetailDTOList); //保存操作记录 BillOperationLogDO billOperationLogDO = new BillOperationLogDO(); diff --git a/mhd_bms/src/main/java/com/mhd/bms/application/server/billingStatement/BillingStatementApplicationService.java b/mhd_bms/src/main/java/com/mhd/bms/application/server/billingStatement/BillingStatementApplicationService.java index 9e56458e6..0f553dc75 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/application/server/billingStatement/BillingStatementApplicationService.java +++ b/mhd_bms/src/main/java/com/mhd/bms/application/server/billingStatement/BillingStatementApplicationService.java @@ -585,6 +585,8 @@ public class BillingStatementApplicationService { 此方法只进行实体返回,并不进行数据保存 */ LoginUser loginUser = SecurityUtils.getLoginUser(); + + billingStatementDO.setAccountExpenseType(billingStatementDO.getAccountExpenseType()); if (ObjectUtil.isNull(loginUser)) { throw new DigitalLogisticsException(UserError.TIMEOUT); } diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/facade/IBillDetailService.java b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/facade/IBillDetailService.java index f2cbe3d43..192395468 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/facade/IBillDetailService.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/facade/IBillDetailService.java @@ -38,4 +38,6 @@ public interface IBillDetailService extends IService public BillDetailPO getInfo(Long billDetailId); List getDetailsByBillManageId(Long billManageId); -} + + List getDetailsByBillManageIdAndGroup(Long billManageId); +} \ No newline at end of file diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/mapper/BillDetailMapper.java b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/mapper/BillDetailMapper.java index 1ea7709f4..044e5565c 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/mapper/BillDetailMapper.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/mapper/BillDetailMapper.java @@ -5,6 +5,7 @@ import com.mhd.bms.domain.billManage.entity.BillDetail; import com.mhd.bms.domain.billManage.repository.po.BillDetailPO; import org.apache.ibatis.annotations.Param; +import java.math.BigDecimal; import java.util.List; /** @@ -17,4 +18,8 @@ public interface BillDetailMapper extends BaseMapper { List getDetailsByBillManageId(@Param("billManageId") Long billManageId); -} + + List getDetailsByBillManageIdAndGroup(@Param("billManageId") Long billManageId); + + Double getTaxRate(@Param("code") String code); +} \ No newline at end of file diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/mapper/BillManageMapper.java b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/mapper/BillManageMapper.java index 1a075701b..5a4edf3f3 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/mapper/BillManageMapper.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/mapper/BillManageMapper.java @@ -44,4 +44,6 @@ public interface BillManageMapper extends BaseMapper String getDeptName(@Param("dictCode") String dictCode); String getOrgCodeNc(@Param("organizationId") Long organizationId); + + Long getShipperId(@Param("userId") Long userId, @Param("organizationId") Long organizationId); } \ No newline at end of file diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/persistence/BillDetailImpl.java b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/persistence/BillDetailImpl.java index cf62504d6..2aa419a1f 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/persistence/BillDetailImpl.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/persistence/BillDetailImpl.java @@ -75,4 +75,9 @@ public class BillDetailImpl extends ServiceImpl im public List getDetailsByBillManageId(Long billManageId) { return billDetailMapper.getDetailsByBillManageId(billManageId); } -} + + @Override + public List getDetailsByBillManageIdAndGroup(Long billManageId) { + return billDetailMapper.getDetailsByBillManageIdAndGroup(billManageId); + } +} \ No newline at end of file diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/persistence/BillManageImpl.java b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/persistence/BillManageImpl.java index 014e611f8..8f5a7b64c 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/persistence/BillManageImpl.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/persistence/BillManageImpl.java @@ -9,8 +9,11 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.mhd.bms.domain.billManage.entity.BillDetail; import com.mhd.bms.domain.billManage.entity.BillManage; +import com.mhd.bms.domain.billManage.repository.facade.IBillDetailService; import com.mhd.bms.domain.billManage.repository.facade.IBillManageService; +import com.mhd.bms.domain.billManage.repository.mapper.BillDetailMapper; import com.mhd.bms.domain.billManage.repository.mapper.BillManageMapper; import com.mhd.bms.domain.billManage.repository.po.BillManagePO; import com.mhd.bms.domain.billManage.repository.todo.BillManageDO; @@ -24,6 +27,9 @@ import com.mhd.bms.domain.ncDataPushConfig.entity.NcDataPushConfig; import com.mhd.bms.domain.ncDataPushConfig.repository.mapper.NcDataPushConfigMapper; import com.mhd.bms.domain.ncLog.entity.NcLog; import com.mhd.bms.domain.ncLog.repository.mapper.NcLogMapper; +import com.mhd.bms.domain.settlementCustomers.entity.SettlementCustomers; +import com.mhd.bms.domain.settlementCustomers.repository.facade.ISettlementCustomersService; +import com.mhd.bms.interfaces.dto.billManage.BillDetailDTO; import com.mhd.bms.interfaces.dto.billManage.BillManageDTO; import com.mhd.common.core.domain.dto.ReconciliationDTO; import com.mhd.common.core.domain.dto.nc.*; @@ -83,6 +89,12 @@ public class BillManageImpl extends ServiceImpl im @Autowired private BillManageMapper billManageMapper; @Autowired + private IBillDetailService billDetailService; + @Autowired + private IBillManageService billManageService; + @Autowired + private BillDetailMapper billDetailMapper; + @Autowired private BmsInvoiceListMapper bmsInvoiceListMapper; //nc测试环境地址 @@ -103,6 +115,8 @@ public class BillManageImpl extends ServiceImpl im private BmsMakeOutInvoiceMapper bmsMakeOutInvoiceMapper; @Resource private BmsMakeOutInvoiceItemMapper bmsMakeOutInvoiceItemMapper; + @Autowired + private ISettlementCustomersService settlementCustomersService; /** * 查询账单管理列表 */ @@ -177,7 +191,6 @@ public class BillManageImpl extends ServiceImpl im return true; } - public boolean synchronousNc_TY(String businessDocumentDetaliId) { BillManage reconciliation=billManageMapper.selectById(businessDocumentDetaliId); if(reconciliation.getSynchronousStatus()==1){ @@ -190,273 +203,306 @@ public class BillManageImpl extends ServiceImpl im SimpleDateFormat sdf2 = new SimpleDateFormat("MM"); String dateString = sdf.format(date); String invoiceId = reconciliation.getInvoiceId(); - List bmsMakeOutInvoices = bmsMakeOutInvoiceMapper.selectList(new LambdaQueryWrapper().eq(BmsMakeOutInvoice::getInvoiceId, invoiceId)); - if (bmsMakeOutInvoices != null && bmsMakeOutInvoices.size() > 0){ - int count = 0; - for (BmsMakeOutInvoice make : bmsMakeOutInvoices) { - count++; - List ysitemList=new ArrayList(); - String url = ""; - Long organizationId = reconciliation.getOrganizationId(); - String organizationName = reconciliation.getOrganizationName(); - String ncUrl = billManageMapper.getNcUrl("nc", organizationName, organizationId); - if (ncUrl!=null&&ncUrl!="") { - url = ncUrl; - } else { - reconciliation.setSynchronousStatus(2); - billManageMapper.updateById(reconciliation); - throw new ServiceException("未找到该组织的推送地址!"); - } - String salesmanId = reconciliation.getSalesmanId(); - String customerUserDept = billManageMapper.getCustomerUserDept(salesmanId); - String deptValue = billManageMapper.getDeptValue(customerUserDept); - String deptName = billManageMapper.getDeptName(customerUserDept); - String salespersonNcCode = billManageMapper.getsalespersonNcCode(salesmanId); - String salesmanCodeNc=salespersonNcCode; - String appointShipper=make.getActualInvoiceCustomerName(); - String actualInvoiceCustomerId = make.getActualInvoiceCustomerId(); - String customerCodeNc = billManageMapper.getCustomerCodeNc(actualInvoiceCustomerId); - String customerCodeNcJson = billManageMapper.getCustomerCodeNcJson(actualInvoiceCustomerId); - if (customerCodeNcJson != null && !customerCodeNcJson.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); - List> listNc = objectMapper.readValue( - customerCodeNcJson, - new TypeReference>>() {} - ); - if (listNc != null && listNc.size() > 0) { - Map targetMap = listNc.stream() - .filter(map -> { - Object codeObj = map.get("code"); - return codeObj != null && codeObj.toString().equals(reconciliation.getOrganizationId().toString()); - }) - .findFirst() - .orElse(null); - if (targetMap != null) { - customerCodeNc = (String) targetMap.get("ncCustomer"); - } - } - } - String settlementCurrency=reconciliation.getSettlementCurrency(); - String orgCodeNc = billManageMapper.getOrgCodeNc(organizationId); - String documentPreparerNcCode = billManageMapper.getDocumentPreparerNcCode(salesmanId); - String makerCodeNc = documentPreparerNcCode; - String settlementCurrencyNcCode = settlementCurrency; - String invoiceNumber=make.getInvoiceNumber(); - List bmsMakeOutInvoiceItems = bmsMakeOutInvoiceItemMapper.selectList(new LambdaQueryWrapper().eq(BmsMakeOutInvoiceItem::getMakeId, make.getId())); - if (bmsMakeOutInvoiceItems != null && bmsMakeOutInvoiceItems.size() > 0) { - for (BmsMakeOutInvoiceItem item1 : bmsMakeOutInvoiceItems) { - if(item1.getInvoiceValue().compareTo(BigDecimal.ZERO)>0){ - Ysitem item=new Ysitem(); - if (deptValue != null && !deptValue.isEmpty()) { - item.setSo_deptid(deptValue); - } else { - item.setSo_deptid("NG0408"); - } - if (deptValue != null && !deptValue.isEmpty()) { - item.setPk_deptid(deptValue); - } else { - item.setPk_deptid("NG0408"); - } - //业务员nc - item.setPk_psndoc(salesmanCodeNc); - //客户nc - item.setCustomer(customerCodeNc); - item.setObjtype("0"); - item.setDirection("1"); - String invoiceItem = item1.getInvoiceItem(); - List names = new ArrayList<>(); - List nccodes = new ArrayList<>(); - if (invoiceItem != null && !invoiceItem.isEmpty()) { - String[] items = invoiceItem.split(","); - for (String s : items) { - String invoiceItemName1 = billManageMapper.getInvoiceItemName(s); - String invoiceItemNcCode1 = billManageMapper.getInvoiceItemNcCode(s); - names.add(invoiceItemName1); - nccodes.add(invoiceItemNcCode1); - } - } - String invoiceItemName = String.join(",", names); - //item.setDef29(invoiceItemName); - if (deptName != null && !deptName.isEmpty()) { - item.setScomment(deptName+":应收"+appointShipper+invoiceItemName+invoiceNumber); - } else { - item.setScomment("业务部:应收"+appointShipper+invoiceItemName+invoiceNumber); - } - // item.setPk_currtype("CNY"); - item.setPk_currtype(settlementCurrencyNcCode); - item.setPurchaseorder(""); - item.setTaxrate(String.valueOf(item1.getTaxRate())); - item.setQuantity_de("0"); - item.setMoney_de(String.valueOf(item1.getInvoiceValue())); - item.setMoney_bal(String.valueOf(item1.getInvoiceValue())); - BigDecimal tax_de=item1.getTaxAmount(); - BigDecimal notax_de=item1.getTaxFreeFee(); - item.setNotax_de(String.valueOf(notax_de)); - item.setLocal_tax_de(String.valueOf(tax_de)); - item.setTax_de(String.valueOf(tax_de)); - item.setPrice(String.valueOf(item1.getInvoiceValue())); - item.setTaxprice(String.valueOf(item1.getInvoiceValue())); -// 费用类别 - String feeType = item1.getFeeType(); - String serviceItemsCodeNc = billManageMapper.getServiceItemsCodeNc(feeType); - if (serviceItemsCodeNc != null && !serviceItemsCodeNc.isEmpty()) { - item.setDef75(serviceItemsCodeNc); - } else { - item.setDef75("T04"); - } - String invoiceItem1 = item1.getInvoiceItem(); - if (invoiceItem1 != null && !invoiceItem1.isEmpty()) { - String[] split = invoiceItem1.split(","); - item.setDef29(split[0]); - //item.setDef29(invoiceItem1); - } - if (nccodes != null && !nccodes.isEmpty()&&nccodes.size()>0) { - item.setDef29(nccodes.get(0)); - } - item.setTaxcodeid("ZL01"); - item.setInvoiceno(invoiceNumber); - ysitemList.add(item); - } - } - } + List billDetails = billDetailService.getDetailsByBillManageIdAndGroup(Long.parseLong(businessDocumentDetaliId)); - Ysbodys bodys=new Ysbodys(); - bodys.setItem(ysitemList); - Ysbillhead billhead=new Ysbillhead(); - billhead.setPk_group("CNK"); - if (orgCodeNc != null && !orgCodeNc.isEmpty()) { - billhead.setPk_org(orgCodeNc); - billhead.setSett_org(orgCodeNc); - } else { - billhead.setPk_org("NG04"); - billhead.setSett_org("NG04"); - } - billhead.setCreationtime(dateString); - billhead.setCreator(makerCodeNc); - billhead.setPk_billtype("F0"); - billhead.setPk_tradetype("D0"); - billhead.setBillclass("ys"); - billhead.setIsinit("N"); - date=reconciliation.getCreateTime(); - dateString = sdf.format(date); - billhead.setBilldate(dateString); - billhead.setSyscode("0"); - billhead.setBillno(""); - billhead.setDef59(""); - billhead.setSrc_syscode("0"); - billhead.setBillstatus("0"); - billhead.setBillmaker(makerCodeNc); - billhead.setPk_busitype(""); - billhead.setBillyear(sdf1.format(date)); - billhead.setBillperiod(sdf2.format(date)); - billhead.setEffectstatus("0"); - billhead.setDef28("nqyw"); - billhead.setDef29(reconciliation.getBillNumber()); - billhead.setBodys(bodys); - Ysbill bill=new Ysbill(); - bill.setId("ys"+String.valueOf(reconciliation.getBillManageId())+"_"+count); - bill.setBillhead(billhead); - Ysufinterface ufinterface=new Ysufinterface(); - ufinterface.setAccount("NKNC"); - ufinterface.setBilltype("F0"); - ufinterface.setBusinessunitcode(""); - ufinterface.setFilename(""); - ufinterface.setIsexchange("Y"); - if (orgCodeNc != null && !orgCodeNc.isEmpty()) { - ufinterface.setOrgcode(orgCodeNc); - ufinterface.setReceiver(orgCodeNc); - } else { - ufinterface.setOrgcode("NG04"); - ufinterface.setReceiver("NG04"); - } - ufinterface.setReplace("Y"); - ufinterface.setRoottag(""); - ufinterface.setSender("nqyw"); - ufinterface.setBill(bill); - JAXBContext jaxbContext = JAXBContext.newInstance(Ysufinterface.class); - Marshaller marshaller = jaxbContext.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // 格式化输出,可选 - StringWriter sw = new StringWriter(); - marshaller.marshal(ufinterface, sw); - String xmlString = sw.toString(); // 这是要发送的XML字符串 - System.out.println(xmlString); - NcLog ncLog=new NcLog(); - ncLog.setOrderId(reconciliation.getBillManageId()); - ncLog.setRequestBody(xmlString); - ncLog.setResponeBody(""); - ncLog.setType(0L); - ncLog.setSendTime(new Date()); - ncLog.setOrganizationId(reconciliation.getOrganizationId()); - ncLog.setOrganizationName(reconciliation.getOrganizationName()); - ncLog.setTopOrganizationId(reconciliation.getTopOrganizationId()); - ncLogMapper.insert(ncLog); - reconciliation.setSynchronousStatus(1); - reconciliation.setSynchronousTime(new Date()); - reconciliation.setNcId("ys"+String.valueOf(reconciliation.getBillManageId())); - //reconciliationMapper.updateById(reconciliation); - CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost(url); - StringEntity postingString = new StringEntity(xmlString, "UTF-8"); - httpPost.setEntity(postingString); - httpPost.setHeader("Content-type", "application/xml"); - try { - CloseableHttpResponse response = httpClient.execute(httpPost); - String responseString = EntityUtils.toString(response.getEntity()); - System.out.println(responseString); - ncLog.setResponeBody(responseString); - // 创建DOM解析器 - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document document = builder.parse(new InputSource(new StringReader(responseString))); - - // 获取根元素 - Element root = document.getDocumentElement(); - - // 获取ufinterface元素的属性 - String billtype = root.getAttribute("billtype"); - String filename = root.getAttribute("filename"); - System.out.println("billtype: " + billtype); - System.out.println("filename: " + filename); - - // 获取sendresult节点 - NodeList sendResultList = root.getElementsByTagName("sendresult"); - if (sendResultList.getLength() > 0) { - Element sendResult = (Element) sendResultList.item(0); - - // 获取子元素内容 - String bdocid = sendResult.getElementsByTagName("bdocid").item(0).getTextContent(); - String resultcode = sendResult.getElementsByTagName("resultcode").item(0).getTextContent(); - String content = sendResult.getElementsByTagName("content").item(0).getTextContent(); - - System.out.println("bdocid: " + bdocid); - System.out.println("resultcode: " + resultcode); - System.out.println("content: " + content); - if(resultcode.equals("1")){ - reconciliation.setSynchronousStatus(1); - }else{ - reconciliation.setSynchronousStatus(2); - } - } - ncLogMapper.updateById(ncLog); - billManageMapper.updateById(reconciliation); - response.close(); - } catch (Exception e) { - reconciliation.setSynchronousStatus(2); - billManageMapper.updateById(reconciliation); - e.printStackTrace(); - } finally { - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + //保存税额等 + double allTaxRate = 0.0d; + BigDecimal allTaxAmount = BigDecimal.ZERO; + BigDecimal allTaxFreeFee = BigDecimal.ZERO; + for (BillDetail item : billDetails) { + String firstSubjectCode = item.getInvoiceItem(); + Double taxRate = billDetailMapper.getTaxRate(firstSubjectCode); + BigDecimal amount = item.getBillingAmount(); + BigDecimal taxAmount = amount.divide(BigDecimal.ONE.add(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))),10, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal taxFreeFee = amount.subtract(taxAmount); + if (item.getTaxAmount() == null) { + item.setTaxAmount(taxAmount); } + if (item.getTaxFreeFee() == null) { + item.setTaxFreeFee(taxFreeFee); + } + if (item.getTaxRate() == null) { + item.setTaxRate(taxRate); + } + allTaxRate += taxRate; + allTaxAmount = allTaxAmount.add(taxAmount); + allTaxFreeFee = allTaxFreeFee.add(taxFreeFee); + } + + if (reconciliation.getTaxRate() == null) { + reconciliation.setTaxRate(allTaxRate); + } + if (reconciliation.getTaxAmount() == null) { + reconciliation.setTaxAmount(allTaxAmount); + } + if (reconciliation.getTaxFreeFee() == null) { + reconciliation.setTaxFreeFee(allTaxFreeFee); + } + + + List ysitemList=new ArrayList(); + String url = ""; + Long organizationId = reconciliation.getOrganizationId(); + String organizationName = reconciliation.getOrganizationName(); + String ncUrl = billManageMapper.getNcUrl("nc", organizationName, organizationId); + if (ncUrl!=null&&ncUrl!="") { + url = ncUrl; } else { reconciliation.setSynchronousStatus(2); billManageMapper.updateById(reconciliation); + throw new ServiceException("未找到该组织的推送地址!"); } + String salesmanId = reconciliation.getSalesmanId(); + String customerUserDept = billManageMapper.getCustomerUserDept(salesmanId); + String deptValue = billManageMapper.getDeptValue(customerUserDept); + String deptName = billManageMapper.getDeptName(customerUserDept); + String salespersonNcCode = billManageMapper.getsalespersonNcCode(salesmanId); + String salesmanCodeNc=salespersonNcCode; + + Long settlementCustomersId = reconciliation.getSettlementCustomersId(); + SettlementCustomers settlementCustomers = settlementCustomersService.getById(settlementCustomersId); + if (settlementCustomers==null){ + throw new ServiceException("结算对象未找到!"); + } + Long settlementEntityId = settlementCustomers.getSettlementEntityId(); + Long shipperId = billManageMapper.getShipperId(settlementEntityId, organizationId); + if (shipperId==null||shipperId==0){ + throw new ServiceException("结算对象未找到!"); + } + String appointShipper=settlementCustomers.getSettlementEntity(); + String actualInvoiceCustomerId = String.valueOf(shipperId); + String customerCodeNc = billManageMapper.getCustomerCodeNc(actualInvoiceCustomerId); + String customerCodeNcJson = billManageMapper.getCustomerCodeNcJson(actualInvoiceCustomerId); + if (customerCodeNcJson != null && !customerCodeNcJson.isEmpty()) { + ObjectMapper objectMapper = new ObjectMapper(); + List> listNc = objectMapper.readValue( + customerCodeNcJson, + new TypeReference>>() {} + ); + if (listNc != null && listNc.size() > 0) { + Map targetMap = listNc.stream() + .filter(map -> { + Object codeObj = map.get("code"); + return codeObj != null && codeObj.toString().equals(reconciliation.getOrganizationId().toString()); + }) + .findFirst() + .orElse(null); + if (targetMap != null) { + customerCodeNc = (String) targetMap.get("ncCustomer"); + } + } + } + String settlementCurrency=reconciliation.getSettlementCurrency(); + String orgCodeNc = billManageMapper.getOrgCodeNc(organizationId); + String documentPreparerNcCode = billManageMapper.getDocumentPreparerNcCode(salesmanId); + String makerCodeNc = documentPreparerNcCode; + String settlementCurrencyNcCode = settlementCurrency; + + if (billDetails!=null&&billDetails.size()>0){ + for (BillDetail make : billDetails) { + if(make.getBillingAmount().compareTo(BigDecimal.ZERO)>0){ + Ysitem item=new Ysitem(); + if (deptValue != null && !deptValue.isEmpty()) { + item.setSo_deptid(deptValue); + } else { + item.setSo_deptid("NG0408"); + } + if (deptValue != null && !deptValue.isEmpty()) { + item.setPk_deptid(deptValue); + } else { + item.setPk_deptid("NG0408"); + } + //业务员nc + item.setPk_psndoc(salesmanCodeNc); + //客户nc + item.setCustomer(customerCodeNc); + item.setObjtype("0"); + item.setDirection("1"); + String invoiceItem = make.getInvoiceItem(); + List names = new ArrayList<>(); + List nccodes = new ArrayList<>(); + if (invoiceItem != null && !invoiceItem.isEmpty()) { + String invoiceItemName1 = billManageMapper.getInvoiceItemName(invoiceItem); + String invoiceItemNcCode1 = billManageMapper.getInvoiceItemNcCode(invoiceItem); + names.add(invoiceItemName1); + nccodes.add(invoiceItemNcCode1); + } + String invoiceItemName = make.getInvoiceItemName(); + //item.setDef29(invoiceItemName); + if (deptName != null && !deptName.isEmpty()) { + item.setScomment(deptName+":应收"+appointShipper+invoiceItemName); + } else { + item.setScomment("业务部:应收"+appointShipper+invoiceItemName); + } + item.setPk_currtype(settlementCurrencyNcCode); + item.setPurchaseorder(""); + item.setTaxrate(String.valueOf(make.getTaxRate())); + item.setQuantity_de("0"); + item.setMoney_de(String.valueOf(make.getBillingAmount())); + item.setMoney_bal(String.valueOf(make.getBillingAmount())); + BigDecimal tax_de=make.getTaxAmount(); + BigDecimal notax_de=make.getTaxFreeFee(); + item.setNotax_de(String.valueOf(notax_de)); + item.setLocal_tax_de(String.valueOf(tax_de)); + item.setTax_de(String.valueOf(tax_de)); + item.setPrice(String.valueOf(make.getBillingAmount())); + item.setTaxprice(String.valueOf(make.getBillingAmount())); + //费用类别 + String feeType = make.getFeeType(); + String serviceItemsCodeNc = billManageMapper.getServiceItemsCodeNc(feeType); + if (serviceItemsCodeNc != null && !serviceItemsCodeNc.isEmpty()) { + item.setDef75(serviceItemsCodeNc); + } else { + item.setDef75("T04"); + } + String invoiceItem1 = make.getInvoiceItem(); + if (invoiceItem1 != null && !invoiceItem1.isEmpty()) { + item.setDef29(invoiceItem1); + } + if (nccodes != null && !nccodes.isEmpty()&&nccodes.size()>0) { + item.setDef29(nccodes.get(0)); + } + item.setTaxcodeid("ZL01"); + item.setInvoiceno(""); + ysitemList.add(item); + } + } + } + + Ysbodys bodys=new Ysbodys(); + bodys.setItem(ysitemList); + Ysbillhead billhead=new Ysbillhead(); + billhead.setPk_group("CNK"); + if (orgCodeNc != null && !orgCodeNc.isEmpty()) { + billhead.setPk_org(orgCodeNc); + billhead.setSett_org(orgCodeNc); + } else { + billhead.setPk_org("NG04"); + billhead.setSett_org("NG04"); + } + billhead.setCreationtime(dateString); + billhead.setCreator(makerCodeNc); + billhead.setPk_billtype("F0"); + billhead.setPk_tradetype("D0"); + billhead.setBillclass("ys"); + billhead.setIsinit("N"); + date=reconciliation.getCreateTime(); + dateString = sdf.format(date); + billhead.setBilldate(dateString); + billhead.setSyscode("0"); + billhead.setBillno(""); + billhead.setDef59(""); + billhead.setSrc_syscode("0"); + billhead.setBillstatus("0"); + billhead.setBillmaker(makerCodeNc); + billhead.setPk_busitype(""); + billhead.setBillyear(sdf1.format(date)); + billhead.setBillperiod(sdf2.format(date)); + billhead.setEffectstatus("0"); + billhead.setDef28("nqyw"); + billhead.setDef29(reconciliation.getBillNumber()); + billhead.setBodys(bodys); + Ysbill bill=new Ysbill(); + bill.setId("ys"+String.valueOf(reconciliation.getBillManageId())+"_"+1); + bill.setBillhead(billhead); + Ysufinterface ufinterface=new Ysufinterface(); + ufinterface.setAccount("NKNC"); + ufinterface.setBilltype("F0"); + ufinterface.setBusinessunitcode(""); + ufinterface.setFilename(""); + ufinterface.setIsexchange("Y"); + if (orgCodeNc != null && !orgCodeNc.isEmpty()) { + ufinterface.setOrgcode(orgCodeNc); + ufinterface.setReceiver(orgCodeNc); + } else { + ufinterface.setOrgcode("NG04"); + ufinterface.setReceiver("NG04"); + } + ufinterface.setReplace("Y"); + ufinterface.setRoottag(""); + ufinterface.setSender("nqyw"); + ufinterface.setBill(bill); + JAXBContext jaxbContext = JAXBContext.newInstance(Ysufinterface.class); + Marshaller marshaller = jaxbContext.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // 格式化输出,可选 + StringWriter sw = new StringWriter(); + marshaller.marshal(ufinterface, sw); + String xmlString = sw.toString(); // 这是要发送的XML字符串 + System.out.println(xmlString); + NcLog ncLog=new NcLog(); + ncLog.setOrderId(reconciliation.getBillManageId()); + ncLog.setRequestBody(xmlString); + ncLog.setResponeBody(""); + ncLog.setType(0L); + ncLog.setSendTime(new Date()); + ncLog.setOrganizationId(reconciliation.getOrganizationId()); + ncLog.setOrganizationName(reconciliation.getOrganizationName()); + ncLog.setTopOrganizationId(reconciliation.getTopOrganizationId()); + ncLogMapper.insert(ncLog); + reconciliation.setSynchronousStatus(1); + reconciliation.setSynchronousTime(new Date()); + reconciliation.setNcId("ys"+String.valueOf(reconciliation.getBillManageId())); + //reconciliationMapper.updateById(reconciliation); + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + StringEntity postingString = new StringEntity(xmlString, "UTF-8"); + httpPost.setEntity(postingString); + httpPost.setHeader("Content-type", "application/xml"); + try { + CloseableHttpResponse response = httpClient.execute(httpPost); + String responseString = EntityUtils.toString(response.getEntity()); + System.out.println(responseString); + ncLog.setResponeBody(responseString); + // 创建DOM解析器 + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(new InputSource(new StringReader(responseString))); + + // 获取根元素 + Element root = document.getDocumentElement(); + + // 获取ufinterface元素的属性 + String billtype = root.getAttribute("billtype"); + String filename = root.getAttribute("filename"); + System.out.println("billtype: " + billtype); + System.out.println("filename: " + filename); + + // 获取sendresult节点 + NodeList sendResultList = root.getElementsByTagName("sendresult"); + if (sendResultList.getLength() > 0) { + Element sendResult = (Element) sendResultList.item(0); + + // 获取子元素内容 + String bdocid = sendResult.getElementsByTagName("bdocid").item(0).getTextContent(); + String resultcode = sendResult.getElementsByTagName("resultcode").item(0).getTextContent(); + String content = sendResult.getElementsByTagName("content").item(0).getTextContent(); + + System.out.println("bdocid: " + bdocid); + System.out.println("resultcode: " + resultcode); + System.out.println("content: " + content); + if(resultcode.equals("1")){ + reconciliation.setSynchronousStatus(1); + }else{ + reconciliation.setSynchronousStatus(2); + } + } + ncLogMapper.updateById(ncLog); + billManageMapper.updateById(reconciliation); + response.close(); + } catch (Exception e) { + reconciliation.setSynchronousStatus(2); + billManageMapper.updateById(reconciliation); + e.printStackTrace(); + } finally { + try { + httpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } catch (JAXBException e) { reconciliation.setSynchronousStatus(2); billManageMapper.updateById(reconciliation); @@ -469,6 +515,298 @@ public class BillManageImpl extends ServiceImpl im return true; } + //按发票推送版本 +// public boolean synchronousNc_TY(String businessDocumentDetaliId) { +// BillManage reconciliation=billManageMapper.selectById(businessDocumentDetaliId); +// if(reconciliation.getSynchronousStatus()==1){ +// throw new ServiceException("该记录已同步,不需要再次同步"); +// } +// try { +// Date date = reconciliation.getCreateTime(); +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy"); +// SimpleDateFormat sdf2 = new SimpleDateFormat("MM"); +// String dateString = sdf.format(date); +// String invoiceId = reconciliation.getInvoiceId(); +// List bmsMakeOutInvoices = bmsMakeOutInvoiceMapper.selectList(new LambdaQueryWrapper().eq(BmsMakeOutInvoice::getInvoiceId, invoiceId)); +// if (bmsMakeOutInvoices != null && bmsMakeOutInvoices.size() > 0){ +// int count = 0; +// for (BmsMakeOutInvoice make : bmsMakeOutInvoices) { +// count++; +// List ysitemList=new ArrayList(); +// String url = ""; +// Long organizationId = reconciliation.getOrganizationId(); +// String organizationName = reconciliation.getOrganizationName(); +// String ncUrl = billManageMapper.getNcUrl("nc", organizationName, organizationId); +// if (ncUrl!=null&&ncUrl!="") { +// url = ncUrl; +// } else { +// reconciliation.setSynchronousStatus(2); +// billManageMapper.updateById(reconciliation); +// throw new ServiceException("未找到该组织的推送地址!"); +// } +// String salesmanId = reconciliation.getSalesmanId(); +// String customerUserDept = billManageMapper.getCustomerUserDept(salesmanId); +// String deptValue = billManageMapper.getDeptValue(customerUserDept); +// String deptName = billManageMapper.getDeptName(customerUserDept); +// String salespersonNcCode = billManageMapper.getsalespersonNcCode(salesmanId); +// String salesmanCodeNc=salespersonNcCode; +// String appointShipper=make.getActualInvoiceCustomerName(); +// String actualInvoiceCustomerId = make.getActualInvoiceCustomerId(); +// String customerCodeNc = billManageMapper.getCustomerCodeNc(actualInvoiceCustomerId); +// String customerCodeNcJson = billManageMapper.getCustomerCodeNcJson(actualInvoiceCustomerId); +// if (customerCodeNcJson != null && !customerCodeNcJson.isEmpty()) { +// ObjectMapper objectMapper = new ObjectMapper(); +// List> listNc = objectMapper.readValue( +// customerCodeNcJson, +// new TypeReference>>() {} +// ); +// if (listNc != null && listNc.size() > 0) { +// Map targetMap = listNc.stream() +// .filter(map -> { +// Object codeObj = map.get("code"); +// return codeObj != null && codeObj.toString().equals(reconciliation.getOrganizationId().toString()); +// }) +// .findFirst() +// .orElse(null); +// if (targetMap != null) { +// customerCodeNc = (String) targetMap.get("ncCustomer"); +// } +// } +// } +// String settlementCurrency=reconciliation.getSettlementCurrency(); +// String orgCodeNc = billManageMapper.getOrgCodeNc(organizationId); +// String documentPreparerNcCode = billManageMapper.getDocumentPreparerNcCode(salesmanId); +// String makerCodeNc = documentPreparerNcCode; +// String settlementCurrencyNcCode = settlementCurrency; +// String invoiceNumber=make.getInvoiceNumber(); +// List bmsMakeOutInvoiceItems = bmsMakeOutInvoiceItemMapper.selectList(new LambdaQueryWrapper().eq(BmsMakeOutInvoiceItem::getMakeId, make.getId())); +// if (bmsMakeOutInvoiceItems != null && bmsMakeOutInvoiceItems.size() > 0) { +// for (BmsMakeOutInvoiceItem item1 : bmsMakeOutInvoiceItems) { +// if(item1.getInvoiceValue().compareTo(BigDecimal.ZERO)>0){ +// Ysitem item=new Ysitem(); +// if (deptValue != null && !deptValue.isEmpty()) { +// item.setSo_deptid(deptValue); +// } else { +// item.setSo_deptid("NG0408"); +// } +// if (deptValue != null && !deptValue.isEmpty()) { +// item.setPk_deptid(deptValue); +// } else { +// item.setPk_deptid("NG0408"); +// } +// //业务员nc +// item.setPk_psndoc(salesmanCodeNc); +// //客户nc +// item.setCustomer(customerCodeNc); +// item.setObjtype("0"); +// item.setDirection("1"); +// String invoiceItem = item1.getInvoiceItem(); +// List names = new ArrayList<>(); +// List nccodes = new ArrayList<>(); +// if (invoiceItem != null && !invoiceItem.isEmpty()) { +// String[] items = invoiceItem.split(","); +// for (String s : items) { +// String invoiceItemName1 = billManageMapper.getInvoiceItemName(s); +// String invoiceItemNcCode1 = billManageMapper.getInvoiceItemNcCode(s); +// names.add(invoiceItemName1); +// nccodes.add(invoiceItemNcCode1); +// } +// } +// String invoiceItemName = String.join(",", names); +// //item.setDef29(invoiceItemName); +// if (deptName != null && !deptName.isEmpty()) { +// item.setScomment(deptName+":应收"+appointShipper+invoiceItemName+invoiceNumber); +// } else { +// item.setScomment("业务部:应收"+appointShipper+invoiceItemName+invoiceNumber); +// } +// // item.setPk_currtype("CNY"); +// item.setPk_currtype(settlementCurrencyNcCode); +// item.setPurchaseorder(""); +// item.setTaxrate(String.valueOf(item1.getTaxRate())); +// item.setQuantity_de("0"); +// item.setMoney_de(String.valueOf(item1.getInvoiceValue())); +// item.setMoney_bal(String.valueOf(item1.getInvoiceValue())); +// BigDecimal tax_de=item1.getTaxAmount(); +// BigDecimal notax_de=item1.getTaxFreeFee(); +// item.setNotax_de(String.valueOf(notax_de)); +// item.setLocal_tax_de(String.valueOf(tax_de)); +// item.setTax_de(String.valueOf(tax_de)); +// item.setPrice(String.valueOf(item1.getInvoiceValue())); +// item.setTaxprice(String.valueOf(item1.getInvoiceValue())); +//// 费用类别 +// String feeType = item1.getFeeType(); +// String serviceItemsCodeNc = billManageMapper.getServiceItemsCodeNc(feeType); +// if (serviceItemsCodeNc != null && !serviceItemsCodeNc.isEmpty()) { +// item.setDef75(serviceItemsCodeNc); +// } else { +// item.setDef75("T04"); +// } +// String invoiceItem1 = item1.getInvoiceItem(); +// if (invoiceItem1 != null && !invoiceItem1.isEmpty()) { +// String[] split = invoiceItem1.split(","); +// item.setDef29(split[0]); +// //item.setDef29(invoiceItem1); +// } +// if (nccodes != null && !nccodes.isEmpty()&&nccodes.size()>0) { +// item.setDef29(nccodes.get(0)); +// } +// item.setTaxcodeid("ZL01"); +// item.setInvoiceno(invoiceNumber); +// ysitemList.add(item); +// } +// } +// } +// +// Ysbodys bodys=new Ysbodys(); +// bodys.setItem(ysitemList); +// Ysbillhead billhead=new Ysbillhead(); +// billhead.setPk_group("CNK"); +// if (orgCodeNc != null && !orgCodeNc.isEmpty()) { +// billhead.setPk_org(orgCodeNc); +// billhead.setSett_org(orgCodeNc); +// } else { +// billhead.setPk_org("NG04"); +// billhead.setSett_org("NG04"); +// } +// billhead.setCreationtime(dateString); +// billhead.setCreator(makerCodeNc); +// billhead.setPk_billtype("F0"); +// billhead.setPk_tradetype("D0"); +// billhead.setBillclass("ys"); +// billhead.setIsinit("N"); +// date=reconciliation.getCreateTime(); +// dateString = sdf.format(date); +// billhead.setBilldate(dateString); +// billhead.setSyscode("0"); +// billhead.setBillno(""); +// billhead.setDef59(""); +// billhead.setSrc_syscode("0"); +// billhead.setBillstatus("0"); +// billhead.setBillmaker(makerCodeNc); +// billhead.setPk_busitype(""); +// billhead.setBillyear(sdf1.format(date)); +// billhead.setBillperiod(sdf2.format(date)); +// billhead.setEffectstatus("0"); +// billhead.setDef28("nqyw"); +// billhead.setDef29(reconciliation.getBillNumber()); +// billhead.setBodys(bodys); +// Ysbill bill=new Ysbill(); +// bill.setId("ys"+String.valueOf(reconciliation.getBillManageId())+"_"+count); +// bill.setBillhead(billhead); +// Ysufinterface ufinterface=new Ysufinterface(); +// ufinterface.setAccount("NKNC"); +// ufinterface.setBilltype("F0"); +// ufinterface.setBusinessunitcode(""); +// ufinterface.setFilename(""); +// ufinterface.setIsexchange("Y"); +// if (orgCodeNc != null && !orgCodeNc.isEmpty()) { +// ufinterface.setOrgcode(orgCodeNc); +// ufinterface.setReceiver(orgCodeNc); +// } else { +// ufinterface.setOrgcode("NG04"); +// ufinterface.setReceiver("NG04"); +// } +// ufinterface.setReplace("Y"); +// ufinterface.setRoottag(""); +// ufinterface.setSender("nqyw"); +// ufinterface.setBill(bill); +// JAXBContext jaxbContext = JAXBContext.newInstance(Ysufinterface.class); +// Marshaller marshaller = jaxbContext.createMarshaller(); +// marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); +// marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // 格式化输出,可选 +// StringWriter sw = new StringWriter(); +// marshaller.marshal(ufinterface, sw); +// String xmlString = sw.toString(); // 这是要发送的XML字符串 +// System.out.println(xmlString); +// NcLog ncLog=new NcLog(); +// ncLog.setOrderId(reconciliation.getBillManageId()); +// ncLog.setRequestBody(xmlString); +// ncLog.setResponeBody(""); +// ncLog.setType(0L); +// ncLog.setSendTime(new Date()); +// ncLog.setOrganizationId(reconciliation.getOrganizationId()); +// ncLog.setOrganizationName(reconciliation.getOrganizationName()); +// ncLog.setTopOrganizationId(reconciliation.getTopOrganizationId()); +// ncLogMapper.insert(ncLog); +// reconciliation.setSynchronousStatus(1); +// reconciliation.setSynchronousTime(new Date()); +// reconciliation.setNcId("ys"+String.valueOf(reconciliation.getBillManageId())); +// //reconciliationMapper.updateById(reconciliation); +// CloseableHttpClient httpClient = HttpClients.createDefault(); +// HttpPost httpPost = new HttpPost(url); +// StringEntity postingString = new StringEntity(xmlString, "UTF-8"); +// httpPost.setEntity(postingString); +// httpPost.setHeader("Content-type", "application/xml"); +// try { +// CloseableHttpResponse response = httpClient.execute(httpPost); +// String responseString = EntityUtils.toString(response.getEntity()); +// System.out.println(responseString); +// ncLog.setResponeBody(responseString); +// // 创建DOM解析器 +// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); +// DocumentBuilder builder = factory.newDocumentBuilder(); +// Document document = builder.parse(new InputSource(new StringReader(responseString))); +// +// // 获取根元素 +// Element root = document.getDocumentElement(); +// +// // 获取ufinterface元素的属性 +// String billtype = root.getAttribute("billtype"); +// String filename = root.getAttribute("filename"); +// System.out.println("billtype: " + billtype); +// System.out.println("filename: " + filename); +// +// // 获取sendresult节点 +// NodeList sendResultList = root.getElementsByTagName("sendresult"); +// if (sendResultList.getLength() > 0) { +// Element sendResult = (Element) sendResultList.item(0); +// +// // 获取子元素内容 +// String bdocid = sendResult.getElementsByTagName("bdocid").item(0).getTextContent(); +// String resultcode = sendResult.getElementsByTagName("resultcode").item(0).getTextContent(); +// String content = sendResult.getElementsByTagName("content").item(0).getTextContent(); +// +// System.out.println("bdocid: " + bdocid); +// System.out.println("resultcode: " + resultcode); +// System.out.println("content: " + content); +// if(resultcode.equals("1")){ +// reconciliation.setSynchronousStatus(1); +// }else{ +// reconciliation.setSynchronousStatus(2); +// } +// } +// ncLogMapper.updateById(ncLog); +// billManageMapper.updateById(reconciliation); +// response.close(); +// } catch (Exception e) { +// reconciliation.setSynchronousStatus(2); +// billManageMapper.updateById(reconciliation); +// e.printStackTrace(); +// } finally { +// try { +// httpClient.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } +// } else { +// reconciliation.setSynchronousStatus(2); +// billManageMapper.updateById(reconciliation); +// } +// } catch (JAXBException e) { +// reconciliation.setSynchronousStatus(2); +// billManageMapper.updateById(reconciliation); +// e.printStackTrace(); +// } catch (JsonMappingException e) { +// throw new RuntimeException(e); +// } catch (JsonProcessingException e) { +// throw new RuntimeException(e); +// } +// return true; +// } + @Override public boolean synchronousNcSK(String businessDocumentDetaliIds) { String [] businessDocumentDetaliIdArray=businessDocumentDetaliIds.split(","); @@ -500,273 +838,310 @@ public class BillManageImpl extends ServiceImpl im SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy"); SimpleDateFormat sdf2 = new SimpleDateFormat("MM"); String dateString = sdf.format(date); - String invoiceId = reconciliation.getInvoiceId(); - ReconciliationDTO makeQuery=new ReconciliationDTO(); - makeQuery.setInnerNumber(invoiceId); - List bmsMakeOutInvoices = bmsMakeOutInvoiceMapper.selectList(new LambdaQueryWrapper().eq(BmsMakeOutInvoice::getInvoiceId, invoiceId)); - if (bmsMakeOutInvoices != null && bmsMakeOutInvoices.size() > 0) { - int count= 0; - for (BmsMakeOutInvoice make : bmsMakeOutInvoices) { - count++; - List ysitemList=new ArrayList(); - ReconciliationDTO reconciliationDTO=new ReconciliationDTO(); - reconciliationDTO.setInnerNumber(reconciliation.getBillNumber()); - String url = ""; - Long organizationId = reconciliation.getOrganizationId(); - String orgCodeNc = billManageMapper.getOrgCodeNc(organizationId); - String organizationName = reconciliation.getOrganizationName(); - String ncUrl = billManageMapper.getNcUrl("nc", organizationName, organizationId); - if (ncUrl!=null&&ncUrl!="") { - url = ncUrl; - } else { - reconciliation.setSkSynchronousStatus(2); - billManageMapper.updateById(reconciliation); - throw new ServiceException("未找到该组织的推送地址!"); - } - List bmsMakeOutInvoiceItems = bmsMakeOutInvoiceItemMapper.selectList(new LambdaQueryWrapper().eq(BmsMakeOutInvoiceItem::getMakeId, make.getId())); - String makerCodeNc = ""; - if(bmsMakeOutInvoiceItems != null && bmsMakeOutInvoiceItems.size() > 0){ - if(ObjectUtil.isNotNull(bmsMakeOutInvoiceItems)){ - // 汇总 list 中 invoiceValue 的总值 - BigDecimal totalInvoiceValue = bmsMakeOutInvoiceItems.stream() - .map(BmsMakeOutInvoiceItem::getInvoiceValue) - .filter(java.util.Objects::nonNull) - .reduce(BigDecimal.ZERO, BigDecimal::add); + List billDetails = billDetailService.list(new LambdaQueryWrapper() + .eq(BillDetail::getBillManageId, reconciliation.getBillManageId()) + .eq(BillDetail::getDelFlag, 1)); - // 将 feeType 用、拼接起来 - String feeTypes = bmsMakeOutInvoiceItems.stream() - .map(BmsMakeOutInvoiceItem::getFeeType) - .filter(java.util.Objects::nonNull) - .collect(java.util.stream.Collectors.joining("、")); - - // 按 createTime 倒序排序并获取第一条记录 - BmsMakeOutInvoiceItem firstItem = bmsMakeOutInvoiceItems.stream() - .sorted((a, b) -> { - if (a.getCreateTime() == null) return 1; - if (b.getCreateTime() == null) return -1; - return b.getCreateTime().compareTo(a.getCreateTime()); - }) - .findFirst() - .orElse(null); - String salesmanId = reconciliation.getSalesmanId(); - String customerUserDept = billManageMapper.getCustomerUserDept(salesmanId); - String deptValue = billManageMapper.getDeptValue(customerUserDept); - String deptName = billManageMapper.getDeptName(customerUserDept); - String salespersonNcCode = billManageMapper.getsalespersonNcCode(salesmanId); - String salesmanCodeNc=salespersonNcCode; - String appointShipper=make.getActualInvoiceCustomerName(); - String actualInvoiceCustomerId = make.getActualInvoiceCustomerId(); - String customerCodeNc = billManageMapper.getCustomerCodeNc(actualInvoiceCustomerId); - String customerCodeNcJson = billManageMapper.getCustomerCodeNcJson(actualInvoiceCustomerId); - if (customerCodeNcJson != null && !customerCodeNcJson.isEmpty()) { - ObjectMapper objectMapper = new ObjectMapper(); - List> listNc = objectMapper.readValue( - customerCodeNcJson, - new TypeReference>>() {} - ); - if (listNc != null && listNc.size() > 0) { - Map targetMap = listNc.stream() - .filter(map -> { - Object codeObj = map.get("code"); - return codeObj != null && codeObj.toString().equals(reconciliation.getOrganizationId().toString()); - }) - .findFirst() - .orElse(null); - if (targetMap != null) { - customerCodeNc = (String) targetMap.get("ncCustomer"); - } - } - } - String documentPreparerNcCode = billManageMapper.getDocumentPreparerNcCode(salesmanId); - String settlementCurrency=reconciliation.getSettlementCurrency(); - String settlementCurrencyNcCode = settlementCurrency; - makerCodeNc=documentPreparerNcCode; - SKitem item=new SKitem(); - if (deptValue != null && !deptValue.isEmpty()) { - item.setSo_deptid(deptValue); - } else { - item.setSo_deptid("NG0408"); - } - if (deptValue != null && !deptValue.isEmpty()) { - item.setPk_deptid(deptValue); - } else { - item.setPk_deptid("NG0408"); - } - item.setCheckdirection("ar"); - item.setPk_psndoc(salesmanCodeNc); - item.setCustomer(customerCodeNc); - item.setPurchaseorder(""); - item.setObjtype("0"); - item.setDirection("1"); - if (deptName != null && !deptName.isEmpty()) { - if (feeTypes != null && !feeTypes.isEmpty()) { - item.setScomment(deptName+":"+appointShipper+feeTypes); - } else { - item.setScomment(deptName+":"+appointShipper+feeTypes); - } - } else { - if (feeTypes != null && !feeTypes.isEmpty()) { - item.setScomment("业务部:"+appointShipper+feeTypes); - } else { - item.setScomment("业务部:"+appointShipper+feeTypes); - } - } - // 费用类别 - String feeType = firstItem.getFeeType(); - String serviceItemsCodeNc = billManageMapper.getServiceItemsCodeNc(feeType); - if (serviceItemsCodeNc != null && !serviceItemsCodeNc.isEmpty()) { - item.setDef75(serviceItemsCodeNc); - } else { - item.setDef75("T10"); - } - String invoiceItem1 = firstItem.getInvoiceItem(); - if (invoiceItem1 != null && !invoiceItem1.isEmpty()) { - String[] split = invoiceItem1.split(","); - item.setDef29(split[0]); - } - item.setPk_currtype(settlementCurrencyNcCode); - item.setMoney_cr(String.valueOf(totalInvoiceValue)); - item.setMoney_bal(String.valueOf(totalInvoiceValue)); - ysitemList.add(item); - } - } - SKbodys bodys=new SKbodys(); - bodys.setItem(ysitemList); - SKbillhead billhead=new SKbillhead(); - billhead.setPk_group("CNK"); - if (orgCodeNc != null && !orgCodeNc.isEmpty()) { - billhead.setPk_org(orgCodeNc); - billhead.setSett_org(orgCodeNc); - } else { - billhead.setPk_org("NG04"); - billhead.setSett_org("NG04"); - } - billhead.setCreationtime(dateString); - billhead.setPk_billtype("F2"); - billhead.setCreator(makerCodeNc); - billhead.setPk_tradetype("D2"); - billhead.setBillclass("sk"); - billhead.setBilldate(dateString); - billhead.setSyscode("0"); - billhead.setBillno(""); - billhead.setDef59(""); - billhead.setSrc_syscode("0"); - billhead.setBillstatus("0"); - billhead.setBillmaker(makerCodeNc); - billhead.setPk_busitype(""); - billhead.setBillyear(sdf1.format(date)); - billhead.setBillperiod(sdf2.format(date)); - billhead.setEffectstatus("0"); - billhead.setDef28("nqyw"); - billhead.setDef29(reconciliation.getBillNumber()); - billhead.setBodys(bodys); - SKbill bill=new SKbill(); - bill.setId("sk"+String.valueOf(reconciliation.getBillManageId())+"_"+count); - bill.setBillhead(billhead); - SKufinterface ufinterface=new SKufinterface(); - ufinterface.setAccount("NKNC"); - ufinterface.setBilltype("F2"); - ufinterface.setBusinessunitcode(""); - ufinterface.setFilename(""); - ufinterface.setIsexchange("Y"); - if (orgCodeNc != null && !orgCodeNc.isEmpty()) { - ufinterface.setOrgcode(orgCodeNc); - ufinterface.setReceiver(orgCodeNc); - } else { - ufinterface.setOrgcode("NG04"); - ufinterface.setReceiver("NG04"); - } - ufinterface.setReplace("Y"); - ufinterface.setRoottag(""); - ufinterface.setSender("nqyw"); - ufinterface.setBill(bill); - JAXBContext jaxbContext = null; - //String xmlString =""; - jaxbContext = JAXBContext.newInstance(SKufinterface.class); - Marshaller marshaller = jaxbContext.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // 格式化输出,可选 - StringWriter sw = new StringWriter(); - marshaller.marshal(ufinterface, sw); - String xmlString = sw.toString(); // 这是要发送的XML字符串 - System.out.println(xmlString); - NcLog ncLog=new NcLog(); - ncLog.setOrderId(reconciliation.getBillManageId()); - ncLog.setRequestBody(xmlString); - ncLog.setResponeBody(""); - ncLog.setType(1L); - ncLog.setSendTime(new Date()); - ncLog.setOrganizationId(reconciliation.getOrganizationId()); - ncLog.setOrganizationName(reconciliation.getOrganizationName()); - ncLog.setTopOrganizationId(reconciliation.getTopOrganizationId()); - ncLogMapper.insert(ncLog); - reconciliation.setSkSynchronousStatus(1); - reconciliation.setSkSynchronousTime(new Date()); - reconciliation.setSkNcId("sk"+String.valueOf(reconciliation.getBillManageId())); - //reconciliationMapper.updateById(reconciliation); - CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpPost httpPost = new HttpPost(url); - StringEntity postingString = new StringEntity(xmlString, "UTF-8"); - httpPost.setEntity(postingString); - httpPost.setHeader("Content-type", "application/xml"); - try { - CloseableHttpResponse response = httpClient.execute(httpPost); - String responseString = EntityUtils.toString(response.getEntity()); - System.out.println(responseString); - ncLog.setResponeBody(responseString); - // 创建DOM解析器 - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - DocumentBuilder builder = factory.newDocumentBuilder(); - Document document = builder.parse(new InputSource(new StringReader(responseString))); - - // 获取根元素 - Element root = document.getDocumentElement(); - - // 获取ufinterface元素的属性 - String billtype = root.getAttribute("billtype"); - String filename = root.getAttribute("filename"); - System.out.println("billtype: " + billtype); - System.out.println("filename: " + filename); - - // 获取sendresult节点 - NodeList sendResultList = root.getElementsByTagName("sendresult"); - if (sendResultList.getLength() > 0) { - Element sendResult = (Element) sendResultList.item(0); - - // 获取子元素内容 - String bdocid = sendResult.getElementsByTagName("bdocid").item(0).getTextContent(); - String resultcode = sendResult.getElementsByTagName("resultcode").item(0).getTextContent(); - String content = sendResult.getElementsByTagName("content").item(0).getTextContent(); - - System.out.println("bdocid: " + bdocid); - System.out.println("resultcode: " + resultcode); - System.out.println("content: " + content); - if(resultcode.equals("1")){ - reconciliation.setSkSynchronousStatus(1); - }else{ - reconciliation.setSkSynchronousStatus(2); - } - } - ncLogMapper.updateById(ncLog); - billManageMapper.updateById(reconciliation); - response.close(); - } catch (Exception e) { - reconciliation.setSkSynchronousStatus(2); - billManageMapper.updateById(reconciliation); - e.printStackTrace(); - } finally { - try { - httpClient.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } + //保存税额等 + double allTaxRate = 0.0d; + BigDecimal allTaxAmount = BigDecimal.ZERO; + BigDecimal allTaxFreeFee = BigDecimal.ZERO; + for (BillDetail item : billDetails) { + String firstSubjectCode = item.getInvoiceItem(); + Double taxRate = billDetailMapper.getTaxRate(firstSubjectCode); + BigDecimal amount = item.getBillingAmount(); + BigDecimal taxAmount = amount.divide(BigDecimal.ONE.add(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))),10, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(taxRate).divide(BigDecimal.valueOf(100))).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal taxFreeFee = amount.subtract(taxAmount); + if (item.getTaxAmount() == null) { + item.setTaxAmount(taxAmount); } + if (item.getTaxFreeFee() == null) { + item.setTaxFreeFee(taxFreeFee); + } + if (item.getTaxRate() == null) { + item.setTaxRate(taxRate); + } + allTaxRate += taxRate; + allTaxAmount = allTaxAmount.add(taxAmount); + allTaxFreeFee = allTaxFreeFee.add(taxFreeFee); + } + + if (reconciliation.getTaxRate() == null) { + reconciliation.setTaxRate(allTaxRate); + } + if (reconciliation.getTaxAmount() == null) { + reconciliation.setTaxAmount(allTaxAmount); + } + if (reconciliation.getTaxFreeFee() == null) { + reconciliation.setTaxFreeFee(allTaxFreeFee); + } + + List ysitemList=new ArrayList(); + ReconciliationDTO reconciliationDTO=new ReconciliationDTO(); + reconciliationDTO.setInnerNumber(reconciliation.getBillNumber()); + String url = ""; + Long organizationId = reconciliation.getOrganizationId(); + String orgCodeNc = billManageMapper.getOrgCodeNc(organizationId); + String organizationName = reconciliation.getOrganizationName(); + String ncUrl = billManageMapper.getNcUrl("nc", organizationName, organizationId); + if (ncUrl!=null&&ncUrl!="") { + url = ncUrl; } else { reconciliation.setSkSynchronousStatus(2); billManageMapper.updateById(reconciliation); + throw new ServiceException("未找到该组织的推送地址!"); } + String makerCodeNc = ""; + if(billDetails != null && billDetails.size() > 0){ + if(ObjectUtil.isNotNull(billDetails)){ + // 汇总 list 中 invoiceValue 的总值 + BigDecimal totalInvoiceValue = billDetails.stream() + .map(BillDetail::getBillingAmount) + .filter(java.util.Objects::nonNull) + .reduce(BigDecimal.ZERO, BigDecimal::add); + + // 将 feeType 用、拼接起来 + String feeTypes = billDetails.stream() + .map(BillDetail::getInvoiceItemName) + .filter(java.util.Objects::nonNull) + .collect(java.util.stream.Collectors.joining("、")); + + // 按 createTime 倒序排序并获取第一条记录 + BillDetail firstItem = billDetails.stream() + .sorted((a, b) -> { + if (a.getCreateTime() == null) return 1; + if (b.getCreateTime() == null) return -1; + return b.getCreateTime().compareTo(a.getCreateTime()); + }) + .findFirst() + .orElse(null); + String salesmanId = reconciliation.getSalesmanId(); + String customerUserDept = billManageMapper.getCustomerUserDept(salesmanId); + String deptValue = billManageMapper.getDeptValue(customerUserDept); + String deptName = billManageMapper.getDeptName(customerUserDept); + String salespersonNcCode = billManageMapper.getsalespersonNcCode(salesmanId); + String salesmanCodeNc=salespersonNcCode; + Long settlementCustomersId = reconciliation.getSettlementCustomersId(); + SettlementCustomers settlementCustomers = settlementCustomersService.getById(settlementCustomersId); + if (settlementCustomers==null){ + throw new ServiceException("结算对象未找到!"); + } + Long settlementEntityId = settlementCustomers.getSettlementEntityId(); + Long shipperId = billManageMapper.getShipperId(settlementEntityId, organizationId); + if (shipperId==null||shipperId==0){ + throw new ServiceException("结算对象未找到!"); + } + String appointShipper=settlementCustomers.getSettlementEntity(); + String actualInvoiceCustomerId = String.valueOf(shipperId); + String customerCodeNc = billManageMapper.getCustomerCodeNc(actualInvoiceCustomerId); + String customerCodeNcJson = billManageMapper.getCustomerCodeNcJson(actualInvoiceCustomerId); + if (customerCodeNcJson != null && !customerCodeNcJson.isEmpty()) { + ObjectMapper objectMapper = new ObjectMapper(); + List> listNc = objectMapper.readValue( + customerCodeNcJson, + new TypeReference>>() {} + ); + if (listNc != null && listNc.size() > 0) { + Map targetMap = listNc.stream() + .filter(map -> { + Object codeObj = map.get("code"); + return codeObj != null && codeObj.toString().equals(reconciliation.getOrganizationId().toString()); + }) + .findFirst() + .orElse(null); + if (targetMap != null) { + customerCodeNc = (String) targetMap.get("ncCustomer"); + } + } + } + String documentPreparerNcCode = billManageMapper.getDocumentPreparerNcCode(salesmanId); + String settlementCurrency=reconciliation.getSettlementCurrency(); + String settlementCurrencyNcCode = settlementCurrency; + makerCodeNc=documentPreparerNcCode; + SKitem item=new SKitem(); + if (deptValue != null && !deptValue.isEmpty()) { + item.setSo_deptid(deptValue); + } else { + item.setSo_deptid("NG0408"); + } + if (deptValue != null && !deptValue.isEmpty()) { + item.setPk_deptid(deptValue); + } else { + item.setPk_deptid("NG0408"); + } + item.setCheckdirection("ar"); + item.setPk_psndoc(salesmanCodeNc); + item.setCustomer(customerCodeNc); + item.setPurchaseorder(""); + item.setObjtype("0"); + item.setDirection("1"); + if (deptName != null && !deptName.isEmpty()) { + if (feeTypes != null && !feeTypes.isEmpty()) { + item.setScomment(deptName+":"+appointShipper+feeTypes); + } else { + item.setScomment(deptName+":"+appointShipper+feeTypes); + } + } else { + if (feeTypes != null && !feeTypes.isEmpty()) { + item.setScomment("业务部:"+appointShipper+feeTypes); + } else { + item.setScomment("业务部:"+appointShipper+feeTypes); + } + } + // 费用类别 + String feeType = firstItem.getFeeType(); + String serviceItemsCodeNc = billManageMapper.getServiceItemsCodeNc(feeType); + if (serviceItemsCodeNc != null && !serviceItemsCodeNc.isEmpty()) { + item.setDef75(serviceItemsCodeNc); + } else { + item.setDef75("T10"); + } + String invoiceItem1 = firstItem.getInvoiceItem(); + if (invoiceItem1 != null && !invoiceItem1.isEmpty()) { + String[] split = invoiceItem1.split(","); + item.setDef29(split[0]); + } + item.setPk_currtype(settlementCurrencyNcCode); + item.setMoney_cr(String.valueOf(totalInvoiceValue)); + item.setMoney_bal(String.valueOf(totalInvoiceValue)); + ysitemList.add(item); + } + } + SKbodys bodys=new SKbodys(); + bodys.setItem(ysitemList); + SKbillhead billhead=new SKbillhead(); + billhead.setPk_group("CNK"); + if (orgCodeNc != null && !orgCodeNc.isEmpty()) { + billhead.setPk_org(orgCodeNc); + billhead.setSett_org(orgCodeNc); + } else { + billhead.setPk_org("NG04"); + billhead.setSett_org("NG04"); + } + billhead.setCreationtime(dateString); + billhead.setPk_billtype("F2"); + billhead.setCreator(makerCodeNc); + billhead.setPk_tradetype("D2"); + billhead.setBillclass("sk"); + billhead.setBilldate(dateString); + billhead.setSyscode("0"); + billhead.setBillno(""); + billhead.setDef59(""); + billhead.setSrc_syscode("0"); + billhead.setBillstatus("0"); + billhead.setBillmaker(makerCodeNc); + billhead.setPk_busitype(""); + billhead.setBillyear(sdf1.format(date)); + billhead.setBillperiod(sdf2.format(date)); + billhead.setEffectstatus("0"); + billhead.setDef28("nqyw"); + billhead.setDef29(reconciliation.getBillNumber()); + billhead.setBodys(bodys); + SKbill bill=new SKbill(); + bill.setId("sk"+String.valueOf(reconciliation.getBillManageId())+"_"+1); + bill.setBillhead(billhead); + SKufinterface ufinterface=new SKufinterface(); + ufinterface.setAccount("NKNC"); + ufinterface.setBilltype("F2"); + ufinterface.setBusinessunitcode(""); + ufinterface.setFilename(""); + ufinterface.setIsexchange("Y"); + if (orgCodeNc != null && !orgCodeNc.isEmpty()) { + ufinterface.setOrgcode(orgCodeNc); + ufinterface.setReceiver(orgCodeNc); + } else { + ufinterface.setOrgcode("NG04"); + ufinterface.setReceiver("NG04"); + } + ufinterface.setReplace("Y"); + ufinterface.setRoottag(""); + ufinterface.setSender("nqyw"); + ufinterface.setBill(bill); + JAXBContext jaxbContext = null; + //String xmlString =""; + jaxbContext = JAXBContext.newInstance(SKufinterface.class); + Marshaller marshaller = jaxbContext.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // 格式化输出,可选 + StringWriter sw = new StringWriter(); + marshaller.marshal(ufinterface, sw); + String xmlString = sw.toString(); // 这是要发送的XML字符串 + System.out.println(xmlString); + NcLog ncLog=new NcLog(); + ncLog.setOrderId(reconciliation.getBillManageId()); + ncLog.setRequestBody(xmlString); + ncLog.setResponeBody(""); + ncLog.setType(1L); + ncLog.setSendTime(new Date()); + ncLog.setOrganizationId(reconciliation.getOrganizationId()); + ncLog.setOrganizationName(reconciliation.getOrganizationName()); + ncLog.setTopOrganizationId(reconciliation.getTopOrganizationId()); + ncLogMapper.insert(ncLog); + reconciliation.setSkSynchronousStatus(1); + reconciliation.setSkSynchronousTime(new Date()); + reconciliation.setSkNcId("sk"+String.valueOf(reconciliation.getBillManageId())); + //reconciliationMapper.updateById(reconciliation); + CloseableHttpClient httpClient = HttpClients.createDefault(); + HttpPost httpPost = new HttpPost(url); + StringEntity postingString = new StringEntity(xmlString, "UTF-8"); + httpPost.setEntity(postingString); + httpPost.setHeader("Content-type", "application/xml"); + try { + CloseableHttpResponse response = httpClient.execute(httpPost); + String responseString = EntityUtils.toString(response.getEntity()); + System.out.println(responseString); + ncLog.setResponeBody(responseString); + // 创建DOM解析器 + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(new InputSource(new StringReader(responseString))); + + // 获取根元素 + Element root = document.getDocumentElement(); + + // 获取ufinterface元素的属性 + String billtype = root.getAttribute("billtype"); + String filename = root.getAttribute("filename"); + System.out.println("billtype: " + billtype); + System.out.println("filename: " + filename); + + // 获取sendresult节点 + NodeList sendResultList = root.getElementsByTagName("sendresult"); + if (sendResultList.getLength() > 0) { + Element sendResult = (Element) sendResultList.item(0); + + // 获取子元素内容 + String bdocid = sendResult.getElementsByTagName("bdocid").item(0).getTextContent(); + String resultcode = sendResult.getElementsByTagName("resultcode").item(0).getTextContent(); + String content = sendResult.getElementsByTagName("content").item(0).getTextContent(); + + System.out.println("bdocid: " + bdocid); + System.out.println("resultcode: " + resultcode); + System.out.println("content: " + content); + if(resultcode.equals("1")){ + reconciliation.setSkSynchronousStatus(1); + }else{ + reconciliation.setSkSynchronousStatus(2); + } + } + ncLogMapper.updateById(ncLog); + billManageMapper.updateById(reconciliation); + response.close(); + } catch (Exception e) { + reconciliation.setSkSynchronousStatus(2); + billManageMapper.updateById(reconciliation); + e.printStackTrace(); + } finally { + try { + httpClient.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + } catch (JAXBException e) { reconciliation.setSkSynchronousStatus(2); billManageMapper.updateById(reconciliation); @@ -778,6 +1153,297 @@ public class BillManageImpl extends ServiceImpl im } return true; } + + //按发票推送版本 +// public boolean synchronousNcSK_TY(String businessDocumentDetaliId) { +// BillManage reconciliation=billManageMapper.selectById(businessDocumentDetaliId); +// if(reconciliation.getSkSynchronousStatus()==1){ +// throw new ServiceException("该记录已同步,不需要再次同步"); +// } +// try { +// Date date = reconciliation.getCreateTime(); +// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy"); +// SimpleDateFormat sdf2 = new SimpleDateFormat("MM"); +// String dateString = sdf.format(date); +// String invoiceId = reconciliation.getInvoiceId(); +// ReconciliationDTO makeQuery=new ReconciliationDTO(); +// makeQuery.setInnerNumber(invoiceId); +// List bmsMakeOutInvoices = bmsMakeOutInvoiceMapper.selectList(new LambdaQueryWrapper().eq(BmsMakeOutInvoice::getInvoiceId, invoiceId)); +// if (bmsMakeOutInvoices != null && bmsMakeOutInvoices.size() > 0) { +// int count= 0; +// for (BmsMakeOutInvoice make : bmsMakeOutInvoices) { +// count++; +// List ysitemList=new ArrayList(); +// ReconciliationDTO reconciliationDTO=new ReconciliationDTO(); +// reconciliationDTO.setInnerNumber(reconciliation.getBillNumber()); +// String url = ""; +// Long organizationId = reconciliation.getOrganizationId(); +// String orgCodeNc = billManageMapper.getOrgCodeNc(organizationId); +// String organizationName = reconciliation.getOrganizationName(); +// String ncUrl = billManageMapper.getNcUrl("nc", organizationName, organizationId); +// if (ncUrl!=null&&ncUrl!="") { +// url = ncUrl; +// } else { +// reconciliation.setSkSynchronousStatus(2); +// billManageMapper.updateById(reconciliation); +// throw new ServiceException("未找到该组织的推送地址!"); +// } +// List bmsMakeOutInvoiceItems = bmsMakeOutInvoiceItemMapper.selectList(new LambdaQueryWrapper().eq(BmsMakeOutInvoiceItem::getMakeId, make.getId())); +// String makerCodeNc = ""; +// if(bmsMakeOutInvoiceItems != null && bmsMakeOutInvoiceItems.size() > 0){ +// if(ObjectUtil.isNotNull(bmsMakeOutInvoiceItems)){ +// // 汇总 list 中 invoiceValue 的总值 +// BigDecimal totalInvoiceValue = bmsMakeOutInvoiceItems.stream() +// .map(BmsMakeOutInvoiceItem::getInvoiceValue) +// .filter(java.util.Objects::nonNull) +// .reduce(BigDecimal.ZERO, BigDecimal::add); +// +// // 将 feeType 用、拼接起来 +// String feeTypes = bmsMakeOutInvoiceItems.stream() +// .map(BmsMakeOutInvoiceItem::getFeeType) +// .filter(java.util.Objects::nonNull) +// .collect(java.util.stream.Collectors.joining("、")); +// +// // 按 createTime 倒序排序并获取第一条记录 +// BmsMakeOutInvoiceItem firstItem = bmsMakeOutInvoiceItems.stream() +// .sorted((a, b) -> { +// if (a.getCreateTime() == null) return 1; +// if (b.getCreateTime() == null) return -1; +// return b.getCreateTime().compareTo(a.getCreateTime()); +// }) +// .findFirst() +// .orElse(null); +// String salesmanId = reconciliation.getSalesmanId(); +// String customerUserDept = billManageMapper.getCustomerUserDept(salesmanId); +// String deptValue = billManageMapper.getDeptValue(customerUserDept); +// String deptName = billManageMapper.getDeptName(customerUserDept); +// String salespersonNcCode = billManageMapper.getsalespersonNcCode(salesmanId); +// String salesmanCodeNc=salespersonNcCode; +// String appointShipper=make.getActualInvoiceCustomerName(); +// String actualInvoiceCustomerId = make.getActualInvoiceCustomerId(); +// String customerCodeNc = billManageMapper.getCustomerCodeNc(actualInvoiceCustomerId); +// String customerCodeNcJson = billManageMapper.getCustomerCodeNcJson(actualInvoiceCustomerId); +// if (customerCodeNcJson != null && !customerCodeNcJson.isEmpty()) { +// ObjectMapper objectMapper = new ObjectMapper(); +// List> listNc = objectMapper.readValue( +// customerCodeNcJson, +// new TypeReference>>() {} +// ); +// if (listNc != null && listNc.size() > 0) { +// Map targetMap = listNc.stream() +// .filter(map -> { +// Object codeObj = map.get("code"); +// return codeObj != null && codeObj.toString().equals(reconciliation.getOrganizationId().toString()); +// }) +// .findFirst() +// .orElse(null); +// if (targetMap != null) { +// customerCodeNc = (String) targetMap.get("ncCustomer"); +// } +// } +// } +// String documentPreparerNcCode = billManageMapper.getDocumentPreparerNcCode(salesmanId); +// String settlementCurrency=reconciliation.getSettlementCurrency(); +// String settlementCurrencyNcCode = settlementCurrency; +// makerCodeNc=documentPreparerNcCode; +// SKitem item=new SKitem(); +// if (deptValue != null && !deptValue.isEmpty()) { +// item.setSo_deptid(deptValue); +// } else { +// item.setSo_deptid("NG0408"); +// } +// if (deptValue != null && !deptValue.isEmpty()) { +// item.setPk_deptid(deptValue); +// } else { +// item.setPk_deptid("NG0408"); +// } +// item.setCheckdirection("ar"); +// item.setPk_psndoc(salesmanCodeNc); +// item.setCustomer(customerCodeNc); +// item.setPurchaseorder(""); +// item.setObjtype("0"); +// item.setDirection("1"); +// if (deptName != null && !deptName.isEmpty()) { +// if (feeTypes != null && !feeTypes.isEmpty()) { +// item.setScomment(deptName+":"+appointShipper+feeTypes); +// } else { +// item.setScomment(deptName+":"+appointShipper+feeTypes); +// } +// } else { +// if (feeTypes != null && !feeTypes.isEmpty()) { +// item.setScomment("业务部:"+appointShipper+feeTypes); +// } else { +// item.setScomment("业务部:"+appointShipper+feeTypes); +// } +// } +// // 费用类别 +// String feeType = firstItem.getFeeType(); +// String serviceItemsCodeNc = billManageMapper.getServiceItemsCodeNc(feeType); +// if (serviceItemsCodeNc != null && !serviceItemsCodeNc.isEmpty()) { +// item.setDef75(serviceItemsCodeNc); +// } else { +// item.setDef75("T10"); +// } +// String invoiceItem1 = firstItem.getInvoiceItem(); +// if (invoiceItem1 != null && !invoiceItem1.isEmpty()) { +// String[] split = invoiceItem1.split(","); +// item.setDef29(split[0]); +// } +// item.setPk_currtype(settlementCurrencyNcCode); +// item.setMoney_cr(String.valueOf(totalInvoiceValue)); +// item.setMoney_bal(String.valueOf(totalInvoiceValue)); +// ysitemList.add(item); +// } +// } +// SKbodys bodys=new SKbodys(); +// bodys.setItem(ysitemList); +// SKbillhead billhead=new SKbillhead(); +// billhead.setPk_group("CNK"); +// if (orgCodeNc != null && !orgCodeNc.isEmpty()) { +// billhead.setPk_org(orgCodeNc); +// billhead.setSett_org(orgCodeNc); +// } else { +// billhead.setPk_org("NG04"); +// billhead.setSett_org("NG04"); +// } +// billhead.setCreationtime(dateString); +// billhead.setPk_billtype("F2"); +// billhead.setCreator(makerCodeNc); +// billhead.setPk_tradetype("D2"); +// billhead.setBillclass("sk"); +// billhead.setBilldate(dateString); +// billhead.setSyscode("0"); +// billhead.setBillno(""); +// billhead.setDef59(""); +// billhead.setSrc_syscode("0"); +// billhead.setBillstatus("0"); +// billhead.setBillmaker(makerCodeNc); +// billhead.setPk_busitype(""); +// billhead.setBillyear(sdf1.format(date)); +// billhead.setBillperiod(sdf2.format(date)); +// billhead.setEffectstatus("0"); +// billhead.setDef28("nqyw"); +// billhead.setDef29(reconciliation.getBillNumber()); +// billhead.setBodys(bodys); +// SKbill bill=new SKbill(); +// bill.setId("sk"+String.valueOf(reconciliation.getBillManageId())+"_"+count); +// bill.setBillhead(billhead); +// SKufinterface ufinterface=new SKufinterface(); +// ufinterface.setAccount("NKNC"); +// ufinterface.setBilltype("F2"); +// ufinterface.setBusinessunitcode(""); +// ufinterface.setFilename(""); +// ufinterface.setIsexchange("Y"); +// if (orgCodeNc != null && !orgCodeNc.isEmpty()) { +// ufinterface.setOrgcode(orgCodeNc); +// ufinterface.setReceiver(orgCodeNc); +// } else { +// ufinterface.setOrgcode("NG04"); +// ufinterface.setReceiver("NG04"); +// } +// ufinterface.setReplace("Y"); +// ufinterface.setRoottag(""); +// ufinterface.setSender("nqyw"); +// ufinterface.setBill(bill); +// JAXBContext jaxbContext = null; +// //String xmlString =""; +// jaxbContext = JAXBContext.newInstance(SKufinterface.class); +// Marshaller marshaller = jaxbContext.createMarshaller(); +// marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true); +// marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); // 格式化输出,可选 +// StringWriter sw = new StringWriter(); +// marshaller.marshal(ufinterface, sw); +// String xmlString = sw.toString(); // 这是要发送的XML字符串 +// System.out.println(xmlString); +// NcLog ncLog=new NcLog(); +// ncLog.setOrderId(reconciliation.getBillManageId()); +// ncLog.setRequestBody(xmlString); +// ncLog.setResponeBody(""); +// ncLog.setType(1L); +// ncLog.setSendTime(new Date()); +// ncLog.setOrganizationId(reconciliation.getOrganizationId()); +// ncLog.setOrganizationName(reconciliation.getOrganizationName()); +// ncLog.setTopOrganizationId(reconciliation.getTopOrganizationId()); +// ncLogMapper.insert(ncLog); +// reconciliation.setSkSynchronousStatus(1); +// reconciliation.setSkSynchronousTime(new Date()); +// reconciliation.setSkNcId("sk"+String.valueOf(reconciliation.getBillManageId())); +// //reconciliationMapper.updateById(reconciliation); +// CloseableHttpClient httpClient = HttpClients.createDefault(); +// HttpPost httpPost = new HttpPost(url); +// StringEntity postingString = new StringEntity(xmlString, "UTF-8"); +// httpPost.setEntity(postingString); +// httpPost.setHeader("Content-type", "application/xml"); +// try { +// CloseableHttpResponse response = httpClient.execute(httpPost); +// String responseString = EntityUtils.toString(response.getEntity()); +// System.out.println(responseString); +// ncLog.setResponeBody(responseString); +// // 创建DOM解析器 +// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); +// DocumentBuilder builder = factory.newDocumentBuilder(); +// Document document = builder.parse(new InputSource(new StringReader(responseString))); +// +// // 获取根元素 +// Element root = document.getDocumentElement(); +// +// // 获取ufinterface元素的属性 +// String billtype = root.getAttribute("billtype"); +// String filename = root.getAttribute("filename"); +// System.out.println("billtype: " + billtype); +// System.out.println("filename: " + filename); +// +// // 获取sendresult节点 +// NodeList sendResultList = root.getElementsByTagName("sendresult"); +// if (sendResultList.getLength() > 0) { +// Element sendResult = (Element) sendResultList.item(0); +// +// // 获取子元素内容 +// String bdocid = sendResult.getElementsByTagName("bdocid").item(0).getTextContent(); +// String resultcode = sendResult.getElementsByTagName("resultcode").item(0).getTextContent(); +// String content = sendResult.getElementsByTagName("content").item(0).getTextContent(); +// +// System.out.println("bdocid: " + bdocid); +// System.out.println("resultcode: " + resultcode); +// System.out.println("content: " + content); +// if(resultcode.equals("1")){ +// reconciliation.setSkSynchronousStatus(1); +// }else{ +// reconciliation.setSkSynchronousStatus(2); +// } +// } +// ncLogMapper.updateById(ncLog); +// billManageMapper.updateById(reconciliation); +// response.close(); +// } catch (Exception e) { +// reconciliation.setSkSynchronousStatus(2); +// billManageMapper.updateById(reconciliation); +// e.printStackTrace(); +// } finally { +// try { +// httpClient.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// +// } +// } else { +// reconciliation.setSkSynchronousStatus(2); +// billManageMapper.updateById(reconciliation); +// } +// } catch (JAXBException e) { +// reconciliation.setSkSynchronousStatus(2); +// billManageMapper.updateById(reconciliation); +// e.printStackTrace(); +// } catch (JsonMappingException e) { +// throw new RuntimeException(e); +// } catch (JsonProcessingException e) { +// throw new RuntimeException(e); +// } +// return true; +// } @Override diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/todo/BillManageDO.java b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/todo/BillManageDO.java index 399ad44c4..cfb053614 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/todo/BillManageDO.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/billManage/repository/todo/BillManageDO.java @@ -264,4 +264,6 @@ public class BillManageDO extends BaseVOEntity{ private String paymentAccountId; @ApiModelProperty("收款帐户名称") private String paymentAccountName; + @ApiModelProperty("业务员ID") + private String salesmanId; } \ No newline at end of file diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/billingStatement/repository/po/BillingStatementPO.java b/mhd_bms/src/main/java/com/mhd/bms/domain/billingStatement/repository/po/BillingStatementPO.java index 447b38446..6a5d308c7 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/billingStatement/repository/po/BillingStatementPO.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/billingStatement/repository/po/BillingStatementPO.java @@ -100,6 +100,10 @@ public class BillingStatementPO extends BaseVOEntity{ @Excel(name = "收支类型", readConverterExp = "1=-应收,2-应付") private Integer accountExpenseType; + @ApiModelProperty("收支类型(1-应收,2-应付)") + @Excel(name = "收支类型", readConverterExp = "1=-应收,2-应付") + private Integer billType; + @ApiModelProperty("流水备注") @Excel(name = "流水备注") private String billingRemark; diff --git a/mhd_bms/src/main/java/com/mhd/bms/domain/billingStatement/repository/todo/BillingStatementDO.java b/mhd_bms/src/main/java/com/mhd/bms/domain/billingStatement/repository/todo/BillingStatementDO.java index af1576753..23fc1d687 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/domain/billingStatement/repository/todo/BillingStatementDO.java +++ b/mhd_bms/src/main/java/com/mhd/bms/domain/billingStatement/repository/todo/BillingStatementDO.java @@ -101,6 +101,10 @@ public class BillingStatementDO extends BaseVOEntity{ @Excel(name = "收支类型", readConverterExp = "1=-应收,2-应付") private Integer accountExpenseType; + @ApiModelProperty("收支类型(1-应收,2-应付)") + @Excel(name = "收支类型", readConverterExp = "1=-应收,2-应付") + private Integer billType; + @ApiModelProperty("流水备注") @Excel(name = "流水备注") private String billingRemark; diff --git a/mhd_bms/src/main/java/com/mhd/bms/interfaces/dto/billingStatement/BillingStatementDTO.java b/mhd_bms/src/main/java/com/mhd/bms/interfaces/dto/billingStatement/BillingStatementDTO.java index 48e195c69..855e5040b 100644 --- a/mhd_bms/src/main/java/com/mhd/bms/interfaces/dto/billingStatement/BillingStatementDTO.java +++ b/mhd_bms/src/main/java/com/mhd/bms/interfaces/dto/billingStatement/BillingStatementDTO.java @@ -102,6 +102,10 @@ public class BillingStatementDTO extends BaseVOEntity{ @Excel(name = "收支类型", readConverterExp = "1=-应收,2-应付") private Integer accountExpenseType; + @ApiModelProperty("收支类型(1-应收,2-应付)") + @Excel(name = "收支类型", readConverterExp = "1=-应收,2-应付") + private Integer billType; + @ApiModelProperty("流水备注") @Excel(name = "流水备注") private String billingRemark; diff --git a/mhd_bms/src/main/resources/bootstrap.yml b/mhd_bms/src/main/resources/bootstrap.yml index d68deb6eb..5532be09f 100644 --- a/mhd_bms/src/main/resources/bootstrap.yml +++ b/mhd_bms/src/main/resources/bootstrap.yml @@ -18,15 +18,15 @@ spring: discovery: # server-addr: 127.0.0.1:8848 # 线上测试环境配置 容器名+端口号 -# server-addr: 10.33.0.129:6010 - server-addr: 10.102.192.30:6848 + server-addr: 10.33.0.129:6010 +# server-addr: 10.102.192.31:6848 username: nacos password: manhuoda@2023 config: # server-addr: 127.0.0.1:8848 # 线上测试环境配置 容器名+端口号 -# server-addr: 10.33.0.129:6010 - server-addr: 10.102.192.30:6848 + server-addr: 10.33.0.129:6010 +# server-addr: 10.102.192.31:6848 username: nacos password: manhuoda@2023 group: DEFAULT_GROUP # 默认分组就是DEFAULT_GROUP,如果使用默认分组可以不配置 diff --git a/mhd_bms/src/main/resources/mapper/BillDetailMapper.xml b/mhd_bms/src/main/resources/mapper/BillDetailMapper.xml index e56269307..0fc27b019 100644 --- a/mhd_bms/src/main/resources/mapper/BillDetailMapper.xml +++ b/mhd_bms/src/main/resources/mapper/BillDetailMapper.xml @@ -27,5 +27,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND bd.bill_manage_id = #{billManageId} + - + + + + \ No newline at end of file diff --git a/mhd_bms/src/main/resources/mapper/BillManageMapper.xml b/mhd_bms/src/main/resources/mapper/BillManageMapper.xml index 6be84c7ad..398e298ce 100644 --- a/mhd_bms/src/main/resources/mapper/BillManageMapper.xml +++ b/mhd_bms/src/main/resources/mapper/BillManageMapper.xml @@ -162,4 +162,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" SELECT NC_CODE FROM NGWL_TEST_PRODUCT."SYS_ORGANIZATION" where DEL_FLAG = 1 and organization_id = #{organizationId} limit 1 + + \ No newline at end of file diff --git a/mhd_bms/src/main/resources/mapper/SettlementCustomersMapper.xml b/mhd_bms/src/main/resources/mapper/SettlementCustomersMapper.xml index 54d6b7a3a..e2fd28e11 100644 --- a/mhd_bms/src/main/resources/mapper/SettlementCustomersMapper.xml +++ b/mhd_bms/src/main/resources/mapper/SettlementCustomersMapper.xml @@ -200,10 +200,6 @@ AND ( a.organization_id = #{settlementCustomersDO.organizationId} - OR b.org_code LIKE concat('%"code":"', #{settlementCustomersDO.organizationId}, '"%') - OR b.org_code LIKE concat('%code:', #{settlementCustomersDO.organizationId}, '%') - OR b.org_code LIKE concat('%code: ', #{settlementCustomersDO.organizationId}, '%') - OR b.org_code LIKE concat('%"code":', #{settlementCustomersDO.organizationId}, '%') ) @@ -216,4 +212,4 @@ and a.customer_type_code = #{settlementCustomersDO.customerTypeCode} - + \ No newline at end of file diff --git a/mhd_wms/src/main/resources/bootstrap.yml b/mhd_wms/src/main/resources/bootstrap.yml index 39eb710cb..e8f169bf2 100644 --- a/mhd_wms/src/main/resources/bootstrap.yml +++ b/mhd_wms/src/main/resources/bootstrap.yml @@ -14,18 +14,18 @@ spring: nacos: discovery: # server-addr: 127.0.0.1:8848 - server-addr: 10.33.0.129:6010 +# server-addr: 10.33.0.129:6010 # 线上测试环境配置 容器名+端口号 -# server-addr: 10.102.192.30:6848 + server-addr: 10.102.192.31:6848 username: nacos password: manhuoda@2023 #线上正式环境 # server-addr: 10.102.192.105:6848 config: # server-addr: 127.0.0.1:8848 - server-addr: 10.33.0.129:6010 +# server-addr: 10.33.0.129:6010 # 线上测试环境配置 容器名+端口号 -# server-addr: 10.102.192.30:6848 + server-addr: 10.102.192.31:6848 username: nacos password: manhuoda@2023 #线上正式环境 diff --git a/mhd_wms/src/main/resources/mapper/reviewOrder/ReviewOrderMapper.xml b/mhd_wms/src/main/resources/mapper/reviewOrder/ReviewOrderMapper.xml index 86a8a0466..d03ce31fc 100644 --- a/mhd_wms/src/main/resources/mapper/reviewOrder/ReviewOrderMapper.xml +++ b/mhd_wms/src/main/resources/mapper/reviewOrder/ReviewOrderMapper.xml @@ -4,7 +4,7 @@ - + @@ -84,7 +84,7 @@ - a.review_order_id, + a.review_order_id AS review_order_id, a.review_order_number, a.out_order_id, a.out_order_number,