package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.whyc.dto.AlarmDaoFactory;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.AlarmManualClearMapper;
|
import com.whyc.pojo.*;
|
import com.whyc.util.ActionUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class AlarmManualClearService {
|
|
@Resource
|
private AlarmManualClearMapper mapper;
|
|
@Autowired
|
private BattInfService battInfService;
|
|
@Autowired
|
private PowerInfService powerInfService;
|
|
@Autowired
|
private BattAlarmDataVerifyService battAlarmService;
|
|
@Autowired
|
private BattalarmDataHistoryService battAlarmHistoryService;
|
|
@Autowired
|
private DevAlarmDataVerifyService devAlarmService;
|
|
@Autowired
|
private DevalarmDataHistoryService devAlarmHistoryService;
|
|
@Autowired
|
private PwrDevAlarmVerifyService powerAlarmService;
|
|
@Autowired
|
private PwrdevAlarmHistoryService powerAlarmHistoryService;
|
|
@Transactional
|
public Response submit(AlarmManualClear clear) {
|
int userId = ActionUtil.getUser().getUId().intValue();
|
clear.setDealUserId(userId);
|
clear.setCreateTime(new Date());
|
//插入对应的站点id,用于后期用户相关
|
Integer alarmType = clear.getAlarmType();
|
String stationId;
|
Integer num = clear.getNum();
|
if(alarmType == 1){ //电池告警
|
stationId = battInfService.getStationIdByBattGroupId(clear.getBattGroupId());
|
//添加到历史告警,移除告警确认数据
|
BattAlarmDataVerify data = battAlarmService.getById(num);
|
battAlarmHistoryService.add(data);
|
battAlarmService.delete(num);
|
} else if (alarmType == 2) { //设备告警
|
stationId = battInfService.getStationIdByDeviceId(clear.getDeviceId());
|
DevAlarmDataVerify data = devAlarmService.getById(num);
|
devAlarmHistoryService.add(data);
|
devAlarmService.delete(num);
|
|
}else{ //电源告警
|
stationId = powerInfService.getStationIdByPowerDeviceId(clear.getPowerDeviceId());
|
PwrDevAlarmVerify data = powerAlarmService.getById(num);
|
powerAlarmHistoryService.add(data);
|
powerAlarmService.delete(num);
|
}
|
clear.setStationId(stationId);
|
mapper.insert(clear);
|
return new Response().set(1,"提交完成");
|
}
|
|
public Response getRecordByAlarmInfo(AlarmManualClear clear) {
|
QueryWrapper<AlarmManualClear> query = Wrappers.query();
|
Integer alarmType = clear.getAlarmType();
|
String alarmName;
|
if(alarmType == 1) {
|
alarmName = AlarmDaoFactory.getAllAlarmName(clear.getAlmSignalId());
|
query.eq("batt_group_id",clear.getBattGroupId()).eq("alm_signal_id",clear.getAlmSignalId());
|
}else if(alarmType == 2){
|
query.eq("device_id",clear.getDeviceId());
|
alarmName = AlarmDaoFactory.getAllAlarmName(clear.getAlmId());
|
}else{
|
query.eq("power_device_id",clear.getPowerDeviceId());
|
alarmName = AlarmDaoFactory.getAllAlarmName(clear.getAlmId());
|
}
|
query.eq("alm_start_time",clear.getAlmStartTime())
|
.eq("alm_id",clear.getAlmId()).last(" limit 1");
|
AlarmManualClear clearDB = mapper.selectOne(query);
|
|
clearDB.setAlarmName(alarmName);
|
return new Response().set(1,clearDB);
|
|
}
|
|
public Response getPage(int pageNum,int pageSize) {
|
int userId = ActionUtil.getUser().getUId().intValue();
|
//查询所有的记录分页
|
PageHelper.startPage(pageNum,pageSize);
|
List<AlarmManualClear> list = mapper.getAll(userId);
|
PageInfo<AlarmManualClear> pageInfo = new PageInfo<>(list);
|
////装配电池/设备/电源信息
|
//List<AlarmManualClear> dataList = pageInfo.getList();
|
//List<Integer> battGroupIdList = dataList.stream().filter(data -> data.getAlarmType() == 1).map(AlarmManualClear::getBattGroupId).collect(Collectors.toList());
|
//List<Integer> deviceIdList = dataList.stream().filter(data -> data.getAlarmType() == 2).map(AlarmManualClear::getDeviceId).collect(Collectors.toList());
|
//List<Integer> powerDeviceIdList = dataList.stream().filter(data -> data.getAlarmType() == 3).map(AlarmManualClear::getPowerDeviceId).collect(Collectors.toList());
|
pageInfo.getList().stream().forEach(data->{
|
if(data.getAlarmType()==1){
|
data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmSignalId()));
|
}else{
|
data.setAlarmName(AlarmDaoFactory.getAllAlarmName(data.getAlmId()));
|
}
|
});
|
return new Response().set(1,pageInfo);
|
}
|
}
|