瀏覽代碼

Merge branch '20200918' of http://114.135.61.188:53000/ZONIOT/water-iot into 20200918

oppadmin 4 年之前
父節點
當前提交
28a5b9ae6e
共有 16 個文件被更改,包括 180 次插入91 次删除
  1. 1 1
      smart-city-platform/build.gradle
  2. 12 0
      smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/archives/PayBaseCustomerandmeterrelaController.java
  3. 2 2
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayFeeMapper.java
  4. 1 1
      smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/archives/PayBaseCustomerandmeterrelaMapper.java
  5. 2 0
      smart-city-platform/src/main/java/com/bz/smart_city/dto/pay/payfee/PayValveStateInfo.java
  6. 2 0
      smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/PayControlValve.java
  7. 2 1
      smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimateMsgSendServiceImpl.java
  8. 2 1
      smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimatedDayServiceImpl.java
  9. 2 1
      smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimatedValveServiceImpl.java
  10. 55 21
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountWaterUsedAmountServiceImpl.java
  11. 52 47
      smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayFeeServiceImp.java
  12. 16 6
      smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java
  13. 5 2
      smart-city-platform/src/main/java/com/bz/smart_city/service/pay/archives/impl/PayBaseCustomerandmeterrelaServiceImpl.java
  14. 13 5
      smart-city-platform/src/main/resources/mapper/PayBaseCustomerandmeterrelaMapper.xml
  15. 1 1
      smart-city-platform/src/main/resources/mapper/pay/PayControlRecordMapper.xml
  16. 12 2
      smart-city-platform/src/main/resources/mapper/pay/payFeeMapper.xml

+ 1 - 1
smart-city-platform/build.gradle

