app功能合并

This commit is contained in:
xy
2026-03-25 13:33:47 +08:00
parent fc7694a1db
commit 720afd42df
127 changed files with 5356 additions and 1346 deletions

View File

@@ -0,0 +1,96 @@
package com.njcn.csharmonic.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.pojo.dto.LineParamDTO;
import com.njcn.csharmonic.pojo.po.CsAlarm;
import com.njcn.csharmonic.pojo.vo.AlarmVO;
import com.njcn.csharmonic.service.ICsAlarmService;
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.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author xy
* @since 2026-03-16
*/
@Slf4j
@RestController
@RequestMapping("/csAlarm")
@Api(tags = "运行告警事件")
@AllArgsConstructor
public class CsAlarmController extends BaseController {
private final ICsAlarmService csAlarmService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryAlarmList")
@ApiOperation("运行告警事件列表(app)")
@ApiImplicitParam(name = "param", value = "事件查询参数", required = true)
public HttpResult<List<AlarmVO>> queryAlarmList(@RequestBody LineParamDTO param) {
String methodDescribe = getMethodDescribe("queryAlarmList");
List<AlarmVO> result = csAlarmService.queryAlarmList(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryAlarmDetail")
@ApiOperation("运行告警事件详情(app)")
@ApiImplicitParam(name = "param", value = "事件查询参数", required = true)
public HttpResult<List<AlarmVO.AlarmDetail>> queryAlarmDetail(@RequestBody LineParamDTO.DevParamDTO param) {
String methodDescribe = getMethodDescribe("queryAlarmDetail");
List<AlarmVO.AlarmDetail> result = csAlarmService.queryAlarmDetail(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/addList")
@ApiOperation("批量写入数据")
@ApiImplicitParam(name = "list", value = "参数", required = true)
public HttpResult<Boolean> addList(@RequestBody List<CsAlarm> list) {
String methodDescribe = getMethodDescribe("addList");
boolean result = csAlarmService.saveOrUpdateBatch(list);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryListByTime")
@ApiOperation("按日期查询数据")
@ApiImplicitParam(name = "time", value = "时间", required = true)
public HttpResult<List<CsAlarm>> queryListByTime(@RequestParam String time) {
String methodDescribe = getMethodDescribe("queryListByTime");
LambdaQueryWrapper<CsAlarm> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CsAlarm::getTime, time);
List<CsAlarm> list = csAlarmService.list(wrapper);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/deleteListByTime")
@ApiOperation("按日期删除数据")
@ApiImplicitParam(name = "time", value = "时间", required = true)
public HttpResult<Boolean> deleteListByTime(@RequestParam String time) {
String methodDescribe = getMethodDescribe("deleteListByTime");
LambdaQueryWrapper<CsAlarm> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CsAlarm::getTime, time);
boolean result = csAlarmService.remove(wrapper);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -176,5 +176,25 @@ public class CsEventController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getDevAlarmList")
@ApiOperation("获取设备运行告警事件")
@ApiImplicitParam(name = "param", value = "事件信息", required = true)
public HttpResult<List<CsEventPO>> getDevAlarmList(@RequestBody CsEventUserQueryParam param) {
String methodDescribe = getMethodDescribe("getDevAlarmList");
List<CsEventPO> list = csEventPOService.getDevAlarmList(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getEventByIdList")
@ApiOperation("根据事件id获取事件详情")
@ApiImplicitParam(name = "list", value = "id集合", required = true)
public HttpResult<List<CsEventPO>> getEventByIdList(@RequestBody List<String> list) {
String methodDescribe = getMethodDescribe("getEventByIdList");
List<CsEventPO> result = csEventPOService.listByIds(list);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -0,0 +1,97 @@
package com.njcn.csharmonic.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.pojo.dto.LineParamDTO;
import com.njcn.csharmonic.pojo.po.CsHarmonic;
import com.njcn.csharmonic.pojo.vo.HarmonicDetailVO;
import com.njcn.csharmonic.pojo.vo.HarmonicVO;
import com.njcn.csharmonic.service.ICsHarmonicService;
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.web.bind.annotation.*;
import java.util.List;
/**
* <p>
* 前端控制器
* </p>
*
* @author xy
* @since 2026-03-13
*/
@Slf4j
@RestController
@RequestMapping("/csHarmonic")
@Api(tags = "稳态事件")
@AllArgsConstructor
public class CsHarmonicController extends BaseController {
private final ICsHarmonicService csHarmonicService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryHarmonicList")
@ApiOperation("稳态事件列表(app)")
@ApiImplicitParam(name = "param", value = "暂降事件查询参数", required = true)
public HttpResult<HarmonicVO> queryHarmonicList(@RequestBody LineParamDTO param) {
String methodDescribe = getMethodDescribe("queryHarmonicList");
HarmonicVO vo = csHarmonicService.queryAppList(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryHarmonicDetail")
@ApiOperation("稳态事件详情(app)")
@ApiImplicitParam(name = "param", value = "暂降事件查询参数", required = true)
public HttpResult<List<HarmonicDetailVO>> queryHarmonicDetail(@RequestBody LineParamDTO param) {
String methodDescribe = getMethodDescribe("queryHarmonicDetail");
List<HarmonicDetailVO> vo = csHarmonicService.queryHarmonicDetail(param);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/addList")
@ApiOperation("批量写入数据")
@ApiImplicitParam(name = "list", value = "暂降事件查询参数", required = true)
public HttpResult<Boolean> addList(@RequestBody List<CsHarmonic> list) {
String methodDescribe = getMethodDescribe("addList");
boolean result = csHarmonicService.saveOrUpdateBatch(list);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryListByTime")
@ApiOperation("按日期查询数据")
@ApiImplicitParam(name = "time", value = "时间", required = true)
public HttpResult<List<CsHarmonic>> queryListByTime(@RequestParam String time) {
String methodDescribe = getMethodDescribe("queryListByTime");
LambdaQueryWrapper<CsHarmonic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CsHarmonic::getTime, time);
List<CsHarmonic> list = csHarmonicService.list(wrapper);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/deleteListByTime")
@ApiOperation("按日期删除数据")
@ApiImplicitParam(name = "time", value = "时间", required = true)
public HttpResult<Boolean> deleteListByTime(@RequestParam String time) {
String methodDescribe = getMethodDescribe("deleteListByTime");
LambdaQueryWrapper<CsHarmonic> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(CsHarmonic::getTime, time);
boolean result = csHarmonicService.remove(wrapper);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -26,6 +26,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.InputStream;
import java.util.List;
/**
@@ -44,9 +45,6 @@ public class CustomReportController extends BaseController {
private final CustomReportService customReportService;
/**
* 替换报表数据并返回
* @author qijian

View File

@@ -1,5 +1,6 @@
package com.njcn.csharmonic.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
@@ -10,6 +11,7 @@ import com.njcn.csharmonic.param.CldWarnParam;
import com.njcn.csharmonic.param.CsEventUserQueryPage;
import com.njcn.csharmonic.param.CsEventUserQueryParam;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
import com.njcn.csharmonic.service.CsEventUserPOService;
import com.njcn.web.controller.BaseController;
@@ -98,4 +100,24 @@ public class EventUserController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/addUserEventList")
@ApiOperation("新增数据")
public HttpResult<Boolean> addUserEventList(@RequestBody List<CsEventUserPO> list) {
String methodDescribe = getMethodDescribe("addUserEventList");
Boolean result = csEventUserPOService.saveBatch(list);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/deleteByIds")
@ApiOperation("根据id删除数据")
public HttpResult<Boolean> deleteByIds(@RequestBody List<String> eventList) {
String methodDescribe = getMethodDescribe("deleteByIds");
LambdaQueryWrapper<CsEventUserPO> wrapper = new LambdaQueryWrapper<>();
wrapper.in(CsEventUserPO::getEventId, eventList);
Boolean result = csEventUserPOService.remove(wrapper);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -0,0 +1,42 @@
package com.njcn.csharmonic.controller;
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.pojo.vo.EngineeringHomePageVO;
import com.njcn.csharmonic.service.HomePageService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @author xy
*/
@Slf4j
@RestController
@RequestMapping("/homePage")
@Api(tags = "app首页")
@AllArgsConstructor
public class HomePageController extends BaseController {
private final HomePageService homePageService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/getEngineeringHomePage")
@ApiOperation("工程用户首页")
public HttpResult<List<EngineeringHomePageVO>> getEngineeringHomePage(){
String methodDescribe = getMethodDescribe("getEngineeringHomePage");
List<EngineeringHomePageVO> result = homePageService.getEngineeringHomePage();
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
}
}

View File

@@ -13,9 +13,9 @@ import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csharmonic.pojo.param.PqSensitiveUserParam;
import com.njcn.csharmonic.pojo.po.PqSensitiveUser;
import com.njcn.csharmonic.pojo.vo.PqSensitiveUserVo;
import com.njcn.csharmonic.service.IPqSensitiveUserService;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.web.controller.BaseController;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;

View File

@@ -83,7 +83,7 @@ public class MqttMessageHandler {
public void responseRtData(String topic, @NamedValue("pageId") String pageId, MqttMessage message, @Payload String payload) {
List<CsRtDataVO> list = lineTargetService.getLineData(pageId);
Gson gson = new Gson();
publisher.send("/zl/rtData/" + pageId, gson.toJson(list), 1, false);
publisher.send("/zl/rtData/" + pageId, gson.toJson(list), 1, false);
}
@MqttSubscribe(value = "/zl/askTemperData/{devId}", qos = 1)

View File

@@ -0,0 +1,16 @@
package com.njcn.csharmonic.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.csharmonic.pojo.po.CsAlarm;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xy
* @since 2026-03-16
*/
public interface CsAlarmMapper extends BaseMapper<CsAlarm> {
}

View File

@@ -4,11 +4,13 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.csharmonic.param.CsEventUserQueryPage;
import com.njcn.csharmonic.param.CsEventUserQueryParam;
import com.njcn.csharmonic.pojo.dto.UnReadEventDto;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
*
@@ -21,6 +23,8 @@ import java.util.List;
public interface CsEventUserPOMapper extends BaseMapper<CsEventUserPO> {
Integer queryEventCount(@Param("csEventUserQueryParam") CsEventUserQueryParam csEventUserQueryParam);
List<UnReadEventDto> queryEngineeringEventCount(@Param("userIndex") String userIndex);
List<EventDetailVO> queryUserEventList(@Param("csEventUserQueryParam") CsEventUserQueryParam csEventUserQueryParam, @Param("devIds") List<String> devIds, @Param("flag") Boolean flag);
Page<EventDetailVO> queryEventpage(Page<EventDetailVO> returnpage, @Param("csEventUserQueryPage") CsEventUserQueryPage csEventUserQueryPage, @Param("devIds") List<String> devIds, @Param("flag") Boolean flag);

View File

@@ -0,0 +1,16 @@
package com.njcn.csharmonic.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.csharmonic.pojo.po.CsHarmonic;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xy
* @since 2026-03-13
*/
public interface CsHarmonicMapper extends BaseMapper<CsHarmonic> {
}

View File

@@ -1,16 +1,16 @@
package com.njcn.csharmonic.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.csharmonic.pojo.po.PqSensitiveUser;
/**
* <p>
* Mapper 接口
* </p>
*
* @author xy
* @since 2025-11-17
*/
public interface PqSensitiveUserMapper extends BaseMapper<PqSensitiveUser> {
}
//package com.njcn.csharmonic.mapper;
//
//import com.baomidou.mybatisplus.core.mapper.BaseMapper;
//import com.njcn.csharmonic.pojo.po.PqSensitiveUser;
//
///**
// * <p>
// * Mapper 接口
// * </p>
// *
// * @author xy
// * @since 2025-11-17
// */
//public interface PqSensitiveUserMapper extends BaseMapper<PqSensitiveUser> {
//
//}

View File

@@ -28,6 +28,19 @@
</select>
<select id="queryEngineeringEventCount" resultType="com.njcn.csharmonic.pojo.dto.UnReadEventDto">
SELECT
t2.device_id AS deviceId,
COUNT(DISTINCT event_id) AS count
FROM
cs_event_user t1 LEFT JOIN cs_event t2 ON t1.event_id = t2.id
WHERE
t1.`status` = 0
AND t2.type IN (0, 1)
AND t1.user_id = #{userIndex}
GROUP BY t2.device_id
</select>
<select id="queryUserEventList" resultType="com.njcn.csharmonic.pojo.vo.EventDetailVO">
select DISTINCT a.event_id id,
<if test="flag">
@@ -83,7 +96,7 @@
1 status,
</if>
b.device_id deviceId,b.line_id lineId,b.code code,
b.start_time startTime,b.tag tag ,b.wave_path wavePath,b.instant_pics,b.rms_pics , b.type type,b.level level,b.location location,d.name lineName
b.start_time startTime, b.amplitude evtParamVVaDepth,b.persist_time evtParamTm,b.tag tag ,b.wave_path wavePath,b.instant_pics,b.rms_pics , b.type type,b.level level,b.location location,d.name lineName
from cs_event_user a inner join cs_event b on a.event_id=b.id inner join cs_equipment_delivery c on b.device_id=c.id inner join cs_line d on d.device_id=b.device_id and d.clDid=b.cl_did where 1=1
and b.process=c.process
<if test="csEventUserQueryPage!=null and csEventUserQueryPage.endTime != null and csEventUserQueryPage.endTime !=''">
@@ -118,7 +131,22 @@
<if test="csEventUserQueryPage!=null and csEventUserQueryPage.userId != null and csEventUserQueryPage.userId !=''">
and a.user_id=#{ csEventUserQueryPage.userId}
</if>
order by b.start_time desc
<if test="csEventUserQueryPage!=null and csEventUserQueryPage.sortField != null">
<choose>
<when test="csEventUserQueryPage.sortField == 0">
order by b.start_time desc
</when>
<when test="csEventUserQueryPage.sortField == 1">
order by b.amplitude desc
</when>
<when test="csEventUserQueryPage.sortField == 2">
order by b.persist_time desc
</when>
<otherwise>
order by b.start_time desc
</otherwise>
</choose>
</if>
</select>
<select id="queryEventPageWeb" resultType="com.njcn.csharmonic.pojo.vo.EventDetailVO">

View File

@@ -71,4 +71,10 @@ public interface CsEventPOService extends IService<CsEventPO>{
List<EventStatisticsVo> getEventStatistics(CsEventUserQueryParam param);
List<CsWarnDescVO> getEventDesc(List<String> lineIdList);
//获取设备告警事件详情
List<CsEventPO> getEvents(List<String> idList);
List<CsEventPO> getDevAlarmList(CsEventUserQueryParam param);
}

View File

@@ -5,12 +5,14 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csharmonic.param.CldWarnParam;
import com.njcn.csharmonic.param.CsEventUserQueryPage;
import com.njcn.csharmonic.param.CsEventUserQueryParam;
import com.njcn.csharmonic.pojo.dto.UnReadEventDto;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
import com.njcn.web.pojo.param.BaseParam;
import java.util.List;
import java.util.Map;
/**
*
@@ -25,6 +27,8 @@ public interface CsEventUserPOService extends IService<CsEventUserPO>{
Integer queryEventCount(CsEventUserQueryParam csEventUserQueryParam);
List<UnReadEventDto> queryEngineeringEventCount(String userIndex);
List<EventDetailVO> queryUserEventList(CsEventUserQueryParam csEventUserQueryParam);
void updateStatus(CsEventUserQueryParam csEventUserQueryParam);
@@ -34,4 +38,13 @@ public interface CsEventUserPOService extends IService<CsEventUserPO>{
Page<EventDetailVO> queryEventPageWeb(CsEventUserQueryPage csEventUserQueryPage);
Page<CsEventPO> getFrontWarnInfo(CldWarnParam baseParam);
/**
* 查询用户事件列表
* @param userIndex
* @return
*/
List<CsEventUserPO> queryEventListByUserId(String userIndex,List<String> eventList);
}

View File

@@ -0,0 +1,14 @@
package com.njcn.csharmonic.service;
import com.njcn.csdevice.pojo.vo.EngineeringHomePageVO;
import java.util.List;
/**
* @author xy
*/
public interface HomePageService {
List<EngineeringHomePageVO> getEngineeringHomePage();
}

View File

@@ -0,0 +1,24 @@
package com.njcn.csharmonic.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csdevice.pojo.dto.LineParamDTO;
import com.njcn.csharmonic.pojo.po.CsAlarm;
import com.njcn.csharmonic.pojo.vo.AlarmVO;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author xy
* @since 2026-03-16
*/
public interface ICsAlarmService extends IService<CsAlarm> {
List<AlarmVO> queryAlarmList(LineParamDTO param);
List<AlarmVO.AlarmDetail> queryAlarmDetail(LineParamDTO.DevParamDTO param);
}

View File

@@ -0,0 +1,25 @@
package com.njcn.csharmonic.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csdevice.pojo.dto.LineParamDTO;
import com.njcn.csharmonic.pojo.po.CsHarmonic;
import com.njcn.csharmonic.pojo.vo.HarmonicDetailVO;
import com.njcn.csharmonic.pojo.vo.HarmonicVO;
import java.util.List;
/**
* <p>
* 服务类
* </p>
*
* @author xy
* @since 2026-03-13
*/
public interface ICsHarmonicService extends IService<CsHarmonic> {
HarmonicVO queryAppList(LineParamDTO param);
List<HarmonicDetailVO> queryHarmonicDetail(LineParamDTO param);
}

View File

@@ -3,8 +3,8 @@ package com.njcn.csharmonic.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csharmonic.pojo.param.PqSensitiveUserParam;
import com.njcn.csharmonic.pojo.po.PqSensitiveUser;
import com.njcn.csharmonic.pojo.vo.PqSensitiveUserVo;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.web.pojo.param.BaseParam;
import java.util.List;

View File

@@ -6,6 +6,7 @@ import com.njcn.csharmonic.pojo.param.LimitCalendarQueryParam;
import com.njcn.csharmonic.pojo.param.LimitExtentDayQueryParam;
import com.njcn.csharmonic.pojo.param.LimitExtentQueryParam;
import com.njcn.csharmonic.pojo.param.LimitProbabilityQueryParam;
import com.njcn.csharmonic.pojo.po.RStatLimitRateDPO;
import com.njcn.csharmonic.pojo.po.RStatLimitRateDetailDPO;
import com.njcn.csharmonic.pojo.vo.LimitCalendarVO;
import com.njcn.csharmonic.pojo.vo.LimitExtentVO;
@@ -27,4 +28,6 @@ public interface IRStatLimitRateDetailDService extends IService<RStatLimitRateDe
List<LimitProbabilityVO> limitProbabilityData(LimitProbabilityQueryParam param);
List<LimitTimeProbabilityVO> limitTimeProbabilityData(LimitProbabilityQueryParam param);
List<RStatLimitRateDetailDPO> monitorIdsGetLimitRateInfo(String date, List<String> monitorIds);
}

View File

@@ -0,0 +1,200 @@
package com.njcn.csharmonic.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.njcn.csdevice.api.CsCommTerminalFeignClient;
import com.njcn.csdevice.api.CsLedgerFeignClient;
import com.njcn.csdevice.pojo.dto.LineParamDTO;
import com.njcn.csdevice.pojo.po.CsLedger;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csharmonic.mapper.CsAlarmMapper;
import com.njcn.csharmonic.pojo.po.CsAlarm;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.vo.AlarmVO;
import com.njcn.csharmonic.service.CsEventPOService;
import com.njcn.csharmonic.service.CsEventUserPOService;
import com.njcn.csharmonic.service.ICsAlarmService;
import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.pojo.po.EleEpdPqd;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import static com.njcn.harmonic.utils.PublicDataUtils.calculateMonthEnd;
import static com.njcn.harmonic.utils.PublicDataUtils.calculateMonthStart;
/**
* <p>
* 服务实现类
* </p>
*
* @author xy
* @since 2026-03-16
*/
@Service
@AllArgsConstructor
public class CsAlarmServiceImpl extends ServiceImpl<CsAlarmMapper, CsAlarm> implements ICsAlarmService {
private final CsLedgerFeignClient csLedgerFeignClient;
private final CsEventUserPOService csEventUserPOService;
private final CsCommTerminalFeignClient csCommTerminalFeignClient;
private final CsEventPOService csEventPOService;
private final EpdFeignClient epdFeignClient;
@Override
public List<AlarmVO> queryAlarmList(LineParamDTO param) {
List<AlarmVO> result = new ArrayList<>();
List<CsLedger> lineLedger = csLedgerFeignClient.queryLine(param).getData();
if (CollectionUtil.isNotEmpty(lineLedger)) {
List<CsLedger> devLedger = new ArrayList<>();
//获取所有台账数据
List<CsLedgerVO> ledgers = csLedgerFeignClient.getAllLedger().getData();
ledgers.forEach(item->{
lineLedger.forEach(item2->{
if (Objects.equals(item.getId(), item2.getPid())) {
devLedger.add(item2);
}
});
});
if (CollectionUtil.isNotEmpty(devLedger)) {
List<String> ownerDevList = csCommTerminalFeignClient.getDevIdsByUser(RequestUtil.getUserIndex()).getData();
List<String> devList = devLedger.stream().map(CsLedger::getPid).collect(Collectors.toList());
// 取 ownerDevList 和 devList 的交集
if (CollectionUtil.isNotEmpty(ownerDevList)) {
devList = devList.stream()
.filter(ownerDevList::contains)
.distinct()
.collect(Collectors.toList());
} else {
devList = new ArrayList<>();
}
LambdaQueryWrapper<CsAlarm> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.ge(StrUtil.isNotBlank(param.getTime()), CsAlarm::getTime, calculateMonthStart(param.getTime()))
.le(StrUtil.isNotBlank(param.getTime()), CsAlarm::getTime, calculateMonthEnd(param.getTime()))
.orderByDesc(CsAlarm::getTime);
//先获取设备通讯数据
List<CsAlarm> list = list(queryWrapper);
if (CollectionUtil.isNotEmpty(list)) {
//获取用户推送事件
List<CsEventUserPO> userEvents = csEventUserPOService.queryEventListByUserId(RequestUtil.getUserIndex(), list.stream().map(CsAlarm::getId).collect(Collectors.toList()));
List<String> finalDevList = devList;
result = list.stream()
.map(alarm -> {
AlarmVO alarmVO = new AlarmVO();
alarmVO.setEventId(alarm.getId());
alarmVO.setDate(alarm.getTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
String devListStr = alarm.getDevList();
String[] devIds = devListStr.split(",");
List<String> matchedDevIds = Arrays.stream(devIds)
.filter(devId -> StrUtil.isNotBlank(devId.trim()))
.filter(finalDevList::contains)
.collect(Collectors.toList());
alarmVO.setWarnNums(matchedDevIds.size());
alarmVO.setDevIds(matchedDevIds);
alarmVO.setIsRead(userEvents.stream().filter(item1->item1.getEventId().equals(alarm.getId())).findFirst().map(CsEventUserPO::getStatus).orElse(0));
return alarmVO;
})
.filter(alarmVO -> alarmVO.getWarnNums() > 0)
.sorted((a1, a2) -> a2.getDate().compareTo(a1.getDate()))
.collect(Collectors.toList());
}
}
}
return result;
}
@Override
public List<AlarmVO.AlarmDetail> queryAlarmDetail(LineParamDTO.DevParamDTO param) {
List<AlarmVO.AlarmDetail> result = new ArrayList<>();
LambdaQueryWrapper<CsAlarm> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrUtil.isNotBlank(param.getTime()), CsAlarm::getTime, param.getTime());
CsAlarm alarm = getOne(queryWrapper);
if (ObjectUtil.isNotNull(alarm)) {
//获取所有台账数据
List<CsLedgerVO> ledgers = csLedgerFeignClient.getAllLedger().getData();
Map<String,CsLedgerVO> ledgerMap = ledgers.stream().collect(Collectors.toMap(CsLedgerVO::getId, item->item));
String devStr = alarm.getDevList();
String[] devIds = devStr.split(",");
for (int i = 0; i < devIds.length; i++) {
for (int i1 = 0; i1 < param.getDevList().size(); i1++) {
if (Objects.equals(devIds[i], param.getDevList().get(i1))) {
CsLedgerVO csLedgerVO = ledgerMap.get(devIds[i]);
AlarmVO.AlarmDetail alarmDetail = new AlarmVO.AlarmDetail();
alarmDetail.setEngineeringName(ledgerMap.get(csLedgerVO.getPids().split(",")[1]).getName());
alarmDetail.setProjectName(ledgerMap.get(csLedgerVO.getPids().split(",")[2]).getName());
alarmDetail.setDevName(csLedgerVO.getName());
if (ObjectUtil.isNotNull(alarm.getInterruptEvent())) {
String interruptEvent = alarm.getInterruptEvent();
List<List<String>> resultList = new ArrayList<>();
if (StrUtil.isNotBlank(interruptEvent)) {
try {
ObjectMapper objectMapper = new ObjectMapper();
resultList = objectMapper.readValue(interruptEvent, new TypeReference<List<List<String>>>() {});
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
List<String> interruptDetails = resultList.get(i);
if (CollectionUtil.isNotEmpty(interruptDetails)) {
alarmDetail.setInterruptCounts(interruptDetails.get(0).split("").length);
alarmDetail.setInterruptDetails(interruptDetails);
}
}
if (ObjectUtil.isNotNull(alarm.getAlarmEvent())) {
String alarmEvent = alarm.getAlarmEvent();
List<List<String>> resultList = new ArrayList<>();
if (StrUtil.isNotBlank(alarmEvent)) {
try {
ObjectMapper objectMapper = new ObjectMapper();
resultList = objectMapper.readValue(alarmEvent, new TypeReference<List<List<String>>>() {});
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
List<String> eventDetails = resultList.get(i);
if (CollectionUtil.isNotEmpty(eventDetails)) {
alarmDetail.setWarnCounts(eventDetails.size());
//获取告警时间详情
List<CsEventPO> csEventPOList = csEventPOService.getEvents(eventDetails);
alarmDetail.setWarnDetails(csEventPOList.stream()
.map(event -> {
AlarmVO.AlarmDetail.WarnDetail warnDetail = new AlarmVO.AlarmDetail.WarnDetail();
warnDetail.setWarnEventTime(event.getStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(event.getTag()).getData();
warnDetail.setWarnEventDesc(Objects.isNull(eleEpdPqd) ? event.getTag() : eleEpdPqd.getShowName());
return warnDetail;
}).collect(Collectors.toList())
);
alarmDetail.setWarnDetails(alarmDetail.getWarnDetails().stream().sorted((a1, a2) -> a2.getWarnEventTime().compareTo(a1.getWarnEventTime())).collect(Collectors.toList()));
}
}
result.add(alarmDetail);
}
}
}
}
return result;
}
}

View File

@@ -13,10 +13,12 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.access.pojo.dto.NoticeUserDto;
import com.njcn.access.utils.SendMessageUtil;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsDeviceUserFeignClient;
import com.njcn.csdevice.api.CsLedgerFeignClient;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
import com.njcn.csdevice.pojo.po.CsLinePO;
@@ -30,6 +32,7 @@ import com.njcn.csharmonic.param.CsEventUserQueryParam;
import com.njcn.csharmonic.param.DataParam;
import com.njcn.csharmonic.pojo.param.EventStatisticParam;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.vo.CsEventVO;
import com.njcn.csharmonic.pojo.vo.CsWarnDescVO;
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
@@ -59,6 +62,11 @@ import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.pojo.po.DictData;
import com.njcn.system.pojo.po.EleEpdPqd;
import com.njcn.system.pojo.po.EleEvtParm;
import com.njcn.user.api.AppInfoSetFeignClient;
import com.njcn.user.api.AppUserFeignClient;
import com.njcn.user.api.UserFeignClient;
import com.njcn.user.pojo.po.User;
import com.njcn.user.pojo.po.app.AppInfoSet;
import com.njcn.web.factory.PageFactory;
import com.njcn.web.utils.RequestUtil;
import lombok.RequiredArgsConstructor;
@@ -116,8 +124,13 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
private final MinIoUtils minIoUtils;
private final DicDataFeignClient dicDataFeignClient;
private final WlRmpEventDetailMapper wlRmpEventDetailMapper;
//private final CommonEventWaveAnalysisService commonEventWaveAnalysisService;
private final EquipmentFeignClient equipmentFeignClient;
private final AppUserFeignClient appUserFeignClient;
private final CsDeviceUserFeignClient csDeviceUserFeignClient;
private final UserFeignClient userFeignClient;
private final AppInfoSetFeignClient appInfoSetFeignClient;
private final CsLedgerFeignClient csLedgerFeignclient;
private final SendMessageUtil sendMessageUtil;
@Override
public List<EventDetailVO> queryEventList(CsEventUserQueryParam csEventUserQueryParam) {
@@ -407,6 +420,50 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
}
//同步数据到 r_mp_event_detail
insertEvent(uuid, param, time);
//根据设备获取主用户、子用户,设置事件未读数据
NoticeUserDto noticeUserDto = new NoticeUserDto();
NoticeUserDto.Payload payload = new NoticeUserDto.Payload();
List<CsEventUserPO> result = new ArrayList<>();
List<String> eventUser = getEventUser(po.getDeviceId(),true);
//针对用户记录未读信息和推送告警
eventUser.forEach(item->{
CsEventUserPO csEventUser = new CsEventUserPO();
csEventUser.setUserId(item);
csEventUser.setStatus(0);
csEventUser.setEventId(uuid);
result.add(csEventUser);
});
List<User> users = getSendUser(eventUser,0);
if (CollectionUtil.isNotEmpty(users)){
List<String> devCodeList = users.stream().map(User::getDevCode).distinct().collect(Collectors.toList());
noticeUserDto.setPushClientId(devCodeList);
noticeUserDto.setTitle("暂态事件");
}
//获取台账信息
String eventName = epdFeignClient.findByName(getTag(param.getEventType())).getData().getShowName();
DevDetailDTO devDetailDto = csLedgerFeignclient.queryDevDetail(po.getDeviceId()).getData();
String content = devDetailDto.getEngineeringName() + "-" + devDetailDto.getProjectName() + "-" + devDetailDto.getEquipmentName() + "" + time.format(DatePattern.NORM_DATETIME_MS_FORMATTER) + "发生" + eventName;
noticeUserDto.setContent(content);
payload.setType(0);
payload.setPath("/pages/message/message?type="+payload.getType());
noticeUserDto.setPayload(payload);
if (CollectionUtil.isNotEmpty(noticeUserDto.getPushClientId())) {
List<String> filteredList = noticeUserDto.getPushClientId().stream()
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(filteredList)) {
noticeUserDto.setPushClientId(filteredList);
sendMessageUtil.sendEventToUser(noticeUserDto);
}
}
//事件用户关系入库
if (CollectionUtil.isNotEmpty(result)){
csEventUserPOService.saveBatch(result);
}
} else {
if (StrUtil.isNotBlank(param.getWavePath())) {
//更新文件信息
@@ -422,6 +479,54 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
}
}
public List<String> getEventUser(String devId,boolean isAdmin) {
List<User> adminUser = appUserFeignClient.getAdminInfo().getData();
List<String> adminList = adminUser.stream().map(User::getId).collect(Collectors.toList());
if (isAdmin) {
List<String> list = csDeviceUserFeignClient.findUserById(devId).getData();
adminList.addAll(list);
}
return adminList;
}
/**
* 获取所有打开推送的用户信息
*/
public List<User> getSendUser(List<String> userList,Integer type) {
List<User> users = new ArrayList<>();
List<String> result = new ArrayList<>();
List<AppInfoSet> appInfoSet = appInfoSetFeignClient.getListById(userList).getData();
switch (type) {
case 0:
result = appInfoSet.stream()
.filter(person -> person.getEventInfo() == 1)
.map(AppInfoSet::getUserId).collect(Collectors.toList());
break;
case 1:
result = appInfoSet.stream()
.filter(person -> person.getHarmonicInfo() == 1)
.map(AppInfoSet::getUserId).collect(Collectors.toList());
break;
case 2:
result = appInfoSet.stream()
.filter(person -> person.getRunInfo() == 1)
.map(AppInfoSet::getUserId).collect(Collectors.toList());
break;
case 3:
result = appInfoSet.stream()
.filter(person -> person.getAlarmInfo() == 1)
.map(AppInfoSet::getUserId).collect(Collectors.toList());
break;
default:
break;
}
if (CollectionUtil.isNotEmpty(result)){
users = userFeignClient.appuserByIdList(result).getData();
}
return users;
}
public void insertEvent(String uuid, CldEventParam param, LocalDateTime time) {
RmpEventDetailPO rmpEventDetailPO = new RmpEventDetailPO();
rmpEventDetailPO.setEventId(uuid);
@@ -499,6 +604,23 @@ public class CsEventPOServiceImpl extends ServiceImpl<CsEventPOMapper, CsEventPO
return csWarnDescVOList;
}
@Override
public List<CsEventPO> getEvents(List<String> idList) {
LambdaQueryWrapper<CsEventPO> wrapper = new LambdaQueryWrapper<>();
wrapper.in(CsEventPO::getId,idList);
return this.list(wrapper);
}
@Override
public List<CsEventPO> getDevAlarmList(CsEventUserQueryParam param) {
LambdaQueryWrapper<CsEventPO> wrapper = new LambdaQueryWrapper<>();
wrapper.between(CsEventPO::getStartTime,param.getStartTime(),param.getEndTime())
.eq(CsEventPO::getType,3)
.in(CsEventPO::getLevel,Arrays.asList(1,2,3,6,7))
.in(CsEventPO::getDeviceId,param.getTarget());
return this.list(wrapper);
}
public String getTag(Integer type) {
String tag;
switch (type) {

View File

@@ -21,6 +21,7 @@ import com.njcn.csharmonic.mapper.CsEventUserPOMapper;
import com.njcn.csharmonic.param.CldWarnParam;
import com.njcn.csharmonic.param.CsEventUserQueryPage;
import com.njcn.csharmonic.param.CsEventUserQueryParam;
import com.njcn.csharmonic.pojo.dto.UnReadEventDto;
import com.njcn.csharmonic.pojo.po.CsEventPO;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.vo.EventDetailVO;
@@ -40,6 +41,8 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -71,6 +74,11 @@ public class CsEventUserPOServiceImpl extends ServiceImpl<CsEventUserPOMapper, C
return integer;
}
@Override
public List<UnReadEventDto> queryEngineeringEventCount(String userIndex) {
return this.getBaseMapper().queryEngineeringEventCount(userIndex);
}
@Override
public List<EventDetailVO> queryUserEventList(CsEventUserQueryParam csEventUserQueryParam) {
csEventUserQueryParam.setUserId(RequestUtil.getUserIndex());
@@ -236,139 +244,194 @@ public class CsEventUserPOServiceImpl extends ServiceImpl<CsEventUserPOMapper, C
if( Objects.equals(role, AppRoleEnum.APP_VIP_USER.getCode())&&Objects.equals(csEventUserQueryPage.getType(),"3")){
csEventUserQueryPage.setLevel("3");
}
// if( Objects.equals(role, AppRoleEnum.OPERATION_MANAGER.getCode())||Objects.equals(role, AppRoleEnum.ROOT.getCode())){
// csEventUserQueryPage.setUserId(null);
// flag = Boolean.FALSE;
// }
List<String> deviceId = new ArrayList<>();
List<CsLedgerVO> data = csLedgerFeignClient.getDeviceTree().getData();
// List<String> collect = data.stream().filter(temp->StringUtils.isEmpty(csEventUserQueryPage.getEngineeringid())||
// Objects.equals(temp.getId(), csEventUserQueryPage.getEngineeringid())).map(CsLedgerVO::getChildren).
// flatMap(Collection::stream).filter(
// temp->StringUtils.isEmpty(csEventUserQueryPage.getProjectId())||
// Objects.equals(temp.getId(), csEventUserQueryPage.getProjectId())
// ).
// map(CsLedgerVO::getChildren).
// flatMap(Collection::stream).filter(
// temp->StringUtils.isEmpty(csEventUserQueryPage.getDeviceId())||
// Objects.equals(temp.getId(), csEventUserQueryPage.getDeviceId())
// ).
// map(CsLedgerVO::getId).
// collect(Collectors.toList());
List<String> collect = data.stream().filter(temp->StringUtils.isEmpty(csEventUserQueryPage.getEngineeringid())||
Objects.equals(temp.getId(), csEventUserQueryPage.getEngineeringid()))
.map(CsLedgerVO::getChildren).flatMap(Collection::stream).filter(
temp->StringUtils.isEmpty(csEventUserQueryPage.getProjectId())||
Objects.equals(temp.getId(), csEventUserQueryPage.getProjectId())
).
map(CsLedgerVO::getChildren).flatMap(Collection::stream).filter(
temp->StringUtils.isEmpty(csEventUserQueryPage.getDeviceId())||
Objects.equals(temp.getId(), csEventUserQueryPage.getDeviceId())
).
map(CsLedgerVO::getChildren).flatMap(Collection::stream).filter(
temp->StringUtils.isEmpty(csEventUserQueryPage.getDeviceId())||
Objects.equals(temp.getId(), csEventUserQueryPage.getDeviceId())
).
map(CsLedgerVO::getId).
collect(Collectors.toList());
if (CollectionUtils.isEmpty(collect)){
List<CsLedgerVO> data = csLedgerFeignClient.lineTree().getData();
if (CollectionUtils.isEmpty(data)) {
return returnpage;
}
returnpage = this.getBaseMapper().queryEventpage(returnpage,csEventUserQueryPage,collect,flag);
// 获取第一层节点(根节点),从第二层开始才是真正的工程
List<CsLedgerVO> firstLevelNodes = new ArrayList<>();
for (CsLedgerVO rootNode : data) {
List<CsLedgerVO> children = rootNode.getChildren();
if (CollectionUtil.isNotEmpty(children)) {
firstLevelNodes.addAll(children);
}
}
returnpage.getRecords().forEach(temp->{
DevDetailDTO devDetail = csLedgerFeignClient.queryDevDetail(temp.getDeviceId()).getData();
temp.setEquipmentName(devDetail.getEquipmentName());
temp.setProjectId(devDetail.getProjectId());
temp.setProjectName(devDetail.getProjectName());
temp.setEngineeringid(devDetail.getEngineeringid());
temp.setEngineeringName(devDetail.getEngineeringName());
EleEpdPqd ele = epdFeignClient.findByName(temp.getTag()).getData();
temp.setShowName(ele.getShowName());
temp.setCode(ele.getDefaultValue());
if(Objects.equals(csEventUserQueryPage.getType(),"0")){
if (CollectionUtils.isEmpty(firstLevelNodes)) {
return returnpage;
}
List<EleEvtParm> data1 = eleEvtFeignClient.queryByPid(ele.getId()).getData();
List<EventDataSetDTO> eventDataSetDTOS = new ArrayList<>();
for (EleEvtParm eleEvtParm : data1) {
EventDataSetDTO eventDataSetDTO = new EventDataSetDTO();
BeanUtils.copyProperties(eleEvtParm,eventDataSetDTO);
if (Objects.equals(eventDataSetDTO.getName(),"Evt_Param_Position")) {
continue;
// eventDataSetDTO.setValue(Objects.equals(temp.getLocation(),"grid")?"电网侧":"负载侧");
}
EventDataSetDTO evtData = evtDataService.getEventDataSet("evt_data", temp.getId(), eleEvtParm.getName());
if (evtData == null) {
eventDataSetDTO.setValue("-");
}else {
eventDataSetDTO.setValue(Optional.ofNullable(evtData.getValue()).orElse("-"));
}
// if (Objects.equals(eventDataSetDTO.getName(),"Evt_Param_Position")) {
// eventDataSetDTO.setValue(Objects.equals(temp.getLocation(),"grid")?"电网侧":"负载侧");
// }
eventDataSetDTOS.add(eventDataSetDTO);
}
temp.setDataSet(eventDataSetDTOS);
List<EventDataSetDTO> evtParamVVaDepth = eventDataSetDTOS.stream().
filter(dataSetDTO -> Objects.equals(dataSetDTO.getName(), "Evt_Param_VVaDepth")).
collect(Collectors.toList());
if(CollectionUtil.isEmpty(evtParamVVaDepth)){
temp.setEvtParamVVaDepth("-");
}else {
temp.setEvtParamVVaDepth(evtParamVVaDepth.get(0).getValue()+(Objects.isNull(evtParamVVaDepth.get(0).getUnit())?"":evtParamVVaDepth.get(0).getUnit()));
}
List<EventDataSetDTO> evtParamPosition = eventDataSetDTOS.stream().
filter(dataSetDTO -> Objects.equals(dataSetDTO.getName(), "Evt_Param_Position")).
collect(Collectors.toList());
if(CollectionUtil.isEmpty(evtParamPosition)){
temp.setEvtParamPosition("-");
}else {
//temp.setEvtParamPosition(evtParamPosition.get(0).getValue()+(Objects.isNull(evtParamPosition.get(0).getUnit())?"":evtParamPosition.get(0).getUnit()));
temp.setEvtParamPosition(evtParamPosition.get(0).getValue());
}
if (Objects.equals(temp.getEvtParamPosition(),"-")) {
if (!Objects.isNull(temp.getLocation())) {
temp.setEvtParamPosition(Objects.equals(temp.getLocation(),"grid")?"电网侧":"负载侧");
}
}
List<EventDataSetDTO> evtParamTm = eventDataSetDTOS.stream().
filter(dataSetDTO -> Objects.equals(dataSetDTO.getName(), "Evt_Param_Tm")).
collect(Collectors.toList());
if(CollectionUtil.isEmpty(evtParamTm)){
temp.setEvtParamTm("-");
}else {
temp.setEvtParamTm(evtParamTm.get(0).getValue()+(Objects.isNull(evtParamTm.get(0).getUnit())?"":evtParamTm.get(0).getUnit()));
}
List<EventDataSetDTO> evtParamPhase = eventDataSetDTOS.stream().
filter(dataSetDTO -> Objects.equals(dataSetDTO.getName(), "Evt_Param_Phase")).
collect(Collectors.toList());
if(CollectionUtil.isEmpty(evtParamPhase)){
temp.setEvtParamPhase("-");
}else {
temp.setEvtParamPhase(evtParamPhase.get(0).getValue()+(Objects.isNull(evtParamPhase.get(0).getUnit())?"":evtParamPhase.get(0).getUnit()));
}
// 缓存查询条件到局部变量
String engineeringId = csEventUserQueryPage.getEngineeringid();
String projectId = csEventUserQueryPage.getProjectId();
String deviceId = csEventUserQueryPage.getDeviceId();
String lineId = csEventUserQueryPage.getLineId();
// 从第二层开始遍历:工程 -> 项目 -> 设备 -> 监测点
List<String> collect = new ArrayList<>();
for (CsLedgerVO engineering : firstLevelNodes) {
// 过滤工程
if (StringUtil.isNotBlank(engineeringId)
&& !Objects.equals(engineering.getId(), engineeringId)) {
continue;
}
});
List<CsLedgerVO> projects = engineering.getChildren();
if (CollectionUtils.isEmpty(projects)) {
continue;
}
for (CsLedgerVO project : projects) {
// 过滤项目
if (StringUtil.isNotBlank(projectId)
&& !Objects.equals(project.getId(), projectId)) {
continue;
}
List<CsLedgerVO> devices = project.getChildren();
if (CollectionUtils.isEmpty(devices)) {
continue;
}
for (CsLedgerVO device : devices) {
// 过滤设备
if (StringUtil.isNotBlank(deviceId)
&& !Objects.equals(device.getId(), deviceId)) {
continue;
}
// 如果传了监测点 ID需要进一步过滤
if (StringUtil.isNotBlank(lineId)) {
List<CsLedgerVO> lines = device.getChildren();
if (CollectionUtil.isNotEmpty(lines)) {
boolean hasLine = lines.stream()
.anyMatch(line -> Objects.equals(line.getId(), lineId));
if (hasLine) {
collect.add(device.getId());
}
}
} else {
// 没有传监测点 ID直接添加设备 ID
collect.add(device.getId());
}
}
}
}
if (CollectionUtils.isEmpty(collect)) {
return returnpage;
}
returnpage = this.getBaseMapper().queryEventpage(returnpage, csEventUserQueryPage, collect, flag);
// 先获取原始记录
List<EventDetailVO> originalRecords = returnpage.getRecords();
if (CollectionUtil.isNotEmpty(originalRecords)) {
// 过滤出满足 lineId 条件的记录
List<EventDetailVO> filteredRecords = new ArrayList<>();
for (EventDetailVO temp : originalRecords) {
// 如果没有传 lineId 或者 lineId 匹配,则处理该记录
if (StringUtil.isBlank(csEventUserQueryPage.getLineId())
|| Objects.equals(temp.getLineId(), csEventUserQueryPage.getLineId())) {
DevDetailDTO devDetail = csLedgerFeignClient.queryDevDetail(temp.getDeviceId()).getData();
temp.setEquipmentName(devDetail.getEquipmentName());
temp.setProjectId(devDetail.getProjectId());
temp.setProjectName(devDetail.getProjectName());
temp.setEngineeringid(devDetail.getEngineeringid());
temp.setEngineeringName(devDetail.getEngineeringName());
EleEpdPqd ele = epdFeignClient.findByName(temp.getTag()).getData();
temp.setShowName(Objects.isNull(ele) ? temp.getTag() : ele.getShowName());
temp.setCode(Objects.isNull(ele) ? null : ele.getDefaultValue());
if (Objects.equals(csEventUserQueryPage.getType(), "0")) {
List<EleEvtParm> data1 = eleEvtFeignClient.queryByPid(ele.getId()).getData();
List<EventDataSetDTO> eventDataSetDTOS = new ArrayList<>();
for (EleEvtParm eleEvtParm : data1) {
EventDataSetDTO eventDataSetDTO = new EventDataSetDTO();
BeanUtils.copyProperties(eleEvtParm, eventDataSetDTO);
if (Objects.equals(eventDataSetDTO.getName(), "Evt_Param_Position")) {
continue;
}
EventDataSetDTO evtData = evtDataService.getEventDataSet("evt_data", temp.getId(), eleEvtParm.getName());
if (evtData == null) {
eventDataSetDTO.setValue("-");
} else {
if (Objects.equals(eleEvtParm.getName(), "Evt_Param_VVaDepth") || Objects.equals(eleEvtParm.getName(), "Evt_Param_Tm")) {
BigDecimal bd = new BigDecimal(evtData.getValue());
bd = bd.setScale(2, RoundingMode.HALF_UP);
eventDataSetDTO.setValue(Optional.ofNullable(bd.toString()).orElse("-"));
} else {
eventDataSetDTO.setValue(Optional.ofNullable(evtData.getValue()).orElse("-"));
}
}
eventDataSetDTOS.add(eventDataSetDTO);
}
temp.setDataSet(eventDataSetDTOS);
List<EventDataSetDTO> evtParamVVaDepth = eventDataSetDTOS.stream()
.filter(dataSetDTO -> Objects.equals(dataSetDTO.getName(), "Evt_Param_VVaDepth"))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(evtParamVVaDepth)) {
temp.setEvtParamVVaDepth("-");
} else {
if (Objects.equals(evtParamVVaDepth.get(0).getValue(),"-")) {
temp.setEvtParamVVaDepth("-");
} else {
BigDecimal bd = new BigDecimal(evtParamVVaDepth.get(0).getValue());
bd = bd.setScale(2, RoundingMode.HALF_UP);
temp.setEvtParamVVaDepth(bd + (Objects.isNull(evtParamVVaDepth.get(0).getUnit()) ? "" : evtParamVVaDepth.get(0).getUnit()));
}
}
List<EventDataSetDTO> evtParamPosition = eventDataSetDTOS.stream()
.filter(dataSetDTO -> Objects.equals(dataSetDTO.getName(), "Evt_Param_Position"))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(evtParamPosition)) {
temp.setEvtParamPosition("-");
} else {
temp.setEvtParamPosition(evtParamPosition.get(0).getValue());
}
if (Objects.equals(temp.getEvtParamPosition(), "-")) {
if (!Objects.isNull(temp.getLocation())) {
temp.setEvtParamPosition(Objects.equals(temp.getLocation(), "grid") ? "电网侧" : "负载侧");
}
}
List<EventDataSetDTO> evtParamTm = eventDataSetDTOS.stream()
.filter(dataSetDTO -> Objects.equals(dataSetDTO.getName(), "Evt_Param_Tm"))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(evtParamTm)) {
temp.setEvtParamTm("-");
} else {
if (Objects.equals(evtParamTm.get(0).getValue(),"-")) {
temp.setEvtParamTm("-");
} else {
BigDecimal bd = new BigDecimal(evtParamTm.get(0).getValue());
bd = bd.setScale(2, RoundingMode.HALF_UP);
temp.setEvtParamTm(bd + (Objects.isNull(evtParamTm.get(0).getUnit()) ? "" : evtParamTm.get(0).getUnit()));
}
}
List<EventDataSetDTO> evtParamPhase = eventDataSetDTOS.stream()
.filter(dataSetDTO -> Objects.equals(dataSetDTO.getName(), "Evt_Param_Phase"))
.collect(Collectors.toList());
if (CollectionUtil.isEmpty(evtParamPhase)) {
temp.setEvtParamPhase("-");
} else {
temp.setEvtParamPhase(evtParamPhase.get(0).getValue()
+ (Objects.isNull(evtParamPhase.get(0).getUnit()) ? "" : evtParamPhase.get(0).getUnit()));
}
}
// 将处理后的记录添加到结果列表
filteredRecords.add(temp);
}
}
// 清空原来的记录,加入过滤后的记录
returnpage.setRecords(filteredRecords);
}
return returnpage;
}
@@ -557,4 +620,11 @@ public class CsEventUserPOServiceImpl extends ServiceImpl<CsEventUserPOMapper, C
}
return page;
}
@Override
public List<CsEventUserPO> queryEventListByUserId(String userIndex, List<String> eventList) {
LambdaQueryWrapper<CsEventUserPO> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(CsEventUserPO::getUserId, userIndex).in(CsEventUserPO::getEventId, eventList);
return baseMapper.selectList(queryWrapper);
}
}

View File

@@ -0,0 +1,339 @@
package com.njcn.csharmonic.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.njcn.csdevice.api.CsCommTerminalFeignClient;
import com.njcn.csdevice.api.CsLedgerFeignClient;
import com.njcn.csdevice.pojo.dto.LineParamDTO;
import com.njcn.csdevice.pojo.po.CsLedger;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csharmonic.mapper.CsHarmonicMapper;
import com.njcn.csharmonic.pojo.dto.PhaseData;
import com.njcn.csharmonic.pojo.po.CsEventUserPO;
import com.njcn.csharmonic.pojo.po.CsHarmonic;
import com.njcn.csharmonic.pojo.po.RStatLimitRateDetailDPO;
import com.njcn.csharmonic.pojo.vo.HarmonicDetailVO;
import com.njcn.csharmonic.pojo.vo.HarmonicVO;
import com.njcn.csharmonic.service.CsEventUserPOService;
import com.njcn.csharmonic.service.ICsHarmonicService;
import com.njcn.csharmonic.service.IRStatLimitRateDetailDService;
import com.njcn.harmonic.utils.PublicDataUtils;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import java.lang.reflect.Field;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
/**
* <p>
* 服务实现类
* </p>
*
* @author xy
* @since 2026-03-13
*/
@AllArgsConstructor
@Service
public class CsHarmonicServiceImpl extends ServiceImpl<CsHarmonicMapper, CsHarmonic> implements ICsHarmonicService {
private final CsLedgerFeignClient csLedgerFeignClient;
private final CsEventUserPOService csEventUserPOService;
private final IRStatLimitRateDetailDService rStatLimitRateDetailDService;
private final CsCommTerminalFeignClient csCommTerminalFeignClient;
@Override
public HarmonicVO queryAppList(LineParamDTO param) {
HarmonicVO vo = new HarmonicVO();
List<CsLedger> lineLedger = csLedgerFeignClient.queryLine(param).getData();
if (CollectionUtil.isNotEmpty(lineLedger)) {
List<String> lineIds = lineLedger.stream().map(CsLedger::getId).collect(Collectors.toList());
//根据用户获取设备数据权限
List<String> ownerList = csCommTerminalFeignClient.getLineIdsByUser(RequestUtil.getUserIndex()).getData();
List<String> combinedLineIds = new ArrayList<>();
if (CollectionUtil.isNotEmpty(ownerList)) {
combinedLineIds = lineIds.stream()
.filter(ownerList::contains)
.distinct()
.collect(Collectors.toList());
} else {
combinedLineIds = lineIds;
}
LambdaQueryWrapper<CsHarmonic> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.in(CsHarmonic::getLineId, combinedLineIds)
.ge(StrUtil.isNotBlank(param.getTime()), CsHarmonic::getTime, PublicDataUtils.calculateMonthStart(param.getTime()))
.le(StrUtil.isNotBlank(param.getTime()), CsHarmonic::getTime, PublicDataUtils.calculateMonthEnd(param.getTime()))
.orderByDesc(CsHarmonic::getTime);
List<CsHarmonic> list = list(queryWrapper);
if (CollectionUtil.isNotEmpty(list)) {
//获取所有台账数据
List<CsLedgerVO> ledgers = csLedgerFeignClient.getAllLedger().getData();
Map<String,CsLedgerVO> ledgerMap = ledgers.stream().collect(Collectors.toMap(CsLedgerVO::getId, item->item));
List<HarmonicVO.LineHarmonicDetail> lineHarmonicDetails = new ArrayList<>();
vo.setHarmonicNums(list.size());
//获取越限天数
Set<LocalDate> distinctTimes = list.stream().map(CsHarmonic::getTime).filter(Objects::nonNull).collect(Collectors.toSet());
int overDay = distinctTimes.size();
vo.setOverDays(overDay);
//获取监测点
Set<String> distinctLineIds = list.stream().map(CsHarmonic::getLineId).collect(Collectors.toSet());
int overLine = distinctLineIds.size();
vo.setOverLineNums(overLine);
//获取用户推送事件
List<CsEventUserPO> userEvents = csEventUserPOService.queryEventListByUserId(RequestUtil.getUserIndex(), list.stream().map(CsHarmonic::getId).collect(Collectors.toList()));
list.forEach(item->{
CsLedger ledger = lineLedger.stream().filter(item1->item1.getId().equals(item.getLineId())).findFirst().orElse(null);
HarmonicVO.LineHarmonicDetail lineHarmonicDetail = new HarmonicVO.LineHarmonicDetail();
lineHarmonicDetail.setEventId(item.getId());
lineHarmonicDetail.setEngineeringName(ledgerMap.get(ledger.getPids().split(",")[1]).getName());
lineHarmonicDetail.setProjectName(ledgerMap.get(ledger.getPids().split(",")[2]).getName());
lineHarmonicDetail.setDevName(ledgerMap.get(ledger.getPids().split(",")[3]).getName());
lineHarmonicDetail.setLineId(item.getLineId());
lineHarmonicDetail.setLineName(ledger.getName());
lineHarmonicDetail.setStatisticsDate(item.getTime());
lineHarmonicDetail.setOverLimitDesc(item.getTag());
lineHarmonicDetail.setIsRead(userEvents.stream().filter(item1->item1.getEventId().equals(item.getId())).findFirst().map(CsEventUserPO::getStatus).orElse(0));
lineHarmonicDetails.add(lineHarmonicDetail);
});
vo.setList(lineHarmonicDetails);
}
}
return vo;
}
@Override
public List<HarmonicDetailVO> queryHarmonicDetail(LineParamDTO param) {
List<HarmonicDetailVO> list = new ArrayList<>();
//先获取越限详细数据
List<RStatLimitRateDetailDPO> overData = rStatLimitRateDetailDService.monitorIdsGetLimitRateInfo(param.getTime(), Collections.singletonList(param.getLineId()));
//定义监测项配置:字段名 -> 名称前缀
Map<String, String> simpleFields = new LinkedHashMap<>();
simpleFields.put("freqDevOvertime", "频率偏差");
simpleFields.put("voltageDevOvertime", "电压偏差");
simpleFields.put("ubalanceOvertime", "三相电压不平衡度");
simpleFields.put("flickerOvertime", "闪变");
simpleFields.put("uaberranceOvertime", "电压总谐波畸变率");
simpleFields.put("iNegOvertime", "负序电流");
//根据数据组装
overData.forEach(item->{
// 处理简单字段
simpleFields.forEach((fieldName, targetName) -> {
String json = reflectGetValue(item, fieldName);
addHarmonicData(list, json, targetName);
});
// 处理谐波电压含有率 (2-25 次)
for (int i = 2; i <= 25; i++) {
String json = reflectGetValue(item, "uharm" + i + "Overtime");
addHarmonicData(list, json, i + "次谐波电压含有率");
}
// 处理谐波电流有效值 (2-25 次)
for (int i = 2; i <= 25; i++) {
String json = reflectGetValue(item, "iharm" + i + "Overtime");
addHarmonicData(list, json, i + "次谐波电流有效值");
}
// 处理间谐波电压含有率 (0.5-15.5 次)
for (int i = 1; i <= 16; i++) {
String json = reflectGetValue(item, "inuharm" + i + "Overtime");
addHarmonicData(list, json, (i-0.5) + "次间谐波电压含有率");
}
});
return list;
}
/**
* 添加谐波数据到列表
* @param list 结果列表
* @param jsonData JSON 数据
* @param targetName 监测项名称
*/
private void addHarmonicData(List<HarmonicDetailVO> list, String jsonData, String targetName) {
if (ObjectUtil.isNotNull(jsonData)) {
HarmonicDetailVO vo = new HarmonicDetailVO();
vo.setTargetName(targetName);
vo.setHarmDetailList(AnalyzeData(jsonData));
list.add(vo);
}
}
/**
* 使用反射获取对象的字段值
* @param obj 对象实例
* @param fieldName 字段名
* @return 字段值
*/
private String reflectGetValue(Object obj, String fieldName) {
try {
Field field = obj.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
Object value = field.get(obj);
return value == null ? null : value.toString();
} catch (Exception e) {
return null;
}
}
public List<HarmonicDetailVO.HarmDetail> AnalyzeData(String jsonString) {
List<HarmonicDetailVO.HarmDetail> result = new ArrayList<>();
ObjectMapper mapper = new ObjectMapper();
List<PhaseData> phaseDataList = null;
try {
phaseDataList = mapper.readValue(jsonString, new TypeReference<List<PhaseData>>() {});
// 合并数据
Map<String, Map<String, String>> mergedData = new TreeMap<>(new TimeComparator());
for (PhaseData phaseData : phaseDataList) {
String[] times = phaseData.time.split(",");
String[] values = phaseData.value.split(",");
for (int i = 0; i < times.length; i++) {
String time = times[i].trim();
mergedData.putIfAbsent(time, new HashMap<>());
mergedData.get(time).put(phaseData.phasic, values[i].trim());
}
}
// 构建所有详情列表
List<HarmonicDetailVO.HarmDetail> allDetails = new ArrayList<>();
for (Map.Entry<String, Map<String, String>> entry : mergedData.entrySet()) {
String time = entry.getKey();
Map<String, String> values = entry.getValue();
HarmonicDetailVO.HarmDetail detail = new HarmonicDetailVO.HarmDetail();
detail.setStatisticsTime(time);
detail.setDataA(formatValue(values.get("A")));
detail.setDataB(formatValue(values.get("B")));
detail.setDataC(formatValue(values.get("C")));
detail.setDataT(formatValue(values.get("T")));
detail.setValueType(phaseDataList.get(0).valueType);
detail.setOverLimitData(phaseDataList.get(0).overLimitValue);
detail.setHasT(values.containsKey("T"));
allDetails.add(detail);
}
// 选取最严重的 10 条记录(按 dataT 的绝对值排序,如果没有则取其他相)
List<HarmonicDetailVO.HarmDetail> top10Details = allDetails.stream()
.sorted((d1, d2) -> {
Double v1 = getNumericValue(d1);
Double v2 = getNumericValue(d2);
return Double.compare(Math.abs(v2), Math.abs(v1));
})
.limit(10)
.collect(Collectors.toList());
// 按时间排序后返回
result = top10Details.stream()
.sorted((d1, d2) -> {
String t1 = d1.getStatisticsTime();
String t2 = d2.getStatisticsTime();
if (t1 == null || t2 == null) {
return 0;
}
String[] parts1 = t1.split(":");
String[] parts2 = t2.split(":");
for (int i = 0; i < 3; i++) {
int cmp = Integer.compare(Integer.parseInt(parts1[i]), Integer.parseInt(parts2[i]));
if (cmp != 0) return cmp;
}
return 0;
})
.collect(Collectors.toList());
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return result;
}
/**
* 获取用于比较严重程度的数值
* @param detail 谐波详情
* @return 各相数据的绝对值之和
*/
private Double getNumericValue(HarmonicDetailVO.HarmDetail detail) {
double sum = 0.0;
// 累加 dataA
String dataA = detail.getDataA();
if (dataA != null && !"/".equals(dataA)) {
try {
sum += Math.abs(Double.parseDouble(dataA));
} catch (NumberFormatException e) {
// 忽略解析失败的数据
}
}
// 累加 dataB
String dataB = detail.getDataB();
if (dataB != null && !"/".equals(dataB)) {
try {
sum += Math.abs(Double.parseDouble(dataB));
} catch (NumberFormatException e) {
// 忽略解析失败的数据
}
}
// 累加 dataC
String dataC = detail.getDataC();
if (dataC != null && !"/".equals(dataC)) {
try {
sum += Math.abs(Double.parseDouble(dataC));
} catch (NumberFormatException e) {
// 忽略解析失败的数据
}
}
// 累加 dataT
String dataT = detail.getDataT();
if (dataT != null && !"/".equals(dataT)) {
try {
sum += Math.abs(Double.parseDouble(dataT));
} catch (NumberFormatException e) {
// 忽略解析失败的数据
}
}
return sum;
}
/**
* 格式化数值:有值则保留两位小数,无值则返回 /
* @param value 原始字符串值
* @return 格式化后的字符串
*/
private String formatValue(String value) {
if (value == null || value.trim().isEmpty() || "/".equals(value.trim())) {
return "/";
}
try {
DecimalFormat df = new DecimalFormat("0.00");
return df.format(Double.parseDouble(value));
} catch (NumberFormatException e) {
return "/";
}
}
static class TimeComparator implements Comparator<String> {
@Override
public int compare(String t1, String t2) {
String[] parts1 = t1.split(":");
String[] parts2 = t2.split(":");
for (int i = 0; i < 3; i++) {
int cmp = Integer.compare(Integer.parseInt(parts1[i]), Integer.parseInt(parts2[i]));
if (cmp != 0) return cmp;
}
return 0;
}
}
}

View File

@@ -0,0 +1,111 @@
package com.njcn.csharmonic.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import com.njcn.csdevice.api.CsLedgerFeignClient;
import com.njcn.csdevice.api.CsUserPinsFeignClient;
import com.njcn.csdevice.api.EngineeringFeignClient;
import com.njcn.csdevice.pojo.dto.DevDetailDTO;
import com.njcn.csdevice.pojo.param.CsEngineeringQueryParm;
import com.njcn.csdevice.pojo.po.CsUserPins;
import com.njcn.csdevice.pojo.vo.CsEngineeringVO;
import com.njcn.csdevice.pojo.vo.CsLedgerVO;
import com.njcn.csdevice.pojo.vo.EngineeringHomePageVO;
import com.njcn.csharmonic.pojo.dto.UnReadEventDto;
import com.njcn.csharmonic.service.CsEventUserPOService;
import com.njcn.csharmonic.service.HomePageService;
import com.njcn.web.utils.RequestUtil;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author xy
*/
@Service
@AllArgsConstructor
@Slf4j
public class HomePageServiceImpl implements HomePageService {
private final CsEventUserPOService csEventUserPOService;
private final EngineeringFeignClient engineeringFeignClient;
private final CsLedgerFeignClient csLedgerFeignClient;
private final CsUserPinsFeignClient csUserPinsFeignClient;
@Override
public List<EngineeringHomePageVO> getEngineeringHomePage() {
List<EngineeringHomePageVO> result = new ArrayList<>();
List<CsEngineeringVO> engineeringList = engineeringFeignClient.queryEngineering(new CsEngineeringQueryParm()).getData();
if (CollectionUtils.isNotEmpty(engineeringList)) {
List<String> engineeringIds = engineeringList.stream().map(CsEngineeringVO::getId).collect(Collectors.toList());
//根据工程获取设备信息
List<DevDetailDTO> devList = csLedgerFeignClient.getDevInfoByEngineerIds(engineeringIds).getData();
Map<String, List<DevDetailDTO>> devMap = devList.stream().collect(Collectors.groupingBy(DevDetailDTO::getEngineeringid));
//获取未读事件
List<UnReadEventDto> unReadEventList = csEventUserPOService.queryEngineeringEventCount(RequestUtil.getUserIndex());
Map<String, List<UnReadEventDto>> unReadEventMap = unReadEventList.stream().collect(Collectors.groupingBy(UnReadEventDto::getDeviceId));
engineeringList.forEach(item->{
EngineeringHomePageVO vo = new EngineeringHomePageVO();
vo.setEngineeringId(item.getId());
vo.setEngineeringName(item.getName());
List<DevDetailDTO> devs = devMap.get(item.getId());
vo.setDevTotal(Objects.isNull(devs) ? 0:devs.size());
long status1Count = devs == null ? 0 : devs.stream().filter(d -> d.getRunStatus() == 1).count();
long status2Count = devs == null ? 0 : devs.stream().filter(d -> d.getRunStatus() == 2).count();
vo.setOnlineDevTotal((int) status2Count);
vo.setOfflineDevTotal((int) status1Count);
vo.setSort(item.getSort());
//未读的告警数量
int alarmTotal = Objects.isNull(devs) ? 0 : devs.stream()
.map(DevDetailDTO::getEquipmentId)
.filter(Objects::nonNull)
.mapToInt(deviceId -> {
List<UnReadEventDto> events = unReadEventMap.get(deviceId);
return Objects.isNull(events) ? 0 : events.stream()
.mapToInt(UnReadEventDto::getCount)
.sum();
})
.sum();
vo.setAlarmTotal(alarmTotal);
result.add(vo);
});
//获取用户是否有置顶的工程
List<CsUserPins> pinList = csUserPinsFeignClient.getPinToTopList().getData();
if (CollectionUtils.isNotEmpty(pinList)) {
List<String> targetIdList = pinList.stream()
.filter(item -> Objects.equals(item.getTargetType(), 2))
.map(CsUserPins::getTargetId)
.collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(targetIdList)) {
// 分离出匹配 targetIdList 的节点和未匹配的节点
List<EngineeringHomePageVO> matchedList = new ArrayList<>();
List<EngineeringHomePageVO> unmatchedList = new ArrayList<>();
for (EngineeringHomePageVO node : result) {
if (targetIdList.contains(node.getEngineeringId())) {
node.setIsTop(1);
matchedList.add(node);
} else {
unmatchedList.add(node);
}
}
// 根据 targetIdList 的顺序对匹配的节点进行排序
matchedList.sort(Comparator.comparingInt(node -> targetIdList.indexOf(node.getEngineeringId())));
// 未匹配的节点按照原有的 sort 字段排序,处理 null 值情况
unmatchedList.sort(Comparator.comparing(node -> node.getSort() != null ? node.getSort() : Integer.MAX_VALUE));
// 清空原列表并添加排序后的数据
result.clear();
result.addAll(matchedList);
result.addAll(unmatchedList);
}
}
}
return result;
}
}

View File

@@ -12,11 +12,11 @@ import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.csdevice.api.CsLineFeignClient;
import com.njcn.csdevice.pojo.po.CsLinePO;
import com.njcn.csharmonic.mapper.PqSensitiveUserMapper;
import com.njcn.csharmonic.pojo.param.PqSensitiveUserParam;
import com.njcn.csharmonic.pojo.po.PqSensitiveUser;
import com.njcn.csharmonic.pojo.vo.PqSensitiveUserVo;
import com.njcn.csharmonic.service.IPqSensitiveUserService;
import com.njcn.device.biz.mapper.PqSensitiveUserMapper;
import com.njcn.device.biz.pojo.po.PqSensitiveUser;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.pojo.po.DictData;
import com.njcn.web.pojo.param.BaseParam;

View File

@@ -521,6 +521,13 @@ public class RStatLimitRateDetailDServiceImpl extends ServiceImpl<RStatLimitRate
return result;
}
@Override
public List<RStatLimitRateDetailDPO> monitorIdsGetLimitRateInfo(String date, List<String> monitorIds) {
return this.baseMapper.selectList(new LambdaQueryWrapper<RStatLimitRateDetailDPO>()
.in(RStatLimitRateDetailDPO::getLineId, monitorIds)
.eq(RStatLimitRateDetailDPO::getTime, date));
}
/**
* 设置LimitExtentVO的最大值和相关信息
*/

View File

@@ -1,48 +1,58 @@
//package com.njcn;
//
//import com.njcn.influx.utils.InfluxDbUtils;
//import com.njcn.influxdb.param.InfluxDBPublicParam;
//import com.njcn.influxdb.utils.InfluxDbUtils;
//import lombok.AllArgsConstructor;
//import org.influxdb.InfluxDB;
//import org.influxdb.dto.BatchPoints;
//import org.influxdb.dto.Point;
//
//import java.util.*;
//import java.util.concurrent.TimeUnit;
//
///**
// * 类的介绍:
// *
// * @author xuyang
// * @version 1.0.0
// * @createTime 2023/6/5 14:44
// */
//@AllArgsConstructor
//public class InfluxDbTest {
//
// public static void main(String[] args) {
// InfluxDbUtils influxDbUtils = new InfluxDbUtils("admin", "123456", "http://192.168.1.16:8086", "pqsbase_zl", "");
// List<String> records = new ArrayList<>();
// List<String> phasic = Arrays.asList("A","B","C");
// List<String> dataType = Arrays.asList("max","min","avg","cp95");
// long time = System.currentTimeMillis();
// for (String item1 : phasic) {
// for (String item2 : dataType) {
// Map<String, String> tags = new HashMap<>();
// Map<String, Object> fields = new HashMap<>();
// tags.put("line_id","4aea410500fc0cea5a62790e8d493542");
// tags.put("phasic_type",item1);
// tags.put("value_type",item2);
// fields.put("Hz",new Random().nextDouble());
// fields.put("PhV",new Random().nextDouble());
// Point point = influxDbUtils.pointBuilder("data_v", time, TimeUnit.MILLISECONDS, tags, fields);
// BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName ()).tag(InfluxDBPublicParam.LINE_ID, "4aea410500fc0cea5a62790e8d493542").tag(InfluxDBPublicParam.PHASIC_TYPE,item1).tag(InfluxDBPublicParam.VALUE_TYPE,item2).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
// batchPoints.point(point);
// records.add(batchPoints.lineProtocol());
// }
// }
// influxDbUtils.batchInsert(influxDbUtils.getDbName (),"", InfluxDB.ConsistencyLevel.ALL, records);
// }
//
//}
package com.njcn;
import com.njcn.influx.utils.InfluxDbUtils;
import lombok.AllArgsConstructor;
import org.influxdb.InfluxDB;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/6/5 14:44
*/
@AllArgsConstructor
public class InfluxDbTest {
public static void main(String[] args) {
InfluxDbUtils influxDbUtils = new InfluxDbUtils("root", "123456", "http://127.0.0.1:8086", "pqsadmin_jb", "");
List<String> records = new ArrayList<>();
List<String> phasic = Arrays.asList("A","B","C","M");
List<String> dataType = Arrays.asList("max","min","avg","cp95");
long time = System.currentTimeMillis();
for (String item1 : phasic) {
for (String item2 : dataType) {
Map<String, String> tags = new HashMap<>();
Map<String, Object> fields = new HashMap<>();
tags.put("line_id","00B78D0171091");
tags.put("phasic_type",item1);
tags.put("value_type",item2);
tags.put("cl_did","1");
tags.put("process","4");
tags.put("quality_flag","0");
fields.put("Pq_P",1);
fields.put("Pq_PF",null);
fields.put("Pq_DF",1);
Point point = influxDbUtils.pointBuilder("data_harmpower_p", time, TimeUnit.MILLISECONDS, tags, fields);
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName ()).tag("line_id", "00B78D0171091")
.tag("phasic_type",item1)
.tag("value_type",item2)
.tag("cl_did","1")
.tag("process","4")
.tag("quality_flag","0")
.retentionPolicy("")
.consistency(InfluxDB.ConsistencyLevel.ALL)
.build();
batchPoints.point(point);
records.add(batchPoints.lineProtocol());
}
}
influxDbUtils.batchInsert(influxDbUtils.getDbName (),"", InfluxDB.ConsistencyLevel.ALL, records);
}
}