package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.whyc.dto.AlarmDaoFactory;
|
import com.whyc.dto.GroupWithStationAndAlarmDTO;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.BaoJiGroupMapper;
|
import com.whyc.mapper.BaoJiGroupUserMapper;
|
import com.whyc.mapper.BaoJiGroupBattGroupMapper;
|
import com.whyc.mapper.CommonMapper;
|
import com.whyc.pojo.*;
|
import com.whyc.util.ActionUtil;
|
import com.whyc.util.MessageUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class BaoJiGroupService {
|
|
@Resource
|
private BaoJiGroupMapper mapper;
|
|
@Resource
|
private BaoJiGroupUserMapper baoJiGroupUserMapper;
|
|
@Resource
|
private BaoJiGroupBattGroupMapper BaoJiGroupBattGroupMapper;
|
|
@Resource
|
private CommonMapper commonMapper;
|
|
@Autowired
|
private BattInfService battInfService;
|
|
@Autowired
|
private BattalarmDataService battAlarmDataService;
|
|
@Autowired
|
private DevalarmDataService deviceAlarmDataService;
|
|
@Autowired
|
private PwrdevAlarmService powerAlarmService;
|
|
@Autowired
|
private PermitGroupService permitGroupService;
|
|
public void add(String groupName) {
|
BaoJiGroup baoJiGroup = new BaoJiGroup();
|
baoJiGroup.setBaoJiGroupName(groupName);
|
baoJiGroup.setDischargePlanFlag(0);
|
|
mapper.insert(baoJiGroup);
|
}
|
|
public void update(BaoJiGroup baoJiGroup) {
|
mapper.updateById(baoJiGroup);
|
}
|
|
public void delete(long baoJiGroupId) {
|
//删除包机组
|
mapper.deleteById(baoJiGroupId);
|
//删除关联的用户
|
UpdateWrapper<BaoJiGroupUser> userWrapper = Wrappers.update();
|
userWrapper.eq("baoji_group_id",baoJiGroupId);
|
baoJiGroupUserMapper.delete(userWrapper);
|
//删除关联的站点/电池组
|
UpdateWrapper<BaojiGroupBattGroup> battGroupWrapper = Wrappers.update();
|
battGroupWrapper.eq("baoji_group_id",baoJiGroupId);
|
BaoJiGroupBattGroupMapper.delete(battGroupWrapper);
|
}
|
|
public Response getBaoJiGroup() {
|
//验证是否存在usr_query_permit权限
|
if (!permitGroupService.checkUserPermitWithName("usr_query_permit")) {
|
return new Response<Boolean>().set(1,false, "当前用户没有查询权限");
|
}
|
List<BaoJiGroup> list=mapper.selectList((Wrapper<BaoJiGroup>) ActionUtil.objeNull);
|
return new Response<List<BaoJiGroup>>().set(1,list);
|
}
|
|
/**
|
* 每次设置放电标识时,提前校验组内是否与其他标识班组存在相同站点,存在则提示,不修改
|
* @param baoJiGroupId
|
* @param flag
|
* @return
|
*/
|
public Response updateDischargeFlag(Long baoJiGroupId, Integer flag) {
|
if(flag==1) {
|
//查询要设置的包机组的站点
|
QueryWrapper<BaojiGroupBattGroup> query = Wrappers.query();
|
query.select("baoji_group_id", "StationId").eq("baoji_group_id", baoJiGroupId);
|
List<BaojiGroupBattGroup> stationIdList = BaoJiGroupBattGroupMapper.selectList(query);
|
stationIdList = stationIdList.stream().distinct().collect(Collectors.toList());
|
//查询其他的组,包含的所有站点
|
List<BaojiGroupBattGroup> stationIdListWithDischargePlanFlag = BaoJiGroupBattGroupMapper.getStationIdListWithDischargePlanFlag();
|
stationIdListWithDischargePlanFlag = stationIdListWithDischargePlanFlag.stream().distinct().collect(Collectors.toList());
|
List<BaojiGroupBattGroup> repeatedStationIdList = new LinkedList<>();
|
for (int i = 0; i < stationIdList.size(); i++) {
|
BaojiGroupBattGroup baojiGroupBattGroup = stationIdList.get(i);
|
for (int j = 0; j < stationIdListWithDischargePlanFlag.size(); j++) {
|
BaojiGroupBattGroup baojiGroupBattGroupWithFlag = stationIdListWithDischargePlanFlag.get(j);
|
if (baojiGroupBattGroupWithFlag.getStationId().equals(baojiGroupBattGroup.getStationId())) {
|
repeatedStationIdList.add(baojiGroupBattGroupWithFlag);
|
break;
|
}
|
}
|
}
|
//查询重复站点的信息
|
if (repeatedStationIdList.size() > 0) {
|
return new Response().setII(1, false, repeatedStationIdList, "设置失败");
|
}
|
}
|
UpdateWrapper<BaoJiGroup> update = Wrappers.update();
|
update.set("discharge_plan_flag",flag).eq("baoji_group_id",baoJiGroupId);
|
mapper.update((BaoJiGroup) ActionUtil.objeNull,update);
|
return new Response().set(1,true,"设置完成");
|
}
|
|
public List<BaoJiGroup> getBaoJiGroupNameListByFlag(int dischargePlanFlag) {
|
QueryWrapper<BaoJiGroup> query = Wrappers.query();
|
query.eq("discharge_plan_flag",dischargePlanFlag);
|
return mapper.selectList(query);
|
}
|
|
public Response getGroupWithStationAndAlarmForScreen(int userId) {
|
try {
|
List<GroupWithStationAndAlarmDTO> list = mapper.getGroupWithStation(userId);
|
list.forEach(item -> {
|
List<StationInf> stationInfList = item.getStationInfList();
|
List<StationInf> stationInfList2 = stationInfList.stream().collect(Collectors.collectingAndThen(
|
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StationInf::getTogetherFlag))),
|
ArrayList::new));
|
item.setStationInfList(stationInfList2);
|
item.setStationCount(stationInfList2.size());
|
List<String> stationIdList = stationInfList.stream().map(StationInf::getStationId).collect(Collectors.toList());
|
//电池
|
int battAlarmCount = battAlarmDataService.getCountByStationIds(stationIdList,1);
|
item.setBattAlarmCount(battAlarmCount);
|
//设备
|
int deviceAlarmCount = deviceAlarmDataService.getCountByStationIds(stationIdList,1);
|
item.setDeviceAlarmCount(deviceAlarmCount);
|
//电源
|
int powerAlarmCount = powerAlarmService.getCountByStationIds(stationIdList,1);
|
item.setPowerAlarmCount(powerAlarmCount);
|
});
|
|
return new Response().set(1, list);
|
}catch (Exception e){
|
return new Response<>().set(1,false,"发生异常:"+e.getCause());
|
}
|
}
|
//山西晋源特定接口
|
public Response getGroupWithStationAndAlarmForScreenJY() {
|
try {
|
List<GroupWithStationAndAlarmDTO> list = mapper.getGroupWithStationJY();
|
list.forEach(item -> {
|
List<StationInf> stationInfList = item.getStationInfList();
|
List<StationInf> stationInfList2 = stationInfList.stream().collect(Collectors.collectingAndThen(
|
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StationInf::getTogetherFlag))),
|
ArrayList::new));
|
item.setStationInfList(stationInfList2);
|
item.setStationCount(stationInfList2.size());
|
List<String> stationIdList = stationInfList.stream().map(StationInf::getStationId).collect(Collectors.toList());
|
//电池
|
int battAlarmCount = battAlarmDataService.getCountByStationIds(stationIdList,1);
|
item.setBattAlarmCount(battAlarmCount);
|
//设备
|
int deviceAlarmCount = deviceAlarmDataService.getCountByStationIds(stationIdList,1);
|
item.setDeviceAlarmCount(deviceAlarmCount);
|
//电源
|
int powerAlarmCount = powerAlarmService.getCountByStationIds(stationIdList,1);
|
item.setPowerAlarmCount(powerAlarmCount);
|
});
|
|
return new Response().set(1, list);
|
}catch (Exception e){
|
return new Response<>().set(1,false,"发生异常:"+e.getCause());
|
}
|
}
|
|
public Response getGroupWithStationAndAlarm(int userId) {
|
try {
|
List<GroupWithStationAndAlarmDTO> list = mapper.getGroupWithStation(userId);
|
list.forEach(item -> {
|
List<StationInf> stationInfList = item.getStationInfList();
|
List<StationInf> stationInfList2 = stationInfList.stream().collect(Collectors.collectingAndThen(
|
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(StationInf::getTogetherFlag))),
|
ArrayList::new));
|
//站点合并统计机房数
|
item.setStationCount(stationInfList2.size());
|
List<String> stationIdList = stationInfList.stream().map(StationInf::getStationId).collect(Collectors.toList());
|
//电池
|
List<BattalarmData> battAlarmList = battAlarmDataService.getListByStationIds(stationIdList);
|
for (BattalarmData data : battAlarmList) {
|
data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmSignalId()));
|
}
|
item.setBattAlarmCount(battAlarmList.size());
|
//设备
|
List<DevalarmData> deviceAlarmList = deviceAlarmDataService.getListByStationIds(stationIdList);
|
for (DevalarmData data : deviceAlarmList) {
|
data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmType()));
|
}
|
item.setDeviceAlarmCount(deviceAlarmList.size());
|
//电源
|
List<PwrdevAlarm> powerAlarmList = powerAlarmService.getListByStationIds(stationIdList);
|
for (PwrdevAlarm data : powerAlarmList) {
|
data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmType()));
|
data.setPwrAlmFlag((int) (data.getPowerDeviceId()/1000000));
|
}
|
item.setPowerAlarmCount(powerAlarmList.size());
|
//遍历每个告警列表,如果与站点相符,则加入到站点里面
|
for (BattalarmData alarm : battAlarmList) {
|
for (StationInf stationInf : stationInfList) {
|
if(alarm.getStationId().equals(stationInf.getStationId())) {
|
List<BattalarmData> containList = stationInf.getBattAlarmList();
|
if(containList == null){
|
containList = new LinkedList<>();
|
}
|
containList.add(alarm);
|
stationInf.setBattAlarmList(containList);
|
stationInf.setAlarmFlag(1);
|
break;
|
}
|
}
|
}
|
for (DevalarmData alarm : deviceAlarmList) {
|
for (StationInf stationInf : stationInfList) {
|
if(alarm.getStationId().equals(stationInf.getStationId())) {
|
List<DevalarmData> containList = stationInf.getDeviceAlarmList();
|
if(containList == null){
|
containList = new LinkedList<>();
|
}
|
containList.add(alarm);
|
stationInf.setDeviceAlarmList(containList);
|
stationInf.setAlarmFlag(1);
|
break;
|
}
|
}
|
}
|
for (PwrdevAlarm alarm : powerAlarmList) {
|
for (StationInf stationInf : stationInfList) {
|
if(alarm.getStationId().equals(stationInf.getStationId())) {
|
List<PwrdevAlarm> containList = stationInf.getPowerAlarmList();
|
if(containList == null){
|
containList = new LinkedList<>();
|
}
|
containList.add(alarm);
|
stationInf.setPowerAlarmList(containList);
|
stationInf.setAlarmFlag(1);
|
break;
|
}
|
}
|
}
|
List<StationInf> stationInfListOrdered = stationInfList.stream().sorted(Comparator.comparing(StationInf::getAlarmFlag).reversed()).collect(Collectors.toList());
|
item.setStationInfList(stationInfListOrdered);
|
});
|
return new Response().set(1, list);
|
}catch (Exception e){
|
return new Response<>().set(1,false,"发生异常:"+e.getCause());
|
}
|
}
|
}
|