@@ -110,7 +110,7 @@ tasks.withType(JavaCompile) {
     options.encoding = 'UTF-8'
 }
 def releaseTime() {
-    return new Date().format("yyyyMMdd", TimeZone.getTimeZone("GMT+08:00"))
+    return new Date().format("yyyyMMddHHmmss", TimeZone.getTimeZone("GMT+08:00"))
 }
 allprojects {
 

+ 12 - 0
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/archives/PayBaseCustomerandmeterrelaController.java

@@ -11,6 +11,9 @@ import com.bz.smart_city.dto.pay.PayCustomerDto;
 import com.bz.smart_city.dto.pay.PaySaveCustomerDto;
 import com.bz.smart_city.entity.pay.archives.CustomerListInfo;
 import com.bz.smart_city.entity.pay.archives.PayAccountInfo;
+import com.bz.smart_city.quartz.service.EstimateMsgSendService;
+import com.bz.smart_city.quartz.service.EstimatedDayService;
+import com.bz.smart_city.quartz.service.EstimatedValveService;
 import com.bz.smart_city.service.impl.ImportServiceImpl;
 import com.bz.smart_city.service.pay.archives.PayBaseCustomerandmeterrelaService;
 import io.swagger.annotations.Api;
@@ -46,6 +49,15 @@ public class PayBaseCustomerandmeterrelaController {
     @Autowired
     private RedisUtil redisUtil;
 
+    @Autowired
+    private EstimatedDayService estimatedDayService;
+
+    @Autowired
+    private EstimatedValveService estimatedValveService;
+
+    @Autowired
+    private EstimateMsgSendService estimateMsgSendService;
+
     @ResponseBody
     @GetMapping("/pageOpenList")
     @ApiOperation(value = "计费系统-获取开户分页")

+ 2 - 2
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/PayFeeMapper.java

@@ -72,7 +72,7 @@ public interface PayFeeMapper {
 
     List<PayValveStateInfo> getDeviceValveStateByRecord();
 
-   Integer deleteControlValveInfoByDevice(@Param("list")List<BigInteger> list);
+    Integer deleteControlValveInfoByDevice(@Param("list")List<BigInteger> list);
 
-    List<PayControlRule> getValveRulesByType(@Param("type")Integer type);
+    List<PayControlRule> getValveRulesByType(@Param("action")Integer action ,@Param("types")List<Integer> types,@Param("siteId")Integer siteId, @Param("customer")Integer customer);
 }

+ 1 - 1
smart-city-platform/src/main/java/com/bz/smart_city/dao/pay/archives/PayBaseCustomerandmeterrelaMapper.java

@@ -105,7 +105,7 @@ public interface PayBaseCustomerandmeterrelaMapper {
 
     public List<PayControlRule> getRuleNames(@Param("siteId")Integer siteId,@Param("customerId")Integer customerId,@Param("list")List<String> list);
 
-    void insertValve(@Param("deviceId")BigInteger deviceId,@Param("date")LocalDateTime date,@Param("controlState")int controlState);
+    void insertValve(@Param("deviceId")BigInteger deviceId,@Param("date")LocalDateTime date,@Param("controlState")int controlState,@Param("controlRuleId")int controlRuleId);
 
     PayBaseCustomerandmeterrela getAccountCustomer(@Param("id") BigInteger id);
 }

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

@@ -17,9 +17,11 @@ public class PayValveStateInfo {
     private String eleno;
     private String valveState;
     private BigDecimal debt;
+    private BigDecimal remaining;
     private BigInteger accountId;
     private BigInteger meterId;
     private BigInteger customerNo;
+    private Integer controlRuleId;
     private Integer operation;  //0关阀1开阀
     private BigInteger siteId;
     private BigInteger customerId;

+ 2 - 0
smart-city-platform/src/main/java/com/bz/smart_city/entity/pay/PayControlValve.java

@@ -23,4 +23,6 @@ public class PayControlValve {
     private LocalDateTime controlTime;//下发时间
     @ApiModelProperty(value = "操作类型")
     private Integer controlState;//操作类型 0关 1开
+    @ApiModelProperty(value = "阀控规则ID")
+    private int controlRuleId;//阀控规则ID
 }

+ 2 - 1
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimateMsgSendServiceImpl.java

@@ -77,7 +77,8 @@ public class EstimateMsgSendServiceImpl implements EstimateMsgSendService, Initi
                 minute = sp[1];
                 //String cron = "0 */3 * * * ?";
                 //String cron ="0 40 14 * * ?";
-                String cron = "0 "+Integer.valueOf(minute)+" "+Integer.valueOf(time)+" * * ?";
+                //String cron = "0 "+Integer.valueOf(minute)+" "+Integer.valueOf(time)+" * * ?";
+                String cron = String.format("%s %s %s * * ?",0,15,17);
                 //String cron = "0 2 15 * * ?";
                 log.info("预计费每天推送:" + cron);
                 log.info("预计费每天推送:" + "站点ID:"+siteId+"水司ID:"+customerId);

+ 2 - 1
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimatedDayServiceImpl.java

@@ -60,7 +60,8 @@ public class EstimatedDayServiceImpl implements EstimatedDayService, Initializin
         if(!exists) {
             //String cron = "0 */2 * * * ?";
             //String cron = "0 0 0 * * ?";
-            String cron = "0 0 15 * * ?";
+            //String cron = "0 0 15 * * ?";
+            String cron = String.format("%s %s %s * * ?",0,10,17);
             log.info("预计费每天统计:" + cron);
             log.info("预计费每天统计:" + "站点ID:"+siteId+"水司ID:"+customerId);
             entity.setCronExpression(cron);

+ 2 - 1
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/EstimatedValveServiceImpl.java

@@ -75,7 +75,8 @@ public class EstimatedValveServiceImpl implements EstimatedValveService, Initial
                 DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                 LocalDateTime localDateTime = LocalDateTime.parse(currTime,df);
                 LocalDateTime esTime = localDateTime.plusMinutes(30);
-                String cron = String.format("%s %s %s * * ?",esTime.getSecond(),esTime.getMinute(),esTime.getHour());
+                //String cron = String.format("%s %s %s * * ?",esTime.getSecond(),esTime.getMinute(),esTime.getHour());
+                String cron = String.format("%s %s %s * * ?",0,12,17);
                 //String cron = "0 */2 * * * ?";
                 //String cron ="0 40 14 * * ?";
                 //String cron = "0 "+Integer.valueOf(minute)+" "+Integer.valueOf(time)+" * * ?";

+ 55 - 21
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/AmountWaterUsedAmountServiceImpl.java

@@ -225,13 +225,16 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
             }
         }
         if(idList.size()>0){
-            List<PayControlRule> payControlRules = payFeeMapper.getValveRulesByType(2);
+            List<Integer> types =new ArrayList<>();
+            types.add(2);
+            List<PayControlRule> payControlRules = payFeeMapper.getValveRulesByType(null,types,loginUser.getSiteId(),loginUser.getCustomerId());
             for(int i=0;2000*i<idList.size();i++){
                 if(2000*i+2000<idList.size()){
                     List<PayValveStateInfo> PayValveStateInfos = payFeeMapper.getDeviceValveStateByAmount(idList.subList(2000*i,2000*i+2000));
                     for(PayValveStateInfo payValveStateInfo :PayValveStateInfos){
                         for(PayControlRule payControlRule :payControlRules){
                             if(payValveStateInfo.getDebt() != null && payControlRule.checkCondition(payValveStateInfo.getDebt())){
+                                payValveStateInfo.setControlRuleId(payControlRule.getId().intValue());
                                 payValveStateInfo.setOperation(payControlRule.getAction());
                                 payValveStateInfo.setCustomerId(BigInteger.valueOf(loginUser.getCustomerId()));
                                 payValveStateInfo.setSiteId(BigInteger.valueOf(loginUser.getSiteId()));
@@ -244,6 +247,7 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
                     for(PayValveStateInfo payValveStateInfo :PayValveStateInfos){
                         for(PayControlRule payControlRule :payControlRules){
                             if(payValveStateInfo.getDebt() != null && payControlRule.checkCondition(payValveStateInfo.getDebt())){
+                                payValveStateInfo.setControlRuleId(payControlRule.getId().intValue());
                                 payValveStateInfo.setOperation(payControlRule.getAction());
                                 payValveStateInfo.setCustomerId(BigInteger.valueOf(loginUser.getCustomerId()));
                                 payValveStateInfo.setSiteId(BigInteger.valueOf(loginUser.getSiteId()));
@@ -836,10 +840,8 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
             List<EstimatedDayDto>  list = amountWaterUsedAmountMapper.getEstimatedDay(beforDate,baseClosingAccountInfoDto.getYear(),baseClosingAccountInfoDto.getMonth(),siteId,customerId);
             if(list != null && list.size() > 0){
                 for(EstimatedDayDto dto:list){
-
                     PayBaseCustomerandmeterrela customerInfo = payBaseCustomerandmeterrelaMapper.get(dto.getId());
                     Integer calculateway = customerInfo.getCalculateway();//结算方式
-
                     BigDecimal dayReading = dto.getDayReading();
                     BigDecimal mReading = dto.getMReading();
                     String readdate = dto.getReaddate();
@@ -851,15 +853,17 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
                     //必须当天有数据,并且月结数据也有数据才进行计算
                     if(dayReading != null && mReading != null){
                         BigDecimal amount = dayReading.subtract(mReading);
-
-                        // 0水量 不计费但计量
+                        // 不计费但计量
                         if(amount.intValue()<=0|| calculateway == 3){
+                            //0水量
                             amount = new BigDecimal(0);
                         }
+                        //按固定量
                         if(calculateway ==2){
                             amount = customerInfo.getFixedamount();
                         }
 
+                        //判断是否按照阶梯计算
                         Integer isEnable = this.isEnable(baseClosingAccountInfoDto.getYear(),baseClosingAccountInfoDto.getMonth(),watermeterId,waterPropertyId,siteId,customerId);
                         //isEnable 0非阶梯  1阶梯  2异常(不做处理)
                         if(isEnable ==0){
@@ -878,28 +882,42 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
                             balance = remaining.subtract(fee);
                         }else if(isEnable == 1){
                             //阶梯用水
-                            Integer debtFlag = 1;
                             PayBaseAccount payBaseAccount = payBaseAccountMapper.get(accountId);
-                            debtFlag =payBaseAccount.getState();
                             int n = 4;   //阶梯级别
                             BigDecimal fee = BigDecimal.ZERO;
+                            //判断年阶梯是否需要执行多次
+                            Boolean flag = false;
+                            BaseWaterProperty baseWaterProperty= baseWaterPropertyMapper.get(waterPropertyId,siteId,customerId);
                             for (int i = 1; i <= n; i++) {
+                                //阶梯可用量
                                 BigDecimal availableAmount =  new BigDecimal(0);
                                 Object objAmount = ReflectionsUtil.getFieldValue(payBaseAccount, "availableamount" + i);
                                 if (objAmount != null) {
                                     availableAmount = new BigDecimal(objAmount.toString());
                                 }
+                                //如果阶梯可用量为空则用阶梯量代替
                                 if(availableAmount.compareTo(BigDecimal.ZERO) == 0){
+                                    Integer laddertype = baseWaterProperty.getLaddertype();
                                     Object objlableL = new Object();
-                                    if(i > 1){
-                                        Object objlableL1 = ReflectionsUtil.getFieldValue(payBaseAccount, "availableL" + i);
-                                        objlableL = ReflectionsUtil.getFieldValue(payBaseAccount, "availableL" + (i-1));
-                                        //减去前一阶的阶梯量
-                                        availableAmount = new BigDecimal(objlableL1.toString()).subtract(new BigDecimal(objlableL.toString()));
-                                    }else{
-                                        objlableL = ReflectionsUtil.getFieldValue(payBaseAccount, "availableL" + i);
+                                    if(laddertype == 2){
+                                        flag = false;
+                                        //年阶梯
+                                        objlableL = ReflectionsUtil.getFieldValue(payBaseAccount, "availableamount" + 4);
                                         availableAmount = new BigDecimal(objlableL.toString());
+                                    }else if(laddertype == 1){
+                                        flag = true;
+                                        if(i > 1){
+                                            Object objlableL1 = ReflectionsUtil.getFieldValue(payBaseAccount, "availableL" + i);
+                                            objlableL = ReflectionsUtil.getFieldValue(payBaseAccount, "availableL" + (i-1));
+                                            //减去前一阶的阶梯量
+                                            availableAmount = new BigDecimal(objlableL1.toString()).subtract(new BigDecimal(objlableL.toString()));
+                                        }else{
+                                            objlableL = ReflectionsUtil.getFieldValue(payBaseAccount, "availableL" + i);
+                                            availableAmount = new BigDecimal(objlableL.toString());
+                                        }
                                     }
+                                }else{
+                                    flag = true;
                                 }
                                 //阶梯结算水量
                                 BigDecimal calAmount = BigDecimal.ZERO;
@@ -914,20 +932,36 @@ public class AmountWaterUsedAmountServiceImpl implements AmountWaterUsedAmountSe
                                         calAmount = amount;
                                         amount =  BigDecimal.ZERO;
                                     }
-                                    BaseWaterProperty baseWaterProperty= baseWaterPropertyMapper.get(waterPropertyId,siteId,customerId);
-                                    List<PayBaseWaterprice> priceList = baseWaterPropertyMapper.getFeeInfo(waterPropertyId,i,customerId,siteId);
-                                    if (priceList!=null && priceList.size() > 0) {
-                                        for (PayBaseWaterprice info : priceList) {
-                                            // 应收费用=水量 * 价格
-                                            BigDecimal debt = calAmount.multiply(info.getPrice());
-                                            fee= fee.add(debt);
+                                    if(flag){
+                                        List<PayBaseWaterprice> priceList = baseWaterPropertyMapper.getFeeInfo(waterPropertyId,i,customerId,siteId);
+                                        if (priceList!=null && priceList.size() > 0) {
+                                            for (PayBaseWaterprice info : priceList) {
+                                                // 应收费用=水量 * 价格
+                                                BigDecimal debt = calAmount.multiply(info.getPrice());
+                                                fee= fee.add(debt);
+                                            }
+                                        }
+                                    }else{
+                                        List<PayBaseWaterprice> priceList = baseWaterPropertyMapper.getFeeInfo(waterPropertyId,4,customerId,siteId);
+                                        if (priceList!=null && priceList.size() > 0) {
+                                            for (PayBaseWaterprice info : priceList) {
+                                                // 应收费用=水量 * 价格
+                                                BigDecimal debt = calAmount.multiply(info.getPrice());
+                                                fee= fee.add(debt);
+                                            }
                                         }
                                     }
                                 }
+                                if(!flag){
+                                    //年阶梯没有可用量只执行一次
+                                    break;
+                                }
                             }
                             //预存余额-用水金额=用水余额
                             balance = remaining.subtract(fee);
                         }
+                    }else{
+                        balance =  BigDecimal.ZERO;
                     }
                     //查询该户是否有历史欠费
                     BigDecimal historyDebt = payPayReceivableMapper.getHistoryDebt(siteId,customerId,accountId);

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

@@ -311,21 +311,7 @@ public class PayFeeServiceImp implements PayFeeService {
         if(transactiondetailsDtoList.size()>0){
             payTransactiondetailsMapper.batchInsert(transactiondetailsDtoList);
         }
-        //查询阀门状态,判断是否需要开阀
-        List<PayValveStateInfo> payValveStateInfos = payFeeMapper.getDeviceValveState(new BigInteger(id));
-        for(PayValveStateInfo payValveStateInfo : payValveStateInfos){
-            if(payValveStateInfo != null
-                    && payValveStateInfo.getDebt()!= null && payValveStateInfo.getDebt().compareTo(BigDecimal.ZERO) ==1
-                    && payValveStateInfo.getValveState()!= null && payValveStateInfo.getValveState().equals("0")){
-                payValveStateInfo.setOperation(1);
-                payValveStateInfo.setSiteId(BigInteger.valueOf(loginUser.getSiteId()));
-                payValveStateInfo.setCustomerId(BigInteger.valueOf(loginUser.getCustomerId()));
-                Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
-                if(!sendValveCommondResult){
-//                    result+="; 开阀异常:"+String.format("%.2f", transAmount)+"元";
-                }
-            }
-        }
+        openValveByPayFee(new BigInteger(id), loginUser.getSiteId(),loginUser.getCustomerId());
         //返回批次号
         PayfeeResult payfeeResult=new PayfeeResult();
         payfeeResult.setMsg(result);
@@ -337,7 +323,52 @@ public class PayFeeServiceImp implements PayFeeService {
 
     }
 
-   /*
+    private void openValveByPayFee(BigInteger id, Integer siteId, Integer customerId) {
+        //查询阀门状态,判断是否需要开阀
+        List<PayValveStateInfo> payValveStateInfos = payFeeMapper.getDeviceValveState(id);
+
+        List<Integer> types =new ArrayList<>();
+        types.add(2);   //欠费金额
+        types.add(3);   //预存金额
+        types.add(7);   //预存与欠费差额
+        List<PayControlRule> payControlRules = payFeeMapper.getValveRulesByType(1,types,siteId,customerId);
+
+        for(PayValveStateInfo payValveStateInfo : payValveStateInfos){
+            if(payValveStateInfo != null && payValveStateInfo.getDebt()!= null
+                    && ((payValveStateInfo.getValveState()!= null && payValveStateInfo.getValveState().equals("0"))
+                            || payValveStateInfo.getValveState() == null)){
+
+                for(PayControlRule payControlRule : payControlRules){
+                    if(payControlRule.getConditionId() == 2 && payControlRule.checkCondition(payValveStateInfo.getDebt())){
+                        payValveStateInfo.setControlRuleId(payControlRule.getId().intValue());
+                        payValveStateInfo.setOperation(1);
+                        payValveStateInfo.setSiteId(BigInteger.valueOf(siteId));
+                        payValveStateInfo.setCustomerId(BigInteger.valueOf(customerId));
+                        Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
+                        break;
+                    }
+                    if(payControlRule.getConditionId() == 3 && payControlRule.checkCondition(payValveStateInfo.getRemaining())){
+                        payValveStateInfo.setControlRuleId(payControlRule.getId().intValue());
+                        payValveStateInfo.setOperation(1);
+                        payValveStateInfo.setSiteId(BigInteger.valueOf(siteId));
+                        payValveStateInfo.setCustomerId(BigInteger.valueOf(customerId));
+                        Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
+                        break;
+                    }
+                    if(payControlRule.getConditionId() == 7 && payControlRule.checkCondition(payValveStateInfo.getRemaining().subtract(payValveStateInfo.getDebt()))){
+                        payValveStateInfo.setControlRuleId(payControlRule.getId().intValue());
+                        payValveStateInfo.setOperation(1);
+                        payValveStateInfo.setSiteId(BigInteger.valueOf(siteId));
+                        payValveStateInfo.setCustomerId(BigInteger.valueOf(customerId));
+                        Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
+    /*
     * @Description: 缴纳欠费
     * @auther: wangli
     * @date: 2020-04-22 16:35
@@ -577,21 +608,7 @@ public class PayFeeServiceImp implements PayFeeService {
          payTransactiondetailsMapper.batchInsert(transactiondetailsDtoList);
        }
 
-       //查询阀门状态,判断是否需要开阀
-       List<PayValveStateInfo> payValveStateInfos = payFeeMapper.getDeviceValveState(payCustomRechargeDto.getAccountId());
-       for(PayValveStateInfo payValveStateInfo : payValveStateInfos){
-           if(payValveStateInfo != null
-                   && payValveStateInfo.getDebt()!= null && payValveStateInfo.getDebt().compareTo(BigDecimal.ZERO) ==1
-                   && payValveStateInfo.getValveState()!= null && payValveStateInfo.getValveState().equals("0")){
-               payValveStateInfo.setOperation(1);
-               payValveStateInfo.setSiteId(BigInteger.valueOf(loginUser.getSiteId()));
-               payValveStateInfo.setCustomerId(BigInteger.valueOf(loginUser.getCustomerId()));
-               Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
-               if(!sendValveCommondResult){
-//                    result+="; 开阀异常:"+String.format("%.2f", transAmount)+"元";
-               }
-           }
-       }
+       openValveByPayFee(payCustomRechargeDto.getAccountId(), loginUser.getSiteId(),loginUser.getCustomerId());
 
         //返回批次号
        return  payseriesno;
@@ -1248,21 +1265,7 @@ public class PayFeeServiceImp implements PayFeeService {
         payAgenttransaction.setDelFlag("0");
         payAgenttransactionMapper.insertAgenttransaction(payAgenttransaction);
 
-        //查询阀门状态,判断是否需要开阀
-        List<PayValveStateInfo> payValveStateInfos = payFeeMapper.getDeviceValveState(payCustomRechargeDto.getAccountId());
-        for(PayValveStateInfo payValveStateInfo : payValveStateInfos){
-            if(payValveStateInfo != null
-                    && payValveStateInfo.getDebt()!= null && payValveStateInfo.getDebt().compareTo(BigDecimal.ZERO) ==1
-                    && payValveStateInfo.getValveState()!= null && payValveStateInfo.getValveState().equals("0")){
-                payValveStateInfo.setOperation(1);
-                payValveStateInfo.setSiteId(BigInteger.valueOf(siteId));
-                payValveStateInfo.setCustomerId(BigInteger.valueOf(customerId));
-                Boolean sendValveCommondResult = this.sendValveCommond(payValveStateInfo);
-                if(!sendValveCommondResult){    //关阀失败
-//                    result+="; 开阀异常:"+String.format("%.2f", transAmount)+"元";
-                }
-            }
-        }
+        openValveByPayFee(payCustomRechargeDto.getAccountId(), siteId,customerId);
         return new BankPayfeeMsg("9999","交易成功");
     }
 
@@ -1378,7 +1381,7 @@ public class PayFeeServiceImp implements PayFeeService {
             log.info("开关阀请求结果"+result);
             JSONObject jsonObject= JSON.parseObject(result);
             Integer status= jsonObject.getInteger("status");
-            if(status .equals("0")){   //返回正常
+            if(status == 0){   //返回正常
                 //添加阀控记录
                 PayControlRecord payControlRecord = new PayControlRecord();
                 payControlRecord.setAccountId(payValveStateInfo.getAccountId());
@@ -1388,6 +1391,8 @@ public class PayFeeServiceImp implements PayFeeService {
                 payControlRecord.setState(0);//状态为关阀
                 payControlRecord.setType(1);//开阀操作
 
+                payControlRecord.setControlRuleId(payValveStateInfo.getControlRuleId());
+
                 payControlRecord.setCreateBy(userId);
                 payControlRecord.setCreateDate(LocalDateTime.now());
                 payControlRecord.setUpdateBy(userId);

+ 16 - 6
smart-city-platform/src/main/java/com/bz/smart_city/service/importfile/AsyncTaskImportService.java

@@ -249,8 +249,22 @@ public class AsyncTaskImportService {
                                PayBaseCustomerandmeterrela device = payBaseCustomerandmeterrelaMapper.getDeviceId(loginUser.getSiteId(),loginUser.getCustomerId(),metercode);
                                //根据用水性质名称寻找用水性质id
                                PayBaseCustomerandmeterrela property = payBaseCustomerandmeterrelaMapper.getWaterPropertyId(loginUser.getSiteId(),loginUser.getCustomerId(),propertyName);
+                               List<PayControlRule> contollList = newArrayList();
+                               if(StringUtils.isNotBlank(contollName)){
+                                   //根据阀控规则查找ID
+                                   contollList =payControlRuleMapper.findList(null,contollName,customerId);
+                                   if(contollList != null && contollList.size() > 0){
+                                       if(contollList.get(0).getConditionId() == 5){
+                                           //插入阀控记录
+                                           valve.setDeviceId(device.getId());
+                                           valve.setControlState(1);
+                                           valve.setControlTime(LocalDateTime.now());
+                                           valve.setControlRuleId(contollList.get(0).getId().intValue());
+                                           valveList.add(valve);
+                                       }
+                                   }
+                               }
                                //根据阀控规则名称寻找阀控ID
-                               List<PayControlRule> contollList = payControlRuleMapper.findList(null,contollName,customerId);
                                //根据机构名称寻找机构id
                                Organization office =  null;
                                if(StringUtils.isNotBlank(officeName)){
@@ -396,11 +410,7 @@ public class AsyncTaskImportService {
                                    customerList.add(customer);
                                }
 
-                               //插入阀控记录
-                               valve.setDeviceId(device.getId());
-                               valve.setControlState(1);
-                               valve.setControlTime(LocalDateTime.now());
-                               valveList.add(valve);
+
 
                                //计算可用水量
                                if(property.getWaterPropertyId() != null){

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

@@ -444,6 +444,11 @@ public class PayBaseCustomerandmeterrelaServiceImpl implements PayBaseCustomeran
                 List<PayControlRule> RList = payBaseCustomerandmeterrelaMapper.getRuleNames(loginUser.getSiteId(),loginUser.getCustomerId(),list);
                 if (RList != null && RList.size() >0){
                     for(PayControlRule dao:RList){
+                        if(dao.getConditionId() == 5){
+                            //有开户开阀规则
+                            //往阀控表插入开阀记录
+                            payBaseCustomerandmeterrelaMapper.insertValve(device.getId(),LocalDateTime.now(),1,dao.getId().intValue());
+                        }
                         String name = dao.getName();
                         RName = RName + name +",";
                     }
@@ -489,8 +494,6 @@ public class PayBaseCustomerandmeterrelaServiceImpl implements PayBaseCustomeran
         //修改水表安装信息为已开户
         payBaseCustomerandmeterrelaMapper.updateMeterInstallOpen(2,loginUser.getUpdateBy(),LocalDateTime.now(),device.getId());
 
-        //往阀控表插入开阀记录
-        payBaseCustomerandmeterrelaMapper.insertValve(device.getId(),LocalDateTime.now(),1);
         if (customerList.size() > 0) {
             int reslut = payBaseCustomerandmeterrelaMapper.insertList(customerList);
 

+ 13 - 5
smart-city-platform/src/main/resources/mapper/PayBaseCustomerandmeterrelaMapper.xml

@@ -117,14 +117,16 @@
         (
             device_id,
             control_time,
-            control_state
+            control_state,
+            control_rule_id
         )
         values
         <foreach collection="valve" item="valve" index="index" separator=",">
             (
                 #{valve.deviceId,jdbcType=BIGINT},
                 #{valve.controlTime,jdbcType=TIMESTAMP},
-                #{valve.controlState,jdbcType=INTEGER}
+                #{valve.controlState,jdbcType=INTEGER},
+                #{valve.controlRuleId,jdbcType=INTEGER}
             )
         </foreach>
     </insert>
@@ -698,7 +700,11 @@
     </select>
 
     <select id="getRuleNames" resultType="com.bz.smart_city.entity.pay.PayControlRule">
-        select c.name from pay_control_rule c
+        select
+            c.id,
+            c.name,
+            c.condition_id as "conditionId"
+        from pay_control_rule c
         <where>
             <if test="siteId != null">
                 and c.site_id =#{siteId}
@@ -720,13 +726,15 @@
         (
             device_id,
             control_time,
-            control_state
+            control_state,
+            control_rule_id
         )
         values
         (
             #{deviceId},
             #{date},
-            #{controlState}
+            #{controlState},
+            #{controlRuleId}
         )
     </insert>
 

+ 1 - 1
smart-city-platform/src/main/resources/mapper/pay/PayControlRecordMapper.xml

@@ -143,7 +143,7 @@
         limit 1
     </select>
     <update id="updateDeviceValveState">
-        udpate sc_device  set control_status = #{valveStatus}  where metercode = #{meterCode}
+        update sc_device  set control_status = #{valveStatus}  where metercode = #{meterCode}
     </update>
     <update id="updateControlRecordResult">
         update pay_control_record set result =#{result} ,state =#{valveStatus} where id = #{id}

+ 12 - 2
smart-city-platform/src/main/resources/mapper/pay/payFeeMapper.xml

@@ -410,8 +410,10 @@
             ,d.control_status as "valveState"
             ,(select sum(debt) from pay_pay_receivable where debt>0 and account_id=#{accountId}) as "debt"
             ,cs.customer_no as "customerNo"
+            ,r.remaining
         from sc_device d
         left join pay_base_customerandmeterrela c on c.watermeter_id=d.id
+        left join pay_pay_rechargeaccount r on r.account_id = c.account_id
         left join sc_customer cs on cs.id=d.customer_id
         where c.account_id=#{accountId}
 
@@ -460,7 +462,8 @@
 
     <select id="getDeviceValveStateByRecord" resultType="com.bz.smart_city.dto.pay.payfee.PayValveStateInfo">
         select
-            c.account_id as "accountId"
+            v.control_rule_id as "controlRuleId"
+            ,c.account_id as "accountId"
             ,d.id as "meterId"
             ,d.water_meter_no as "eleno"
             ,ifnull(d.water_meter_no,d.metercode )as "metercode"
@@ -491,7 +494,14 @@
             ,value as "value"
             ,action as "action"
         from pay_control_rule
-        where `disable` = 0 and  condition_id =#{type}
+        where `disable` = 0  and site_id = #{siteId} and customer_id = #{customer}
+        <if test="action != null">and action = #{action} </if>
+        <if test="types != null and  types.size() > 0">
+            and condition_id in
+            <foreach collection="types" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
     </select>
 
 </mapper>