/**
|
# __----~~~~~~~~~~~------___
|
# . . ~~//====...... __--~ ~~
|
# -. \_|// |||\\ ~~~~~~::::... /~
|
# ___-==_ _-~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.waterfacilitytype.ReqCreateWaterFacilityType;
|
import com.nanjing.water.entity.request.waterfacilitytype.ReqModifyWaterFacilityType;
|
import com.nanjing.water.entity.search.SearchWaterFacilityType;
|
import com.nanjing.water.repository.impl.WaterFacilityMapperImpl;
|
import com.nanjing.water.repository.impl.WaterFacilityTypeMapperImpl;
|
import com.nanjing.water.repository.impl.WaterMonitoryPointMapperImpl;
|
import com.nanjing.water.repository.po.WaterFacilityPO;
|
import com.nanjing.water.repository.po.WaterFacilityTypePO;
|
import com.nanjing.water.repository.po.WaterMonitoryPointPO;
|
import com.nanjing.water.repository.vo.WaterFacilityTypeVO;
|
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 WaterFacilityTypeService extends BaseService {
|
@Autowired
|
private WaterFacilityTypeMapperImpl mapper;
|
@Autowired
|
private WaterFacilityMapperImpl waterFacilityMapper;
|
@Autowired
|
private WaterMonitoryPointMapperImpl waterMonitoryPointMapper;
|
|
public ExecutedResult<Long> create(ReqCreateWaterFacilityType request) {
|
// 转换po
|
WaterFacilityTypePO item = CopierUtil.mapTo(request, WaterFacilityTypePO.class);
|
// 设置状态
|
//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(ReqModifyWaterFacilityType request) {
|
// 验证记录是否存在
|
ExecutedResult<WaterFacilityTypePO> checkExists = this.check4Id(request.getId());
|
if (checkExists.isFailed()) {
|
return ExecutedResult.failed(checkExists.getMsg());
|
}
|
// 转换po
|
WaterFacilityTypePO item = CopierUtil.mapTo(request, WaterFacilityTypePO.class);
|
|
int rowCount = mapper.updateById(item);
|
if (rowCount != 1) {
|
return ExecutedResult.failed("编辑[设备类型表]失败。");
|
}
|
return ExecutedResult.success();
|
}
|
|
public ExecutedResult<WaterFacilityTypeVO> get(Long id) {
|
WaterFacilityTypeVO result = new WaterFacilityTypeVO();
|
|
WaterFacilityTypePO find = mapper.get(id);
|
if (null != find) {
|
result = CopierUtil.mapTo(find, WaterFacilityTypeVO.class);
|
}
|
return ExecutedResult.success(result);
|
}
|
|
// public ExecutedResult<String> stop(Long id) {
|
// // 验证记录是否存在
|
// ExecutedResult<WaterFacilityTypePO> checkExists = this.check4Id(id);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// WaterFacilityTypePO item = new WaterFacilityTypePO();
|
// 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<WaterFacilityTypePO> checkExists = this.check4Id(id);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// WaterFacilityTypePO item = new WaterFacilityTypePO();
|
// item.setId(id);
|
// item.setStatus(EState.NORMAL.getValue());
|
//
|
// int rowCount = mapper.updateById(item);\n" +
|
// if (rowCount != 1) {
|
// return ExecutedResult.failed("启用[设备类型表]失败。");
|
// }
|
// return ExecutedResult.success();
|
// }
|
//
|
// public ExecutedResult<String> setSort(ReqSetSort request) {
|
// // 验证记录是否存在
|
// ExecutedResult<WaterFacilityTypePO> checkExists = this.check4Id(request.getId());
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
// WaterFacilityTypePO item = new WaterFacilityTypePO();
|
// item.setId(request.getId());
|
// item.setSort(request.getSort());
|
//
|
// int rowCount = mapper.updateById(item);\n" +
|
// 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<WaterFacilityTypePO>> checkExists = this.check4Id(listId);
|
// if (checkExists.isFailed()) {
|
// return ExecutedResult.failed(checkExists.getMsg());
|
// }
|
//
|
// List<WaterFacilityTypePO> listUpdate = request.getList().stream()
|
// .map(c -> {
|
// WaterFacilityTypePO item = new WaterFacilityTypePO();
|
// 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) {
|
int i = mapper.deleteById(id);
|
if (i<1) {
|
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<WaterFacilityTypeVO>> getList(List<Long> listId) {
|
List<WaterFacilityTypeVO> result = new ArrayList<>();
|
|
List<WaterFacilityTypePO> list = mapper.getList(listId);
|
if (ListUtil.isNotNullOrEmpty(list)) {
|
result = CopierUtil.mapTo(list, WaterFacilityTypeVO.class);
|
}
|
return ExecutedResult.success(result);
|
}
|
|
public ExecutedResult<PagerResult<WaterFacilityTypeVO>> search(SearchWaterFacilityType 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<WaterFacilityTypePO> pageList = mapper.search(search);
|
List<WaterFacilityTypeVO> listVo = new ArrayList<>();
|
List<WaterFacilityTypePO> list = pageList.getList();
|
if (ListUtil.isNotNullOrEmpty(list)) {
|
pageList.setLastId(list.get(list.size() - 1).getId());
|
// 转换vo
|
listVo = CopierUtil.mapTo(list, WaterFacilityTypeVO.class);
|
}
|
PagerResult<WaterFacilityTypeVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo);
|
result.setLastId(pageList.getLastId());
|
return ExecutedResult.success(result);
|
}
|
|
protected ExecutedResult<WaterFacilityTypePO> check4Id(Long id) {
|
WaterFacilityTypePO exists = mapper.get(id);
|
if (Objects.isNull(exists)) {
|
return ExecutedResult.failed("[设备类型表]不存在:" + id);
|
}
|
return ExecutedResult.success(exists);
|
}
|
protected ExecutedResult<List<WaterFacilityTypePO>> check4Id(List<Long> listId) {
|
// 从数据库查找设备类型表
|
List<WaterFacilityTypePO> list = mapper.getList(listId);
|
if (ListUtil.isNullOrEmpty(list)) {
|
return ExecutedResult.failed("[设备类型表]不存在." + listId);
|
}
|
// 数据库找到的id列表
|
List<Long> listIdFind = list.stream().map(WaterFacilityTypePO::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);
|
}
|
|
public ExecutedResult<List<WaterFacilityTypeVO>> getFacilityList(Integer type){
|
List<WaterFacilityTypeVO> result=new ArrayList<>();
|
List<WaterFacilityTypePO> list = mapper.getList();
|
//获取所有监测点
|
List<WaterMonitoryPointPO> pointPOList = waterMonitoryPointMapper.getListByType(type);
|
List<Long> collect = pointPOList.stream().map(WaterMonitoryPointPO::getId).collect(Collectors.toList());
|
//根据监测点获取所有设备信息
|
List<WaterFacilityPO> facilityPOList = waterFacilityMapper.getList();
|
List<WaterFacilityPO> facilityList = facilityPOList.stream().filter(x -> collect.contains(x.getPointId())).collect(Collectors.toList());
|
if(ListUtil.isNotNullOrEmpty(facilityList)){
|
List<Long> typeIdList = facilityList.stream().map(WaterFacilityPO::getFacilityType).distinct().collect(Collectors.toList());
|
List<WaterFacilityTypePO> collect1 = list.stream().filter(x -> typeIdList.contains(x.getId())).collect(Collectors.toList());
|
if(ListUtil.isNotNullOrEmpty(collect1)){
|
result=CopierUtil.mapTo(collect1, WaterFacilityTypeVO.class);
|
for(WaterFacilityTypeVO vo:result){
|
vo.setFacilityPOList(facilityList.stream().filter(x->x.getFacilityType().equals(vo.getId())).collect(Collectors.toList()));
|
}
|
}
|
}
|
return ExecutedResult.success(result);
|
}
|
}
|