Selaa lähdekoodia

添加银行文档对账接口调整

lihui007 4 vuotta sitten
vanhempi
commit
6ac4d04ca9

+ 20 - 2
smart-city-platform/src/main/java/com/bz/smart_city/SmartCityApplication.java

@@ -1,24 +1,42 @@
 package com.bz.smart_city;
 
+import lombok.extern.slf4j.Slf4j;
 import org.activiti.spring.boot.SecurityAutoConfiguration;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.builder.SpringApplicationBuilder;
 import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
 import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.env.Environment;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
 @SpringBootApplication(exclude = SecurityAutoConfiguration.class)
 @EnableScheduling
 @EnableAsync
 @EnableCaching  //开启缓存
+@Slf4j
 public class SmartCityApplication extends SpringBootServletInitializer {
 
-    public static void main(String[] args) {
-        SpringApplication.run(SmartCityApplication.class, args);
+
+
+
+    public static void main(String[] args) throws UnknownHostException {
+        ApplicationContext context = SpringApplication.run(SmartCityApplication.class, args);
+        Environment env = context.getEnvironment();
+        String ip = InetAddress.getLocalHost().getHostAddress();
+        String port = env.getProperty("server.port");
+        log.info("\n----------------------------------------------------------\n\t" +
+                "Application smart_city is running! Access URLs:\n\t" +
+                "接口Doc: \t\thttp://" + ip + ":" + port + "/api/swagger-ui.html\n" +
+                "----------------------------------------------------------");
     }
 
+
     @Override
     protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
         return builder.sources(SmartCityApplication.class);

+ 3 - 1
smart-city-platform/src/main/java/com/bz/smart_city/commom/security/WebSecurityConfig.java

@@ -98,7 +98,9 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/device/synArchies")
                 .antMatchers("/installPlan/**")
                 .antMatchers("/customer/synCustomer")
-                .antMatchers("/druid/**");
+                .antMatchers("/druid/**")
+                .antMatchers("/account/checking/**");
+
 
     }
 

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/commom/util/MessageSend/SMSClient.java

@@ -30,8 +30,8 @@ public class SMSClient  {
         sendReq.setApId(apId);
         sendReq.setEcName(ecName);
         sendReq.setSecretKey(secretKey);
-        sendReq.setContent("豆渣,这是短信接口测试");
-        sendReq.setMobiles("17796348920,15071426392");
+        sendReq.setContent("短信接口测试");
+        sendReq.setMobiles("13682689635");
         sendReq.setSign(sign);
 
         int result = sendMsg(sendReq);

+ 97 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/checking/AccountCheckingController.java

@@ -0,0 +1,97 @@
+package com.bz.smart_city.controller.checking;
+
+import com.bz.smart_city.commom.util.RedisUtil;
+import com.bz.smart_city.dto.pay.payfee.BankCheckBillParm;
+import com.bz.smart_city.dto.pay.payfee.BankCheckBillsMsg;
+import com.bz.smart_city.dto.pay.payfee.BankChecking;
+import com.bz.smart_city.entity.pay.PayPayAgentbranch;
+import com.bz.smart_city.service.checking.PayFeeCheckingService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+* @Author lihui
+* @Description 对账接口
+* @Date 16:10 2021/5/13
+**/
+@RestController
+@RequestMapping("account/checking")
+@Api(tags = "对账接口")
+public class AccountCheckingController {
+
+    @Autowired
+    PayFeeCheckingService payFeeCheckingService;
+
+    @Autowired
+    protected RedisUtil redisUtil;
+
+    static Map<Integer, String> mmp = new HashMap<>();
+
+    static  {
+        /**
+         * 当前已对账的日期
+         */
+        mmp.put(1, "check_bill_date");
+        /**
+         * 队列:文件丢失队列
+         */
+        mmp.put(2, "check_bill_lose_date_queue");
+    }
+
+    @GetMapping("/selectPayAgentbranchInfo")
+    @ApiOperation(value="selectPayAgentbranchInfo")
+    public PayPayAgentbranch selectPayAgentbranchInfo(
+            @ApiParam(value = "code") @RequestParam String billAgentCode,
+            @ApiParam(value = "pwd") @RequestParam Integer customerId) {
+        return payFeeCheckingService.selectPayAgentbranchInfo(billAgentCode, customerId);
+    }
+
+    @PostMapping("/checkBill")
+    @ApiOperation(value="checkBill")
+    public BankCheckBillsMsg selectPayAgentbranchInfo(
+            @RequestBody @Valid BankChecking bankChecking) {
+        if (bankChecking == null){
+            return null;
+        }
+        return payFeeCheckingService.checkBill(bankChecking.getPayPayAgentbranch(), bankChecking.getBankCheckBillParm());
+    }
+
+    @GetMapping("/get")
+    @ApiOperation(value="get")
+    public String get() {
+        return redisUtil.get(mmp.get(1));
+    }
+
+    @GetMapping("/leftPush")
+    @ApiOperation(value="leftPush")
+    public Long leftPush(@ApiParam(value = "timeString") @RequestParam String timeString) {
+        return redisUtil.leftPush(mmp.get(2),timeString);
+    }
+
+    @GetMapping("/set")
+    @ApiOperation(value="set")
+    public void set(@ApiParam(value = "timeString") @RequestParam String timeString) {
+        redisUtil.set(mmp.get(1),timeString);
+    }
+
+    @GetMapping("/leftPop")
+    @ApiOperation(value="leftPop")
+    public String leftPop() {
+        return redisUtil.leftPop(mmp.get(2));
+    }
+
+    @PostMapping("/leftPushAll")
+    @ApiOperation(value="leftPushAll")
+    public long leftPushAll(@RequestBody List<String> list) {
+        return redisUtil.leftPushAll(mmp.get(2), list);
+    }
+
+}

+ 2 - 1
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/BankCheckBill.java

@@ -6,6 +6,7 @@ import lombok.Data;
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 /**
  * @description 银行代收对账信息
@@ -23,7 +24,7 @@ public class BankCheckBill implements Serializable {
     @ApiModelProperty("用户编号")
     private String accountNumber;
     @ApiModelProperty("缴费金额")
-    private Float money;
+    private BigDecimal money;
     @ApiModelProperty("缴费时间,格式为yyyyMMddhhmmss")
     private String payTime;
 

+ 5 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/BankCheckBillParm.java

@@ -62,4 +62,9 @@ public class BankCheckBillParm implements Serializable {
         }
         return null;
     }
+
+    @Override
+    public  String toString(){
+        return "agentCode ["+agentCode+"],agentPwd ["+agentPwd+"]";
+    }
 }

+ 9 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/BankCheckBillsMsg.java

@@ -21,6 +21,9 @@ public class BankCheckBillsMsg extends BankPayResult implements Serializable {
     @ApiModelProperty("对账失败信息")
     private List<BankCheckBill> bankCheckBills;
 
+    @ApiModelProperty("对账成功数")
+    private int successTotal;
+
     public BankCheckBillsMsg(String rtnCode,String rtnMsg){
         super(rtnCode,rtnMsg);
     }
@@ -29,4 +32,10 @@ public class BankCheckBillsMsg extends BankPayResult implements Serializable {
         super(rtnCode,rtnMsg);
         this.bankCheckBills=bankCheckBills;
     }
+
+    public BankCheckBillsMsg(String rtnCode,String rtnMsg,int successTotal,List<BankCheckBill> bankCheckBills){
+        super(rtnCode,rtnMsg);
+        this.bankCheckBills=bankCheckBills;
+        this.successTotal = successTotal;
+    }
 }

+ 20 - 0
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/BankChecking.java

@@ -0,0 +1,20 @@
+package com.bz.smart_city.dto.pay.payfee;
+
+import com.bz.smart_city.entity.pay.PayPayAgentbranch;
+import lombok.Data;
+
+/**
+ * @ClassName BankChecking
+ * @Description: TODO
+ * @Author lihui
+ * @Date 2021/5/13
+ * @Version V1.0
+ **/
+@Data
+public class BankChecking {
+
+    PayPayAgentbranch payPayAgentbranch;
+
+    BankCheckBillParm bankCheckBillParm;
+
+}

+ 2 - 1
smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/BankPayFeeParm.java

@@ -6,6 +6,7 @@ import lombok.Data;
 import org.apache.commons.lang3.StringUtils;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 
 /**
  * @description 银行代收支付接口参数
@@ -27,7 +28,7 @@ public class BankPayFeeParm implements Serializable {
     @ApiModelProperty("代收单位验证密钥,与营业系统代收单位对应(营收系统分配)")
     private String agentPwd;
     @ApiModelProperty("缴费总金额(包含预存),缴费金额需大于等于欠费金额")
-    private Float money;
+    private BigDecimal money;
     @ApiModelProperty("缴费时间,格式为yyyyMMddhhmmss")
     private String payTime;
 

+ 21 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/checking/PayFeeCheckingService.java

@@ -0,0 +1,21 @@
+package com.bz.smart_city.service.checking;
+
+
+import com.bz.smart_city.dto.pay.payfee.BankCheckBillParm;
+import com.bz.smart_city.dto.pay.payfee.BankCheckBillsMsg;
+import com.bz.smart_city.entity.pay.PayPayAgentbranch;
+
+/**
+ * @Author wangli
+ * 2020-04-15 16:43
+ * @Description
+ * @Version 1.0
+ */
+public interface PayFeeCheckingService {
+
+    PayPayAgentbranch selectPayAgentbranchInfo(String code, Integer customerId);
+
+    BankCheckBillsMsg checkBill(PayPayAgentbranch payPayAgentbranch, BankCheckBillParm bankCheckBillParm);
+
+
+}

+ 621 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/checking/impl/PayFeeCheckingImpl.java

@@ -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;
+    }
+
+}

