Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1bb9ad1cf7 | |||
| 186eec4f7e |
@@ -0,0 +1,26 @@
|
||||
package com.njcn.access.api;
|
||||
|
||||
import com.njcn.access.api.fallback.CsLineLatestDataClientFallbackFactory;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.common.pojo.constant.ServerInfo;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@FeignClient(value = ServerInfo.ACCESS_BOOT, path = "/csLineLatestData", fallbackFactory = CsLineLatestDataClientFallbackFactory.class,contextId = "csLineLatestData")
|
||||
|
||||
public interface CsLineLatestDataFeignClient {
|
||||
|
||||
@PostMapping("/add")
|
||||
HttpResult<String> addData(@RequestBody CsLineLatestData csLineLatestData);
|
||||
|
||||
@PostMapping("/list")
|
||||
HttpResult<List<CsLineLatestData>> listData();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.njcn.access.api.fallback;
|
||||
|
||||
import com.njcn.access.api.CsLineLatestDataFeignClient;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import feign.hystrix.FallbackFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class CsLineLatestDataClientFallbackFactory implements FallbackFactory<CsLineLatestDataFeignClient> {
|
||||
@Override
|
||||
public CsLineLatestDataFeignClient create(Throwable cause) {
|
||||
//判断抛出异常是否为解码器抛出的业务异常
|
||||
Enum<?> exceptionEnum = CommonResponseEnum.SERVICE_FALLBACK;
|
||||
if (cause.getCause() instanceof BusinessException) {
|
||||
BusinessException businessException = (BusinessException) cause.getCause();
|
||||
}
|
||||
Enum<?> finalExceptionEnum = exceptionEnum;
|
||||
return new CsLineLatestDataFeignClient() {
|
||||
|
||||
@Override
|
||||
public HttpResult<String> addData(CsLineLatestData csLineLatestData) {
|
||||
log.error("{}异常,降级处理,异常为:{}","新增治理设备最近数据时间",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResult<List<CsLineLatestData>> listData() {
|
||||
log.error("{}异常,降级处理,异常为:{}","查询整体数据",cause.toString());
|
||||
throw new BusinessException(finalExceptionEnum);
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.njcn.access.pojo.po;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.github.jeffreyning.mybatisplus.anno.MppMultiId;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -14,35 +15,26 @@ import java.time.LocalDateTime;
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-26
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@TableName("cs_line_run_data")
|
||||
public class CsLineRunData implements Serializable {
|
||||
@TableName("cs_line_latest_data")
|
||||
public class CsLineLatestData implements Serializable{
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 监测点id
|
||||
*/
|
||||
@MppMultiId(value = "line_id")
|
||||
private String lineId;
|
||||
|
||||
/**
|
||||
* 子模块编号id(没有子模块,则为0)
|
||||
*/
|
||||
private Integer moduleId;
|
||||
|
||||
/**
|
||||
* 最新数据时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime timeId;
|
||||
|
||||
/**
|
||||
* 子模块通讯状态(0:离线 1:连接)
|
||||
*/
|
||||
private Integer runState;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.njcn.access.controller;
|
||||
|
||||
import com.njcn.access.pojo.po.CsLineRunData;
|
||||
import com.njcn.access.service.ICsLineRunDataService;
|
||||
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.service.ICsLineLatestDataService;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
@@ -13,7 +14,6 @@ import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -27,26 +27,35 @@ import java.util.List;
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-26
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/csLineRunData")
|
||||
@Slf4j
|
||||
@Api(tags = "治理设备数据运行记录")
|
||||
@RestController
|
||||
@RequestMapping("/csLineLatestData")
|
||||
@Api(tags = "暂降事件")
|
||||
@AllArgsConstructor
|
||||
public class CsLineRunDataController extends BaseController {
|
||||
public class CsLineLatestDataController extends BaseController {
|
||||
|
||||
private final ICsLineRunDataService csLineRunDataService;
|
||||
private final ICsLineLatestDataService csLineLatestDataService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增数据")
|
||||
@ApiImplicitParam(name = "list", value = "参数", required = true)
|
||||
public HttpResult<String> addData(@RequestBody @Validated List<CsLineRunData> list){
|
||||
String methodDescribe = getMethodDescribe("addData");
|
||||
csLineRunDataService.addData(list);
|
||||
@ApiOperation("新增")
|
||||
@ApiImplicitParam(name = "csLineLatestData", value = "实体", required = true)
|
||||
public HttpResult<String> addData(@RequestBody CsLineLatestData csLineLatestData) {
|
||||
String methodDescribe = getMethodDescribe("csLineLatestData");
|
||||
csLineLatestDataService.addData(csLineLatestData);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("查询")
|
||||
public HttpResult<List<CsLineLatestData>> listData() {
|
||||
String methodDescribe = getMethodDescribe("listData");
|
||||
List<CsLineLatestData> list = csLineLatestDataService.list();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.njcn.access.mapper;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
public interface CsLineLatestDataMapper extends MppBaseMapper<CsLineLatestData> {
|
||||
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.njcn.access.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.njcn.access.pojo.po.CsLineRunData;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-26
|
||||
*/
|
||||
public interface CsLineRunDataMapper extends BaseMapper<CsLineRunData> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
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 io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
public interface ICsLineLatestDataService extends IService<CsLineLatestData> {
|
||||
|
||||
void addData(CsLineLatestData csLineLatestData);
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.njcn.access.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.access.pojo.po.CsLineRunData;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-26
|
||||
*/
|
||||
public interface ICsLineRunDataService extends IService<CsLineRunData> {
|
||||
|
||||
void addData(List<CsLineRunData> list);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.access.mapper.CsLineLatestDataMapper;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.service.ICsLineLatestDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-07-03
|
||||
*/
|
||||
@Service
|
||||
public class CsLineLatestDataServiceImpl extends MppServiceImpl<CsLineLatestDataMapper, CsLineLatestData> implements ICsLineLatestDataService {
|
||||
|
||||
@Override
|
||||
public void addData(CsLineLatestData csLineLatestData) {
|
||||
this.saveOrUpdateByMultiId(csLineLatestData);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.njcn.access.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.mapper.CsLineRunDataMapper;
|
||||
import com.njcn.access.pojo.po.CsLineRunData;
|
||||
import com.njcn.access.service.ICsLineRunDataService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 治理设备模块运行状态记录表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-26
|
||||
*/
|
||||
@Service
|
||||
public class CsLineRunDataServiceImpl extends ServiceImpl<CsLineRunDataMapper, CsLineRunData> implements ICsLineRunDataService {
|
||||
|
||||
@Override
|
||||
public void addData(List<CsLineRunData> list) {
|
||||
this.saveBatch(list);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package com.njcn.stat.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.api.CsLineLatestDataFeignClient;
|
||||
import com.njcn.access.pojo.po.CsLineLatestData;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
@@ -30,6 +32,10 @@ import org.influxdb.dto.Point;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -51,10 +57,12 @@ public class StatServiceImpl implements IStatService {
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final CsLineLatestDataFeignClient csLineLatestDataFeignClient;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
LocalDateTime time = null;
|
||||
log.info("开始消费{},发送时间{}",appAutoDataMessage.getKey(),appAutoDataMessage.getSendTime());
|
||||
//1.根据设备网络识别码获取设备id,查询到所用的模板,用来判断模板的类型(治理模板还是电能质量模板)
|
||||
//2.解析appAutoDataMessage的Did,来判断当前数据是治理数据还是电能质量数据
|
||||
@@ -124,10 +132,19 @@ public class StatServiceImpl implements IStatService {
|
||||
}
|
||||
List<String> result = assembleData(lineId,dataArrayList,item,appAutoDataMessage.getMsg().getClDid(),dataArrayParam.getStatMethod(),po.getProcess());
|
||||
recordList.addAll(result);
|
||||
//获取时间
|
||||
time = Instant.ofEpochSecond(item.getDataTimeSec()-8*3600)
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(recordList)){
|
||||
//influx数据批量入库
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, recordList);
|
||||
//记录监测点最新数据时间
|
||||
CsLineLatestData csLineLatestData = new CsLineLatestData();
|
||||
csLineLatestData.setLineId(lineId);
|
||||
csLineLatestData.setTimeId(Objects.isNull(time) ? LocalDateTime.now() : time);
|
||||
csLineLatestDataFeignClient.addData(csLineLatestData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +98,16 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
throw new BusinessException(DATA_ERROR);
|
||||
}
|
||||
}
|
||||
//判断是否有重复数据
|
||||
CsEventPO po2 = this.lambdaQuery().eq(CsEventPO::getLineId,lineId)
|
||||
.eq(CsEventPO::getStartTime,eventTime)
|
||||
.eq(CsEventPO::getClDid,appEventMessage.getMsg().getClDid())
|
||||
.eq(CsEventPO::getProcess,po.getProcess())
|
||||
.eq(CsEventPO::getTag,tag).one();
|
||||
if (po2 != null) {
|
||||
throw new BusinessException(DATA_ERROR);
|
||||
}
|
||||
|
||||
//事件入库
|
||||
CsEventPO csEvent = new CsEventPO();
|
||||
csEvent.setLineId(lineId);
|
||||
|
||||
Reference in New Issue
Block a user