方案数据除统计接口第一阶段提交

This commit is contained in:
guofeihu
2024-06-13 20:30:18 +08:00
parent 74ebff1592
commit bee3171860
11 changed files with 517 additions and 385 deletions

View File

@@ -0,0 +1,31 @@
package com.njcn.csdevice.param;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@NoArgsConstructor
public class WlRecordPageParam extends BaseParam {
/**
* 测试项ID
*/
@ApiModelProperty(value="测试项ID")
private String id;
/**
* 测试项ID
*/
@ApiModelProperty(value="是否匹配测试项ID")
private Integer isTrueFlag;
/**
* 关键字多个匹配
*/
@ApiModelProperty(value="关键字多个匹配")
private String searchText;
}

View File

@@ -3,9 +3,6 @@ package com.njcn.csdevice.pojo.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;
/**
@@ -18,8 +15,7 @@ import java.util.List;
@Data
public class WlRecordParam {
@ApiModelProperty("方案、测试项名称")
@NotBlank(message = "名称不可为空")
@ApiModelProperty("方案名称")
private String itemName;
@ApiModelProperty("描述")
@@ -29,72 +25,55 @@ public class WlRecordParam {
@EqualsAndHashCode(callSuper = true)
public static class Record extends WlRecordParam {
@ApiModelProperty("工程名称")
private String gcName;
@ApiModelProperty("测试项名称")
private String itemName;
@ApiModelProperty("测试项监测位置")
private String location;
@ApiModelProperty("统计间隔")
@NotNull(message = "统计间隔不可为空")
private Integer statisticalInterval;
@ApiModelProperty("电压等级")
@NotNull(message = "电压等级不可为空")
private String voltageLevel;
@ApiModelProperty("电压接线方式(星型、角型、V型)")
@NotNull(message = "电压接线方式不可为空")
private String volConType;
@ApiModelProperty("电流接线方式(正常、合成IB、合成IC)")
@NotNull(message = "电流接线方式不可为空")
private String curConSel;
@ApiModelProperty("基准短路容量MVA")
@NotNull(message = "基准短路容量不可为空")
private Float capacitySscb;
@ApiModelProperty("最小短路容量MVA")
@NotNull(message = "最小短路容量不可为空")
private Float capacitySscmin;
@ApiModelProperty("供电设备容量MVA")
@NotNull(message = "供电设备容量不可为空")
private Float capacitySt;
@ApiModelProperty("用户协议容量MVA")
@NotNull(message = "用户协议容量不可为空")
private Float capacitySi;
@ApiModelProperty("PT变比")
@NotNull(message = "PT变比不可为空")
private Integer pt;
@ApiModelProperty("CT变比")
@NotNull(message = "CT变比不可为空")
private Integer ct;
@ApiModelProperty("测试项监测位置")
@NotNull(message = "测试项监测位置不可为空")
private String location;
@ApiModelProperty("电压等级")
private String voltageLevel;
@ApiModelProperty("数据类型(0方案 1测试项)")
@NotNull(message = "数据类型不可为空")
private Integer type;
@ApiModelProperty("基准短路容量MVA")
private Float capacitySscb;
@ApiModelProperty("状态0删除 1正常")
@NotNull(message = "状态不可为空")
private Integer state;
@ApiModelProperty("最小短路容量MVA")
private Float capacitySscmin;
@ApiModelProperty("测试项集合ID")
@ApiModelProperty("供电设备容量MVA")
private Float capacitySt;
@ApiModelProperty("用户协议容量MVA")
private Float capacitySi;
@ApiModelProperty("电压接线方式(星型、角型、V型)")
private String volConType;
@ApiModelProperty("基础数据集合ID")
private List<String> list;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class UpdateRecord extends Record {
@ApiModelProperty("id")
@NotNull(message = "id")
private String id;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static class AddRecord extends WlRecordParam {
@ApiModelProperty("records")
private List<Record> records;
}
}

View File

@@ -1,5 +1,6 @@
package com.njcn.csdevice.pojo.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.njcn.db.bo.BaseEntity;
import lombok.Getter;
@@ -118,7 +119,8 @@ public class WlRecord extends BaseEntity {
private String location;
/**
* 数据类型(0方案 1测试项)
* 数据类型(0方案 1测试项)
* 0 测试项 1基础数据
*/
private Integer type;
@@ -130,27 +132,7 @@ public class WlRecord extends BaseEntity {
/**
* 描述
*/
@TableField(value = "`describe`")
private String describe;
/**
* 创建用户
*/
private String createBy;
/**
* 创建时间
*/
private LocalDateTime createTime;
/**
* 更新用户
*/
private String updateBy;
/**
* 更新时间
*/
private LocalDateTime updateTime;
}

