platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/dto/ContractInvoiceQueryDTO.java
@@ -13,4 +13,6 @@ * 1/蓝 2/红 */ private String invoiceCategory; private String bwRequestResult; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/dto/ContractInvoiceUpateDTO.java
New file @@ -0,0 +1,12 @@ package com.by4cloud.platformx.business.dto; import lombok.Data; @Data public class ContractInvoiceUpateDTO { private String invoicePreview; private Long id; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/dto/ContractSubjectChangeDTO.java
New file @@ -0,0 +1,22 @@ package com.by4cloud.platformx.business.dto; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.persistence.Column; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; import java.math.BigDecimal; import java.util.Date; import java.util.List; @Data public class ContractSubjectChangeDTO { private String id; private List<ContractSubjectMatterAddDTO> contractSubjectMatter; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/dto/GenInvoiceInfoDTO.java
@@ -1,5 +1,6 @@ package com.by4cloud.platformx.business.dto; import com.by4cloud.platformx.business.vo.ContractInvoiceBipVo; import com.by4cloud.platformx.business.vo.ContractOutBoundInvoiceVo; import lombok.Data; @@ -18,7 +19,15 @@ private String vehicleNo; private String origin; private String tonnage; private String passengersLimited; private String certificateNo; private String vehicleData; private String remarks; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/dto/TaxCodeQueryDTO.java
@@ -7,6 +7,8 @@ private String mc; private String jc; private String bm; private Integer childNum; platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/dto/ToInvoiceDTO.java
New file @@ -0,0 +1,79 @@ package com.by4cloud.platformx.business.dto; import com.by4cloud.platformx.business.vo.ContractInvoiceBipVo; import com.by4cloud.platformx.business.vo.ContractOutBoundInvoiceVo; import com.by4cloud.platformx.business.vo.InvoiceItemVo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.math.BigDecimal; import java.util.List; @Data public class ToInvoiceDTO { @Schema(description = "合同id") private Long contractId; @Schema(description = "合同类型") private String contractCategory; @Schema(description = "预开发票") private String advanceInvoice; @Schema(description = "车架号") private String vehicleNo; @Schema(description = "车辆合格证号") private String certificateNo; @Schema(description = "交税分类") private String invoiceType; @Schema(description = "机动车交税分类") private String invoiceVehicleType; @Schema(description = "甲方名称") private String partyA; @Schema(description = "甲方税号") private String partyAOrgCode; @Schema(description = "乙方名称") private String partyB; @Schema(description = "乙方税号") private String partyBOrgCode; @Schema(description = "甲方开户行") private String partyAOpenBank; @Schema(description = "甲方银行账号") private String partyABankAccount; @Schema(description = "乙方开户行") private String partyBOpenBank; @Schema(description = "乙方银行账号") private String partyBBankAccount; @Schema(description = "开票金额(含税)") private BigDecimal totalPrice; @Schema(description = "税额") private BigDecimal totalTax; @Schema(description = "大写开票金额") private String priceWords; private String vehicleData; private String remarks; private ContractInvoiceBipVo bipVo; private List<ContractOutBoundInvoiceVo> outBoundInvoiceList; private List<InvoiceItemVo> invoiceItemList; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/entity/BankStatement.java
@@ -80,4 +80,8 @@ @Column(columnDefinition="VARCHAR(255) comment '交易说明'") private String remark; @Schema(description = "借贷标识") @Column(columnDefinition="char comment '借贷标识:1借;2贷'") private String dcFlag; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/entity/BankStatementItem.java
@@ -38,4 +38,7 @@ @Column(columnDefinition = "decimal(10,2) comment '合同确认金额'") private BigDecimal confirmAmount; @Schema(description = "推送标识") @Column(columnDefinition="char default '0' comment '推送标识 0/未推 1/已推'") private String pushFlag; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/entity/BipDict.java
New file @@ -0,0 +1,36 @@ package com.by4cloud.platformx.business.entity; import com.by4cloud.platformx.common.data.mybatis.BaseModel; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.persistence.Column; import jakarta.persistence.Entity; import lombok.Data; import org.hibernate.annotations.Table; /** * 2026年8月7日 16:04:22 * syt */ @Data @Entity//加了才能自动生成表 @Table(appliesTo="bip_dict",comment = "bip字典")//给表加注释 @jakarta.persistence.Table(name = "bip_dict")//数据库创建的表明 public class BipDict extends BaseModel<BipDict> { @Schema(description = "字典KEY") @Column(columnDefinition="VARCHAR(128) comment '字典KEY'") private String dictKey; @Schema(description = "编码") @Column(columnDefinition="VARCHAR(128) comment '编码'") private String dictCode; @Schema(description = "名称") @Column(columnDefinition="VARCHAR(128) comment '名称'") private String dictName; @Schema(description = "上级ID") @Column(columnDefinition="bigint comment '上级ID'") private Long parentId; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/entity/ContractSubjectMatterChange.java
New file @@ -0,0 +1,47 @@ package com.by4cloud.platformx.business.entity; import com.by4cloud.platformx.common.data.mybatis.BaseModel; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Table; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; import org.springframework.format.annotation.DateTimeFormat; import java.math.BigDecimal; import java.util.Date; /** * 2026年9月4日 15:21:14 * syt */ @Data @Entity//加了才能自动生成表 @org.hibernate.annotations.Table(appliesTo="contract_subject_matter_change",comment = "合同标的物变更")//给表加注释 @jakarta.persistence.Table(name = "contract_subject_matter_change")//数据库创建的表明 public class ContractSubjectMatterChange extends BaseModel<ContractSubjectMatterChange> { @Schema(description = "关联合同ID") @Column(columnDefinition = "bigint comment '关联合同ID'") private Long contractId; @Schema(description = "变更前") @Column(columnDefinition = "text comment '变更前'") private String beforeChange; @Schema(description = "变更后") @Column(columnDefinition = "text comment '变更后'") private String afterChange; @Schema(description = "变更单地址") @Column(columnDefinition = "varchar(255) comment '变更单地址'") private String attachmentUrl; @Schema(description = "变更单名称") @Column(columnDefinition = "varchar(255) comment '变更单名称'") private String attachmentName; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/entity/ErpRequestRecord.java
@@ -18,9 +18,13 @@ public class ErpRequestRecord extends BaseModel<ErpRequestRecord> { @Schema(description = "erp公司") @Column(columnDefinition="VARCHAR(128) comment '接口名称'") @Column(columnDefinition="VARCHAR(128) comment 'erp公司'") private String erpName; @Schema(description = "接口名称") @Column(columnDefinition="VARCHAR(128) comment '接口名称'") private String mothedName; @Schema(description = "入参") @Column(columnDefinition="text comment '入参'") private String requestParams; platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/ContractDetailVo.java
@@ -251,6 +251,8 @@ private BigDecimal paidAmount; private ContractInvoiceBipVo bipVo; private List<ContractPaymentSchedule> contractPaymentSchedule; private List<ContractSubjectMatter> contractSubjectMatter; platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/ContractInvoiceBipVo.java
New file @@ -0,0 +1,39 @@ package com.by4cloud.platformx.business.vo; import lombok.Data; import java.util.List; @Data public class ContractInvoiceBipVo { private String djrq; private String kpzz; private String ywzz; private String bm; private String ywy; private String djfx; private String jylx; private String wldxlx; private String kh; private String bz; private String fjzs; private String pzzdr; private String sfzy; private String hsdy; private String sfnbwl; private String sfjyjs; private String zy; private List<InvoiceItemVo> itemList; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/ContractPageVo.java
@@ -187,4 +187,8 @@ private Long warrantyScheduleId; private String centerPushFlag; private String beforeChange; private String afterChange; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/CustInfoVo.java
@@ -14,6 +14,10 @@ private String legalPerson; private String registrationAddress; private String country; private String custclass; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/GenInvoiceInfoVo.java
@@ -9,11 +9,20 @@ @Data public class GenInvoiceInfoVo { @Schema(description = "合同id") private Long contractId; @Schema(description = "合同类型") private String contractCategory; @Schema(description = "预开发票") private String advanceInvoice; private String origin; private String tonnage; private String passengersLimited; @Schema(description = "车架号") private String vehicleNo; @@ -62,5 +71,11 @@ private String vehicleData; private String remarks; private List<ContractOutBoundInvoiceVo> outBoundInvoiceList; private ContractInvoiceBipVo bipVo; private List<InvoiceItemVo> invoiceItemList; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/HomeInvoiceVo.java
@@ -24,4 +24,10 @@ private Date invoiceTime; private BigDecimal invoiceTotalPriceTax; private String invoicePath; private String bwRequestResult; private String invoicePreview; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/InvoiceItemVo.java
@@ -38,4 +38,20 @@ @Schema(description = "税收分类编码") private String taxCode; private String jjsx; private String sfjs; private String hsjylx; private String kxmx; private String cpwlfl; private String hsdy; private String zyys; private String bkfl; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/OrgInfoVo.java
New file @@ -0,0 +1,13 @@ package com.by4cloud.platformx.business.vo; import lombok.Data; @Data public class OrgInfoVo { private String orgCode; private String orgName; private String orgLevel; } platformx-business-finance-api/src/main/java/com/by4cloud/platformx/business/vo/StatementContractVo.java
@@ -27,4 +27,6 @@ private String partyA; private BigDecimal amount; private String pushFlag; } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/BankStatementController.java
@@ -176,4 +176,15 @@ return bankStatementService.backAll(id); } /** * 通过id推送bip * @param itemId id * @return R */ @Operation(summary = "通过id删除银行流水历史确认" , description = "通过id删除银行流水历史确认" ) @GetMapping("/pushBip/{itemId}" ) public R pushBip(@PathVariable("itemId" ) Long itemId) { return bankStatementService.pushBip(itemId); } } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/ContractController.java
@@ -370,4 +370,29 @@ } return contractService.importContractMultiSheet(file); } /** * 合同标的物变更 * @param changeDTO 合同管理 * @return R */ @Operation(summary = "合同标的物变更" , description = "合同标的物变更" ) @SysLog("合同标的物变更" ) @PostMapping("/subjectChange") @PreAuthorize("@pms.hasPermission('business_contract_subchange')" ) public R subjectChange(@RequestBody ContractSubjectChangeDTO changeDTO) { return contractService.subjectChange(changeDTO); } /** * 合同标的物变更分页 * @param changeDTO 合同管理 * @return R */ @Operation(summary = "合同标的物变更分页" , description = "合同标的物变更分页" ) @SysLog("合同标的物变更分页" ) @GetMapping("/subjectChangePage") public R subjectChangePage(@ParameterObject Page page, @ParameterObject ContracQueryDTO queryDTO) { return R.ok(contractService.subjectChangePage(page,queryDTO)); } } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/ContractInvoiceController.java
@@ -4,10 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.by4cloud.platformx.business.dto.ContractInvoiceQueryDTO; import com.by4cloud.platformx.business.dto.ContractQueryDTO; import com.by4cloud.platformx.business.dto.GenInvoiceInfoDTO; import com.by4cloud.platformx.business.dto.InvoiceQueryDTO; import com.by4cloud.platformx.business.dto.*; import com.by4cloud.platformx.business.entity.Contract; import com.by4cloud.platformx.business.entity.ContractInvoice; import com.by4cloud.platformx.business.entity.ContractOutBound; @@ -123,8 +120,8 @@ * @return */ @PostMapping("/toInvoice" ) public R toInvoice(@RequestBody GenInvoiceInfoDTO genInvoiceInfoDTO) { return contractInvoiceService.toInvoice(genInvoiceInfoDTO); public R toInvoice(@RequestBody ToInvoiceDTO toInvoiceDTO) { return contractInvoiceService.toInvoice(toInvoiceDTO); } /** @@ -174,6 +171,24 @@ } /** * 手动推送bip * @return */ @GetMapping("/bipPushPdf/{invoiceId}") public R bipPushPdf(@PathVariable("invoiceId")Long invoiceId) { return contractInvoiceService.bipPushPdf(invoiceId); } /** * 保存并推送 * @return */ @PostMapping("/saveAndPush") public R saveAndPush(@RequestBody ContractInvoiceUpateDTO upateDTO) { return contractInvoiceService.saveAndPush(upateDTO); } /** * 红票查询 * @return */ @@ -192,4 +207,25 @@ public R queryInvoice(@ParameterObject Page page, @ParameterObject InvoiceQueryDTO queryDTO) { return contractInvoiceService.queryInvoice(page, queryDTO); } /** * 通过id查询 * @return R */ @Operation(summary = "通过id查询" , description = "通过id查询" ) @GetMapping("/{id}" ) public R getById(@PathVariable("id" ) Long id) { return R.ok(contractInvoiceService.getById(id)); } /** * 通过key查询bip字典 * @return R */ @Operation(summary = "通过key查询bip字典" , description = "通过key查询bip字典" ) @GetMapping("/selectBipByKey/{dictKey}" ) public R selectBipByKey(@PathVariable("dictKey" ) String dictKey) { return contractInvoiceService.selectBipByKey(dictKey); } } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/mapper/BipDictMapper.java
New file @@ -0,0 +1,11 @@ package com.by4cloud.platformx.business.mapper; import com.by4cloud.platformx.common.data.datascope.PlatformxBaseMapper; import com.by4cloud.platformx.business.entity.BipDict; import org.apache.ibatis.annotations.Mapper; @Mapper public interface BipDictMapper extends PlatformxBaseMapper<BipDict> { } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/mapper/BipViewMapper.java
@@ -3,6 +3,7 @@ import com.baomidou.dynamic.datasource.annotation.DS; import com.by4cloud.platformx.business.vo.CustBankVo; import com.by4cloud.platformx.business.vo.CustInfoVo; import com.by4cloud.platformx.business.vo.OrgInfoVo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Select; @@ -12,9 +13,12 @@ @DS("druid_bip_view") public interface BipViewMapper { @Select("select certificate_id, cust_name,legal_person,registration_address,cust_code from mdm_send.mdm_cust_base_info_tra_send WHERE is_deleted = '0' and cust_name = #{companyName}") @Select("select certificate_id, cust_name,legal_person,registration_address,cust_code,country,custclass from mdm_send.mdm_cust_base_info_tra_send WHERE is_deleted = '0' and cust_name = #{companyName}") CustInfoVo selectBaseInfoByCustName(String companyName); @Select("SELECT mcbats.bank_account,mcbats.bank_name FROM mdm_send.mdm_cust_bank_account_tra_send AS mcbats WHERE is_deleted = '0' and holder_name = #{companyName}") List<CustBankVo> selectBankByCustName(String companyName); @Select("select org_code,org_name,org_level from mdm_send.mdp_organize_tra_send WHERE is_deleted = '0' and org_name = #{companyName} ") List<OrgInfoVo> selectOrgByName(String partyA); } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/mapper/ContractSubjectMatterChangeMapper.java
New file @@ -0,0 +1,17 @@ package com.by4cloud.platformx.business.mapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.by4cloud.platformx.business.dto.ContracQueryDTO; import com.by4cloud.platformx.business.entity.ContractSubjectMatterChange; import com.by4cloud.platformx.business.vo.ContractPageVo; import com.by4cloud.platformx.common.data.datascope.DataScope; import com.by4cloud.platformx.common.data.datascope.PlatformxBaseMapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @Mapper public interface ContractSubjectMatterChangeMapper extends PlatformxBaseMapper<ContractSubjectMatterChange> { Page<ContractPageVo> subjectChangePage(Page page, @Param("queryDTO") ContracQueryDTO queryDTO, DataScope comp_id); } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/BankStatementService.java
@@ -18,4 +18,6 @@ R backAll(Long id); R backHis(Long id); R pushBip(Long itemId); } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/ContractInvoiceService.java
@@ -1,10 +1,7 @@ package com.by4cloud.platformx.business.service; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.by4cloud.platformx.business.dto.ContractInvoiceQueryDTO; import com.by4cloud.platformx.business.dto.ContractQueryDTO; import com.by4cloud.platformx.business.dto.GenInvoiceInfoDTO; import com.by4cloud.platformx.business.dto.InvoiceQueryDTO; import com.by4cloud.platformx.business.dto.*; import com.by4cloud.platformx.business.entity.ContractInvoice; import com.by4cloud.platformx.common.core.util.R; @@ -15,7 +12,7 @@ R genInvoiceInfo(GenInvoiceInfoDTO genInvoiceInfoDTO); R toInvoice(GenInvoiceInfoDTO genInvoiceInfoDTO); R toInvoice(ToInvoiceDTO toInvoiceDTO); R getContractInvoiceList(Long contractId); @@ -42,4 +39,12 @@ R queryInvoice(Page page, InvoiceQueryDTO queryDTO); R add(ContractInvoice contractInvoice); ContractInvoice getById(Long id); R bipPushPdf(Long invoiceId); R selectBipByKey(String dictKey); R saveAndPush(ContractInvoiceUpateDTO upateDTO); } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/ContractPaymentScheduleProcessService.java
@@ -3,9 +3,12 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.by4cloud.platformx.business.dto.ContractPaymentScheduleProcessAddDTO; import com.by4cloud.platformx.business.entity.Contract; import com.by4cloud.platformx.business.entity.ContractPaymentSchedule; import com.by4cloud.platformx.business.entity.ContractPaymentScheduleProcess; import com.by4cloud.platformx.business.entity.PaymentConfirm; import com.by4cloud.platformx.common.core.util.R; import java.util.Date; public interface ContractPaymentScheduleProcessService extends IService<ContractPaymentScheduleProcess> { @@ -14,4 +17,6 @@ R selectScheduleProcess(Long id); void handleBeforeRemain(PaymentConfirm currentConfim, Contract contract); void saveScheduleProcess(Date date, ContractPaymentSchedule schedule); } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/ContractService.java
@@ -71,4 +71,8 @@ R pushCenter(Long id); R importContractMultiSheet(MultipartFile file); R subjectChange(ContractSubjectChangeDTO changeDTO); Page subjectChangePage(Page page, ContracQueryDTO queryDTO); } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/BankStatementServiceImpl.java
@@ -6,7 +6,6 @@ import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -16,12 +15,10 @@ import com.by4cloud.platformx.business.dto.BankStatementUpdateDTO; import com.by4cloud.platformx.business.dto.PaymentConfirmAddDTO; import com.by4cloud.platformx.business.entity.*; import com.by4cloud.platformx.business.mapper.BankStatementItemMapper; import com.by4cloud.platformx.business.mapper.BankStatementMapper; import com.by4cloud.platformx.business.mapper.BusinessCustomerMapper; import com.by4cloud.platformx.business.mapper.ContractMapper; import com.by4cloud.platformx.business.mapper.*; import com.by4cloud.platformx.business.service.BankStatementService; import com.by4cloud.platformx.business.service.PaymentConfirmService; import com.by4cloud.platformx.business.vo.CustInfoVo; import com.by4cloud.platformx.business.vo.StatementContractVo; import com.by4cloud.platformx.common.core.util.R; import com.by4cloud.platformx.common.security.util.SecurityUtils; @@ -33,6 +30,7 @@ import org.springframework.stereotype.Service; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -53,12 +51,20 @@ private final StringRedisTemplate redisTemplate; private final RemoteDeptService remoteDeptService; private final BankStatementItemMapper bankStatementItemMapper; private final ErpRequestRecordMapper erpRequestRecordMapper; private final BipViewMapper bipViewMapper; @Value("${bip.url}") private String url; @Value("${bip.flag}") private Boolean bipFlag; @Value("${dept.sgb}") private String sgb; @Value("${erp.sgb}") private String sgbErp; @Override public R edit(BankStatementUpdateDTO updateDTO) { @@ -68,16 +74,8 @@ } BigDecimal toPaidTotal = updateDTO.getContractCollectionList().stream() .map(StatementContractDTO::getToPaidAmount) .reduce(BigDecimal.ZERO, BigDecimal::add); if (toPaidTotal.compareTo(statement.getTranAmount().subtract(statement.getConfirmAmount()))>0){ return R.failed("确认收款总额不能超过交易流水金额"); } //bip推送 if (bipFlag) { R r = pushSaveCollection(statement, updateDTO.getContractCollectionList()); if (!r.isOk()){ return r; } if (toPaidTotal.compareTo(statement.getTranAmount().subtract(statement.getConfirmAmount()))!=0){ return R.failed("确认收款总额必须与交易流水金额一致"); } statement.setConfirmAmount(statement.getConfirmAmount().add(toPaidTotal)); @@ -96,13 +94,86 @@ addDTO.setBusGuestId(statement.getBusGuestId()+""); addDTO.setConfirmTime(statement.getTranDate()); addDTO.setContractNo(contract.getContractNo()); addDTO.setInOrOut("1"); addDTO.setInOrOut(statement.getDcFlag()); addDTO.setTransationAmount(statementContractDTO.getToPaidAmount()); addDTO.setBankSeqNo(statement.getBankSeqNo()); paymentConfirmService.add(addDTO); //石工泵主动推送系统 if ((StrUtil.equals(SecurityUtils.getUser().getCompId() + "", sgb)) && StrUtil.isNotEmpty(sgbErp)) { BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); if (ObjUtil.isNotNull(customer)) { pushCollection(statement, contract,customer,item); } } }); //判断是否内部单位 CustInfoVo custInfoVo = bipViewMapper.selectBaseInfoByCustName(statement.getPayBankAccName()); if (ObjUtil.isNull(custInfoVo)){ return R.ok(); } //bip推送 if (bipFlag&&custInfoVo.getCustCode().equals("01")) { return pushSaveCollection(statement, updateDTO.getContractCollectionList()); } log.info("内部往来收款单,客户名称:{},客户类型:{},不用保存收款单",custInfoVo.getCustName(),custInfoVo.getCustclass()); return R.ok(); } private void pushCollection(BankStatement statement,Contract contract,BusinessCustomer customer,BankStatementItem item) { new Thread(() -> { JSONObject request = genErpParam(statement,contract,customer,item); String resp = ""; String reqPath = ""; log.info("工业泵收款/退款:{},入参:{}",statement.getDcFlag(),request.toJSONString()); if (statement.getDcFlag().equals("1")){ reqPath = sgbErp + "/arpclose/create"; } if (statement.getDcFlag().equals("2")){ reqPath = sgbErp+"/arpclose/create"; } resp = HttpUtil.post(reqPath,request.toJSONString()); saveErpRequestRecord("sgb",reqPath,request.toJSONString(),resp); log.info("工业泵收款/退款回参:{}",resp); try { } catch (Exception e) { e.printStackTrace(); } }).start(); } private void saveErpRequestRecord(String ymj,String medthodName, String toJSONString, String result) { ErpRequestRecord record = new ErpRequestRecord(); record.setErpName(ymj); record.setMothedName(medthodName); record.setRequestParams(toJSONString); record.setResponseParams(result); erpRequestRecordMapper.insert(record); } private JSONObject genErpParam(BankStatement statement, Contract contract,BusinessCustomer customer,BankStatementItem item) { JSONObject req = new JSONObject(); JSONObject djt = new JSONObject(); djt.put("iAmt",item.getConfirmAmount()); djt.put("iAmt_f",item.getConfirmAmount()); djt.put("cCusVen",customer.getErpCompanyCode()); djt.put("cexch_name","人民币"); djt.put("iAmount",item.getConfirmAmount()); req.put("单据头",djt); JSONArray array = new JSONArray(); JSONObject djti = new JSONObject(); djti.put("cVouchID",statement.getBankSeqNo()); djti.put("dVouchDate",DateUtil.formatDate(statement.getTranDate())); djti.put("cDwCode",customer.getErpCompanyCode()); djti.put("cexch_name","人民币"); djti.put("iAmount",item.getConfirmAmount()); array.add(djti); req.put("单据头",array); return req; } private R pushSaveCollection(BankStatement statement, List<StatementContractDTO> contractDTOList) { @@ -118,11 +189,6 @@ } String finalAccessToken = accessToken; BusinessCustomer customer = businessCustomerMapper.selectById(statement.getBusGuestId()); if (ObjUtil.isNull(customer)||StrUtil.isEmpty(customer.getBipCode())){ log.error("查询客户信息异常"); return R.failed("查询客户信息异常"); } R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId()); log.info("查询单位信息:{}",JSONObject.toJSONString(r.getData())); if (!r.isOk()){ @@ -130,7 +196,7 @@ return R.failed("查询单位信息异常"); } SysDept dept = r.getData(); JSONObject params = genRequestParam(statement,dept,customer,contractDTOList); JSONObject params = genRequestParam(statement,dept,contractDTOList); log.info("收款单集成 Request:{}", params.toJSONString()); String result = HttpUtil.post(url + "/yonbip/EFI/collection/saveandsubmit?access_token=" + finalAccessToken, params.toJSONString()); @@ -143,7 +209,9 @@ return R.ok(); } private JSONObject genRequestParam(BankStatement statement,SysDept dept,BusinessCustomer customer,List<StatementContractDTO> contractDTOList) { private JSONObject genRequestParam(BankStatement statement,SysDept dept,List<StatementContractDTO> contractDTOList) { Contract contract1 = contractMapper.selectById(contractDTOList.get(0).getId()); BusinessCustomer customer = businessCustomerMapper.selectById(contract1.getPartyAId()); JSONObject jsonObject = new JSONObject(); JSONObject data = new JSONObject(); data.put("billDate",DateUtil.format(statement.getTranDate(), DatePattern.NORM_DATETIME_FORMAT)); @@ -182,6 +250,7 @@ .select(Contract::getAmount) .leftJoin(Contract.class,Contract::getId,BankStatementItem::getContractId) .eq(BankStatementItem::getCompId,SecurityUtils.getUser().getCompId()) .eq(BankStatementItem::getStatetId,id) .orderByDesc(BankStatementItem::getCreateTime); return R.ok(bankStatementItemMapper.selectJoinList(StatementContractVo.class, wrapper)); } @@ -468,4 +537,22 @@ jsonObject.put("data",data); return jsonObject; } @Override public R pushBip(Long itemId) { BankStatementItem item = bankStatementItemMapper.selectById(itemId); BankStatement statement = baseMapper.selectById(item.getStatetId()); List<StatementContractDTO> statementContractDTOList = new ArrayList<>(); StatementContractDTO contractDTO = new StatementContractDTO(); contractDTO.setId(item.getContractId()); contractDTO.setToPaidAmount(item.getConfirmAmount()); statementContractDTOList.add(contractDTO); R r = pushSaveCollection(statement,statementContractDTOList); if (r.isOk()){ item.setPushFlag("1"); bankStatementItemMapper.updateById(item); return r; } return r; } } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractInvoiceServiceImpl.java
@@ -5,7 +5,9 @@ import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.lang.tree.Tree; import cn.hutool.core.lang.tree.TreeNode; import cn.hutool.core.lang.tree.TreeUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; @@ -20,10 +22,7 @@ import com.by4cloud.platformx.admin.api.feign.RemoteDeptService; import com.by4cloud.platformx.business.api.feign.RemoteFlowProcessService; import com.by4cloud.platformx.business.constant.FlowNameEnum; import com.by4cloud.platformx.business.dto.ContractInvoiceQueryDTO; import com.by4cloud.platformx.business.dto.ContractQueryDTO; import com.by4cloud.platformx.business.dto.GenInvoiceInfoDTO; import com.by4cloud.platformx.business.dto.InvoiceQueryDTO; import com.by4cloud.platformx.business.dto.*; import com.by4cloud.platformx.business.entity.*; import com.by4cloud.platformx.business.mapper.*; import com.by4cloud.platformx.business.service.ContractInvoiceService; @@ -36,6 +35,7 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; @@ -68,6 +68,8 @@ private final RemoteFlowProcessService remoteFlowProcessService; private final PaymentConfirmService paymentConfirmService; private final StringRedisTemplate redisTemplate; private final BipViewMapper bipViewMapper; private final BipDictMapper bipDictMapper; @Value("${BWInvoice.url}") @@ -79,11 +81,26 @@ @Value("${bip.url}") private String url; @Value("${bip.appKey}") private String appKey; @Value("${dept.sgb}") private String sgb; @Value("${bip.appSecret}") private String appSecret; @Value("${dept.smj}") private String smj; @Value("${dept.smjzt}") private String smjzt; @Value("${dept.smjsc}") private String smjsc; @Value("${dept.tfgs}") private String tfgs; @Value("${dept.jxc}") private String jxc; @Value("${dept.ymj}") private String ymj; @Value("${file.path}") private String localPath; @@ -112,7 +129,7 @@ contractInvoiceOutBoundVo.setToInvoiceNum(contractInvoiceOutBoundVo.getInvoiceNum()); }); } return R.ok(invoiceOutBoundVoList); return R.ok(invoiceOutBoundVoList.stream().filter(item->item.getUnitPrice().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList())); } @Override @@ -124,13 +141,13 @@ .selectAs(ContractSubjectMatter::getQuantity, "outBoundNum") .eq(ContractSubjectMatter::getContractId, contractId); List<ContractInvoiceOutBoundVo> invoiceOutBoundVoList = contractSubjectMatterMapper.selectJoinList(ContractInvoiceOutBoundVo.class, wrapper); if (ArrayUtil.isNotEmpty(invoiceOutBoundVoList)) { if (CollUtil.isNotEmpty(invoiceOutBoundVoList)) { invoiceOutBoundVoList.stream().forEach(contractInvoiceOutBoundVo -> { contractInvoiceOutBoundVo.setInvoiceNum(contractInvoiceOutBoundVo.getOutBoundNum().subtract(contractInvoiceOutBoundVo.getAdvanceNum())); contractInvoiceOutBoundVo.setToInvoiceNum(contractInvoiceOutBoundVo.getInvoiceNum()); }); } return R.ok(invoiceOutBoundVoList); return R.ok(invoiceOutBoundVoList.stream().filter(item->item.getUnitPrice().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList())); } @Override @@ -171,6 +188,10 @@ return R.failed("获取开票单位异常"); } SysDept b = r.getData(); BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); if (ObjUtil.isNull(customer)){ return R.failed("获取购方单位异常"); } BigDecimal advanceAmount = new BigDecimal("0"); for (ContractOutBoundInvoiceVo contractOutBoundInvoiceVo : genInvoiceInfoDTO.getOutBoundInvoiceList()) { ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); @@ -184,7 +205,7 @@ return R.failed("开票金额超出合同签订阶段应收金额:" + schedule.getPlannedAmount() + ",请调整开票数量"); } GenInvoiceInfoVo vo = genAdvanceInvoiceInfoVo(genInvoiceInfoDTO, contract, b); vo = transBipVo(vo,b,customer); return R.ok(vo); } @@ -205,6 +226,10 @@ return R.failed("获取开票单位异常"); } SysDept b = r.getData(); BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); if (ObjUtil.isNull(customer)){ return R.failed("获取购方单位异常"); } //机动车开票 if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "3") || StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "4")) { if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())) { @@ -220,19 +245,46 @@ return r1; } JSONObject request1 = genQueryVehDetailParam(genInvoiceInfoDTO.getVehicleNo(), b); R r2 = requestQueryVehicleDetail(request1); R<JSONObject> r2 = requestQueryVehicleDetail(request1,genInvoiceInfoDTO); if (!r2.isOk()) { return r2; } r2.getData().put("contact",b.getOrgContact()); genInvoiceInfoDTO.setVehicleData(r2.getData().toString()); } GenInvoiceInfoVo vo = genInvoiceInfoVo(genInvoiceInfoDTO, contract, b); vo = transBipVo(vo,b,customer); return R.ok(vo); } private R requestQueryVehicleDetail(JSONObject request) { private GenInvoiceInfoVo transBipVo(GenInvoiceInfoVo vo,SysDept comp,BusinessCustomer customer) { ContractInvoiceBipVo bipVo = new ContractInvoiceBipVo(); bipVo.setDjrq(DateUtil.today()); bipVo.setKpzz(comp.getBipCode()); bipVo.setYwzz(comp.getBipCode()); R<SysDept> rDept = remoteDeptService.getById(SecurityUtils.getUser().getDeptId()); if (rDept.isOk()) { bipVo.setBm(rDept.getData().getOrgCode()); bipVo.setHsdy(rDept.getData().getOrgCode()); } bipVo.setYwy(SecurityUtils.getUser().getNickname()); bipVo.setPzzdr(SecurityUtils.getUser().getNickname()); bipVo.setJylx("ZBYXGLXT"); bipVo.setWldxlx("1"); bipVo.setKh(customer.getCreditCode()); bipVo.setBz("CNY"); bipVo.setFjzs("1"); bipVo.setSfzy("1"); bipVo.setSfnbwl("1"); bipVo.setSfjyjs("0"); bipVo.setDjfx("1"); bipVo.setItemList(vo.getInvoiceItemList()); vo.setBipVo(bipVo); return vo; } private R requestQueryVehicleDetail(JSONObject request,GenInvoiceInfoDTO invoiceInfoDTO) { String requestId = IdUtil.fastUUID(); log.info("机动车合格证查询接口入参:{},", request.toJSONString()); @@ -247,6 +299,17 @@ JSONArray models = resultObj.getJSONArray("model"); if (CollUtil.isNotEmpty(models)) { JSONObject model = (JSONObject) models.get(0); if (StrUtil.isNotBlank(invoiceInfoDTO.getOrigin())) { model.put("origin",invoiceInfoDTO.getOrigin()); } if (StrUtil.isNotBlank(invoiceInfoDTO.getTonnage())) { model.put("tonnage",invoiceInfoDTO.getTonnage()); } if (StrUtil.isNotBlank(invoiceInfoDTO.getPassengersLimited())) { model.put("passengersLimited",invoiceInfoDTO.getPassengersLimited()); } model.put("origin",invoiceInfoDTO.getOrigin()); model.put("vehicleNo",invoiceInfoDTO.getVehicleNo()); return R.ok(model); } return R.failed("机动车合格证查询异常"); @@ -295,6 +358,7 @@ private GenInvoiceInfoVo genInvoiceInfoVo(GenInvoiceInfoDTO genInvoiceInfoDTO, Contract contract, SysDept b) { GenInvoiceInfoVo vo = new GenInvoiceInfoVo(); BusinessCustomer a = businessCustomerMapper.selectById(contract.getPartyAId()); vo.setContractId(contract.getId()); vo.setPartyA(a.getCompanyName()); vo.setPartyAOrgCode(a.getCreditCode()); vo.setPartyAOpenBank(a.getBankName()); @@ -304,6 +368,8 @@ vo.setPartyBOpenBank(b.getOrgBank()); vo.setPartyBBankAccount(b.getOrgBankAccount()); vo.setInvoiceType(a.getInvoiceType()); vo.setRemarks(genInvoiceInfoDTO.getRemarks()); vo.setOutBoundInvoiceList(genInvoiceInfoDTO.getOutBoundInvoiceList()); if (StrUtil.isNotBlank(genInvoiceInfoDTO.getInvoiceType())) { vo.setInvoiceVehicleType(genInvoiceInfoDTO.getInvoiceType()); } @@ -335,8 +401,20 @@ mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode()+subjectMatter.getUnitPrice()); mergeVo.setMaterialInternalName(contractOutBound.getSubjectMatterName()); mergeVo.setQuantity(contractOutBoundInvoiceVo.getInvoiceNum()); Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode()) .eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1")); Product product = new Product(); List<String> smjList = new ArrayList<>(); smjList.add(smj); smjList.add(smjsc); smjList.add(smjzt); if ((""+SecurityUtils.getUser().getCompId()).equals(smj)||(""+SecurityUtils.getUser().getCompId()).equals(smjsc)|| (""+SecurityUtils.getUser().getCompId()).equals(smjzt)){ product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode()) .in(Product::getCompId, smjList).last("limit 1")); }else { product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode()) .eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1")); } if (ObjUtil.isNotNull(product)) { mergeVo.setTaxClass(product.getTaxClass()); mergeVo.setSpecification(product.getProductType()); @@ -361,14 +439,15 @@ List<ContractOutBoundMergeVo> filteredList = mergeOutBounds.stream() .filter(item -> item.getMaterialCode().equals(subjectMatter.getMaterialCode()+subjectMatter.getUnitPrice())) // 防止空指针,建议常量在前 .collect(Collectors.toList()); if (ArrayUtil.isNotEmpty(filteredList)) { if (CollUtil.isNotEmpty(filteredList)) { filteredList.get(0).setQuantity(filteredList.get(0).getQuantity().add(contractOutBound.getOutBoundNum())); } } }); if (ArrayUtil.isNotEmpty(mergeOutBounds)) { if (CollUtil.isNotEmpty(mergeOutBounds)) { invoiceItemVoList = BeanUtil.copyToList(mergeOutBounds, InvoiceItemVo.class); invoiceItemVoList.stream().forEach(invoiceItemVo -> { invoiceItemVoList.stream().filter(invoiceItem->invoiceItem.getUnitPrice().compareTo(new BigDecimal("0"))>0) .forEach(invoiceItemVo -> { // for (InvoiceItemVo invoiceItemVo:invoiceItemVoList) { BigDecimal itemPrice = invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity()); BigDecimal itemPriceTax = itemPrice.divide(new BigDecimal("100").add(invoiceItemVo.getTaxRate()), 2, RoundingMode.HALF_UP).multiply(invoiceItemVo.getTaxRate()); @@ -383,7 +462,7 @@ } } } else { if (ArrayUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { if (CollUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); @@ -424,14 +503,15 @@ } else { List<ContractOutBoundMergeVo> filterMergeVo = mergeOutBounds.stream().filter(item -> item.getMaterialCode() .equals(schedule.getSubjectMatterCode())).collect(Collectors.toList()); if (ArrayUtil.isNotEmpty(filterMergeVo)) { if (CollUtil.isNotEmpty(filterMergeVo)) { filterMergeVo.get(0).setPriceAndTax(schedule.getPlannedAmount().add(filterMergeVo.get(0).getPriceAndTax())); } } }); if (ArrayUtil.isNotEmpty(mergeOutBounds)) { if (CollUtil.isNotEmpty(mergeOutBounds)) { invoiceItemVoList = BeanUtil.copyToList(mergeOutBounds, InvoiceItemVo.class); invoiceItemVoList.stream().forEach(invoiceItemVo -> { invoiceItemVoList.stream().filter(invoiceItem->invoiceItem.getUnitPrice().compareTo(new BigDecimal("0"))>0) .forEach(invoiceItemVo -> { // for (InvoiceItemVo invoiceItemVo:invoiceItemVoList) { BigDecimal itemPrice = invoiceItemVo.getPriceAndTax(); BigDecimal itemPriceTax = itemPrice.divide(new BigDecimal("100").add(invoiceItemVo.getTaxRate()), 2, RoundingMode.HALF_UP).multiply(invoiceItemVo.getTaxRate()); @@ -452,6 +532,7 @@ private GenInvoiceInfoVo genAdvanceInvoiceInfoVo(GenInvoiceInfoDTO genInvoiceInfoDTO, Contract contract, SysDept b) { GenInvoiceInfoVo vo = new GenInvoiceInfoVo(); BusinessCustomer a = businessCustomerMapper.selectById(contract.getPartyAId()); vo.setContractId(contract.getId()); vo.setAdvanceInvoice("111"); vo.setPartyA(a.getCompanyName()); vo.setPartyAOrgCode(a.getCreditCode()); @@ -461,6 +542,8 @@ vo.setPartyBOrgCode(b.getOrgCode()); vo.setPartyBOpenBank(b.getOrgBank()); vo.setPartyBBankAccount(b.getOrgBankAccount()); vo.setRemarks(genInvoiceInfoDTO.getRemarks()); vo.setOutBoundInvoiceList(genInvoiceInfoDTO.getOutBoundInvoiceList()); List<InvoiceItemVo> invoiceItemVoList = new ArrayList<>(); List<String> erpCode = new ArrayList<>(); List<ContractOutBoundMergeVo> mergeOutBounds = new ArrayList<>(); @@ -504,9 +587,9 @@ } }); if (ArrayUtil.isNotEmpty(mergeOutBounds)) { if (CollUtil.isNotEmpty(mergeOutBounds)) { invoiceItemVoList = BeanUtil.copyToList(mergeOutBounds, InvoiceItemVo.class); invoiceItemVoList.stream().forEach(invoiceItemVo -> { invoiceItemVoList.stream().filter(invoiceItem->invoiceItem.getUnitPrice().compareTo(new BigDecimal("0"))>0).forEach(invoiceItemVo -> { // for (InvoiceItemVo invoiceItemVo:invoiceItemVoList) { BigDecimal itemPrice = invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity()); BigDecimal itemPriceTax = itemPrice.divide(new BigDecimal("100").add(invoiceItemVo.getTaxRate()), 2, RoundingMode.HALF_UP).multiply(invoiceItemVo.getTaxRate()); @@ -525,36 +608,18 @@ } @Override public R toInvoice(GenInvoiceInfoDTO genInvoiceInfoDTO) { if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { return R.failed("请选择开票出库单后再操作"); public R toInvoice(ToInvoiceDTO toInvoiceDTO) { Contract contract = contractMapper.selectById(toInvoiceDTO.getContractId()); if (ObjUtil.isNull(contract)) { return R.failed("合同信息异常,请联系技术人员"); } genInvoiceInfoDTO.setOutBoundInvoiceList(genInvoiceInfoDTO.getOutBoundInvoiceList().stream().filter(item-> item.getInvoiceNum().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList())); if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { return R.failed("请选择开票出库单后或调整开票数量再操作"); } if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "3") || StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "4")) { if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())) { return R.failed("机动车开票请输入车架号"); } BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item -> item.getInvoiceNum()).reduce(BigDecimal.ZERO, BigDecimal::add); if (invoiceNumSum.compareTo(new BigDecimal("1")) > 0) { return R.failed("机动车开票只能1次开1辆"); } } Long contractId = null; if (StrUtil.isNotBlank(genInvoiceInfoDTO.getContractId())) { if (StrUtil.isNotBlank(toInvoiceDTO.getAdvanceInvoice())) { ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery() .eq(ContractPaymentSchedule::getStageName, "合同签订").eq(ContractPaymentSchedule::getContractId, genInvoiceInfoDTO.getContractId()) .eq(ContractPaymentSchedule::getStageName, "合同签订").eq(ContractPaymentSchedule::getContractId, toInvoiceDTO.getContractId()) .last("limit 1")); if (ObjUtil.isNull(schedule)) { return R.failed("合同预收款阶段异常,请联系技术人员"); } Contract contract = contractMapper.selectById(genInvoiceInfoDTO.getContractId()); if (ObjUtil.isNull(contract)) { return R.failed("合同信息异常,请联系技术人员"); } ContractInvoice lastInvoice = baseMapper.selectOne(Wrappers.<ContractInvoice>lambdaQuery().eq(ContractInvoice::getContractId, contract.getId()) .orderByDesc(ContractInvoice::getCreateTime).last("limit 1")); @@ -567,7 +632,7 @@ } SysDept b = r.getData(); BigDecimal advanceAmount = new BigDecimal("0"); for (ContractOutBoundInvoiceVo contractOutBoundInvoiceVo : genInvoiceInfoDTO.getOutBoundInvoiceList()) { for (ContractOutBoundInvoiceVo contractOutBoundInvoiceVo : toInvoiceDTO.getOutBoundInvoiceList()) { ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); if (ObjUtil.isNotNull(subjectMatter)) { advanceAmount = advanceAmount.add(contractOutBoundInvoiceVo.getInvoiceNum().multiply(subjectMatter.getUnitPrice())); @@ -577,9 +642,9 @@ if (advanceAmount.compareTo(schedule.getPlannedAmount()) > 0) { return R.failed("开票金额超出合同签订阶段应收金额:" + schedule.getPlannedAmount() + ",请调整开票数量"); } GenInvoiceInfoVo vo = genAdvanceInvoiceInfoVo(genInvoiceInfoDTO, contract, b); GenInvoiceInfoVo vo = BeanUtil.copyProperties(toInvoiceDTO,GenInvoiceInfoVo.class); //发票保存 ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "1"); ContractInvoice invoice = saveContractInvoice(vo, contract, toInvoiceDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "1"); //启动流程 ProcessInstanceParamDto dto = new ProcessInstanceParamDto(); Map<String, Object> map = BeanUtil.beanToMap(invoice); @@ -590,57 +655,20 @@ return R.failed("流程启动失败"); } //更新合同出库单状态 genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { toInvoiceDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); subjectMatter.setAdvanceNum(subjectMatter.getAdvanceNum().add(contractOutBoundInvoiceVo.getInvoiceNum())); contractSubjectMatterMapper.updateById(subjectMatter); }); return R.ok(); } if (!StrUtil.equals(genInvoiceInfoDTO.getContractCategory(), "water_house")) { ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId()); contractId = outBound.getContractId(); } else { ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId()); contractId = schedule.getContractId(); } Contract contract = contractMapper.selectById(contractId); if (ObjUtil.isNull(contract)) { return R.failed("合同信息异常,请联系技术人员"); } R<SysDept> r = remoteDeptService.getById(contract.getPartyBId()); if (!r.isOk()) { return R.failed("获取开票单位异常"); } SysDept b = r.getData(); //机动车开票 if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "3") || StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "4")) { if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())) { return R.failed("机动车开票请输入车架号"); } BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item -> item.getInvoiceNum()).reduce(BigDecimal.ZERO, BigDecimal::add); if (invoiceNumSum.compareTo(new BigDecimal("1")) > 0) { return R.failed("机动车开票只能1次开1辆"); } JSONObject request = genQueryVinParam(genInvoiceInfoDTO.getVehicleNo(), b); R r1 = requestQueryVehicleNo(request); if (!r1.isOk()) { return r1; } JSONObject request1 = genQueryVehDetailParam(genInvoiceInfoDTO.getVehicleNo(), b); R r2 = requestQueryVehicleDetail(request1); if (!r2.isOk()) { return r2; } genInvoiceInfoDTO.setVehicleData(r2.getData().toString()); } GenInvoiceInfoVo vo = genInvoiceInfoVo(genInvoiceInfoDTO, contract, b); GenInvoiceInfoVo vo = BeanUtil.copyProperties(toInvoiceDTO,GenInvoiceInfoVo.class); //发票保存 ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "0"); ContractInvoice invoice = saveContractInvoice(vo, contract, toInvoiceDTO.getOutBoundInvoiceList(), DateUtil.current() + "", "0"); //启动流程 ProcessInstanceParamDto dto = new ProcessInstanceParamDto(); Map<String, Object> map = BeanUtil.beanToMap(invoice); if (StrUtil.equals(genInvoiceInfoDTO.getContractCategory(), "water_house")) { if (StrUtil.equals(toInvoiceDTO.getContractCategory(), "water_house")) { map.put("contractCategory", "water_house"); } dto.setParamMap(map); @@ -651,7 +679,7 @@ } if (!StrUtil.equals(contract.getContractCategory(), "water_house")) { //更新合同出库单状态 genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { toInvoiceDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); contractOutBound.setInvoiceStatus("1"); contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum())); @@ -659,7 +687,7 @@ }); } else { //更新合同房租 水电 费开票状态 genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { toInvoiceDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); schedule.setInvoiceFlag("1"); contractPaymentScheduleMapper.updateById(schedule); @@ -727,7 +755,7 @@ data.put("invoiceTotalPriceTax", vo.getTotalPrice()); data.put("buyerBankName", vo.getPartyAOpenBank()); data.put("buyerBankNumber", vo.getPartyABankAccount()); data.put("remarks",vo.getRemarks()); jsonObject.put("data", data); return jsonObject; } @@ -768,7 +796,6 @@ @Override public R toRedInvoice(Long invoiceId) { ContractInvoice blueInvoice = baseMapper.selectById(invoiceId); blueInvoice.setRedReversal("2"); baseMapper.updateById(blueInvoice); @@ -782,10 +809,21 @@ invoice.setInvoiceTotalTax(blueInvoice.getInvoiceTotalTax()); invoice.setInvoiceTotalPrice(blueInvoice.getInvoiceTotalPrice()); invoice.setInvoiceTotalPriceTax(blueInvoice.getInvoiceTotalPriceTax()); invoice.setInvoicePreview(blueInvoice.getInvoicePreview()); invoice.setInvoiceTotalTax(blueInvoice.getInvoiceTotalTax()); invoice.setInvoiceTotalPrice(blueInvoice.getInvoiceTotalPrice()); invoice.setInvoiceTotalPriceTax(blueInvoice.getInvoiceTotalPriceTax()); ToInvoiceDTO toInvoiceDTO = BeanUtil.copyProperties(JSONObject.parseObject(blueInvoice.getInvoicePreview()),ToInvoiceDTO.class); toInvoiceDTO.setTotalPrice(toInvoiceDTO.getTotalPrice().multiply(new BigDecimal(-1))); toInvoiceDTO.setTotalTax(toInvoiceDTO.getTotalTax().multiply(new BigDecimal(-1))); if (CollUtil.isNotEmpty(toInvoiceDTO.getInvoiceItemList())){ toInvoiceDTO.getInvoiceItemList().stream().forEach(item->{ item.setPriceTax(item.getPriceTax().multiply(new BigDecimal("-1"))); item.setPriceNoTax(item.getPriceNoTax().multiply(new BigDecimal("-1"))); item.setPriceAndTax(item.getPriceAndTax().multiply(new BigDecimal("-1"))); }); } invoice.setInvoicePreview(JSONObject.toJSONString(toInvoiceDTO)); invoice.setInvoiceTotalTax(blueInvoice.getInvoiceTotalTax().multiply(new BigDecimal("-1"))); invoice.setInvoiceTotalPrice(blueInvoice.getInvoiceTotalPrice().multiply(new BigDecimal("-1"))); invoice.setInvoiceTotalPriceTax(blueInvoice.getInvoiceTotalPriceTax().multiply(new BigDecimal("-1"))); invoice.setOutBoundId(blueInvoice.getOutBoundId()); invoice.setInvoiceTime(new Date()); invoice.setInvoiceCategory("2"); @@ -814,26 +852,26 @@ return R.ok(); } private JSONObject genRedInvoice(Contract contract, ContractInvoice blueInvoice, String redConfirmSerialNo) { private JSONObject genRedInvoice(Contract contract, ContractInvoice blueInvoice,ContractInvoice redInvoice, String redConfirmSerialNo) { JSONObject jsonObject = new JSONObject(); jsonObject.put("taxNo", blueInvoice.getTaxNo()); jsonObject.put("taxNo", redInvoice.getTaxNo()); jsonObject.put("redConfirmSerialNo", redConfirmSerialNo); jsonObject.put("entryIdentity", "01"); jsonObject.put("sellerTaxNo", blueInvoice.getTaxNo()); jsonObject.put("sellerTaxName", blueInvoice.getSellerTaxName()); jsonObject.put("buyerTaxName", blueInvoice.getBuyerTaxName()); jsonObject.put("buyerTaxNo", blueInvoice.getBuyerTaxNo()); jsonObject.put("sellerTaxNo", redInvoice.getTaxNo()); jsonObject.put("sellerTaxName", redInvoice.getSellerTaxName()); jsonObject.put("buyerTaxName", redInvoice.getBuyerTaxName()); jsonObject.put("buyerTaxNo", redInvoice.getBuyerTaxNo()); jsonObject.put("originInvoiceDate", DateUtil.formatDateTime(blueInvoice.getInvoiceTime())); jsonObject.put("originInvoiceTotalPrice", blueInvoice.getInvoiceTotalPrice()); jsonObject.put("originInvoiceTotalTax", blueInvoice.getInvoiceTotalTax()); jsonObject.put("invoiceTotalPrice", blueInvoice.getInvoiceTotalPrice().multiply(new BigDecimal("-1"))); jsonObject.put("invoiceTotalTax", blueInvoice.getInvoiceTotalTax().multiply(new BigDecimal("-1"))); jsonObject.put("originInvoiceTotalPrice", redInvoice.getInvoiceTotalPriceTax()); jsonObject.put("originInvoiceTotalTax", redInvoice.getInvoiceTotalTax()); jsonObject.put("invoiceTotalPrice", redInvoice.getInvoiceTotalPrice()); jsonObject.put("invoiceTotalTax", redInvoice.getInvoiceTotalTax()); jsonObject.put("originInvoiceIsPaper", "N"); jsonObject.put("originInvoiceType", "01"); jsonObject.put("redInvoiceLabel", "01"); jsonObject.put("invoiceSource", "2"); jsonObject.put("originalInvoiceNo", blueInvoice.getInvoiceNo()); GenInvoiceInfoVo vo = BeanUtil.copyProperties(JSONObject.parseObject(blueInvoice.getInvoicePreview()), GenInvoiceInfoVo.class); GenInvoiceInfoVo vo = BeanUtil.copyProperties(JSONObject.parseObject(redInvoice.getInvoicePreview()), GenInvoiceInfoVo.class); JSONArray invoiceDetailsList = new JSONArray(); Integer lineNo = 1; for (InvoiceItemVo invoiceItemVo : vo.getInvoiceItemList()) { @@ -842,12 +880,15 @@ invoiceDetail.put("projectName", invoiceItemVo.getItemName()); invoiceDetail.put("goodsLineNo", lineNo); invoiceDetail.put("goodsCode", invoiceItemVo.getTaxCode()); invoiceDetail.put("goodsTaxRate", invoiceItemVo.getTaxRate().divide(new BigDecimal("100"))); invoiceDetail.put("goodsTaxRate", invoiceItemVo.getTaxRate()); invoiceDetail.put("goodsUnit", invoiceItemVo.getUnit()); invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity()); // invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice()); invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceNoTax().multiply(new BigDecimal("-1"))); invoiceDetail.put("goodsTotalTax", invoiceItemVo.getPriceTax().multiply(new BigDecimal("-1"))); invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceNoTax()); invoiceDetail.put("goodsTotalTax", invoiceItemVo.getPriceTax()); if (vo.getInvoiceVehicleType().equals("3")||vo.getInvoiceVehicleType().equals("4")){ invoiceDetail.put("goodsSpecification", invoiceItemVo.getSpecification()); } invoiceDetailsList.add(invoiceDetail); lineNo++; } @@ -863,7 +904,7 @@ .eq(ContractInvoice::getApprovalStatus, "1") .eq(ContractInvoice::getBwRequestResult, "1") .isNull(ContractInvoice::getInvoicePath)); if (ArrayUtil.isNotEmpty(contractInvoices)) { if (CollUtil.isNotEmpty(contractInvoices)) { contractInvoices.stream().forEach(contractInvoice -> { JSONObject request = new JSONObject(); request.put("taxNo", contractInvoice.getTaxNo()); @@ -885,7 +926,7 @@ contractInvoice.setInvoiceStatus("2"); baseMapper.updateById(contractInvoice); //传输附件 pushBipInvoicePdf(contractInvoice); // pushBipInvoicePdf(contractInvoice); } }); } @@ -893,7 +934,7 @@ return R.ok(); } private void pushBipInvoicePdf(ContractInvoice contractInvoice) { private void pushBipInvoicePdf(ContractInvoice contractInvoice){ String accessToken = ""; if (redisTemplate.hasKey("BIP_TOKEN")) { accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN"); @@ -936,7 +977,7 @@ .execute(); log.info("应收发票附件上传回参:{}", response.body()); //保存请求记录 paymentConfirmService.saveBipRequestRecord(request, "应收发票集成接口", response.body()); paymentConfirmService.saveBipRequestRecord(request, "应收发票附件上传接口", response.body()); JSONObject resultJson = JSONObject.parseObject(response.body()); if (resultJson.containsKey("code") && resultJson.getString("code").equals("200")) { JSONObject datas = resultJson.getJSONObject("data"); @@ -970,8 +1011,40 @@ // 2. 解码 Base64 为字节数组 byte[] fileBytes = Base64.getDecoder().decode(base64Str); File file = new File(targetPath); // 1. 获取父目录对象 File parentDir = file.getParentFile(); // 2. 如果父目录不为空且不存在,则创建所有必需的父目录 if (parentDir != null && !parentDir.exists()) { // mkdirs() 会递归创建所有不存在的父目录 // 必须检查返回值,因为可能因权限不足或路径非法而失败 if (!parentDir.mkdirs()) { // 如果 mkdirs 返回 false,再次检查是否存在(处理并发情况) if (!parentDir.exists()) { log.error("无法创建父目录: " + parentDir.getAbsolutePath()); } } } // 3. 创建文件本身 // createNewFile() 仅在文件不存在时创建,如果已存在则返回 false 但不报错 if (!file.exists()) { boolean created = false; try { created = file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } if (!created) { // 处理并发创建失败或其他异常 log.error("无法创建文件: " + file.getAbsolutePath()); } } // 3. 将字节数组写入文件 try (FileOutputStream fos = new FileOutputStream(new File(targetPath))) { try (FileOutputStream fos = new FileOutputStream(file)) { fos.write(fileBytes); fos.flush(); System.out.println("文件保存成功: " + targetPath); @@ -1083,22 +1156,76 @@ data.put("bustypeCode", "ZBYXGLXT");//交易类型编码 暂估默认ZGYSFP,销售默认ZBYXGLXT data.put("contractNo", contract.getContractNo()); data.put("oriCurrencyCode", "CNY");//币种 data.put("_status", "Insert"); GenInvoiceInfoVo vo = BeanUtil.copyProperties(JSONObject.parseObject(contractInvoice.getInvoicePreview()), GenInvoiceInfoVo.class); JSONArray bodyItem = new JSONArray(); for (InvoiceItemVo invoiceItemVo : vo.getInvoiceItemList()) { for (InvoiceItemVo invoiceItemVo : vo.getBipVo().getItemList()) { JSONObject item = new JSONObject(); item.put("expenseItemCode",invoiceItemVo.getJjsx());//经济事项 item.put("invoiceNo", contractInvoice.getInvoiceNo()); item.put("taxRate", invoiceItemVo.getTaxRate()); item.put("oriTaxAmount", invoiceItemVo.getPriceTax()); item.put("oriTaxIncludedAmount", invoiceItemVo.getPriceAndTax()); item.put("_status", "Insert"); JSONObject freeChId = new JSONObject(); freeChId.put("GX08",invoiceItemVo.getHsdy());//核算单元 freeChId.put("YSYF31",invoiceItemVo.getSfjs());//是否计税 freeChId.put("JT04",invoiceItemVo.getHsjylx());//核算交易类型 0101 集团外部 01020301 三级分子公司间 01020302 三级分公司与子子公司之间 freeChId.put("JT06",invoiceItemVo.getKxmx());//款项明细 freeChId.put("JT32",invoiceItemVo.getZyys());//作业要素 freeChId.put("zzbkfl",invoiceItemVo.getBkfl());//板块分类 freeChId.put("JT12",invoiceItemVo.getCpwlfl());//产品物料分类 item.put("freeChId",freeChId); bodyItem.add(item); } data.put("bodyItem", bodyItem); JSONObject freeChId = new JSONObject(); freeChId.put("YSYF_SFZY",vo.getBipVo().getSfzy());//是否主营 freeChId.put("fk_038",vo.getBipVo().getPzzdr());//凭证制单人 freeChId.put("YSYF_08",vo.getBipVo().getSfnbwl());//是否内部往来 freeChId.put("YSYF24",vo.getBipVo().getSfjyjs());//是否简易计税 freeChId.put("fk_002",vo.getBipVo().getFjzs());//附件1 freeChId.put("GX08",vo.getBipVo().getHsdy());//核算单元 freeChId.put("TzMY042",contract.getExpirationDate());//预计回款日期 data.put("freeChId", freeChId); data.put("remarks",vo.getBipVo().getZy());//摘要 jsonObject.put("data", data); return jsonObject; } private String transEconomic(String economicMatters) { if (economicMatters.equals("1")){ return "09001006"; } if (economicMatters.equals("2")){ return "09004003"; } if (economicMatters.equals("3")){ return "09003005"; } if (economicMatters.equals("4")){ return "09002042"; } if (economicMatters.equals("5")){ return "09002002"; } if (economicMatters.equals("6")){ return "09004001"; } if (economicMatters.equals("7")){ return "09003002001"; } if (economicMatters.equals("8")){ return "09003002002"; } if (economicMatters.equals("9")){ return "09003002003"; } if (economicMatters.equals("10")){ return "09003003"; } return ""; } @Override @@ -1106,7 +1233,7 @@ if (bwFlag) { List<ContractInvoice> contractInvoices = baseMapper.selectList(Wrappers.<ContractInvoice>lambdaQuery() .eq(ContractInvoice::getInvoiceCategory, "2").eq(ContractInvoice::getInvoiceStatus, "3")); if (ArrayUtil.isNotEmpty(contractInvoices)) { if (CollUtil.isNotEmpty(contractInvoices)) { contractInvoices.stream().forEach(contractInvoice -> { JSONObject request = new JSONObject(); request.put("taxNo", contractInvoice.getTaxNo()); @@ -1126,7 +1253,7 @@ return; } JSONArray models = resultObj.getJSONArray("model"); if (ArrayUtil.isNotEmpty(models)) { if (CollUtil.isNotEmpty(models)) { JSONObject model = (JSONObject) models.get(0); if (StrUtil.isEmpty(model.getString("confirmBillingMark")) || StrUtil.equals(model.getString("confirmBillingMark"), "N")) { @@ -1137,7 +1264,7 @@ contractInvoice.setInvoiceNo(model.getString("redInvoiceNo")); contractInvoice.setRedReversal("1"); //推送BIP pushBipInvoice(contractInvoice); // pushBipInvoice(contractInvoice); } } }); @@ -1164,15 +1291,15 @@ //蓝票 if (invoice.getInvoiceCategory().equals("1")) { // TODO 开蓝票接口机动车 if (StrUtil.equals(vo.getInvoiceVehicleType(), "3")) { // TODO 开蓝票接口机动车销售 if (StrUtil.equals(vo.getInvoiceVehicleType(), "4")) { JSONObject request = genBlueInvoiceVehicle(vo, invoice.getSerialNo(), dept); String requestId = IdUtil.fastUUID(); invoice.setBwRequestId(requestId); invoice.setBwRequestParam(request.toJSONString()); log.info("机动车发票开具请求接口入参:{}", request.toJSONString()); log.info("机动车销售统一发票开具请求接口入参:{}", request.toJSONString()); String result = HttpUtil.post(bwUrl + "method=baiwang.output.invoice.vehicleissue&version=1.0&requestId=" + requestId, request.toJSONString()); log.info("机动车发票开具请求接口回参:{}", result); log.info("机动车销售统一发票开具请求接口回参:{}", result); saveBwRequestRecord("baiwang.output.invoice.vehicleissue", requestId, request.toJSONString(), result); JSONObject resultObj = JSONObject.parseObject(result); if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && @@ -1186,13 +1313,39 @@ invoice.setInvoiceTime(invoiceDate); invoice.setInvoiceNo(modelJson.getString("invoiceNo")); //推送BIP pushBipInvoice(invoice); // pushBipInvoice(invoice); } } // TODO 开蓝票接口机动车专用 if (StrUtil.equals(vo.getInvoiceVehicleType(), "3")) { JSONObject request = genBlueInvoiceVehiclePre(vo, invoice.getSerialNo(), dept); String requestId = IdUtil.fastUUID(); invoice.setBwRequestId(requestId); invoice.setBwRequestParam(request.toJSONString()); log.info("机动车专用发票开具请求接口入参:{}", request.toJSONString()); String result = HttpUtil.post(bwUrl + "method=baiwang.output.invoice.issue&version=1.0&requestId=" + requestId, request.toJSONString()); log.info("机动车专用发票开具请求接口回参:{}", result); saveBwRequestRecord("baiwang.output.invoice.issue", requestId, request.toJSONString(), result); JSONObject resultObj = JSONObject.parseObject(result); if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && resultObj.getBoolean("success")) { log.info("开票成功!!!"); invoice.setBwRequestResult("1"); } JSONObject modelJson = resultObj.getJSONObject("model"); if (ObjUtil.isNotNull(modelJson)) { Date invoiceDate = DateUtil.parse(modelJson.getString("invoiceDate"), DatePattern.PURE_DATETIME_PATTERN); invoice.setInvoiceTime(invoiceDate); invoice.setInvoiceNo(modelJson.getString("invoiceNo")); //推送BIP // pushBipInvoice(invoice); } } // TODO 开蓝票接口 非机动车 JSONObject request = genBlueInvoice(vo, invoice.getSerialNo(), dept); if (bwFlag) { if (!StrUtil.equals(vo.getInvoiceVehicleType(), "3")&&!StrUtil.equals(vo.getInvoiceVehicleType(), "4")) { JSONObject request = genBlueInvoice(vo, invoice.getSerialNo(), dept); String requestId = IdUtil.fastUUID(); invoice.setBwRequestId(requestId); invoice.setBwRequestParam(request.toJSONString()); @@ -1215,7 +1368,7 @@ invoice.setInvoiceTime(invoiceDate); invoice.setInvoiceNo(model.getString("invoiceNo")); //推送BIP pushBipInvoice(invoice); // pushBipInvoice(invoice); } } } @@ -1258,7 +1411,7 @@ //判断是否有可开票记录 List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() .eq(ContractPaymentSchedule::getContractId, contract.getId()).eq(ContractPaymentSchedule::getInvoiceFlag, "0")); if (ArrayUtil.isEmpty(scheduleList)) { if (CollUtil.isEmpty(scheduleList)) { contract.setBillingStatus("3"); } else { contract.setBillingStatus("2"); @@ -1280,7 +1433,7 @@ //判断是否有可开票记录 List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() .eq(ContractPaymentSchedule::getContractId, contract.getId())); if (ArrayUtil.isEmpty(scheduleList)) { if (CollUtil.isEmpty(scheduleList)) { contract.setBillingStatus("1"); } else { contract.setBillingStatus("2"); @@ -1295,7 +1448,7 @@ if (invoice.getInvoiceCategory().equals("2")) { // TODO 开红票接口 ContractInvoice blueInvoice = baseMapper.selectById(invoice.getBlueInvoiceId()); JSONObject request = genRedInvoice(contract, blueInvoice, invoice.getSerialNo()); JSONObject request = genRedInvoice(contract,blueInvoice, invoice, invoice.getSerialNo()); String requestId = IdUtil.fastUUID(); invoice.setBwRequestId(requestId); invoice.setBwRequestParam(request.toJSONString()); @@ -1323,12 +1476,12 @@ invoice.setInvoiceNo(model.getString("redInvoiceNo")); invoice.setRedReversal("1"); //推送BIP pushBipInvoice(invoice); // pushBipInvoice(invoice); } } } baseMapper.updateById(invoice); contract.setBillingAmout(contract.getBillingAmout().subtract(invoice.getInvoiceTotalPriceTax())); contract.setBillingAmout(contract.getBillingAmout().add(invoice.getInvoiceTotalPriceTax())); //防止重复审开票审核通过后 开票金额为负 if (contract.getBillingAmout().compareTo(new BigDecimal("0")) < 0) { contract.setBillingAmout(new BigDecimal("0")); @@ -1339,7 +1492,7 @@ if (StrUtil.isNotBlank(vo.getAdvanceInvoice())) { //还原预开数量 List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class); if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) { if (CollUtil.isNotEmpty(outBoundInvoiceVoList)) { outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); if (ObjUtil.isNotNull(subjectMatter)) { @@ -1359,7 +1512,7 @@ if (!StrUtil.equals(contract.getContractCategory(), "water_house")) { //更新合同出库单状态 List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class); if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) { if (CollUtil.isNotEmpty(outBoundInvoiceVoList)) { outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum())); @@ -1369,7 +1522,7 @@ } else { //更新合同房租 水电 费开票状态 List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class); if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) { if (CollUtil.isNotEmpty(outBoundInvoiceVoList)) { outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); schedule.setInvoiceFlag("0"); @@ -1379,6 +1532,60 @@ } } } private JSONObject genBlueInvoiceVehiclePre(GenInvoiceInfoVo vo, String serialNo, SysDept dept) { JSONObject vechicleData = JSONObject.parseObject(vo.getVehicleData()); JSONObject jsonObject = new JSONObject(); //销方 jsonObject.put("taxNo", vo.getPartyBOrgCode());//税号 jsonObject.put("taxUserName", SecurityUtils.getUser().getPhone());//数电账号 jsonObject.put("formatGenerate", false);//是否需要生成版式返回版式链接(true / false) jsonObject.put("formatPushType", false);//版式生成是否推送(true / false) jsonObject.put("taxUserName", dept.getInvoiceContact()); //data JSONObject data = new JSONObject(); data.put("invoiceTypeCode", "01"); data.put("invoiceType", "0"); data.put("serialNo", serialNo); data.put("invoiceSpecialMark","14");//特定业务标识 14-机动车 // data.put("taxationMethod","2"); // data.put("taxationLabel","02");//发票类型代码为“01-数电发票(增值税专用发票)、02-数电发票(普通发票)”时且征税方式为“2-差额征税”时必填 List<JSONObject> invoiceDetailsList = new ArrayList<>(); Integer lineNo = 1; //data.invoiceDetailsList for (InvoiceItemVo invoiceItemVo : vo.getInvoiceItemList()) { JSONObject invoiceDetail = new JSONObject(); invoiceDetail.put("goodsLineNo", lineNo); invoiceDetail.put("goodsName", invoiceItemVo.getItemName()); invoiceDetail.put("projectName", invoiceItemVo.getItemName()); invoiceDetail.put("goodsCode", invoiceItemVo.getTaxCode()); invoiceDetail.put("goodsTaxRate", invoiceItemVo.getTaxRate().divide(new BigDecimal("100"))); invoiceDetail.put("goodsUnit", "辆"); invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity()); // invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice()); invoiceDetail.put("goodsSpecification", vo.getVehicleNo()); invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceNoTax()); invoiceDetail.put("goodsTotalTax", invoiceItemVo.getPriceTax()); invoiceDetailsList.add(invoiceDetail); lineNo++; } data.put("invoiceDetailsList", invoiceDetailsList); //购方 data.put("buyerTaxNo", vo.getPartyAOrgCode()); data.put("buyerName", vo.getPartyA()); data.put("sellerTaxNo", vo.getPartyBOrgCode());// TODO 税务总局系统登陆人手机号 data.put("invoiceTotalPrice", vo.getTotalPrice().subtract(vo.getTotalTax())); data.put("invoiceTotalPriceTax", vo.getTotalPrice()); data.put("invoiceTotalTax", vo.getTotalTax()); data.put("buyerBankName", vo.getPartyAOpenBank()); data.put("buyerBankNumber", vo.getPartyABankAccount()); jsonObject.put("data", data); return jsonObject; } private JSONObject genBlueInvoiceVehicle(GenInvoiceInfoVo vo, String serialNo, SysDept dept) { @@ -1442,7 +1649,7 @@ if (!StrUtil.equals(contract.getContractCategory(), "water_house")) { //更新合同出库单状态 List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(invoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class); if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) { if (CollUtil.isNotEmpty(outBoundInvoiceVoList)) { outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum())); @@ -1452,7 +1659,7 @@ } else { //更新合同房租 水电 费开票状态 List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(invoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class); if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) { if (CollUtil.isNotEmpty(outBoundInvoiceVoList)) { outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); schedule.setInvoiceFlag("0"); @@ -1511,7 +1718,7 @@ invoice.setInvoiceTime(invoiceDate); invoice.setInvoiceNo(model.getString("invoiceNo")); //推送BIP pushBipInvoice(invoice); // pushBipInvoice(invoice); } } } @@ -1535,7 +1742,7 @@ } invoice.setBwRequestResult("1"); JSONArray models = resultObj.getJSONArray("model"); if (ArrayUtil.isNotEmpty(models)) { if (CollUtil.isNotEmpty(models)) { JSONObject model = (JSONObject) models.get(0); if (StrUtil.isEmpty(model.getString("confirmBillingMark")) || StrUtil.equals(model.getString("confirmBillingMark"), "N")) { //等待确认 @@ -1545,7 +1752,7 @@ invoice.setInvoiceNo(model.getString("redInvoiceNo")); invoice.setRedReversal("1"); //推送BIP pushBipInvoice(invoice); // pushBipInvoice(invoice); } } } @@ -1716,6 +1923,51 @@ return R.ok(); } @Override public ContractInvoice getById(Long id) { return baseMapper.selectById(id); } @Override public R bipPushPdf(Long invoiceId) { ContractInvoice invoice = baseMapper.selectById(invoiceId); pushBipInvoicePdf(invoice); return R.ok(); } @Override public R selectBipByKey(String dictKey) { List<BipDict> bipDictList = bipDictMapper.selectList(Wrappers.<BipDict>lambdaQuery().eq(BipDict::getDictKey,dictKey)); if (CollUtil.isNotEmpty(bipDictList)){ // 权限内部门 List<TreeNode<Long>> collect = bipDictList.stream() .map(dict -> { TreeNode<Long> treeNode = new TreeNode<>(); treeNode.setId(dict.getId()); treeNode.setParentId(dict.getParentId()); treeNode.setName(dict.getDictName()); treeNode.setWeight(dict.getDictCode()); return treeNode; }) .collect(Collectors.toList()); return R.ok(TreeUtil.build(collect,0L)); } return R.failed("字典获取失败"); } @Override public R saveAndPush(ContractInvoiceUpateDTO upateDTO) { ContractInvoice invoice = baseMapper.selectById(upateDTO.getId()); invoice.setInvoicePreview(upateDTO.getInvoicePreview()); baseMapper.updateById(invoice); R r = bipPush(invoice.getId()); if (!r.isOk()){ return r; } return bipPushPdf(invoice.getId()); } public static void main(String[] args) { File file = new File("d://tmp//" + IdUtil.fastUUID() + ".pdf"); HttpUtil.downloadFile("http://fp.baiwang.com/format/d?d=BB99645F8ED2AE7D2055E7D29330D366B7CAE92C278C6BB84D222610CEC2118D", file); platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractPaymentScheduleProcessServiceImpl.java
@@ -54,13 +54,14 @@ } private void saveScheduleProcess(ContractPaymentScheduleProcessAddDTO addDTO, ContractPaymentSchedule schedule) { //履约 ContractPaymentScheduleProcess contractPaymentScheduleProcess = BeanUtil.copyProperties(addDTO, ContractPaymentScheduleProcess.class); public void saveScheduleProcess(Date date, ContractPaymentSchedule schedule) { //更新履约 ContractPaymentScheduleProcess contractPaymentScheduleProcess = new ContractPaymentScheduleProcess(); contractPaymentScheduleProcess.setContractId(schedule.getContractId()); contractPaymentScheduleProcess.setContractName(schedule.getContractName()); contractPaymentScheduleProcess.setScheduleId(schedule.getId()); contractPaymentScheduleProcess.setScheduleName(schedule.getStageName()); contractPaymentScheduleProcess.setProcessDate(date); ContractPaymentScheduleProcess lastProcess = baseMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId()) .eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1")); if (ObjUtil.isNull(lastProcess)) { @@ -89,7 +90,7 @@ updateCurrentSchedule(addDTO.getProcessDate(), schedule, contract); //保存履约记录 saveScheduleProcess(addDTO, schedule); saveScheduleProcess(addDTO.getProcessDate(), schedule); return R.ok(); } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/ContractServiceImpl.java
@@ -92,6 +92,7 @@ private final ContractOutBoundMapper contractOutBoundMapper; private final RemoteDictService remoteDictService; private final ContractPaymentScheduleProcessService processService; private final ContractSubjectMatterChangeMapper changeMapper; @Value("${erp.ymj}") private String ymjErp; @@ -435,9 +436,35 @@ detailVo.setPaymentSlip(slipList); } BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId()); ContractInvoiceBipVo bipVo = new ContractInvoiceBipVo(); bipVo.setDjrq(DateUtil.today()); R<SysDept> r = remoteDeptService.getById(contract.getPartyBId()); if (r.isOk()) { bipVo.setKpzz(r.getData().getBipCode()); } if (ObjUtil.isNotNull(customer)) { detailVo.setInvoiceType(customer.getInvoiceType()); bipVo.setYwzz(r.getData().getBipCode()); } R<SysDept> rDept = remoteDeptService.getById(SecurityUtils.getUser().getDeptId()); if (rDept.isOk()) { bipVo.setBm(rDept.getData().getOrgCode()); bipVo.setHsdy(rDept.getData().getOrgCode()); } bipVo.setYwy(SecurityUtils.getUser().getNickname()); bipVo.setPzzdr(SecurityUtils.getUser().getNickname()); bipVo.setJylx("ZBYXGLXT"); bipVo.setWldxlx("1"); bipVo.setKh(customer.getCreditCode()); bipVo.setBz("人民币"); bipVo.setFjzs("1"); bipVo.setSfzy("是"); bipVo.setSfnbwl("是"); bipVo.setSfjyjs("否"); bipVo.setDjfx("1"); detailVo.setBipVo(bipVo); return detailVo; } @@ -569,7 +596,7 @@ request.put("moneySum", contract.getAmount()); request.put("signManner", "面签"); request.put("salesman", ""); if (ArrayUtil.isNotEmpty(subjectMatterList)) { if (CollUtil.isNotEmpty(subjectMatterList)) { JSONArray subjectMatter = new JSONArray(); subjectMatterList.stream().forEach(contractSubjectMatter -> { JSONObject subjectMatterItem = new JSONObject(); @@ -623,7 +650,7 @@ request.put("moneySum", contract.getAmount()); request.put("signManner", "面签"); request.put("salesman", ""); if (ArrayUtil.isNotEmpty(subjectMatterList)) { if (CollUtil.isNotEmpty(subjectMatterList)) { JSONArray subjectMatter = new JSONArray(); subjectMatterList.stream().forEach(contractSubjectMatter -> { JSONObject subjectMatterItem = new JSONObject(); @@ -865,7 +892,7 @@ .lt(ContractPaymentSchedule::getEffectiveEndDate, DateUtil.today()) .ne(ContractPaymentSchedule::getPaymentStatus, "2") .ne(ContractPaymentSchedule::getPaymentStatus, 3)); if (ArrayUtil.isNotEmpty(scheduleList)) { if (CollUtil.isNotEmpty(scheduleList)) { scheduleList.stream().forEach(contractPaymentSchedule -> { Contract contract = baseMapper.selectById(contractPaymentSchedule.getContractId()); if (ObjUtil.isNotNull(contract)) { @@ -1073,7 +1100,7 @@ public R genCycleReceiced() { List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery() .le(ContractExecDate::getExecDate, DateUtil.today()).eq(ContractExecDate::getGenFlag, "0")); if (ArrayUtil.isNotEmpty(execDateList)) { if (CollUtil.isNotEmpty(execDateList)) { execDateList.stream().forEach(contractExecDate -> { Contract contract = baseMapper.selectById(contractExecDate.getContractId()); ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() @@ -1585,10 +1612,10 @@ @Override public R addContractSgb(ContractAddDTO addDTO) { if (ArrayUtil.isEmpty(addDTO.getContractSubjectMatter())) { if (CollUtil.isEmpty(addDTO.getContractSubjectMatter())) { return R.failed("请添加标的物"); } if (ArrayUtil.isEmpty(addDTO.getContractPaymentSchedule())) { if (CollUtil.isEmpty(addDTO.getContractPaymentSchedule())) { return R.failed("请添加付款阶段或付款阶段缺少"); } if (!isValidPaymentStages(addDTO.getContractPaymentSchedule())) { @@ -1637,7 +1664,7 @@ } baseMapper.insert(contract); if (ArrayUtil.isNotEmpty(addDTO.getContractSubjectMatter())) { if (CollUtil.isNotEmpty(addDTO.getContractSubjectMatter())) { addDTO.getContractSubjectMatter().stream().forEach(contractSubjectMatterAddDTO -> { ContractSubjectMatter subjectMatter = BeanUtil.copyProperties(contractSubjectMatterAddDTO, ContractSubjectMatter.class); subjectMatter.setContractId(contract.getId()); @@ -1668,7 +1695,7 @@ } if (ArrayUtil.isNotEmpty(addDTO.getContractPaymentSchedule())) { if (CollUtil.isNotEmpty(addDTO.getContractPaymentSchedule())) { AtomicInteger index = new AtomicInteger(1); addDTO.getContractPaymentSchedule().stream().forEach(contractPaymentScheduleAddDTO -> { int currentIndex = index.getAndIncrement(); @@ -1711,10 +1738,10 @@ @Override public R updateContractSgb(ContractUpdateDTO updateDTO) { if (ArrayUtil.isEmpty(updateDTO.getContractSubjectMatter())) { if (CollUtil.isEmpty(updateDTO.getContractSubjectMatter())) { return R.failed("请添加标的物"); } if (ArrayUtil.isEmpty(updateDTO.getContractPaymentSchedule())) { if (CollUtil.isEmpty(updateDTO.getContractPaymentSchedule())) { return R.failed("请添加付款阶段或付款阶段缺少"); } if (!isValidPaymentStages(updateDTO.getContractPaymentSchedule())) { @@ -1747,7 +1774,7 @@ } baseMapper.updateById(contract); if (ArrayUtil.isNotEmpty(updateDTO.getContractSubjectMatter())) { if (CollUtil.isNotEmpty(updateDTO.getContractSubjectMatter())) { contractSubjectMatterMapper.delete(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId, contract.getId())); updateDTO.getContractSubjectMatter().stream().forEach(contractSubjectMatterAddDTO -> { @@ -1773,7 +1800,7 @@ }); } if (ArrayUtil.isNotEmpty(updateDTO.getContractPaymentSchedule())) { if (CollUtil.isNotEmpty(updateDTO.getContractPaymentSchedule())) { contractPaymentScheduleMapper.delete(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId())); AtomicInteger index = new AtomicInteger(1); @@ -1966,21 +1993,21 @@ @Override public Page fourAssociation(Page page, ContractQueryDTO queryDTO) { Page<FourAssociationPageVo> page1 = baseMapper.fourAssociation(page, queryDTO, DataScope.of("comp_id")); if (ArrayUtil.isNotEmpty(page1.getRecords())) { if (CollUtil.isNotEmpty(page1.getRecords())) { page1.getRecords().stream().forEach(fourAssociationPageVo -> { List<PaymentSlip> slips = paymentSlipMapper.selectList(Wrappers.<PaymentSlip>lambdaQuery().eq(PaymentSlip::getContractId, fourAssociationPageVo.getId()) .orderByAsc(PaymentSlip::getPaymentTime)); if (ArrayUtil.isNotEmpty(slips)) { if (CollUtil.isNotEmpty(slips)) { fourAssociationPageVo.setSlipVoList(BeanUtil.copyToList(slips, ContractSlipVo.class)); } List<ContractInvoice> invoices = contractInvoiceMapper.selectList(Wrappers.<ContractInvoice>lambdaQuery().eq(ContractInvoice::getContractId, fourAssociationPageVo.getId()) .orderByAsc(ContractInvoice::getInvoiceTime)); if (ArrayUtil.isNotEmpty(invoices)) { if (CollUtil.isNotEmpty(invoices)) { fourAssociationPageVo.setInvoiceVoList(BeanUtil.copyToList(invoices, ContractInvoiceVo.class)); } if (fourAssociationPageVo.getAmount().compareTo(fourAssociationPageVo.getPaidAmount()) == 0 && fourAssociationPageVo.getAmount().compareTo(fourAssociationPageVo.getBillingAmout()) == 0 && ArrayUtil.isNotEmpty(slips) && ArrayUtil.isNotEmpty(invoices) CollUtil.isNotEmpty(slips) && CollUtil.isNotEmpty(invoices) ) { fourAssociationPageVo.setAssociation("已完成"); } @@ -2535,4 +2562,48 @@ } return R.ok(); } @Override public R subjectChange(ContractSubjectChangeDTO changeDTO) { Contract contract = baseMapper.selectById(changeDTO.getId()); if (ObjUtil.isNull(contract)){ return R.failed("合同状态异常"); } if (contract.getBillingAmout().compareTo(new BigDecimal("0"))>0){ return R.failed("合同已开票,不能进行变更"); } if (ObjUtil.isNotNull(contract.getOutBoundAmout())&&contract.getOutBoundAmout().compareTo(new BigDecimal("0"))>0){ return R.failed("合同标的物已出库,不能进行变更"); } if (CollUtil.isEmpty(changeDTO.getContractSubjectMatter())){ return R.failed("合同变更后标的物不能为空"); } BigDecimal changeAmount = changeDTO.getContractSubjectMatter().stream().map(subject->subject.getUnitPrice().multiply(subject.getQuantity())).reduce(BigDecimal.ZERO,BigDecimal::add); if (contract.getAmount().compareTo(changeAmount)!=0){ return R.failed("合同变更后标的物总价必须与合同总价一致"); } List<ContractSubjectMatter> beforeList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId,changeDTO.getId())); ContractSubjectMatterChange change = new ContractSubjectMatterChange(); change.setContractId(contract.getId()); change.setBeforeChange(JSONObject.toJSONString(beforeList)); change.setAfterChange(JSONObject.toJSONString(changeDTO.getContractSubjectMatter())); changeMapper.insert(change); contractSubjectMatterMapper.delete(Wrappers.<ContractSubjectMatter>lambdaQuery().eq(ContractSubjectMatter::getContractId,changeDTO.getId())); changeDTO.getContractSubjectMatter().stream().forEach(contractSubjectMatterAddDTO -> { ContractSubjectMatter subjectMatter = BeanUtil.copyProperties(contractSubjectMatterAddDTO, ContractSubjectMatter.class); subjectMatter.setContractId(contract.getId()); subjectMatter.setLineNo(ItemGeneratorUtil.nextId()); subjectMatter.setDeliveredQuantity(new BigDecimal("0")); subjectMatter.setDeliveryStatus(0); subjectMatter.setTotalAmount(contractSubjectMatterAddDTO.getQuantity().multiply(contractSubjectMatterAddDTO.getUnitPrice())); contractSubjectMatterMapper.insert(subjectMatter); }); return R.ok(); } @Override public Page subjectChangePage(Page page, ContracQueryDTO queryDTO) { return changeMapper.subjectChangePage(page,queryDTO,DataScope.of("comp_id")); } } platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/MeterReadRecordServiceImpl.java
@@ -1,7 +1,7 @@ package com.by4cloud.platformx.business.service.impl; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -143,7 +143,7 @@ List<MeterReadRecord> recordList = baseMapper.selectList(Wrappers.<MeterReadRecord>lambdaQuery() .eq(MeterReadRecord::getContractId,contract.getId()) .isNull(MeterReadRecord::getMeterReadNum)); if (ArrayUtil.isEmpty(execDateList)&&ArrayUtil.isEmpty(recordList)){ if (CollUtil.isEmpty(execDateList)&& CollUtil.isEmpty(recordList)){ List<PaymentConfirm> confirmList = paymentConfirmMapper.selectList(Wrappers.<PaymentConfirm>lambdaQuery() .eq(PaymentConfirm::getContractId, contract.getId()) .and(wrapper -> wrapper @@ -153,7 +153,7 @@ .or() .eq(PaymentConfirm::getBusinessType, "不征税自来水应收") )); if (ArrayUtil.isNotEmpty(confirmList)){ if (CollUtil.isNotEmpty(confirmList)){ BigDecimal total = confirmList.stream().map(PaymentConfirm::getTransationAmount).filter(amount -> amount != null).reduce(BigDecimal.ZERO, BigDecimal::add); contract.setAmount(total); contractMapper.updateById(contract); platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/OutBoundServiceImpl.java
@@ -337,18 +337,6 @@ // beforeSchedule.setEffectiveEndDate(schedule.getEffectiveDate()); // scheduleMapper.updateById(beforeSchedule); // } //更新履约 ContractPaymentScheduleProcess contractPaymentScheduleProcess = new ContractPaymentScheduleProcess(); contractPaymentScheduleProcess.setContractId(schedule.getContractId()); contractPaymentScheduleProcess.setContractName(schedule.getContractName()); contractPaymentScheduleProcess.setScheduleId(schedule.getId()); contractPaymentScheduleProcess.setScheduleName(schedule.getStageName()); contractPaymentScheduleProcess.setProcessDate(addDTO.getOutBoundTime()); ContractPaymentScheduleProcess lastProcess = scheduleProcessMapper.selectOne(Wrappers.<ContractPaymentScheduleProcess>lambdaQuery().eq(ContractPaymentScheduleProcess::getContractId, schedule.getContractId()) .eq(ContractPaymentScheduleProcess::getScheduleId, schedule.getId()).last("limit 1")); if (ObjUtil.isNull(lastProcess)) { scheduleProcessMapper.insert(contractPaymentScheduleProcess); } } //查询是否有后续阶段 @@ -473,14 +461,15 @@ public R addContractOut(OutBoundAddDTO addDTO) { //校验参数 R<Contract> r = vailParam(addDTO); if (!r.isOk()){ if (!r.isOk()) { return r; } Contract contract = r.getData(); //出库 handleOutBound(contract,addDTO); handleOutBound(contract, addDTO); //保存资金明细 BigDecimal outBoundAmount = savePaymentConfirm(contract,addDTO); BigDecimal outBoundAmount = savePaymentConfirm(contract, addDTO); //更新合同状态及阶段 contract.setOutBoundAmout(outBoundAmount); updateContractSchedule(contract); @@ -492,35 +481,37 @@ List<ContractSubjectMatter> unComOutList = contractSubjectMatterMapper.selectList(Wrappers.<ContractSubjectMatter>lambdaQuery() .eq(ContractSubjectMatter::getContractId, contract.getId()) .ne(ContractSubjectMatter::getDeliveryStatus, 2)); if (CollUtil.isEmpty(unComOutList)){ if (CollUtil.isEmpty(unComOutList)) { contract.setNextScheduleName("货到签收"); } contract.setBillingStatus("2"); contractMapper.updateById(contract); } private BigDecimal savePaymentConfirm(Contract contract,OutBoundAddDTO addDTO) { private BigDecimal savePaymentConfirm(Contract contract, OutBoundAddDTO addDTO) { //查询合同是否有出库阶段 ContractPaymentSchedule schedule = scheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery().eq(ContractPaymentSchedule::getContractId, contract.getId()) .eq(ContractPaymentSchedule::getStageName, "发货前").gt(ContractPaymentSchedule::getPaymentRatio,0).last("limit 1")); if (ObjUtil.isNull(schedule.getEffectiveDate())&&ObjUtil.isNull(schedule.getEffectiveEndDate())){ .eq(ContractPaymentSchedule::getStageName, "发货前").last("limit 1")); if (ObjUtil.isNull(schedule.getEffectiveDate()) && ObjUtil.isNull(schedule.getEffectiveEndDate())) { schedule.setEffectiveDate(addDTO.getOutBoundTime()); schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(),schedule.getAgreedDays())); schedule.setEffectiveEndDate(DateUtil.offsetDay(addDTO.getOutBoundTime(), schedule.getAgreedDays())); scheduleMapper.updateById(schedule); } //履约几率 processService.saveScheduleProcess(addDTO.getOutBoundTime(),schedule); BigDecimal outAmount = new BigDecimal("0"); //计算出库价格 BigDecimal outAmount = new BigDecimal("0"); for (OutSubjectMatterAddDTO outSubjectMatterAddDTO : addDTO.getSubjectMatterList()) { ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() .eq(ContractSubjectMatter::getContractId, contract.getId()) .eq(ContractSubjectMatter::getMaterialCode, outSubjectMatterAddDTO.getSubjectMatterCode()) .eq(StrUtil.isNotBlank(outSubjectMatterAddDTO.getLineNo()),ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo()) .eq(StrUtil.isNotBlank(outSubjectMatterAddDTO.getLineNo()), ContractSubjectMatter::getLineNo, outSubjectMatterAddDTO.getLineNo()) .last("limit 1")); outAmount = outAmount.add(outSubjectMatterAddDTO.getOutBoundNum().multiply(subjectMatter.getUnitPrice())); } //存在发货前收款阶段 if (ObjUtil.isNotNull(schedule)) { if (schedule.getPaymentRatio().compareTo(new BigDecimal("0")) > 0) { //新增当前阶段应收 PaymentConfirm currentConfim = new PaymentConfirm(); currentConfim.setBusinessType(schedule.getStageName() + "应收"); @@ -533,7 +524,7 @@ currentConfim.setScheduleName(schedule.getStageName()); currentConfim.setConfirmTime(addDTO.getOutBoundTime()); //按出库比例计算应收 currentConfim.setTransationAmount(schedule.getPlannedAmount().multiply(outAmount.divide(contract.getAmount(),2,RoundingMode.HALF_UP))); currentConfim.setTransationAmount(schedule.getPlannedAmount().multiply(outAmount.divide(contract.getAmount(), 2, RoundingMode.HALF_UP))); currentConfim.setReceivableAmount(currentConfim.getTransationAmount()); PaymentConfirm lastConfirm = paymentConfirmMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); @@ -547,7 +538,7 @@ currentConfim.setTotalAmount(currentConfim.getTransationAmount().multiply(new BigDecimal("-1"))); paymentConfirmMapper.insert(currentConfim); //历史资金余额 processService.handleBeforeRemain(currentConfim,contract); processService.handleBeforeRemain(currentConfim, contract); } return outAmount; } @@ -581,7 +572,7 @@ contractSubjectMatterMapper.updateById(subjectMatter); //保存erp出库 String batchNumber = genBatchNumber(); Long outBoundId = saveErpOutBound(contract,addDTO,outSubjectMatterAddDTO,batchNumber); Long outBoundId = saveErpOutBound(contract, addDTO, outSubjectMatterAddDTO, batchNumber); //保存合同出库记录 saveContractOutBound(contract, addDTO, subjectMatter, outBoundId); }); @@ -607,7 +598,7 @@ return ""; } private Long saveErpOutBound(Contract contract, OutBoundAddDTO addDTO,OutSubjectMatterAddDTO outSubjectMatterAddDTO,String batchNumber) { private Long saveErpOutBound(Contract contract, OutBoundAddDTO addDTO, OutSubjectMatterAddDTO outSubjectMatterAddDTO, String batchNumber) { OutBound outBound = new OutBound(); outBound.setBatchNumber(batchNumber); outBound.setOutBoundNum(outSubjectMatterAddDTO.getOutBoundNum()); platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/PaymentConfirmServiceImpl.java
@@ -3,7 +3,6 @@ import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.HttpUtil; @@ -94,114 +93,76 @@ return R.failed("客商查询失败,请检查客商"); } PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); BigDecimal lastTotal = new BigDecimal("0"); if (ObjUtil.isNotNull(lastConfirm)) { lastTotal = lastConfirm.getTotalAmount(); } //转入 if (StrUtil.equals(addDTO.getInOrOut(), "1")) { //保存收款单 savePaymentSlip(addDTO,customer,contract); //保存收款单 savePaymentConfirm(addDTO,contract,customer); //处理收款 handleSlipToSchedule(addDTO,contract); //更新状态 updateContractStatus(addDTO,contract); } //转出 if (StrUtil.equals(addDTO.getInOrOut(), "2")) { return handleBackSlip(addDTO,contract,customer); } } //新增付款单 PaymentSlip slip = new PaymentSlip(); slip.setBusGuestId(customer.getId()); slip.setBusGuestName(customer.getCompanyName()); slip.setPayeeCompId(SecurityUtils.getUser().getCompId()); slip.setPaymentTime(addDTO.getConfirmTime()); slip.setPaymentAmount(addDTO.getTransationAmount()); slip.setPayType(addDTO.getPayType()); slip.setContractId(contract.getId()); paymentSlipMapper.insert(slip); return R.ok(); } BigDecimal newtotal = addDTO.getTransationAmount().add(lastTotal); PaymentConfirm entity = new PaymentConfirm(); entity.setContractId(contract.getId()); entity.setContractName(contract.getContractName()); entity.setContractNo(addDTO.getContractNo()); if (ObjUtil.isNotNull(lastConfirm)) { entity.setScheduleId(lastConfirm.getScheduleId()); entity.setScheduleName(lastConfirm.getScheduleName()); } entity.setBusGuestId(customer.getId()); entity.setBusGuestName(customer.getCompanyName()); entity.setBusinessType("客户付款"); if (newtotal.compareTo(new BigDecimal("0")) > 0) { entity.setTransationAmount(addDTO.getTransationAmount()); entity.setAdvanceAmount(newtotal); entity.setTotalAmount(newtotal); entity.setConfirmTime(new Date()); baseMapper.insert(entity); } else if (newtotal.compareTo(new BigDecimal("0")) == 0) { entity.setTransationAmount(addDTO.getTransationAmount()); entity.setTotalAmount(newtotal); entity.setConfirmTime(new Date()); baseMapper.insert(entity); } else { entity.setTransationAmount(addDTO.getTransationAmount()); entity.setReceivableAmount(newtotal.multiply(new BigDecimal("-1"))); entity.setTotalAmount(newtotal); entity.setConfirmTime(new Date()); baseMapper.insert(entity); } private R handleBackSlip(PaymentConfirmAddDTO addDTO,Contract contract,BusinessCustomer customer) { PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); PaymentConfirm entity = new PaymentConfirm(); entity.setContractId(contract.getId()); entity.setContractName(contract.getContractName()); entity.setContractNo(contract.getContractNo()); //更新付款阶段付款 List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2).ne(ContractPaymentSchedule::getPaymentStatus, 3) .orderByAsc(ContractPaymentSchedule::getCreateTime)); if (CollUtil.isNotEmpty(scheduleList)) { BigDecimal remain = addDTO.getTransationAmount(); for (ContractPaymentSchedule schedule : scheduleList) { BigDecimal lastRemain = remain; remain = remain.subtract(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount() : schedule.getPlannedAmount().subtract(schedule.getActualAmount())); if (remain.compareTo(new BigDecimal("0")) >= 0) { schedule.setActualAmount(schedule.getPlannedAmount()); schedule.setPaymentDate(addDTO.getConfirmTime()); schedule.setPaymentStatus(2); contractPaymentScheduleMapper.updateById(schedule); //查询是否有当前逾期 CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); if (ObjUtil.isNotNull(currentOverdue)) { //新增逾期历史 HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); historyOverdue.setPaymentTime(addDTO.getConfirmTime()); historyOverdue.setCompId(schedule.getCompId()); historyOverdueMapper.insert(historyOverdue); //删除当前逾期 currentOverdueMapper.deleteById(currentOverdue); } } else { schedule.setActualAmount(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount().add(remain) : schedule.getActualAmount().add(lastRemain)); schedule.setPaymentDate(addDTO.getConfirmTime()); schedule.setPaymentStatus(1); contractPaymentScheduleMapper.updateById(schedule); //查询是否有当前逾期 CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); if (ObjUtil.isNotNull(currentOverdue)) { //新增逾期历史 HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); historyOverdue.setReceivableAmount(lastRemain); historyOverdue.setPaymentTime(addDTO.getConfirmTime()); historyOverdue.setCompId(schedule.getCompId()); historyOverdueMapper.insert(historyOverdue); //更新当前逾期 currentOverdue.setReceivableAmount(schedule.getPlannedAmount().subtract(schedule.getActualAmount())); currentOverdueMapper.updateById(currentOverdue); } break; } } } } //非房屋租赁 水电 if (!StrUtil.equals(contract.getContractCategory(), "water_house")) { entity.setBusGuestId(customer.getId()); entity.setBusGuestName(customer.getCompanyName()); entity.setBusinessType("退款"); entity.setTransationAmount(addDTO.getTransationAmount()); BigDecimal newtotal = addDTO.getTransationAmount().multiply(new BigDecimal("-1")).add(lastConfirm.getTotalAmount()); if (newtotal.compareTo(new BigDecimal("0")) > 0) { entity.setAdvanceAmount(newtotal); entity.setTotalAmount(newtotal); } else if (newtotal.compareTo(new BigDecimal("0")) == 0) { entity.setTotalAmount(newtotal); } else { return R.failed("当前客户余额为" + lastConfirm.getTotalAmount() + "不足以满足当前发生金额,无法操作"); } entity.setConfirmTime(new Date()); baseMapper.insert(entity); contract.setPaidAmount(contract.getPaidAmount().subtract(addDTO.getTransationAmount())); contract.setContractStatus(2); contractService.updateById(contract); return R.ok(); } private void updateContractStatus(PaymentConfirmAddDTO addDTO,Contract contract) { //非房屋租赁 水电 if (!StrUtil.equals(contract.getContractCategory(), "water_house")) { //更新合同已付款 BigDecimal paid = new BigDecimal("0"); if (ObjUtil.isNotNull(contract.getPaidAmount())) { paid = contract.getPaidAmount(); } paid = paid.add(addDTO.getTransationAmount()); contract.setPaidAmount(paid); if (paid.compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0&&contract.getBillingAmout().compareTo(contract.getAmount())==0) { contract.setContractStatus(3); contract.setPaidAmount(contract.getAmount().subtract(contract.getDropAmount())); } contractService.updateById(contract); }else { List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery().eq(ContractExecDate::getContractId,contract.getId()) .eq(ContractExecDate::getGenFlag,"0")); if (CollUtil.isEmpty(execDateList)){ //更新合同已付款 BigDecimal paid = new BigDecimal("0"); if (ObjUtil.isNotNull(contract.getPaidAmount())) { @@ -209,275 +170,120 @@ } paid = paid.add(addDTO.getTransationAmount()); contract.setPaidAmount(paid); if (paid.compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0&&contract.getBillingAmout().compareTo(contract.getAmount())==0) { if (contract.getBillingAmout().compareTo(contract.getAmount())==0&&paid.compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0) { contract.setContractStatus(3); contract.setPaidAmount(contract.getAmount().subtract(contract.getDropAmount())); contract.setPaidAmount(contract.getAmount()); } contractService.updateById(contract); }else { List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery().eq(ContractExecDate::getContractId,contract.getId()) .eq(ContractExecDate::getGenFlag,"0")); if (CollUtil.isEmpty(execDateList)){ //更新合同已付款 BigDecimal paid = new BigDecimal("0"); if (ObjUtil.isNotNull(contract.getPaidAmount())) { paid = contract.getPaidAmount(); } paid = paid.add(addDTO.getTransationAmount()); contract.setPaidAmount(paid); if (contract.getBillingAmout().compareTo(contract.getAmount())==0&&paid.compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0) { contract.setContractStatus(3); contract.setPaidAmount(contract.getAmount()); } contractService.updateById(contract); } } //转出 if (StrUtil.equals(addDTO.getInOrOut(), "2")) { PaymentConfirm entity = new PaymentConfirm(); entity.setContractId(contract.getId()); entity.setContractName(contract.getContractName()); entity.setContractNo(addDTO.getContractNo()); entity.setBusGuestId(customer.getId()); entity.setBusGuestName(customer.getCompanyName()); entity.setBusinessType("退款"); entity.setTransationAmount(addDTO.getTransationAmount()); BigDecimal newtotal = addDTO.getTransationAmount().multiply(new BigDecimal("-1")).add(lastConfirm.getTotalAmount()); if (newtotal.compareTo(new BigDecimal("0")) > 0) { entity.setAdvanceAmount(newtotal); entity.setTotalAmount(newtotal); } else if (newtotal.compareTo(new BigDecimal("0")) == 0) { entity.setTotalAmount(newtotal); } else { return R.failed("当前客户余额为" + lastConfirm.getTotalAmount() + "不足以满足当前发生金额,无法操作"); } entity.setConfirmTime(new Date()); baseMapper.insert(entity); } } // else { // // List<Contract> customerContractList = contractService.list(Wrappers.<Contract>lambdaQuery().eq(Contract::getPartyAId, addDTO.getBusGuestId()) // .eq(Contract::getPartyBId, SecurityUtils.getUser().getCompId()).orderByAsc(Contract::getCreateTime) // .apply(" ((contract_category != 'water_house' and amount != paid_amount) or contract_category = 'water_house')")); // if (ArrayUtil.isEmpty(customerContractList)) { // return R.failed("为查询到未付款合同"); // } // BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery() // .eq(StrUtil.isNotBlank(addDTO.getBusGuestName()), BusinessCustomer::getRegisterName, addDTO.getBusGuestName()) // .eq(ObjUtil.isNotNull(addDTO.getBusGuestId()), BusinessCustomer::getId, addDTO.getBusGuestId()) // .last("limit 1")); // if (ObjUtil.isNull(customer)) { // return R.failed("客商查询失败"); // } // //新增付款单 // PaymentSlip slip = new PaymentSlip(); // slip.setBusGuestId(customer.getId()); // slip.setBusGuestName(customer.getRegisterName()); // slip.setPayeeCompId(SecurityUtils.getUser().getCompId()); // slip.setPaymentTime(addDTO.getConfirmTime()); // slip.setPaymentAmount(addDTO.getTransationAmount()); // slip.setPayType(addDTO.getPayType()); // paymentSlipMapper.insert(slip); // // BigDecimal transtionAmount = addDTO.getTransationAmount(); // //剩余付款 // BigDecimal transtionRemainAmount = transtionAmount; // //收到付款的合同 // List<Contract> payContractList = new ArrayList<>(); // //付款完成的合同 // List<Contract> payCompleteContractList = new ArrayList<>(); // //付款未完成的合同 // List<Contract> payNoCompleteContractList = new ArrayList<>(); // //有预付款的合同 // List<Contract> advanceContractList = new ArrayList<>(); // //付款时间 // Date payDate = addDTO.getConfirmTime(); // Iterator<Contract> iterator = customerContractList.iterator(); // while (iterator.hasNext()) { // Contract contract = iterator.next(); // PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) // .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); // BigDecimal lastTotal = new BigDecimal("0"); // if (ObjUtil.isNotNull(lastConfirm)) { // lastTotal = lastConfirm.getTotalAmount(); // } else { // // } // // //合同最近明细总额为0 或 > 0 情况下 // if (lastTotal.compareTo(new BigDecimal("0")) >= 0) { // log.info("当前合同号:{},明细总额无应收款", contract.getContractNo()); // advanceContractList.add(contract); // if (iterator.hasNext()) { // continue; // } // } // // transtionRemainAmount = transtionRemainAmount.add(lastTotal); // PaymentConfirm entity = new PaymentConfirm(); // entity.setContractId(contract.getId()); // entity.setContractName(contract.getContractName()); // entity.setContractNo(contract.getContractNo()); // if (ObjUtil.isNotNull(lastConfirm)) { // entity.setScheduleId(lastConfirm.getScheduleId()); // entity.setScheduleName(lastConfirm.getScheduleName()); // } // entity.setBusGuestId(customer.getId()); // entity.setBusGuestName(customer.getRegisterName()); // entity.setBusinessType("客户付款"); // if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) { // entity.setConfirmTime(payDate); // // 判断是否是最后一个 // if (!iterator.hasNext()) { // entity.setTransationAmount(transtionRemainAmount.subtract(lastTotal)); // entity.setAdvanceAmount(transtionRemainAmount); // entity.setTotalAmount(transtionRemainAmount); // } else { // entity.setTransationAmount(lastTotal.multiply(new BigDecimal("-1"))); // entity.setTotalAmount(new BigDecimal("0")); // } // baseMapper.insert(entity); // payContractList.add(contract); // } else if (transtionRemainAmount.compareTo(new BigDecimal("0")) == 0) { // entity.setTransationAmount(lastTotal.multiply(new BigDecimal("-1"))); // entity.setTotalAmount(new BigDecimal("0")); // entity.setConfirmTime(payDate); // baseMapper.insert(entity); // payContractList.add(contract); // break; // } else { // entity.setTransationAmount(transtionRemainAmount.subtract(lastTotal)); // entity.setReceivableAmount(transtionRemainAmount.multiply(new BigDecimal("-1"))); // entity.setTotalAmount(transtionRemainAmount); // entity.setConfirmTime(payDate); // baseMapper.insert(entity); // payContractList.add(contract); // break; // } // } // // payContractList.stream().forEach(contract -> { // //更新付款阶段付款 // List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() // .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2) // .ne(ContractPaymentSchedule::getPaymentStatus, 3) // .orderByAsc(ContractPaymentSchedule::getCreateTime)); // if (ArrayUtil.isNotEmpty(scheduleList)) { // BigDecimal remain = transtionAmount; // for (ContractPaymentSchedule schedule : scheduleList) { // BigDecimal lastRemain = remain; // remain = lastRemain.subtract(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount() : // schedule.getPlannedAmount().subtract(schedule.getActualAmount())); // if (remain.compareTo(new BigDecimal("0")) >= 0) { // schedule.setActualAmount(schedule.getPlannedAmount()); // schedule.setPaymentDate(payDate); // schedule.setPaymentStatus(2); // contractPaymentScheduleMapper.updateById(schedule); // //查询是否有当前逾期 // CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) // .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); // if (ObjUtil.isNotNull(currentOverdue)) { // //新增逾期历史 // HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); // historyOverdue.setPaymentTime(payDate); // historyOverdue.setCompId(schedule.getCompId()); // historyOverdueMapper.insert(historyOverdue); // //删除当前逾期 // currentOverdueMapper.deleteById(currentOverdue); // } // } else { // schedule.setActualAmount(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount().add(remain) : // schedule.getActualAmount().add(lastRemain)); // schedule.setPaymentDate(payDate); // schedule.setPaymentStatus(1); // contractPaymentScheduleMapper.updateById(schedule); // //查询是否有当前逾期 // CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) // .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); // if (ObjUtil.isNotNull(currentOverdue)) { // //新增逾期历史 // HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); // historyOverdue.setReceivableAmount(lastRemain); // historyOverdue.setPaymentTime(payDate); // historyOverdue.setCompId(schedule.getCompId()); // historyOverdueMapper.insert(historyOverdue); // //查询历史已付逾期金额 // List<HistoryOverdue> historyOverdueList = historyOverdueMapper.selectList(Wrappers.<HistoryOverdue>lambdaQuery().eq(HistoryOverdue::getScheduleId, currentOverdue.getScheduleId())); // BigDecimal hisTotal = historyOverdueList.stream().map(item -> item.getReceivableAmount()).reduce(BigDecimal.ZERO, BigDecimal::add); // //更新当前逾期 // currentOverdue.setReceivableAmount(schedule.getPlannedAmount().subtract(hisTotal)); // currentOverdueMapper.updateById(currentOverdue); // } // break; // } // } // } // //合同所有付款阶段 // List<ContractPaymentSchedule> payComScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() // .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 0) // .ne(ContractPaymentSchedule::getPaymentStatus, 3)); // if (ArrayUtil.isNotEmpty(payComScheduleList)) { // BigDecimal payTotal = payComScheduleList.stream().map(item -> StrUtil.equals(item.getPaymentStatus() + "", "2") ? item.getPlannedAmount() : // item.getActualAmount()).reduce(BigDecimal.ZERO, BigDecimal::add); // contract.setPaidAmount(payTotal); //// if (payComScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) { //// contract.setContractStatus(3); //// } // if (contract.getAmount().compareTo(contract.getPaidAmount()) == 0) { // // contract.setContractStatus(3); // payCompleteContractList.add(contract); // } // //付款 且 付款未全付 // if (contract.getAmount().compareTo(contract.getPaidAmount()) > 0) { // payNoCompleteContractList.add(contract); // } // if (StrUtil.isNotEmpty(contract.getContractCategory()) && StrUtil.equals(contract.getContractCategory(), "water_house")) { // List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery() // .eq(ContractExecDate::getContractId, contract.getId()).eq(ContractExecDate::getGenFlag, "0")); // if (ArrayUtil.isEmpty(execDateList)) { // List<ContractPaymentSchedule> contractPaymentScheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() // .eq(ContractPaymentSchedule::getContractId, contract.getId())); // if (ArrayUtil.isNotEmpty(contractPaymentScheduleList) && contractPaymentScheduleList.stream().allMatch(item -> Objects.equals(item.getPaymentStatus(), 2))) { // contract.setContractStatus(3); // contractService.updateById(contract); // } // } // } else { // contractService.updateById(contract); // } // // } // }); } //客户预付有剩余 且 有预付款的合同 // if (transtionRemainAmount.compareTo(new BigDecimal("0")) > 0) { // if (ArrayUtil.isNotEmpty(payNoCompleteContractList)){ // //余额 放到付款未完成合同 预收 // Contract lastContract = payNoCompleteContractList.get(0); // //保存明细 // saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate); // } // if (ArrayUtil.isEmpty(payNoCompleteContractList)&&ArrayUtil.isNotEmpty(advanceContractList)){ // //客户预付有剩余 没有预付款的合同 // Contract lastContract = advanceContractList.get(0); // //保存明细 // saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate); // } // if (ArrayUtil.isEmpty(payNoCompleteContractList)&&ArrayUtil.isEmpty(advanceContractList) // &&ArrayUtil.isNotEmpty(payCompleteContractList)) { // //客户预付有剩余 没有预付款的合同 // Contract lastContract = payCompleteContractList.get(payCompleteContractList.size() - 1); // //保存明细 // saveNewPaymentConfirm(customer,null,lastContract,transtionRemainAmount,payDate); // // } // } // } return R.ok(); private void handleSlipToSchedule(PaymentConfirmAddDTO addDTO,Contract contract) { //更新付款阶段付款 List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() .eq(ContractPaymentSchedule::getContractId, contract.getId()).ne(ContractPaymentSchedule::getPaymentStatus, 2).ne(ContractPaymentSchedule::getPaymentStatus, 3) .orderByAsc(ContractPaymentSchedule::getCreateTime)); if (CollUtil.isNotEmpty(scheduleList)) { BigDecimal remain = addDTO.getTransationAmount(); for (ContractPaymentSchedule schedule : scheduleList) { BigDecimal lastRemain = remain; remain = remain.subtract(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount() : schedule.getPlannedAmount().subtract(schedule.getActualAmount())); if (remain.compareTo(new BigDecimal("0")) >= 0) { schedule.setActualAmount(schedule.getPlannedAmount()); schedule.setPaymentDate(addDTO.getConfirmTime()); schedule.setPaymentStatus(2); contractPaymentScheduleMapper.updateById(schedule); //查询是否有当前逾期 CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); if (ObjUtil.isNotNull(currentOverdue)) { //新增逾期历史 HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); historyOverdue.setPaymentTime(addDTO.getConfirmTime()); historyOverdue.setCompId(schedule.getCompId()); historyOverdueMapper.insert(historyOverdue); //删除当前逾期 currentOverdueMapper.deleteById(currentOverdue); } } else { schedule.setActualAmount(StrUtil.equals(schedule.getPaymentStatus() + "", "0") ? schedule.getPlannedAmount().add(remain) : schedule.getActualAmount().add(lastRemain)); schedule.setPaymentDate(addDTO.getConfirmTime()); schedule.setPaymentStatus(1); contractPaymentScheduleMapper.updateById(schedule); //查询是否有当前逾期 CurrentOverdue currentOverdue = currentOverdueMapper.selectOne(Wrappers.<CurrentOverdue>lambdaQuery().eq(CurrentOverdue::getScheduleId, schedule.getId()) .eq(CurrentOverdue::getContractId, schedule.getContractId()).last("limit 1")); if (ObjUtil.isNotNull(currentOverdue)) { //新增逾期历史 HistoryOverdue historyOverdue = BeanUtil.copyProperties(currentOverdue, HistoryOverdue.class, "id"); historyOverdue.setReceivableAmount(lastRemain); historyOverdue.setPaymentTime(addDTO.getConfirmTime()); historyOverdue.setCompId(schedule.getCompId()); historyOverdueMapper.insert(historyOverdue); //更新当前逾期 currentOverdue.setReceivableAmount(schedule.getPlannedAmount().subtract(schedule.getActualAmount())); currentOverdueMapper.updateById(currentOverdue); } break; } } } } private void savePaymentConfirm(PaymentConfirmAddDTO addDTO,Contract contract,BusinessCustomer customer) { PaymentConfirm lastConfirm = baseMapper.selectOne(Wrappers.<PaymentConfirm>lambdaQuery().eq(PaymentConfirm::getContractId, contract.getId()) .orderByDesc(PaymentConfirm::getCreateTime).last("limit 1")); BigDecimal lastTotal = new BigDecimal("0"); if (ObjUtil.isNotNull(lastConfirm)) { lastTotal = lastConfirm.getTotalAmount(); } BigDecimal newtotal = addDTO.getTransationAmount().add(lastTotal); PaymentConfirm entity = new PaymentConfirm(); entity.setContractId(contract.getId()); entity.setContractName(contract.getContractName()); entity.setContractNo(addDTO.getContractNo()); if (ObjUtil.isNotNull(lastConfirm)) { entity.setScheduleId(lastConfirm.getScheduleId()); entity.setScheduleName(lastConfirm.getScheduleName()); } entity.setBusGuestId(customer.getId()); entity.setBusGuestName(customer.getCompanyName()); entity.setBusinessType("客户付款"); if (newtotal.compareTo(new BigDecimal("0")) > 0) { entity.setTransationAmount(addDTO.getTransationAmount()); entity.setAdvanceAmount(newtotal); entity.setTotalAmount(newtotal); entity.setConfirmTime(new Date()); baseMapper.insert(entity); } else if (newtotal.compareTo(new BigDecimal("0")) == 0) { entity.setTransationAmount(addDTO.getTransationAmount()); entity.setTotalAmount(newtotal); entity.setConfirmTime(new Date()); baseMapper.insert(entity); } else { entity.setTransationAmount(addDTO.getTransationAmount()); entity.setReceivableAmount(newtotal.multiply(new BigDecimal("-1"))); entity.setTotalAmount(newtotal); entity.setConfirmTime(new Date()); baseMapper.insert(entity); } } private void savePaymentSlip(PaymentConfirmAddDTO addDTO,BusinessCustomer customer,Contract contract) { //新增付款单 PaymentSlip slip = new PaymentSlip(); slip.setBusGuestId(customer.getId()); slip.setBusGuestName(customer.getCompanyName()); slip.setPayeeCompId(SecurityUtils.getUser().getCompId()); slip.setPaymentTime(addDTO.getConfirmTime()); slip.setPaymentAmount(addDTO.getTransationAmount()); slip.setPayType(addDTO.getPayType()); slip.setContractId(contract.getId()); paymentSlipMapper.insert(slip); } @Override @@ -515,6 +321,7 @@ }else { params.put("enddate", DateUtil.today()); } params.put("dc_flag","1");//1 借 2 贷 只查收款 //单据状态已审批 params.put("accentity_code", bipCode); String finalAccessToken = accessToken; @@ -601,27 +408,19 @@ return; } log.info("==================开始处理银行流水信息==================="); recordList.stream().forEach(record -> { savePaymentConfirm((JSONObject) record, dept); recordList.stream().forEach(obj -> { JSONObject record = (JSONObject) obj; BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery() .eq(BusinessCustomer::getCompanyName, record.getString("to_acct_name")) .eq(BusinessCustomer::getCompId,dept.getDeptId()) ); //保存付款单 Boolean codeFlag = saveBankStatement(customer, record,dept); if (!codeFlag) { log.error("付款单id:{},付款单已存在"); } }); log.info("==================结束处理银行流水信息==================="); } private void savePaymentConfirm(JSONObject record, SysDept dept) { BusinessCustomer customer = businessCustomerService.getOne(Wrappers.<BusinessCustomer>lambdaQuery() .eq(BusinessCustomer::getCompanyName, record.getString("to_acct_name")) .eq(BusinessCustomer::getCompId,dept.getDeptId()) ); //保存付款单 Boolean codeFlag = saveBankStatement(customer, record,dept); if (codeFlag) { log.error("付款单id:{},付款单已存在"); return; } } private Boolean saveBankStatement(BusinessCustomer customer, JSONObject record,SysDept dept) { @@ -634,6 +433,7 @@ bankStatement.setPayBankAccName(record.getString("to_acct_name")); bankStatement.setTranDate(DateUtil.parseDateTime(record.getString("tran_date"))); bankStatement.setTranAmount(record.getBigDecimal("tran_amt")); bankStatement.setDcFlag(record.getString("dc_flag")); bankStatement.setDataId(record.getLong("id")); bankStatement.setDataJson(record.toJSONString()); if (ObjUtil.isNotNull(customer)) { platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/TaxCodeServiceImpl.java
@@ -39,6 +39,7 @@ .selectAll(TaxCode.class) .selectAs("(select count(1) from tax_code t1 where t1.parent_bm = t.bm)",TaxCode::getChildNum) .like(StrUtil.isNotBlank(queryDTO.getMc()),TaxCode::getMc,queryDTO.getMc()) .like(StrUtil.isNotBlank(queryDTO.getJc()),TaxCode::getSphwjc,queryDTO.getJc()) .like(StrUtil.isNotBlank(queryDTO.getBm()),TaxCode::getBm,queryDTO.getBm()); if (ObjUtil.isNotNull(queryDTO.getChildNum())){ if (queryDTO.getChildNum()==0){ platformx-business-finance-biz/src/main/resources/mapper/BipDictMapper.xml
New file @@ -0,0 +1,19 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.by4cloud.platformx.business.mapper.BipDictMapper"> <resultMap id="bipDictMap" type="com.by4cloud.platformx.business.entity.BipDict"> <id property="id" column="id"/> <result property="compId" column="comp_id"/> <result property="dictCode" column="dict_code"/> <result property="dictKey" column="dict_key"/> <result property="dictName" column="dict_name"/> <result property="parentId" column="parent_id"/> <result property="createBy" column="create_by"/> <result property="createTime" column="create_time"/> <result property="updateBy" column="update_by"/> <result property="updateTime" column="update_time"/> <result property="delFlag" column="del_flag"/> </resultMap> </mapper> platformx-business-finance-biz/src/main/resources/mapper/ContractInvoiceMapper.xml
@@ -454,6 +454,7 @@ t.comp_id, t1.contract_no, t2.company_name AS busGuestName, t.bw_request_result, t1.party_b FROM contract_invoice t @@ -467,6 +468,9 @@ <if test="queryDTO.invoiceCategory !=null and queryDTO.invoiceCategory !=''"> AND t.invoice_category = #{queryDTO.invoiceCategory} </if> <if test="queryDTO.bwRequestResult !=null and queryDTO.bwRequestResult !=''"> AND t.bw_request_result = #{queryDTO.bwRequestResult} </if> <if test="queryDTO.contractNo !=null and queryDTO.contractNo !=''"> AND t1.contract_no LIKE CONCAT('%', #{queryDTO.contractNo}, '%') </if> platformx-business-finance-biz/src/main/resources/mapper/ContractSubjectMatterChangeMapper.xml
New file @@ -0,0 +1,76 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.by4cloud.platformx.business.mapper.ContractSubjectMatterChangeMapper"> <resultMap id="contractSubjectMatterMap" type="com.by4cloud.platformx.business.entity.ContractSubjectMatterChange"> <id property="id" column="id"/> <result property="compId" column="comp_id"/> <result property="attachmentName" column="attachment_name"/> <result property="attachmentUrl" column="attachment_url"/> <result property="beforeChange" column="before_change"/> <result property="afterChange" column="after_change"/> <result property="contractId" column="contract_id"/> <result property="createBy" column="create_by"/> <result property="createTime" column="create_time"/> <result property="updateBy" column="update_by"/> <result property="updateTime" column="update_time"/> <result property="delFlag" column="del_flag"/> </resultMap> <select id="subjectChangePage" resultType="com.by4cloud.platformx.business.vo.ContractPageVo"> SELECT c.id, c.contract_no, c.contract_name, c.party_a_id, c.party_a, c.party_b_id, c.party_b, c.amount, c.contract_type, c.supply_attribute, c.contract_status, c.contract_attribute, c.sign_date, c.sign_place, c.effective_date, c.delivery_cycle, c.expiration_date, c.attachment_url, c.remark, c.parent_id, c.approve_time, c.arrival_schedule_id, c.accept_schedule_id, c.billing_status, c.billing_amout, c.template_id, c.sales_model, c.paid_amount, c.contract_category, c.exec_frequency, c.next_schedule_name, c.warranty_schedule_id, c.comp_id, c.center_push_flag, csmc.before_change, csmc.after_change FROM contract_subject_matter_change csmc left join contract c on csmc.contract_id = c.id WHERE c.del_flag = '0' AND csmc.del_flag = '0' <if test="queryDTO.contractName !=null and queryDTO.contractName !=''"> AND contract_name LIKE CONCAT('%', #{queryDTO.contractName}, '%') </if> <if test="queryDTO.contractNo !=null and queryDTO.contractNo !=''"> AND contract_no LIKE CONCAT('%', #{queryDTO.contractNo}, '%') </if> <if test="queryDTO.partyA !=null and queryDTO.partyA !=''"> AND party_a LIKE CONCAT('%', #{queryDTO.partyA}, '%') </if> order by csmc.create_time desc </select> </mapper> platformx-business-finance-biz/src/main/resources/mapper/ProductMapper.xml
@@ -46,7 +46,7 @@ <select id="getProductListByParentId" resultType="com.by4cloud.platformx.business.vo.ProductSelectVo"> SELECT t.id, t.product_name, CONCAT(t.product_name,IFNULL(t.product_type,'')) product_name, t.main_code, t.erp_code, t.product_type, @@ -91,7 +91,7 @@ <select id="getProductSMJListByParentId" resultType="com.by4cloud.platformx.business.vo.ProductSelectVo"> SELECT t.id, t.product_name, CONCAT(t.product_name,IFNULL(t.product_type,'')) product_name, t.main_code, t.erp_code, t.product_type,