治理设备新增模块状态查询功能
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package com.njcn.csdevice.controller.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* 动态注解类
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
* @data 2024/11/7 11:00
|
||||
*/
|
||||
@Target({ElementType.TYPE,ElementType.METHOD,ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface InsertBean {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.njcn.csdevice.controller.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
*
|
||||
* 动态注解类
|
||||
*
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
* @data 2024/11/7 11:00
|
||||
*/
|
||||
@Target({ElementType.TYPE,ElementType.METHOD,ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface QueryBean {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.njcn.csdevice.controller.bean;
|
||||
|
||||
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.controller.annotation.InsertBean;
|
||||
import com.njcn.csdevice.controller.annotation.QueryBean;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
* @data 2024/11/7 11:31
|
||||
*/
|
||||
@Component
|
||||
public class DynamicBeanProcessor implements BeanPostProcessor {
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
/**
|
||||
* 查询配置
|
||||
*/
|
||||
@Value("${data.source.query:Influxdb}")
|
||||
private String queryParam;
|
||||
|
||||
/**
|
||||
* 插入配置
|
||||
*/
|
||||
@Value("${data.source.insert:Relation}")
|
||||
private String insertParam;
|
||||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean.getClass().isAnnotationPresent(Controller.class) || bean.getClass().isAnnotationPresent(RestController.class) || bean.getClass().isAnnotationPresent(Service.class)) {
|
||||
processFields(bean);
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
private void processFields(Object bean) {
|
||||
Field[] fields = bean.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
String beanId;
|
||||
Class<?> type = field.getType();
|
||||
// 判断是否是接口类型,并且是否是注解指定类库
|
||||
if (type.isInterface() && (field.isAnnotationPresent(QueryBean.class) || field.isAnnotationPresent(InsertBean.class))) {
|
||||
String name = type.getName();
|
||||
beanId = name.substring(name.lastIndexOf(".") + 2);
|
||||
if (field.isAnnotationPresent(QueryBean.class)) {
|
||||
beanId = queryParam + beanId + "Impl";
|
||||
} else if (field.isAnnotationPresent(InsertBean.class)) {
|
||||
beanId = insertParam + beanId + "Impl";
|
||||
}
|
||||
try {
|
||||
field.setAccessible(true);
|
||||
field.set(bean, context.getBean(beanId));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new BusinessException("获取动态实现类失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.njcn.csdevice.controller.data;
|
||||
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.constant.OperateType;
|
||||
import com.njcn.common.pojo.enums.common.LogEnum;
|
||||
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.HttpResultUtil;
|
||||
import com.njcn.csdevice.controller.annotation.QueryBean;
|
||||
import com.njcn.csdevice.param.LineCountEvaluateParam;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.service.ICsCommunicateService;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author hongawen
|
||||
* @version 1.0
|
||||
* @data 2024/11/6 19:48
|
||||
*/
|
||||
@Validated
|
||||
@Slf4j
|
||||
@Controller
|
||||
@RestController
|
||||
@RequestMapping("/pqsCommunicate")
|
||||
@Api(tags = "获取装置上下线记录")
|
||||
public class PqsCommunicateController extends BaseController {
|
||||
|
||||
@QueryBean
|
||||
private ICsCommunicateService pqsCommunicateCvtQuery;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getRawDataLatest")
|
||||
@ApiOperation("获取取出最新装置数据")
|
||||
public HttpResult<List<PqsCommunicateDto>> getRawDataLatest(@RequestBody LineCountEvaluateParam lineParam) {
|
||||
String methodDescribe = getMethodDescribe("getRawDataLatest");
|
||||
List<PqsCommunicateDto> rawData = pqsCommunicateCvtQuery.getRawDataLatest(lineParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rawData, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getRawData")
|
||||
@ApiOperation("获取原始数据")
|
||||
public HttpResult<List<PqsCommunicateDto>> getRawData(@RequestBody LineCountEvaluateParam lineParam) {
|
||||
String methodDescribe = getMethodDescribe("getRawData");
|
||||
List<PqsCommunicateDto> rawData = pqsCommunicateCvtQuery.getRawData(lineParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rawData, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getRawDataEnd")
|
||||
@ApiOperation("获取是否有当天最后一条数据")
|
||||
public HttpResult<List<PqsCommunicateDto>> getRawDataEnd(@RequestBody LineCountEvaluateParam lineParam) {
|
||||
String methodDescribe = getMethodDescribe("getRawData");
|
||||
List<PqsCommunicateDto> rawData = pqsCommunicateCvtQuery.getRawDataEnd(lineParam);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rawData, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.ADD)
|
||||
@PostMapping("/insertion")
|
||||
@ApiOperation("插入数据")
|
||||
public HttpResult<String> insertion(@RequestBody PqsCommunicateDto pqsCommunicateDto) {
|
||||
String methodDescribe = getMethodDescribe("insertion");
|
||||
pqsCommunicateCvtQuery.insertion(pqsCommunicateDto);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.njcn.csdevice.controller.data;
|
||||
|
||||
|
||||
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.po.RStatIntegrityD;
|
||||
import com.njcn.csdevice.service.IRStatIntegrityDService;
|
||||
import com.njcn.csharmonic.pojo.param.StatisticsDataParam;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据完整性日表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-23
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/rStatIntegrityD")
|
||||
@Api(tags = "数据完整性接口")
|
||||
@AllArgsConstructor
|
||||
public class RStatIntegrityDController extends BaseController {
|
||||
|
||||
private final IRStatIntegrityDService irStatIntegrityDService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增数据完整性(可根据时间段进行补召)")
|
||||
@ApiImplicitParam(name = "param", value = "参数", required = true)
|
||||
public HttpResult<String> addData(@RequestBody @Validated StatisticsDataParam param){
|
||||
String methodDescribe = getMethodDescribe("addData");
|
||||
irStatIntegrityDService.addData(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("获取数据")
|
||||
public HttpResult<List<RStatIntegrityD>> list(@Validated @RequestParam("list") List<String> list, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime){
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
List<RStatIntegrityD> result = irStatIntegrityDService.getData(list,startTime,endTime);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.njcn.csdevice.controller.data;
|
||||
|
||||
|
||||
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.po.RStatOnlineRateD;
|
||||
import com.njcn.csdevice.service.IRStatOnlineRateDService;
|
||||
import com.njcn.csharmonic.pojo.param.StatisticsDataParam;
|
||||
import com.njcn.web.controller.BaseController;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 在线率日表 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-23
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/rStatOnlineRateD")
|
||||
@Api(tags = "终端在线率接口")
|
||||
@AllArgsConstructor
|
||||
public class RStatOnlineRateDController extends BaseController {
|
||||
|
||||
private final IRStatOnlineRateDService rStatOnlineRateDService;
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("新增终端在线率(可根据时间段进行补召)")
|
||||
@ApiImplicitParam(name = "param", value = "参数", required = true)
|
||||
public HttpResult<String> addData(@RequestBody @Validated StatisticsDataParam param){
|
||||
String methodDescribe = getMethodDescribe("addData");
|
||||
rStatOnlineRateDService.addData(param);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/list")
|
||||
@ApiOperation("获取数据")
|
||||
public HttpResult<List<RStatOnlineRateD>> list(@Validated @RequestParam("list") List<String> list, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime){
|
||||
String methodDescribe = getMethodDescribe("list");
|
||||
List<RStatOnlineRateD> result = rStatOnlineRateDService.getData(list,startTime,endTime);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,14 +4,11 @@ import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.annotation.OperateInfo;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
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.constant.DataParam;
|
||||
import com.njcn.csdevice.enums.DeviceOperate;
|
||||
import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO;
|
||||
import com.njcn.csdevice.pojo.param.*;
|
||||
@@ -342,4 +339,13 @@ public class EquipmentDeliveryController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/getDevByLineId")
|
||||
@ApiOperation("根据监测点id查询装置信息")
|
||||
public HttpResult<CsEquipmentDeliveryPO> getDevByLineId(@RequestParam("lineId") String lineId){
|
||||
String methodDescribe = getMethodDescribe("getDevByLineId");
|
||||
CsEquipmentDeliveryPO po = csEquipmentDeliveryService.getDevByLineId(lineId);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, po, methodDescribe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.csdevice.mapper;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
|
||||
import com.njcn.csdevice.pojo.po.RStatIntegrityD;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据完整性日表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-23
|
||||
*/
|
||||
@Mapper
|
||||
public interface RStatIntegrityDMapper extends MppBaseMapper<RStatIntegrityD> {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.njcn.csdevice.mapper;
|
||||
|
||||
import com.github.jeffreyning.mybatisplus.base.MppBaseMapper;
|
||||
import com.njcn.csdevice.pojo.po.RStatOnlineRateD;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 在线率日表 Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-23
|
||||
*/
|
||||
@Mapper
|
||||
public interface RStatOnlineRateDMapper extends MppBaseMapper<RStatOnlineRateD> {
|
||||
|
||||
}
|
||||
@@ -133,4 +133,6 @@ public interface CsEquipmentDeliveryService extends IService<CsEquipmentDelivery
|
||||
* 判断设备型号
|
||||
*/
|
||||
boolean judgeDevModel(String nDid);
|
||||
|
||||
CsEquipmentDeliveryPO getDevByLineId(String lineId);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.njcn.csdevice.service;
|
||||
|
||||
|
||||
import com.njcn.csdevice.param.LineCountEvaluateParam;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: wr
|
||||
* @Date: 2025/3/6 10:22
|
||||
*/
|
||||
public interface ICsCommunicateService {
|
||||
|
||||
/**
|
||||
* 取出最新装置数据
|
||||
* @param lineParam
|
||||
* @return
|
||||
*/
|
||||
List<PqsCommunicateDto> getRawDataLatest(LineCountEvaluateParam lineParam);
|
||||
|
||||
/**
|
||||
* 获取时间范围数据
|
||||
* @param lineParam
|
||||
* @return
|
||||
*/
|
||||
List<PqsCommunicateDto> getRawData(LineCountEvaluateParam lineParam);
|
||||
|
||||
/**
|
||||
*是否有当天最后一条数据
|
||||
* @param lineParam
|
||||
* @return
|
||||
*/
|
||||
List<PqsCommunicateDto> getRawDataEnd(LineCountEvaluateParam lineParam);
|
||||
|
||||
void insertion(PqsCommunicateDto pqsCommunicateDto);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.csdevice.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csdevice.pojo.po.RStatIntegrityD;
|
||||
import com.njcn.csharmonic.pojo.param.StatisticsDataParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据完整性日表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-23
|
||||
*/
|
||||
public interface IRStatIntegrityDService extends IService<RStatIntegrityD> {
|
||||
|
||||
void addData(StatisticsDataParam param);
|
||||
|
||||
List<RStatIntegrityD> getData(List<String> list, String startTime, String endTime);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.njcn.csdevice.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.csdevice.pojo.po.RStatOnlineRateD;
|
||||
import com.njcn.csharmonic.pojo.param.StatisticsDataParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 在线率日表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-23
|
||||
*/
|
||||
public interface IRStatOnlineRateDService extends IService<RStatOnlineRateD> {
|
||||
|
||||
void addData(StatisticsDataParam param);
|
||||
|
||||
List<RStatOnlineRateD> getData(List<String> list, String startTime, String endTime);
|
||||
|
||||
}
|
||||
@@ -19,7 +19,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.access.api.AskDeviceDataFeignClient;
|
||||
import com.njcn.access.utils.MqttUtil;
|
||||
import com.njcn.common.pojo.dto.DeviceLogDTO;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLogsFeignClient;
|
||||
import com.njcn.csdevice.constant.DataParam;
|
||||
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
||||
import com.njcn.csdevice.mapper.CsEquipmentDeliveryMapper;
|
||||
@@ -44,7 +46,6 @@ import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.enums.DicTreeEnum;
|
||||
import com.njcn.system.pojo.po.SysDicTreePO;
|
||||
import com.njcn.system.pojo.vo.DictTreeVO;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import com.njcn.web.utils.RequestUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -96,6 +97,8 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
private final CsSoftInfoMapper csSoftInfoMapper;
|
||||
private final IMqttUserService mqttUserService;
|
||||
private final MqttUtil mqttUtil;
|
||||
private final CsLogsFeignClient csLogsFeignClient;
|
||||
|
||||
@Override
|
||||
public void refreshDeviceDataCache() {
|
||||
LambdaQueryWrapper<CsEquipmentDeliveryPO> queryWrapper = new LambdaQueryWrapper<>();
|
||||
@@ -226,10 +229,9 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Boolean updateEquipmentDelivery(CsEquipmentDeliveryAuditParm csEquipmentDeliveryAuditParm) {
|
||||
StringUtil.containsSpecialCharacters(csEquipmentDeliveryAuditParm.getNdid());
|
||||
|
||||
|
||||
boolean result;
|
||||
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(CsEquipmentDeliveryPO::getNdid,csEquipmentDeliveryAuditParm.getNdid())
|
||||
@@ -240,6 +242,11 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
if (countByAccount >= 1) {
|
||||
throw new BusinessException(AlgorithmResponseEnum.NDID_ERROR);
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<CsEquipmentDeliveryPO> lambdaQueryWrapper2 = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper2.eq(CsEquipmentDeliveryPO::getId, csEquipmentDeliveryAuditParm.getId());
|
||||
CsEquipmentDeliveryPO po = this.baseMapper.selectOne(lambdaQueryWrapper2);
|
||||
|
||||
List<CsEquipmentDeliveryPO> list = this.lambdaQuery()
|
||||
.ne(CsEquipmentDeliveryPO::getId, csEquipmentDeliveryAuditParm.getId())
|
||||
.ne(CsEquipmentDeliveryPO::getNdid, csEquipmentDeliveryAuditParm.getNdid())
|
||||
@@ -251,8 +258,23 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
CsEquipmentDeliveryPO csEquipmentDeliveryPo = new CsEquipmentDeliveryPO();
|
||||
BeanUtils.copyProperties (csEquipmentDeliveryAuditParm, csEquipmentDeliveryPo);
|
||||
result = this.updateById(csEquipmentDeliveryPo);
|
||||
//修改台账树中的设备名称
|
||||
CsLedger csLedger = csLedgerService.findDataById(csEquipmentDeliveryAuditParm.getId());
|
||||
CsLedgerParam.Update csLedgerParam = new CsLedgerParam.Update();
|
||||
BeanUtils.copyProperties (csLedger, csLedgerParam);
|
||||
csLedgerParam.setName(csEquipmentDeliveryAuditParm.getName());
|
||||
csLedgerService.updateLedgerTree(csLedgerParam);
|
||||
|
||||
if (result) {
|
||||
refreshDeviceDataCache();
|
||||
if (!Objects.equals(po.getUsageStatus(),csEquipmentDeliveryAuditParm.getUsageStatus())) {
|
||||
DeviceLogDTO dto = new DeviceLogDTO();
|
||||
dto.setUserName(RequestUtil.getUsername());
|
||||
dto.setOperate("设备使用状态被修改");
|
||||
dto.setResult(1);
|
||||
dto.setLoginName(RequestUtil.getLoginName());
|
||||
csLogsFeignClient.addUserLog(dto);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -307,6 +329,9 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
} else {
|
||||
queryWrapper.in("cs_equipment_delivery.run_status", Arrays.asList(1,2));
|
||||
}
|
||||
if (!Objects.isNull(queryParam.getProcess())){
|
||||
queryWrapper.eq("cs_equipment_delivery.process", queryParam.getProcess());
|
||||
}
|
||||
Page<CsEquipmentDeliveryVO> page = this.baseMapper.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), queryWrapper);
|
||||
page.getRecords().forEach(item->{
|
||||
if (!Objects.isNull(item.getQrPath())){
|
||||
@@ -731,6 +756,12 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CsEquipmentDeliveryPO getDevByLineId(String lineId) {
|
||||
CsLinePO linePO = csLinePOService.getById(lineId);
|
||||
return this.lambdaQuery().eq(CsEquipmentDeliveryPO::getId,linePO.getDeviceId()).ne(CsEquipmentDeliveryPO::getRunStatus,0).one();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ndid生成二维码
|
||||
* @param ndid
|
||||
|
||||
@@ -85,7 +85,7 @@ public class CsLinePOServiceImpl extends ServiceImpl<CsLinePOMapper, CsLinePO> i
|
||||
|
||||
@Override
|
||||
public List<CsLinePO> getLinesByDevList(List<String> list) {
|
||||
return this.lambdaQuery().in(CsLinePO::getDevId,list).eq(CsLinePO::getStatus,1).list();
|
||||
return this.lambdaQuery().in(CsLinePO::getDeviceId,list).eq(CsLinePO::getStatus,1).list();
|
||||
}
|
||||
|
||||
// /**
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.njcn.csdevice.param.LineCountEvaluateParam;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.service.CsEquipmentDeliveryService;
|
||||
import com.njcn.csdevice.service.ICsCommunicateService;
|
||||
import com.njcn.influx.imapper.PqsCommunicateMapper;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
import com.njcn.influx.pojo.po.PqsCommunicate;
|
||||
import com.njcn.influx.query.InfluxQueryWrapper;
|
||||
import com.njcn.influx.utils.InfluxDbUtils;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.influxdb.InfluxDB;
|
||||
import org.influxdb.dto.BatchPoints;
|
||||
import org.influxdb.dto.Point;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Author: wr
|
||||
* @Date: 2025/3/7 10:13
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("InfluxdbCsCommunicateServiceImpl")
|
||||
@AllArgsConstructor
|
||||
public class InfluxdbCsCommunicateServiceImpl implements ICsCommunicateService {
|
||||
|
||||
private final InfluxDbUtils influxDbUtils;
|
||||
private final CsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
@Resource
|
||||
private PqsCommunicateMapper pqsCommunicateMapper;
|
||||
private final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
|
||||
|
||||
@Override
|
||||
public List<PqsCommunicateDto> getRawDataLatest(LineCountEvaluateParam lineParam) {
|
||||
List<PqsCommunicateDto> result = new ArrayList<>();
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(PqsCommunicate.class);
|
||||
influxQueryWrapper.regular(PqsCommunicate::getDevId, lineParam.getLineId())
|
||||
.select(PqsCommunicate::getTime)
|
||||
.select(PqsCommunicate::getDevId)
|
||||
.select(PqsCommunicate::getDescription)
|
||||
.select(PqsCommunicate::getType)
|
||||
.timeDesc()
|
||||
.limit(1);
|
||||
List<PqsCommunicate> list = pqsCommunicateMapper.selectByQueryWrapper(influxQueryWrapper);
|
||||
list.forEach(item -> {
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
BeanUtils.copyProperties(item, dto);
|
||||
dto.setTime(DATE_TIME_FORMATTER.format(item.getTime()));
|
||||
result.add(dto);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Description: 获取时间段内的数据
|
||||
* @Param:
|
||||
* @return: java.util.List<com.njcn.dataProcess.dto.DataVDTO>
|
||||
* @Author: clam
|
||||
* @Date: 2025/02/24
|
||||
*/
|
||||
@Override
|
||||
public List<PqsCommunicateDto> getRawData(LineCountEvaluateParam lineParam) {
|
||||
List<PqsCommunicateDto> result = new ArrayList<>();
|
||||
List<PqsCommunicate> list = getPqsCommunicateData(lineParam);
|
||||
list.forEach(item -> {
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
BeanUtils.copyProperties(item, dto);
|
||||
dto.setTime(DATE_TIME_FORMATTER.format(item.getTime()));
|
||||
result.add(dto);
|
||||
});
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PqsCommunicateDto> getRawDataEnd(LineCountEvaluateParam lineParam) {
|
||||
List<PqsCommunicateDto> result = new ArrayList<>();
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(PqsCommunicate.class);
|
||||
influxQueryWrapper.regular(PqsCommunicate::getDevId, lineParam.getLineId())
|
||||
.select(PqsCommunicate::getTime)
|
||||
.select(PqsCommunicate::getDevId)
|
||||
.select(PqsCommunicate::getDescription)
|
||||
.select(PqsCommunicate::getType)
|
||||
.le(PqsCommunicate::getTime, lineParam.getEndTime())
|
||||
.timeDesc()
|
||||
.limit(1);
|
||||
List<PqsCommunicate> list = pqsCommunicateMapper.selectByQueryWrapper(influxQueryWrapper);
|
||||
list.forEach(item -> {
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
BeanUtils.copyProperties(item, dto);
|
||||
dto.setTime(DATE_TIME_FORMATTER.format(item.getTime()));
|
||||
result.add(dto);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertion(PqsCommunicateDto pqsCommunicateDto) {
|
||||
//根据NDID获取装置信息
|
||||
CsEquipmentDeliveryPO po = csEquipmentDeliveryService.findDevByNDid(pqsCommunicateDto.getDevId());
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(PqsCommunicate.class);
|
||||
influxQueryWrapper.eq(PqsCommunicate::getDevId,po.getId()).timeDesc().limit(1);
|
||||
List<PqsCommunicate> pqsCommunicates = pqsCommunicateMapper.selectByQueryWrapper(influxQueryWrapper);
|
||||
//如果不存数据或者状态不一样则插入数据
|
||||
if(CollectionUtils.isEmpty(pqsCommunicates) || !Objects.equals(pqsCommunicates.get(0).getType(),pqsCommunicateDto.getType())){
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put("dev_id",po.getId());
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
fields.put("type",pqsCommunicateDto.getType());
|
||||
fields.put("description",pqsCommunicateDto.getDescription());
|
||||
long time = LocalDateTime.parse(pqsCommunicateDto.getTime(), DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
||||
Point point = influxDbUtils.pointBuilder("pqs_communicate", time, TimeUnit.MILLISECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, Collections.singletonList(batchPoints.lineProtocol()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public List<PqsCommunicate> getPqsCommunicateData(LineCountEvaluateParam lineParam) {
|
||||
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(PqsCommunicate.class);
|
||||
influxQueryWrapper.regular(PqsCommunicate::getDevId, lineParam.getLineId())
|
||||
.select(PqsCommunicate::getTime)
|
||||
.select(PqsCommunicate::getDevId)
|
||||
.select(PqsCommunicate::getDescription)
|
||||
.select(PqsCommunicate::getType)
|
||||
.between(PqsCommunicate::getTime, lineParam.getStartTime(), lineParam.getEndTime())
|
||||
.timeAsc();
|
||||
return pqsCommunicateMapper.selectByQueryWrapper(influxQueryWrapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.mapper.RStatIntegrityDMapper;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.csdevice.pojo.po.RStatIntegrityD;
|
||||
import com.njcn.csdevice.service.IRStatIntegrityDService;
|
||||
import com.njcn.csdevice.util.TimeUtil;
|
||||
import com.njcn.csharmonic.pojo.param.StatisticsDataParam;
|
||||
import com.njcn.influx.pojo.dto.StatisticalDataDTO;
|
||||
import com.njcn.influx.service.CommonService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据完整性日表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-23
|
||||
*/
|
||||
@DS("sjzx")
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RStatIntegrityDServiceImpl extends MppServiceImpl<RStatIntegrityDMapper, RStatIntegrityD> implements IRStatIntegrityDService {
|
||||
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final CsLineFeignClient csLineFeignClient;
|
||||
private final CommonService commonService;
|
||||
|
||||
@Override
|
||||
public void addData(StatisticsDataParam param) {
|
||||
List<RStatIntegrityD> result = new ArrayList<>();
|
||||
//获取库中正常的所有装置
|
||||
List<CsEquipmentDeliveryPO> devList = equipmentFeignClient.getAll().getData();
|
||||
if (CollectionUtil.isNotEmpty(devList)) {
|
||||
Map<String, CsEquipmentDeliveryPO> devMap = devList.stream().collect(Collectors.toMap(CsEquipmentDeliveryPO::getId, Function.identity()));
|
||||
//获取所有监测点
|
||||
List<String> devIdList = devList.stream().map(CsEquipmentDeliveryPO::getId).collect(Collectors.toList());
|
||||
if (CollectionUtil.isNotEmpty(devIdList)) {
|
||||
//获取需要计算的时间
|
||||
List<String> dateRange = TimeUtil.getDateRangeAsString(param.getStartTime(), param.getEndTime());
|
||||
//获取监测点信息
|
||||
List<CsLinePO> csLinePOList = csLineFeignClient.getLinesByDevList(devIdList).getData();
|
||||
csLinePOList.forEach(item->{
|
||||
//应收数据
|
||||
int dueCount = 1440 / item.getLineInterval();
|
||||
Integer process = devMap.get(item.getDeviceId()).getProcess();
|
||||
for (String time : dateRange) {
|
||||
StatisticalDataDTO statisticalDataDTO;
|
||||
RStatIntegrityD data = new RStatIntegrityD();
|
||||
//治理监测点
|
||||
if (item.getClDid() == 0) {
|
||||
statisticalDataDTO = commonService.getCounts(item.getLineId(),"apf_data","Apf_Freq","frequency","M","avg",item.getClDid().toString(),process.toString(),time+" 00:00:00",time+" 23:59:59");
|
||||
}
|
||||
//电能质量监测点
|
||||
else {
|
||||
statisticalDataDTO = commonService.getCounts(item.getLineId(),"pqd_data","Pq_Freq","frequency","M","avg",item.getClDid().toString(),process.toString(),time+" 00:00:00",time+" 23:59:59");
|
||||
}
|
||||
data.setTimeId(LocalDate.parse(time, DatePattern.NORM_DATE_FORMATTER));
|
||||
data.setLineIndex(item.getLineId());
|
||||
data.setDueTime(dueCount);
|
||||
data.setRealTime(statisticalDataDTO == null || statisticalDataDTO.getFrequency() == null
|
||||
? 0 : Integer.parseInt(statisticalDataDTO.getFrequency()));
|
||||
result.add(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(result)) {
|
||||
this.saveOrUpdateBatchByMultiId(result);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RStatIntegrityD> getData(List<String> list, String startTime, String endTime) {
|
||||
return this.lambdaQuery()
|
||||
.in(RStatIntegrityD::getLineIndex,list)
|
||||
.between(RStatIntegrityD::getTimeId,startTime,endTime)
|
||||
.list();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
package com.njcn.csdevice.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.mapper.RStatOnlineRateDMapper;
|
||||
import com.njcn.csdevice.param.LineCountEvaluateParam;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
import com.njcn.csdevice.pojo.po.RStatOnlineRateD;
|
||||
import com.njcn.csdevice.service.ICsCommunicateService;
|
||||
import com.njcn.csdevice.service.IRStatOnlineRateDService;
|
||||
import com.njcn.csdevice.util.TimeUtil;
|
||||
import com.njcn.csharmonic.pojo.param.StatisticsDataParam;
|
||||
import com.njcn.influx.deprecated.InfluxDBPublicParam;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 在线率日表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2025-06-23
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@DS("sjzx")
|
||||
public class RStatOnlineRateDServiceImpl extends MppServiceImpl<RStatOnlineRateDMapper, RStatOnlineRateD> implements IRStatOnlineRateDService {
|
||||
|
||||
private final Integer online = 1;
|
||||
private final EquipmentFeignClient equipmentFeignClient;
|
||||
private final ICsCommunicateService pqsCommunicateService;
|
||||
|
||||
@Override
|
||||
public void addData(StatisticsDataParam param) {
|
||||
List<RStatOnlineRateD> list = new ArrayList<>();
|
||||
//获取库中正常的所有装置
|
||||
List<CsEquipmentDeliveryPO> devList = equipmentFeignClient.getAll().getData();
|
||||
if (CollectionUtil.isNotEmpty(devList)) {
|
||||
//获取需要计算的时间
|
||||
List<String> dateRange = TimeUtil.getDateRangeAsString(param.getStartTime(), param.getEndTime());
|
||||
for (String time : dateRange) {
|
||||
List<PqsCommunicateDto> outCommunicateData = new ArrayList<>();
|
||||
LineCountEvaluateParam lineParam = new LineCountEvaluateParam();
|
||||
lineParam.setStartTime(time + " 00:00:00");
|
||||
lineParam.setEndTime(time + " 23:59:59");
|
||||
for (CsEquipmentDeliveryPO s : devList) {
|
||||
lineParam.setLineId(Collections.singletonList(s.getId()));
|
||||
List<PqsCommunicateDto> data = pqsCommunicateService.getRawDataLatest(lineParam);
|
||||
if (CollectionUtil.isEmpty(data)) {
|
||||
PqsCommunicateDto dto = new PqsCommunicateDto();
|
||||
dto.setTime(time + " 00:00:00");
|
||||
dto.setDevId(s.getId());
|
||||
if (s.getRunStatus() == 1) {
|
||||
dto.setType(0);
|
||||
dto.setDescription("通讯中断");
|
||||
} else if (s.getRunStatus() == 2) {
|
||||
dto.setType(1);
|
||||
dto.setDescription("通讯正常");
|
||||
}
|
||||
outCommunicateData.add(dto);
|
||||
}
|
||||
outCommunicateData.addAll(data);
|
||||
}
|
||||
Date dateOut = DateUtil.parse(time);
|
||||
for (PqsCommunicateDto pqsCommunicate : outCommunicateData) {
|
||||
RStatOnlineRateD po = new RStatOnlineRateD();
|
||||
Date newDate = DateUtil.parse(pqsCommunicate.getTime());
|
||||
lineParam.setLineId(Collections.singletonList(pqsCommunicate.getDevId()));
|
||||
RStatOnlineRateD onLineRate = onLineMinute(newDate, dateOut, pqsCommunicate.getType(), lineParam);
|
||||
po.setTimeId(LocalDate.parse(time, DatePattern.NORM_DATE_FORMATTER));
|
||||
po.setDevIndex(pqsCommunicate.getDevId());
|
||||
po.setOnlineMin(onLineRate.getOnlineMin());
|
||||
po.setOfflineMin(onLineRate.getOfflineMin());
|
||||
list.add(po);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(list)) {
|
||||
this.saveOrUpdateBatchByMultiId(list,1000);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RStatOnlineRateD> getData(List<String> list, String startTime, String endTime) {
|
||||
return this.lambdaQuery()
|
||||
.in(RStatOnlineRateD::getDevIndex,list)
|
||||
.between(RStatOnlineRateD::getTimeId,startTime,endTime)
|
||||
.list();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* new的时间和当前统计时间 不是/是 同一天
|
||||
*/
|
||||
private RStatOnlineRateD onLineMinute(Date newDate, Date date, Integer type, LineCountEvaluateParam lineParam) {
|
||||
RStatOnlineRateD onLineRate = new RStatOnlineRateD();
|
||||
Integer minute = 0;
|
||||
/*new的时间和当前统计时间是同一天*/
|
||||
if (DateUtil.isSameDay(newDate, date)) {
|
||||
minute = processData(newDate, date, type, lineParam);
|
||||
} else {
|
||||
/*new的时间和当前统计时间不是同一天*/
|
||||
Date nowDate = new Date();
|
||||
/*数据补招的情况下*/
|
||||
if (DateUtil.between(date, nowDate, DateUnit.DAY) > DateUtil.between(newDate, nowDate, DateUnit.DAY)) {
|
||||
minute = processData(newDate, date, null, lineParam);
|
||||
} else {
|
||||
if (online.equals(type)) {
|
||||
minute = InfluxDBPublicParam.DAY_MINUTE;
|
||||
}
|
||||
}
|
||||
}
|
||||
onLineRate.setOnlineMin(minute);
|
||||
onLineRate.setOfflineMin(InfluxDBPublicParam.DAY_MINUTE - minute);
|
||||
return onLineRate;
|
||||
}
|
||||
|
||||
private Integer processData(Date newDate, Date date, Integer type,LineCountEvaluateParam lineParam) {
|
||||
int minute = 0;
|
||||
List<PqsCommunicateDto> communicateData = pqsCommunicateService.getRawData(lineParam);
|
||||
/*当前统计时间内存在多条数据*/
|
||||
if (communicateData.size() > 1) {
|
||||
Date lastTime = null;
|
||||
long onlineTime = 0;
|
||||
long offlineTime = 0;
|
||||
for (int i = 0; i < communicateData.size(); i++) {
|
||||
long differ;
|
||||
if (i == 0) {
|
||||
/*首次比较取统计时间*/
|
||||
differ = DateUtil.between(date, DateUtil.parse(communicateData.get(i).getTime()), DateUnit.MINUTE);
|
||||
} else {
|
||||
/*后续取上一次数据时间*/
|
||||
differ = DateUtil.between(lastTime, DateUtil.parse(communicateData.get(i).getTime()), DateUnit.MINUTE);
|
||||
}
|
||||
if (online.equals(communicateData.get(i).getType())) {
|
||||
offlineTime = offlineTime + differ;
|
||||
} else {
|
||||
onlineTime = onlineTime + differ;
|
||||
}
|
||||
lastTime = DateUtil.parse(communicateData.get(i).getTime());
|
||||
}
|
||||
if (online.equals(communicateData.get(communicateData.size() - 1).getType())) {
|
||||
minute = InfluxDBPublicParam.DAY_MINUTE - (int) offlineTime;
|
||||
} else {
|
||||
minute = (int) onlineTime;
|
||||
}
|
||||
} else {
|
||||
if (type != null) {
|
||||
/*当前统计时间内仅有一条数据*/
|
||||
long differ = DateUtil.between(date, newDate, DateUnit.MINUTE);
|
||||
if (online.equals(type)) {
|
||||
minute = InfluxDBPublicParam.DAY_MINUTE - (int) differ;
|
||||
}
|
||||
} else {
|
||||
List<PqsCommunicateDto> communicateDataOld = pqsCommunicateService.getRawDataEnd(lineParam);
|
||||
if (!communicateDataOld.isEmpty()){
|
||||
if (online.equals(communicateDataOld.get(0).getType())){
|
||||
minute = InfluxDBPublicParam.DAY_MINUTE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return minute;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.njcn.csdevice.util;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 类的介绍:
|
||||
* 二维码工具
|
||||
* @author xuyang
|
||||
* @version 1.0.0
|
||||
* @createTime 2023/8/21 13:57
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class TimeUtil {
|
||||
|
||||
public static List<String> getDateRangeAsString(String startDateStr, String endDateStr) {
|
||||
// 定义日期格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
// 解析为LocalDate对象
|
||||
LocalDate startDate = LocalDate.parse(startDateStr, formatter);
|
||||
LocalDate endDate = LocalDate.parse(endDateStr, formatter);
|
||||
// 计算天数差
|
||||
long numOfDays = ChronoUnit.DAYS.between(startDate, endDate) + 1;
|
||||
// 生成日期流,格式化为字符串并收集为列表
|
||||
return Stream.iterate(startDate, date -> date.plusDays(1))
|
||||
.limit(numOfDays)
|
||||
.map(formatter::format)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,10 @@ logging:
|
||||
level:
|
||||
root: info
|
||||
|
||||
|
||||
data:
|
||||
source:
|
||||
query: Influxdb
|
||||
insert: Relation
|
||||
#mybatis配置信息
|
||||
mybatis-plus:
|
||||
#别名扫描
|
||||
|
||||
@@ -1,14 +1,39 @@
|
||||
package com.njcn;
|
||||
|
||||
import com.njcn.csdevice.CsDeviceBootApplication;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.service.DeviceFtpService;
|
||||
import com.njcn.csdevice.service.ICsCommunicateService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
public class AppTest
|
||||
{
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebAppConfiguration
|
||||
@SpringBootTest(classes = CsDeviceBootApplication.class)
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
public class AppTest{
|
||||
|
||||
@Autowired
|
||||
private DeviceFtpService deviceFtpService;
|
||||
|
||||
@Autowired
|
||||
private ICsCommunicateService csCommunicateService;
|
||||
|
||||
|
||||
/**
|
||||
* Rigorous Test :-)
|
||||
*/
|
||||
@@ -17,4 +42,35 @@ public class AppTest
|
||||
{
|
||||
assertTrue( true );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 测试下载文件
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void downloadFileTest() {
|
||||
String nDid = "00B78D016AB5";
|
||||
String name = "/etc/pqs_arm.bin";
|
||||
Integer size = 5123552;
|
||||
String fileCheck = "859E36E8";
|
||||
for (int i = 0; i < 10; i++) {
|
||||
log.info("开始第{}次", i);
|
||||
deviceFtpService.downloadFile(nDid,name,size,fileCheck);
|
||||
Thread.sleep(1000 * 60 * 4);
|
||||
log.info("这是第{}次询问装置,结果为:{}", i, null);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void writeData() {
|
||||
PqsCommunicateDto pqsCommunicateDto = new PqsCommunicateDto();
|
||||
pqsCommunicateDto.setTime("2024-01-01 00:00:00");
|
||||
pqsCommunicateDto.setDevId("da7aa071bf89864bedea8833133676b7");
|
||||
pqsCommunicateDto.setType(1);
|
||||
pqsCommunicateDto.setDescription("通讯连接");
|
||||
csCommunicateService.insertion(pqsCommunicateDto);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.njcn;
|
||||
|
||||
import com.njcn.csdevice.CsDeviceBootApplication;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebAppConfiguration
|
||||
@SpringBootTest(classes = CsDeviceBootApplication.class)
|
||||
public class BaseJunitTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
double num1 = 123.456;
|
||||
double num2 = 123.4;
|
||||
double num3 = 123.0;
|
||||
|
||||
System.out.println(roundToTwoDecimalPlaces(num1)); // 输出: 123.46
|
||||
System.out.println(roundToTwoDecimalPlaces(num2)); // 输出: 123.40
|
||||
System.out.println(roundToTwoDecimalPlaces(num3)); // 输出: 123.00
|
||||
}
|
||||
|
||||
public static double roundToTwoDecimalPlaces(double num) {
|
||||
// 乘以100,然后四舍五入,再除以100
|
||||
return Math.round(num * 100.0) / 100.0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.njcn;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.njcn.csdevice.pojo.dto.PqsCommunicateDto;
|
||||
import com.njcn.csdevice.service.DeviceFtpService;
|
||||
import com.njcn.influx.imapper.EvtDataMapper;
|
||||
import com.njcn.influx.imapper.PqsCommunicateMapper;
|
||||
import com.njcn.influx.pojo.po.PqsCommunicate;
|
||||
import com.njcn.influx.pojo.po.cs.EntData;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import lombok.SneakyThrows;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.Files;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
|
||||
public class DownloadFileTest extends BaseJunitTest{
|
||||
|
||||
@Autowired
|
||||
private DeviceFtpService deviceFtpService;
|
||||
|
||||
@Autowired
|
||||
private FileStorageUtil fileStorageUtil;
|
||||
@Autowired
|
||||
private EvtDataMapper evtDataMapper;
|
||||
@Autowired
|
||||
private PqsCommunicateMapper pqsCommunicateMapper;
|
||||
private final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
|
||||
|
||||
/**
|
||||
* inflxudb写入
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void addInfluxdb() {
|
||||
PqsCommunicateDto pqsCommunicate = new PqsCommunicateDto();
|
||||
pqsCommunicate.setTime("2025-06-23 ");
|
||||
pqsCommunicate.setDevId("da7aa071bf89864bedea8833133676b7");
|
||||
pqsCommunicate.setType(1);
|
||||
pqsCommunicate.setDescription("设备上线");
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试下载文件
|
||||
*/
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void downloadFileTest() {
|
||||
String nDid = "00B78D016AB3";
|
||||
String name = "/etc/pqs_arm.bin";
|
||||
Integer size = 5127376;
|
||||
String fileCheck = "E883C579";
|
||||
String filePath = "C:\\Users\\徐扬\\Desktop\\download.txt";
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println("开始第"+i+"次");
|
||||
deviceFtpService.downloadFile(nDid,name,size,fileCheck);
|
||||
String dataToAppend = LocalDateTime.now() + "开始下载,这是第"+i+"次,结果为:" + null + "\r\n";
|
||||
// 第二个参数为 true 表示追加模式
|
||||
try (FileWriter fileWriter = new FileWriter(filePath, true)) {
|
||||
fileWriter.write(dataToAppend); // 写入数据
|
||||
System.out.println("数据已成功追加到文件中。");
|
||||
} catch (IOException e) {
|
||||
System.err.println("写入文件时发生错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@Test
|
||||
public void moveFile() {
|
||||
String oldPath = "/db0/cmn/07/min/20240925/line2_avg.bin";
|
||||
StringBuilder result = null;
|
||||
String[] arr = oldPath.split("/");
|
||||
for (String s : arr) {
|
||||
s = s + File.separator;
|
||||
}
|
||||
System.out.println("result==:" + result);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String nDid = "00B78D016AB3";
|
||||
String oldPath = "/db0/cmn/07/min/20240925/line2_avg.bin";
|
||||
String path = getFilePath(oldPath,nDid);
|
||||
System.out.println("path==:" + path);
|
||||
}
|
||||
|
||||
private static String getFilePath(String path, String nDid) {
|
||||
String[] parts = path.split("/");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean first = true;
|
||||
for (int i = 3; i < parts.length; i++) {
|
||||
if (!first) {
|
||||
sb.append(File.separator);
|
||||
}
|
||||
sb.append(parts[i]);
|
||||
first = false;
|
||||
}
|
||||
|
||||
return nDid + File.separator + sb.toString();
|
||||
}
|
||||
|
||||
// private static String getFilePath(String path, String nDid) {
|
||||
// path = nDid + "/" + path;
|
||||
// String[] parts = path.split("/");
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// boolean first = true;
|
||||
// for (int i = 4; i < parts.length; i++) {
|
||||
// if (!first) {
|
||||
// sb.append("/");
|
||||
// }
|
||||
// sb.append(parts[i]);
|
||||
// first = false;
|
||||
// }
|
||||
// return sb.toString();
|
||||
// }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user