View File

@@ -0,0 +1,41 @@
package com.njcn.csdevice.pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 类的介绍: 测试项详情表
*
* @author xuyang
* @version 1.0.0
* @createTime 2024/4/1 20:10
*/
@Data
public class RecordPageVo {
@ApiModelProperty("基础数据id")
private String id;
@ApiModelProperty("设备名称")
private String devName;
@ApiModelProperty("设备MAC")
private String devMac;
@ApiModelProperty("网络设备ID")
private String devNdId;
@ApiModelProperty("监测点名称(线路号)")
private String lineName;
@ApiModelProperty("数据起始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
@ApiModelProperty("数据结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;
}

View File

@@ -3,8 +3,6 @@ package com.njcn.csdevice.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -18,35 +16,23 @@ import java.util.List;
public class RecordTreeVo {
@ApiModelProperty("方案id")
private String schemeId;
private String id;
@ApiModelProperty("方案名称")
private String name;
@ApiModelProperty("下层数据")
@ApiModelProperty("测试项数据")
private List<Children> children;
@Data
@EqualsAndHashCode(callSuper = true)
public static class Children extends RecordTreeVo {
@ApiModelProperty("id")
private String id;
@ApiModelProperty("名称")
private String recordName;
@ApiModelProperty("设备MAC")
private String devMac;
@ApiModelProperty("监测点名称")
private String lineName;
@ApiModelProperty("测试项开始时间")
private LocalDateTime startTime;
private String startTime;
@ApiModelProperty("测试项结束时间")
private LocalDateTime endTime;
private String endTime;
}
}

View File

@@ -1,8 +1,8 @@
package com.njcn.csdevice.pojo.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
@@ -19,29 +19,19 @@ public class RecordVo {
private String id;
@ApiModelProperty("测试项名称")
private String recordName;
@ApiModelProperty("设备名称")
private String devName;
@ApiModelProperty("设备MAC")
private String devMac;
@ApiModelProperty("监测点名称")
private String lineName;
private String itemName;
@ApiModelProperty("数据起始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
@ApiModelProperty("数据结束时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;
@ApiModelProperty("测试位置")
private String location;
@ApiModelProperty("数据类型")
private Integer type;
@ApiModelProperty("统计间隔")
private Integer statisticalInterval;
@@ -51,7 +41,7 @@ public class RecordVo {
@ApiModelProperty("CT变比")
private Integer ct;
@ApiModelProperty("CT变比")
@ApiModelProperty("电压等级")
private String voltageLevel;
@ApiModelProperty("基准短路容量")
@@ -69,6 +59,4 @@ public class RecordVo {
@ApiModelProperty("电压接线方式")
private String volConType;
@ApiModelProperty("电流接线方式")
private String curConSel;
}

View File

@@ -1,6 +1,6 @@
package com.njcn.csdevice.controller.scheme;
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;
@@ -8,8 +8,10 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.csdevice.param.WlRecordPageParam;
import com.njcn.csdevice.pojo.param.WlRecordParam;
import com.njcn.csdevice.pojo.po.WlRecord;
import com.njcn.csdevice.pojo.vo.RecordPageVo;
import com.njcn.csdevice.pojo.vo.RecordTreeVo;
import com.njcn.csdevice.pojo.vo.RecordVo;
import com.njcn.csdevice.service.IWlRecordService;
@@ -21,8 +23,8 @@ import lombok.AllArgsConstructor;
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;
/**
* <p>
@@ -43,128 +45,135 @@ public class WlRecordController extends BaseController {
private final IWlRecordService wlRecordService;
/**
* 新增方案测试项
* 两层树方案+测试项*
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
@PostMapping("/add")
@ApiOperation("新增方案测试项")
@ApiImplicitParam(name = "list", value = "测试项集合", required = true)
public HttpResult<Boolean> add(@RequestBody @Validated List<WlRecordParam.Record> list) {
String methodDescribe = getMethodDescribe("add");
try {
LogUtil.njcnDebug(log, "{},新增的测试项集合为:{}", methodDescribe, list);
wlRecordService.add(list);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} catch (Exception e) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
/**
* 修改方案
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
@PostMapping("/update")
@ApiOperation("修改方案")
@ApiImplicitParam(name = "list", value = "测试项集合", required = true)
public HttpResult<Boolean> update(@RequestBody @Validated List<WlRecordParam.UpdateRecord> list) {
String methodDescribe = getMethodDescribe("update");
try {
LogUtil.njcnDebug(log, "{},修改的测试项集合为:{}", methodDescribe, list);
wlRecordService.update(list);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} catch (Exception e) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
/**
* 根据方案查询测试项信息
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
@PostMapping("/getRecordById")
@ApiOperation("通过方案id查询所属测试项")
@ApiImplicitParam(name = "id", value = "用户id", required = true)
public HttpResult<List<RecordVo>> getRecordById(@RequestParam @Validated String id) {
String methodDescribe = getMethodDescribe("getRecordById");
try {
LogUtil.njcnDebug(log, "{}测试项id为{}", methodDescribe, id);
List<RecordVo> result = wlRecordService.getRecordById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
} catch (Exception e) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
/**
* 查询所有测试项信息
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
@PostMapping("/listRecord")
@ApiOperation("查询所有测试项信息")
public HttpResult<List<RecordTreeVo>> listRecord() {
String methodDescribe = getMethodDescribe("listRecord");
try {
LogUtil.njcnDebug(log, "{}", methodDescribe);
List<RecordTreeVo> result = wlRecordService.getRecordTree();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
} catch (Exception e) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
/**
* 两层方案树
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
@PostMapping("/schemeTree")
@ApiOperation("两层方案树")
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
@GetMapping("/schemeTree")
@ApiOperation("两层树方案+测试项")
public HttpResult<List<RecordTreeVo>> getSchemeTree() {
String methodDescribe = getMethodDescribe("getSchemeTree");
try {
LogUtil.njcnDebug(log, "{}", methodDescribe);
List<RecordTreeVo> result = wlRecordService.getSchemeTree();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
} catch (Exception e) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
}
/**
* 删除方案
* @param id 方案、测试项id
* 根据测试项ID查询测试项信息*
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
@DeleteMapping("/delete")
@ApiOperation("删除方案")
@ApiImplicitParam(name = "id", value = "方案id", required = true)
public HttpResult<Boolean> delete(@RequestParam @Validated String id) {
String methodDescribe = getMethodDescribe("delete");
try {
LogUtil.njcnDebug(log, "{}方案id为{}", methodDescribe, id);
wlRecordService.delete(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} catch (Exception e) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
}
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
@GetMapping("/getTestRecordById")
@ApiOperation("根据测试项ID查询测试项信息")
@ApiImplicitParam(name = "testRecordId", value = "测试项ID", required = true)
public HttpResult<RecordVo> getTestRecordById(@RequestParam @Validated String testRecordId) {
String methodDescribe = getMethodDescribe("getTestRecordById");
LogUtil.njcnDebug(log, "{}测试项id为{}", methodDescribe, testRecordId);
RecordVo result = wlRecordService.getTestRecordById(testRecordId);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
/**
* 根据测试项id查询测试项详细信息
* 新增方案或新增测试项*
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
@PostMapping("/addRecord")
@ApiOperation("新增方案或新增测试项")
@ApiImplicitParam(name = "records", value = "测试项集合", required = true)
public HttpResult<Boolean> addRecord(@RequestBody @Validated WlRecordParam.AddRecord records) {
String methodDescribe = getMethodDescribe("addRecord");
LogUtil.njcnDebug(log, "{},新增的测试项集合为:{}", methodDescribe, records);
wlRecordService.addRecord(records);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 修改测试项*
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
@PostMapping("/updateTestRecord")
@ApiOperation("修改测试项")
@ApiImplicitParam(name = "record", value = "测试项对象", required = true)
public HttpResult<Boolean> updateTestRecord(@RequestBody @Validated WlRecordParam.UpdateRecord record) {
String methodDescribe = getMethodDescribe("updateTestRecord");
LogUtil.njcnDebug(log, "{},修改的测试项对象为:{}", methodDescribe, record);
wlRecordService.updateTestRecord(record);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 查询测试项下绑定的设备列表*
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
@PostMapping("/queryPage")
@ApiOperation("查询测试项下绑定的设备列表")
public HttpResult<Page<RecordPageVo>> queryPage(@Validated @RequestBody WlRecordPageParam wlRecordPageParam) {
String methodDescribe = getMethodDescribe("queryPage");
LogUtil.njcnDebug(log, "{}", methodDescribe);
Page<RecordPageVo> result = wlRecordService.queryPage(wlRecordPageParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
/**
* 删除测试项或方案
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
@DeleteMapping("/detailById")
@ApiOperation("根据id获取测试项详情")
@ApiImplicitParam(name = "id", value = "测试项id", required = true)
public HttpResult<WlRecord> getDetailById(@RequestParam @Validated String id) {
String methodDescribe = getMethodDescribe("getRecordById");
try {
LogUtil.njcnDebug(log, "{}测试项id为{}", methodDescribe, id);
WlRecord wlRecord = wlRecordService.getDataById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, wlRecord, methodDescribe);
} catch (Exception e) {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
@DeleteMapping("/deleteRecord")
@ApiOperation("删除测试项或方案")
@ApiImplicitParam(name = "id", value = "方案或测试项ID", required = true)
public HttpResult<Boolean> deleteRecord(@RequestParam @Validated String id) {
String methodDescribe = getMethodDescribe("deleteRecord");
LogUtil.njcnDebug(log, "{}方案或测试项ID为{}", methodDescribe, id);
wlRecordService.deleteRecord(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 修改方案名称
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
@PostMapping("/updateSchemeRecordName")
@ApiOperation("修改方案名称")
public HttpResult<List<Map>> updateSchemeRecordName(@RequestBody @Validated WlRecordParam.UpdateRecord record) {
String methodDescribe = getMethodDescribe("updateSchemeRecordName");
wlRecordService.updateSchemeRecordName(record);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 删除测试项中的设备基础数据*
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
@DeleteMapping("/deleteDataRecord")
@ApiOperation("删除测试项中的设备基础数据")
public HttpResult<WlRecord> deleteDataRecord(@RequestBody @Validated WlRecordParam.UpdateRecord record) {
String methodDescribe = getMethodDescribe("deleteDataRecord");
LogUtil.njcnDebug(log, "{}测试项及基础数据ID为{}", methodDescribe, record);
wlRecordService.deleteDataRecord(record);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 添加测试项中的设备基础数据*
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
@PostMapping("/saveDataRecord")
@ApiOperation("添加测试项中的设备基础数据")
public HttpResult<WlRecord> saveDataRecord(@RequestBody @Validated WlRecordParam.UpdateRecord record) {
String methodDescribe = getMethodDescribe("saveDataRecord");
LogUtil.njcnDebug(log, "{}测试项及基础数据ID为{}", methodDescribe, record);
wlRecordService.saveDataRecord(record);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
/**
* 方案下拉框*
*/
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.QUERY)
@GetMapping("/schemeRecordDown")
@ApiOperation("方案下拉框")
public HttpResult<List<Map>> schemeRecordDown() {
String methodDescribe = getMethodDescribe("schemeRecordDown");
List<Map> result = wlRecordService.schemeRecordDown();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -1,11 +1,13 @@
package com.njcn.csdevice.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.csdevice.param.WlRecordPageParam;
import com.njcn.csdevice.pojo.po.WlRecord;
import com.njcn.csdevice.pojo.vo.RecordVo;
import com.njcn.csdevice.pojo.vo.RecordPageVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* <p>
@@ -18,23 +20,28 @@ import java.util.List;
public interface WlRecordMapper extends BaseMapper<WlRecord> {
/**
* 根据方案id查询所属的测试项
* @param id
* @return
* 查询测试项下绑定的设备列表
*/
List<RecordVo> listRecord(@Param("id") String id);
Page<RecordPageVo> queryPage(Page<RecordPageVo> returnpage,@Param("wlRecordPageParam") WlRecordPageParam wlRecordPageParam);
/**
* 查询所有的测试项
* @return
* 添加测试项中的设备基础数据
*/
List<RecordVo> getAllRecord();
void saveDataRecord(@Param("testRecordId") String testRecordId,@Param("dataRecordId") String dataRecordId);
/**
* 查询所有的方案和测试项
* @return
* 删除测试项中的设备基础数据
*/
List<RecordVo> getAll();
void deleteDataRecord(@Param("testRecordId") String testRecordId,@Param("dataRecordId") String dataRecordId);
/**
* 根据测试项ID获取设备基础数据集合
*/
List<String> getDataRecordBytestId(@Param("testRecordId") String testRecordId);
/**
* 方案下拉框
*/
List<Map> schemeRecordDown();
}

View File

@@ -2,56 +2,52 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.csdevice.mapper.WlRecordMapper">
<select id="listRecord" resultType="com.njcn.csdevice.pojo.vo.RecordVo">
<select id="queryPage" resultType="com.njcn.csdevice.pojo.vo.RecordPageVo">
select
a.id,
a.item_name recordName,
b.name devName,
b.mac devMac,
b.ndid devNdId,
c.name lineName,
a.start_time startTime,
a.end_time endTime,
a.location
from
wl_record a
left join cs_equipment_delivery b on a.dev_id = b.id
left join cs_line c on a.line_id = c.line_id
where a.p_id = #{id} and a.state = 1
</select>
<select id="getAllRecord" resultType="com.njcn.csdevice.pojo.vo.RecordVo">
select
a.id,
a.item_name recordName,
b.name devName,
b.mac devMac,
c.name lineName,
a.start_time startTime,
a.end_time endTime,
a.location
a.end_time endTime
from
wl_record a
left join cs_equipment_delivery b on a.dev_id = b.id
left join cs_line c on a.line_id = c.line_id
where a.`type` = 1 and a.state = 1
<if test="wlRecordPageParam.id != null and wlRecordPageParam.isTrueFlag == 1">
and exists (select 1 from wl_record_test_data wd where wd.test_item_id = #{wlRecordPageParam.id} and a.id = wd.data_id)
</if>
<if test="wlRecordPageParam.id != null and wlRecordPageParam.isTrueFlag == 0">
and not exists (select 1 from wl_record_test_data wd where wd.test_item_id = #{wlRecordPageParam.id} and a.id = wd.data_id)
</if>
<if test="wlRecordPageParam.searchText != null and wlRecordPageParam.searchText != ''">
and (b.name like concat('%',#{wlRecordPageParam.searchText},'%')
or b.mac like concat('%',#{wlRecordPageParam.searchText},'%')
or b.ndid like concat('%',#{wlRecordPageParam.searchText},'%'))
</if>
order by a.start_time desc
</select>
<select id="getAll" resultType="com.njcn.csdevice.pojo.vo.RecordVo">
select
a.id,
a.item_name recordName,
b.name devName,
b.mac devMac,
c.name lineName,
a.start_time startTime,
a.end_time endTime,
a.location,
a.type
from
wl_record a
left join cs_equipment_delivery b on a.dev_id = b.id
left join cs_line c on a.line_id = c.line_id
where a.state = 1
<insert id="saveDataRecord">
insert into wl_record_test_data
select #{testRecordId},#{dataRecordId} from dual
where not exists (select 1 from wl_record_test_data wr where wr.test_item_id = #{testRecordId} and wr.data_id = #{dataRecordId})
</insert>
<delete id="deleteDataRecord">
delete from wl_record_test_data where test_item_id = #{testRecordId}
<if test="dataRecordId!=null and dataRecordId!= ''">
and data_id = #{dataRecordId}
</if>
</delete>
<select id="getDataRecordBytestId" resultType="string">
select data_id from wl_record_test_data where test_item_id = #{testRecordId};
</select>
<select id="schemeRecordDown" resultType="map">
select item_name name,item_name value from wl_record where type = 0 and state = 1 and p_id is null order by create_time
</select>
</mapper>

View File

@@ -1,13 +1,15 @@
package com.njcn.csdevice.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csdevice.param.WlRecordPageParam;
import com.njcn.csdevice.pojo.param.WlRecordParam;
import com.njcn.csdevice.pojo.po.WlRecord;
import com.njcn.csdevice.pojo.vo.RecordPageVo;
import com.njcn.csdevice.pojo.vo.RecordTreeVo;
import com.njcn.csdevice.pojo.vo.RecordVo;
import java.util.List;
import java.util.Map;
/**
* <p>
@@ -20,51 +22,72 @@ import java.util.List;
public interface IWlRecordService extends IService<WlRecord> {
/**
* 批量新增方案测试项
* @param list
* @return
*/
void add(List<WlRecordParam.Record> list);
/**
* 批量修改方案信息
* @param list
* @return
*/
void update(List<WlRecordParam.UpdateRecord> list);
/**
* 根据方案查询测试项信息
* @param id
* @return
*/
List<RecordVo> getRecordById(String id);
/**
* 查询所有测试项信息,用于方案添加测试项
* @param
* @return
*/
List<RecordTreeVo> getRecordTree();
/**
* 获取方案树
* 两层树方案+测试项
* @param
* @return
*/
List<RecordTreeVo> getSchemeTree();
/**
* 删除方案
* 根据测试项ID查询测试项信息
* @param testRecordId
* @return
*/
RecordVo getTestRecordById(String testRecordId);
/**
* 新增方案或新增测试项
* @param records
* @return
*/
void addRecord(WlRecordParam.AddRecord records);
/**
* 修改测试项
* @param record
* @return
*/
void updateTestRecord(WlRecordParam.UpdateRecord record);
/**
* 查询测试项下绑定的设备列表
* @param
* @return
*/
void delete(String id);
Page<RecordPageVo> queryPage(WlRecordPageParam wlRecordPageParam);
/**
* 根据测试项id查询测试项详情
* 删除测试项或方案
* @param
* @return
*/
WlRecord getDataById(String id);
void deleteRecord(String id);
/**
* 修改方案名称
* @param
* @return
*/
void updateSchemeRecordName(WlRecordParam.UpdateRecord record);
/**
* 删除测试项中的设备基础数据
* @return
*/
void deleteDataRecord(WlRecordParam.UpdateRecord record);
/**
* 添加测试项中的设备基础数据
* @return
*/
void saveDataRecord(WlRecordParam.UpdateRecord record);
/**
* 方案下拉框
* @return
*/
List<Map> schemeRecordDown();
}

View File

@@ -1,22 +1,29 @@
package com.njcn.csdevice.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.mapper.WlRecordMapper;
import com.njcn.csdevice.param.WlRecordPageParam;
import com.njcn.csdevice.pojo.param.WlRecordParam;
import com.njcn.csdevice.pojo.po.WlRecord;
import com.njcn.csdevice.pojo.vo.RecordPageVo;
import com.njcn.csdevice.pojo.vo.RecordTreeVo;
import com.njcn.csdevice.pojo.vo.RecordVo;
import com.njcn.csdevice.service.IWlRecordService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -32,123 +39,206 @@ public class WlRecordServiceImpl extends ServiceImpl<WlRecordMapper, WlRecord> i
@Override
@Transactional(rollbackFor = Exception.class)
public void add(List<WlRecordParam.Record> list) {
public void addRecord(WlRecordParam.AddRecord records) {
//整理的方案下测试项集合(可能添加多个测试项)
List<WlRecord> insertList = new ArrayList<>();
list.forEach(item->{
String id = IdUtil.simpleUUID();
//整理单独的方案
WlRecord wlRecord = new WlRecord();
BeanUtils.copyProperties(item, wlRecord);
wlRecord.setId(id);
insertList.add(wlRecord);
if (CollUtil.isNotEmpty(item.getList())){
LambdaUpdateWrapper<WlRecord> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.set(WlRecord::getPId, id)
.in(WlRecord::getId,item.getList());
this.update(lambdaUpdateWrapper);
QueryWrapper<WlRecord> qw = new QueryWrapper();
qw.eq("item_name",records.getItemName()).eq("type",0).eq("state",1);
List<WlRecord> wlRecordList = this.baseMapper.selectList(qw);
//如果当前新增的方案名称已存在的话则测试项直接绑定已存在的方案
if(!wlRecordList.isEmpty()){
wlRecord.setId(wlRecordList.get(0).getId());
}else{
//否则新增方案
BeanUtils.copyProperties(records, wlRecord);
wlRecord.setId(IdUtil.simpleUUID());
wlRecord.setType(0);
wlRecord.setState(1);
this.save(wlRecord);
}
//便利测试项
records.getRecords().forEach(item->{
String id = IdUtil.simpleUUID();
WlRecord record = new WlRecord();
BeanUtils.copyProperties(item, record);
record.setId(id);
//当前测试项绑定当前方案
record.setPId(wlRecord.getId());
record.setType(0);
record.setState(1);
insertList.add(record);
//绑定测试项的基础数据
WlRecordParam.UpdateRecord updateRecord = new WlRecordParam.UpdateRecord();
updateRecord.setId(record.getId());
updateRecord.setList(item.getList());
saveDataRecord(updateRecord);
});
this.saveBatch(insertList);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(List<WlRecordParam.UpdateRecord> list) {
public void updateTestRecord(WlRecordParam.UpdateRecord record) {
List<WlRecord> updateList = new ArrayList<>();
list.forEach(item->{
WlRecord wlRecord = new WlRecord();
BeanUtils.copyProperties(item, wlRecord);
updateList.add(wlRecord);
if (CollUtil.isNotEmpty(item.getList())){
//先将方案绑定的测试项去除,然后再根据传递的数据绑定
LambdaUpdateWrapper<WlRecord> lambdaUpdateWrapper1 = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper1.set(WlRecord::getPId, null)
.in(WlRecord::getId,item.getList());
this.update(lambdaUpdateWrapper1);
LambdaUpdateWrapper<WlRecord> lambdaUpdateWrapper2 = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper2.set(WlRecord::getPId, item.getId())
.in(WlRecord::getId,item.getList());
this.update(lambdaUpdateWrapper2);
}
});
this.updateBatchById(updateList);
BeanUtils.copyProperties(record, wlRecord);
this.updateById(wlRecord);
}
@Override
public List<RecordVo> getRecordById(String id) {
return this.baseMapper.listRecord(id);
public RecordVo getTestRecordById(String testRecordId) {
RecordVo recordVo = new RecordVo();
QueryWrapper<WlRecord> qw = new QueryWrapper();
qw.eq("id",testRecordId).eq("type",0).eq("state",1);
List<WlRecord> list = this.baseMapper.selectList(qw);
if(list.isEmpty()){
throw new BusinessException("测试项ID有误");
}
WlRecord wlRecord = list.get(0);
wlRecord.setStartTime(getFirstTimeById(wlRecord.getId()));
wlRecord.setEndTime(getLastTimeById(wlRecord.getId()));
BeanUtils.copyProperties(wlRecord, recordVo);
return recordVo;
}
@Override
public List<RecordTreeVo> getRecordTree() {
List<RecordTreeVo> result = new ArrayList<>();
Optional.ofNullable(this.baseMapper.getAllRecord())
.ifPresent(list -> list.stream()
.collect(Collectors.groupingBy(RecordVo::getDevName))
.forEach((devName, records) -> {
List<RecordTreeVo.Children> childrenList = records.stream()
.map(this::mapToChildren)
.collect(Collectors.toList());
RecordTreeVo vo = new RecordTreeVo();
vo.setName(devName);
vo.setChildren(childrenList);
result.add(vo);
}));
return result;
public Page<RecordPageVo> queryPage(WlRecordPageParam wlRecordPageParam) {
Page<RecordPageVo> returnpage = new Page<> (wlRecordPageParam.getPageNum(), wlRecordPageParam.getPageSize ( ));
returnpage = this.getBaseMapper().queryPage(returnpage,wlRecordPageParam);
return returnpage;
}
@Override
public List<RecordTreeVo> getSchemeTree() {
List<RecordTreeVo> result = new ArrayList<>();
List<RecordVo> list = this.baseMapper.getAll();
// 过滤出方案数据和测试项数据
List<RecordVo> schemes = list.stream().filter(item -> item.getType() == 0).collect(Collectors.toList());
List<RecordVo> testItems = list.stream().filter(item -> item.getType() == 1).collect(Collectors.toList());
QueryWrapper<WlRecord> qw = new QueryWrapper();
qw.eq("state","1").eq("type","0");
List<WlRecord> list = this.baseMapper.selectList(qw);
// 过滤出方案数据和测试项数据(组装成tree)
List<WlRecord> schemes = list.stream().filter(item -> item.getPId() == null).collect(Collectors.toList());
List<WlRecord> testItems = list.stream().filter(item -> item.getPId() != null).collect(Collectors.toList());
if (CollUtil.isNotEmpty(schemes)){
// 遍历方案数据
for (RecordVo scheme : schemes) {
for (WlRecord scheme : schemes) {
RecordTreeVo vo = new RecordTreeVo();
vo.setSchemeId(scheme.getId());
vo.setName(scheme.getRecordName());
if (CollUtil.isNotEmpty(testItems)){
// 将测试项数据映射为子节点列表
List<RecordTreeVo.Children> childrenList = testItems.stream()
.map(item -> {
vo.setId(scheme.getId());
vo.setName(scheme.getItemName());
List<RecordTreeVo.Children> childrens = new ArrayList<>();
for(WlRecord testItem : testItems.stream().filter(e->e.getPId() .equals( scheme.getId())).collect(Collectors.toList())){
RecordTreeVo.Children children = new RecordTreeVo.Children();
children.setId(item.getId());
String name = item.getDevName() + "-" + item.getLocation() + "(" + item.getStartTime() + "~" + item.getEndTime() + ")";
children.setRecordName(name);
return children;
})
.collect(Collectors.toList());
vo.setChildren(childrenList);
result.add(vo);
children.setId(testItem.getId());
children.setName(testItem.getItemName());
children.setStartTime(LocalDateTimeUtil.format(getFirstTimeById(testItem.getId()), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
children.setEndTime(LocalDateTimeUtil.format(getLastTimeById(testItem.getId()), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
childrens.add(children);
}
vo.setChildren(childrens);
result.add(vo);
}
}
return result;
}
@Override
public void delete(String id) {
@Transactional(rollbackFor = Exception.class)
public void deleteRecord(String id) {
QueryWrapper<WlRecord> qw = new QueryWrapper();
qw.eq("id",id).eq("state","1").eq("type","0");
List<WlRecord> wlRecordList = this.baseMapper.selectList(qw);
if(!wlRecordList.isEmpty()){
LambdaUpdateWrapper<WlRecord> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.set(WlRecord::getState,0)
.eq(WlRecord::getId, id)
.eq(WlRecord::getType, 0);
this.update(lambdaUpdateWrapper);
WlRecord wlRecord = wlRecordList.get(0);
//如果删除的是测试项
if(wlRecord.getPId() != null){
//方案关联的设备基础数据也删除
this.baseMapper.deleteDataRecord(id,null);
}else{
//如果删除的是方案 那么连带方案下的所有测试项也要删除
qw = new QueryWrapper();
qw.eq("p_id",id).eq("state","1").eq("type","0");
for (WlRecord wl : this.baseMapper.selectList(qw)){
LambdaUpdateWrapper<WlRecord> uw = new LambdaUpdateWrapper<>();
uw.set(WlRecord::getState,0)
.eq(WlRecord::getId, wl.getId());
this.update(uw);
//方案关联的设备基础数据也删除
this.baseMapper.deleteDataRecord(wl.getId(),null);
}
}
}
}
@Override
public WlRecord getDataById(String id) {
return lambdaQuery().eq(WlRecord::getId, id)
.eq(WlRecord::getType,1)
.eq(WlRecord::getState, 1)
.one();
public void updateSchemeRecordName(WlRecordParam.UpdateRecord record) {
LambdaUpdateWrapper<WlRecord> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.set(WlRecord::getItemName,record.getItemName()).set(WlRecord::getDescribe,record.getDescribe())
.eq(WlRecord::getId, record.getId())
.eq(WlRecord::getType, 0);
this.update(lambdaUpdateWrapper);
}
private RecordTreeVo.Children mapToChildren(RecordVo record) {
RecordTreeVo.Children children = new RecordTreeVo.Children();
BeanUtils.copyProperties(record, children);
return children;
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteDataRecord(WlRecordParam.UpdateRecord record) {
for(String dataRecordId : record.getList()){
this.baseMapper.deleteDataRecord(record.getId(),dataRecordId);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveDataRecord(WlRecordParam.UpdateRecord record) {
for(String dataRecordId : record.getList()){
this.baseMapper.saveDataRecord(record.getId(),dataRecordId);
}
}
@Override
public List<Map> schemeRecordDown() {
return this.baseMapper.schemeRecordDown();
}
/**
* 获取测试项绑定的基础数据最早的设备开始时间
* @param testRecordId
* @return
*/
private LocalDateTime getFirstTimeById(String testRecordId) {
QueryWrapper<WlRecord> qw = new QueryWrapper();
List<String> recordIds = this.baseMapper.getDataRecordBytestId(testRecordId);
if(recordIds.isEmpty()){
recordIds.add("-1");
}
qw.eq("state","1").in("id",recordIds).orderByAsc("start_Time");
List<WlRecord> list = this.baseMapper.selectList(qw);
if(list.isEmpty()){
return null;
}
return list.get(0).getStartTime();
}
/**
* 获取测试项绑定的基础数据最晚的设备结束时间
* @param testRecordId
* @return
*/
private LocalDateTime getLastTimeById(String testRecordId) {
QueryWrapper<WlRecord> qw = new QueryWrapper();
List<String> recordIds = this.baseMapper.getDataRecordBytestId(testRecordId);
if(recordIds.isEmpty()){
recordIds.add("-1");
}
qw.eq("state","1").in("id",recordIds).orderByDesc("end_Time");
List<WlRecord> list = this.baseMapper.selectList(qw);
if(list.isEmpty()){
return null;
}
return list.get(0).getEndTime();
}
}