Browse Source

阀控修改

oppadmin 4 years ago
parent
commit
39144f42f4

+ 0 - 3
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayControlRecordController.java

@@ -5,8 +5,6 @@ import com.bz.smart_city.commom.model.AjaxMessage;
 import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.dto.pay.PayControlRecordDto;
-import com.bz.smart_city.entity.pay.PayControlRecord;
-import com.bz.smart_city.entity.pay.PayControlRule;
 import com.bz.smart_city.service.pay.PayControlRecordService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -16,7 +14,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
-import java.math.BigInteger;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;

+ 0 - 1
smart-city-platform/src/main/java/com/bz/smart_city/controller/pay/PayControlRuleController.java

@@ -6,7 +6,6 @@ import com.bz.smart_city.commom.model.ResultStatus;
 import com.bz.smart_city.entity.pay.PayControlRule;
 import com.bz.smart_city.service.pay.PayControlRuleService;
 import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiModelProperty;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import org.apache.commons.lang3.StringUtils;

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

@@ -1,6 +1,7 @@
 package com.bz.smart_city.dao.pay;
 
 import com.bz.smart_city.dto.pay.PayPayReceivableDto;
+import com.bz.smart_city.entity.Device;
 import com.bz.smart_city.entity.pay.PayControlRule;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -41,4 +42,5 @@ public interface PayControlRuleMapper {
     //开户状态
     Integer findOpenUse(@Param("accountId") String accountId);
 
+    Device findDevice(@Param("watermeterId") BigInteger watermeterId);
 }

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

@@ -124,4 +124,6 @@ public class Device {
     @ApiModelProperty(value = "水表起度")
     private String newMeterStart;
 
+    @ApiModelProperty(value = "阀门状态")
+    private Integer controlStatus;
 }

+ 73 - 69
smart-city-platform/src/main/java/com/bz/smart_city/quartz/service/impl/ControlDayServiceImpl.java

@@ -9,8 +9,8 @@ import com.bz.smart_city.dao.pay.PayMessagetemplateMapper;
 import com.bz.smart_city.dao.pay.archives.PayBaseCustomerandmeterrelaMapper;
 import com.bz.smart_city.dto.pay.PayMessageTemplateDto;
 import com.bz.smart_city.entity.Customer;
+import com.bz.smart_city.entity.Device;
 import com.bz.smart_city.entity.SyncValveResult;
-import com.bz.smart_city.entity.SyncValveSend;
 import com.bz.smart_city.entity.pay.PayControlRecord;
 import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
 import com.bz.smart_city.quartz.entity.QuartzEntity;
@@ -21,18 +21,10 @@ import com.bz.smart_city.service.pay.PayControlRecordService;
 import com.bz.smart_city.service.pay.PayControlRuleService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.InitializingBean;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Component;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import java.math.BigInteger;
@@ -143,78 +135,90 @@ public class ControlDayServiceImpl implements ControlDayService, InitializingBea
        return "";
     }
 
