1.源装置,入参和发送指令业务编写

This commit is contained in:
wr
2024-12-16 20:47:07 +08:00
parent 5fde9586fc
commit 532ad9fcb5
20 changed files with 890 additions and 31 deletions

View File

@@ -17,7 +17,7 @@ public class SocketResponseService {
System.out.println("进入deal+++++++++++++++++++"); System.out.println("进入deal+++++++++++++++++++");
webSocketHandler.senMsgToUser(userId,msg); webSocketHandler.sendMsgToUser(userId,msg);
SocketManager.getChannelByUserId(userId).close(); SocketManager.getChannelByUserId(userId).close();

View File

@@ -9,12 +9,15 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor @RequiredArgsConstructor
public class SocketSourceResponseService { public class SocketSourceResponseService {
/**
* 向webSocket客户端发送消息
*/
private final WebSocketHandler webSocketHandler; private final WebSocketHandler webSocketHandler;
public void deal(String userId,String msg){ public void deal(String userId,String msg){
System.out.println("进入deal+++++++++++++++++++"); System.out.println("进入deal+++++++++++++++++++");
webSocketHandler.senMsgToUser(userId,msg); webSocketHandler.sendMsgToUser(userId,msg);
SocketManager.getChannelByUserId(userId).close(); SocketManager.getChannelByUserId(userId).close();

View File

@@ -12,10 +12,19 @@ import java.util.List;
@Data @Data
public class PreDetectionParam { public class PreDetectionParam {
//用户功能组成唯一标识 zhangsan_test /**
* 检测计划id
*/
private String plan;
/**
* 用户功能组成唯一标识 zhangsan_test
*/
private String userPageId; private String userPageId;
/**
* 检测终端id集合
*/
private List<String> devIds; private List<String> devIds;
} }

View File

@@ -0,0 +1,33 @@
package com.njcn.gather.detection.pojo.vo;
import lombok.Data;
/**
* @author wr
* @description
* @date 2024/12/13 9:09
*/
@Data
public class SocketDataMsg {
/**
* 请求id确保接收到响应时知晓是针对的哪次请求的应答
*/
private String requestId;
/**
* 源初始化 INIT_GATHER$01 INIT_GATHER采集初始化01 统计采集、02 暂态采集、03 实时采集
*/
private String operateCode;
/**
* 数据体传输前需要将对象、Array等转为String
*/
private String data;
/**
* code码
*/
private String code;
}

View File

@@ -4,6 +4,8 @@ import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import java.util.List; import java.util.List;
import com.njcn.gather.detection.pojo.param.PreDetectionParam;
/** /**
* @author wr * @author wr
* @description 预检测流程 * @description 预检测流程
@@ -13,12 +15,11 @@ public interface PreDetectionService {
/** /**
* 源通讯校验socket入参拼接 * 源通讯校验socket入参拼接
* @param * @param param
* @return: java.lang.String
* @Author: wr * @Author: wr
* @Date: 2024/12/11 13:26 * @Date: 2024/12/11 13:26
*/ */
void sourceCommunicationCheck(); void sourceCommunicationCheck(PreDetectionParam param);
/** /**
* 装置通讯校验 * 装置通讯校验

View File

@@ -1,21 +1,28 @@
package com.njcn.gather.detection.service.impl; package com.njcn.gather.detection.service.impl;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.njcn.gather.detection.handler.SocketSourceResponseService; import com.njcn.gather.detection.handler.SocketSourceResponseService;
import com.njcn.gather.detection.handler.SocketResponseService;
import com.njcn.gather.detection.pojo.param.PreDetectionParam; import com.njcn.gather.detection.pojo.param.PreDetectionParam;
import com.njcn.gather.detection.pojo.vo.SocketMsg; import com.njcn.gather.detection.pojo.vo.SocketMsg;
import com.njcn.gather.detection.service.PreDetectionService; import com.njcn.gather.detection.service.PreDetectionService;
import com.njcn.gather.detection.util.socket.cilent.NettyClient; import com.njcn.gather.detection.util.socket.cilent.NettyClient;
import com.njcn.gather.detection.util.socket.cilent.NettySourceClientHandler; import com.njcn.gather.detection.util.socket.cilent.NettySourceClientHandler;
import com.njcn.gather.device.device.mapper.PqDevMapper;
import com.njcn.gather.device.device.pojo.po.PqDev;
import com.njcn.gather.device.device.pojo.vo.PreDetection; import com.njcn.gather.device.device.pojo.vo.PreDetection;
import com.njcn.gather.device.device.service.IPqDevService; import com.njcn.gather.device.device.service.IPqDevService;
import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.device.script.pojo.po.SourceIssue;
import com.njcn.gather.device.script.service.IPqScriptDtlsService;
import com.njcn.gather.device.source.pojo.po.SourceInitialize;
import com.njcn.gather.device.source.service.IPqSourceService;
import com.njcn.gather.plan.pojo.po.AdPlan;
import com.njcn.gather.plan.pojo.po.AdPlanSource;
import com.njcn.gather.plan.service.IAdPlanService;
import com.njcn.gather.plan.service.IAdPlanSourceService;
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
import com.njcn.gather.system.dictionary.service.IDictDataService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -30,7 +37,11 @@ import java.util.Map;
public class PreDetectionServiceImpl implements PreDetectionService { public class PreDetectionServiceImpl implements PreDetectionService {
private final IPqDevService iPqDevService; private final IPqDevService iPqDevService;
private final IDictDataService dictDataService;
private final IAdPlanService iAdPlanService;
private final IAdPlanSourceService adPlanSourceService;
private final IPqSourceService pqSourceService;
private final IPqScriptDtlsService pqScriptDtlsService;
@Value("${socket.source.ip}") @Value("${socket.source.ip}")
private String ip; private String ip;
@@ -41,9 +52,74 @@ public class PreDetectionServiceImpl implements PreDetectionService {
private final SocketSourceResponseService sourceResponseService; private final SocketSourceResponseService sourceResponseService;
@Override
public void sourceCommunicationCheck() {
private final String userId = "aaa";
@Override
public void sourceCommunicationCheck(PreDetectionParam param) {
/*
先组装源通讯协议
查询计划什么模式的(除了对比式,其他都是一个计划对应一个源)
*/
AdPlan plan = iAdPlanService.getById(param.getPlan());
if (ObjectUtil.isNotNull(plan)) {
String code = dictDataService.getDictDataById(plan.getPattern()).getCode();
DictDataEnum dictDataEnumByCode = DictDataEnum.getDictDataEnumByCode(code);
switch (dictDataEnumByCode) {
case DIGITAL:
case SIMULATE:
sendYtxSocket(plan.getId());
break;
case CONTRAST:
//todo 对比式可以是多个源
break;
default:
//todo 没有找到对应的模式
break;
}
} else {
//todo 需要向前端推送消息查不到检测计划
}
}
/**
* 源参数下发
* @param scriptId
*/
private void sendSourceIssue(String scriptId){
}
private void sendYtxSocket(String planId){
AdPlanSource planSource = adPlanSourceService.getById(planId);
if(ObjectUtil.isNotNull(planSource)){
SourceInitialize sourceParam = pqSourceService.getSourceInitializeParam(planSource.getSourceId());
if(ObjectUtil.isNotNull(sourceParam)){
//开始组装socket报文请求头
SocketMsg msg=new SocketMsg();
msg.setRequestId("yjc_ytxjy");
msg.setOperateCode("");
msg.setData(JSON.toJSONString(sourceParam));
NettyClient.socketClient(ip, port, JSON.toJSONString(msg), new NettySourceClientHandler(ip, sourceResponseService));
PqScriptIssueParam param=new PqScriptIssueParam();
param.setScriptId(planSource.getSourceId());
param.setPlanId(planId);
param.setSourceId(planSource.getSourceId());
List<SourceIssue> sourceIssues = pqScriptDtlsService.listSourceIssue(param);
for (SourceIssue sourceIssue : sourceIssues) {
String jsonString = JSON.toJSONString(sourceIssue);
}
}else{
//todo 提示处理源表信息不存在
}
}else{
//todo 提示处理计划和源关系不存在
}
} }
@Override @Override

View File

@@ -1,7 +1,7 @@
package com.njcn.gather.detection.util.socket; package com.njcn.gather.detection.util.socket;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.njcn.gather.detection.pojo.vo.SocketMsg; import com.njcn.gather.detection.pojo.vo.SocketDataMsg;
/** /**
* @author wr * @author wr
@@ -12,7 +12,7 @@ import com.njcn.gather.detection.pojo.vo.SocketMsg;
public class MsgUtil { public class MsgUtil {
public SocketMsg a(String textMsg){ public SocketDataMsg socketDataMsg(String textMsg){
return JSON.parseObject(textMsg,SocketMsg.class); return JSON.parseObject(textMsg,SocketDataMsg.class);
} }
} }

View File

@@ -127,7 +127,7 @@ public class WebSocketHandler extends SimpleChannelInboundHandler<TextWebSocketF
/** /**
* 推送数据至前台 * 推送数据至前台
*/ */
public void senMsgToUser(String userId, String msg) { public void sendMsgToUser(String userId, String msg) {
WebServiceManager.sendMsg(userId, msg); WebServiceManager.sendMsg(userId, msg);
} }
} }

View File

@@ -34,6 +34,11 @@
<version>1.0.0</version> <version>1.0.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>
</dependencies> </dependencies>

View File

@@ -2,6 +2,7 @@ package com.njcn.gather.device.script.mapper;
import com.github.yulichang.base.MPJBaseMapper; import com.github.yulichang.base.MPJBaseMapper;
import com.njcn.gather.device.script.pojo.po.PqScript; import com.njcn.gather.device.script.pojo.po.PqScript;
import org.apache.ibatis.annotations.Param;
/** /**
* @author caozehui * @author caozehui
@@ -9,5 +10,13 @@ import com.njcn.gather.device.script.pojo.po.PqScript;
*/ */
public interface PqScriptMapper extends MPJBaseMapper<PqScript> { public interface PqScriptMapper extends MPJBaseMapper<PqScript> {
/**
* 获取检测脚本信息
* @param scriptId
* @return: com.njcn.gather.device.script.pojo.po.PqScript
* @Author: wr
* @Date: 2024/12/16 18:08
*/
Boolean selectScriptIsValueType(@Param("scriptId") String scriptId);
} }

View File

@@ -3,5 +3,14 @@
<mapper namespace="com.njcn.gather.device.script.mapper.PqScriptMapper"> <mapper namespace="com.njcn.gather.device.script.mapper.PqScriptMapper">
<select id="selectScriptIsValueType" resultType="java.lang.Boolean">
SELECT
IF((SELECT CODE FROM sys_dict_data WHERE id = Value_Type) = 'Ratio', 'true', 'false')
FROM
pq_script
where
State=1
and Id = #{scriptId}
</select>
</mapper> </mapper>

View File

@@ -0,0 +1,24 @@
package com.njcn.gather.device.script.pojo.param;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @Description:
* @Author: wr
* @Date: 2024/12/16 16:00
*/
@Data
public class PqScriptIssueParam {
@ApiModelProperty("检测脚本Id")
private String scriptId;
@ApiModelProperty("检测计划id")
private String planId;
@ApiModelProperty("源id")
private String sourceId ="111";
}

View File

@@ -1,5 +1,6 @@
package com.njcn.gather.device.script.pojo.po; package com.njcn.gather.device.script.pojo.po;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
@@ -32,12 +33,12 @@ public class PqScriptDtls implements Serializable {
/** /**
* 检测脚本类型 * 检测脚本类型
*/ */
private String scritpType; private String scriptType;
/** /**
* 误差体系类型 * 表明指标类型例如VOL电压、CUR电流、Freq频率...
*/ */
private String errorType; private String valueType;
/** /**
* 相别,字典表 * 相别,字典表
@@ -57,26 +58,31 @@ public class PqScriptDtls implements Serializable {
/** /**
* (间)谐波次数 * (间)谐波次数
*/ */
private Float harmNum; @TableField("HarmNum")
private Integer harmNum;
/** /**
* 暂态幅度(% * 暂态幅度(%
*/ */
@TableField("TransValue")
private Float transValue; private Float transValue;
/** /**
* 持续时间(周波) * 持续时间(周波)
*/ */
@TableField("RetainTime")
private Float retainTime; private Float retainTime;
/** /**
* 变动频度(次/min * 变动频度(次/min
*/ */
@TableField("ChagFre")
private Float chagFre; private Float chagFre;
/** /**
* 变动量(% * 变动量(%
*/ */
@TableField("ChagValue")
private Float chagValue; private Float chagValue;
/** /**

View File

@@ -0,0 +1,275 @@
package com.njcn.gather.device.script.pojo.po;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author wr
* @description
* @date 2024/12/16 11:24
*/
@NoArgsConstructor
@Data
public class SourceIssue {
/**
* 源ID
*/
@JSONField(name = "sourceId", ordinal = 1)
private String sourceId;
/**
* 检测类型
*/
@JSONField(name = "type", ordinal = 2)
private String type;
/**
* 多量响量
*/
@JSONField(name = "subType", ordinal = 3)
private String subType;
/**
* 被检设备额定电压
*/
@JSONField(name = "fUn", ordinal = 4)
private Float fUn;
/**
* 被检设备额定电流
*/
@JSONField(name = "fIn", ordinal = 5)
private Float fIn;
/**
* 频率
*/
@JSONField(name = "fFreq", ordinal = 6)
private Float fFreq;
/**
* 通道信息
*/
@JSONField(name = "channelList", ordinal = 7)
private List<ChannelListDTO> channelList;
@NoArgsConstructor
@Data
public static class ChannelListDTO {
/**
* 通道使能标志
*/
@JSONField(name = "channelFlag", ordinal = 1)
private Boolean channelFlag;
/**
* 谐波使能标志
*/
@JSONField(name = "harmFlag", ordinal = 2)
private Boolean harmFlag;
/**
* 间谐波使能标志
*/
@JSONField(name = "inHarmFlag", ordinal = 3)
private Boolean inHarmFlag;
/**
* 暂态使能标志
*/
@JSONField(name = "dipFlag", ordinal = 4)
private Boolean dipFlag;
/**
* 闪变使能标志
*/
@JSONField(name = "flickerFlag", ordinal = 5)
private Boolean flickerFlag;
/**
* 通道信息 枚举类型,包括{Ua, Ub, Uc, Ux, Ia, Ib, Ic, Ix ,NULL}
*/
@JSONField(name = "channelType", ordinal = 6)
private String channelType;
/**
* 幅值
*/
@JSONField(name = "fAmp", ordinal = 7)
private Float fAmp;
/**
* 相角
*/
@JSONField(name = "fPhase", ordinal = 8)
private Float fPhase;
/**
* 谐波叠加列表
*/
@JSONField(name = "harmList", ordinal = 9)
private List<HarmModel> harmList;
/**
* 间谐波叠加列表
*/
@JSONField(name = "inharmList", ordinal = 10)
private List<InharmModel> inharmList;
/**
* 暂态数据
*/
@JSONField(name = "dipData", ordinal = 11)
private DipDataDTO dipData;
/**
* 闪变数据
*/
@JSONField(name = "flickerData", ordinal = 12)
private FlickerDataDTO flickerData;
/**
* 谐波叠加列表
*/
@NoArgsConstructor
@Data
public static class HarmModel {
/**
* 谐波次数
*/
@JSONField(name = "harm", ordinal = 1)
private Integer harm;
/**
* 谐波含有率
*/
@JSONField(name = "fApm", ordinal = 2)
private Float fApm;
/**
* 谐波相角
*/
@JSONField(name = "fPhase", ordinal = 3)
private Float fPhase;
}
/**
* 间谐波叠加列表
*/
@NoArgsConstructor
@Data
public static class InharmModel {
/**
* 间谐波次数
*/
@JSONField(name = "inharm", ordinal = 1)
private Integer inharm;
/**
* 间谐波含有率
*/
@JSONField(name = "fApm", ordinal = 2)
private Float fApm;
/**
* 间谐波相角
*/
@JSONField(name = "fPhase", ordinal = 3)
private Float fPhase;
}
/**
* 暂态数据
*/
@NoArgsConstructor
@Data
public static class DipDataDTO {
/**
* 暂态幅值(%
*/
@JSONField(name = "fTransValue", ordinal = 1)
private Float fTransValue;
/**
* 暂态前时间s
*/
@JSONField(name = "fPreTime", ordinal = 2)
private Float fPreTime;
/**
* 写入时间s
*/
@JSONField(name = "fRampIn", ordinal = 3)
private Float fRampIn;
/**
* 暂态持续时间s
*/
@JSONField(name = "fRetainTime", ordinal = 4)
private Float fRetainTime;
/**
* 写出时间s
*/
@JSONField(name = "fRampOut", ordinal = 5)
private Float fRampOut;
/**
* 暂态后时间s
*/
@JSONField(name = "fAfterTime", ordinal = 6)
private Float fAfterTime;
}
/**
* 闪变数据
*/
@NoArgsConstructor
@Data
public static class FlickerDataDTO {
/**
* 波动类型
*/
@JSONField(name = "waveFluType", ordinal = 1)
private Object waveFluType;
/**
* 闪变调制波形类型
*/
@JSONField(name = "waveType", ordinal = 2)
private Object waveType;
/**
* 占空比
*/
@JSONField(name = "fDutyCycle", ordinal = 3)
private Float fDutyCycle;
/**
* 变动次数
*/
@JSONField(name = "fChagFre", ordinal = 4)
private Float fChagFre;
/**
* 变动量
*/
@JSONField(name = "fChagValue", ordinal = 5)
private Float fChagValue;
}
}
}

View File

@@ -1,7 +1,9 @@
package com.njcn.gather.device.script.service; package com.njcn.gather.device.script.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.device.script.pojo.po.PqScriptDtls; import com.njcn.gather.device.script.pojo.po.PqScriptDtls;
import com.njcn.gather.device.script.pojo.po.SourceIssue;
import java.util.List; import java.util.List;
@@ -50,4 +52,11 @@ public interface IPqScriptDtlsService extends IService<PqScriptDtls> {
* @return 脚本详情列表 * @return 脚本详情列表
*/ */
List<PqScriptDtls> listPqScriptDtlByScriptId(String scriptId); List<PqScriptDtls> listPqScriptDtlByScriptId(String scriptId);
/**
* 根据计划绑定检测脚本id获取全部检测脚本
* @param param
* @return
*/
List<SourceIssue> listSourceIssue(PqScriptIssueParam param);
} }

View File

@@ -1,18 +1,25 @@
package com.njcn.gather.device.script.service.impl; package com.njcn.gather.device.script.service.impl;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njcn.common.pojo.enums.common.DataStateEnum; import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.gather.device.device.pojo.po.PqDev;
import com.njcn.gather.device.device.service.IPqDevService;
import com.njcn.gather.device.script.mapper.PqScriptDtlsMapper; import com.njcn.gather.device.script.mapper.PqScriptDtlsMapper;
import com.njcn.gather.device.script.mapper.PqScriptMapper;
import com.njcn.gather.device.script.pojo.param.PqScriptIssueParam;
import com.njcn.gather.device.script.pojo.po.PqScript; import com.njcn.gather.device.script.pojo.po.PqScript;
import com.njcn.gather.device.script.pojo.po.PqScriptDtls; import com.njcn.gather.device.script.pojo.po.PqScriptDtls;
import com.njcn.gather.device.script.pojo.po.SourceIssue;
import com.njcn.gather.device.script.service.IPqScriptDtlsService; import com.njcn.gather.device.script.service.IPqScriptDtlsService;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author caozehui * @author caozehui
@@ -23,6 +30,20 @@ import java.util.List;
@RequiredArgsConstructor @RequiredArgsConstructor
public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqScriptDtls> implements IPqScriptDtlsService { public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqScriptDtls> implements IPqScriptDtlsService {
private final static String FREQ = "Freq";
private final static String VOL = "VOL";
private final static String CUR = "CUR";
private final static String HARM_V = "Harm_V";
private final static String HARM_I = "Harm_I";
private final static String INHARM_V = "InHarm_V";
private final static String INHARM_I = "InHarm_I";
private final static String DIP = "Dip";
private final static String FLICKER = "Flicker";
private final IPqDevService pqDevService;
private final PqScriptMapper pqScriptMapper;
@Override @Override
public boolean savePqScriptDtls(PqScriptDtls pqScriptDtls) { public boolean savePqScriptDtls(PqScriptDtls pqScriptDtls) {
return this.save(pqScriptDtls); return this.save(pqScriptDtls);
@@ -56,4 +77,238 @@ public class PqScriptDtlsServiceImpl extends ServiceImpl<PqScriptDtlsMapper, PqS
.eq(PqScriptDtls::getScriptId, scriptId); .eq(PqScriptDtls::getScriptId, scriptId);
return this.getBaseMapper().selectJoinList(PqScriptDtls.class, queryWrapper); return this.getBaseMapper().selectJoinList(PqScriptDtls.class, queryWrapper);
} }
@Override
public List<SourceIssue> listSourceIssue(PqScriptIssueParam param) {
List<SourceIssue> sourceIssues = new ArrayList<>();
//校验终端额定电压电流是否相同
List<PqDev> list = pqDevService.list(new LambdaQueryWrapper<PqDev>()
.eq(PqDev::getPlanId, param.getPlanId())
.eq(PqDev::getState, DataStateEnum.ENABLE.getCode())
);
//额定电压信息
Set<Float> voltSet = list.stream().map(PqDev::getDevVolt).collect(Collectors.toSet());
//额定电流信息
Set<Float> currSet = list.stream().map(PqDev::getDevCurr).collect(Collectors.toSet());
if (voltSet.size() == 1 && currSet.size() == 1) {
Float volt = voltSet.stream().collect(Collectors.toList()).stream().findFirst().get();
Float curr = currSet.stream().collect(Collectors.toList()).stream().findFirst().get();
List<PqScriptDtls> pqScriptDtls = this.pqScriptDtls(param.getScriptId(), volt, curr);
if (CollUtil.isNotEmpty(pqScriptDtls)) {
/**
* 1.获取全部检测点脚本
* 2.根据检测脚本Index,进行分组来确定是第几行数据,理论上基本数据只有七条
* 3.根据见树形字典在区分大类下面有多少小类
* 3.组装所有检测格式
*/
Map<Integer, List<PqScriptDtls>> scriptDtlsMap = pqScriptDtls.stream()
.sorted(Comparator.comparing(PqScriptDtls::getIndex))
.collect(Collectors.groupingBy(PqScriptDtls::getIndex));
scriptDtlsMap.forEach((key, value) -> {
/**
* 分组获取有多少小类
* VOL-Base:额定工作条件下的检测
* VOL-Freq:频率对电压测量的影响
* VOL-Harm:谐波对电压测量的影响
*/
List<PqScriptDtls> freq = value.stream().filter(x -> FREQ.equals(x.getValueType())).collect(Collectors.toList());
if (CollUtil.isNotEmpty(freq)) {
PqScriptDtls freqDtls = freq.get(0);
String[] split = freqDtls.getScriptType().replace("Base", "NULL").split("-");
SourceIssue issue = new SourceIssue();
issue.setSourceId(param.getSourceId());
issue.setType(split[0]);
issue.setSubType(split[1]);
issue.setFUn(volt);
issue.setFIn(curr);
issue.setFFreq(freqDtls.getValue());
List<SourceIssue.ChannelListDTO> channelListDTOS = new ArrayList<>();
//1.通道电压(ABC)
List<PqScriptDtls> volList = value.stream().filter(x -> VOL.equals(x.getValueType()) || HARM_V.equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
.collect(Collectors.toList());
//谐波电压,间谐波
List<PqScriptDtls> dtlsVList = value.stream().filter(x -> HARM_V.equals(x.getValueType()) || INHARM_V.equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
.collect(Collectors.toList());
issueAdd(volList, dtlsVList, HARM_V, INHARM_V, "U", channelListDTOS);
//2.通道电流(ABC)
List<PqScriptDtls> curList = value.stream().filter(x -> CUR.equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
.collect(Collectors.toList());
//谐波电流,间谐波电流
List<PqScriptDtls> dtlsIList = value.stream().filter(x -> HARM_I.equals(x.getValueType()) || HARM_I.equals(x.getValueType()))
.sorted(Comparator.comparing(PqScriptDtls::getPhase))
.collect(Collectors.toList());
issueAdd(curList, dtlsIList, HARM_I, INHARM_I, "I", channelListDTOS);
//todo 暂降和闪变没写
issue.setChannelList(channelListDTOS);
sourceIssues.add(issue);
}
});
}
}
return sourceIssues;
}
private List<PqScriptDtls> pqScriptDtls(String scriptId, Float volt, Float curr) {
//先获取检测脚本类型是否相对值 true相对值 false绝对值相对值要乘额定值,绝对值不需要处理)
Boolean isValueType = pqScriptMapper.selectScriptIsValueType(scriptId);
List<PqScriptDtls> pqScriptDtls = this.listPqScriptDtlByScriptId(scriptId);
if (isValueType) {
for (PqScriptDtls pqScriptDtl : pqScriptDtls) {
if (VOL.equals(pqScriptDtl.getValueType())) {
pqScriptDtl.setValue(pqScriptDtl.getChagValue() * volt);
}
if (CUR.equals(pqScriptDtl.getValueType())) {
pqScriptDtl.setValue(pqScriptDtl.getChagValue() * curr);
}
}
}
return pqScriptDtls;
}
/**
* @param dtlsList 检测集合
* @param dtlsList 其他类型检测集合(谐波,间谐波等)
* @param harm 谐波
* @param harm 间谐波
* @param code U,I
* @param channelListDTOS 通道信息
* @param channelListDTOS 通道信息
* @Description: 通道信息组装
* @Author: wr
* @Date: 2024/12/16 15:51
*/
private static void issueAdd(List<PqScriptDtls> dtlsList,
List<PqScriptDtls> dtlsOtherList,
String harm,
String inHarm,
String code,
List<SourceIssue.ChannelListDTO> channelListDTOS) {
for (PqScriptDtls dtls : dtlsList) {
SourceIssue.ChannelListDTO channelListDTO = new SourceIssue.ChannelListDTO();
channelListDTO.setChannelFlag(true);
channelListDTO.setHarmFlag(false);
channelListDTO.setInHarmFlag(false);
channelListDTO.setDipFlag(false);
channelListDTO.setFlickerFlag(false);
channelListDTO.setChannelType(code + dtls.getPhase().toLowerCase());
channelListDTO.setFAmp(dtls.getValue());
channelListDTO.setFPhase(dtls.getAngle());
channelListDTO.setHarmList(new ArrayList<>());
channelListDTO.setInharmList(new ArrayList<>());
//暂态数据
SourceIssue.ChannelListDTO.DipDataDTO dipDataDTO = new SourceIssue.ChannelListDTO.DipDataDTO();
dipDataDTO.setFTransValue(0.0f);
dipDataDTO.setFPreTime(0.0f);
dipDataDTO.setFRampIn(0.001f);
dipDataDTO.setFRetainTime(0.0f);
dipDataDTO.setFRampOut(0.001f);
dipDataDTO.setFAfterTime(0.0f);
channelListDTO.setDipData(dipDataDTO);
//闪变数据
SourceIssue.ChannelListDTO.FlickerDataDTO flickerDataDTO = new SourceIssue.ChannelListDTO.FlickerDataDTO();
flickerDataDTO.setWaveFluType(null);
flickerDataDTO.setWaveType(null);
flickerDataDTO.setFDutyCycle(0.0f);
flickerDataDTO.setFChagFre(0.0f);
flickerDataDTO.setFChagValue(0.0f);
channelListDTO.setFlickerData(flickerDataDTO);
if (CollUtil.isNotEmpty(dtlsOtherList)) {
List<PqScriptDtls> phaseList = dtlsOtherList.stream().filter(x -> dtls.getPhase().equals(x.getPhase()))
.sorted(Comparator.comparing(PqScriptDtls::getHarmNum))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(phaseList)) {
//处理谐波类型
List<PqScriptDtls> harmList = phaseList.stream().filter(x -> harm.equals(x.getValueType()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(harmList)) {
channelListDTO.setHarmList(getHarmModels(harmList));
channelListDTO.setHarmFlag(true);
}
//处理间谐波电压
List<PqScriptDtls> inHarmList = phaseList.stream().filter(x -> inHarm.equals(x.getValueType()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(inHarmList)) {
channelListDTO.setInharmList(getInHarmModels(inHarmList));
channelListDTO.setInHarmFlag(true);
}
//处理暂态数据
List<PqScriptDtls> dipList = phaseList.stream().filter(x -> DIP.equals(x.getValueType()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(dipList)) {
PqScriptDtls dip = dipList.get(0);
dipDataDTO.setFTransValue(dip.getTransValue());
dipDataDTO.setFPreTime(0.0f);
dipDataDTO.setFRampIn(0.001f);
dipDataDTO.setFRetainTime(0.0f);
dipDataDTO.setFRampOut(0.001f);
dipDataDTO.setFAfterTime(0.0f);
channelListDTO.setDipFlag(true);
channelListDTO.setDipData(dipDataDTO);
}
//处理闪变数据
List<PqScriptDtls> flickeRList = phaseList.stream().filter(x -> FLICKER.equals(x.getValueType()))
.collect(Collectors.toList());
if (CollUtil.isNotEmpty(flickeRList)) {
PqScriptDtls flicke = flickeRList.get(0);
flickerDataDTO.setWaveFluType(null);
flickerDataDTO.setWaveType(null);
flickerDataDTO.setFDutyCycle(0.0f);
flickerDataDTO.setFChagFre(0.0f);
flickerDataDTO.setFChagValue(0.0f);
channelListDTO.setFlickerFlag(true);
channelListDTO.setFlickerData(flickerDataDTO);
}
}
}
channelListDTOS.add(channelListDTO);
}
}
/**
* 处理谐波信息
*
* @param phaseHarmVList
* @return
*/
private static List<SourceIssue.ChannelListDTO.HarmModel> getHarmModels(List<PqScriptDtls> phaseHarmVList) {
List<SourceIssue.ChannelListDTO.HarmModel> info = new ArrayList<>();
SourceIssue.ChannelListDTO.HarmModel harmModel;
for (PqScriptDtls pqScriptDtls : phaseHarmVList) {
harmModel = new SourceIssue.ChannelListDTO.HarmModel();
harmModel.setHarm(pqScriptDtls.getHarmNum());
harmModel.setFApm(pqScriptDtls.getValue());
harmModel.setFPhase(pqScriptDtls.getAngle());
info.add(harmModel);
}
return info;
}
/**
* 处理间谐波谐波信息
*
* @param phaseHarmVList
* @return
*/
private static List<SourceIssue.ChannelListDTO.InharmModel> getInHarmModels(List<PqScriptDtls> phaseHarmVList) {
List<SourceIssue.ChannelListDTO.InharmModel> info = new ArrayList<>();
SourceIssue.ChannelListDTO.InharmModel inHarmModel;
for (PqScriptDtls pqScriptDtls : phaseHarmVList) {
inHarmModel = new SourceIssue.ChannelListDTO.InharmModel();
inHarmModel.setInharm(pqScriptDtls.getHarmNum());
inHarmModel.setFApm(pqScriptDtls.getValue());
inHarmModel.setFPhase(pqScriptDtls.getChagValue());
info.add(inHarmModel);
}
return info;
}
} }

View File

@@ -0,0 +1,54 @@
package com.njcn.gather.device.source.pojo.po;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.List;
/**
* @author caozehui
* @data 2024-12-09
*/
@Data
public class SourceInitialize {
@JSONField(ordinal = 1)
private String sourceId;
@JSONField(ordinal = 2)
private String sourceType;
@JSONField(ordinal = 4)
private String sourceDesc;
@JSONField(ordinal = 3)
private List<Initialize> sourceParamList;
@Data
public static class Initialize {
@JSONField(serialize = false)
private String id;
@JSONField(serialize = false)
private String pId;
@JSONField(ordinal = 1)
private String type;
@JSONField(ordinal = 2)
private String desc;
@JSONField(ordinal =4)
private String value;
@JSONField(serialize = false)
private Integer sort;
@JSONField(ordinal = 3)
private List<Initialize> children;
}
}

View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.gather.device.source.pojo.param.PqSourceParam; import com.njcn.gather.device.source.pojo.param.PqSourceParam;
import com.njcn.gather.device.source.pojo.po.PqSource; import com.njcn.gather.device.source.pojo.po.PqSource;
import com.njcn.gather.device.source.pojo.po.SourceInitialize;
import com.njcn.gather.device.source.pojo.po.SourceParam; import com.njcn.gather.device.source.pojo.po.SourceParam;
import java.util.List; import java.util.List;
@@ -71,6 +72,15 @@ public interface IPqSourceService extends IService<PqSource> {
*/ */
List<SourceParam> getSourceParam(String sourceId); List<SourceParam> getSourceParam(String sourceId);
/**
* 根据源参数组装源初始化参数
*
* @param sourceId
* @return
*/
SourceInitialize getSourceInitializeParam(String sourceId);
/** /**
* 根据名称获取检测源Id列表 * 根据名称获取检测源Id列表
* *

View File

@@ -1,6 +1,7 @@
package com.njcn.gather.device.source.service.impl; package com.njcn.gather.device.source.service.impl;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray; import cn.hutool.json.JSONArray;
@@ -14,6 +15,7 @@ import com.njcn.gather.device.pojo.enums.DevResponseEnum;
import com.njcn.gather.device.source.mapper.PqSourceMapper; import com.njcn.gather.device.source.mapper.PqSourceMapper;
import com.njcn.gather.device.source.pojo.param.PqSourceParam; import com.njcn.gather.device.source.pojo.param.PqSourceParam;
import com.njcn.gather.device.source.pojo.po.PqSource; import com.njcn.gather.device.source.pojo.po.PqSource;
import com.njcn.gather.device.source.pojo.po.SourceInitialize;
import com.njcn.gather.device.source.pojo.po.SourceParam; import com.njcn.gather.device.source.pojo.po.SourceParam;
import com.njcn.gather.device.source.service.IPqSourceService; import com.njcn.gather.device.source.service.IPqSourceService;
import com.njcn.gather.system.dictionary.pojo.po.DictData; import com.njcn.gather.system.dictionary.pojo.po.DictData;
@@ -23,10 +25,7 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Comparator; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -111,6 +110,32 @@ public class PqSourceServiceImpl extends ServiceImpl<PqSourceMapper, PqSource> i
return null; return null;
} }
@Override
public SourceInitialize getSourceInitializeParam(String sourceId) {
PqSource pqSource = this.lambdaQuery().eq(PqSource::getId, sourceId).eq(PqSource::getState, DataStateEnum.ENABLE.getCode()).one();
if (ObjectUtil.isNotNull(pqSource)) {
String parameter = pqSource.getParameter();
if (StrUtil.isNotBlank(parameter)) {
List<SourceInitialize.Initialize> list = new JSONArray(parameter).toList(SourceInitialize.Initialize.class);
List<SourceInitialize.Initialize> sourceParams = list.stream().filter(p -> p.getPId().equals(CommonEnum.FATHER_ID.getValue()))
.peek(p -> p.setChildren(getInitializeChildren(p, list)))
.sorted(Comparator.comparingInt(SourceInitialize.Initialize::getSort))
.collect(Collectors.toList());
if(CollUtil.isNotEmpty(sourceParams)){
SourceInitialize initialize=new SourceInitialize();
SourceInitialize.Initialize source = sourceParams.get(0);
initialize.setSourceId(source.getValue());
initialize.setSourceType(source.getType());
initialize.setSourceDesc(source.getDesc());
initialize.setSourceParamList(source.getChildren());
return initialize;
}
return null;
}
}
return null;
}
@Override @Override
public List<String> listPqSourceIdByName(String[] sourceNames) { public List<String> listPqSourceIdByName(String[] sourceNames) {
return this.lambdaQuery().in(PqSource::getName, sourceNames).eq(PqSource::getState, DataStateEnum.ENABLE.getCode()).list().stream().map(PqSource::getId).collect(Collectors.toList()); return this.lambdaQuery().in(PqSource::getName, sourceNames).eq(PqSource::getState, DataStateEnum.ENABLE.getCode()).list().stream().map(PqSource::getId).collect(Collectors.toList());
@@ -124,6 +149,14 @@ public class PqSourceServiceImpl extends ServiceImpl<PqSourceMapper, PqSource> i
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
private List<SourceInitialize.Initialize> getInitializeChildren(SourceInitialize.Initialize current, List<SourceInitialize.Initialize> list) {
return list.stream()
.filter(p -> p.getPId().equals(current.getId()))
.peek(p -> p.setChildren(getInitializeChildren(p, list)))
.sorted(Comparator.comparingInt(SourceInitialize.Initialize::getSort))
.collect(Collectors.toList());
}
// private List<SourceParam> filterTree(List<SourceParam> tree, String keyword) { // private List<SourceParam> filterTree(List<SourceParam> tree, String keyword) {
// if (CollectionUtils.isEmpty(tree) || StrUtil.isBlank(keyword)) { // if (CollectionUtils.isEmpty(tree) || StrUtil.isBlank(keyword)) {
// return tree; // return tree;

View File

@@ -0,0 +1,48 @@
package com.njcn.gather.system.dictionary.pojo.enums;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
/**
* @author caozehui
* @data 2024-12-12
*/
@Getter
public enum DictDataEnum {
/**
* 计划模式
*/
DIGITAL("数字式", "Digital"),
SIMULATE("模拟式", "Simulate"),
CONTRAST("比对式", "Contrast"),;
private final String name;
private final String code;
DictDataEnum(String name, String code) {
this.name = name;
this.code = code;
}
public static String getMsgByValue(Integer name) {
for (DictDataEnum state : DictDataEnum.values()) {
if (state.getName().equals(name)) {
return state.getCode();
}
}
return null;
}
public static DictDataEnum getDictDataEnumByCode(String code) {
for (DictDataEnum steadyIndicatorEnum : DictDataEnum.values()) {
if (StringUtils.equals(code, steadyIndicatorEnum.getCode())) {
return steadyIndicatorEnum;
}
}
return null;
}
}