1、新增云协议设备台账录入功能;

2、新增云协议设备实时数据请求功能
This commit is contained in:
xy
2025-09-04 13:58:30 +08:00
parent 066dceaeaf
commit 8c442d8897
44 changed files with 1938 additions and 267 deletions

View File

@@ -45,7 +45,6 @@ import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Description:
* 接口文档访问地址http://serverIP:port/swagger-ui.html
@@ -60,7 +59,6 @@ import java.util.stream.Stream;
@Api(tags = " 出厂设备")
@AllArgsConstructor
public class EquipmentDeliveryController extends BaseController {
private final CsEquipmentDeliveryService csEquipmentDeliveryService;
private final IMqttUserService mqttUserService;
private final CsDevModelRelationService csDevModelRelationService;
@@ -85,7 +83,6 @@ public class EquipmentDeliveryController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/AuditEquipmentDelivery")
@ApiOperation("删除出厂设备")
@@ -115,16 +112,13 @@ public class EquipmentDeliveryController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryEquipmentByndid")
@ApiOperation("通过ndid查询出厂设备")
@ApiImplicitParam(name = "ndid", value = "网关识别码", required = true)
public HttpResult<CsEquipmentDeliveryVO> queryEquipmentByndid(@RequestParam("ndid")String ndid){
String methodDescribe = getMethodDescribe("queryEquipmentByndid");
CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentByndid (ndid);
CsEquipmentDeliveryVO csEquipmentDeliveryVO = csEquipmentDeliveryService.queryEquipmentByndid (ndid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, csEquipmentDeliveryVO, methodDescribe);
}
@@ -146,11 +140,12 @@ public class EquipmentDeliveryController extends BaseController {
@ApiImplicitParam(name = "status", value = "状态", required = true)
})
@DeviceLog(operateType = DeviceOperate.UPDATESTATUSBYNDID)
public HttpResult<Boolean> updateStatusBynDid(@RequestParam("nDId") String nDid,@RequestParam("status") Integer status){
public HttpResult<Boolean> updateStatusBynDid(@RequestParam("nDId") String nDid,@RequestParam("status") Integer status){
String methodDescribe = getMethodDescribe("updateStatusBynDid");
csEquipmentDeliveryService.updateStatusBynDid(nDid,status);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryEquipmentById")
@ApiOperation("设备查询通过id获取")
@@ -217,13 +212,11 @@ public class EquipmentDeliveryController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
}
@ResponseBody
@ApiOperation("导出设备模板")
@GetMapping(value = "getExcelTemplate")
public HttpResult<String> getExcelTemplate(HttpServletResponse response) {
String methodDescribe = getMethodDescribe("getExcelTemplate");
ExportParams exportParams = new ExportParams("批量导入模板(请严格按照模板标准填入数据)", "终端入网检测录入信息");
exportParams.setStyle(ExcelStyleUtil.class);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, DeviceExcelTemplete.class, new ArrayList<DeviceExcelTemplete>());
@@ -256,10 +249,10 @@ public class EquipmentDeliveryController extends BaseController {
mqttUserService.insertMqttUser(temp.getNdid());
}
});
}
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@ResponseBody
@ApiOperation("联调完成")
@PostMapping(value = "testcompletion")
@@ -282,8 +275,8 @@ public class EquipmentDeliveryController extends BaseController {
@PostMapping("/updateSoftInfo")
@ApiOperation("更新设备软件信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "nDid", value = "网络设备码", required = true),
@ApiImplicitParam(name = "id", value = "软件信息id", required = true)
@ApiImplicitParam(name = "nDid", value = "网络设备码", required = true),
@ApiImplicitParam(name = "id", value = "软件信息id", required = true)
})
@ApiIgnore
public HttpResult<String> updateSoftInfo(@RequestParam("nDid") String nDid,@RequestParam("id") String id){
@@ -306,7 +299,6 @@ public class EquipmentDeliveryController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/rebootDevice")
@ApiOperation("重启设备")
@@ -348,4 +340,37 @@ public class EquipmentDeliveryController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
}
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/addCldDev")
@ApiOperation("新增云前置设备")
@ApiImplicitParam(name = "param", value = "参数", required = true)
@DeviceLog(operateType = DeviceOperate.ADD)
public HttpResult<CsEquipmentDeliveryPO> addCldDev(@RequestBody @Validated CsEquipmentDeliveryAddParm param){
String methodDescribe = getMethodDescribe("addCldDev");
CsEquipmentDeliveryPO po = csEquipmentDeliveryService.saveCld(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/delCldDev")
@ApiOperation("删除云前置设备")
@ApiImplicitParam(name = "id", value = "id", required = true)
@DeviceLog(operateType = DeviceOperate.DELETE)
public HttpResult<Boolean> delCldDev(@RequestBody @Validated String id){
String methodDescribe = getMethodDescribe("delCldDev");
boolean result = csEquipmentDeliveryService.delCldDev(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/updateCldDev")
@ApiOperation("修改云前置设备")
@ApiImplicitParam(name = "param", value = "参数", required = true)
@DeviceLog(operateType = DeviceOperate.UPDATE)
public HttpResult<Boolean> updateCldDev(@RequestBody @Validated CsEquipmentDeliveryAuditParm param){
String methodDescribe = getMethodDescribe("updateCldDev");
boolean result = csEquipmentDeliveryService.updateCldDev(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -0,0 +1,59 @@
package com.njcn.csdevice.controller.icd;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.param.IcdLedgerParam;
import com.njcn.csdevice.param.IcdParam;
import com.njcn.csdevice.pojo.vo.DeviceInfo;
import com.njcn.csdevice.service.IcdService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author xy
* @version V1.0.0
*/
@Slf4j
@RestController
@RequestMapping("/icd")
@Api(tags = "云前置改造")
@AllArgsConstructor
public class IcdController extends BaseController {
private final IcdService icdService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getLedgerInfo")
@ApiOperation("获取台账信息")
@ApiImplicitParam(name = "param", value = "参数", required = true)
public HttpResult<List<DeviceInfo>> getLedgerInfo(@RequestBody @Validated IcdParam param){
String methodDescribe = getMethodDescribe("getLedgerInfo");
List<DeviceInfo> result = icdService.getLedgerInfo(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/addLedgerInfo")
@ApiOperation("新增台账信息")
@ApiImplicitParam(name = "param", value = "参数", required = true)
public HttpResult<List<DeviceInfo>> addLedgerInfo(@RequestBody @Validated IcdLedgerParam param){
String methodDescribe = getMethodDescribe("addLedgerInfo");
icdService.addLedgerInfo(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -0,0 +1,163 @@
package com.njcn.csdevice.controller.icd;
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.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.pojo.param.NodeParam;
import com.njcn.csdevice.pojo.po.Node;
import com.njcn.csdevice.service.INodeService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
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 javax.validation.constraints.NotNull;
import java.util.List;
/**
* 前置程序控制器
* @author xy
*/
@Slf4j
@Api(tags = "前置机管理")
@RestController
@RequestMapping("node")
@RequiredArgsConstructor
public class NodeController extends BaseController {
private final INodeService iNodeService;
/**
* 新增前置机
* @author cdf
* @date 2021/6/23
*/
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
@ApiOperation("新增前置机")
@ApiImplicitParam(value = "前置机信息",name = "nodeParam",required = true)
@PostMapping("addNode")
public HttpResult<Boolean> addNode(@Validated @RequestBody NodeParam nodeParam){
String methodDescribe = getMethodDescribe("addNode");
boolean result = iNodeService.addNode(nodeParam);
if (result){
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
/**
* 修改前置机
* @author cdf
* @date 2021/6/23
*/
@ApiOperation("修改前置机")
@ApiImplicitParam(value = "前置机信息",name = "updateNodeParam",required = true)
@PutMapping("updateNode")
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.UPDATE)
public HttpResult<Boolean> updateNode(@Validated @RequestBody NodeParam.NodeUpdateParam updateNodeParam){
String methodDescribe = getMethodDescribe("updateNode");
boolean result = iNodeService.updateNode(updateNodeParam);
if (result){
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
/**
* 删除前置
* @author cdf
* @date 2021/6/23
*/
@ApiOperation(value = "删除前置机")
@ApiImplicitParam(value = "前置机id",name = "id",required = true)
@PostMapping("delNode")
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.DELETE)
public HttpResult<Boolean> delNode(@Validated @NotNull(message = "id不可为空") @RequestParam("id")String id){
String methodDescribe = getMethodDescribe("delNode");
boolean result = iNodeService.delNode(id);
if (result){
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
/**
* 变更前置机状态
* @author cdf
* @date 2021/6/23
*/
@ApiOperation(value = "变更前置机状态")
@ApiImplicitParams({
@ApiImplicitParam(value = "前置机id",name = "id",required = true ),
@ApiImplicitParam(value = "前置机状态",name = "state",required = true )
})
@PostMapping("updateNodeState")
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.UPDATE)
public HttpResult<Boolean> updateNodeState(@Validated @NotNull(message = "id不可为空") @RequestParam("id")String id,@NotNull(message = "状态不为空") @RequestParam("state")Integer state){
String methodDescribe = getMethodDescribe("updateNodeState");
boolean result = iNodeService.updateNodeState(id,state);
if (result){
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
} else {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
}
}
/**
* 获取全部前置机分页
* @author cdf
* @date 2021/6/23
*/
@ApiOperation("获取全部前置机")
@OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
@PostMapping("nodeList")
public HttpResult<Page<Node>> nodeList(@RequestBody NodeParam.NodeQueryParam nodeQueryParam){
String methodDescribe = getMethodDescribe("nodeList");
Page<Node> page = iNodeService.nodeList(nodeQueryParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
}
/**
* 获取全部前置机不分页
* @author cdf
* @date 2021/6/23
*/
@ApiOperation("获取全部前置机")
@OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
@GetMapping("/nodeAllList")
public HttpResult<List<Node>> nodeAllList(){
String methodDescribe = getMethodDescribe("nodeAllList");
List<Node> resList = iNodeService.nodeAllList();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, resList, methodDescribe);
}
/**
* 根据id获取前置机
* @author cdf
* @date 2021/6/23
*/
@ApiOperation("根据id获取前置机")
@ApiImplicitParam(value = "前置机id",name = "id",required = true)
@OperateInfo(info = LogEnum.BUSINESS_MEDIUM)
@GetMapping("/getNodeById")
public HttpResult<Node> getNodeById(@Validated @NotNull(message = "id不可为空") @RequestParam("id")String id){
String methodDescribe = getMethodDescribe("getNodeById");
Node node = iNodeService.getNodeById(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, node, methodDescribe);
}
}

View File

@@ -92,16 +92,6 @@ public class CslineController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
// @OperateInfo(info = LogEnum.BUSINESS_COMMON)
// @PostMapping("/addLineList")
// @ApiOperation("批量新增监测点及绑定关系")
// @ApiImplicitParam(name = "list", value = "监测点数据集", required = true)
// public HttpResult<String> addLines(@RequestBody List<CsLineParm> list){
// String methodDescribe = getMethodDescribe("addLines");
// csLinePOService.addLines(list);
// return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
// }
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/findByNdid")
@ApiOperation("根据ndid查询监测点")
@@ -167,4 +157,32 @@ public class CslineController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/addCldLine")
@ApiOperation("新增云前置监测点")
@ApiImplicitParam(name = "param", value = "param", required = true)
public HttpResult<List<CsLinePO>> addCldLine(@RequestBody @Validated CsLineParam param) {
String methodDescribe = getMethodDescribe("addCldLine");
csLinePOService.addCldLine(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/updateCldLine")
@ApiOperation("修改云前置监测点")
@ApiImplicitParam(name = "id", value = "id", required = true)
public HttpResult<List<CsLinePO>> updateCldLine(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("updateCldLine");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/delCldLine")
@ApiOperation("删除云前置监测点")
@ApiImplicitParam(name = "id", value = "监测点id", required = true)
public HttpResult<List<CsLinePO>> delCldLine(@RequestParam("id") String id) {
String methodDescribe = getMethodDescribe("delCldLine");
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -1,5 +1,6 @@
package com.njcn.csdevice.controller.project;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
@@ -68,8 +69,8 @@ public class AppProjectController extends BaseController {
public HttpResult<Boolean> addAppProject(@Validated AppProjectAddParm appProjectAddParm){
String methodDescribe = getMethodDescribe("addAppProject");
Boolean flag = appProjectService.addAppProject(appProjectAddParm);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
AppProjectPO po = appProjectService.addAppProject(appProjectAddParm);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, ObjectUtil.isNotNull(po), methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/auditAppProject")

View File

@@ -1,5 +1,6 @@
package com.njcn.csdevice.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -21,6 +22,7 @@ import java.util.List;
* @author clam
* @version V1.0.0
*/
@DS("master")
public interface CsEquipmentDeliveryMapper extends BaseMapper<CsEquipmentDeliveryPO> {
Page<ProjectEquipmentVO> queryProjectEquipmentVO(Page<ProjectEquipmentVO> returnpage,@Param("projectEquipmentQueryParm")ProjectEquipmentQueryParm projectEquipmentQueryParm,@Param("device")List<String> device);
@@ -32,4 +34,5 @@ public interface CsEquipmentDeliveryMapper extends BaseMapper<CsEquipmentDeliver
//获取符合条件的设备数量
int getCounts(@Param("queryParam") CsEquipmentDeliveryQueryParm queryParam);
int getListByNodeProcess(@Param("nodeId")String nodeId,@Param("process")Integer process);
}

View File

@@ -0,0 +1,25 @@
package com.njcn.csdevice.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.csdevice.param.IcdParam;
import com.njcn.csdevice.pojo.po.Node;
import com.njcn.csdevice.pojo.vo.DeviceInfo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* <p>
* Mapper 接口
* </p>
*
* @author cdf
* @since 2022-01-04
*/
@DS("sjzx")
public interface NodeMapper extends BaseMapper<Node> {
List<DeviceInfo> nodeDeviceList(@Param("nodeDeviceParam") IcdParam icdParam);
}

View File

@@ -124,4 +124,17 @@
</if>
</where>
</select>
<select id="getListByNodeProcess" resultType="int">
select
count(1)
from
cs_equipment_delivery
where
node_id = #{nodeId} and run_status != 0
<if test="process != null and process !=''">
and node_process > #{process}
</if>
</select>
</mapper>

View File

@@ -0,0 +1,43 @@
<?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.csdevice.mapper.NodeMapper">
<select id="nodeDeviceList" resultType="com.njcn.csdevice.pojo.vo.DeviceInfo">
SELECT
pq_device.Id id,
pq_device.IP ip,
s1.Name devType,
pq_device.Port port,
pq_line.Name name,
sub.Name subName,
pq_device.Update_Time updateTime,
s2.Name manufacturer,
pq_device.Com_Flag status,
pq_device.Series series,
pq_device_process.process_no processNo,
pq_device.Dev_Key devKey,
pq_node.max_Process_Num maxProcessNum
FROM
pq_device
LEFT JOIN pq_node ON pq_node.Id = pq_device.Node_Id
LEFT JOIN pq_line on pq_device.id = pq_line.id
LEFT JOIN pq_line sub on pq_line.pid = sub.id
LEFT JOIN pq_device_process on pq_device_process.id = pq_device.id
LEFT JOIN pq_dev_type s1 ON pq_device.Dev_Type = s1.id
LEFT JOIN sys_dict_data s2 ON pq_device.Manufacturer = s2.id
<where>
<if test="nodeDeviceParam.ip!=null and nodeDeviceParam.ip != ''">
pq_node.ip=#{nodeDeviceParam.ip}
</if>
<if test="nodeDeviceParam.devId!=null and nodeDeviceParam.devId != ''">
pq_device.id=#{nodeDeviceParam.devId}
</if>
<if test="nodeDeviceParam.runFlag!=null and nodeDeviceParam.runFlag.size()!=0">
AND pq_device.Run_Flag in
<foreach collection="nodeDeviceParam.runFlag" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
</if>
</where>
</select>
</mapper>

View File

@@ -27,8 +27,8 @@ public interface AppProjectService extends IService<AppProjectPO> {
* @return: java.lang.Boolean
* @Author: clam
* @Date: 2023/3/27
*/
Boolean addAppProject(AppProjectAddParm appProjectAddOrAuditParm);
*/
AppProjectPO addAppProject(AppProjectAddParm appProjectAddOrAuditParm);
/**
* @Description: AuditAppProject
* @Param: [appProjectAuditParm]

View File

@@ -76,4 +76,10 @@ public interface CsDevModelService extends IService<CsDevModelPO>{
*/
CsDevModelPO getModelById(String id);
/**
* 获取云前置模板
* @return
*/
CsDevModelPO getCldModel();
}

View File

@@ -32,30 +32,30 @@ public interface CsEquipmentDeliveryService extends IService<CsEquipmentDelivery
*/
void refreshDeviceDataCache();
/**
* @Description: save
* @Param: [csEquipmentDeliveryAddParm]
* @return: java.lang.Boolean
* @Author: clam
* @Date: 2023/3/31
*/
CsEquipmentDeliveryPO save(CsEquipmentDeliveryAddParm csEquipmentDeliveryAddParm);
/**
* @Description: AuditEquipmentDelivery
* @Param: [id]
* @return: java.lang.Boolean
* @Author: clam
* @Date: 2023/3/31
*/
Boolean AuditEquipmentDelivery(String id);
/**
* @Description: queryEquipmentByndid
* @Param: [ndid]
* @return: com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO
* @Author: clam
* @Date: 2023/3/31
*/
CsEquipmentDeliveryVO queryEquipmentByndid(String ndid);
/**
* @Description: save
* @Param: [csEquipmentDeliveryAddParm]
* @return: java.lang.Boolean
* @Author: clam
* @Date: 2023/3/31
*/
CsEquipmentDeliveryPO save(CsEquipmentDeliveryAddParm csEquipmentDeliveryAddParm);
/**
* @Description: AuditEquipmentDelivery
* @Param: [id]
* @return: java.lang.Boolean
* @Author: clam
* @Date: 2023/3/31
*/
Boolean AuditEquipmentDelivery(String id);
/**
* @Description: queryEquipmentByndid
* @Param: [ndid]
* @return: com.njcn.algorithm.pojo.vo.CsEquipmentDeliveryVO
* @Author: clam
* @Date: 2023/3/31
*/
CsEquipmentDeliveryVO queryEquipmentByndid(String ndid);
/**
* @Description: queryEquipmentByProject
* @Param: [projectEquipmentQueryParm]
@@ -135,4 +135,36 @@ public interface CsEquipmentDeliveryService extends IService<CsEquipmentDelivery
boolean judgeDevModel(String nDid);
CsEquipmentDeliveryPO getDevByLineId(String lineId);
/**
* 新增云前置设备
* @param param
* @return
*/
CsEquipmentDeliveryPO saveCld(CsEquipmentDeliveryAddParm param);
/**
* 删除云前置设备
* @param id
* @return
*/
Boolean delCldDev(String id);
/**
* 更新云前置设备
* @param param
* @return
*/
Boolean updateCldDev(CsEquipmentDeliveryAuditParm param);
/**
* 根据前置ip和运行状态获取装置数据
* @param id
* @param runFlag
* @return
*/
List<CsEquipmentDeliveryPO> getCldDevByIp(String id, List<Integer> runFlag);
}

View File

@@ -47,4 +47,7 @@ public interface CsLinePOService extends IService<CsLinePO>{
void updateIds(CsLineParam csLineParam);
List<CsLinePO> getLinesByDevList(List<String> list);
void addCldLine(CsLineParam param);
}

View File

@@ -0,0 +1,79 @@
package com.njcn.csdevice.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csdevice.pojo.param.NodeParam;
import com.njcn.csdevice.pojo.po.Node;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author cdf
* @since 2022-01-07
*/
public interface INodeService extends IService<Node> {
/**
* 新增前置机
* @author cdf
* @date 2021/6/23
*/
boolean addNode(NodeParam nodeParam);
/**
* 修改前置机
* @author cdf
* @date 2021/6/23
*/
boolean updateNode(NodeParam.NodeUpdateParam nodeParam);
/**
* 删除前置机
* @author cdf
* @date 2021/6/23
*/
boolean delNode(String id);
/**
* 修改前置机状态
* @author cdf
* @date 2021/6/23
*/
boolean updateNodeState(String id, Integer state);
/**
* 查询前置机列表
* @author cdf
* @date 2021/6/23
*/
Page<Node> nodeList(NodeParam.NodeQueryParam nodeQueryParam);
/**
* 查询前置机列表不分页
* @author cdf
* @date 2021/6/23
*/
List<Node> nodeAllList();
/**
* 根据前置机id获取前置机
* @author cdf
* @date 2021/6/23
*/
Node getNodeById(String id);
/**
* 根据前置机名称获取详细信息
* @param nodeName 前置机名称
* @return 前置信息
*/
Node getNodeByNodeName(String nodeName);
Node getNodeByIp(String ip);
}

View File

@@ -0,0 +1,15 @@
package com.njcn.csdevice.service;
import com.njcn.csdevice.param.IcdLedgerParam;
import com.njcn.csdevice.param.IcdParam;
import com.njcn.csdevice.pojo.vo.DeviceInfo;
import java.util.List;
public interface IcdService {
List<DeviceInfo> getLedgerInfo(IcdParam param);
void addLedgerInfo(IcdLedgerParam param);
}

View File

@@ -55,7 +55,7 @@ class AppProjectServiceImpl extends ServiceImpl<AppProjectMapper, AppProjectPO>
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean addAppProject(AppProjectAddParm appProjectAddOrAuditParm) {
public AppProjectPO addAppProject(AppProjectAddParm appProjectAddOrAuditParm) {
AppProjectPO appProjectPO = new AppProjectPO ( );
// Boolean result = checkName (appProjectAddOrAuditParm.getUserId ( ), appProjectAddOrAuditParm.getName ( ));
// if (result) {
@@ -109,19 +109,33 @@ class AppProjectServiceImpl extends ServiceImpl<AppProjectMapper, AppProjectPO>
}
}
CsLedger csLedger = csLedgerMapper.selectById(appProjectAddOrAuditParm.getEngineeringId());
Optional.ofNullable(csLedger).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.ENGINEERING_DATA_ERROR));
CsLedger csLedger1 = new CsLedger();
csLedger1.setId(appProjectPO.getId());
csLedger1.setPid(appProjectAddOrAuditParm.getEngineeringId());
csLedger1.setPids(csLedger.getPids()+ ","+appProjectAddOrAuditParm.getEngineeringId());
csLedger1.setLevel(1);
csLedger1.setName(appProjectPO.getName());
csLedger1.setState(1);
csLedger1.setSort(0);
csLedgerMapper.insert(csLedger1);
return save;
//云协议工程
if (Objects.nonNull(appProjectAddOrAuditParm.getIcdEngineeringId())){
CsLedger csLedger1 = new CsLedger();
csLedger1.setId(appProjectPO.getId());
csLedger1.setPid(appProjectAddOrAuditParm.getEngineeringId());
csLedger1.setPids("0,"+appProjectAddOrAuditParm.getEngineeringId());
csLedger1.setLevel(1);
csLedger1.setName(appProjectPO.getName());
csLedger1.setState(1);
csLedger1.setSort(0);
csLedgerMapper.insert(csLedger1);
}
//其他工程
else {
CsLedger csLedger = csLedgerMapper.selectById(appProjectAddOrAuditParm.getEngineeringId());
Optional.ofNullable(csLedger).orElseThrow(()-> new BusinessException(AlgorithmResponseEnum.ENGINEERING_DATA_ERROR));
CsLedger csLedger1 = new CsLedger();
csLedger1.setId(appProjectPO.getId());
csLedger1.setPid(appProjectAddOrAuditParm.getEngineeringId());
csLedger1.setPids(csLedger.getPids()+ ","+appProjectAddOrAuditParm.getEngineeringId());
csLedger1.setLevel(1);
csLedger1.setName(appProjectPO.getName());
csLedger1.setState(1);
csLedger1.setSort(0);
csLedgerMapper.insert(csLedger1);
}
return appProjectPO;
}
private Boolean checkName( String name,String id,String engineeringId) {

View File

@@ -1,10 +1,12 @@
package com.njcn.csdevice.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
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.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.mapper.CsDevModelMapper;
import com.njcn.csdevice.pojo.param.CsDevModelAddParm;
import com.njcn.csdevice.pojo.param.CsDevModelAuditParm;
@@ -26,6 +28,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Date;
import java.util.List;
import java.util.Objects;
/**
@@ -157,4 +160,20 @@ public class CsDevModelServiceImpl extends ServiceImpl<CsDevModelMapper, CsDevMo
return this.lambdaQuery().eq(CsDevModelPO::getId,id).one();
}
@Override
public CsDevModelPO getCldModel() {
List<CsDevModelPO> list = this.lambdaQuery()
.eq(CsDevModelPO::getDevTypeName,"CLD")
.eq(CsDevModelPO::getStatus,1)
.list();
if (CollectionUtil.isEmpty(list)) {
throw new BusinessException(AlgorithmResponseEnum.CLD_MODEL_MISSING);
} else {
if (list.size() > 1) {
throw new BusinessException(AlgorithmResponseEnum.CLD_MODEL_MORE);
}
}
return list.get(0);
}
}

View File

@@ -26,6 +26,7 @@ import com.njcn.csdevice.api.CsLogsFeignClient;
import com.njcn.csdevice.constant.DataParam;
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.mapper.CsEquipmentDeliveryMapper;
import com.njcn.csdevice.mapper.CsLedgerMapper;
import com.njcn.csdevice.mapper.CsSoftInfoMapper;
import com.njcn.csdevice.pojo.param.*;
import com.njcn.csdevice.pojo.po.*;
@@ -66,9 +67,8 @@ import java.io.InputStream;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
*
*
* Description:
* 接口文档访问地址http://serverIP:port/swagger-ui.html
* Date: 2023/3/30 16:23【需求编号】
@@ -79,7 +79,6 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliveryMapper, CsEquipmentDeliveryPO> implements CsEquipmentDeliveryService{
private final CsDevModelRelationService csDevModelRelationService;
private final ICsDataSetService csDataSetService;
private final ICsLedgerService csLedgerService;
@@ -98,6 +97,10 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
private final IMqttUserService mqttUserService;
private final MqttUtil mqttUtil;
private final CsLogsFeignClient csLogsFeignClient;
private final INodeService nodeService;
private final CsDevModelService csDevModelService;
private final CsLedgerMapper csLedgerMapper;
@Override
public void refreshDeviceDataCache() {
@@ -143,7 +146,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
csEquipmentProcess.setStartTime(LocalDateTime.now());
csEquipmentProcess.setProcess(1);
csEquipmentProcess.setStatus (1);
csEquipmentProcessPOService.save(csEquipmentProcess);
result = this.save (csEquipmentDeliveryPo);
if (result) {
@@ -153,7 +155,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
}
@Override
// @Transactional(rollbackFor = {Exception.class}, propagation = Propagation.REQUIRED)
public Boolean AuditEquipmentDelivery(String id) {
//物理删除
QueryWrapper<CsEquipmentDeliveryPO> wrapper = new QueryWrapper();
@@ -186,8 +187,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
/*后续徐那边做处理*/
// CsEquipmentDeliveryPO csEquipmentDeliveryPO = this.getBaseMapper().selectById(id);
// mqttUserService.deleteUser(csEquipmentDeliveryPO.getNdid());
csDevModelRelationService.lambdaUpdate().eq(CsDevModelRelationPO::getDevId,id).set(CsDevModelRelationPO::getStatus,0).update();
if (update) {
refreshDeviceDataCache();
@@ -205,6 +204,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
BeanUtils.copyProperties (csEquipmentDeliveryPO,result);
return result;
}
public CsEquipmentDeliveryPO queryEquipmentPOByndid(String ndid) {
QueryWrapper<CsEquipmentDeliveryPO> wrapper = new QueryWrapper();
wrapper.eq ("ndid", ndid);
@@ -220,7 +220,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
if(CollectionUtils.isEmpty(device)){
return returnpage;
}
Page<ProjectEquipmentVO> list = this.baseMapper.queryProjectEquipmentVO(returnpage,projectEquipmentQueryParm,device);
list.getRecords().stream().forEach(temp->{
temp.setIsPrimaryUser(csDeviceUserPOService.isPrimaryUser(temp.getEquipmentId()));
@@ -235,18 +234,16 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
boolean result;
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(CsEquipmentDeliveryPO::getNdid,csEquipmentDeliveryAuditParm.getNdid())
.in(CsEquipmentDeliveryPO::getStatus,Arrays.asList(1,2,3))
.ne(CsEquipmentDeliveryPO::getId, csEquipmentDeliveryAuditParm.getId());
.in(CsEquipmentDeliveryPO::getStatus,Arrays.asList(1,2,3))
.ne(CsEquipmentDeliveryPO::getId, csEquipmentDeliveryAuditParm.getId());
int countByAccount = this.count(lambdaQueryWrapper);
//大于等于1个则表示重复
if (countByAccount >= 1) {
throw new BusinessException(AlgorithmResponseEnum.NDID_ERROR);
}
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper2 = new LambdaQueryWrapper<>();
lambdaQueryWrapper2.eq(CsEquipmentDeliveryPO::getId, csEquipmentDeliveryAuditParm.getId());
CsEquipmentDeliveryPO po = this.baseMapper.selectOne(lambdaQueryWrapper2);
List<CsEquipmentDeliveryPO> list = this.lambdaQuery()
.ne(CsEquipmentDeliveryPO::getId, csEquipmentDeliveryAuditParm.getId())
.ne(CsEquipmentDeliveryPO::getNdid, csEquipmentDeliveryAuditParm.getNdid())
@@ -264,7 +261,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
BeanUtils.copyProperties (csLedger, csLedgerParam);
csLedgerParam.setName(csEquipmentDeliveryAuditParm.getName());
csLedgerService.updateLedgerTree(csLedgerParam);
if (result) {
refreshDeviceDataCache();
if (!Objects.equals(po.getUsageStatus(),csEquipmentDeliveryAuditParm.getUsageStatus())) {
@@ -328,73 +324,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
return page;
}
// @Override
// public Page<CsEquipmentDeliveryVO> list(CsEquipmentDeliveryQueryParm queryParam) {
// QueryWrapper<CsEquipmentDeliveryPO> queryWrapper = new QueryWrapper<CsEquipmentDeliveryPO>();
// if (ObjectUtil.isNotNull(queryParam)) {
// //查询参数不为空,进行条件填充
// if (StrUtil.isNotBlank(queryParam.getSearchValue())) {
// //部门根据名称模糊查询
// queryWrapper
// .and(param -> param.like("cs_equipment_delivery.name", queryParam.getSearchValue())
// .or().like("cs_equipment_delivery.ndid", queryParam.getSearchValue())
// .or().like("cs_equipment_delivery.mac", queryParam.getSearchValue()));
// }
// //排序
// if (ObjectUtil.isAllNotEmpty(queryParam.getSortBy(), queryParam.getOrderBy())) {
// queryWrapper.orderBy(true, queryParam.getOrderBy().equalsIgnoreCase(DbConstant.ASC), StrUtil.toUnderlineCase(queryParam.getSortBy()));
// } else {
// //默认根据创建时间排序
// queryWrapper.orderBy(true, false, "create_time");
// }
// }
// if (StrUtil.isNotBlank(queryParam.getDevType()) && !Objects.isNull(queryParam.getDevType())){
// queryWrapper.eq("cs_equipment_delivery.dev_type", queryParam.getDevType());
// }
// if (StrUtil.isNotBlank(queryParam.getDevModel()) && !Objects.isNull(queryParam.getDevModel())){
// queryWrapper.eq("cs_equipment_delivery.dev_model", queryParam.getDevModel());
// }
// if (StrUtil.isNotBlank(queryParam.getDevAccessMethod()) && !Objects.isNull(queryParam.getDevAccessMethod())){
// queryWrapper.eq("cs_equipment_delivery.dev_access_method", queryParam.getDevAccessMethod());
// }
// if (!Objects.isNull(queryParam.getStatus())){
// queryWrapper.eq("cs_equipment_delivery.status", queryParam.getStatus());
// } else {
// queryWrapper.in("cs_equipment_delivery.status", Arrays.asList(1,2,3));
// }
// if (!Objects.isNull(queryParam.getRunStatus())){
// queryWrapper.eq("cs_equipment_delivery.run_status", queryParam.getRunStatus());
// } else {
// queryWrapper.in("cs_equipment_delivery.run_status", Arrays.asList(1,2));
// }
// if (!Objects.isNull(queryParam.getProcess())){
// queryWrapper.eq("cs_equipment_delivery.process", queryParam.getProcess());
// }
// Page<CsEquipmentDeliveryVO> page = this.baseMapper.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper);
// page.getRecords().forEach(item->{
// if (!Objects.isNull(item.getQrPath())){
// item.setQrPath(item.getQrPath());
// }
// });
// //新增逻辑(只针对便携式设备):修改设备中的未注册状态(status = 1)改为5(前端定义的字典也即未接入)
// for(CsEquipmentDeliveryVO csEquipmentDeliveryVO : page.getRecords()){
// if(DataParam.portableDevType.equals(csEquipmentDeliveryVO.getDevType()) && csEquipmentDeliveryVO.getStatus() == 1){
// csEquipmentDeliveryVO.setStatus(5);
// } else if (DataParam.portableDevType.equals(csEquipmentDeliveryVO.getDevType()) && csEquipmentDeliveryVO.getStatus() == 2) {
// csEquipmentDeliveryVO.setStatus(6);
// }
// //判断装置是否已经连接上mqtt服务器
// String clientName = "NJCN-" + csEquipmentDeliveryVO.getNdid().substring(csEquipmentDeliveryVO.getNdid().length() - 6);
// boolean mqttClient = mqttUtil.judgeClientOnline(clientName);
// if (mqttClient) {
// csEquipmentDeliveryVO.setConnectStatus("已连接");
// } else {
// csEquipmentDeliveryVO.setConnectStatus("未连接");
// }
// }
// return page;
// }
@Override
public DeviceManagerVO getDeviceData(String deviceId, String type, String lineId) {
DeviceManagerVO deviceManagerVo = new DeviceManagerVO();
@@ -443,7 +372,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
dataSet = csDataSetService.findDataSetByModelId(modelId,2);
}
setDataSetValues(csEquipmentDeliveryPo, dataSet, dataSetList, type, deviceManagerVo);
}else if(Objects.equals(devTypeCode, DicDataEnum.PORTABLE.getCode())){
} else if(Objects.equals(devTypeCode, DicDataEnum.PORTABLE.getCode()) || Objects.equals(devTypeCode, DicDataEnum.DEV_CLD.getCode())){
List<CsDataSet> dataSet = new ArrayList<>();
List<CsDevModelRelationPO> modelId = csDevModelRelationService.findModelByDevId(deviceId);
if (CollUtil.isNotEmpty(modelId)){
@@ -472,6 +401,8 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
} else {
CsDataSet item = dataSet.get(0);
boolean isPortableDevice = DataParam.portableDevType.equals(csEquipmentDeliveryPo.getDevType());
boolean isCLdDevice = DicDataEnum.DEV_CLD.getCode().equals(dictTreeFeignClient.queryById(csEquipmentDeliveryPo.getDevType()).getData().getCode());
addDataSet(dataSetList, item, "最新数据", "rt");
addDataSet(dataSetList, item, "历史统计数据", "history");
addDataSet(dataSetList, item, "历史趋势", "trenddata");
@@ -491,6 +422,10 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
addDataSet(dataSetList, item, "暂态事件", "event");
addDataSet(dataSetList, item, "测试项日志", "items");
}
if (isCLdDevice) {
// 云前置数据集
addDataSet(dataSetList, item, "实时数据", "realtimedata");
}
deviceManagerVo.setDataLevel(item.getDataLevel());
}
deviceManagerVo.setDataSetList(dataSetList);
@@ -540,10 +475,8 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
//如果存在非法数据,将不合格的数据导出
List<DeviceExcelTemplete> trueCollect = new ArrayList<> ( );
List<DeviceExcelTemplete.IllegalityDeviceExcelTemplete> falseCollect = new ArrayList<> ( );
for (int i = 0; i < terminalBaseList.getList ( ).size ( ); i++) {
DeviceExcelTemplete deviceExcelTemplete = terminalBaseList.getList ( ).get (i);
if(!deviceExcelTemplete.getNdid().matches(regex)){
DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete();
BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException);
@@ -551,7 +484,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
falseCollect.add(idlegalityDeviceException);
continue;
}
CsEquipmentDeliveryPO po = this.queryEquipmentPOByndid (deviceExcelTemplete.getNdid ( ));
if(!Objects.isNull (po)){
DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete();
@@ -572,7 +504,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
//设备类型
List<SysDicTreePO> children = deviceType.get(0).getChildren();
Map<String, SysDicTreePO> map = children.stream().collect(Collectors.toMap(SysDicTreePO::getName, dictTreeVO -> dictTreeVO));
List<SysDicTreePO> collect = children.stream().filter(temp -> Objects.equals(temp.getName(), deviceExcelTemplete.getDevType())).collect(Collectors.toList());
SysDicTreePO sysDicTreePO = map.get(deviceExcelTemplete.getDevType());
if(CollectionUtils.isEmpty(collect)){
@@ -583,15 +514,11 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
continue;
}else {
deviceExcelTemplete.setDevType(map.get(deviceExcelTemplete.getDevType()).getId());
}
//设备型号
List<SysDicTreePO> children1 = sysDicTreePO.getChildren();
Map<String, SysDicTreePO> map2 = children1.stream().collect(Collectors.toMap(SysDicTreePO::getName, dictTreeVO -> dictTreeVO));
List<SysDicTreePO> collect2 = children1.stream().filter(temp -> Objects.equals(temp.getName(), deviceExcelTemplete.getDevModel())).collect(Collectors.toList());
if(CollectionUtils.isEmpty(collect2)){
DeviceExcelTemplete.IllegalityDeviceExcelTemplete idlegalityDeviceException = new DeviceExcelTemplete.IllegalityDeviceExcelTemplete();
BeanUtils.copyProperties(deviceExcelTemplete,idlegalityDeviceException);
@@ -602,8 +529,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
deviceExcelTemplete.setDevModel(map2.get(deviceExcelTemplete.getDevModel()).getId());
trueCollect.add(deviceExcelTemplete);
}
}
if (!CollectionUtils.isEmpty (trueCollect)) {
List<CsEquipmentProcessPO> collect1 = new ArrayList<>();
@@ -618,7 +543,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
csEquipmentDeliveryPO.setStatus(1);
csEquipmentDeliveryPO.setProcess(2);
csEquipmentDeliveryPO.setSort(100);
CsEquipmentProcessPO csEquipmentProcess = new CsEquipmentProcessPO();
csEquipmentProcess.setDevId(csEquipmentDeliveryPO.getNdid());
csEquipmentProcess.setOperator(RequestUtil.getUserIndex());
@@ -630,7 +554,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
}).collect (Collectors.toList ( ));
csEquipmentProcessPOService.saveBatch(collect1,500);
this.saveOrUpdateBatch (collect, 500);
return collect;
}
if (!CollectionUtils.isEmpty (falseCollect)) {
@@ -639,21 +562,21 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
ExcelStyleUtil.exportFileByWorkbook (workbook, "非法设备信息.xlsx", response);
return null;
}
} catch (Exception e) {
e.printStackTrace ( );
}
return null;
}
/*
* 物理删除设备相关数据
*
* 2.删除cs_ledger
* 3.删除cs_dev_model_relation
* 4.删除cs_line
* 5.删除cs_line_topology_diagram
* 6.删除cs_device_user
* */
* 物理删除设备相关数据
*
* 2.删除cs_ledger
* 3.删除cs_dev_model_relation
* 4.删除cs_line
* 5.删除cs_line_topology_diagram
* 6.删除cs_device_user
* */
@Override
@Transactional(rollbackFor = Exception.class)
public void delete(String devId) {
@@ -713,11 +636,10 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
@Override
public void deleteTest(String deviceId, Integer type ,String remark) {
CsEquipmentDeliveryPO one = this.lambdaQuery().eq(CsEquipmentDeliveryPO::getId, deviceId).one();
this.lambdaUpdate().eq(CsEquipmentDeliveryPO::getId,deviceId).
// set(CsEquipmentDeliveryPO::getStatus,1).
// set(CsEquipmentDeliveryPO::getRunStatus,1).
set(CsEquipmentDeliveryPO::getProcess,type).update();
set(CsEquipmentDeliveryPO::getProcess,type).update();
this.delete(deviceId);
List<CsEquipmentProcessPO> list = csEquipmentProcessPOService.lambdaQuery().eq(CsEquipmentProcessPO::getDevId, one.getNdid()).
eq(CsEquipmentProcessPO::getProcess, type).orderByDesc(CsEquipmentProcessPO::getStartTime).list();
@@ -735,8 +657,8 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
boolean result;
LambdaUpdateWrapper<CsEquipmentDeliveryPO> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
lambdaUpdateWrapper.eq(CsEquipmentDeliveryPO::getNdid,nDid)
.ne(CsEquipmentDeliveryPO::getRunStatus,0)
.set(CsEquipmentDeliveryPO::getSoftinfoId,id);
.ne(CsEquipmentDeliveryPO::getRunStatus,0)
.set(CsEquipmentDeliveryPO::getSoftinfoId,id);
result = this.update(lambdaUpdateWrapper);
if (result) {
refreshDeviceDataCache();
@@ -800,6 +722,195 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
return this.lambdaQuery().eq(CsEquipmentDeliveryPO::getId,linePO.getDeviceId()).ne(CsEquipmentDeliveryPO::getRunStatus,0).one();
}
@Override
@Transactional(rollbackFor = Exception.class)
public CsEquipmentDeliveryPO saveCld(CsEquipmentDeliveryAddParm param) {
boolean result;
CsEquipmentDeliveryPO one = this.lambdaQuery().eq(CsEquipmentDeliveryPO::getName, param.getName()).ne(CsEquipmentDeliveryPO::getRunStatus, 0).one();
if(Objects.nonNull (one)){
throw new BusinessException ("设备名称不能重复");
}
StringUtil.containsSpecialCharacters(param.getNdid());
CsEquipmentDeliveryPO po = this.queryEquipmentPOByndid (param.getNdid());
if(!Objects.isNull (po)){
throw new BusinessException (AlgorithmResponseEnum.NDID_ERROR);
}
CsEquipmentDeliveryPO csEquipmentDeliveryPo = new CsEquipmentDeliveryPO();
BeanUtils.copyProperties (param,csEquipmentDeliveryPo);
csEquipmentDeliveryPo.setStatus (3);
csEquipmentDeliveryPo.setRunStatus(1);
csEquipmentDeliveryPo.setUsageStatus(1);
csEquipmentDeliveryPo.setProcess(4);
csEquipmentDeliveryPo.setMac(param.getMac());
//这边自动分配前置机进程号,需要做判断 1.新增装置时判断是否已经是最大装置数量2.根据进程号,选择最少的分配
csEquipmentDeliveryPo.setNodeId(param.getNodeId());
//判断1
Node node = nodeService.getNodeById(param.getNodeId());
List<CsEquipmentDeliveryPO> devList = getListByNodeId(param.getNodeId());
if (ObjectUtil.isNotEmpty(devList) && devList.size() >= node.getNodeDevNum()) {
throw new BusinessException (AlgorithmResponseEnum.OVER_MAX_DEV_COUNT);
}
//判断2
int process = findLeastFrequentProcess(devList,node.getMaxProcessNum());
csEquipmentDeliveryPo.setNodeProcess(process);
result = this.save(csEquipmentDeliveryPo);
//新增设备与模板之间的关系 获取云前置模板
CsDevModelPO csDevModelPO = csDevModelService.getCldModel();
CsDevModelRelationAddParm relationAddParam = new CsDevModelRelationAddParm();
relationAddParam.setDevId(csEquipmentDeliveryPo.getId());
relationAddParam.setModelId(csDevModelPO.getId());
relationAddParam.setDid(1);
CsDevModelRelationPO relation = csDevModelRelationService.addDevModelRelation(relationAddParam);
//新增台账数据
CsLedger csLedger = new CsLedger();
csLedger.setId(csEquipmentDeliveryPo.getId());
csLedger.setPid(param.getProjectId());
csLedger.setPids("0," + param.getEngineeringId() + "," + param.getProjectId());
csLedger.setLevel(2);
csLedger.setName(param.getName());
csLedger.setState(1);
csLedger.setSort(0);
int addLedger = csLedgerMapper.insert(csLedger);
if (result && ObjectUtil.isNotNull(relation) && addLedger > 0) {
refreshDeviceDataCache();
}
return csEquipmentDeliveryPo;
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean delCldDev(String id) {
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(CsEquipmentDeliveryPO::getId,id);
boolean update = this.remove(lambdaQueryWrapper);
List<CsLedger> list = csLedgerService.lambdaQuery().eq(CsLedger::getPid, id).list();
if(!CollectionUtils.isEmpty(list)){
List<String> collect = list.stream().map(CsLedger::getId).collect(Collectors.toList());
LambdaQueryWrapper<CsLinePO> csLinePOLambdaQueryWrapper = new LambdaQueryWrapper<>();
csLinePOLambdaQueryWrapper.in(CsLinePO::getLineId,collect);
csLinePOService.remove(csLinePOLambdaQueryWrapper);
}
LambdaQueryWrapper<CsLedger> csLedgerLambdaQueryWrapper = new LambdaQueryWrapper<>();
csLedgerLambdaQueryWrapper.clear();
csLedgerLambdaQueryWrapper.eq(CsLedger::getId,id);
csLedgerService.remove(csLedgerLambdaQueryWrapper);
csLedgerLambdaQueryWrapper.clear();
csLedgerLambdaQueryWrapper.eq(CsLedger::getPid,id);
csLedgerService.remove(csLedgerLambdaQueryWrapper);
csDevModelRelationService.lambdaUpdate().eq(CsDevModelRelationPO::getDevId,id).set(CsDevModelRelationPO::getStatus,0).update();
if (update) {
refreshDeviceDataCache();
}
return true;
}
@Override
public Boolean updateCldDev(CsEquipmentDeliveryAuditParm param) {
//云前置设备判断,修改云前置判断设备是否达到上限
if(ObjectUtil.isNotNull(param.getNodeId())){
Node node = nodeService.getNodeById(param.getNodeId());
List<CsEquipmentDeliveryPO> devList = getListByNodeId(param.getNodeId());
if (ObjectUtil.isNotEmpty(devList) && devList.size() >= node.getNodeDevNum()) {
throw new BusinessException (AlgorithmResponseEnum.OVER_MAX_DEV_COUNT);
}
//自动分配进程号
int process = findLeastFrequentProcess(devList,node.getMaxProcessNum());
param.setNodeProcess(process);
}
StringUtil.containsSpecialCharacters(param.getNdid());
boolean result;
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(CsEquipmentDeliveryPO::getNdid,param.getNdid())
.in(CsEquipmentDeliveryPO::getStatus,Arrays.asList(1,2,3))
.ne(CsEquipmentDeliveryPO::getId, param.getId());
int countByAccount = this.count(lambdaQueryWrapper);
//大于等于1个则表示重复
if (countByAccount >= 1) {
throw new BusinessException(AlgorithmResponseEnum.NDID_ERROR);
}
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper2 = new LambdaQueryWrapper<>();
lambdaQueryWrapper2.eq(CsEquipmentDeliveryPO::getId, param.getId());
CsEquipmentDeliveryPO po = this.baseMapper.selectOne(lambdaQueryWrapper2);
List<CsEquipmentDeliveryPO> list = this.lambdaQuery()
.ne(CsEquipmentDeliveryPO::getId, param.getId())
.ne(CsEquipmentDeliveryPO::getNdid, param.getNdid())
.eq(CsEquipmentDeliveryPO::getName, param.getName())
.ne(CsEquipmentDeliveryPO::getRunStatus, 0).list();
if(!CollectionUtils.isEmpty (list)){
throw new BusinessException ("设备名称不能重复");
}
CsEquipmentDeliveryPO csEquipmentDeliveryPo = new CsEquipmentDeliveryPO();
BeanUtils.copyProperties (param, csEquipmentDeliveryPo);
String path = this.createPath(param.getNdid());
csEquipmentDeliveryPo.setMac(path);
result = this.updateById(csEquipmentDeliveryPo);
//修改台账树中的设备名称
CsLedger csLedger = csLedgerService.findDataById(param.getId());
if (!Objects.isNull(csLedger)) {
CsLedgerParam.Update csLedgerParam = new CsLedgerParam.Update();
BeanUtils.copyProperties (csLedger, csLedgerParam);
csLedgerParam.setName(param.getName());
csLedgerService.updateLedgerTree(csLedgerParam);
}
if (result) {
refreshDeviceDataCache();
if (!Objects.equals(po.getUsageStatus(),param.getUsageStatus())) {
DeviceLogDTO dto = new DeviceLogDTO();
dto.setUserName(RequestUtil.getUsername());
dto.setOperate("设备使用状态被修改");
dto.setResult(1);
dto.setLoginName(RequestUtil.getLoginName());
csLogsFeignClient.addUserLog(dto);
}
}
return result;
}
@Override
public List<CsEquipmentDeliveryPO> getCldDevByIp(String id, List<Integer> runFlag) {
//运行状态转换
List<Integer> state = new ArrayList<>();
if (CollectionUtil.isNotEmpty(runFlag)) {
if (runFlag.contains(0)) {
state.add(1);
}
if (runFlag.contains(2)) {
state.add(0);
}
//fixme 目前治理设备只有启用和停用,没有那么多状态,如果前置传递其他状态,先设置一个不存在的状态
state.add(9);
}
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(CsEquipmentDeliveryPO::getNodeId,id)
.in(ObjectUtil.isNotEmpty(state),CsEquipmentDeliveryPO::getUsageStatus,state);
return this.list(lambdaQueryWrapper);
}
//根据前置机id获取装置数量
public List<CsEquipmentDeliveryPO> getListByNodeId(String nodeId) {
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(CsEquipmentDeliveryPO::getNodeId,nodeId)
.in(CsEquipmentDeliveryPO::getRunStatus,Arrays.asList(1,2));
return this.list(lambdaQueryWrapper);
}
public int findLeastFrequentProcess(List<CsEquipmentDeliveryPO> items, Integer process) {
Map<Integer, Long> processCounts = items.stream()
.collect(Collectors.groupingBy(CsEquipmentDeliveryPO::getNodeProcess, Collectors.counting()));
for (int i = 1; i <= process; i++) {
processCounts.putIfAbsent(i, 0L);
}
//如果列表为空默认返回1
return processCounts.entrySet().stream()
.min(Comparator.comparingLong(Map.Entry::getValue))
.map(Map.Entry::getKey)
.orElse(1);
}
/**
* 根据ndid生成二维码
* @param ndid
@@ -819,7 +930,6 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
e.printStackTrace();
}
return filePath;
}
public InputStream bufferedImageToInputStream(BufferedImage image) {
@@ -833,6 +943,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
}
return null;
}
/*将ndid转成mac地址*/
public String createPath(String nDid) {
// 使用StringBuilder来构建新的字符串
@@ -854,4 +965,4 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
}
return output.toString();
}
}
}

View File

@@ -7,14 +7,22 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.csdevice.mapper.CsLedgerMapper;
import com.njcn.csdevice.mapper.CsLinePOMapper;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.CsDataSet;
import com.njcn.csdevice.pojo.po.CsDevModelPO;
import com.njcn.csdevice.pojo.po.CsLedger;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csdevice.service.CsDevModelService;
import com.njcn.csdevice.service.CsLinePOService;
import com.njcn.csdevice.service.ICsDataSetService;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@@ -29,7 +37,11 @@ import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> implements CsLinePOService{
private final CsLedgerMapper csLedgerMapper;
private final CsDevModelService csDevModelService;
private final ICsDataSetService csDataSetService;
private final DicDataFeignClient dicDataFeignClient;
@Override
public List<CsLinePO> getLineByDev(List<String> list) {
@@ -88,6 +100,42 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
return this.lambdaQuery().in(CsLinePO::getDeviceId,list).eq(CsLinePO::getStatus,1).list();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void addCldLine(CsLineParam param) {
CsLinePO po = new CsLinePO();
//1.新增监测点信息
BeanUtils.copyProperties(param,po);
po.setStatus(1);
po.setRunStatus(2);
po.setLineId(param.getDevMac().replace(":","") + param.getClDid());
//模板id
CsDevModelPO po1 = csDevModelService.getCldModel();
po.setDataModelId(po1.getId());
//设备id
po.setDeviceId(param.getDevId());
//数据集id
List<CsDataSet> list = csDataSetService.findDataSetByModelId(po1.getId());
if (CollectionUtil.isNotEmpty(list)) {
po.setDataSetId(list.get(0).getId());
}
//监测位置
DictData data = dicDataFeignClient.getDicDataByCode(DicDataEnum.GRID_SIDE.getCode()).getData();
po.setPosition(data.getId());
this.save(po);
//2.新增台账树信息
CsLedger csLedger = new CsLedger();
csLedger.setId(param.getDevMac().replace(":","") + param.getClDid());
csLedger.setPid(param.getDevId());
csLedger.setPids("0," + param.getEngineeringId() + "," + param.getProjectId() + "," + param.getDevId());
csLedger.setName(param.getName());
csLedger.setLevel(3);
csLedger.setState(1);
csLedger.setSort(0);
csLedgerMapper.insert(csLedger);
}
// /**
// * 1.平台端默认配置拓扑图模板,包含拓扑图信息(cs_topology_diagram_template)和拓扑图上监测点的点位信息(cs_line_topology_template)
// *

View File

@@ -0,0 +1,220 @@
package com.njcn.csdevice.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.njcn.access.utils.ChannelObjectUtil;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.param.IcdLedgerParam;
import com.njcn.csdevice.param.IcdParam;
import com.njcn.csdevice.pojo.param.AppProjectAddParm;
import com.njcn.csdevice.pojo.param.CsEquipmentDeliveryAddParm;
import com.njcn.csdevice.pojo.param.CsLineParam;
import com.njcn.csdevice.pojo.po.*;
import com.njcn.csdevice.pojo.vo.DeviceInfo;
import com.njcn.csdevice.service.*;
import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.SysDicTreePO;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service
@RequiredArgsConstructor
class IcdServiceImpl implements IcdService {
private final INodeService nodeService;
private final ChannelObjectUtil channelObjectUtil;
private final RedisUtil redisUtil;
private final CsEngineeringService csEngineeringService;
private final AppProjectService appProjectService;
private final CsEquipmentDeliveryService csEquipmentDeliveryService;
private final CsDevModelRelationService csDevModelRelationService;
private final CsLinePOService csLinePOService;
@Override
public List<DeviceInfo> getLedgerInfo(IcdParam param) {
//获取装置型号
Map<String,SysDicTreePO> sysDicTreeMap = new HashMap<>();
List<SysDicTreePO> dictTreeList = channelObjectUtil.objectToList(redisUtil.getObjectByKey(AppRedisKey.DICT_TREE),SysDicTreePO.class);
SysDicTreePO po = dictTreeList.stream().filter(item -> Objects.equals(item.getCode(), DicDataEnum.DEV_CLD.getCode())).findFirst().orElse(null);
if (ObjectUtil.isNotNull(po)) {
String id = po.getId();
List<SysDicTreePO> cldDevType = dictTreeList.stream().filter(item->Objects.equals(item.getPid(),id)).collect(Collectors.toList());
sysDicTreeMap = cldDevType.stream().collect(Collectors.toMap(SysDicTreePO::getId, Function.identity()));
}
List<DeviceInfo> result = new ArrayList<>();
//根据ip获取前置机信息
Node node = nodeService.getNodeByIp(param.getIp());
if (ObjectUtil.isNotNull(node)) {
//根据前置机ip获取装置信息
List<CsEquipmentDeliveryPO> poList = csEquipmentDeliveryService.getCldDevByIp(node.getId(),param.getRunFlag());
if (CollectionUtil.isNotEmpty(poList)) {
//获取监测点集合
List<String> devList = poList.stream().map(CsEquipmentDeliveryPO::getId).collect(Collectors.toList());
List<CsLinePO> lineList = csLinePOService.getLinesByDevList(devList);
Map<String,List<CsLinePO>> lineMap = lineList.stream().collect(Collectors.groupingBy(CsLinePO::getDeviceId));
//组装返回结构体
Map<String, SysDicTreePO> finalSysDicTreeMap = sysDicTreeMap;
poList.forEach(dev->{
DeviceInfo detail = new DeviceInfo();
detail.setId(dev.getId());
detail.setName(dev.getName());
detail.setIp(dev.getMac());
detail.setDevType(Objects.isNull(finalSysDicTreeMap.get(dev.getDevModel())) ? "/":finalSysDicTreeMap.get(dev.getDevModel()).getCode());
detail.setNode(dev.getNodeProcess());
// 只获取当前设备的监测点数据
List<CsLinePO> lines = lineMap.get(dev.getId());
if (CollectionUtil.isNotEmpty(lines)) {
List<DeviceInfo.MonitorInfo> monitorInfos = new ArrayList<>();
lines.forEach(line->{
DeviceInfo.MonitorInfo monitorInfo = new DeviceInfo.MonitorInfo();
monitorInfo.setDeviceId(dev.getId());
monitorInfo.setId(line.getLineId());
monitorInfo.setName(line.getName());
monitorInfo.setLineNo(String.valueOf(line.getClDid()));
monitorInfo.setVoltageLevel(line.getVolGrade() + "kV");
monitorInfo.setStatus(line.getRunStatus());
monitorInfo.setPtType(String.valueOf(line.getConType()));
monitorInfo.setPt1(line.getPtRatio());
monitorInfo.setPt2(line.getPt2Ratio());
monitorInfo.setCt1(line.getCtRatio());
monitorInfo.setCt2(line.getCt2Ratio());
monitorInfos.add(monitorInfo);
});
detail.setMonitorData(monitorInfos);
}
result.add(detail);
});
}
}
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void addLedgerInfo(IcdLedgerParam param) {
// 第一种:全流程创建
if (isAllIndicesNull(param)) {
handleFullProcessCreation(param);
}
// 第二种:从工程创建
else if (ObjectUtil.isNotNull(param.getEngineeringIndex())) {
handleFromEngineeringCreation(param);
}
// 第三种:从项目创建
else if (ObjectUtil.isNotNull(param.getProjectIndex())) {
handleFromProjectCreation(param);
}
// 第四种:从设备创建
else if (CollectionUtil.isNotEmpty(param.getDevice())) {
handleFromDeviceCreation(param);
}
}
private boolean isAllIndicesNull(IcdLedgerParam param) {
return ObjectUtil.isNull(param.getEngineeringIndex())
&& ObjectUtil.isNull(param.getProjectIndex())
&& ObjectUtil.isNull(param.getDevIndex());
}
private void handleFullProcessCreation(@NotNull IcdLedgerParam param) {
if (ObjectUtil.isNotNull(param.getEngineering())) {
CsEngineeringPO po1 = csEngineeringService.addEngineering(param.getEngineering());
param.setEngineeringIndex(po1.getId());
createProjectAndDevices(param);
}
}
private void handleFromEngineeringCreation(IcdLedgerParam param) {
createProjectAndDevices(param);
}
private void handleFromProjectCreation(IcdLedgerParam param) {
saveDevicesAndLines(param);
}
private void handleFromDeviceCreation(IcdLedgerParam param) {
saveLines(param);
}
private void createProjectAndDevices(IcdLedgerParam param) {
AppProjectAddParm project = param.getProject();
if (ObjectUtil.isNotNull(project)) {
project.setEngineeringId(param.getEngineeringIndex());
project.setIcdEngineeringId(param.getEngineeringIndex());
AppProjectPO po2 = appProjectService.addAppProject(project);
param.setProjectIndex(po2.getId());
}
saveDevicesAndLines(param);
}
private void saveDevicesAndLines(IcdLedgerParam param) {
List<CsEquipmentDeliveryAddParm> devList = param.getDevice();
if (CollectionUtil.isNotEmpty(devList)) {
Map<String,String> devMacMap = new HashMap<>();
for (CsEquipmentDeliveryAddParm dev : devList) {
dev.setEngineeringId(param.getEngineeringIndex());
dev.setProjectId(param.getProjectIndex());
CsEquipmentDeliveryPO po3 = csEquipmentDeliveryService.saveCld(dev);
devMacMap.put(dev.getMac(),po3.getId());
}
param.setDevMacMap(devMacMap);
}
saveLines(param);
}
private void saveLines(IcdLedgerParam param) {
List<CsLineParam> lineList = param.getLine();
if (CollectionUtil.isNotEmpty(lineList)) {
boolean result = checkAndAlertDuplicates(lineList);
if (result) {
throw new BusinessException("监测点线路号重复,请调整!");
}
for (CsLineParam line : lineList) {
line.setEngineeringId(param.getEngineeringIndex());
line.setProjectId(param.getProjectIndex());
if (Objects.isNull(param.getDevIndex())) {
line.setDevId(param.getDevMacMap().get(line.getDevMac()));
} else {
LambdaQueryWrapper<CsLinePO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CsLinePO::getDeviceId,param.getDevIndex()).eq(CsLinePO::getClDid,line.getClDid()).eq(CsLinePO::getStatus,1);
CsLinePO po4 = csLinePOService.getOne(wrapper);
if (ObjectUtil.isNotNull(po4)) {
throw new BusinessException("监测点线路号重复,请调整!");
}
line.setDevId(param.getDevIndex());
}
csLinePOService.addCldLine(line);
}
}
}
//判断相同设备不能存在相同的线路号监测点
public boolean checkAndAlertDuplicates(List<CsLineParam> devices) {
// 使用Set来记录已经出现过的devMac+clDid组合
Set<String> seenCombinations = new HashSet<>();
List<CsLineParam> duplicates = new ArrayList<>();
for (CsLineParam device : devices) {
String combination = device.getDevMac() + "-" + device.getClDid();
if (seenCombinations.contains(combination)) {
// 发现重复,添加到重复列表
duplicates.add(device);
} else {
seenCombinations.add(combination);
}
}
return !duplicates.isEmpty();
}
}

View File

@@ -0,0 +1,166 @@
package com.njcn.csdevice.service.impl;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.mapper.CsEquipmentDeliveryMapper;
import com.njcn.csdevice.mapper.NodeMapper;
import com.njcn.csdevice.pojo.param.NodeParam;
import com.njcn.csdevice.pojo.po.Node;
import com.njcn.csdevice.service.INodeService;
import com.njcn.db.constant.DbConstant;
import com.njcn.device.biz.enums.DeviceResponseEnum;
import com.njcn.web.factory.PageFactory;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Objects;
/**
* <p>
* 服务实现类
* </p>
*
* @author cdf
* @since 2022-01-07
*/
@DS("sjzx")
@Service
@AllArgsConstructor
public class NodeServiceImpl extends ServiceImpl<NodeMapper, Node> implements INodeService {
private final CsEquipmentDeliveryMapper csEquipmentDeliveryMapper;
@Override
public boolean addNode(NodeParam nodeParam) {
checkNode(nodeParam, false);
Node node = new Node();
BeanUtils.copyProperties(nodeParam, node);
node.setState(DataStateEnum.ENABLE.getCode());
this.save(node);
return true;
}
@Override
public boolean updateNode(NodeParam.NodeUpdateParam nodeParam) {
//修改最大进程时,需要判断,如果进程数减少,需要先将少的进程数下面的测点分配到其他进程下面
int count = csEquipmentDeliveryMapper.getListByNodeProcess(nodeParam.getId(),nodeParam.getMaxProcessNum());
if (count > 0) {
throw new BusinessException(AlgorithmResponseEnum.DEV_OLD_DATA);
}
checkNode(nodeParam, true);
Node node = new Node();
BeanUtils.copyProperties(nodeParam, node);
this.updateById(node);
return true;
}
@Override
public boolean delNode(String id) {
//删除前置机,如果前置机下有设备,不允许删除
int count = csEquipmentDeliveryMapper.getListByNodeProcess(id,null);
if (count > 0) {
throw new BusinessException(AlgorithmResponseEnum.DEV_EXIST_DATA);
}
return this.removeById(id);
}
@Override
public boolean updateNodeState(String id, Integer state) {
Node node = new Node();
node.setId(id);
node.setState(state);
return this.updateById(node);
}
@Override
public Page<Node> nodeList(NodeParam.NodeQueryParam nodeQueryParam) {
QueryWrapper<Node> queryWrapper = new QueryWrapper<>();
//查询参数不为空,进行条件填充
if (Objects.nonNull(nodeQueryParam)) {
if(Objects.nonNull(nodeQueryParam.getNodeGrade()) ){
queryWrapper.eq("pq_node.node_grade",nodeQueryParam.getNodeGrade());
}
if(Objects.nonNull(nodeQueryParam.getSearchState()) ){
queryWrapper.eq("pq_node.state",nodeQueryParam.getSearchState());
}
//模糊值查询
if (StrUtil.isNotBlank(nodeQueryParam.getSearchValue())) {
//仅提供名称、ip模糊查询
queryWrapper.and(param -> param.like("pq_node.name", nodeQueryParam.getSearchValue())
.or().like("pq_node.ip", nodeQueryParam.getSearchValue()));
}
//排序字段不为空
if (ObjectUtil.isAllNotEmpty(nodeQueryParam.getSortBy(), nodeQueryParam.getOrderBy())) {
queryWrapper.orderBy(true, nodeQueryParam.getOrderBy().equals(DbConstant.ASC), StrUtil.toUnderlineCase(nodeQueryParam.getSortBy()));
} else {
//没有排序参数默认根据sort字段排序没有排序字段的根据updateTime更新时间排序
queryWrapper.orderBy(true, true, "pq_node.sort");
}
}
return this.page(new Page<>(PageFactory.getPageNum(nodeQueryParam), PageFactory.getPageSize(nodeQueryParam)), queryWrapper);
}
@Override
public List<Node> nodeAllList(){
LambdaQueryWrapper<Node> nodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
nodeLambdaQueryWrapper.eq(Node::getState,DataStateEnum.ENABLE.getCode()).orderByAsc(Node::getState);
return this.list(nodeLambdaQueryWrapper);
}
@Override
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public Node getNodeById(String id) {
return this.getById(id);
}
@Override
public Node getNodeByNodeName(String nodeName) {
LambdaQueryWrapper<Node> nodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
nodeLambdaQueryWrapper.eq(Node::getName, nodeName)
.eq(Node::getState, DataStateEnum.ENABLE.getCode());
return this.baseMapper.selectOne(nodeLambdaQueryWrapper);
}
@Override
public Node getNodeByIp(String ip) {
LambdaQueryWrapper<Node> nodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
nodeLambdaQueryWrapper.eq(Node::getIp, ip)
.eq(Node::getState, DataStateEnum.ENABLE.getCode());
return this.baseMapper.selectOne(nodeLambdaQueryWrapper);
}
/**
* 校验参数,检查是否存在相同编码的字典类型
*/
private void checkNode(NodeParam nodeParam, boolean isExcludeSelf) {
LambdaQueryWrapper<Node> nodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
nodeLambdaQueryWrapper
.eq(Node::getIp, nodeParam.getIp())
.eq(Node::getState, DataStateEnum.ENABLE.getCode());
//更新的时候,需排除当前记录
if (isExcludeSelf) {
if (nodeParam instanceof NodeParam.NodeUpdateParam) {
nodeLambdaQueryWrapper.ne(Node::getId, ((NodeParam.NodeUpdateParam) nodeParam).getId());
}
}
int countByAccount = this.count(nodeLambdaQueryWrapper);
//大于等于1个则表示重复
if (countByAccount >= 1) {
throw new BusinessException(DeviceResponseEnum.NODE_IP_SAME);
}
}
}