| | |
| | | package com.by4cloud.platformx.business.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.by4cloud.platformx.admin.api.entity.SysDept; |
| | | import com.by4cloud.platformx.admin.api.feign.RemoteDeptService; |
| | | import com.by4cloud.platformx.business.dto.BankStatementUpdateDTO; |
| | | import com.by4cloud.platformx.business.dto.PaymentConfirmAddDTO; |
| | | import com.by4cloud.platformx.business.entity.BankStatement; |
| | | import com.by4cloud.platformx.business.entity.BusinessCustomer; |
| | | import com.by4cloud.platformx.business.entity.Contract; |
| | | 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.service.BankStatementService; |
| | | import com.by4cloud.platformx.business.service.PaymentConfirmService; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import com.by4cloud.platformx.common.security.util.SecurityUtils; |
| | | import lombok.RequiredArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 银行流水 |
| | | * |
| | |
| | | private final ContractMapper contractMapper; |
| | | private final BusinessCustomerMapper businessCustomerMapper; |
| | | private final StringRedisTemplate redisTemplate; |
| | | private final RemoteDeptService remoteDeptService; |
| | | private final BankStatementItemMapper bankStatementItemMapper; |
| | | |
| | | @Value("${bip.url}") |
| | | private String url; |
| | | |
| | | @Value("${BWInvoice.flag}") |
| | | private Boolean bwFlag; |
| | | |
| | | @Override |
| | | public R edit(BankStatementUpdateDTO updateDTO) { |
| | | BankStatement statement = baseMapper.selectById(updateDTO.getId()); |
| | | Contract contract = contractMapper.selectById(updateDTO.getContractId()); |
| | | if (ObjUtil.isNull(contract)){ |
| | | return R.failed("合同查询失败"); |
| | | if (CollUtil.isEmpty(updateDTO.getContractCollectionList())){ |
| | | return R.failed("请选择收款合同后在提交"); |
| | | } |
| | | 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("确认收款总额不能超过交易流水金额"); |
| | | } |
| | | statement.setConfirmAmount(statement.getConfirmAmount().add(toPaidTotal)); |
| | | baseMapper.updateById(statement); |
| | | |
| | | updateDTO.getContractCollectionList().stream().forEach(statementContractDTO -> { |
| | | BankStatementItem item = new BankStatementItem(); |
| | | item.setStatetId(statement.getId()); |
| | | item.setBankSeqNo(statement.getBankSeqNo()); |
| | | item.setConfirmAmount(statementContractDTO.getToPaidAmount()); |
| | | item.setContractId(statementContractDTO.getId()); |
| | | bankStatementItemMapper.insert(item); |
| | | |
| | | Contract contract = contractMapper.selectById(statementContractDTO.getId()); |
| | | PaymentConfirmAddDTO addDTO = new PaymentConfirmAddDTO(); |
| | | addDTO.setBusGuestId(statement.getBusGuestId()+""); |
| | | addDTO.setConfirmTime(statement.getTranDate()); |
| | | addDTO.setContractNo(contract.getContractNo()); |
| | | addDTO.setInOrOut("1"); |
| | | addDTO.setTransationAmount(statement.getTranAmount()); |
| | | R r = paymentConfirmService.add(addDTO); |
| | | if (!r.isOk()){ |
| | | return r; |
| | | } |
| | | statement.setContractId(updateDTO.getContractId()); |
| | | baseMapper.updateById(statement); |
| | | addDTO.setTransationAmount(statementContractDTO.getToPaidAmount()); |
| | | addDTO.setBankSeqNo(statement.getBankSeqNo()); |
| | | paymentConfirmService.add(addDTO); |
| | | }); |
| | | |
| | | |
| | | |
| | | //bip推送 |
| | | pushSaveCollection(statement); |
| | | if (bwFlag) { |
| | | pushSaveCollection(statement, updateDTO.getContractCollectionList()); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private void pushSaveCollection(BankStatement statement) { |
| | | private void pushSaveCollection(BankStatement statement, List<StatementContractDTO> contractDTOList) { |
| | | String accessToken = ""; |
| | | if (redisTemplate.hasKey("BIP_TOKEN")) { |
| | | accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN"); |
| | | } else { |
| | | paymentConfirmService.getAccessToken(accessToken); |
| | | accessToken = paymentConfirmService.getAccessToken(accessToken); |
| | | } |
| | | if (StrUtil.isEmpty(accessToken)) { |
| | | log.error("bip accessToken 获取异常"); |
| | | return; |
| | | } |
| | | String finalAccessToken = accessToken; |
| | | JSONObject params = genRequestParam(statement); |
| | | |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(statement.getBusGuestId()); |
| | | if (ObjUtil.isNull(customer)||StrUtil.isEmpty(customer.getBipCode())){ |
| | | log.error("查询客户信息异常"); |
| | | return; |
| | | } |
| | | R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId()); |
| | | if (!r.isOk()){ |
| | | log.error("查询单位信息异常"); |
| | | return; |
| | | } |
| | | SysDept dept = r.getData(); |
| | | JSONObject params = genRequestParam(statement,dept,customer,contractDTOList); |
| | | |
| | | log.info("收款单集成 Request:{}", params.toJSONString()); |
| | | String result = HttpUtil.post(url + "/yonbip/EFI/receivable/save?access_token=" + finalAccessToken, params.toJSONString()); |
| | |
| | | |
| | | } |
| | | |
| | | private JSONObject genRequestParam(BankStatement statement) { |
| | | BusinessCustomer customer = businessCustomerMapper.selectById(statement.getBusGuestId()); |
| | | Contract contract = contractMapper.selectById(statement.getContractId()); |
| | | JSONObject req = new JSONObject(); |
| | | |
| | | private JSONObject genRequestParam(BankStatement statement,SysDept dept,BusinessCustomer customer,List<StatementContractDTO> contractDTOList) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | JSONObject data = new JSONObject(); |
| | | |
| | | |
| | | JSONObject freeCh = new JSONObject(); |
| | | freeCh.put("YSYF57","MJHYXGLXT"); |
| | | |
| | | data.put("freeChId",freeCh); |
| | | data.put("extVouchCode",statement.getBankSeqNo()); |
| | | data.put("billDate",statement.getTranDate()); |
| | | data.put("billDate",DateUtil.format(statement.getTranDate(), DatePattern.NORM_DATETIME_FORMAT)); |
| | | data.put("exchangeRate","1");//汇率 |
| | | data.put("exchangeRateDate",DateUtil.now());//汇率时间 |
| | | data.put("objectType","1"); |
| | | data.put("customerCode",customer.getCreditCode()); |
| | | data.put("exchangeRate",1); |
| | | data.put("exchangeRateDate", DateUtil.now()); |
| | | data.put("contractNo",contract.getContractNo()); |
| | | |
| | | JSONArray bodyItems = new JSONArray(); |
| | | |
| | | JSONObject bodyItem = new JSONObject(); |
| | | bodyItem.put("srcBillType","38"); |
| | | bodyItem.put("srcBillNo",statement.getBankSeqNo()); |
| | | |
| | | JSONObject freeChItem = new JSONObject(); |
| | | freeChItem.put("YSZJX01A","业务资金预算项目"); |
| | | freeChItem.put("YSZJX05",""); |
| | | freeChItem.put("YSZJX11","2146820445301112836"); |
| | | freeChItem.put("zzbkfl",""); |
| | | bodyItem.put("freeChId",freeChItem); |
| | | |
| | | bodyItems.add(bodyItem); |
| | | data.put("bodyItem",bodyItems); |
| | | |
| | | data.put("customerCode",customer.getBipCode());//客户编码 |
| | | data.put("financeOrgCode",dept.getBipCode());//开票组织编码 |
| | | data.put("orgCode",dept.getBipCode());//业务组织编码 |
| | | data.put("bustypeCode","");//交易类型编码 暂估默认ZGYSFP,销售默认MJHYXGLXT |
| | | data.put("oriCurrencyCode","CNY");//币种 |
| | | data.put("_status","Insert"); |
| | | data.put("oriTaxIncludedAmount",statement.getTranAmount()); |
| | | |
| | | req.put("data",data); |
| | | return req; |
| | | |
| | | JSONArray bodyItem = new JSONArray(); |
| | | for (StatementContractDTO statementContractDTO:contractDTOList) { |
| | | Contract contract = contractMapper.selectById(statementContractDTO.getId()); |
| | | JSONObject item = new JSONObject(); |
| | | item.put("oriTaxIncludedAmount", statementContractDTO.getToPaidAmount()); |
| | | item.put("contractNo", contract.getContractNo()); |
| | | item.put("quickTypeCode", "1"); |
| | | item.put("_status", "Insert"); |
| | | bodyItem.add(item); |
| | | } |
| | | data.put("bodyItem",bodyItem); |
| | | jsonObject.put("data",data); |
| | | return jsonObject; |
| | | } |
| | | } |