项目结构调整
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
package com.njcn.gather.plan.controller;
|
||||
|
||||
import cn.afterturn.easypoi.excel.ExcelImportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ImportParams;
|
||||
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.device.device.pojo.vo.PqDevExcel;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
|
||||
import com.njcn.gather.device.pojo.enums.PatternEnum;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import com.njcn.web.utils.ExcelUtil;
|
||||
import com.njcn.web.utils.HttpResultUtil;
|
||||
import com.njcn.web.utils.PoiUtil;
|
||||
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.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Slf4j
|
||||
@Api(tags = "检测计划管理")
|
||||
@RestController
|
||||
@RequestMapping("/adPlan")
|
||||
@RequiredArgsConstructor
|
||||
public class AdPlanController extends BaseController {
|
||||
|
||||
private final IAdPlanService adPlanService;
|
||||
private final IPqDevService pqDevService;
|
||||
|
||||
@OperateInfo
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("分页查询检测计划")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public HttpResult<Page<AdPlanVO>> list(@RequestBody @Validated AdPlanParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
Page<AdPlanVO> result = adPlanService.listAdPlan(queryParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.ADD)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增检测计划")
|
||||
@ApiImplicitParam(name = "pqDevParam", value = "检测计划", required = true)
|
||||
public HttpResult<Object> add(@RequestBody @Validated AdPlanParam param) {
|
||||
String methodDescribe = getMethodDescribe("add");
|
||||
LogUtil.njcnDebug(log, "{},新增数据为:{}", methodDescribe, param);
|
||||
boolean result = adPlanService.addAdPlan(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 = "updateParam", value = "检测计划", required = true)
|
||||
public HttpResult<Object> update(@RequestBody @Validated AdPlanParam.UpdateParam updateParam) {
|
||||
String methodDescribe = getMethodDescribe("update");
|
||||
LogUtil.njcnDebug(log, "{},修改数据为:{}", methodDescribe, updateParam);
|
||||
boolean result = adPlanService.updateAdPlan(updateParam);
|
||||
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 = adPlanService.deleteAdPlan(ids);
|
||||
if (result) {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
} else {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/listByPattern")
|
||||
@ApiOperation("按照模式查询检测计划")
|
||||
@ApiImplicitParam(name = "pattern", value = "模式Id", required = true)
|
||||
public HttpResult<List<Map<String, Object>>> listByPattern(@RequestParam("pattern") String pattern) {
|
||||
String methodDescribe = getMethodDescribe("listByPattern");
|
||||
LogUtil.njcnDebug(log, "{},模式Id为:{}", methodDescribe, pattern);
|
||||
List<Map<String, Object>> result = adPlanService.listByPattern(pattern);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(operateType = OperateType.DOWNLOAD)
|
||||
@PostMapping("/export")
|
||||
@ApiOperation("导出检测计划")
|
||||
@ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
|
||||
public void export(@RequestBody @Validated AdPlanParam.QueryParam queryParam) {
|
||||
String methodDescribe = getMethodDescribe("download");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, queryParam);
|
||||
List<AdPlanExcel> data = adPlanService.getExportData(queryParam);
|
||||
ExcelUtil.exportExcel("检测计划导出数据.xlsx", AdPlanExcel.class, data);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPLOAD)
|
||||
@PostMapping(value = "/import")
|
||||
@ApiOperation("批量导入检测计划数据")
|
||||
@ApiImplicitParam(name = "file", value = "检测计划数据文件", required = true)
|
||||
public HttpResult<Object> importData(@RequestParam("file") MultipartFile file, HttpServletResponse response) {
|
||||
String methodDescribe = getMethodDescribe("importData");
|
||||
LogUtil.njcnDebug(log, "{},上传文件为:{}", methodDescribe, file.getOriginalFilename());
|
||||
|
||||
try {
|
||||
Workbook workBook = ExcelUtil.getWorkBook(file);
|
||||
int numberOfSheets = workBook.getNumberOfSheets();
|
||||
if (numberOfSheets == 2) {
|
||||
ImportParams params = new ImportParams();
|
||||
params.setHeadRows(1);
|
||||
params.setNeedVerify(true);
|
||||
params.setSheetNum(1);
|
||||
|
||||
params.setStartSheetIndex(0);
|
||||
ExcelImportResult<AdPlanExcel> adPlanExcelResult = ExcelImportUtil.importExcelMore(file.getInputStream(), AdPlanExcel.class, params);
|
||||
if (adPlanExcelResult.isVerifyFail()) {
|
||||
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
|
||||
PoiUtil.exportFileByWorkbook(adPlanExcelResult.getFailWorkbook(), "非法检测计划数据.xlsx", response);
|
||||
} else {
|
||||
List<AdPlanExcel> adPlanExcelList = adPlanExcelResult.getList();
|
||||
if (ObjectUtil.isNotEmpty(adPlanExcelList)) {
|
||||
params.setStartSheetIndex(1);
|
||||
String pattern = adPlanExcelList.get(0).getPattern();
|
||||
if (PatternEnum.CONTRAST.getValue().equals(pattern)) {
|
||||
ExcelImportResult<PqDevExcel.ContrastImportData> pqDevExcelResult = ExcelImportUtil.importExcelMore(file.getInputStream(), PqDevExcel.ContrastImportData.class, params);
|
||||
if (pqDevExcelResult.isVerifyFail()) {
|
||||
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
|
||||
PoiUtil.exportFileByWorkbook(pqDevExcelResult.getFailWorkbook(), "非法检测计划数据.xlsx", response);
|
||||
} else {
|
||||
adPlanService.importData(adPlanExcelList);
|
||||
pqDevService.importContrastData(pqDevExcelResult.getList());
|
||||
}
|
||||
} else {
|
||||
ExcelImportResult<PqDevExcel.SimulateOrDigitalImportData> pqDevExcelResult = ExcelImportUtil.importExcelMore(file.getInputStream(), PqDevExcel.SimulateOrDigitalImportData.class, params);
|
||||
if (pqDevExcelResult.isVerifyFail()) {
|
||||
// 此处前端要做特殊处理,具体可以参考技术监督的数据导入
|
||||
PoiUtil.exportFileByWorkbook(pqDevExcelResult.getFailWorkbook(), "非法检测计划数据.xlsx", response);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new BusinessException(DevResponseEnum.IMPORT_DATA_FAIL);
|
||||
}
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo
|
||||
@GetMapping("/getPieData")
|
||||
@ApiOperation("获取饼状图数据")
|
||||
@ApiImplicitParam(name = "id", value = "检测计划id", required = true)
|
||||
public HttpResult<List<List<Map<String, Object>>>> getPieData(@RequestParam("planId") String planId) {
|
||||
String methodDescribe = getMethodDescribe("getPieData");
|
||||
LogUtil.njcnDebug(log, "{},查询数据为:{}", methodDescribe, planId);
|
||||
List<List<Map<String, Object>>> result = pqDevService.getPieData(planId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.njcn.gather.plan.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
public interface AdPlanMapper extends MPJBaseMapper<AdPlan> {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.gather.plan.mapper;
|
||||
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||
import com.njcn.gather.device.source.pojo.po.PqSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
public interface AdPlanSourceMapper extends MPJBaseMapper<AdPlanSource> {
|
||||
|
||||
/**
|
||||
* 根据检测计划id获取检测源
|
||||
*
|
||||
* @param planId 检测计划id
|
||||
* @return 检测源列表
|
||||
*/
|
||||
List<PqSource> selectPqSourceByPlanId(String planId);
|
||||
}
|
||||
|
||||
@@ -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.plan.mapper.AdPlanMapper">
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
<?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.plan.mapper.AdPlanSourceMapper">
|
||||
|
||||
|
||||
<select id="selectPqSourceByPlanId" resultType="com.njcn.gather.device.source.pojo.po.PqSource">
|
||||
SELECT pq_source.*
|
||||
FROM pq_source,
|
||||
ad_plan_source
|
||||
WHERE pq_source.id = ad_plan_source.Source_Id
|
||||
AND ad_plan_source.Plan_Id = #{planId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.gather.plan.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-12
|
||||
*/
|
||||
@Getter
|
||||
public enum DataSourceEnum {
|
||||
THREE_SENSE_ACTUAL_TIME_DATA("0", "3秒实时数据"),
|
||||
|
||||
MINUTE_STATISTICS_MAX("1", "分钟统计数据-最大"),
|
||||
MINUTE_STATISTICS_MIN("2", "分钟统计数据-最小"),
|
||||
MINUTE_STATISTICS_AVG("3", "分钟统计数据-平均"),
|
||||
MINUTE_STATISTICS_CP95("4", "分钟统计数据-CP95"),
|
||||
RECORDED_DATA("5", "录播数据");
|
||||
|
||||
private String value;
|
||||
private String msg;
|
||||
|
||||
DataSourceEnum(String value, String msg) {
|
||||
this.value = value;
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public static String getMsgByValue(String value) {
|
||||
for (DataSourceEnum dataSourceEnum : DataSourceEnum.values()) {
|
||||
if (dataSourceEnum.getValue().equals(value)) {
|
||||
return dataSourceEnum.getMsg();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getValueByMsg(String msg) {
|
||||
for (DataSourceEnum dataSourceEnum : DataSourceEnum.values()) {
|
||||
if (dataSourceEnum.getMsg().equals(msg)) {
|
||||
return dataSourceEnum.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
package com.njcn.gather.plan.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.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
public class AdPlanParam {
|
||||
|
||||
@ApiModelProperty(value = "名称", required = true)
|
||||
@NotBlank(message = DevValidMessage.NAME_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.PLAN_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "模式", required = true)
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
|
||||
private String pattern;
|
||||
|
||||
// @ApiModelProperty(value = "父计划ID")
|
||||
// @Pattern(regexp = PatternRegex.SYSTEM_ID, message = DeviceValidMessage.PATTERN_FORMAT_ERROR)
|
||||
// private String fatherPlanId;
|
||||
|
||||
@ApiModelProperty(value = "检测源ID列表",required = true)
|
||||
@NotEmpty(message = DevValidMessage.SOURCE_IDS_NOT_EMPTY)
|
||||
private List<@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.SOURCE_ID_FORMAT_ERROR)String> sourceIds;
|
||||
|
||||
@ApiModelProperty(value = "数据源ID列表", required = true)
|
||||
@NotEmpty(message = DevValidMessage.DATASOURCE_ID_NOT_EMPTY)
|
||||
private List<String> datasourceIds;
|
||||
|
||||
@ApiModelProperty(value = "检测脚本ID", required = true)
|
||||
@NotBlank(message = DevValidMessage.SCRIPT_ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.SCRIPT_ID_FORMAT_ERROR)
|
||||
private String scriptId;
|
||||
|
||||
@ApiModelProperty(value = "误差体系ID", required = true)
|
||||
@NotBlank(message = DevValidMessage.ERROR_SYS_ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ERROR_SYS_ID_FORMAT_ERROR)
|
||||
private String errorSysId;
|
||||
|
||||
@ApiModelProperty(value = "守时检测")
|
||||
@NotNull(message = DevValidMessage.TIME_CHECK_NOT_NULL)
|
||||
@Min(value = 0, message = DevValidMessage.TIME_CHECK_FORMAT_ERROR)
|
||||
@Max(value = 1, message = DevValidMessage.TIME_CHECK_FORMAT_ERROR)
|
||||
private Integer timeCheck;
|
||||
|
||||
@ApiModelProperty("被检设备ID列表")
|
||||
@NotNull(message = DevValidMessage.PQ_DEV_IDS_NOT_NULL)
|
||||
private List<String> devIds;
|
||||
|
||||
/**
|
||||
* 分页查询实体
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class QueryParam extends BaseParam {
|
||||
@ApiModelProperty("名称")
|
||||
@Pattern(regexp = PatternRegex.DEV_NAME_REGEX, message = DevValidMessage.NAME_FORMAT_ERROR)
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "模式,字典表(数字、模拟、比对)")
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.PATTERN_FORMAT_ERROR)
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
private String pattern;
|
||||
|
||||
@ApiModelProperty(value = "检测状态")
|
||||
@Min(value = 0, message = DevValidMessage.TEST_STATE_FORMAT_ERROR)
|
||||
@Max(value = 2, message = DevValidMessage.TEST_STATE_FORMAT_ERROR)
|
||||
private Integer testState;
|
||||
|
||||
@ApiModelProperty(value = "报告生成状态")
|
||||
@Min(value = 0, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
@Max(value = 2, message = DevValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
private Integer reportState;
|
||||
|
||||
@ApiModelProperty(value = "检测结果")
|
||||
@Min(value = 0, message = DevValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
|
||||
@Max(value = 2, message = DevValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
|
||||
private Integer result;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class UpdateParam extends AdPlanParam {
|
||||
@ApiModelProperty(value = "id", required = true)
|
||||
@NotBlank(message = DevValidMessage.ID_NOT_BLANK)
|
||||
@Pattern(regexp = PatternRegex.SYSTEM_ID, message = DevValidMessage.ID_FORMAT_ERROR)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 检测状态,字典表(未检、检测中、检测完成)
|
||||
*/
|
||||
// @ApiModelProperty(value = "检测状态")
|
||||
// @NotNull(message = DeviceValidMessage.TEST_STATE_NOT_NULL)
|
||||
// @Min(value = 0, message = DeviceValidMessage.TEST_STATE_FORMAT_ERROR)
|
||||
// @Max(value = 2, message = DeviceValidMessage.TEST_STATE_FORMAT_ERROR)
|
||||
// private Integer testState;
|
||||
|
||||
/**
|
||||
* 报告生成状态,字典表(未生成、部分生成、全部生成)
|
||||
*/
|
||||
// @ApiModelProperty(value = "报告生成状态")
|
||||
// @NotNull(message = DeviceValidMessage.REPORT_STATE_NOT_NULL)
|
||||
// @Min(value = 0, message = DeviceValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
// @Max(value = 2, message = DeviceValidMessage.REPORT_STATE_FORMAT_ERROR)
|
||||
// private Integer reportState;
|
||||
|
||||
/**
|
||||
* 检测结果,字典表(符合、不符合、/)
|
||||
*/
|
||||
// @ApiModelProperty(value = "检测结果")
|
||||
// @NotNull(message = DeviceValidMessage.CHECK_RESULT_STATE_NOT_NULL)
|
||||
// @Min(value = 0, message = DeviceValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
|
||||
// @Max(value = 2, message = DeviceValidMessage.CHECK_RESULT_STATE_FORMAT_ERROR)
|
||||
// private Integer result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.njcn.gather.plan.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.njcn.db.mybatisplus.bo.BaseEntity;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("ad_plan")
|
||||
public class AdPlan extends BaseEntity implements Serializable {
|
||||
private static final long serialVersionUID = 923200973006628094L;
|
||||
|
||||
/**
|
||||
* 检测计划ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 检测计划名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 模式,字典表(数字、模拟、比对)
|
||||
*/
|
||||
private String pattern;
|
||||
|
||||
/**
|
||||
* 父计划ID
|
||||
*/
|
||||
private String fatherPlanId;
|
||||
|
||||
/**
|
||||
* 数据源ID,字典表
|
||||
*/
|
||||
private String datasourceId;
|
||||
|
||||
/**
|
||||
* 检测脚本ID,关联PQ_Script表
|
||||
*/
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 误差体系ID,关联PQ_Error_Sys表
|
||||
*/
|
||||
private String errorSysId;
|
||||
|
||||
/**
|
||||
* 守时检测
|
||||
*/
|
||||
private Integer timeCheck;
|
||||
|
||||
/**
|
||||
* 检测状态,字典表(未检、检测中、检测完成)
|
||||
*/
|
||||
private Integer testState;
|
||||
|
||||
/**
|
||||
* 报告生成状态,字典表(未生成、部分生成、全部生成)
|
||||
*/
|
||||
private Integer reportState;
|
||||
|
||||
/**
|
||||
* 检测结果,字典表(符合、不符合)
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 自动生成,用于生成数据表后缀
|
||||
*/
|
||||
private Integer code;
|
||||
|
||||
/**
|
||||
* 状态:0-删除 1-正常
|
||||
*/
|
||||
private Integer state;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.njcn.gather.plan.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
@TableName("ad_plan_source")
|
||||
@AllArgsConstructor
|
||||
public class AdPlanSource implements Serializable {
|
||||
private static final long serialVersionUID = -76292730578149530L;
|
||||
/**
|
||||
* 检测计划表Id
|
||||
*/
|
||||
private String planId;
|
||||
|
||||
/**
|
||||
* 检测源表Id
|
||||
*/
|
||||
private String sourceId;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.njcn.gather.plan.pojo.vo;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import cn.afterturn.easypoi.excel.annotation.ExcelCollection;
|
||||
import com.njcn.gather.device.device.pojo.vo.PqDevExcel;
|
||||
import com.njcn.gather.device.pojo.constant.DevValidMessage;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-11
|
||||
*/
|
||||
@Data
|
||||
public class AdPlanExcel {
|
||||
@Excel(name = "名称", width = 40)
|
||||
private String name;
|
||||
|
||||
@Excel(name = "模式", width = 20)
|
||||
@NotBlank(message = DevValidMessage.PATTERN_NOT_BLANK)
|
||||
private String pattern;
|
||||
|
||||
@Excel(name = "父计划id", width = 25)
|
||||
private String fatherPlanId;
|
||||
|
||||
@Excel(name = "数据源", width = 20)
|
||||
private String datasource;
|
||||
|
||||
@Excel(name = "脚本", width = 50)
|
||||
private String script;
|
||||
|
||||
@Excel(name = "误差体系", width = 30)
|
||||
private String errorSys;
|
||||
|
||||
@Excel(name = "是否做守时检测", width = 15, replace = {"否_0", "是_1"})
|
||||
private Integer timeCheck;
|
||||
|
||||
@Excel(name = "检测状态", width = 10, replace = {"未检_0", "检测中_1", "检测完成_2"})
|
||||
private Integer testState;
|
||||
|
||||
@Excel(name = "报告生成状态", width = 15, replace = {"未生成_0", "部分生成_1", "全部生成_2"})
|
||||
private Integer reportState;
|
||||
|
||||
@Excel(name = "检测结果", width = 10, replace = {"不符合_0", "符合_1", "未检_2"})
|
||||
private Integer result;
|
||||
|
||||
@Excel(name = "数据表后缀", width = 20)
|
||||
private Integer code;
|
||||
|
||||
@ExcelCollection(name = "绑定的设备")
|
||||
private List<PqDevExcel> devices;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package com.njcn.gather.plan.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2024-12-09
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AdPlanVO {
|
||||
|
||||
/**
|
||||
* 检测计划ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 检测计划名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 模式,字典表(数字、模拟、比对)
|
||||
*/
|
||||
private String pattern;
|
||||
|
||||
/**
|
||||
* 父计划ID
|
||||
*/
|
||||
private String fatherPlanId;
|
||||
|
||||
/**
|
||||
* 数据源ID列表
|
||||
*/
|
||||
private List<String> datasourceIds;
|
||||
|
||||
/**
|
||||
* 检测源id
|
||||
*/
|
||||
private List<String> sourceIds;
|
||||
|
||||
/**
|
||||
* 检测源名称
|
||||
*/
|
||||
private List<String> sourceName;
|
||||
|
||||
/**
|
||||
* 检测脚本ID,关联PQ_Script表
|
||||
*/
|
||||
private String scriptId;
|
||||
|
||||
/**
|
||||
* 检测脚本名称
|
||||
*/
|
||||
private String scriptName;
|
||||
|
||||
/**
|
||||
* 误差体系ID,关联PQ_Error_Sys表
|
||||
*/
|
||||
private String errorSysId;
|
||||
|
||||
/**
|
||||
* 误差体系名称
|
||||
*/
|
||||
private String errorSysName;
|
||||
|
||||
/**
|
||||
* 守时检测
|
||||
*/
|
||||
private Integer timeCheck;
|
||||
|
||||
/**
|
||||
* 检测状态,字典表(未检、检测中、检测完成)
|
||||
*/
|
||||
private Integer testState;
|
||||
|
||||
/**
|
||||
* 报告生成状态,字典表(未生成、部分生成、全部生成)
|
||||
*/
|
||||
private Integer reportState;
|
||||
|
||||
/**
|
||||
* 检测结果,字典表(符合、不符合)
|
||||
*/
|
||||
private Integer result;
|
||||
|
||||
/**
|
||||
* 自动生成,用于生成数据表后缀
|
||||
*/
|
||||
private Integer code;
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package com.njcn.gather.plan.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
public interface IAdPlanService extends IService<AdPlan> {
|
||||
|
||||
/**
|
||||
* 分页查询检测计划
|
||||
*
|
||||
* @param queryParam 分页查询参数
|
||||
* @return 分页查询结果
|
||||
*/
|
||||
Page<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 新增检测计划
|
||||
*
|
||||
* @param param 检测计划参数
|
||||
* @return 新增成功则返回true,否则返回false
|
||||
*/
|
||||
boolean addAdPlan(AdPlanParam param);
|
||||
|
||||
/**
|
||||
* 更新检测计划
|
||||
*
|
||||
* @param param 更新参数
|
||||
* @return 更新成功则返回true,否则返回false
|
||||
*/
|
||||
boolean updateAdPlan(AdPlanParam.UpdateParam param);
|
||||
|
||||
/**
|
||||
* 删除检测计划
|
||||
*
|
||||
* @param ids 检测计划id列表
|
||||
* @return 删除成功则返回true,否则返回false
|
||||
*/
|
||||
boolean deleteAdPlan(List<String> ids);
|
||||
|
||||
/**
|
||||
* 根据模式查询检测计划
|
||||
*
|
||||
* @param pattern 模式Id
|
||||
* @return 检测计划列表
|
||||
*/
|
||||
List<Map<String, Object>> listByPattern(String pattern);
|
||||
|
||||
/**
|
||||
* 获取检测计划导出时所需的SheetList (包含与之关联的设备信息)
|
||||
*
|
||||
* @param queryParam 查询参数
|
||||
* @return SheetList
|
||||
*/
|
||||
//List<Map<String, Object>> getAdPlanEexportSheetList(AdPlanParam.QueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 获取检测计划导出数据
|
||||
*
|
||||
* @param queryParam 查询参数
|
||||
* @return 检测计划导出数据
|
||||
*/
|
||||
List<AdPlanExcel> getExportData(AdPlanParam.QueryParam queryParam);
|
||||
|
||||
/**
|
||||
* 导入检测计划
|
||||
*
|
||||
* @param adPlanExcelList 检测计划Excel列表
|
||||
* @return 导入成功则返回true,否则返回false
|
||||
*/
|
||||
void importData(List<AdPlanExcel> adPlanExcelList);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.njcn.gather.plan.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||
import com.njcn.gather.device.source.pojo.po.PqSource;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
public interface IAdPlanSourceService extends IService<AdPlanSource> {
|
||||
/**
|
||||
* 根据检测计划id获取检测源
|
||||
*
|
||||
* @param planId 检测计划id
|
||||
* @return 检测源列表
|
||||
*/
|
||||
List<PqSource> listPqSourceByPlanId(String planId);
|
||||
|
||||
/**
|
||||
* 新增检测计划关联检测源数据
|
||||
*
|
||||
* @param planId 检测计划id
|
||||
* @param sourceIds 检测源id列表
|
||||
* @return 新增成功返回true,否则返回false
|
||||
*/
|
||||
boolean addAdPlanSource(String planId, List<String> sourceIds);
|
||||
|
||||
/**
|
||||
* 根据检测计划id删除关联的检测源数据
|
||||
*
|
||||
* @param planIds 检测计划id列表
|
||||
* @return 删除成功返回true,否则返回false
|
||||
*/
|
||||
boolean deleteAdPlanSourceByPlanIds(List<String> planIds);
|
||||
|
||||
/**
|
||||
* 更新检测计划关联的检测源数据
|
||||
*
|
||||
* @param planId 检测计划id
|
||||
* @param sourceIds 检测源id列表
|
||||
* @return 更新成功返回true,否则返回false
|
||||
*/
|
||||
boolean updateAdPlanSource(String planId, List<String> sourceIds);
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
package com.njcn.gather.plan.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
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.device.pojo.enums.TimeCheckResultEnum;
|
||||
import com.njcn.gather.device.device.pojo.param.PqDevParam;
|
||||
import com.njcn.gather.device.device.pojo.po.PqDev;
|
||||
import com.njcn.gather.device.device.service.IPqDevService;
|
||||
import com.njcn.gather.device.err.service.IPqErrSysService;
|
||||
import com.njcn.gather.device.pojo.constant.DevConst;
|
||||
import com.njcn.gather.device.pojo.enums.CheckResultEnum;
|
||||
import com.njcn.gather.device.pojo.enums.CheckStateEnum;
|
||||
import com.njcn.gather.device.pojo.enums.DevResponseEnum;
|
||||
import com.njcn.gather.device.pojo.enums.PlanReportStateEnum;
|
||||
import com.njcn.gather.device.script.service.IPqScriptService;
|
||||
import com.njcn.gather.device.source.pojo.po.PqSource;
|
||||
import com.njcn.gather.plan.mapper.AdPlanMapper;
|
||||
import com.njcn.gather.plan.pojo.enums.DataSourceEnum;
|
||||
import com.njcn.gather.plan.pojo.param.AdPlanParam;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlan;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanExcel;
|
||||
import com.njcn.gather.plan.pojo.vo.AdPlanVO;
|
||||
import com.njcn.gather.plan.service.IAdPlanService;
|
||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AdPlanServiceImpl extends ServiceImpl<AdPlanMapper, AdPlan> implements IAdPlanService {
|
||||
|
||||
private final IPqScriptService pqScriptService;
|
||||
private final IPqErrSysService pqErrSysService;
|
||||
private final IAdPlanSourceService adPlanSourceService;
|
||||
private final IPqDevService pqDevService;
|
||||
private final IDictDataService dictDataService;
|
||||
|
||||
@Override
|
||||
public Page<AdPlanVO> listAdPlan(AdPlanParam.QueryParam queryParam) {
|
||||
Page<AdPlan> page1 = this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), this.getQueryWrapper(queryParam));
|
||||
List<AdPlan> adPlans = page1.getRecords();
|
||||
List<AdPlanVO> adPlanVOList = adPlans.stream().map(adPlan -> {
|
||||
AdPlanVO adPlanVO = new AdPlanVO();
|
||||
BeanUtil.copyProperties(adPlan, adPlanVO);
|
||||
adPlanVO.setDatasourceIds(Arrays.asList(adPlan.getDatasourceId().split(StrUtil.COMMA)));
|
||||
return adPlanVO;
|
||||
}).collect(Collectors.toList());
|
||||
adPlanVOList.forEach(adPlanVO -> {
|
||||
adPlanVO.setScriptName(pqScriptService.getPqScriptById(adPlanVO.getScriptId()).getName());
|
||||
adPlanVO.setErrorSysName(pqErrSysService.getPqErrSysById(adPlanVO.getErrorSysId()).getName());
|
||||
|
||||
List<PqSource> pqSourceList = adPlanSourceService.listPqSourceByPlanId(adPlanVO.getId());
|
||||
adPlanVO.setSourceIds(pqSourceList.stream().map(PqSource::getId).collect(Collectors.toList()));
|
||||
adPlanVO.setSourceName(pqSourceList.stream().map(PqSource::getName).collect(Collectors.toList()));
|
||||
});
|
||||
|
||||
Page<AdPlanVO> page2 = new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam));
|
||||
page2.setTotal(page1.getTotal());
|
||||
page2.setOrders(page1.orders());
|
||||
page2.setPages(page1.getPages());
|
||||
page2.setRecords(adPlanVOList);
|
||||
return page2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAdPlan(AdPlanParam param) {
|
||||
AdPlan adPlan = new AdPlan();
|
||||
BeanUtil.copyProperties(param, adPlan);
|
||||
|
||||
String planId = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
adPlan.setId(planId);
|
||||
adPlan.setState(DataStateEnum.ENABLE.getCode());
|
||||
// 默认为顶级检测计划
|
||||
adPlan.setFatherPlanId(DevConst.FATHER_ID);
|
||||
adPlan.setDatasourceId(String.join(StrUtil.COMMA, param.getDatasourceIds()));
|
||||
adPlan.setTestState(CheckStateEnum.UNCHECKED.getValue());
|
||||
adPlan.setReportState(PlanReportStateEnum.REPORT_STATE_NOT_GENERATED.getValue());
|
||||
adPlan.setResult(CheckResultEnum.UNCHECKED.getValue());
|
||||
// todo code 生成
|
||||
// 日期生成 MMdd
|
||||
//String dateStr = DateFormatUtils.format(new Date(), "MMdd");
|
||||
adPlan.setCode(this.count() + 1);
|
||||
|
||||
// 新增检测计划、检测源关联
|
||||
adPlanSourceService.addAdPlanSource(planId, param.getSourceIds());
|
||||
if (ObjectUtil.isNotEmpty(param.getDevIds())) {
|
||||
// 新增时,绑定设备
|
||||
pqDevService.bind(planId, param.getDevIds());
|
||||
|
||||
// 守时检测
|
||||
pqDevService.updatePqDevTimeCheckResult(param.getDevIds(), TimeCheckResultEnum.UNKNOWN);
|
||||
}
|
||||
|
||||
return this.save(adPlan);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateAdPlan(AdPlanParam.UpdateParam param) {
|
||||
AdPlan adPlan = new AdPlan();
|
||||
BeanUtil.copyProperties(param, adPlan);
|
||||
|
||||
adPlan.setDatasourceId(String.join(StrUtil.COMMA, param.getDatasourceIds()));
|
||||
|
||||
// 修改检测计划、检测源关联
|
||||
adPlanSourceService.updateAdPlanSource(param.getId(), param.getSourceIds());
|
||||
if (ObjectUtil.isNotEmpty(param.getDevIds())) {
|
||||
// 修改时,只有未检测过的设备才可以修改绑定设备
|
||||
List<String> notUnCheckedIds = pqDevService.listNotUnchecked().stream().map(PqDev::getId).collect(Collectors.toList());
|
||||
List<String> intersection = new ArrayList<>(notUnCheckedIds);
|
||||
intersection.retainAll(param.getDevIds());
|
||||
if (ObjectUtil.isEmpty(intersection)) {
|
||||
pqDevService.bind(param.getId(), param.getDevIds());
|
||||
} else {
|
||||
throw new BusinessException(DevResponseEnum.HAS_NOT_UNCHECKED_DEVICE);
|
||||
}
|
||||
}
|
||||
|
||||
return this.updateById(adPlan);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAdPlan(List<String> ids) {
|
||||
for (String id : ids) {
|
||||
PqDevParam.QueryParam queryParam = new PqDevParam.QueryParam();
|
||||
queryParam.setPlanId(id);
|
||||
if (ObjectUtils.isNotEmpty(pqDevService.listByPlanId(queryParam))) {
|
||||
throw new BusinessException(DevResponseEnum.PLAN_HAS_DEVICE_BIND);
|
||||
}
|
||||
}
|
||||
// 删除检测计划、检测源关联
|
||||
adPlanSourceService.deleteAdPlanSourceByPlanIds(ids);
|
||||
|
||||
return this.lambdaUpdate().in(AdPlan::getId, ids).set(AdPlan::getState, DataStateEnum.DELETED.getCode()).update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> listByPattern(String pattern) {
|
||||
List<AdPlan> adPlanList = this.lambdaQuery().eq(AdPlan::getPattern, pattern).eq(AdPlan::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
Map<Integer, List<AdPlan>> map1 = adPlanList.stream().collect(Collectors.groupingBy(AdPlan::getTestState));
|
||||
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
|
||||
for (CheckStateEnum checkStateEnum : CheckStateEnum.values()) {
|
||||
// 检测计划的检测状态中没有 归档 状态
|
||||
if (checkStateEnum.getValue() == CheckStateEnum.DOCUMENTED.getValue()) {
|
||||
continue;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("name", checkStateEnum.getMsg());
|
||||
List<Map<String, Object>> children = new ArrayList<>();
|
||||
if (map1.containsKey(checkStateEnum.getValue())) {
|
||||
map1.get(checkStateEnum.getValue()).forEach(adPlan -> {
|
||||
Map<String, Object> child = new HashMap<>();
|
||||
child.put("id", adPlan.getId());
|
||||
child.put("pid", adPlan.getFatherPlanId());
|
||||
child.put("name", adPlan.getName());
|
||||
children.add(child);
|
||||
});
|
||||
}
|
||||
map.put("children", children);
|
||||
result.add(map);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public List<Map<String, Object>> getAdPlanEexportSheetList(AdPlanParam.QueryParam queryParam) {
|
||||
// List<AdPlan> adPlans = this.list(this.getQueryWrapper(queryParam));
|
||||
//
|
||||
// List<AdPlanExcel> adPlanExcelList = this.getAdPlanExcelList(adPlans);
|
||||
// Map<String, Object> sheetMap1 = new HashMap<>();
|
||||
// ExportParams exportParams = new ExportParams();
|
||||
// exportParams.setSheetName("检测计划");
|
||||
// sheetMap1.put("title", exportParams);
|
||||
// sheetMap1.put("entity", AdPlanExcel.class);
|
||||
// sheetMap1.put("data", adPlanExcelList);
|
||||
//
|
||||
// List<Map<String, Object>> sheetList = new ArrayList<>();
|
||||
// sheetList.add(sheetMap1);
|
||||
// DictData dictData = dictDataService.getDictDataById(queryParam.getPattern());
|
||||
// if (ObjectUtil.isNotNull(dictData)) {
|
||||
// if (PatternEnum.CONTRAST.getValue().equals(dictData.getCode())) {
|
||||
// sheetList.add(pqDevService.getExportSheetMap(adPlans.stream().map(AdPlan::getId).collect(Collectors.toList()), PqDevExcel.ContrastExportData.class));
|
||||
// } else {
|
||||
// sheetList.add(pqDevService.getExportSheetMap(adPlans.stream().map(AdPlan::getId).collect(Collectors.toList()), PqDevExcel.SimulateOrDigitalExportData.class));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return sheetList;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public List<AdPlanExcel> getExportData(AdPlanParam.QueryParam queryParam) {
|
||||
List<AdPlan> planList = this.list(this.getQueryWrapper(queryParam));
|
||||
this.visualize(planList);
|
||||
List<AdPlanExcel> planExcelList = BeanUtil.copyToList(planList, AdPlanExcel.class);
|
||||
return planExcelList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void importData(List<AdPlanExcel> adPlanExcelList) {
|
||||
List<AdPlan> adPlans = BeanUtil.copyToList(adPlanExcelList, AdPlan.class);
|
||||
// 逆向可视化
|
||||
this.reverseVisualize(adPlans);
|
||||
this.saveBatch(adPlans);
|
||||
//todo 脚本、误差体系处理
|
||||
}
|
||||
|
||||
/**
|
||||
* 可视化
|
||||
*
|
||||
* @param adPlans 检测计划列表
|
||||
*/
|
||||
private void visualize(List<AdPlan> adPlans) {
|
||||
adPlans.forEach(adPlan -> {
|
||||
if (StrUtil.isNotBlank(adPlan.getPattern())) {
|
||||
adPlan.setPattern(dictDataService.getDictDataById(adPlan.getPattern()).getName());
|
||||
}
|
||||
if (DevConst.FATHER_ID.equals(adPlan.getFatherPlanId())) {
|
||||
adPlan.setFatherPlanId("");
|
||||
} else {
|
||||
adPlan.setFatherPlanId(this.getById(adPlan.getFatherPlanId()).getName());
|
||||
}
|
||||
if (StrUtil.isNotBlank(adPlan.getDatasourceId())) {
|
||||
String[] datasourceIds = adPlan.getDatasourceId().split(StrUtil.COMMA);
|
||||
adPlan.setDatasourceId(Arrays.stream(datasourceIds).map(id -> DataSourceEnum.getMsgByValue(id)).collect(Collectors.joining(StrUtil.COMMA)));
|
||||
}
|
||||
if (StrUtil.isNotBlank(adPlan.getScriptId())) {
|
||||
String[] scriptIds = adPlan.getScriptId().split(StrUtil.COMMA);
|
||||
adPlan.setScriptId(Arrays.stream(scriptIds).map(id -> pqScriptService.getPqScriptById(id).getName()).collect(Collectors.joining(StrUtil.COMMA)));
|
||||
}
|
||||
if (StrUtil.isNotBlank(adPlan.getErrorSysId())) {
|
||||
adPlan.setErrorSysId(pqErrSysService.getPqErrSysById(adPlan.getErrorSysId()).getName());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 逆向可视化
|
||||
*
|
||||
* @param adPlans 检测计划列表
|
||||
*/
|
||||
private void reverseVisualize(List<AdPlan> adPlans) {
|
||||
adPlans.forEach(adPlan -> {
|
||||
if (StrUtil.isNotBlank(adPlan.getPattern())) {
|
||||
adPlan.setPattern(dictDataService.getDictDataByName(adPlan.getPattern()).getId());
|
||||
}
|
||||
// if (DevConst.FATHER_ID.equals(adPlan.getFatherPlanId())) {
|
||||
// adPlan.setFatherPlanId("");
|
||||
// } else {
|
||||
// adPlan.setFatherPlanId(this.getById(adPlan.getFatherPlanId()).getId());
|
||||
// }
|
||||
if (StrUtil.isNotBlank(adPlan.getDatasourceId())) {
|
||||
String[] datasourceIds = adPlan.getDatasourceId().split(StrUtil.COMMA);
|
||||
adPlan.setDatasourceId(Arrays.stream(datasourceIds).map(id -> DataSourceEnum.getValueByMsg(id)).collect(Collectors.joining(StrUtil.COMMA)));
|
||||
}
|
||||
// if (StrUtil.isNotBlank(adPlan.getScriptId())) {
|
||||
// adPlan.setScriptId(pqScriptService.getPqScriptById(adPlan.getScriptId()).getName());
|
||||
// }
|
||||
// if (StrUtil.isNotBlank(adPlan.getErrorSysId())) {
|
||||
// adPlan.setErrorSysId(pqErrSysService.getPqErrSysById(adPlan.getErrorSysId()).getName());
|
||||
// }
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取查询条件wrapper
|
||||
*
|
||||
* @param queryParam 查询条件
|
||||
* @return
|
||||
*/
|
||||
private Wrapper getQueryWrapper(AdPlanParam.QueryParam queryParam) {
|
||||
QueryWrapper<AdPlan> queryWrapper = new QueryWrapper<>();
|
||||
if (ObjectUtil.isNotNull(queryParam)) {
|
||||
queryWrapper.eq(StrUtil.isNotBlank(queryParam.getPattern()), "ad_plan.pattern", queryParam.getPattern()).eq(StrUtil.isNotBlank(queryParam.getName()), "ad_plan.name", queryParam.getName()).eq(ObjectUtil.isNotNull(queryParam.getTestState()), "ad_plan.Test_State", queryParam.getTestState()).eq(ObjectUtil.isNotNull(queryParam.getReportState()), "ad_plan.Report_State", queryParam.getReportState()).eq(ObjectUtil.isNotNull(queryParam.getResult()), "ad_plan.result", queryParam.getResult());
|
||||
}
|
||||
queryWrapper.eq("ad_plan.state", DataStateEnum.ENABLE.getCode()).orderBy(true, true, "Create_Time");
|
||||
return queryWrapper;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.njcn.gather.plan.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.gather.plan.mapper.AdPlanSourceMapper;
|
||||
import com.njcn.gather.plan.pojo.po.AdPlanSource;
|
||||
import com.njcn.gather.plan.service.IAdPlanSourceService;
|
||||
import com.njcn.gather.device.source.pojo.po.PqSource;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @date 2024-12-09
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AdPlanSourceServiceImpl extends ServiceImpl<AdPlanSourceMapper, AdPlanSource> implements IAdPlanSourceService {
|
||||
|
||||
private final AdPlanSourceMapper adPlanSourceMapper;
|
||||
|
||||
@Override
|
||||
public List<PqSource> listPqSourceByPlanId(String planId) {
|
||||
return adPlanSourceMapper.selectPqSourceByPlanId(planId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAdPlanSource(String planId, List<String> sourceIds) {
|
||||
List<AdPlanSource> adPlanSourceList = new ArrayList<>();
|
||||
for (String sourceId : sourceIds) {
|
||||
adPlanSourceList.add(new AdPlanSource(planId, sourceId));
|
||||
}
|
||||
return this.saveBatch(adPlanSourceList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteAdPlanSourceByPlanIds(List<String> planIds) {
|
||||
QueryWrapper<AdPlanSource> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.in("ad_plan_source.Plan_Id", planIds);
|
||||
return this.remove(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateAdPlanSource(String planId, List<String> sourceIds) {
|
||||
this.deleteAdPlanSourceByPlanIds(Collections.singletonList(planId));
|
||||
this.addAdPlanSource(planId, sourceIds);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user