Parcourir la source

完善阀控规则

oppadmin il y a 4 ans
Parent
commit
9909b9bead

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

@@ -1,5 +1,6 @@
 package com.bz.smart_city.controller.pay;
 
+import com.bz.smart_city.commom.exception.ServiceException;
 import com.bz.smart_city.commom.model.AjaxMessage;
 import com.bz.smart_city.commom.model.Pagination;
 import com.bz.smart_city.commom.model.ResultStatus;
@@ -34,8 +35,7 @@ public class PayControlRecordController {
     @GetMapping("/findList")
     @ApiOperation(value="查询阀控记录",notes="查询阀控记录")
     public AjaxMessage<List<PayControlRecordDto>> findList(
-            @ApiParam(value = "用户ID", required = false) @RequestParam(required = false) String accountId,
-            @ApiParam(value = "水表ID", required = false) @RequestParam(required = false) String meterId,
+            @ApiParam(value = "水表电子号,水表档案号", required = false) @RequestParam(required = false) String meterCode,
             @ApiParam(value = "阀控规则", required = false) @RequestParam(required = false) String controlRuleId,
             @ApiParam(value = "操作类型 0关阀 1开阀", required = false) @RequestParam(required = false) String type,
             @ApiParam(value = "操作结果 0执行中 1成功 2失败", required = false) @RequestParam(required = false) String result,
@@ -47,13 +47,10 @@ public class PayControlRecordController {
             DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
             PayControlRecordDto payControlRecordDto = new PayControlRecordDto();
 
-            if(StringUtils.isNotBlank(accountId)){
-                payControlRecordDto.setAccountId(new BigInteger(accountId));
+            if(StringUtils.isNotBlank(meterCode)){
+                payControlRecordDto.setMeterCode(meterCode);
             }
 
-            if(StringUtils.isNotBlank(meterId)){
-                payControlRecordDto.setMeterId(new BigInteger(meterId));
-            }
             if(StringUtils.isNotBlank(controlRuleId)){
                 payControlRecordDto.setControlRuleId(new Integer(controlRuleId));
             }
@@ -86,8 +83,7 @@ public class PayControlRecordController {
     @GetMapping("/findPage")
     @ApiOperation(value="查询阀控记录,分页",notes="查询阀控记录,分页")
     public AjaxMessage<Pagination<PayControlRecordDto>> findPage(
-            @ApiParam(value = "用户ID", required = false) @RequestParam(required = false) String accountId,
-            @ApiParam(value = "水表ID", required = false) @RequestParam(required = false) String meterId,
+            @ApiParam(value = "水表电子号,水表档案号", required = false) @RequestParam(required = false) String meterCode,
             @ApiParam(value = "阀控规则", required = false) @RequestParam(required = false) String controlRuleId,
             @ApiParam(value = "操作类型 0关阀 1开阀", required = false) @RequestParam(required = false) String type,
             @ApiParam(value = "操作结果 0执行中 1成功 2失败", required = false) @RequestParam(required = false) String result,
@@ -101,12 +97,8 @@ public class PayControlRecordController {
             DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
             PayControlRecordDto payControlRecordDto = new PayControlRecordDto();
 
-            if(StringUtils.isNotBlank(accountId)){
-                payControlRecordDto.setAccountId(new BigInteger(accountId));
-            }
-
-            if(StringUtils.isNotBlank(meterId)){
-                payControlRecordDto.setMeterId(new BigInteger(meterId));
+            if(StringUtils.isNotBlank(meterCode)){
+                payControlRecordDto.setMeterCode(meterCode);
             }
             if(StringUtils.isNotBlank(controlRuleId)){
                 payControlRecordDto.setControlRuleId(new Integer(controlRuleId));
@@ -137,5 +129,26 @@ public class PayControlRecordController {
         }
     }
 
+    @GetMapping("/findByYear")
+    @ApiOperation(value="查询阀控记录(按年)",notes="查询阀控记录(按年)")
+    public AjaxMessage<List<PayControlRecordDto>> findByYear(
+            @ApiParam(value = "客户编号", required = true) @RequestParam(required = true) String accountNumber,
+            @ApiParam(value = "年份yyyy", required = true) @RequestParam(required = true) String year
+    ){
+        try {
+            if(StringUtils.isBlank(accountNumber)){
+                new ServiceException(-99,"客户编号不能为空");
+            }
+            if(StringUtils.isBlank(year)){
+                new ServiceException(-99,"年份不能为空");
+            }
+            List<PayControlRecordDto> payControlRecordList = payControlRecordService.findByYear(accountNumber,new Integer(year));
+            return new AjaxMessage<>(ResultStatus.OK,payControlRecordList);
+        }
+        catch (Exception ex){
+            return  new AjaxMessage<>(-99,ex.getMessage(),null);
+        }
+    }
+
 
 }

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

@@ -29,7 +29,7 @@ public class PayControlRuleController {
     PayControlRuleService payControlRuleService;
 
     @PostMapping("/adds")
-    @ApiModelProperty(value = "添加阀控规则",notes = "添加阀控规则")
+    @ApiOperation(value = "添加阀控规则",notes = "添加阀控规则")
     public AjaxMessage adds(
             @ApiParam(value = "阀控规则",required = true) @RequestBody(required = true) @Validated List<PayControlRule> payControlRules
     ){
@@ -61,7 +61,7 @@ public class PayControlRuleController {
     }
 
     @PostMapping("/edit")
-    @ApiModelProperty(value = "编辑阀控规则",notes = "编辑阀控规则")
+    @ApiOperation(value = "编辑阀控规则",notes = "编辑阀控规则")
     public AjaxMessage edit(
             @ApiParam(value = "阀控规则",required = true) @RequestBody(required = true) @Validated PayControlRule payControlRule
     ){
@@ -84,7 +84,7 @@ public class PayControlRuleController {
     }
 
     @GetMapping("/findList")
-    @ApiModelProperty(value = "查询阀控规则",notes = "查询阀控规则")
+    @ApiOperation(value = "查询阀控规则",notes = "查询阀控规则")
     public AjaxMessage<List<PayControlRule>> findList(
             @ApiParam(value = "阀控规则名称",required = false) @RequestBody(required = false) String name
     ){
@@ -129,4 +129,23 @@ public class PayControlRuleController {
             return  new AjaxMessage<>(-99,ex.getMessage(),null);
         }
     }
+
+    @GetMapping("/disable")
+    @ApiOperation(value = "停用阀控规则",notes = "停用阀控规则")
+    public AjaxMessage disable(
+            @ApiParam(value = "id",required = true) @RequestParam(required = true) String id,
+            @ApiParam(value = "停用标志 0启用 1停用",required = true) @RequestParam(required = true) String disable
+    ){
+        try {
+            Integer result = payControlRuleService.disable(id,disable);
+            if(result != null && result >0)
+                return new AjaxMessage<>(ResultStatus.OK);
+
+            return new AjaxMessage<>(ResultStatus.ERROR);
+        }
+        catch (Exception ex){
+            return  new AjaxMessage<>(-99,ex.getMessage(),null);
+        }
+    }
+
 }

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

@@ -18,9 +18,10 @@ public interface PayControlRecordMapper {
     Integer add(@Param("payControlRecord")PayControlRecord payControlRecord);
 
     //查询
-
     List<PayControlRecordDto> findList(@Param("payControlRecordDto") PayControlRecordDto payControlRecordDto);
 
+    List<PayControlRecordDto> findByYear(@Param("accountNumber") String accountNumber,@Param("year") Integer year);
+
     PayControlRecord findControlRecordByMetercode(@Param("meterCode") String meterCode);
 
     Integer updateDeviceValveState(@Param("valveStatus") String valveStatus,@Param("meterCode") String meterCode);

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

@@ -23,6 +23,9 @@ public interface PayControlRuleMapper {
 
     Integer delete(@Param("id") String id);
 
+    //规则已使用
+    String isUsed(@Param("id") Integer id,@Param("customerId") BigInteger customerId);
+
     //数据是否存在
     List<PayControlRule>ExitsData(@Param("id") String id,@Param("name") String name,@Param("customerId") BigInteger customerId);
 

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

@@ -17,15 +17,15 @@ import java.time.LocalDateTime;
 public class PayControlRecordDto extends PayControlRecord {
 
     @ApiModelProperty(value = "水表电子号")
-    private LocalDateTime waterMeterNo;
+    private String waterMeterNo;
     @ApiModelProperty(value = "水表档案号")
-    private LocalDateTime meterCode;
+    private String meterCode;
     @ApiModelProperty(value = "设备型号")
-    private LocalDateTime deviceModel;
+    private String deviceModel;
     @ApiModelProperty(value = "设备状态")
-    private LocalDateTime controlStatus;
+    private String controlStatus;
     @ApiModelProperty(value = "安装地址")
-    private LocalDateTime locDesc;
+    private String locDesc;
 
     @ApiModelProperty(value = "开始时间",  hidden = true)
     @JsonIgnore

+ 7 - 0
smart-city-platform/src/main/java/com/bz/smart_city/service/impl/pay/PayControlRecordServiceImpl.java

@@ -8,6 +8,7 @@ import com.bz.smart_city.dto.pay.PayControlRecordDto;
 import com.bz.smart_city.entity.pay.PayControlRecord;
 import com.bz.smart_city.service.pay.PayControlRecordService;
 import com.github.pagehelper.PageHelper;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -28,6 +29,12 @@ public class PayControlRecordServiceImpl implements PayControlRecordService {
         return payControlRecordMapper.findList(payControlRecordDto);
     }
 
+    @Override
+    public List<PayControlRecordDto> findByYear(String accountNumber, Integer year)
+    {
+        return payControlRecordMapper.findByYear(accountNumber,year);
+    }
+
     @Override
     public Pagination<PayControlRecordDto> findPage(PayControlRecordDto payControlRecordDto, int pageNum, int pageSize)
     {

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

@@ -14,6 +14,8 @@ import com.bz.smart_city.entity.pay.PayControlRule;
 import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
 import com.bz.smart_city.service.pay.PayControlRuleService;
 import com.github.pagehelper.PageHelper;
+import com.sun.org.apache.bcel.internal.generic.ISUB;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -50,6 +52,7 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
         payControlRule.setUpdateBy(new BigInteger(String.valueOf(loginUser.getId())));
         payControlRule.setUpdateDate(LocalDateTime.now());
         payControlRule.setDelFlag("0");
+        payControlRule.setDisable("0");
 
         Integer result = payControlRuleMapper.add(payControlRule);
         return  result;
@@ -88,15 +91,59 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
         if(ExitsData(null,payControlRule.getName(),new BigInteger(String.valueOf(loginUser.getCustomerId()))))
             throw new ServiceException(-99,"该阀控规则已存在!");
 
+        if(IsUsed(payControlRule.getId().intValue(),new BigInteger(loginUser.getCustomerId().toString()))){
+            throw new ServiceException(-99,"该阀控规则已有客户使用,如编辑会对应用客户有影响,是否继续?");
+        }
+
         Integer result = payControlRuleMapper.edit(payControlRule);
         return  result;
     }
 
     @Override
     public Integer delete(String id){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        if(IsUsed(Integer.parseInt(id),new BigInteger(loginUser.getCustomerId().toString()))){
+            throw new ServiceException(-99,"该阀控规则已有用户应用,无法删除。请对相关户重新设定规则后再进行删除。");
+        }
         return payControlRuleMapper.delete(id);
     }
 
+    @Override
+    public Integer disable(String id,String disable){
+        LoginUser loginUser = UserUtil.getCurrentUser();
+
+        if(disable.equals("1")){
+            if(IsUsed(Integer.parseInt(id),new BigInteger(loginUser.getCustomerId().toString()))){
+                throw new ServiceException(-99,"该阀控规则已有用户应用,关闭后将对所有对应用户停用该规则,是否继续?");
+            }
+        }
+
+        PayControlRule payControlRule = new PayControlRule();
+        payControlRule.setId(new BigInteger(id));
+        payControlRule.setDisable(disable);
+
+        Integer result = payControlRuleMapper.edit(payControlRule);
+        return  result;
+    }
+
+    /**
+     * 阀控规则已使用
+     * @param id 规则id
+     * @param custoemrId
+     * @return true已使用
+     */
+    public boolean IsUsed(Integer id,BigInteger custoemrId){
+        String result = payControlRuleMapper.isUsed(id,custoemrId);
+        String[] sp = result.split(",");
+        if(sp != null && sp.length > 0){
+            for (int i=0;i<sp.length;i++)
+            {
+                if(sp[i].equals(id.toString()))
+                    return true;
+            }
+        }
+        return false;
+    }
 
     /**
      * 判断数据是否存在

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

@@ -16,4 +16,6 @@ public interface PayControlRecordService {
 
     Pagination<PayControlRecordDto> findPage(PayControlRecordDto payControlRecordDto,int pageNum, int pageSize);
 
+    List<PayControlRecordDto>findByYear(String accountNumber, Integer year);
+
 }

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

@@ -25,6 +25,8 @@ public interface PayControlRuleService {
 
     Integer delete(String id);
 
+    Integer disable(String id,String disable);
+
     //欠费天数
     boolean ConditionDebtDay(String accountId,String condition,String value);
 

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

@@ -37,10 +37,41 @@
             <if test="payControlRecordDto.state != null"> and pcr.state = #{payControlRecordDto.state}</if>
             <if test="payControlRecordDto.beginTime != null"> and pcr.update_Date >= #{payControlRecordDto.beginTime,jdbcType=TIMESTAMP}</if>
             <if test="payControlRecordDto.endTime != null"> and pcr.update_Date &lt;= #{payControlRecordDto.endTime,jdbcType=TIMESTAMP}</if>
+            <if test="payControlRecordDto.meterCode != null and payControlRecordDto.meterCode != ''">
+             and (sc.metercode like concat('%',#{payControlRecordDto.meterCode},'%')
+              or sc.water_meter_no like concat('%',#{payControlRecordDto.meterCode},'%')
+             )
+             </if>
         </where>
         order by pcr.update_date desc
     </select>
 
+    <select id="findByYear" resultType="com.bz.smart_city.dto.pay.PayControlRecordDto">
+        select
+        pcr.id,
+        pcr.account_id,
+        pcr.meter_id,
+        pcr.type,
+        pcr.result,
+        pcr.state,
+        pcr.control_rule_id,
+        pcr.create_by,
+        pcr.create_date,
+        pcr.update_by,
+        pcr.update_date,
+        pcr.remarks,
+        pcr.site_id,
+        pcr.customer_id,
+        pcrule.name as controlRuleIdName
+        from pay_control_record pcr
+        left join pay_base_account pba on pcr.account_id = pba.id
+        left join pay_control_rule pcrule on pcr.control_rule_id = pcrule.id
+        where
+        pba.accountnumber = #{accountNumber}
+        and DATE_FORMAT(pcr.create_date,'%Y')=#{year}
+
+    </select>
+
     <insert id="add" useGeneratedKeys="true" keyColumn="id">
         insert into pay_control_record(
         account_id,

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

@@ -30,7 +30,6 @@
         #{payControlRule.action,jdbcType=VARCHAR},
         #{payControlRule.unit,jdbcType=VARCHAR},
         #{payControlRule.disable,jdbcType=VARCHAR},
-
         #{payControlRule.createBy,jdbcType=BIGINT},
         #{payControlRule.createDate,jdbcType=TIMESTAMP},
         #{payControlRule.updateBy,jdbcType=BIGINT},
@@ -98,6 +97,14 @@
 
     </select>
 
+    <select id="isUsed" resultType="string">
+        select valve_rule_id
+        from pay_base_customerandmeterrela
+        WHERE valve_rule_id like concat('%',#{id},'%')
+        <if test="customerId != null and customerId != ''"> and customer_id = #{customerId}</if>
+        limit 1
+    </select>
+
     <delete id="delete">
         update pay_control_rule set del_flag = 1 where id = #{id,jdbcType=INTEGER}
     </delete>