+ 5 - 5
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayFeeServiceImp.java

@@ -1062,7 +1062,7 @@ public class PayFeeServiceImp implements PayFeeService {
      * @param payTime
      */
     @Transactional(rollbackFor = Exception.class)
-    public BankPayfeeMsg payfeeByBank( PayPayAgentbranch payPayAgentbranch ,String orderCode,String accountNumber,Float money, String payTime ){
+    public BankPayfeeMsg payfeeByBank( PayPayAgentbranch payPayAgentbranch ,String orderCode,String accountNumber,BigDecimal money, String payTime ){
         //如果传入时间则用传入的时间做交易时间
         LocalDateTime localDateTime;
         try{
@@ -1080,7 +1080,7 @@ public class PayFeeServiceImp implements PayFeeService {
             return new BankPayfeeMsg("0005","系统信息配置异常");
         }
 
-        BigDecimal payfee = new BigDecimal(money);
+        BigDecimal payfee = money;
         //实收金额不可为负数
         if(payfee.compareTo(BigDecimal.ZERO) == -1){
             return new BankPayfeeMsg("2002","小于最小缴费金额");
@@ -1294,7 +1294,7 @@ public class PayFeeServiceImp implements PayFeeService {
         payAgenttransaction.setAgentbranchId(payPayAgentbranch.getId());
         payAgenttransaction.setAgentName(payPayAgentbranch.getName());
         payAgenttransaction.setAgentCode(payPayAgentbranch.getCode());
-        payAgenttransaction.setAmount(new BigDecimal(money));
+        payAgenttransaction.setAmount(money);
         payAgenttransaction.setState(0);
         payAgenttransaction.setTranstime(localDateTime);
         payAgenttransaction.setPayseriesno(payseriesno);
@@ -1340,7 +1340,7 @@ public class PayFeeServiceImp implements PayFeeService {
                 bankCheckBill.setMessage("已对账");
                 bankCheckBillList.add(bankCheckBill);
                 continue;
-            }else if(payAgenttransactionDto .getAmount() == null || payAgenttransactionDto .getAmount().compareTo(new BigDecimal(bankCheckBill.getMoney())) != 0){
+            }else if(payAgenttransactionDto .getAmount() == null || payAgenttransactionDto .getAmount().compareTo(bankCheckBill.getMoney()) != 0){
                 bankCheckBill.setMessage("对账金额有误");
                 bankCheckBillList.add(bankCheckBill);
                 continue;
@@ -1375,7 +1375,7 @@ public class PayFeeServiceImp implements PayFeeService {
             payCheckbalance.setUserData("");
             payCheckbalance.setServiceCharge(BigDecimal.ZERO);
             payCheckbalance.setRate("");
-            payCheckbalance.setTransFee(new BigDecimal(bankCheckBill.getMoney()));
+            payCheckbalance.setTransFee(bankCheckBill.getMoney());
             payCheckbalance.setRateRemark("");
             payCheckbalance.setCreateBy(BigInteger.valueOf(1));
             payCheckbalance.setCreateDate(localDateTime.now());

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/service/pay/PayFeeService.java

@@ -130,7 +130,7 @@ public interface PayFeeService {
 
     List<BankPayfeeAccountInfo> selectBankPayfeeAccountInfo(String queryType,String queryValue);
 
-    BankPayfeeMsg payfeeByBank( PayPayAgentbranch payPayAgentbranch ,String orderCode,String accountNumber,Float money, String payTime );
+    BankPayfeeMsg payfeeByBank( PayPayAgentbranch payPayAgentbranch ,String orderCode,String accountNumber,BigDecimal money, String payTime );
 
     BankCheckBillsMsg checkBill(PayPayAgentbranch payPayAgentbranch, BankCheckBillParm bankCheckBillParm );