package com.by4cloud.platformx.business.service.impl;
|
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.http.HttpUtil;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
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.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 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;
|
/**
|
* 银行流水
|
*
|
* @author syt
|
* @date 2026-08-07 16:10:36
|
*/
|
@Slf4j
|
@Service
|
@RequiredArgsConstructor
|
public class BankStatementServiceImpl extends ServiceImpl<BankStatementMapper, BankStatement> implements BankStatementService {
|
|
private final PaymentConfirmService paymentConfirmService;
|
private final ContractMapper contractMapper;
|
private final BusinessCustomerMapper businessCustomerMapper;
|
private final StringRedisTemplate redisTemplate;
|
|
@Value("${bip.url}")
|
private String url;
|
|
@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("合同查询失败");
|
}
|
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);
|
|
//bip推送
|
pushSaveCollection(statement);
|
return R.ok();
|
}
|
|
private void pushSaveCollection(BankStatement statement) {
|
String accessToken = "";
|
if (redisTemplate.hasKey("BIP_TOKEN")) {
|
accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN");
|
} else {
|
paymentConfirmService.getAccessToken(accessToken);
|
}
|
if (StrUtil.isEmpty(accessToken)) {
|
log.error("bip accessToken 获取异常");
|
return;
|
}
|
String finalAccessToken = accessToken;
|
JSONObject params = genRequestParam(statement);
|
|
log.info("收款单集成 Request:{}", params.toJSONString());
|
String result = HttpUtil.post(url + "/yonbip/EFI/receivable/save?access_token=" + finalAccessToken, params.toJSONString());
|
log.info("收款单集成 Response:{}", result);
|
|
}
|
|
private JSONObject genRequestParam(BankStatement statement) {
|
BusinessCustomer customer = businessCustomerMapper.selectById(statement.getBusGuestId());
|
Contract contract = contractMapper.selectById(statement.getContractId());
|
JSONObject req = 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("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("_status","Insert");
|
data.put("oriTaxIncludedAmount",statement.getTranAmount());
|
|
req.put("data",data);
|
return req;
|
|
}
|
}
|