523096025 2 лет назад
Родитель
Сommit
23b48bb1cf

+ 5 - 0
huimv-admin/src/main/java/com/huimv/admin/mapper/SysAccountMultilevelMapper.java

@@ -2,8 +2,12 @@ package com.huimv.admin.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.huimv.admin.entity.SysAccountMultilevel;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
+import javax.naming.Name;
+import java.util.List;
+
 /**
  * <p>
  *  Mapper 接口
@@ -15,4 +19,5 @@ import org.springframework.stereotype.Repository;
 @Repository
 public interface SysAccountMultilevelMapper extends BaseMapper<SysAccountMultilevel> {
 
+    List<Integer> getLowerLevel(@Param("userId") Integer userId, @Param("farmId") String farmId);
 }

+ 1 - 0
huimv-admin/src/main/java/com/huimv/admin/service/ISysAccountMultilevelService.java

@@ -29,4 +29,5 @@ public interface ISysAccountMultilevelService extends IService<SysAccountMultile
     Result getLastFarmId(Integer userId);
 
     Result listSubordinateByFarm(String farmId, Integer userId);
+
 }

+ 30 - 19
huimv-admin/src/main/java/com/huimv/admin/service/impl/EnvWarningThresholdServiceImpl.java

@@ -23,6 +23,7 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * <p>
@@ -38,17 +39,13 @@ public class EnvWarningThresholdServiceImpl extends ServiceImpl<EnvWarningThresh
     @Autowired
     EnvWarningThresholdMapper envWarningThresholdMapper;
     @Autowired
-    ISysAccountMultilevelService accountMultilevelService;
+    SysAccountMultilevelMapper sysAccountMultilevelMapper;
     @Override
     public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
         String farmId = paramsMap.get("farmId");
-        Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
-        QueryWrapper<SysAccountMultilevel> wrapper = new QueryWrapper<>();
-        wrapper.like("pids",userId);
-        wrapper.like("farm_ids",farmId);
-        List<SysAccountMultilevel> page = accountMultilevelService.list( wrapper);
-        List<Integer> userIds = page.stream().map(SysAccountMultilevel::getId).collect(Collectors.toList());
 
+        Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
+        List<Integer> userIds =sysAccountMultilevelMapper.getLowerLevel( userId,farmId);
         List<Integer> collect =new ArrayList<>();
         QueryWrapper<EnvWarningThreshold> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("farm_id", farmId);
@@ -58,6 +55,7 @@ public class EnvWarningThresholdServiceImpl extends ServiceImpl<EnvWarningThresh
         if (StringUtils.isNotBlank(userIds1)){
             collect = Arrays.stream(userIds1.split(",")).map(Integer::valueOf).filter(userIds::contains).collect(Collectors.toList());
         }
+
         if (ObjectUtil.isEmpty(envWarningThreshold)) {
             jsonObject.put("maxTem", 0);
             jsonObject.put("minTem", 0);
@@ -88,13 +86,30 @@ public class EnvWarningThresholdServiceImpl extends ServiceImpl<EnvWarningThresh
         String minHum = paramsMap.get("minHum");*/
         String maxNh3= paramsMap.get("maxNh3");
         String maxCo = paramsMap.get("maxCo");
