/**
|
# __----~~~~~~~~~~~------___
|
# . . ~~//====...... __--~ ~~
|
# -. \_|// |||\\ ~~~~~~::::... /~
|
# ___-==_ _-~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.quartztaskerror.ReqCreateQuartzTaskError;
|
import com.nanjing.water.entity.request.quartztaskerror.ReqModifyQuartzTaskError;
|
import com.nanjing.water.entity.search.SearchQuartzTaskError;
|
import com.nanjing.water.repository.impl.QuartzTaskErrorMapperImpl;
|
import com.nanjing.water.repository.po.QuartzTaskErrorPO;
|
import com.nanjing.water.repository.vo.QuartzTaskErrorVO;
|
import com.nanjing.water.service.convert.QuartzTaskErrorConvert;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
/**
|
* 定时任务错误信息
|
* @author lin.liu
|
*/
|
@Service
|
public class QuartzTaskErrorService extends BaseService {
|
@Autowired
|
private QuartzTaskErrorMapperImpl mapper;
|
|
public ExecutedResult<Long> create(ReqCreateQuartzTaskError request) {
|
// 转换po
|
QuartzTaskErrorPO item = QuartzTaskErrorConvert.INSTANCE.toCreate(request);
|
// 设置状态
|
//item.setStatus(EState.NORMAL.getValue());
|
// 设置记录创建时间
|
item.setCreateTime(LocalDateTimeUtil.nowTimeStamp());
|
// 是否删除(逻辑删除)初始值
|
item.setIsDelete(EYesOrNo.NO.getValue());
|
|
int rowCount = mapper.insert(item);
|
if (rowCount != 1) {
|
return ExecutedResult.failed("创建[定时任务错误信息]失败。");
|
}
|
return ExecutedResult.success(item.getId());
|
}
|
|
public ExecutedResult<String> modify(ReqModifyQuartzTaskError request) {
|
// 验证记录是否存在
|
ExecutedResult<QuartzTaskErrorPO> checkExists = this.check4Id(request.getId());
|
if (checkExists.isFailed()) {
|
return ExecutedResult.failed(checkExists.getMsg());
|
}
|
// 转换po
|
QuartzTaskErrorPO item = QuartzTaskErrorConvert.INSTANCE.toModify(request);
|
|
int rowCount = mapper.updateById(item);
|
if (rowCount != 1) {
|
return ExecutedResult.failed("编辑[定时任务错误信息]失败。");
|
}
|
return ExecutedResult.success();
|
}
|
|
public ExecutedResult<QuartzTaskErrorVO> get(Long id) {
|
QuartzTaskErrorVO result = new QuartzTaskErrorVO();
|
|
QuartzTaskErrorPO find = mapper.get(id);
|
if (null != find) {
|
// 转换vo
|
result = QuartzTaskErrorConvert.INSTANCE.toVo(find);
|
}
|
return ExecutedResult.success(result);
|
}
|
|
// public ExecutedResult<String> stop(Long id) {
|
// // 验证记录是否存在
|
// ExecutedResult<QuartzTaskErrorPO> checkExists = this.check4Id(id);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// QuartzTaskErrorPO item = new QuartzTaskErrorPO();
|
// 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<QuartzTaskErrorPO> checkExists = this.check4Id(id);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// QuartzTaskErrorPO item = new QuartzTaskErrorPO();
|
// 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<QuartzTaskErrorPO> checkExists = this.check4Id(request.getId());
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// QuartzTaskErrorPO item = new QuartzTaskErrorPO();
|
// 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<QuartzTaskErrorPO>> checkExists = this.check4Id(listId);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
//
|
// List<QuartzTaskErrorPO> listUpdate = request.getList().stream()
|
// .map(c -> {
|
// QuartzTaskErrorPO item = new QuartzTaskErrorPO();
|
// 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<QuartzTaskErrorVO>> getList(List<Long> listId) {
|
List<QuartzTaskErrorVO> result = new ArrayList<>();
|
|
List<QuartzTaskErrorPO> list = mapper.getList(listId);
|
if (ListUtil.isNotNullOrEmpty(list)) {
|
// 转换vo
|
result = QuartzTaskErrorConvert.INSTANCE.toVo(list);
|
}
|
return ExecutedResult.success(result);
|
}
|
|
public ExecutedResult<PagerResult<QuartzTaskErrorVO>> search(SearchQuartzTaskError 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<QuartzTaskErrorPO> pageList = mapper.search(search);
|
List<QuartzTaskErrorVO> listVo = new ArrayList<>();
|
List<QuartzTaskErrorPO> list = pageList.getList();
|
if (ListUtil.isNotNullOrEmpty(list)) {
|
pageList.setLastId(list.get(list.size() - 1).getId());
|
// 转换vo
|
listVo = QuartzTaskErrorConvert.INSTANCE.toVo(list);
|
}
|
PagerResult<QuartzTaskErrorVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo);
|
result.setLastId(pageList.getLastId());
|
return ExecutedResult.success(result);
|
}
|
|
protected ExecutedResult<QuartzTaskErrorPO> check4Id(Long id) {
|
QuartzTaskErrorPO exists = mapper.get(id);
|
if (Objects.isNull(exists)) {
|
return ExecutedResult.failed("[定时任务错误信息]不存在:" + id);
|
}
|
return ExecutedResult.success(exists);
|
}
|
protected ExecutedResult<List<QuartzTaskErrorPO>> check4Id(List<Long> listId) {
|
// 从数据库查找定时任务错误信息
|
List<QuartzTaskErrorPO> list = mapper.getList(listId);
|
if (ListUtil.isNullOrEmpty(list)) {
|
return ExecutedResult.failed("[定时任务错误信息]不存在." + listId);
|
}
|
// 数据库找到的id列表
|
List<Long> listIdFind = list.stream().map(QuartzTaskErrorPO::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);
|
}}
|