-
     public void start(int flag,BigInteger siteId,BigInteger customerId){
         PayBaseCustomerandmeterrela customer = new PayBaseCustomerandmeterrela();
         customer.setCustomerId(customerId);
         customer.setSiteId(siteId);
         List<PayBaseCustomerandmeterrela> payBaseCustomerandmeterrelaList = payBaseCustomerandmeterrelaMapper.findList(customer);
         if(payBaseCustomerandmeterrelaList.size() > 0){
-
             Customer customerNo = customerMapper.findById(customer.getCustomerId().intValue());
+            List<Integer> filterId = new ArrayList<>();
+            filterId.add(1);
+            filterId.add(3);
+            filterId.add(7);
             for (PayBaseCustomerandmeterrela one: payBaseCustomerandmeterrelaList){
-                String[] deviceType  = StringUtils.split(one.getValveRuleId(),",");
-                String[] deviceTypeName  = StringUtils.split(one.getValveRuleName(),",");
-                //循环用户关联的所有阀控规则
-                Integer ControlResult = null;
-                if(deviceType != null ){
-                    for (int i=0;i<deviceType.length;i++){
-                        //result执行动作,0关阀 1开阀
-                        List<Integer> filterId = new ArrayList<>();
-                        filterId.add(2);
-                        filterId.add(4);
-                        filterId.add(5);
-                        Integer result = payControlRuleService.GetConditionReusl(new Integer(deviceType[i]),one.getAccountId().toString(),flag,filterId);
-                        if(result != null){
-                            try {
-                                //后面规则执行动作与前面一样不操作
-                                if(ControlResult == result.intValue())
-                                    continue;
-                                ControlResult = result;
-
-                                //最近一次阀控动作如果与当前一致则不操作
-                                PayControlRecord payControlRecordTemp = new PayControlRecord();
-                                payControlRecordTemp.setAccountId(one.getAccountId());
-                                PayControlRecord payControlRecordLast = payControlRecordService.getRecord(payControlRecordTemp);
-                                if(payControlRecordLast != null){
-                                    if(payControlRecordLast.getType().intValue() == result){
-                                        continue;
-                                    }
-                                }
-
-                                //执行动作与阀门当前状态一致不操作
-
-
-
-                                //调用阀门接口
-                                String url=SyncUrl + "/api/platform/sendCommond";
-                                String params = String.format("?customerNo=%s&meterNo=%s&type=%s",customerNo.getCustomerNo(),one.getMetercode(),result.toString());
-                                url += params;
-                                String postResult = HttpRequest.doPost(url ,"");
-                                SyncValveResult syncValveResult = JacksonUtil.string2Obj(postResult, SyncValveResult.class);
-                                Integer getResult = Integer.parseInt(syncValveResult.getStatus());
-                                if(getResult != null && getResult == 0){
-                                    //插入数据库
-                                    PayControlRecord payControlRecord = new PayControlRecord();
-                                    payControlRecord.setAccountId(one.getAccountId());
-                                    payControlRecord.setMeterId(one.getWatermeterId());
-                                    payControlRecord.setType(result);
-                                    payControlRecord.setControlRuleId(new Integer(deviceType[i]));
-                                    payControlRecord.setControlRuleIdName(deviceTypeName[i]);
-                                    payControlRecord.setDelFlag("0");
-                                    payControlRecord.setCustomerId(customer.getCustomerId());
-                                    payControlRecord.setSiteId(customer.getSiteId());
-                                    payControlRecord.setCreateDate(LocalDateTime.now());
-                                    payControlRecordMapper.add(payControlRecord);
-                                }
-                            }
-                            catch (Exception e){
-                                e.printStackTrace();
+                sendValve(customerNo.getCustomerNo(),flag,filterId,one);
+            }
+        }
+    }
+
+    /**
+     *
+     * @param customerNo 客户编号
+     * @param flag  阀门动作
+     * @param ConditionIds 阀控条件
+     * @param one 开户信息
+     */
+    public void sendValve(String customerNo,int flag,List<Integer> ConditionIds,PayBaseCustomerandmeterrela one){
+
+        String[] deviceType  = StringUtils.split(one.getValveRuleId(),",");
+        String[] deviceTypeName  = StringUtils.split(one.getValveRuleName(),",");
+        //循环用户关联的所有阀控规则
+        Integer ControlResult = null;
+        if(deviceType != null ){
+            for (int i=0;i<deviceType.length;i++){
+                //result执行动作,0关阀 1开阀
+                Integer result = payControlRuleService.GetConditionReusl(new Integer(deviceType[i]),one.getAccountId().toString(),flag,ConditionIds);
+                if(result != null){
+                    try {
+                        //后面规则执行动作与前面一样不操作
+                        if(ControlResult == result.intValue())
+                            continue;
+                        ControlResult = result;
+
+                        //最近一次阀控动作如果与当前一致则不操作
+                        PayControlRecord payControlRecordTemp = new PayControlRecord();
+                        payControlRecordTemp.setAccountId(one.getAccountId());
+                        PayControlRecord payControlRecordLast = payControlRecordService.getRecord(payControlRecordTemp);
+                        if(payControlRecordLast != null){
+                            if(payControlRecordLast.getType().intValue() == result){
+                                continue;
                             }
                         }
+
+                        //执行动作与阀门当前状态一致不操作
+                        Device device = payControlRuleService.findDevice(one.getWatermeterId());
+                        if(device != null && device.getControlStatus() != null){
+                            if(device.getControlStatus().intValue() == result)
+                                continue;
+                        }
+
+                        //调用阀门接口
+                        String url=SyncUrl + "/api/platform/sendCommond";
+                        String params = String.format("?customerNo=%s&meterNo=%s&type=%s",customerNo,one.getMetercode(),result.toString());
+                        url += params;
+                        String postResult = HttpRequest.doPost(url ,"");
+                        SyncValveResult syncValveResult = JacksonUtil.string2Obj(postResult, SyncValveResult.class);
+                        Integer getResult = Integer.parseInt(syncValveResult.getStatus());
+                        if(getResult != null && getResult == 0){
+                            //插入数据库
+                            PayControlRecord payControlRecord = new PayControlRecord();
+                            payControlRecord.setAccountId(one.getAccountId());
+                            payControlRecord.setMeterId(one.getWatermeterId());
+                            payControlRecord.setType(result);
+                            payControlRecord.setControlRuleId(new Integer(deviceType[i]));
+                            payControlRecord.setControlRuleIdName(deviceTypeName[i]);
+                            payControlRecord.setDelFlag("0");
+                            payControlRecord.setCustomerId(one.getCustomerId());
+                            payControlRecord.setSiteId(one.getSiteId());
+                            payControlRecord.setCreateDate(LocalDateTime.now());
+                            payControlRecordMapper.add(payControlRecord);
+                        }
+                    }
+                    catch (Exception e){
+                        e.printStackTrace();
                     }
                 }
-
             }
         }
     }

+ 14 - 4
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayControlRuleServiceImpl.java

@@ -9,6 +9,7 @@ import com.bz.smart_city.dao.pay.PayRechargeaccountMapper;
 import com.bz.smart_city.dao.pay.archives.PayBaseCustomerandmeterrelaMapper;
 import com.bz.smart_city.dto.LoginUser;
 import com.bz.smart_city.dto.pay.PayRechargeaccountDto;
+import com.bz.smart_city.entity.Device;
 import com.bz.smart_city.entity.pay.PayControlRecord;
 import com.bz.smart_city.entity.pay.PayControlRule;
 import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
@@ -477,11 +478,12 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
      *
      * @param id    阀控规则ID
      * @param accountId
-     * @param flag 过滤执行动作 1只执行开阀,0只执行关阀
+     * @param flag 只执行指定动作 1只执行开阀,0只执行关阀 2开关阀都执行
+     * @param ConditionIds 只执行指定阀控条件
      * @return
      */
     @Override
-    public Integer GetConditionReusl(Integer id,String accountId,int flag,List<Integer> filterId){
+    public Integer GetConditionReusl(Integer id,String accountId,int flag,List<Integer> ConditionIds){
         //["=", "≠", ">", "<", "≥", "≤"]
         List<PayControlRule> payControlRules = payControlRuleMapper.findList(id,null,null);
 
@@ -494,8 +496,11 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
             }
 
             //过滤规则ID
-            if(filterId.contains(payControlRules.get(0).getConditionId()))
-                return null;
+            if(ConditionIds != null){
+                if(!ConditionIds.contains(payControlRules.get(0).getConditionId()))
+                    return null;
+            }
+
 
             String condition= payControlRules.get(0).getOperator().toString();
             int conditionValue= Integer.valueOf(condition);
@@ -563,4 +568,9 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
         }
         return null;
     }
+
+    @Override
+    public Device findDevice(BigInteger watermeterId){
+        return payControlRuleMapper.findDevice(watermeterId);
+    }
 }

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

@@ -1,9 +1,10 @@
 package com.bz.smart_city.service.pay;
 
 import com.bz.smart_city.commom.model.Pagination;
-import com.bz.smart_city.entity.pay.PayControlRecord;
+import com.bz.smart_city.entity.Device;
 import com.bz.smart_city.entity.pay.PayControlRule;
 
+import java.math.BigInteger;
 import java.util.List;
 
 /**
@@ -48,5 +49,7 @@ public interface PayControlRuleService {
     //预存与欠费差额
     boolean ConditionRechargeAndDebt(String accountId,String condition,String value);
 
-    Integer GetConditionReusl(Integer id,String accountId,int flag,List<Integer> filterId);
+    Integer GetConditionReusl(Integer id,String accountId,int flag,List<Integer> ConditionIds);
+
+    Device findDevice(BigInteger watermeterId);
 }

+ 6 - 0
smart-city-platform/src/main/resources/mapper/pay/PayControlRuleMapper.xml

@@ -159,4 +159,10 @@
         from  sc_device scd
         where scd.account_id = #{accountId}
     </select>
+
+    <select id="findDevice" resultType="com.bz.smart_city.entity.Device">
+        select control_status
+        from sc_device
+        where id = #{watermeterId}
+    </select>
 </mapper>