通讯表入库开发

This commit is contained in:
hzj
2025-03-11 18:18:11 +08:00
parent 7b6fd159c0
commit 49daa2cc47
14 changed files with 294 additions and 2 deletions

View File

@@ -71,4 +71,13 @@ public class PqsCommunicateController extends BaseController {
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, rawData, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/insertion")
@ApiOperation("插入数据")
public HttpResult<String> insertion(@RequestBody PqsCommunicateDto pqsCommunicateDto) {
String methodDescribe = getMethodDescribe("insertion");
pqsCommunicateInsert.insertion(pqsCommunicateDto);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -34,4 +34,5 @@ public interface IPqsCommunicate {
*/
List<PqsCommunicateDto> getRawDataEnd(LineCountEvaluateParam lineParam);
void insertion(PqsCommunicateDto pqsCommunicateDto);
}

View File

@@ -2,21 +2,30 @@ package com.njcn.dataProcess.service.impl.influxdb;
import com.njcn.dataProcess.dao.imapper.PqsCommunicateMapper;
import com.njcn.dataProcess.param.LineCountEvaluateParam;
import com.njcn.dataProcess.po.influx.DataHarmrateV;
import com.njcn.dataProcess.po.influx.DataV;
import com.njcn.dataProcess.po.influx.PqsCommunicate;
import com.njcn.dataProcess.pojo.dto.DataHarmDto;
import com.njcn.dataProcess.pojo.dto.PqsCommunicateDto;
import com.njcn.dataProcess.service.IPqsCommunicate;
import com.njcn.device.pq.api.DeviceFeignClient;
import com.njcn.device.pq.pojo.dto.DevComFlagDTO;
import com.njcn.influx.query.InfluxQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
@@ -31,7 +40,8 @@ public class InfluxdbPqsCommunicateImpl implements IPqsCommunicate {
@Resource
private PqsCommunicateMapper pqsCommunicateMapper;
private final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault());
@Autowired
private DeviceFeignClient deviceFeignClient;
@Override
public List<PqsCommunicateDto> getRawDataLatest(LineCountEvaluateParam lineParam) {
List<PqsCommunicateDto> result = new ArrayList<>();
@@ -96,6 +106,36 @@ public class InfluxdbPqsCommunicateImpl implements IPqsCommunicate {
return result;
}
@Override
public void insertion(PqsCommunicateDto pqsCommunicateDto) {
//获取最新一条数据
PqsCommunicate dto = new PqsCommunicate();
InfluxQueryWrapper influxQueryWrapper = new InfluxQueryWrapper(PqsCommunicate.class);
influxQueryWrapper.eq(PqsCommunicate::getDevId,pqsCommunicateDto.getDevId()).timeDesc().limit(1);
List<PqsCommunicate> pqsCommunicates = pqsCommunicateMapper.selectByQueryWrapper(influxQueryWrapper);
PqsCommunicate pqsCommunicate = new PqsCommunicate();
pqsCommunicate.setTime(LocalDateTime.parse(pqsCommunicateDto.getTime(), DATE_TIME_FORMATTER).atZone(ZoneId.systemDefault()).toInstant());
pqsCommunicate.setDevId(pqsCommunicateDto.getDevId());
pqsCommunicate.setType(pqsCommunicateDto.getType());
//如果不存数据或者状态不一样则插入数据
if(CollectionUtils.isEmpty(pqsCommunicates)|| !Objects.equals( pqsCommunicates.get(0).getType(),pqsCommunicateDto.getType())){
pqsCommunicateMapper.insertOne(pqsCommunicate);
//更新mysql数据
DevComFlagDTO devComFlagDTO = new DevComFlagDTO();
devComFlagDTO.setId(pqsCommunicateDto.getDevId());
devComFlagDTO.setDate(LocalDateTime.parse(pqsCommunicateDto.getTime(), DATE_TIME_FORMATTER));
devComFlagDTO.setStatus(pqsCommunicateDto.getType());
deviceFeignClient.updateDevComFlag(devComFlagDTO);
}
}
/**
* 按监测点集合、时间条件获取dataV分钟数据
* timeMap参数来判断是否进行数据出来 timeMap为空则不进行数据处理

View File

@@ -33,4 +33,9 @@ public class RelationPqsCommunicateImpl implements IPqsCommunicate {
public List<PqsCommunicateDto> getRawDataEnd(LineCountEvaluateParam lineParam) {
return Collections.emptyList();
}
@Override
public void insertion(PqsCommunicateDto pqsCommunicateDto) {
}
}