Browse Source

支持批量添加阀控规则

oppadmin 4 năm trước cách đây
mục cha
commit
4c8073a24c

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

@@ -28,30 +28,31 @@ public class PayControlRuleController {
     @Autowired
     PayControlRuleService payControlRuleService;
 
-    @PostMapping("/add")
+    @PostMapping("/adds")
     @ApiModelProperty(value = "添加阀控规则",notes = "添加阀控规则")
-    public AjaxMessage add(
-            @ApiParam(value = "阀控规则",required = true) @RequestBody(required = true) @Validated PayControlRule payControlRule
+    public AjaxMessage adds(
+            @ApiParam(value = "阀控规则",required = true) @RequestBody(required = true) @Validated List<PayControlRule> payControlRules
     ){
         try {
-            if(StringUtils.isBlank(payControlRule.getName()))
-                throw new Exception("阀控规则名称不能为空");
-            if(StringUtils.isBlank(payControlRule.getCondition()))
-                throw new Exception("阀控规则判断条件不能为空");
-            if(StringUtils.isBlank(payControlRule.getOperator()))
-                throw new Exception("阀控规则运算符不能为空");
-            if(StringUtils.isBlank(payControlRule.getValue()))
-                throw new Exception("阀控规则条件值不能为空");
-            if(StringUtils.isBlank(payControlRule.getAction()))
-                throw new Exception("阀控规则执行操作不能为空");
+            for (PayControlRule payControlRule:payControlRules){
+                if(StringUtils.isBlank(payControlRule.getName()))
+                    throw new Exception("阀控规则名称不能为空");
+                if(StringUtils.isBlank(payControlRule.getCondition()))
+                    throw new Exception("阀控规则判断条件不能为空");
+                if(StringUtils.isBlank(payControlRule.getOperator()))
+                    throw new Exception("阀控规则运算符不能为空");
+                if(StringUtils.isBlank(payControlRule.getValue()))
+                    throw new Exception("阀控规则条件值不能为空");
+                if(StringUtils.isBlank(payControlRule.getAction()))
+                    throw new Exception("阀控规则执行操作不能为空");
+            }
 
-            Integer result = payControlRuleService.add(payControlRule);
+            Integer result = payControlRuleService.adds(payControlRules);
             if(result != null){
                 if(result == 1){
                     return new AjaxMessage(ResultStatus.OK);
                 }
             }
-
             return new AjaxMessage(ResultStatus.ERROR);
         }
         catch (Exception ex){

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

@@ -15,6 +15,7 @@ import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
 import com.bz.smart_city.service.pay.PayControlRuleService;
 import com.github.pagehelper.PageHelper;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
@@ -54,6 +55,16 @@ public class PayControlRuleServiceImpl implements PayControlRuleService {
         return  result;
     }
 
+    @Override
+    @Transactional
+    public Integer adds(List<PayControlRule> payControlRuleList){
+        for (PayControlRule payControlRule :payControlRuleList){
+            if( add(payControlRule) <0 )
+                throw new ServiceException(-99,"插入失败");
+        }
+        return 1;
+    }
+
     @Override
     public List<PayControlRule>findList(String name){
         LoginUser loginUser = UserUtil.getCurrentUser();

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

@@ -14,6 +14,8 @@ public interface PayControlRuleService {
     //添加规则
     Integer add(PayControlRule payControlRule);
 
+    Integer adds(List<PayControlRule> payControlRuleList);
+
     //查询规则
     List<PayControlRule> findList(String name);
 

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

@@ -66,7 +66,7 @@
             del_flag = 0
             <if test="customerId != null"> and customer_id = #{customerId} </if>
             <if test="id != null"> and id = #{id}</if>
-            <if test="name != null and name != ''"> and name = #{name}</if>
+            <if test="name != null and name != ''"> and name LIKE concat('%',#{name},'%')</if>
         </where>
         order by update_date desc
     </select>