-        //去掉
-       /* Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
-        QueryWrapper<SysAccountMultilevel> wrapper = new QueryWrapper<>();
-        wrapper.like("pids",userId);
-        wrapper.like("farm_ids",farmId);
-        List<SysAccountMultilevel> page = accountMultilevelService.list( wrapper);
-        List<Integer> userIds = page.stream().map(SysAccountMultilevel::getId).collect(Collectors.toList());*/
+
+        QueryWrapper<EnvWarningThreshold> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("farm_id", farmId);
+        EnvWarningThreshold envWarningThreshold = envWarningThresholdMapper.selectOne(queryWrapper);
+
+        //去掉属于该人物的id
+        Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
+        //下属id
+        List<Integer> lowerLevelIds = sysAccountMultilevelMapper.getLowerLevel( userId,farmId);
+        //上传id
+        List<Integer> uoloadIds = new ArrayList<>();
+        if (StringUtils.isNotBlank(userIds)){
+            uoloadIds = Arrays.stream(userIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
+        }
+        //现有id
+        String oldUserIds = envWarningThreshold.getUserIds();
+        List<Integer> oldUsersIds = new ArrayList<>();
+        if (StringUtils.isNotBlank(oldUserIds)){
+            oldUsersIds = Arrays.stream(oldUserIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
+        }
+        // 现有 -下属 + 上传
+        oldUsersIds.removeAll(lowerLevelIds);
+        oldUsersIds.addAll(uoloadIds);
+
 
         EnvWarningThreshold threshold = new EnvWarningThreshold();
       /*  threshold.setMaxHum(maxHum);
@@ -103,7 +118,7 @@ public class EnvWarningThresholdServiceImpl extends ServiceImpl<EnvWarningThresh
         threshold.setMinTem(minTem);
         threshold.setMaxNh3(maxNh3);
         threshold.setMaxCo(maxCo);
-        threshold.setUserIds(userIds);
+        threshold.setUserIds( oldUsersIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
         threshold.setFarmId(Integer.parseInt(farmId));
 
         if (Integer.parseInt(maxTem) < Integer.parseInt(minTem)) {
@@ -111,16 +126,12 @@ public class EnvWarningThresholdServiceImpl extends ServiceImpl<EnvWarningThresh
         } /*else if (Integer.parseInt(maxHum) < Integer.parseInt(minHum)) {
             return new Result(10001, "最高湿度不能小于最低湿度", false);
         } */else {
-            QueryWrapper<EnvWarningThreshold> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq("farm_id", farmId);
-            EnvWarningThreshold envWarningThreshold = envWarningThresholdMapper.selectOne(queryWrapper);
             if (ObjectUtil.isEmpty(envWarningThreshold)) {
                 envWarningThresholdMapper.insert(threshold);
             } else {
                 threshold.setId(envWarningThreshold.getId());
                 envWarningThresholdMapper.updateById(threshold);
             }
-
         }
         return Result.SUCCESS();
     }

+ 51 - 5
huimv-admin/src/main/java/com/huimv/admin/service/impl/GasThresholdServiceImpl.java

@@ -3,9 +3,13 @@ package com.huimv.admin.service.impl;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.huimv.admin.common.token.TokenSign;
 import com.huimv.admin.common.utils.ResultCode;
+import com.huimv.admin.entity.EnvWarningThreshold;
 import com.huimv.admin.entity.GasThreshold;
 import com.huimv.admin.mapper.GasThresholdMapper;
+import com.huimv.admin.mapper.SysAccountMultilevelMapper;
 import com.huimv.admin.service.IGasThresholdService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -13,8 +17,12 @@ import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletRequest;
 import com.huimv.admin.common.utils.Result;
+
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -29,9 +37,24 @@ public class GasThresholdServiceImpl extends ServiceImpl<GasThresholdMapper, Gas
 
     @Autowired
     private GasThresholdMapper gasThresholdMapper;
+    @Autowired
+    SysAccountMultilevelMapper sysAccountMultilevelMapper;
     @Override
     public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
         String farmId = paramsMap.get("farmId");
+
+        Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
+        List<Integer> userIds =sysAccountMultilevelMapper.getLowerLevel( userId,farmId);
+        List<Integer> collect =new ArrayList<>();
+        QueryWrapper<GasThreshold> wrapper = new QueryWrapper<>();
+        wrapper.eq("farm_id", farmId);
+        GasThreshold envWarningThreshold = gasThresholdMapper.selectOne(wrapper);
+        String userIds1 = envWarningThreshold.getUserIds();
+        if (StringUtils.isNotBlank(userIds1)){
+            collect = Arrays.stream(userIds1.split(",")).map(Integer::valueOf).filter(userIds::contains).collect(Collectors.toList());
+        }
+
+
         QueryWrapper<GasThreshold> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("farm_id", farmId);
         List<GasThreshold> gasThresholds = gasThresholdMapper.selectList(queryWrapper);
@@ -61,7 +84,7 @@ public class GasThresholdServiceImpl extends ServiceImpl<GasThresholdMapper, Gas
                     jsonObject.put("people", gasThreshold);
                 }
             }
-            jsonObject.put("userIds", gasThresholds.get(1).getUserIds());
+            jsonObject.put("userIds", collect);
         }
         return new Result(ResultCode.SUCCESS,jsonObject);
     }
