|
@@ -0,0 +1,621 @@
|
|
|
+package com.bz.smart_city.service.checking.impl;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.bz.smart_city.commom.util.HttpRequest;
|
|
|
+import com.bz.smart_city.commom.util.Util;
|
|
|
+import com.bz.smart_city.dao.pay.*;
|
|
|
+import com.bz.smart_city.dto.pay.PayAgenttransactionDto;
|
|
|
+import com.bz.smart_city.dto.pay.PayCustomRechargeDto;
|
|
|
+import com.bz.smart_city.dto.pay.PaySysDictSelectDto;
|
|
|
+import com.bz.smart_city.dto.pay.PayTransactiondetails;
|
|
|
+import com.bz.smart_city.dto.pay.payfee.*;
|
|
|
+import com.bz.smart_city.entity.pay.*;
|
|
|
+import com.bz.smart_city.service.checking.PayFeeCheckingService;
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Iterator;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Author wangli
|
|
|
+ * 2020-04-15 16:45
|
|
|
+ * @Description 缴费
|
|
|
+ * @Version 1.0
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Log4j2
|
|
|
+public class PayFeeCheckingImpl implements PayFeeCheckingService {
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PayFeeMapper payFeeMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PayTransactiondetailsMapper payTransactiondetailsMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PaySysDictMapper sysDictMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PayAgenttransactionMapper payAgenttransactionMapper;
|
|
|
+ @Resource
|
|
|
+ private PayCheckbalanceMapper payCheckbalanceMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PayPayReceivedMapper payPayReceivedMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PayControlRecordMapper payControlRecordMapper;
|
|
|
+
|
|
|
+ @Value("${Sync.Data.Url}")
|
|
|
+ private String payValveCommondUrl;
|
|
|
+
|
|
|
+ public PayPayAgentbranch selectPayAgentbranchInfo(String code, Integer customerId){
|
|
|
+ return payFeeMapper.selectPayAgentbranchInfo(code,customerId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 银行代缴充值
|
|
|
+ * @param payPayAgentbranch
|
|
|
+ * @param orderCode
|
|
|
+ * @param accountNumber
|
|
|
+ * @param money
|
|
|
+ * @param payTime
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public BankPayfeeMsg payfeeByBank(PayPayAgentbranch payPayAgentbranch , String orderCode, String accountNumber, BigDecimal money, String payTime ){
|
|
|
+ //如果传入时间则用传入的时间做交易时间
|
|
|
+ LocalDateTime localDateTime;
|
|
|
+ try{
|
|
|
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
+ localDateTime= LocalDateTime.parse(payTime, dateTimeFormatter);
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ return new BankPayfeeMsg("0001","时间格式异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer customerId=payPayAgentbranch.getCustomerId();
|
|
|
+ Integer siteId=payPayAgentbranch.getSiteId();
|
|
|
+ //计费系统需要有客户站点信息
|
|
|
+ if(siteId ==null || customerId == null ){
|
|
|
+ return new BankPayfeeMsg("0005","系统信息配置异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal payfee = money;
|
|
|
+ //实收金额不可为负数
|
|
|
+ if (money.compareTo(BigDecimal.ZERO) == -1){
|
|
|
+ return new BankPayfeeMsg("2002","小于最小缴费金额");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ //根据客编获取客户信息
|
|
|
+ PayCustomRechargeDto payCustomRechargeDto = payFeeMapper.getCustomInfoByMeterOrAccount(null,accountNumber,null,BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
|
|
|
+ if(payCustomRechargeDto == null ){
|
|
|
+ //获取客户信息失败
|
|
|
+ return new BankPayfeeMsg("1001","查询的号码不合法或不存在");
|
|
|
+ }
|
|
|
+ //查询欠费信息
|
|
|
+ List<PayReceivable> payReceivableList =payFeeMapper.getReceivable(siteId,customerId,payCustomRechargeDto.getAccountId(),null);
|
|
|
+
|
|
|
+ //支付方式
|
|
|
+ List<PaySysDictSelectDto> payways = sysDictMapper.getDicts("支付方式",BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
|
|
|
+ if(payways.size() == 0){
|
|
|
+ return new BankPayfeeMsg("0005","系统信息配置异常");
|
|
|
+ }
|
|
|
+ String paywayName = payways.stream().filter(item -> item.getValue().equals("3")).findFirst().get().getLabel();
|
|
|
+
|
|
|
+// Map<String,PaySysDictSelectDto> paywayMap = payways.stream().collect(Collectors.toMap(PaySysDictSelectDto::getValue, PaySysDictSelectDto->PaySysDictSelectDto));
|
|
|
+ //收费类型
|
|
|
+ List<PaySysDictSelectDto> feetypes = sysDictMapper.getDicts("收费类型",BigInteger.valueOf(siteId),BigInteger.valueOf(customerId));
|
|
|
+ if(payways.size() == 0) {
|
|
|
+ return new BankPayfeeMsg("0005","系统信息配置异常");
|
|
|
+ }
|
|
|
+ Map<String, PaySysDictSelectDto> feetypeMap = feetypes.stream().collect(Collectors.toMap(PaySysDictSelectDto::getValue, PaySysDictSelectDto -> PaySysDictSelectDto));
|
|
|
+
|
|
|
+ //生成批次号
|
|
|
+ // 微信:W 现金、预存账户:C 银行:B 支付宝:A
|
|
|
+ String payseriesno= Util.getBatchNo("B",payCustomRechargeDto.getAccountnumber());
|
|
|
+ //获取账期
|
|
|
+ BaseClosingAccountInfo baseClosingAccountInfo=payFeeMapper.getLastClosingAccount(siteId,customerId);
|
|
|
+ if(baseClosingAccountInfo == null){
|
|
|
+ //获取账期信息失败、
|
|
|
+ return new BankPayfeeMsg("0005","系统信息配置异常");
|
|
|
+ }
|
|
|
+ int month =baseClosingAccountInfo.getMonth();
|
|
|
+ int year =baseClosingAccountInfo.getYear();
|
|
|
+
|
|
|
+ if(payReceivableList.size() == 0 ){ //没有应收信息走仅充值
|
|
|
+ //余额
|
|
|
+ BigDecimal remaining = payCustomRechargeDto.getRemaining();
|
|
|
+ BigDecimal balance = payCustomRechargeDto.getBalance();
|
|
|
+ //生成交易明细
|
|
|
+ PayTransactiondetails payTransactiondetails = getPayTransactiondetails(3, paywayName, localDateTime, payCustomRechargeDto, payseriesno, month, year, payfee, siteId, customerId, 1);
|
|
|
+ payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "充值");
|
|
|
+ payTransactiondetails.setTranstype(1);
|
|
|
+ payTransactiondetails.setTranstypeLabel("充值");
|
|
|
+ payTransactiondetails.setRemaining(remaining);//交易前账户余额
|
|
|
+ remaining = remaining.add(payfee);
|
|
|
+ if(balance != null){
|
|
|
+ balance = balance.add(payfee);
|
|
|
+ }
|
|
|
+ payTransactiondetails.setLastrecreamaing(remaining);//交易后账户余额
|
|
|
+ payTransactiondetailsMapper.insert(payTransactiondetails);
|
|
|
+ //修改预存账户
|
|
|
+ payFeeMapper.updateRechargeaccount(balance,remaining, BigInteger.valueOf(1), localDateTime, payCustomRechargeDto.getRechargeId());
|
|
|
+ //更新客户状态
|
|
|
+ payFeeMapper.updateAccountState(payCustomRechargeDto.getAccountId());
|
|
|
+
|
|
|
+ }else{
|
|
|
+ BigDecimal debts=BigDecimal.ZERO;
|
|
|
+ for(PayReceivable payReceivable: payReceivableList){
|
|
|
+ debts=debts.add(payReceivable.getDebt());
|
|
|
+ }
|
|
|
+ //预存+实收<欠费 金额不足
|
|
|
+ if(payCustomRechargeDto.getRemaining().add(payfee).compareTo(debts) == -1){
|
|
|
+ return new BankPayfeeMsg("2002","小于最小缴费金额");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //余额
|
|
|
+ BigDecimal remaining = payCustomRechargeDto.getRemaining();
|
|
|
+ BigDecimal balance = payCustomRechargeDto.getBalance();
|
|
|
+ //用作明细记录交易前余额
|
|
|
+ BigDecimal oldRemaining = payCustomRechargeDto.getRemaining();
|
|
|
+ //交易明细最后统一赋值交易前后余额,批量保存
|
|
|
+ List<PayTransactiondetails> transactiondetailsDtoList = new ArrayList();
|
|
|
+ //预存抵扣
|
|
|
+ Iterator<PayReceivable> iterator = payReceivableList.iterator();
|
|
|
+ while(iterator.hasNext()) {
|
|
|
+ //抵扣的应收
|
|
|
+ PayReceivable payReceivable=iterator.next();
|
|
|
+ //账户余额先抵扣
|
|
|
+ if (remaining.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ if(payReceivable.getDebt().compareTo(BigDecimal.ZERO) != 1){
|
|
|
+ //欠费不大于零直接移除
|
|
|
+ iterator.remove();
|
|
|
+ }else if(remaining.compareTo(payReceivable.getDebt()) != -1){
|
|
|
+ //预存余额不小于欠费(完全抵扣)
|
|
|
+ iterator.remove();
|
|
|
+ remaining = remaining.subtract(payReceivable.getDebt());//修改余额
|
|
|
+ //生成并保存实收
|
|
|
+ PayPayReceived payPayReceived = getReceived(payReceivable, year, month, localDateTime,5,payseriesno,payReceivable.getDebt(),feetypeMap, siteId, customerId, 1 );
|
|
|
+ //生成交易明细
|
|
|
+ PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5,"预存账户", localDateTime, payCustomRechargeDto, payseriesno, month, year, payReceivable.getDebt().negate(), siteId, customerId, 1 );
|
|
|
+ payTransactiondetails.setReceivedId(payPayReceived.getId());
|
|
|
+ payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "扣费");
|
|
|
+ payTransactiondetails.setTranstype(2);
|
|
|
+ payTransactiondetails.setTranstypeLabel("扣费");
|
|
|
+ transactiondetailsDtoList.add(payTransactiondetails);
|
|
|
+ //修改应收
|
|
|
+ payReceivable.setDebt(BigDecimal.ZERO);
|
|
|
+ payReceivable.setUpdateDate(localDateTime);
|
|
|
+ payReceivable.setUpdateBy(BigInteger.valueOf(1));
|
|
|
+ payFeeMapper.updatePayReceivable(payReceivable);
|
|
|
+ }else{
|
|
|
+ //预存余额小于于欠费(部分抵扣)
|
|
|
+ //生成并保存实收
|
|
|
+
|
|
|
+ PayPayReceived payPayReceived = getReceived(payReceivable, year, month, localDateTime,5,payseriesno,remaining,feetypeMap, siteId, customerId, 1 );
|
|
|
+
|
|
|
+ PayTransactiondetails payTransactiondetails = getPayTransactiondetails(5, "预存账户",localDateTime, payCustomRechargeDto, payseriesno, month, year, remaining.negate() , siteId, customerId, 1 );
|
|
|
+ payTransactiondetails.setReceivedId(payPayReceived.getId());
|
|
|
+ payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "扣费");
|
|
|
+ payTransactiondetails.setTranstype(2);
|
|
|
+ payTransactiondetails.setTranstypeLabel("扣费");
|
|
|
+ transactiondetailsDtoList.add(payTransactiondetails);
|
|
|
+ //修改应收
|
|
|
+ payReceivable.setDebt(payReceivable.getDebt().subtract(remaining));
|
|
|
+ payReceivable.setUpdateDate(localDateTime);
|
|
|
+ payReceivable.setUpdateBy(BigInteger.valueOf(1));
|
|
|
+ payFeeMapper.updatePayReceivable(payReceivable);
|
|
|
+
|
|
|
+ remaining = BigDecimal.ZERO;//修改余额
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //缴费抵扣
|
|
|
+ Iterator<PayReceivable> iteratorTransAmount = payReceivableList.iterator();
|
|
|
+ while(iteratorTransAmount.hasNext()) {
|
|
|
+ //抵扣的应收
|
|
|
+ PayReceivable payReceivable=iteratorTransAmount.next();
|
|
|
+ //交易金额抵扣
|
|
|
+ if (payfee.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ if(payReceivable.getDebt().compareTo(BigDecimal.ZERO) != 1){
|
|
|
+ //欠费不大于零直接移除
|
|
|
+ iteratorTransAmount.remove();
|
|
|
+ }else if(payfee.compareTo(payReceivable.getDebt()) != -1){
|
|
|
+ //交易金额不小于欠费(完全抵扣)
|
|
|
+ iteratorTransAmount.remove();
|
|
|
+ payfee = payfee.subtract(payReceivable.getDebt());//修改剩余交易金额
|
|
|
+ if(balance != null){
|
|
|
+ balance=balance.add(payReceivable.getDebt());
|
|
|
+ }
|
|
|
+ //生成并保存实收
|
|
|
+ getReceived(payReceivable, year, month, localDateTime,3,payseriesno,payReceivable.getDebt(),feetypeMap, siteId, customerId, 1 );
|
|
|
+ //修改应收
|
|
|
+ payReceivable.setDebt(BigDecimal.ZERO);
|
|
|
+ payReceivable.setUpdateDate(localDateTime);
|
|
|
+ payReceivable.setUpdateBy(BigInteger.valueOf(1));
|
|
|
+ payFeeMapper.updatePayReceivable(payReceivable);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ //交易金额小于于欠费(部分抵扣)
|
|
|
+ //生成并保存实收
|
|
|
+ if(balance != null){
|
|
|
+ balance=balance.add(payfee);
|
|
|
+ }
|
|
|
+ getReceived(payReceivable, year, month, localDateTime,3,payseriesno,payfee,feetypeMap, siteId, customerId, 1 );
|
|
|
+ //修改应收
|
|
|
+ payReceivable.setDebt(payReceivable.getDebt().subtract(payfee));
|
|
|
+ payReceivable.setUpdateDate(localDateTime);
|
|
|
+ payReceivable.setUpdateBy(BigInteger.valueOf(1));
|
|
|
+ payFeeMapper.updatePayReceivable(payReceivable);
|
|
|
+ payfee = BigDecimal.ZERO;//修改余额
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //余额充值或划扣有余额
|
|
|
+ if( payfee.compareTo(BigDecimal.ZERO) == 1){
|
|
|
+ //修改余额
|
|
|
+ remaining=remaining.add(payfee);
|
|
|
+ if(balance != null){
|
|
|
+ balance=balance.add(payfee);
|
|
|
+ }
|
|
|
+ //生成交易明细
|
|
|
+ PayTransactiondetails payTransactiondetails = getPayTransactiondetails(3, paywayName,localDateTime, payCustomRechargeDto, payseriesno, month, year, payfee, siteId, customerId, 1 );
|
|
|
+ payTransactiondetails.setName(payCustomRechargeDto.getAccountname() + payCustomRechargeDto.getAccountnumber() + "缴费");
|
|
|
+ payTransactiondetails.setTranstype(4);
|
|
|
+ payTransactiondetails.setTranstypeLabel("账户转预存");
|
|
|
+ transactiondetailsDtoList.add(payTransactiondetails);
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改预存账户
|
|
|
+ payFeeMapper.updateRechargeaccount(balance,remaining,BigInteger.valueOf(1),localDateTime,payCustomRechargeDto.getRechargeId());
|
|
|
+ //更新客户状态
|
|
|
+ payFeeMapper.updateAccountState(payCustomRechargeDto.getAccountId());
|
|
|
+ //赋值交易明细交易前后余额并保存
|
|
|
+ for(PayTransactiondetails payTransactiondetails : transactiondetailsDtoList){
|
|
|
+ payTransactiondetails.setRemaining(oldRemaining);//交易前账户余额
|
|
|
+ payTransactiondetails.setLastrecreamaing(remaining);//交易后账户余额
|
|
|
+ }
|
|
|
+ //批量保存交易明细
|
|
|
+ if(transactiondetailsDtoList.size()>0){
|
|
|
+ payTransactiondetailsMapper.batchInsert(transactiondetailsDtoList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //第三方交易明细
|
|
|
+ PayAgenttransaction payAgenttransaction = new PayAgenttransaction();
|
|
|
+ payAgenttransaction.setAccountname(payCustomRechargeDto.getAccountname());
|
|
|
+ payAgenttransaction.setAccountnumber(payCustomRechargeDto.getAccountnumber());
|
|
|
+ payAgenttransaction.setAgentbranchId(payPayAgentbranch.getId());
|
|
|
+ payAgenttransaction.setAgentName(payPayAgentbranch.getName());
|
|
|
+ payAgenttransaction.setAgentCode(payPayAgentbranch.getCode());
|
|
|
+ payAgenttransaction.setAmount(money);
|
|
|
+ payAgenttransaction.setState(0);
|
|
|
+ payAgenttransaction.setTranstime(localDateTime);
|
|
|
+ payAgenttransaction.setPayseriesno(payseriesno);
|
|
|
+ payAgenttransaction.setOrderNo(orderCode);
|
|
|
+ payAgenttransaction.setSiteId(BigInteger.valueOf(siteId));
|
|
|
+ payAgenttransaction.setCustomerId(BigInteger.valueOf(customerId));
|
|
|
+ payAgenttransaction.setCreateBy(BigInteger.valueOf(1));
|
|
|
+ payAgenttransaction.setCreateDate(LocalDateTime.now());
|
|
|
+ payAgenttransaction.setUpdateBy(BigInteger.valueOf(1));
|
|
|
+ payAgenttransaction.setUpdateDate(LocalDateTime.now());
|
|
|
+ payAgenttransaction.setRemarks("银行代缴充值");
|
|
|
+ payAgenttransaction.setDelFlag("0");
|
|
|
+ payAgenttransactionMapper.insertAgenttransaction(payAgenttransaction);
|
|
|
+
|
|
|
+ openValveByPayFee(payCustomRechargeDto.getAccountId(), siteId,customerId);
|
|
|
+ return new BankPayfeeMsg("9999","交易成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public BankCheckBillsMsg checkBill(PayPayAgentbranch payPayAgentbranch, BankCheckBillParm bankCheckBillParm ){
|
|
|
+
|
|
|
+ //对账成功的对账信息
|
|
|
+ List<PayCheckbalance> payCheckbalances = new ArrayList();
|
|
|
+ //对账失败的
|
|
|
+ List<BankCheckBill> bankCheckBillList = new ArrayList();
|
|
|
+ for(BankCheckBill bankCheckBill:bankCheckBillParm.getTransDetails()){
|
|
|
+ if(null != bankCheckBill.checkParmIsNull()){
|
|
|
+ bankCheckBill.setMessage(bankCheckBill.checkParmIsNull());
|
|
|
+ bankCheckBillList.add(bankCheckBill);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //订单号查询第三方交易记录
|
|
|
+ PayAgenttransactionDto payAgenttransactionDto = payFeeMapper.selectAgenttransaction(bankCheckBill.getOrderCode());
|
|
|
+ //缺失记录的补记录(缴费)
|
|
|
+ if(payAgenttransactionDto == null || payAgenttransactionDto.getId() == null){
|
|
|
+ BankPayfeeMsg bankPayfeeMsg = payfeeByBank(payPayAgentbranch,bankCheckBill.getOrderCode(),bankCheckBill.getAccountNumber(),bankCheckBill.getMoney(),bankCheckBill.getPayTime());
|
|
|
+ if(!bankPayfeeMsg.getRtnCode().equals("9999")){
|
|
|
+ bankCheckBill.setMessage("补缴失败:"+bankPayfeeMsg.getRtnMsg());
|
|
|
+ bankCheckBillList.add(bankCheckBill);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }else if(payAgenttransactionDto.getState().equals(3)){
|
|
|
+ bankCheckBill.setMessage("已对账");
|
|
|
+ bankCheckBillList.add(bankCheckBill);
|
|
|
+ continue;
|
|
|
+ }else if(payAgenttransactionDto .getAmount() == null || payAgenttransactionDto.getAmount().compareTo(bankCheckBill.getMoney()) != 0){
|
|
|
+ bankCheckBill.setMessage("对账金额有误");
|
|
|
+ bankCheckBillList.add(bankCheckBill);
|
|
|
+ continue;
|
|
|
+ }else if(payAgenttransactionDto .getAccountnumber() == null || !payAgenttransactionDto .getAccountnumber().equals(bankCheckBill.getAccountNumber())){
|
|
|
+ bankCheckBill.setMessage("对账用户编码有误");
|
|
|
+ bankCheckBillList.add(bankCheckBill);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //对账信息无误,修改第三方交易明细状态3
|
|
|
+ payCheckbalanceMapper.updateAgenttransactionState(payAgenttransactionDto.getId());
|
|
|
+ //如果传入时间则用传入的时间做交易时间
|
|
|
+ DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
+ LocalDateTime localDateTime= LocalDateTime.parse(bankCheckBill.getPayTime(), dateTimeFormatter);
|
|
|
+ //记录对账信息
|
|
|
+ PayCheckbalance payCheckbalance = new PayCheckbalance();
|
|
|
+ payCheckbalance.setTranstime(localDateTime);
|
|
|
+ payCheckbalance.setWebchatid("");
|
|
|
+ payCheckbalance.setMachid(payPayAgentbranch.getMchid());
|
|
|
+ payCheckbalance.setNmachid("");
|
|
|
+ payCheckbalance.setDeviceid("");
|
|
|
+ payCheckbalance.setOrderNo(bankCheckBill.getOrderCode());
|
|
|
+ payCheckbalance.setOutTradeNo(bankCheckBill.getOrderCode());
|
|
|
+ payCheckbalance.setUserId("");
|
|
|
+ payCheckbalance.setTranstype("");
|
|
|
+ payCheckbalance.setTransstate("SUCCESS");
|
|
|
+ payCheckbalance.setPayBank("BANK");
|
|
|
+ payCheckbalance.setMoneyType("BANK");
|
|
|
+ payCheckbalance.setOrderFee(BigDecimal.ZERO);
|
|
|
+ payCheckbalance.setCashFee(BigDecimal.ZERO);
|
|
|
+ payCheckbalance.setGoodsName("HXRemotePay");
|
|
|
+ payCheckbalance.setUserData("");
|
|
|
+ payCheckbalance.setServiceCharge(BigDecimal.ZERO);
|
|
|
+ payCheckbalance.setRate("");
|
|
|
+ payCheckbalance.setTransFee(bankCheckBill.getMoney());
|
|
|
+ payCheckbalance.setRateRemark("");
|
|
|
+ payCheckbalance.setCreateBy(BigInteger.valueOf(1));
|
|
|
+ payCheckbalance.setCreateDate(localDateTime.now());
|
|
|
+ payCheckbalance.setUpdateBy(BigInteger.valueOf(1));
|
|
|
+ payCheckbalance.setUpdateDate(localDateTime.now());
|
|
|
+ payCheckbalance.setRemarks("代收对账");
|
|
|
+ payCheckbalance.setDelFlag("0");
|
|
|
+ payCheckbalance.setState(3);
|
|
|
+ payCheckbalance.setSiteId( BigInteger.valueOf(payPayAgentbranch.getSiteId()));
|
|
|
+ payCheckbalance.setCustomerId(BigInteger.valueOf(payPayAgentbranch.getCustomerId()));
|
|
|
+ payCheckbalances.add(payCheckbalance);
|
|
|
+ }
|
|
|
+
|
|
|
+ if(payCheckbalances.size()>0){
|
|
|
+ payCheckbalanceMapper.batchInsert(payCheckbalances);
|
|
|
+ }
|
|
|
+ bankCheckBillParm.setSuccessCount(payCheckbalances.size());
|
|
|
+ bankCheckBillParm.setCreateDate(LocalDateTime.now());
|
|
|
+ payCheckbalanceMapper.insertCheckBalanceLog(bankCheckBillParm);
|
|
|
+
|
|
|
+ return new BankCheckBillsMsg("9999",
|
|
|
+ "对账完成,对账总数:"+bankCheckBillParm.getTotalCount()+",对账成功数:"+payCheckbalances.size(),payCheckbalances.size(),bankCheckBillList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /*
|
|
|
+ * @Description: 生成交易明细
|
|
|
+ *
|
|
|
+ * @auther: wangli
|
|
|
+ * @date: 2020-04-26 8:17
|
|
|
+ * @param: payway 支付方式
|
|
|
+ * @param: localDateTime 交易时间
|
|
|
+ * @param: payCustomRechargeDto 客户信息
|
|
|
+ * @param: payseriesno 批次号
|
|
|
+ * @param: year 账期年
|
|
|
+ * @param: month 账期月
|
|
|
+ * @param: transamount 交易金额
|
|
|
+ * @return:
|
|
|
+ *
|
|
|
+ */
|
|
|
+ private PayTransactiondetails getPayTransactiondetails(int payway, String paywayName, LocalDateTime localDateTime, PayCustomRechargeDto payCustomRechargeDto, String payseriesno, int month, int year, BigDecimal transamount, Integer siteId, Integer customerId, Integer userId) {
|
|
|
+
|
|
|
+ //生成明细
|
|
|
+ PayTransactiondetails payTransactiondetails = new PayTransactiondetails();
|
|
|
+
|
|
|
+ payTransactiondetails.setAccountname(payCustomRechargeDto.getAccountname());
|
|
|
+ payTransactiondetails.setAccountnumber(payCustomRechargeDto.getAccountnumber());
|
|
|
+ payTransactiondetails.setAccountId(payCustomRechargeDto.getAccountId());
|
|
|
+ payTransactiondetails.setMeterId(payCustomRechargeDto.getWatermeterId());
|
|
|
+ payTransactiondetails.setMetercode(payCustomRechargeDto.getMetercode());
|
|
|
+ payTransactiondetails.setPayseriesno(payseriesno);
|
|
|
+ payTransactiondetails.setOfficeId(payCustomRechargeDto.getOfficeId());
|
|
|
+ payTransactiondetails.setTransamount(transamount);
|
|
|
+ payTransactiondetails.setTranstime(localDateTime);
|
|
|
+
|
|
|
+ payTransactiondetails.setIscanceled(0);
|
|
|
+ payTransactiondetails.setPayway(payway);
|
|
|
+ payTransactiondetails.setPaywayLabel(paywayName);
|
|
|
+ payTransactiondetails.setState(1);
|
|
|
+ payTransactiondetails.setYear(year);
|
|
|
+ payTransactiondetails.setMonth(month);
|
|
|
+
|
|
|
+ payTransactiondetails.setUpdateBy(BigInteger.valueOf(userId));
|
|
|
+ payTransactiondetails.setUpdateDate(localDateTime);
|
|
|
+ payTransactiondetails.setCreateBy(BigInteger.valueOf(userId));
|
|
|
+ payTransactiondetails.setCreateDate(localDateTime);
|
|
|
+ payTransactiondetails.setDelFlag("0");
|
|
|
+ payTransactiondetails.setSiteId(BigInteger.valueOf(siteId));
|
|
|
+ payTransactiondetails.setCustomerId(BigInteger.valueOf(customerId));
|
|
|
+ return payTransactiondetails;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 应收生成实收信息(相对应信息)
|
|
|
+ * @param payReceivable 应收信息
|
|
|
+ * @param year 账期年
|
|
|
+ * @param month 账期月
|
|
|
+ * @param localDateTime 交易时间
|
|
|
+ * @param payway 支付方式
|
|
|
+ * @param payseriesno 批次号
|
|
|
+ * @param receivedamount 实收金额
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor=Exception.class)
|
|
|
+ public PayPayReceived getReceived(PayReceivable payReceivable,Integer year ,Integer month ,LocalDateTime localDateTime,int payway,String payseriesno,BigDecimal receivedamount,Map<String,PaySysDictSelectDto> feetypeMap ,Integer siteId,Integer customerId,Integer userId) {
|
|
|
+
|
|
|
+ PayPayReceived payReceived=new PayPayReceived();
|
|
|
+ payReceived.setReceivableId(payReceivable.getId());
|
|
|
+ payReceived.setAccountId(payReceivable.getAccountId());
|
|
|
+ payReceived.setAccountname(payReceivable.getAccountname());
|
|
|
+ payReceived.setAccountnumber(payReceivable.getAccountnumber());
|
|
|
+ payReceived.setCustomerandmeterrelaId(payReceivable.getCustomerandmeterrelaId());
|
|
|
+ payReceived.setMeterId(payReceivable.getMeterId());
|
|
|
+ payReceived.setMetercode(payReceivable.getMetercode());
|
|
|
+ payReceived.setPayamount(payReceivable.getPayamount());
|
|
|
+ payReceived.setPrice(payReceivable.getWaterbasicprice());
|
|
|
+ payReceived.setFeetype(payReceivable.getFeetype());
|
|
|
+ payReceived.setWaterpropertyId(payReceivable.getWaterpropertyId());
|
|
|
+ payReceived.setOfficeId(payReceivable.getOfficeId());
|
|
|
+ payReceived.setState(1);
|
|
|
+ payReceived.setWatertype(payReceivable.getWatertype());
|
|
|
+ payReceived.setLadderlevel(payReceivable.getLadderlevel());
|
|
|
+ payReceived.setName(year+"年"+month+"月"+feetypeMap.get(payReceivable.getFeetype().toString()).getLabel());//账期+费用feetype
|
|
|
+ payReceived.setYear(year);
|
|
|
+ payReceived.setMonth(month);
|
|
|
+ payReceived.setIscanceled(0);
|
|
|
+ payReceived.setCreateBy(BigInteger.valueOf(userId));
|
|
|
+ payReceived.setCreateDate(localDateTime);
|
|
|
+ payReceived.setUpdateBy(BigInteger.valueOf(userId));
|
|
|
+ payReceived.setUpdateDate(localDateTime);
|
|
|
+ payReceived.setDelFlag("0");
|
|
|
+ payReceived.setSiteId(BigInteger.valueOf(siteId));
|
|
|
+ payReceived.setCustomerId(BigInteger.valueOf(customerId));
|
|
|
+ payReceived.setPayway(payway);
|
|
|
+ payReceived.setReceivedamount(receivedamount);
|
|
|
+ payReceived.setPayseriesno(payseriesno);
|
|
|
+
|
|
|
+
|
|
|
+ //保存实收并返写id
|
|
|
+ payPayReceivedMapper.insert(payReceived);
|
|
|
+ return payReceived;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void openValveByPayFee(BigInteger id, Integer siteId, Integer customerId) {
|
|
|
+ //查询阀门状态,判断是否需要开阀
|
|
|
+ List<PayValveStateInfoDto> payValveStateInfos = payFeeMapper.getDeviceValveState(id);
|
|
|
+
|
|
|
+ List<Integer> types =new ArrayList<>();
|
|
|
+ types.add(2); //欠费金额
|
|
|
+ types.add(3); //预存金额
|
|
|
+ types.add(4); //用水余额
|
|
|
+ types.add(7); //预存与欠费差额
|
|
|
+ List<PayControlRule> payControlRules = payFeeMapper.getValveRulesByType(1,types,siteId,customerId);
|
|
|
+
|
|
|
+ for(PayValveStateInfoDto payValveStateInfo : payValveStateInfos){
|
|
|
+ if(payValveStateInfo != null
|
|
|
+ && ((payValveStateInfo.getValveState()!= null && payValveStateInfo.getValveState() == 0)
|
|
|
+ || payValveStateInfo.getValveState() == null)){
|
|
|
+ payValveStateInfo.setOperation(1);
|
|
|
+ payValveStateInfo.setSiteId(BigInteger.valueOf(siteId));
|
|
|
+ payValveStateInfo.setCustomerId(BigInteger.valueOf(customerId));
|
|
|
+
|
|
|
+ for(PayControlRule payControlRule : payControlRules){
|
|
|
+ if((","+payValveStateInfo.getValveRuleIds()+",").indexOf(","+payControlRule.getId()+",") != -1){
|
|
|
+ if(payControlRule.getConditionId() == 2 && payValveStateInfo.getDebt() != null && payControlRule.checkCondition(payValveStateInfo.getDebt())){
|
|
|
+ payValveStateInfo.setControlRuleId(payControlRule.getId().intValue());
|
|
|
+ Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(payControlRule.getConditionId() == 3 && payValveStateInfo.getRemaining() != null && payControlRule.checkCondition(payValveStateInfo.getRemaining())){
|
|
|
+ payValveStateInfo.setControlRuleId(payControlRule.getId().intValue());
|
|
|
+ Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(payControlRule.getConditionId() == 4 && payValveStateInfo.getBalance() != null && payControlRule.checkCondition(payValveStateInfo.getBalance())){
|
|
|
+ payValveStateInfo.setControlRuleId(payControlRule.getId().intValue());
|
|
|
+ Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if(payControlRule.getConditionId() == 7 && payValveStateInfo.getRemaining() != null && payValveStateInfo.getDebt() != null && payControlRule.checkCondition(payValveStateInfo.getRemaining().subtract(payValveStateInfo.getDebt()))){
|
|
|
+ payValveStateInfo.setControlRuleId(payControlRule.getId().intValue());
|
|
|
+ Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //缴费开阀
|
|
|
+ public Boolean sendValveCommond(PayValveStateInfoDto payValveStateInfo){
|
|
|
+
|
|
|
+ PayControlRecord lastPayControlRecord = payControlRecordMapper.findControlRecordByMetercode(payValveStateInfo.getMeterCode());
|
|
|
+ if(lastPayControlRecord != null && (lastPayControlRecord.getResult() == null ||lastPayControlRecord.getResult() == 0) ){
|
|
|
+ if(lastPayControlRecord.getType().equals(payValveStateInfo.getOperation())){ //操作相同不再添加
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // TODO 用户这一块是没有的,如何解决?????
|
|
|
+ BigInteger userId= new BigInteger("1");
|
|
|
+ /*LoginUser loginUser =UserUtil.getCurrentUser();
|
|
|
+ BigInteger userId;
|
|
|
+ if(loginUser == null || loginUser.getId() == null){
|
|
|
+ userId= new BigInteger("1");
|
|
|
+ }else{
|
|
|
+ userId = BigInteger.valueOf(loginUser.getId());
|
|
|
+ }*/
|
|
|
+// JSONObject parmJson= new JSONObject();
|
|
|
+// parmJson.put("meterNo",payValveStateInfo.getMeterCode());
|
|
|
+// parmJson.put("type",payValveStateInfo.getOperation()); //1开0关
|
|
|
+// parmJson.put("customerNo",payValveStateInfo.getCustomerNo());
|
|
|
+// String context=parmJson.toString();
|
|
|
+ try {
|
|
|
+ //调用阀门接口
|
|
|
+ String url=payValveCommondUrl + "/api/platform/sendCommond";
|
|
|
+ String params = String.format("?customerNo=%s&meterNo=%s&type=%s",payValveStateInfo.getCustomerNo(),payValveStateInfo.getMeterCode(),payValveStateInfo.getOperation());
|
|
|
+ String result = HttpRequest.doPost(url + params ,"");
|
|
|
+// String result= HttpClientUtils.doPostWithJson(payValveCommondUrl+"/api/platform/sendCommond",context);
|
|
|
+ log.info("开关阀请求数据: {},开关阀请求结果: {}", url + params ,result);
|
|
|
+ JSONObject jsonObject= JSON.parseObject(result);
|
|
|
+ Integer status= jsonObject.getInteger("status");
|
|
|
+ if(status == 0){ //返回正常
|
|
|
+ //添加阀控记录
|
|
|
+ PayControlRecord payControlRecord = new PayControlRecord();
|
|
|
+ payControlRecord.setAccountId(payValveStateInfo.getAccountId());
|
|
|
+ payControlRecord.setMeterId(payValveStateInfo.getMeterId());
|
|
|
+ payControlRecord.setRemarks("阀门处理");
|
|
|
+ payControlRecord.setResult(0);//进行中
|
|
|
+ payControlRecord.setState(payValveStateInfo.getValveState());
|
|
|
+ payControlRecord.setType(payValveStateInfo.getOperation());//开阀操作
|
|
|
+
|
|
|
+ payControlRecord.setControlRuleId(payValveStateInfo.getControlRuleId());
|
|
|
+
|
|
|
+ payControlRecord.setCreateBy(userId);
|
|
|
+ payControlRecord.setCreateDate(LocalDateTime.now());
|
|
|
+ payControlRecord.setDelFlag("0");
|
|
|
+ payControlRecord.setCustomerId(payValveStateInfo.getCustomerId());
|
|
|
+ payControlRecord.setSiteId(payValveStateInfo.getSiteId());
|
|
|
+ payControlRecordMapper.add(payControlRecord);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|