合并装置模块和检测计划模块
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
package com.njcn.gather.source.controller;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.source.pojo.param.PqSourceParam;
|
||||
import com.njcn.gather.source.pojo.po.PqSource;
|
||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
||||
import com.njcn.gather.source.pojo.po.SourceParam;
|
||||
import com.njcn.gather.source.service.IPqSourceService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "检测源管理")
|
||||
@RestController
|
||||
@RequestMapping("/pqSource")
|
||||
@RequiredArgsConstructor
|
||||
public class PqSourceController extends BaseController {
|
||||
private final IPqSourceService pqSourceService;
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询检测源")
|
||||
@ApiImplicitParam(name = "param", value = "查询参数", required = true)
|
||||
public HttpResult<Page<PqSource>> list(@RequestBody @Validated PqSourceParam.QueryParam param) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, param);
|
||||
Page<PqSource> result = pqSourceService.listPqSource(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/getById")
|
||||
@ApiOperation("根据id查询检测源")
|
||||
@ApiImplicitParam(name = "id", value = "查询参数", required = true)
|
||||
public HttpResult<PqSource> getPqSourceById(@RequestParam("id") String id) {
|
||||
String methodDescribe = getMethodDescribe("getById");
|
||||
LogUtil.njcnDebug(log, "{},查询ID为:{}", methodDescribe, id);
|
||||
PqSource result = pqSourceService.getPqSourceById(id);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增检测源")
|
||||
@ApiImplicitParam(name = "param", value = "检测源", required = true)
|
||||
public HttpResult<Object> add(@RequestBody @Validated PqSourceParam param) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||
boolean result = pqSourceService.addPqSource(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.UPDATE)
|
||||
@PostMapping("/update")
|
||||
@ApiOperation("修改检测源")
|
||||
@ApiImplicitParam(name = "param", value = "检测源", required = true)
|
||||
public HttpResult<Object> update(@RequestBody @Validated PqSourceParam.UpdateParam param) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, param);
|
||||
boolean result = pqSourceService.updatePqSource(param);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.DELETE)
|
||||
@PostMapping("/delete")
|
||||
@ApiOperation("删除检测源")
|
||||
@ApiImplicitParam(name = "ids", value = "检测源id", required = true)
|
||||
public HttpResult<Object> delete(@RequestBody List<String> ids) {
|
||||
String methodDescribe = getMethodDescribe("delete");
|
||||
LogUtil.njcnDebug(log, "{},删除ID数据为:{}", methodDescribe, String.join(StrUtil.COMMA, ids));
|
||||
boolean result = pqSourceService.deletePqSource(ids);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/getAll")
|
||||
@ApiOperation("获取指定模式下的所有检测源")
|
||||
@ApiImplicitParam(name = "patternId", value = "模式Id", required = true)
|
||||
public HttpResult<List<Map<String, Object>>> getAllPqSource(@RequestParam("patternId") String patternId) {
|
||||
String methodDescribe = getMethodDescribe("getAllPqSource");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, patternId);
|
||||
List<Map<String, Object>> result = pqSourceService.listAllPqSource(patternId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/getSourceParam")
|
||||
@ApiOperation("按照检测源ID获取源参数")
|
||||
@ApiImplicitParam(name = "pqSourceId", value = "检测源ID", required = true)
|
||||
public HttpResult<List<SourceParam>> getSourceParam(@RequestParam("sourceId") String sourceId) {
|
||||
String methodDescribe = getMethodDescribe("getParam");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, sourceId);
|
||||
List<SourceParam> result = pqSourceService.getSourceParam(sourceId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/aa")
|
||||
@ApiOperation("按照检测源ID获取源参数")
|
||||
@ApiImplicitParam(name = "pqSourceId", value = "检测源ID", required = true)
|
||||
public HttpResult<SourceInitialize> aa(@RequestParam("sourceId") String sourceId) {
|
||||
String methodDescribe = getMethodDescribe("getParam");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, sourceId);
|
||||
SourceInitialize sourceInitializeParam = pqSourceService.getSourceInitializeParam(sourceId);
|
||||
String jsonString = JSON.toJSONString(sourceInitializeParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, sourceInitializeParam, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.gather.source.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.source.pojo.po.PqSource;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface PqSourceMapper extends MPJBaseMapper<PqSource> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.njcn.gather.source.mapper.PqSourceMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.njcn.gather.source.pojo.param;
|
||||
|
||||
import com.njcn.common.pojo.constant.PatternRegex;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import com.njcn.web.pojo.param.BaseParam;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-11-28
|
||||
*/
|
||||
@Data
|
||||
public class PqSourceParam {
|
||||
|
||||
/**
|
||||
* 检测源名称(检测源类型 + 设备类型 + 数字自动生成)
|
||||
*/
|
||||
// @ApiModelProperty(value = "检测源名称", required = true)
|
||||
// @NotBlank(message = DeviceValidMessage.NAME_NOT_BLANK)
|
||||
// @Pattern(regexp = PatternRegex.PQ_SOURCE_NAME, message = DeviceValidMessage.PQ_SOURCE_NAME_FORMAT_ERROR)
|
||||
// private String name;
|
||||
|
||||
/**
|
||||
* 检测模式,字典表
|
||||
*/
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
|
||||
private String pattern;
|
||||
|
||||
/**
|
||||
* 检测源类型,字典表
|
||||
*/
|
||||
@ApiModelProperty(value = "检测源类型", required = true)
|
||||
@NotBlank(message = DevValidMessage.PQ_SOURCE_TYPE_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PQ_SOURCE_TYPE_FORMAT_ERROR)
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 设备类型,字典表
|
||||
*/
|
||||
@ApiModelProperty(value = "设备类型", required = true)
|
||||
@NotBlank(message = DevValidMessage.DEV_TYPE_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_TYPE_FORMAT_ERROR)
|
||||
private String devType;
|
||||
|
||||
@ApiModelProperty("源参数")
|
||||
private String parameter;
|
||||
|
||||
// @ApiModelProperty("源参数")
|
||||
// private List<PqSourceParameterParam> parameterList;
|
||||
|
||||
@Data
|
||||
public static class QueryParam extends BaseParam {
|
||||
@ApiModelProperty(value = "检测源名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("模式")
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
|
||||
private String pattern;
|
||||
|
||||
@ApiModelProperty(value = "检测源类型")
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PQ_SOURCE_TYPE_FORMAT_ERROR)
|
||||
private String type;
|
||||
|
||||
@ApiModelProperty(value = "设备类型")
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.DEV_TYPE_FORMAT_ERROR)
|
||||
private String devType;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class UpdateParam extends PqSourceParam {
|
||||
@ApiModelProperty(value = "检测源ID", required = true)
|
||||
@NotBlank(message = DevValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.njcn.gather.source.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("pq_source")
|
||||
public class PqSource extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = -80375393371680137L;
|
||||
/**
|
||||
* 检测源ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 检测源名称(检测源类型 + 设备类型 + 数字自动生成)
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 检测模式,字典表
|
||||
*/
|
||||
private String pattern;
|
||||
|
||||
/**
|
||||
* 检测源类型,字典表
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 设备类型,字典表
|
||||
*/
|
||||
private String devType;
|
||||
|
||||
/**
|
||||
* 源参数
|
||||
*/
|
||||
private String parameter;
|
||||
|
||||
/**
|
||||
* 状态:0-删除 1-正常
|
||||
*/
|
||||
private Integer state;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.njcn.gather.source.pojo.po;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
public class SourceInitialize {
|
||||
|
||||
@JSONField(ordinal = 1)
|
||||
private String sourceId;
|
||||
|
||||
@JSONField(ordinal = 2)
|
||||
private String sourceType;
|
||||
|
||||
@JSONField(ordinal = 4)
|
||||
private String sourceDesc;
|
||||
|
||||
@JSONField(ordinal = 3)
|
||||
private List<Initialize> sourceParamList;
|
||||
|
||||
@Data
|
||||
public static class Initialize {
|
||||
|
||||
@JSONField(serialize = false)
|
||||
private String id;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
private String pId;
|
||||
|
||||
@JSONField(ordinal = 1)
|
||||
private String type;
|
||||
|
||||
@JSONField(ordinal = 2)
|
||||
private String desc;
|
||||
|
||||
|
||||
@JSONField(ordinal =4)
|
||||
private String value;
|
||||
|
||||
@JSONField(serialize = false)
|
||||
private Integer sort;
|
||||
|
||||
@JSONField(ordinal = 3)
|
||||
private List<Initialize> children;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.njcn.gather.source.pojo.po;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
public class SourceParam {
|
||||
private String id;
|
||||
|
||||
private String pId;
|
||||
|
||||
private String type;
|
||||
|
||||
private String desc;
|
||||
|
||||
private String value;
|
||||
|
||||
private Integer sort;
|
||||
|
||||
private List<SourceParam> children;
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package com.njcn.gather.source.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.source.pojo.param.PqSourceParam;
|
||||
import com.njcn.gather.source.pojo.po.PqSource;
|
||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
||||
import com.njcn.gather.source.pojo.po.SourceParam;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface IPqSourceService extends IService<PqSource> {
|
||||
|
||||
/**
|
||||
* 分页查询检测源
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return 分页数据
|
||||
*/
|
||||
Page<PqSource> listPqSource(PqSourceParam.QueryParam param);
|
||||
|
||||
/**
|
||||
* 根据id查询检测源
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
PqSource getPqSourceById(String id);
|
||||
|
||||
/**
|
||||
* 新增检测源
|
||||
*
|
||||
* @param param 新增参数
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean addPqSource(PqSourceParam param);
|
||||
|
||||
/**
|
||||
* 修改检测源
|
||||
*
|
||||
* @param param 修改参数
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean updatePqSource(PqSourceParam.UpdateParam param);
|
||||
|
||||
/**
|
||||
* 删除检测源
|
||||
*
|
||||
* @param ids 检测源id列表
|
||||
* @return 成功返回true,失败返回false
|
||||
*/
|
||||
boolean deletePqSource(List<String> ids);
|
||||
|
||||
/**
|
||||
* 获取指定模式下的所有检测源
|
||||
*
|
||||
* @param patternId 模式Id
|
||||
* @return 检测源列表
|
||||
*/
|
||||
List<Map<String, Object>> listAllPqSource(String patternId);
|
||||
|
||||
/**
|
||||
* 获取指定检测源的指定参数
|
||||
*
|
||||
* @param sourceId 检测源Id
|
||||
* @return 源参数
|
||||
*/
|
||||
List<SourceParam> getSourceParam(String sourceId);
|
||||
|
||||
/**
|
||||
* 根据源参数组装源初始化参数
|
||||
*
|
||||
* @param sourceId
|
||||
* @return
|
||||
*/
|
||||
SourceInitialize getSourceInitializeParam(String sourceId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据名称获取检测源Id列表
|
||||
*
|
||||
* @param sourceNames 检测源名称列表
|
||||
* @return
|
||||
*/
|
||||
List<String> listPqSourceIdByName(String[] sourceNames);
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
package com.njcn.gather.source.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.gather.device.pojo.enums.CommonEnum;
|
||||
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
|
||||
import com.njcn.gather.source.mapper.PqSourceMapper;
|
||||
import com.njcn.gather.source.pojo.param.PqSourceParam;
|
||||
import com.njcn.gather.source.pojo.po.PqSource;
|
||||
import com.njcn.gather.source.pojo.po.SourceInitialize;
|
||||
import com.njcn.gather.source.pojo.po.SourceParam;
|
||||
import com.njcn.gather.source.service.IPqSourceService;
|
||||
import com.njcn.gather.type.entity.DevType;
|
||||
import com.njcn.gather.type.service.IDevTypeService;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class PqSourceServiceImpl extends ServiceImpl<PqSourceMapper, PqSource> implements IPqSourceService {
|
||||
|
||||
private final IDictDataService dictDataService;
|
||||
private final IDevTypeService devTypeService;
|
||||
|
||||
@Override
|
||||
public Page<PqSource> listPqSource(PqSourceParam.QueryParam param) {
|
||||
QueryWrapper<PqSource> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select(PqSource.class, pqSource -> !pqSource.getColumn().equals("parameter"));
|
||||
if (ObjectUtil.isNotNull(param)) {
|
||||
queryWrapper.like(StrUtil.isNotBlank(param.getName()), "pq_source.name", param.getName())
|
||||
.eq(StrUtil.isNotBlank(param.getPattern()), "pq_source.pattern", param.getPattern())
|
||||
.eq(StrUtil.isNotBlank(param.getType()), "pq_source.type", param.getType())
|
||||
.eq(StrUtil.isNotBlank(param.getDevType()), "pq_source.Dev_Type", param.getDevType());
|
||||
}
|
||||
queryWrapper.eq("pq_source.state", DataStateEnum.ENABLE.getCode());
|
||||
return this.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PqSource getPqSourceById(String id) {
|
||||
return this.lambdaQuery().eq(PqSource::getId, id).eq(PqSource::getState, DataStateEnum.ENABLE.getCode()).one();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean addPqSource(PqSourceParam param) {
|
||||
PqSource pqSource = new PqSource();
|
||||
BeanUtil.copyProperties(param, pqSource);
|
||||
pqSource.setName(this.generatePqSourceName(param, true));
|
||||
pqSource.setParameter(StrUtil.isBlank(pqSource.getParameter()) ? null : pqSource.getParameter());
|
||||
pqSource.setState(DataStateEnum.ENABLE.getCode());
|
||||
return this.save(pqSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean updatePqSource(PqSourceParam.UpdateParam param) {
|
||||
PqSource pqSource = new PqSource();
|
||||
BeanUtil.copyProperties(param, pqSource);
|
||||
pqSource.setName(this.generatePqSourceName(param, false));
|
||||
return this.updateById(pqSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public boolean deletePqSource(List<String> ids) {
|
||||
return this.lambdaUpdate().in(PqSource::getId, ids).set(PqSource::getState, DataStateEnum.DELETED.getCode()).update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listAllPqSource(String patternId) {
|
||||
List<PqSource> pqSourceList = this.lambdaQuery().eq(PqSource::getPattern, patternId).eq(PqSource::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
List<Map<String, Object>> result = pqSourceList.stream().map(pqSource -> {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", pqSource.getId());
|
||||
map.put("name", pqSource.getName());
|
||||
return map;
|
||||
}).collect(Collectors.toList());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SourceParam> getSourceParam(String sourceId) {
|
||||
PqSource pqSource = this.lambdaQuery().eq(PqSource::getId, sourceId).eq(PqSource::getState, DataStateEnum.ENABLE.getCode()).one();
|
||||
if (ObjectUtil.isNotNull(pqSource)) {
|
||||
String parameter = pqSource.getParameter();
|
||||
if (StrUtil.isNotBlank(parameter)) {
|
||||
List<SourceParam> list = new JSONArray(parameter).toList(SourceParam.class);
|
||||
List<SourceParam> sourceParams = list.stream().filter(p -> p.getPId().equals(CommonEnum.FATHER_ID.getValue()))
|
||||
.peek(p -> p.setChildren(getChildren(p, list)))
|
||||
.sorted(Comparator.comparingInt(SourceParam::getSort))
|
||||
.collect(Collectors.toList());
|
||||
return sourceParams;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SourceInitialize getSourceInitializeParam(String sourceId) {
|
||||
PqSource pqSource = this.lambdaQuery().eq(PqSource::getId, sourceId).eq(PqSource::getState, DataStateEnum.ENABLE.getCode()).one();
|
||||
if (ObjectUtil.isNotNull(pqSource)) {
|
||||
String parameter = pqSource.getParameter();
|
||||
if (StrUtil.isNotBlank(parameter)) {
|
||||
List<SourceInitialize.Initialize> list = new JSONArray(parameter).toList(SourceInitialize.Initialize.class);
|
||||
List<SourceInitialize.Initialize> sourceParams = list.stream().filter(p -> p.getPId().equals(CommonEnum.FATHER_ID.getValue()))
|
||||
.peek(p -> p.setChildren(getInitializeChildren(p, list)))
|
||||
.sorted(Comparator.comparingInt(SourceInitialize.Initialize::getSort))
|
||||
.collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(sourceParams)){
|
||||
SourceInitialize initialize=new SourceInitialize();
|
||||
SourceInitialize.Initialize source = sourceParams.get(0);
|
||||
initialize.setSourceId(source.getValue());
|
||||
initialize.setSourceType(source.getType());
|
||||
initialize.setSourceDesc(source.getDesc());
|
||||
initialize.setSourceParamList(source.getChildren());
|
||||
return initialize;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listPqSourceIdByName(String[] sourceNames) {
|
||||
return this.lambdaQuery().in(PqSource::getName, sourceNames).eq(PqSource::getState, DataStateEnum.ENABLE.getCode()).list().stream().map(PqSource::getId).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<SourceParam> getChildren(SourceParam current, List<SourceParam> list) {
|
||||
return list.stream()
|
||||
.filter(p -> p.getPId().equals(current.getId()))
|
||||
.peek(p -> p.setChildren(getChildren(p, list)))
|
||||
.sorted(Comparator.comparingInt(SourceParam::getSort))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private List<SourceInitialize.Initialize> getInitializeChildren(SourceInitialize.Initialize current, List<SourceInitialize.Initialize> list) {
|
||||
return list.stream()
|
||||
.filter(p -> p.getPId().equals(current.getId()))
|
||||
.peek(p -> p.setChildren(getInitializeChildren(p, list)))
|
||||
.sorted(Comparator.comparingInt(SourceInitialize.Initialize::getSort))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// private List<SourceParam> filterTree(List<SourceParam> tree, String keyword) {
|
||||
// if (CollectionUtils.isEmpty(tree) || StrUtil.isBlank(keyword)) {
|
||||
// return tree;
|
||||
// }
|
||||
// filter(tree, keyword);
|
||||
// return tree;
|
||||
// }
|
||||
|
||||
// private void filter(List<SourceParam> list, String keyword) {
|
||||
// for (int i = list.size() - 1; i >= 0; i--) {
|
||||
// SourceParam sourceParam = list.get(i);
|
||||
// List<SourceParam> children = sourceParam.getChildren();
|
||||
// if (!keyword.equals(sourceParam.getType())) {
|
||||
// if (!CollectionUtils.isEmpty(children)) {
|
||||
// filter(children, keyword);
|
||||
// }
|
||||
// if (CollectionUtils.isEmpty(sourceParam.getChildren())) {
|
||||
// list.remove(i);
|
||||
// }
|
||||
// }
|
||||
// else {
|
||||
// if (!CollectionUtils.isEmpty(children)) {
|
||||
// filter(children, keyword);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 生成检测源名称(检测源类型+设备类型+数字)
|
||||
*
|
||||
* @return 检测源名称
|
||||
*/
|
||||
private String generatePqSourceName(PqSourceParam param, boolean isAdd) {
|
||||
DevType devType = devTypeService.getById(param.getDevType());
|
||||
DictData typeDictData = dictDataService.getDictDataById(param.getType());
|
||||
|
||||
if (ObjectUtil.isNotNull(devType) && ObjectUtil.isNotNull(typeDictData)) {
|
||||
if (isAdd) {
|
||||
int count = this.lambdaQuery().eq(PqSource::getPattern, param.getPattern()).count();
|
||||
return typeDictData.getName() + "-" + devType.getName() + "-" + (count + 1);
|
||||
} else {
|
||||
PqSource pqSource = this.lambdaQuery().eq(PqSource::getId, ((PqSourceParam.UpdateParam) param).getId()).one();
|
||||
if (ObjectUtil.isNotNull(pqSource)) {
|
||||
String name = pqSource.getName();
|
||||
if (StrUtil.isNotBlank(name)) {
|
||||
int index = name.lastIndexOf("-");
|
||||
return typeDictData.getName() + "-" + devType.getName() + "-" + name.substring(index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new BusinessException(DevResponseEnum.PQ_SOURCE_GEN_NAME_ERROR);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user