@@ -70,6 +93,31 @@ public class GasThresholdServiceImpl extends ServiceImpl<GasThresholdMapper, Gas
     public Result edit(HttpServletRequest httpServletRequest, List<GasThreshold> gasThresholds) {
         for (GasThreshold gasThreshold : gasThresholds) {
             if (ObjectUtil.isNotEmpty(gasThreshold)) {
+                Integer farmId = gasThreshold.getFarmId();
+                String userIds = gasThreshold.getUserIds();
+                QueryWrapper<GasThreshold> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("farm_id", gasThreshold.getFarmId()).eq("gas_type", gasThreshold.getGasType());
+                GasThreshold gasThreshold2 = gasThresholdMapper.selectOne(queryWrapper);
+
+                //去掉属于该人物的id
+                Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
+                //下属id
+                List<Integer> lowerLevelIds = sysAccountMultilevelMapper.getLowerLevel( userId,farmId+"");
+                //上传id
+                List<Integer> uoloadIds = new ArrayList<>();
+                if (StringUtils.isNotBlank(userIds)){
+                    uoloadIds = Arrays.stream(userIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
+                }
+                //现有id
+                String oldUserIds = gasThreshold2.getUserIds();
+                List<Integer> oldUsersIds = new ArrayList<>();
+                if (StringUtils.isNotBlank(oldUserIds)){
+                    oldUsersIds = Arrays.stream(oldUserIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
+                }
+                // 现有 -下属 + 上传
+                oldUsersIds.removeAll(lowerLevelIds);
+                oldUsersIds.addAll(uoloadIds);
+
                 GasThreshold gasThreshold1 = new GasThreshold();
                 gasThreshold1.setGasType(gasThreshold.getGasType());
                 gasThreshold1.setNh3N(gasThreshold.getNh3N());
@@ -80,11 +128,9 @@ public class GasThresholdServiceImpl extends ServiceImpl<GasThresholdMapper, Gas
                 gasThreshold1.setCh3sh(gasThreshold.getCh3sh());
                 gasThreshold1.setSja(gasThreshold.getSja());
                 gasThreshold1.setCq(gasThreshold.getCq());
-                gasThreshold1.setUserIds(gasThreshold.getUserIds());
+                gasThreshold1.setUserIds(oldUsersIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
+                gasThreshold1.setFarmId(farmId);
 
-                QueryWrapper<GasThreshold> queryWrapper = new QueryWrapper<>();
-                queryWrapper.eq("farm_id", gasThreshold.getFarmId()).eq("gas_type", gasThreshold.getGasType());
-                GasThreshold gasThreshold2 = gasThresholdMapper.selectOne(queryWrapper);
                 if (ObjectUtil.isEmpty(gasThreshold2)) {
                     gasThresholdMapper.insert(gasThreshold1);
                 } else {

+ 47 - 6
huimv-admin/src/main/java/com/huimv/admin/service/impl/ProtThresholdServiceImpl.java

@@ -4,18 +4,26 @@ import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.huimv.admin.common.token.TokenSign;
 import com.huimv.admin.common.utils.Result;
 import com.huimv.admin.common.utils.ResultCode;
+import com.huimv.admin.entity.EnvWarningThreshold;
+import com.huimv.admin.entity.GasThreshold;
 import com.huimv.admin.entity.ProtThreshold;
 import com.huimv.admin.mapper.ProtThresholdMapper;
+import com.huimv.admin.mapper.SysAccountMultilevelMapper;
 import com.huimv.admin.service.IProtThresholdService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -30,7 +38,8 @@ public class ProtThresholdServiceImpl extends ServiceImpl<ProtThresholdMapper, P
 
     @Autowired
     private ProtThresholdMapper protThresholdMapper;
-
+    @Autowired
+    SysAccountMultilevelMapper sysAccountMultilevelMapper;
     @Override
     public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
         String farmId = paramsMap.get("farmId");
@@ -38,6 +47,15 @@ public class ProtThresholdServiceImpl extends ServiceImpl<ProtThresholdMapper, P
         QueryWrapper<ProtThreshold> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq("farm_id", farmId);
         List<ProtThreshold> protThresholdList = protThresholdMapper.selectList(queryWrapper);
+
+        Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
+        List<Integer> userIds =sysAccountMultilevelMapper.getLowerLevel( userId,farmId);
+        List<Integer> collect =new ArrayList<>();
+        String userIds1 = protThresholdList.get(0).getUserIds();
+        if (StringUtils.isNotBlank(userIds1)){
+            collect = Arrays.stream(userIds1.split(",")).map(Integer::valueOf).filter(userIds::contains).collect(Collectors.toList());
+        }
+
         if (protThresholdList.size() == 0) {
             JSONObject jsonObject = new JSONObject();
             jsonObject.put("COD1", 0);
@@ -67,7 +85,7 @@ public class ProtThresholdServiceImpl extends ServiceImpl<ProtThresholdMapper, P
                 }
             }
             jsonObject.put("userIds", protThresholdList.get(1).getUserIds());
-            return new Result(ResultCode.SUCCESS,jsonObject);
+            return new Result(ResultCode.SUCCESS,collect);
         }
 
     }
@@ -76,6 +94,31 @@ public class ProtThresholdServiceImpl extends ServiceImpl<ProtThresholdMapper, P
     public Result add(HttpServletRequest httpServletRequest, List<ProtThreshold> protThresholds) {
         for (ProtThreshold protThreshold : protThresholds) {
             if (ObjectUtil.isNotEmpty(protThreshold)) {
+
+                Integer farmId = protThreshold.getFarmId();
+                String userIds = protThreshold.getUserIds();
+                QueryWrapper<ProtThreshold> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("farm_id", protThreshold.getFarmId()).eq("prot_type",protThreshold.getProtType());
+                ProtThreshold threshold = protThresholdMapper.selectOne(queryWrapper);
+                //去掉属于该人物的id
+                Integer userId = TokenSign.getMemberIdByJwtToken(httpServletRequest);
+                //下属id
+                List<Integer> lowerLevelIds = sysAccountMultilevelMapper.getLowerLevel( userId,farmId+"");
+                //上传id
+                List<Integer> uoloadIds = new ArrayList<>();
+                if (StringUtils.isNotBlank(userIds)){
+                    uoloadIds = Arrays.stream(userIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
+                }
+                //现有id
+                String oldUserIds = threshold.getUserIds();
+                List<Integer> oldUsersIds = new ArrayList<>();
+                if (StringUtils.isNotBlank(oldUserIds)){
+                    oldUsersIds = Arrays.stream(oldUserIds.split(",")).map(Integer::valueOf).collect(Collectors.toList());
+                }
+                // 现有 -下属 + 上传
+                oldUsersIds.removeAll(lowerLevelIds);
+                oldUsersIds.addAll(uoloadIds);
+
                 ProtThreshold protThreshold1 = new ProtThreshold();
                 protThreshold1.setProtType(protThreshold.getProtType());
                 protThreshold1.setFarmId(protThreshold.getFarmId());
@@ -91,7 +134,7 @@ public class ProtThresholdServiceImpl extends ServiceImpl<ProtThresholdMapper, P
                 protThreshold1.setTn2(protThreshold.getTn2());
                 protThreshold1.setFlow1(protThreshold.getFlow1());
                 protThreshold1.setFlow2(protThreshold.getFlow2());
-                protThreshold1.setUserIds(protThreshold.getUserIds());
+                protThreshold1.setUserIds(oldUsersIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
                 protThreshold1.setDataType(protThreshold.getDataType());
 
 
@@ -108,9 +151,7 @@ public class ProtThresholdServiceImpl extends ServiceImpl<ProtThresholdMapper, P
                 } else if (Integer.parseInt(protThreshold.getFlow2()) < Integer.parseInt(protThreshold.getFlow1())) {
                     return new Result(ResultCode.FAIL, "红色预警浓度不能低于橙色预警浓度");
                 } else {
-                    QueryWrapper<ProtThreshold> queryWrapper = new QueryWrapper<>();
-                    queryWrapper.eq("farm_id", protThreshold.getFarmId()).eq("prot_type",protThreshold.getProtType());
-                    ProtThreshold threshold = protThresholdMapper.selectOne(queryWrapper);
+
                     if (ObjectUtil.isEmpty(threshold)) {
                         protThresholdMapper.insert(protThreshold1);
                     } else {

+ 9 - 0
huimv-admin/src/main/resources/com/huimv/admin/mapper/AccountMultilevelMapper.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.huimv.admin.mapper.SysAccountMultilevelMapper">
+
+
+    <select id="getLowerLevel" resultType="java.lang.Integer">
+        SELECT id FROM sys_account_multilevel WHERE  pids  LIKE  concat('%',#{userId},'%')   AND  farm_ids LIKE concat('%', #{farmId},'%')
+    </select>
+</mapper>