|
@@ -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 {
|