123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- package com.huimv.admin.service.impl;
- 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>
- * 环保阈值 服务实现类
- * </p>
- *
- * @author author
- * @since 2023-02-14
- */
- @Service
- public class ProtThresholdServiceImpl extends ServiceImpl<ProtThresholdMapper, ProtThreshold> implements IProtThresholdService {
- @Autowired
- private ProtThresholdMapper protThresholdMapper;
- @Autowired
- SysAccountMultilevelMapper sysAccountMultilevelMapper;
- @Override
- public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
- String farmId = paramsMap.get("farmId");
- String protType = paramsMap.get("protType");
- 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<>();
- if (ObjectUtil.isNotEmpty(protThresholdList) &&StringUtils.isNotBlank(protThresholdList.get(0).getUserIds())){
- collect = Arrays.stream(protThresholdList.get(0).getUserIds().split(",")).map(Integer::valueOf).filter(userIds::contains).collect(Collectors.toList());
- }
- if (protThresholdList.size() == 0) {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("COD1", 0);
- jsonObject.put("COD2", 0);
- jsonObject.put("PH1", 0);
- jsonObject.put("PH2", 0);
- jsonObject.put("NH3N1", 0);
- jsonObject.put("NH3N2", 0);
- jsonObject.put("TP1", 0);
- jsonObject.put("TP2", 0);
- jsonObject.put("TN1", 0);
- jsonObject.put("TN2", 0);
- jsonObject.put("FLOW1", 0);
- jsonObject.put("FLOW2", 0);
- jsonObject.put("userIds", 0);
- jsonObject.put("dataType", 0);
- return new Result(ResultCode.SUCCESS, jsonObject);
- } else {
- JSONObject jsonObject = new JSONObject();
- for (int i = 0; i < protThresholdList.size(); i++) {
- if (protThresholdList.get(i).getProtType()==1) {
- jsonObject.put("in", protThresholdList.get(i));
- } else if (protThresholdList.get(i).getProtType()==2) {
- jsonObject.put("deal", protThresholdList.get(i));
- } else if (protThresholdList.get(i).getProtType()==3) {
- jsonObject.put("out", protThresholdList.get(i));
- }
- }
- jsonObject.put("userIds",collect);
- return new Result(ResultCode.SUCCESS,jsonObject);
- }
- }
- @Override
- 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());
- protThreshold1.setCod1(protThreshold.getCod1());
- protThreshold1.setCod2(protThreshold.getCod2());
- protThreshold1.setPh1(protThreshold.getPh1());
- protThreshold1.setPh2(protThreshold.getPh2());
- protThreshold1.setNh3n1(protThreshold.getNh3n1());
- protThreshold1.setNh3n2(protThreshold.getNh3n2());
- protThreshold1.setTp1(protThreshold.getTp1());
- protThreshold1.setTp2(protThreshold.getTp2());
- protThreshold1.setTn1(protThreshold.getTn1());
- protThreshold1.setTn2(protThreshold.getTn2());
- protThreshold1.setFlow1(protThreshold.getFlow1());
- protThreshold1.setFlow2(protThreshold.getFlow2());
- protThreshold1.setUserIds(oldUsersIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
- protThreshold1.setDataType(protThreshold.getDataType());
- if (Integer.parseInt(protThreshold.getCod2()) <= Integer.parseInt(protThreshold.getCod1())) {
- return new Result(ResultCode.FAIL, "红色预警浓度不能低于橙色预警浓度");
- } else if (Integer.parseInt(protThreshold.getPh2()) <= Integer.parseInt(protThreshold.getPh1())) {
- return new Result(ResultCode.FAIL, "红色预警浓度不能低于橙色预警浓度");
- } else if (Integer.parseInt(protThreshold.getNh3n2()) <= Integer.parseInt(protThreshold.getNh3n1())) {
- return new Result(ResultCode.FAIL, "红色预警浓度不能低于橙色预警浓度");
- } else if (Integer.parseInt(protThreshold.getTp2()) <= Integer.parseInt(protThreshold.getTp1())) {
- return new Result(ResultCode.FAIL, "红色预警浓度不能低于橙色预警浓度");
- } else if (Integer.parseInt(protThreshold.getTn2()) <= Integer.parseInt(protThreshold.getTn1())) {
- return new Result(ResultCode.FAIL, "红色预警浓度不能低于橙色预警浓度");
- } else if (Integer.parseInt(protThreshold.getFlow2()) <= Integer.parseInt(protThreshold.getFlow1())) {
- return new Result(ResultCode.FAIL, "红色预警浓度不能低于橙色预警浓度");
- } else {
- if (ObjectUtil.isEmpty(threshold)) {
- protThresholdMapper.insert(protThreshold1);
- } else {
- protThreshold1.setId(protThreshold.getId());
- protThresholdMapper.updateById(protThreshold1);
- }
- }
- }
- }
- return new Result(ResultCode.SUCCESS, "修改成功");
- }
- }
|