From ca019747743a76f9348fcac99385c91736a36638 Mon Sep 17 00:00:00 2001
From: shiyunteng <shiyunteng@example.com>
Date: 星期四, 17 九月 2026 16:44:15 +0800
Subject: [PATCH] feat:标的物变更 合同审核流程改为推送合同中心通过后上传盖章签字件 履约进度新增合同补录按钮
---
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/BankStatementServiceImpl.java | 645 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 588 insertions(+), 57 deletions(-)
diff --git a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/BankStatementServiceImpl.java b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/BankStatementServiceImpl.java
index 15acf79..a6f7d64 100644
--- a/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/BankStatementServiceImpl.java
+++ b/platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/service/impl/BankStatementServiceImpl.java
@@ -1,28 +1,50 @@
package com.by4cloud.platformx.business.service.impl;
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.IdUtil;
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.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.BipQueryDTO;
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.entity.*;
+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.ReceiveBipVo;
+import com.by4cloud.platformx.business.vo.ReceiveItemVo;
+import com.by4cloud.platformx.business.vo.StatementContractVo;
import com.by4cloud.platformx.common.core.util.R;
+import com.by4cloud.platformx.common.data.datascope.DataScope;
+import com.by4cloud.platformx.common.security.util.SecurityUtils;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
/**
* 閾惰娴佹按
*
@@ -38,96 +60,605 @@
private final ContractMapper contractMapper;
private final BusinessCustomerMapper businessCustomerMapper;
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) {
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("璇烽�夋嫨鏀舵鍚堝悓鍚庡湪鎻愪氦");
}
- 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;
+ 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.setContractId(updateDTO.getContractId());
+
+ statement.setConfirmAmount(statement.getConfirmAmount().add(toPaidTotal));
baseMapper.updateById(statement);
- //bip鎺ㄩ��
- pushSaveCollection(statement);
+ updateDTO.getContractCollectionList().stream().forEach(statementContractDTO -> {
+ Contract contract = contractMapper.selectById(statementContractDTO.getId());
+ R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId());
+ SysDept b = r.getData();
+ BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
+ BankStatementItem item = new BankStatementItem();
+ item.setStatetId(statement.getId());
+ item.setBankSeqNo(statement.getBankSeqNo());
+ item.setConfirmAmount(statementContractDTO.getToPaidAmount());
+ item.setContractId(statementContractDTO.getId());
+ ReceiveBipVo bipVo = tranBipVo(statement, item, b, customer);
+ item.setBipParam(JSONObject.toJSONString(bipVo));
+ bankStatementItemMapper.insert(item);
+ PaymentConfirmAddDTO addDTO = new PaymentConfirmAddDTO();
+ addDTO.setBusGuestId(statement.getBusGuestId() + "");
+ addDTO.setConfirmTime(statement.getTranDate());
+ addDTO.setContractNo(contract.getContractNo());
+ 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)) {
+ pushCollectionSgb(statement, updateDTO.getContractCollectionList());
+ }
+
+
return R.ok();
}
- private void pushSaveCollection(BankStatement statement) {
+ private void pushCollectionSgb(BankStatement statement, List<StatementContractDTO> contractCollectionList) {
+ JSONObject request = genErpParam(statement, contractCollectionList);
+ statement.setPushParam(request.toJSONString());
+ log.info("宸ヤ笟娉垫敹娆惧湴鍧�:{}", sgbErp + "/apilink/arclose/create?corpsecret=12345678&appserver=appserver1&accountid=888&tradeid=" + IdUtil.fastUUID());
+
+// HttpResponse resp = HttpUtil.createPost(sgbErp + "/apilink/arclose/create?corpsecret=12345678&appserver=appserver1&accountid=888&tradeid="
+// + IdUtil.fastUUID())
+// .form("",request.toJSONString())
+// .timeout(30000)
+// // 鎸囧畾缂栫爜鏍煎紡
+// .charset(StandardCharsets.UTF_8)
+// .execute();
+
+ log.info("宸ヤ笟娉垫敹娆惧叆鍙�:{}", "=" + request.toJSONString());
+ OkHttpClient client = new OkHttpClient().newBuilder()
+ .build();
+ MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
+ RequestBody body = RequestBody.create(mediaType, "=" + request.toJSONString());
+ Request req = new Request.Builder()
+ .url(sgbErp + "/apilink/arclose/create?corpsecret=12345678&appserver=appserver1&accountid=888&tradeid=" + IdUtil.fastUUID())
+ .method("POST", body)
+ .addHeader("Content-Type", "application/x-www-form-urlencoded")
+ .build();
+ String result = "";
+ try (Response response = client.newCall(req).execute()) {
+ if (response.isSuccessful()) {
+ // 浠呰皟鐢ㄤ竴娆tring()锛岀粨鏋滃瓨鍏ュ彉閲忓鐢紝鍚庣画鎵�鏈夐�昏緫鐩存帴璇诲彇璇ュ彉閲�
+ result = response.body().string();
+ // 涓氬姟閫昏緫鐩存帴浣跨敤result锛岀姝㈠啀娆¤皟鐢╮esponse.body().string()
+ }
+ log.info("宸ヤ笟娉垫敹娆惧洖鍙傦細{}", result);
+ saveErpRequestRecord("sgb", "/apilink/arclose/create", request.toJSONString(), result);
+ JSONObject respJson = JSONObject.parseObject(result);
+ if (respJson.containsKey("errcode") && respJson.getString("errcode").equals("0")) {
+ statement.setPushFlag(1);
+ statement.setPushVouchNo(respJson.getString("code"));
+ baseMapper.updateById(statement);
+ return;
+ }
+ log.error("宸ヤ笟娉垫敹娆炬帹閫佸け璐ワ細{}", response.body().string());
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ 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, List<StatementContractDTO> contractCollectionList) {
+ JSONObject req = new JSONObject();
+ Map<String, Object> djt = new LinkedHashMap<>();
+ Contract contract = contractMapper.selectById(contractCollectionList.get(0).getId());
+ BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
+ djt.put("dVouchDate", DateUtil.formatDate(statement.getTranDate()));//鍗曟嵁鏃ユ湡
+ if (ObjUtil.isNotNull(customer)) {
+ djt.put("cDwCode", customer.getErpCompanyCode());//鍗曚綅缂栫爜
+ }
+ djt.put("cexch_name", "浜烘皯甯�");//鍗曚綅缂栫爜
+ djt.put("cOperator", "10123");//褰曞叆浜虹紪鐮�
+ djt.put("cSSCode", "01");//褰曞叆浜虹紪鐮�
+ djt.put("iAmount", statement.getConfirmAmount());//浜烘皯甯侀噾棰�
+ djt.put("cBankAccount", statement.getReceiveBankAccAcc());//鏈柟閾惰璐﹀彿
+ djt.put("cBank", statement.getPayBankAccName());//鏈柟閾惰璐﹀彿
+ djt.put("cContractType", "161");
+ if (CollUtil.size(contractCollectionList) == 1) {
+ Contract contractHeader = contractMapper.selectById(contractCollectionList.get(0).getId());
+ djt.put("cContractID", contractHeader.getErpContractNo());
+ }
+ req.put("鍗曟嵁澶�", djt);
+ JSONObject line = new JSONObject();
+ JSONArray array = new JSONArray();
+
+ contractCollectionList.stream().forEach(statementContractDTO -> {
+ JSONObject djti = new JSONObject();
+ djti.put("cCusVen", customer.getErpCompanyCode());//寰�鏉ュ崟浣嶇紪鐮�
+ djti.put("iAmt_f", statementContractDTO.getToPaidAmount());//鏈鏈竵閲戦
+ djti.put("iAmt", statementContractDTO.getToPaidAmount());//鏈鏈竵閲戦
+ djti.put("cPersonCode", "00164");//涓氬姟鍛樼紪鐮�
+ djti.put("cConID", contract.getErpContractNo());//鍚堝悓缂栫爜
+ djti.put("娆鹃」绫诲瀷", "搴旀敹娆�");
+ djti.put("cConType", "闀囨睙甯�");
+ array.add(djti);
+ });
+
+ line.put("琛�", array);
+ req.put("鍗曟嵁浣�", line);
+ JSONObject apicontext = new JSONObject();
+ apicontext.put("username", "");
+ req.put("apicontext", apicontext);
+ return req;
+ }
+
+ private R pushSaveCollection(BankStatement statement, BankStatementItem bankStatementItem) {
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;
+ return R.failed("bip accessToken 鑾峰彇寮傚父");
}
String finalAccessToken = accessToken;
- JSONObject params = genRequestParam(statement);
+
+ R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId());
+ log.info("鏌ヨ鍗曚綅淇℃伅:{}", JSONObject.toJSONString(r.getData()));
+ if (!r.isOk()) {
+ log.error("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ return R.failed("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ }
+ SysDept dept = r.getData();
+ JSONObject params = genRequestParam(statement, dept, bankStatementItem);
log.info("鏀舵鍗曢泦鎴� Request:{}", params.toJSONString());
- String result = HttpUtil.post(url + "/yonbip/EFI/receivable/save?access_token=" + finalAccessToken, params.toJSONString());
+ String result = HttpUtil.post(url + "/yonbip/EFI/collection/saveandsubmit?access_token=" + finalAccessToken, params.toJSONString());
log.info("鏀舵鍗曢泦鎴� Response:{}", result);
+ JSONObject resultJson = JSONObject.parseObject(result);
+ if (!resultJson.getString("code").equals("200")) {
+ return R.failed(resultJson.getString("message"));
+ }
+ bankStatementItem.setBipPush("1");
+ bankStatementItem.setBipId(resultJson.getJSONObject("data").getLong("id"));
+ bankStatementItemMapper.updateById(bankStatementItem);
+ return R.ok();
}
- 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, BankStatementItem statementItem) {
+ Contract contract = contractMapper.selectById(statementItem.getContractId());
+ BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
+ ReceiveBipVo bipVo = BeanUtil.copyProperties(JSONObject.parseObject(statementItem.getBipParam()), ReceiveBipVo.class);
+ JSONObject jsonObject = new JSONObject();
JSONObject data = new JSONObject();
+ 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.getBipCode());//瀹㈡埛缂栫爜
+ data.put("financeOrgCode", dept.getBipCode());//寮�绁ㄧ粍缁囩紪鐮�
+ data.put("orgCode", dept.getBipCode());//涓氬姟缁勭粐缂栫爜
+ data.put("bustypeCode", "ar_colsale");// TODO 浜ゆ槗绫诲瀷缂栫爜 鏆備及榛樿ZGYSFP锛岃澶囬粯璁BYXGLXT鏆傛椂涓嶈兘鐢�
+ data.put("oriCurrencyCode", "CNY");//甯佺
+ data.put("srcBillType", "38");
+ data.put("srcBillNo", statement.getBankSeqNo());
+ data.put("_status", "Insert");
+ JSONArray bodyItem = new JSONArray();
+
+ JSONObject item = new JSONObject();
+ item.put("oriTaxIncludedAmount", statementItem.getConfirmAmount());
+ item.put("contractNo", contract.getContractNo());
+ item.put("quickTypeCode", "1");
+ item.put("_status", "Insert");
+
+ item.put("expenseItemCode", bipVo.getItemList().get(0).getJjsx());//缁忔祹浜嬮」
+ item.put("remarks", bipVo.getItemList().get(0).getZy());//鎽樿
+ JSONObject freeChId = new JSONObject();
+ freeChId.put("GX08", bipVo.getItemList().get(0).getHsdy());//鏍哥畻鍗曞厓
+ freeChId.put("YSYF14", "1");//娆鹃」绫诲瀷 1 棰勬敹娆� 2 搴旀敹娆�
+ freeChId.put("JT04", bipVo.getItemList().get(0).getHsjylx());//鏍哥畻浜ゆ槗绫诲瀷 0101 闆嗗洟澶栭儴 01020301 涓夌骇鍒嗗瓙鍏徃闂� 01020302 涓夌骇鍒嗗叕鍙镐笌瀛愬瓙鍏徃涔嬮棿
+ freeChId.put("JT06", bipVo.getItemList().get(0).getKxmx());//娆鹃」鏄庣粏
+ freeChId.put("JT12", bipVo.getItemList().get(0).getCpwlfl());//浜у搧鐗╂枡鍒嗙被
+
+ item.put("freeChId", freeChId);
- JSONObject freeCh = new JSONObject();
- freeCh.put("YSYF57","MJHYXGLXT");
+ bodyItem.add(item);
+ data.put("bodyItem", bodyItem);
+ JSONObject datafreeChId = new JSONObject();
+ datafreeChId.put("YSYF_SFZY", bipVo.getSfzy());//鏄惁涓昏惀
+ datafreeChId.put("fk_038", bipVo.getPzzdr());//鍑瘉鍒跺崟浜�
+ datafreeChId.put("YSYF_08", bipVo.getSfnbwl());//鏄惁鍐呴儴寰�鏉�
+ datafreeChId.put("YSYF24", bipVo.getSfjyjs());//鏄惁绠�鏄撹绋�
+ datafreeChId.put("fk_002", bipVo.getFjzs());//闄勪欢1
+ datafreeChId.put("GX08", bipVo.getHsdy());//鏍哥畻鍗曞厓
+ datafreeChId.put("TzMY042", contract.getExpirationDate());//棰勮鍥炴鏃ユ湡
+ data.put("freeChId", datafreeChId);
+ data.put("remarks", bipVo.getZy());//鎽樿
+ jsonObject.put("data", data);
+ return jsonObject;
+ }
- 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());
+ @Override
+ public R getHistoryById(Long id) {
+ MPJLambdaWrapper<BankStatementItem> wrapper = new MPJLambdaWrapper<BankStatementItem>()
+ .selectAll(BankStatementItem.class)
+ .select(Contract::getContractNo)
+ .select(Contract::getPartyA)
+ .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));
+ }
- JSONArray bodyItems = new JSONArray();
+ @Override
+ public R delHistoryById(Long id) {
- JSONObject bodyItem = new JSONObject();
- bodyItem.put("srcBillType","38");
- bodyItem.put("srcBillNo",statement.getBankSeqNo());
+ BankStatementItem statement = bankStatementItemMapper.selectById(id);
+ BankStatement bankStatement = baseMapper.selectById(statement.getStatetId());
+ Contract contract = contractMapper.selectById(statement.getContractId());
+ if (ObjUtil.isNull(contract)) {
+ return R.failed("鍚堝悓淇℃伅寮傚父");
+ }
+ BusinessCustomer customer = businessCustomerMapper.selectById(contract.getPartyAId());
+ if (ObjUtil.isNull(customer)) {
+ return R.failed("瀹㈡埛淇℃伅淇℃伅寮傚父");
+ }
+ R<SysDept> r = remoteDeptService.getById(contract.getPartyBId());
+ if (!r.isOk()) {
+ return r;
+ }
+ //bip鎺ㄩ��
+ if (bipFlag) {
+ String accessToken = "";
+ if (redisTemplate.hasKey("BIP_TOKEN")) {
+ accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN");
+ } else {
+ accessToken = paymentConfirmService.getAccessToken(accessToken);
+ }
+ if (StrUtil.isEmpty(accessToken)) {
+ log.error("bip accessToken 鑾峰彇寮傚父");
+ return R.failed("bip accessToken 鑾峰彇寮傚父");
+ }
+ String finalAccessToken = accessToken;
+ JSONObject request = genRefundParam(bankStatement, statement, contract, customer, r.getData());
+ log.info("鏀舵閫�娆惧崟-閫�娆惧崟涓�鍘嗗彶纭璇锋眰鍏ュ弬锛歿}", request.toJSONString());
+ String result = HttpUtil.post(url + "/yonbip/EFI/arRefund/saveandsubmit?access_token=" + finalAccessToken, request.toJSONString());
+ log.info("鏀舵閫�娆惧崟-閫�娆惧崟涓�鍘嗗彶纭璇锋眰鍥炲弬:{}", result);
+ JSONObject resultJson = JSONObject.parseObject(result);
+ if (!resultJson.getString("code").equals("200")) {
+ return R.failed(resultJson.getString("message"));
+ }
+ }
+ bankStatementItemMapper.deleteById(id);
- JSONObject freeChItem = new JSONObject();
- freeChItem.put("YSZJX01A","涓氬姟璧勯噾棰勭畻椤圭洰");
- freeChItem.put("YSZJX05","");
- freeChItem.put("YSZJX11","2146820445301112836");
- freeChItem.put("zzbkfl","");
- bodyItem.put("freeChId",freeChItem);
+ bankStatement.setConfirmAmount(bankStatement.getConfirmAmount().subtract(statement.getConfirmAmount()));
+ baseMapper.updateById(bankStatement);
+ return R.ok();
+ }
- bodyItems.add(bodyItem);
- data.put("bodyItem",bodyItems);
+ private JSONObject genRefundParam(BankStatement bankStatement, BankStatementItem statement, Contract contract, BusinessCustomer customer, SysDept dept) {
+ JSONObject jsonObject = new JSONObject();
+ JSONObject data = new JSONObject();
+ data.put("billDate", DateUtil.now());
+ data.put("exchangeRate", "1");//姹囩巼
+ data.put("exchangeRateDate", DateUtil.now());//姹囩巼鏃堕棿
+ data.put("objectType", "1");
+ data.put("customerCode", customer.getBipCode());//瀹㈡埛缂栫爜
+ data.put("financeOrgCode", dept.getBipCode());//寮�绁ㄧ粍缁囩紪鐮�
+ data.put("orgCode", dept.getBipCode());//涓氬姟缁勭粐缂栫爜
+ data.put("bustypeCode", "ar_refsale");//浜ゆ槗绫诲瀷缂栫爜 鏆備及榛樿ZGYSFP锛岄攢鍞粯璁JHYXGLXT
+ data.put("oriCurrencyCode", "CNY");//甯佺
+ data.put("srcBillType", "38");
+ data.put("srcBillNo", bankStatement.getBankSeqNo());
+ data.put("_status", "Insert");
+ JSONArray bodyItem = new JSONArray();
+ JSONObject item = new JSONObject();
+ item.put("oriTaxIncludedAmount", statement.getConfirmAmount());
+ 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;
+ }
- data.put("_status","Insert");
- data.put("oriTaxIncludedAmount",statement.getTranAmount());
+ @Override
+ public R backBal(Long id) {
+ BankStatement bankStatement = baseMapper.selectById(id);
+ BusinessCustomer customer = businessCustomerMapper.selectById(bankStatement.getBusGuestId());
+ if (ObjUtil.isNull(customer) || StrUtil.isEmpty(customer.getBipCode())) {
+ log.error("鏌ヨ瀹㈡埛淇℃伅寮傚父");
+ return R.failed("鏌ヨ瀹㈡埛淇℃伅寮傚父");
+ }
+ R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId());
+ if (!r.isOk()) {
+ log.error("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ return R.failed("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ }
+ SysDept dept = r.getData();
+ List<BankStatementItem> items = bankStatementItemMapper.selectList(Wrappers.<BankStatementItem>lambdaQuery()
+ .eq(BankStatementItem::getStatetId, id));
+ if (bipFlag) {
+ String accessToken = "";
+ if (redisTemplate.hasKey("BIP_TOKEN")) {
+ accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN");
+ } else {
+ accessToken = paymentConfirmService.getAccessToken(accessToken);
+ }
+ if (StrUtil.isEmpty(accessToken)) {
+ log.error("bip accessToken 鑾峰彇寮傚父");
+ return R.failed("bip accessToken 鑾峰彇寮傚父");
+ }
+ String finalAccessToken = accessToken;
+ JSONObject request = genBackBalParam(bankStatement, customer, dept, items);
+ log.info("鏀舵閫�娆惧崟-閫�娆句綑棰濊姹傚叆鍙傦細{}", request.toJSONString());
+ String result = HttpUtil.post(url + "/yonbip/EFI/arRefund/saveandsubmit?access_token=" + finalAccessToken, request.toJSONString());
+ log.info("鏀舵閫�娆惧崟-閫�娆句綑棰濊姹傚洖鍙�:{}", result);
+ JSONObject resultJson = JSONObject.parseObject(result);
+ if (!resultJson.getString("code").equals("200")) {
+ return R.failed(resultJson.getString("message"));
+ }
+ }
+ bankStatement.setTranAmount(bankStatement.getConfirmAmount());
+ baseMapper.updateById(bankStatement);
+ return R.ok();
+ }
- req.put("data",data);
- return req;
+ private JSONObject genBackBalParam(BankStatement bankStatement, BusinessCustomer customer, SysDept dept, List<BankStatementItem> items) {
+ JSONObject jsonObject = new JSONObject();
+ JSONObject data = new JSONObject();
+ data.put("billDate", DateUtil.now());
+ data.put("exchangeRate", "1");//姹囩巼
+ data.put("exchangeRateDate", DateUtil.now());//姹囩巼鏃堕棿
+ data.put("objectType", "1");
+ data.put("customerCode", customer.getBipCode());//瀹㈡埛缂栫爜
+ data.put("financeOrgCode", dept.getBipCode());//寮�绁ㄧ粍缁囩紪鐮�
+ data.put("orgCode", dept.getBipCode());//涓氬姟缁勭粐缂栫爜
+ data.put("bustypeCode", "ar_refsale");//浜ゆ槗绫诲瀷缂栫爜 鏆備及榛樿ZGYSFP锛岄攢鍞粯璁JHYXGLXT
+ data.put("oriCurrencyCode", "CNY");//甯佺
+ data.put("srcBillType", "38");
+ data.put("srcBillNo", bankStatement.getBankSeqNo());
+ data.put("_status", "Insert");
+ JSONArray bodyItem = new JSONArray();
+ JSONObject item = new JSONObject();
+ item.put("oriTaxIncludedAmount", bankStatement.getTranAmount().subtract(bankStatement.getConfirmAmount()));
+ item.put("quickTypeCode", "1");
+ item.put("_status", "Insert");
+ bodyItem.add(item);
+ data.put("bodyItem", bodyItem);
+ jsonObject.put("data", data);
+ return jsonObject;
+ }
+ @Override
+ public R backAll(Long id) {
+ BankStatement bankStatement = baseMapper.selectById(id);
+ BusinessCustomer customer = businessCustomerMapper.selectById(bankStatement.getBusGuestId());
+ if (ObjUtil.isNull(customer) || StrUtil.isEmpty(customer.getBipCode())) {
+ log.error("鏌ヨ瀹㈡埛淇℃伅寮傚父");
+ return R.failed("鏌ヨ瀹㈡埛淇℃伅寮傚父");
+ }
+ R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId());
+ if (!r.isOk()) {
+ log.error("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ return R.failed("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ }
+ SysDept dept = r.getData();
+ List<BankStatementItem> items = bankStatementItemMapper.selectList(Wrappers.<BankStatementItem>lambdaQuery()
+ .eq(BankStatementItem::getStatetId, id));
+ if (bipFlag) {
+ String accessToken = "";
+ if (redisTemplate.hasKey("BIP_TOKEN")) {
+ accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN");
+ } else {
+ accessToken = paymentConfirmService.getAccessToken(accessToken);
+ }
+ if (StrUtil.isEmpty(accessToken)) {
+ log.error("bip accessToken 鑾峰彇寮傚父");
+ return R.failed("bip accessToken 鑾峰彇寮傚父");
+ }
+ String finalAccessToken = accessToken;
+ JSONObject request = genBackAllParam(bankStatement, customer, dept, items);
+ log.info("鏀舵閫�娆惧崟-閫�娆炬墍鏈夎姹傚叆鍙傦細{}", request.toJSONString());
+ String result = HttpUtil.post(url + "/yonbip/EFI/arRefund/saveandsubmit?access_token=" + finalAccessToken, request.toJSONString());
+ log.info("鏀舵閫�娆惧崟-閫�娆炬墍鏈夎姹傚洖鍙�:{}", result);
+ JSONObject resultJson = JSONObject.parseObject(result);
+ if (!resultJson.getString("code").equals("200")) {
+ return R.failed(resultJson.getString("message"));
+ }
+ }
+ bankStatement.setConfirmAmount(new BigDecimal("0"));
+ baseMapper.updateById(bankStatement);
+ return R.ok();
+ }
+
+ private JSONObject genBackAllParam(BankStatement bankStatement, BusinessCustomer customer, SysDept dept, List<BankStatementItem> items) {
+ JSONObject jsonObject = new JSONObject();
+ JSONObject data = new JSONObject();
+ data.put("billDate", DateUtil.now());
+ data.put("exchangeRate", "1");//姹囩巼
+ data.put("exchangeRateDate", DateUtil.now());//姹囩巼鏃堕棿
+ data.put("objectType", "1");
+ data.put("customerCode", customer.getBipCode());//瀹㈡埛缂栫爜
+ data.put("financeOrgCode", dept.getBipCode());//寮�绁ㄧ粍缁囩紪鐮�
+ data.put("orgCode", dept.getBipCode());//涓氬姟缁勭粐缂栫爜
+ data.put("bustypeCode", "ar_refsale");//浜ゆ槗绫诲瀷缂栫爜 鏆備及榛樿ZGYSFP锛岄攢鍞粯璁JHYXGLXT
+ data.put("oriCurrencyCode", "CNY");//甯佺
+ data.put("srcBillType", "38");
+ data.put("srcBillNo", bankStatement.getBankSeqNo());
+ data.put("_status", "Insert");
+ JSONArray bodyItem = new JSONArray();
+ JSONObject item = new JSONObject();
+ item.put("oriTaxIncludedAmount", bankStatement.getTranAmount());
+ item.put("quickTypeCode", "1");
+ item.put("_status", "Insert");
+ bodyItem.add(item);
+ data.put("bodyItem", bodyItem);
+ jsonObject.put("data", data);
+ return jsonObject;
+ }
+
+ @Override
+ public R backHis(Long id) {
+ BankStatement bankStatement = baseMapper.selectById(id);
+ BusinessCustomer customer = businessCustomerMapper.selectById(bankStatement.getBusGuestId());
+ if (ObjUtil.isNull(customer) || StrUtil.isEmpty(customer.getBipCode())) {
+ log.error("鏌ヨ瀹㈡埛淇℃伅寮傚父");
+ return R.failed("鏌ヨ瀹㈡埛淇℃伅寮傚父");
+ }
+ R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId());
+ if (!r.isOk()) {
+ log.error("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ return R.failed("鏌ヨ鍗曚綅淇℃伅寮傚父");
+ }
+ SysDept dept = r.getData();
+ List<BankStatementItem> items = bankStatementItemMapper.selectList(Wrappers.<BankStatementItem>lambdaQuery()
+ .eq(BankStatementItem::getStatetId, id));
+ if (bipFlag) {
+ String accessToken = "";
+ if (redisTemplate.hasKey("BIP_TOKEN")) {
+ accessToken = (String) redisTemplate.opsForValue().get("BIP_TOKEN");
+ } else {
+ accessToken = paymentConfirmService.getAccessToken(accessToken);
+ }
+ if (StrUtil.isEmpty(accessToken)) {
+ log.error("bip accessToken 鑾峰彇寮傚父");
+ return R.failed("bip accessToken 鑾峰彇寮傚父");
+ }
+ String finalAccessToken = accessToken;
+ JSONObject request = genBackHisParam(bankStatement, customer, dept, items);
+ log.info("鏀舵閫�娆惧崟-閫�娆惧巻鍙茬‘璁よ姹傚叆鍙傦細{}", request.toJSONString());
+ String result = HttpUtil.post(url + "/yonbip/EFI/arRefund/saveandsubmit?access_token=" + finalAccessToken, request.toJSONString());
+ log.info("鏀舵閫�娆惧崟-閫�娆惧巻鍙茬‘璁よ姹傚洖鍙�:{}", result);
+ JSONObject resultJson = JSONObject.parseObject(result);
+ if (!resultJson.getString("code").equals("200")) {
+ return R.failed(resultJson.getString("message"));
+ }
+ }
+
+ bankStatement.setConfirmAmount(new BigDecimal("0"));
+ baseMapper.updateById(bankStatement);
+ bankStatementItemMapper.deleteByIds(items.stream().map(item -> item.getId()).collect(Collectors.toList()));
+ return R.ok();
+ }
+
+ private JSONObject genBackHisParam(BankStatement bankStatement, BusinessCustomer customer, SysDept dept, List<BankStatementItem> items) {
+ JSONObject jsonObject = new JSONObject();
+ JSONObject data = new JSONObject();
+ data.put("billDate", DateUtil.now());
+ data.put("exchangeRate", "1");//姹囩巼
+ data.put("exchangeRateDate", DateUtil.now());//姹囩巼鏃堕棿
+ data.put("objectType", "1");
+ data.put("customerCode", customer.getBipCode());//瀹㈡埛缂栫爜
+ data.put("financeOrgCode", dept.getBipCode());//寮�绁ㄧ粍缁囩紪鐮�
+ data.put("orgCode", dept.getBipCode());//涓氬姟缁勭粐缂栫爜
+ data.put("bustypeCode", "ar_refsale");//浜ゆ槗绫诲瀷缂栫爜 鏆備及榛樿ZGYSFP锛岄攢鍞粯璁JHYXGLXT
+ data.put("oriCurrencyCode", "CNY");//甯佺
+ data.put("srcBillType", "38");
+ data.put("srcBillNo", bankStatement.getBankSeqNo());
+ data.put("_status", "Insert");
+ JSONArray bodyItem = new JSONArray();
+ for (BankStatementItem statementItem : items) {
+ Contract contract = contractMapper.selectById(statementItem.getContractId());
+ JSONObject item = new JSONObject();
+ item.put("oriTaxIncludedAmount", statementItem.getConfirmAmount());
+ 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;
+ }
+
+ private ReceiveBipVo tranBipVo(BankStatement statement, BankStatementItem bankStatementItem, SysDept b, BusinessCustomer customer) {
+ ReceiveBipVo bipVo = new ReceiveBipVo();
+ bipVo.setDjrq(DateUtil.formatDate(statement.getTranDate()));
+ bipVo.setKpzz(b.getBipCode());
+ bipVo.setYwzz(b.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("0");
+ bipVo.setSfzy("1");
+ bipVo.setSfnbwl("1");
+ bipVo.setSfjyjs("0");
+ bipVo.setDjfx("1");
+ List<ReceiveItemVo> list = new ArrayList<>();
+ ReceiveItemVo itemVo = new ReceiveItemVo();
+ itemVo.setConfirmAmount(bankStatementItem.getConfirmAmount());
+ list.add(itemVo);
+ bipVo.setItemList(list);
+ return bipVo;
+ }
+
+ @Override
+ public Page pageBip(Page page, BipQueryDTO queryDTO) {
+ return baseMapper.pageBip(page, queryDTO, DataScope.of("comp_id"));
+ }
+
+ @Override
+ public R saveAndPush(BankStatementUpdateDTO updateDTO) {
+ BankStatementItem item = bankStatementItemMapper.selectById(updateDTO.getId());
+ item.setBipParam(updateDTO.getBipParam());
+ bankStatementItemMapper.updateById(item);
+ BankStatement statement = baseMapper.selectById(item.getStatetId());
+
+ //鍒ゆ柇鏄惁鍐呴儴鍗曚綅
+ CustInfoVo custInfoVo = bipViewMapper.selectBaseInfoByCustName(statement.getPayBankAccName());
+ if (ObjUtil.isNotNull(custInfoVo) && custInfoVo.getCustCode().equals("01")) {
+ log.info("鍐呴儴寰�鏉ユ敹娆惧崟锛屽鎴峰悕绉帮細{},瀹㈡埛绫诲瀷锛歿},涓嶇敤淇濆瓨鏀舵鍗�", custInfoVo.getCustName(), custInfoVo.getCustclass());
+ return R.failed("鍐呴儴寰�鏉ユ敹娆惧崟,涓嶇敤鎺ㄩ�丅IP");
+ }
+
+ return pushSaveCollection(statement, item);
}
}
\ No newline at end of file
--
Gitblit v1.9.1