/**
|
* # __----~~~~~~~~~~~------___
|
* # . . ~~//====...... __--~ ~~
|
* # -. \_|// |||\\ ~~~~~~::::... /~
|
* # ___-==_ _-~o~ \/ ||| \\ _/~~-
|
* # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~
|
* # _-~~ .=~ | \\-_ '-~7 /- / || \ /
|
* # .~ .~ | \\ -_ / /- / || \ /
|
* # / ____ / | \\ ~-_/ /|- _/ .|| \ /
|
* # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\
|
* # ' ~-| /| |-~\~~ __--~~
|
* # |-~~-_/ | | ~\_ _-~ /\
|
* # / \ \__ \/~ \__
|
* # _--~ _/ | .-~~____--~-/ ~~==.
|
* # ((->/~ '.|||' -_| ~~-/ , . _||
|
* # -_ ~\ ~~---l__i__i__i--~~_/
|
* # _-~-__ ~) \--______________--~~
|
* # //.-~~~-~_--~- |-------~~~~~~~~
|
* # //.-~~~--\
|
* # 神兽保佑
|
* # 永无BUG!
|
*/
|
package com.nanjing.water.service;
|
|
|
import com.nanjing.water.common.*;
|
import com.nanjing.water.common.enums.*;
|
import com.nanjing.water.common.model.Tuple;
|
import com.nanjing.water.common.util.*;
|
import com.nanjing.water.entity.request.alarmhistory.ReqCreateAlarmHistory;
|
import com.nanjing.water.entity.request.alarmhistory.ReqModifyAlarmHistory;
|
import com.nanjing.water.entity.search.SearchAlarmHistory;
|
import com.nanjing.water.repository.impl.AlarmHistoryMapperImpl;
|
import com.nanjing.water.repository.po.AlarmHistoryPO;
|
import com.nanjing.water.repository.vo.AlarmHistoryVO;
|
import com.nanjing.water.service.convert.AlarmHistoryConvert;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.net.URLEncoder;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* 报警信息
|
* @author lin.liu
|
*/
|
@Service
|
public class AlarmHistoryService extends BaseService {
|
@Autowired
|
private AlarmHistoryMapperImpl mapper;
|
|
public ExecutedResult<String> create(ReqCreateAlarmHistory request) {
|
//查询报警记录是否存在
|
|
// 转换po
|
AlarmHistoryPO item = AlarmHistoryConvert.INSTANCE.toCreate(request);
|
// 设置记录创建时间
|
item.setCreateTime(LocalDateTimeUtil.nowTimeStamp());
|
// 是否删除(逻辑删除)初始值
|
item.setIsDelete(EYesOrNo.NO.getValue());
|
|
int rowCount = mapper.insert(item);
|
if (rowCount != 1) {
|
return ExecutedResult.failed("创建[报警信息]失败。");
|
}
|
|
return ExecutedResult.success();
|
}
|
|
public ExecutedResult<String> modify(ReqModifyAlarmHistory request) {
|
// 验证记录是否存在
|
ExecutedResult<AlarmHistoryPO> checkExists = this.check4Id(request.getId());
|
if (checkExists.isFailed()) {
|
return ExecutedResult.failed(checkExists.getMsg());
|
}
|
// 转换po
|
AlarmHistoryPO item = AlarmHistoryConvert.INSTANCE.toModify(request);
|
|
int rowCount = mapper.updateById(item);
|
if (rowCount != 1) {
|
return ExecutedResult.failed("编辑[报警信息]失败。");
|
}
|
return ExecutedResult.success();
|
}
|
public ExecutedResult<String> editConfirm(Long id,Integer status){
|
// 验证记录是否存在
|
ExecutedResult<AlarmHistoryPO> checkExists = this.check4Id(id);
|
if (checkExists.isFailed()) {
|
return ExecutedResult.failed(checkExists.getMsg());
|
}
|
AlarmHistoryPO data = checkExists.getData();
|
int i = mapper.updateById(data);
|
if(i!=1){
|
return ExecutedResult.failed("编辑[报警信息]失败。");
|
}
|
return ExecutedResult.success();
|
}
|
public ExecutedResult<AlarmHistoryVO> get(Long id) {
|
AlarmHistoryVO result = new AlarmHistoryVO();
|
|
AlarmHistoryPO find = mapper.get(id);
|
if (null != find) {
|
// 转换vo
|
result = AlarmHistoryConvert.INSTANCE.toVo(find);
|
}
|
return ExecutedResult.success(result);
|
}
|
|
// public ExecutedResult<String> stop(Long id) {
|
// // 验证记录是否存在
|
// ExecutedResult<AlarmHistoryPO> checkExists = this.check4Id(id);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// AlarmHistoryPO item = new AlarmHistoryPO();
|
// item.setId(id);
|
// item.setStatus(EState.DISABLED.getValue());
|
//
|
// int rowCount = mapper.updateById(item);
|
// if (rowCount != 1) {
|
// return ExecutedResult.failed("停用[报警信息]失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
//
|
// public ExecutedResult<String> enable(Long id) {
|
// // 验证记录是否存在
|
// ExecutedResult<AlarmHistoryPO> checkExists = this.check4Id(id);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// AlarmHistoryPO item = new AlarmHistoryPO();
|
// item.setId(id);
|
// item.setStatus(EState.NORMAL.getValue());
|
//
|
// int rowCount = mapper.updateById(item);
|
// if (rowCount != 1) {
|
// return ExecutedResult.failed("启用[报警信息]失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
//
|
// public ExecutedResult<String> setSort(ReqSetSort request) {
|
// // 验证记录是否存在
|
// ExecutedResult<AlarmHistoryPO> checkExists = this.check4Id(request.getId());
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// AlarmHistoryPO item = new AlarmHistoryPO();
|
// item.setId(request.getId());
|
// item.setSort(request.getSort());
|
//
|
// int rowCount = mapper.updateById(item);
|
// if (rowCount != 1) {
|
// return ExecutedResult.failed("设置[报警信息]排序值失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
//
|
// public ExecutedResult<String> listSetSort(ReqListSetSort request) {
|
// // id列表
|
// List<Long> listId = request.getList().stream().map(ReqSetSort::getId).collect(Collectors.toList());
|
// // 验证记录是否存在
|
// ExecutedResult<List<AlarmHistoryPO>> checkExists = this.check4Id(listId);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
//
|
// List<AlarmHistoryPO> listUpdate = request.getList().stream()
|
// .map(c -> {
|
// AlarmHistoryPO item = new AlarmHistoryPO();
|
// item.setId(c.getId());
|
// item.setSort(c.getSort());
|
// return item;
|
// })
|
// .collect(Collectors.toList());
|
// Boolean result = mapper.modifyList(listUpdate);
|
// if (result) {
|
// return ExecutedResult.success();
|
// }
|
// return ExecutedResult.failed("[报警信息]设置排序值失败");
|
// }
|
//
|
// public ExecutedResult<String> remove(Long id) {
|
// Boolean result = mapper.deleteLogic(id);
|
// if (BooleanUtils.isFalse(result)) {
|
// return ExecutedResult.failed("删除[报警信息]失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
//
|
// public ExecutedResult<String> removeList(List<Long> ids) {
|
// Boolean result = mapper.deleteLogic(ids);
|
// if (BooleanUtils.isFalse(result)) {
|
// return ExecutedResult.failed("删除[报警信息]失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
|
public ExecutedResult<List<AlarmHistoryVO>> getList(List<Long> listId) {
|
List<AlarmHistoryVO> result = new ArrayList<>();
|
|
List<AlarmHistoryPO> list = mapper.getList(listId);
|
if (ListUtil.isNotNullOrEmpty(list)) {
|
// 转换vo
|
result = AlarmHistoryConvert.INSTANCE.toVo(list);
|
}
|
return ExecutedResult.success(result);
|
}
|
|
public ExecutedResult<PagerResult<AlarmHistoryVO>> search(SearchAlarmHistory search) {
|
// 处理创建时间范围-查询参数
|
Tuple<String, String> createTimeRange = ParameterUtil.getTimeRange(search.getCreateTimeRange());
|
if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem1())) {
|
search.setCreateTimeStart(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem1()).getTime());
|
}
|
if (StringUtil.isNotNullOrEmpty(createTimeRange.getItem2())) {
|
search.setCreateTimeEnd(LocalDateTimeUtil.getTimeStamp(createTimeRange.getItem2()).getTime());
|
}
|
|
PagerResult<AlarmHistoryPO> pageList = mapper.search(search);
|
List<AlarmHistoryVO> listVo = new ArrayList<>();
|
List<AlarmHistoryPO> list = pageList.getList();
|
if (ListUtil.isNotNullOrEmpty(list)) {
|
pageList.setLastId(list.get(list.size() - 1).getId());
|
// 转换vo
|
listVo = CopierUtil.mapTo(list, AlarmHistoryVO.class);
|
}
|
PagerResult<AlarmHistoryVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo);
|
result.setLastId(pageList.getLastId());
|
return ExecutedResult.success(result);
|
}
|
|
protected ExecutedResult<AlarmHistoryPO> check4Id(Long id) {
|
AlarmHistoryPO exists = mapper.get(id);
|
if (Objects.isNull(exists)) {
|
return ExecutedResult.failed("[报警信息]不存在:" + id);
|
}
|
return ExecutedResult.success(exists);
|
}
|
|
protected ExecutedResult<List<AlarmHistoryPO>> check4Id(List<Long> listId) {
|
// 从数据库查找报警信息
|
List<AlarmHistoryPO> list = mapper.getList(listId);
|
if (ListUtil.isNullOrEmpty(list)) {
|
return ExecutedResult.failed("[报警信息]不存在." + listId);
|
}
|
// 数据库找到的id列表
|
List<Long> listIdFind = list.stream().map(AlarmHistoryPO::getId).collect(Collectors.toList());
|
// 数量不一致
|
if (listId.size() != listIdFind.size()) {
|
// 筛选数据库不存在的报警信息
|
List<Long> listIdNotFound = listId.stream().filter(c -> !listIdFind.contains(c)).collect(Collectors.toList());
|
if (ListUtil.isNullOrEmpty(list)) {
|
return ExecutedResult.failed("[报警信息]不存在." + listIdNotFound);
|
}
|
}
|
return ExecutedResult.success(list);
|
}
|
|
}
|