面源、畜禽数据根据设备监测项配置生成数据
This commit is contained in:
parent
cd5d9b4206
commit
5d59fa7cbf
|
|
@ -1,5 +1,6 @@
|
|||
package com.lanhai.service;
|
||||
|
||||
import com.lanhai.entity.SurvDeviceDeploy;
|
||||
import com.lanhai.entity.SurvHisdataLivestockwater;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lanhai.entity.SurvTransdataLivestockwater;
|
||||
|
|
@ -12,5 +13,5 @@ import com.lanhai.entity.SurvTransdataLivestockwater;
|
|||
*/
|
||||
public interface ISurvHisdataLivestockwaterService extends IService<SurvHisdataLivestockwater> {
|
||||
|
||||
SurvTransdataLivestockwater genData(String deployCode);
|
||||
SurvTransdataLivestockwater genData(SurvDeviceDeploy deploy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.lanhai.service;
|
||||
|
||||
import com.lanhai.entity.SurvDeviceDeploy;
|
||||
import com.lanhai.entity.SurvHisdataOrientwater;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.lanhai.entity.SurvTransdataOrientwater;
|
||||
|
|
@ -12,5 +13,5 @@ import com.lanhai.entity.SurvTransdataOrientwater;
|
|||
*/
|
||||
public interface ISurvHisdataOrientwaterService extends IService<SurvHisdataOrientwater> {
|
||||
|
||||
SurvTransdataOrientwater genData(String deployCode);
|
||||
SurvTransdataOrientwater genData(SurvDeviceDeploy deploy);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.lanhai.service.Impl;
|
|||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.lanhai.constant.PollutionConstants;
|
||||
import com.lanhai.entity.ScEquZhibiao;
|
||||
import com.lanhai.entity.SurvDeviceDeploy;
|
||||
import com.lanhai.entity.SurvHisdataLivestockwater;
|
||||
import com.lanhai.entity.SurvTransdataLivestockwater;
|
||||
import com.lanhai.mapper.SurvHisdataLivestockwaterMapper;
|
||||
|
|
@ -10,6 +12,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.lanhai.util.BigDecimalRandomAdjuster;
|
||||
import com.lanhai.util.DateUtils;
|
||||
import com.lanhai.util.SpringBeanUtils;
|
||||
import com.lanhai.util.TUtil;
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -17,8 +21,7 @@ import org.springframework.context.annotation.Lazy;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -33,13 +36,32 @@ public class SurvHisdataLivestockwaterServiceImpl extends ServiceImpl<SurvHisdat
|
|||
@Autowired
|
||||
@Lazy
|
||||
private SurvTransdataLivestockwaterServiceImpl survTransdataLivestockwaterServiceImpl;
|
||||
@Autowired
|
||||
@Lazy
|
||||
private ScEquZhibiaoServiceImpl zhibiaoService;
|
||||
|
||||
@Override
|
||||
public SurvTransdataLivestockwater genData(String deployCode) {
|
||||
public SurvTransdataLivestockwater genData(SurvDeviceDeploy deploy) {
|
||||
String deployCode = deploy.getDeployCode();
|
||||
log.warn("=================畜禽逻辑===================="+deployCode);
|
||||
try {
|
||||
// survTransdataLivestockwaterServiceImpl = SpringBeanUtils.getBean("SurvTransdataLivestockwaterServiceImpl", SurvTransdataLivestockwaterServiceImpl.class);
|
||||
|
||||
SurvTransdataLivestockwater newestData = survTransdataLivestockwaterServiceImpl.getOneByDeviceCode(deployCode);
|
||||
|
||||
//设备监测配置
|
||||
List<ScEquZhibiao> zhibiaos = zhibiaoService.getListByEquid(deploy.getId());
|
||||
Map<String,ScEquZhibiao> zhibiaoMap = new HashMap<>();
|
||||
if(!zhibiaos.isEmpty()){
|
||||
for (ScEquZhibiao zhibiao : zhibiaos) {
|
||||
zhibiaoMap.put(zhibiao.getEntityField(),zhibiao);
|
||||
}
|
||||
}else{
|
||||
log.error("==========设备:{},编号:{}未配置指标==============,跳过",deploy.getDeployDes(),deploy.getDeployCode());
|
||||
XxlJobHelper.log("==========设备:{},编号:{}未配置指标==============,跳过",deploy.getDeployDes(),deploy.getDeployCode());
|
||||
return null;
|
||||
}
|
||||
|
||||
String orgId = null;
|
||||
if (newestData != null) {
|
||||
orgId = newestData.getId();
|
||||
|
|
@ -55,6 +77,11 @@ public class SurvHisdataLivestockwaterServiceImpl extends ServiceImpl<SurvHisdat
|
|||
isNegative = true;
|
||||
}
|
||||
}
|
||||
else if(StringUtils.isNotBlank(newestData.getDataWaterNo())){//跳过负数
|
||||
if(newestData.getDataWaterNo().contains("-") || newestData.getDataWaterNo().length()>10){
|
||||
isNegative = true;
|
||||
}
|
||||
}
|
||||
else if(StringUtils.isNotBlank(newestData.getDataWaterNh()) ){//跳过负数
|
||||
if(newestData.getDataWaterNh().contains("-") || newestData.getDataWaterNh().length()>10){
|
||||
isNegative = true;
|
||||
|
|
@ -82,6 +109,7 @@ public class SurvHisdataLivestockwaterServiceImpl extends ServiceImpl<SurvHisdat
|
|||
newestData = new SurvTransdataLivestockwater();
|
||||
newestData.setDataWaterTp("10.1785");
|
||||
newestData.setDataWaterTn("49.6451");
|
||||
newestData.setDataWaterNo("3.8037");
|
||||
newestData.setDataWaterNh("49.7743");
|
||||
newestData.setDataWaterCod("501.5000");
|
||||
}
|
||||
|
|
@ -100,12 +128,25 @@ public class SurvHisdataLivestockwaterServiceImpl extends ServiceImpl<SurvHisdat
|
|||
hisdataLivestockwater.setCreatedBy("ftask");
|
||||
hisdataLivestockwater.setCreateTime(nowTime);
|
||||
hisdataLivestockwater.setIsDel(0);
|
||||
hisdataLivestockwater.setDataWaterTp(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTp()), fixedRange, scale));
|
||||
hisdataLivestockwater.setDataWaterTn(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTn()), fixedRange, scale));
|
||||
|
||||
hisdataLivestockwater.setDataDateTime(nowTime);
|
||||
hisdataLivestockwater.setDataGatherType("realTime");
|
||||
hisdataLivestockwater.setDataWaterNh(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterNh()), fixedRange, scale));
|
||||
hisdataLivestockwater.setDataWaterCod(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterCod()), fixedRange, scale));
|
||||
|
||||
// hisdataLivestockwater.setDataWaterTp(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTp()), fixedRange, scale));
|
||||
// hisdataLivestockwater.setDataWaterTn(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTn()), fixedRange, scale));
|
||||
// hisdataLivestockwater.setDataWaterNh(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterNh()), fixedRange, scale));
|
||||
// hisdataLivestockwater.setDataWaterCod(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterCod()), fixedRange, scale));
|
||||
|
||||
for (ScEquZhibiao zhibiao : zhibiaos) {
|
||||
String vals = TUtil.getFieldValue(newestData,zhibiao.getEntityField(),String.class);
|
||||
if(StringUtils.isNotBlank(vals)){
|
||||
String correctVal = BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(vals), fixedRange, scale);
|
||||
TUtil.setFieldValue(hisdataLivestockwater,zhibiao.getEntityField(),correctVal);
|
||||
}else{
|
||||
log.error("==========设备:{},编号:{}指标:{}配置错误==============,跳过",deploy.getDeployDes(),deploy.getDeployCode(),zhibiao.getEntityField());
|
||||
XxlJobHelper.log("==========设备:{},编号:{}指标:{}配置错误==============,跳过",deploy.getDeployDes(),deploy.getDeployCode(),zhibiao.getEntityField());
|
||||
}
|
||||
}
|
||||
|
||||
hisdataLivestockwater.setDeployCode(deployCode);
|
||||
hisdataLivestockwater.setFluidLevel(waterFluidLevel[values]);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.lanhai.service.Impl;
|
|||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.lanhai.constant.PollutionConstants;
|
||||
import com.lanhai.entity.ScEquZhibiao;
|
||||
import com.lanhai.entity.SurvDeviceDeploy;
|
||||
import com.lanhai.entity.SurvHisdataOrientwater;
|
||||
import com.lanhai.entity.SurvTransdataOrientwater;
|
||||
import com.lanhai.mapper.SurvHisdataOrientwaterMapper;
|
||||
|
|
@ -12,6 +14,8 @@ import com.lanhai.service.ISurvTransdataOrientwaterService;
|
|||
import com.lanhai.util.BigDecimalRandomAdjuster;
|
||||
import com.lanhai.util.DateUtils;
|
||||
import com.lanhai.util.SpringBeanUtils;
|
||||
import com.lanhai.util.TUtil;
|
||||
import com.xxl.job.core.context.XxlJobHelper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -21,8 +25,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
|
@ -41,12 +44,29 @@ public class SurvHisdataOrientwaterServiceImpl extends ServiceImpl<SurvHisdataOr
|
|||
@Lazy
|
||||
private SurvTransdataOrientwaterServiceImpl orientwaterService ;
|
||||
|
||||
@Autowired
|
||||
@Lazy
|
||||
private ScEquZhibiaoServiceImpl zhibiaoService;
|
||||
|
||||
|
||||
@Override
|
||||
public SurvTransdataOrientwater genData(String deployCode) {
|
||||
public SurvTransdataOrientwater genData(SurvDeviceDeploy deploy) {
|
||||
try {
|
||||
String deployCode = deploy.getDeployCode();
|
||||
log.warn("=================面源逻辑====================" + deployCode);
|
||||
SurvTransdataOrientwater newestData = orientwaterService.getOneByDeviceCode(deployCode);
|
||||
//设备监测配置
|
||||
List<ScEquZhibiao> zhibiaos = zhibiaoService.getListByEquid(deploy.getId());
|
||||
Map<String,ScEquZhibiao> zhibiaoMap = new HashMap<>();
|
||||
if(!zhibiaos.isEmpty()){
|
||||
for (ScEquZhibiao zhibiao : zhibiaos) {
|
||||
zhibiaoMap.put(zhibiao.getEntityField(),zhibiao);
|
||||
}
|
||||
}else{
|
||||
log.error("==========设备:{},编号:{}未配置指标==============,跳过",deploy.getDeployDes(),deploy.getDeployCode());
|
||||
XxlJobHelper.log("==========设备:{},编号:{}未配置指标==============,跳过",deploy.getDeployDes(),deploy.getDeployCode());
|
||||
return null;
|
||||
}
|
||||
String orgId = null;
|
||||
if (newestData != null) {
|
||||
orgId = newestData.getId();
|
||||
|
|
@ -62,16 +82,22 @@ public class SurvHisdataOrientwaterServiceImpl extends ServiceImpl<SurvHisdataOr
|
|||
isNegative = true;
|
||||
}
|
||||
}
|
||||
// else if(StringUtils.isNotBlank(newestData.getDataWaterNo())){//跳过负数
|
||||
// if(newestData.getDataWaterNo().contains("-") || newestData.getDataWaterNo().length()>10){
|
||||
// isNegative = true;
|
||||
// }
|
||||
// }
|
||||
else if(StringUtils.isNotBlank(newestData.getDataWaterNo())){//跳过负数
|
||||
if(newestData.getDataWaterNo().contains("-") || newestData.getDataWaterNo().length()>10){
|
||||
isNegative = true;
|
||||
}
|
||||
}
|
||||
else if(StringUtils.isNotBlank(newestData.getDataWaterNh())){//跳过负数
|
||||
if(newestData.getDataWaterNh().contains("-") || newestData.getDataWaterNh().length()>10){
|
||||
isNegative = true;
|
||||
}
|
||||
}
|
||||
else if(StringUtils.isNotBlank(newestData.getDataWaterCod())){//跳过负数
|
||||
if(newestData.getDataWaterCod().contains("-") || newestData.getDataWaterCod().length()>10){
|
||||
isNegative = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(!isNegative) {//非负数时,检查时间是否过期,否则直接自动覆盖此数据
|
||||
if (newestData.getDataDateTime() != null) {
|
||||
long secs = DateUtils.getSecondsDiff(newestData.getDataDateTime(), new Date());
|
||||
|
|
@ -89,6 +115,7 @@ public class SurvHisdataOrientwaterServiceImpl extends ServiceImpl<SurvHisdataOr
|
|||
newestData.setDataWaterTp("1.0063");
|
||||
newestData.setDataWaterTn("2.1114");
|
||||
newestData.setDataWaterNo("3.8037");
|
||||
newestData.setDataWaterNh("49.7743");
|
||||
newestData.setDataWaterCod("501.5000");
|
||||
if ("xzp-water-02".equals(deployCode)) {
|
||||
newestData.setDataWaterNo("16.3254");
|
||||
|
|
@ -116,12 +143,27 @@ public class SurvHisdataOrientwaterServiceImpl extends ServiceImpl<SurvHisdataOr
|
|||
hisdataOrientwater.setCreatedBy("ftask");
|
||||
hisdataOrientwater.setCreateTime(nowTime);
|
||||
hisdataOrientwater.setIsDel(0);
|
||||
hisdataOrientwater.setDataWaterTp(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTp()), fixedRange, scale));
|
||||
hisdataOrientwater.setDataWaterTn(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTn()), fixedRange, scale));
|
||||
|
||||
hisdataOrientwater.setDataDateTime(nowTime);
|
||||
hisdataOrientwater.setDataGatherType("realTime");
|
||||
|
||||
// hisdataOrientwater.setDataWaterTp(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTp()), fixedRange, scale));
|
||||
// hisdataOrientwater.setDataWaterTn(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterTn()), fixedRange, scale));
|
||||
// hisdataOrientwater.setDataWaterNo(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterNo()), fixedRange, scale));
|
||||
hisdataOrientwater.setDataWaterCod(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterCod()), fixedRange, scale));
|
||||
// hisdataOrientwater.setDataWaterCod(BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(newestData.getDataWaterCod()), fixedRange, scale));
|
||||
|
||||
for (ScEquZhibiao zhibiao : zhibiaos) {
|
||||
String vals = TUtil.getFieldValue(newestData,zhibiao.getEntityField(),String.class);
|
||||
if(StringUtils.isNotBlank(vals)){
|
||||
String correctVal = BigDecimalRandomAdjuster.randomAdjustByFixedRange(new BigDecimal(vals), fixedRange, scale);
|
||||
TUtil.setFieldValue(hisdataOrientwater,zhibiao.getEntityField(),correctVal);
|
||||
}else{
|
||||
log.error("==========设备:{},编号:{}指标:{}配置错误==============,跳过",deploy.getDeployDes(),deploy.getDeployCode(),zhibiao.getEntityField());
|
||||
XxlJobHelper.log("==========设备:{},编号:{}指标:{}配置错误==============,跳过",deploy.getDeployDes(),deploy.getDeployCode(),zhibiao.getEntityField());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
hisdataOrientwater.setDeployCode(deployCode);
|
||||
hisdataOrientwater.setDataWaterTpSy(waterTpSy[values]);
|
||||
hisdataOrientwater.setDataWaterTpLd(waterTpLd[values]);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.lanhai.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @createTime 2023年07月26日 20:54:00
|
||||
|
|
@ -57,4 +59,93 @@ public class TUtil {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据字段名称获取实体对象的字段值
|
||||
* @param entity 实体对象
|
||||
* @param fieldName 字段名称
|
||||
* @return 字段值
|
||||
*/
|
||||
public static Object getFieldValue(Object entity, String fieldName) {
|
||||
if (entity == null || fieldName == null || fieldName.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
Field field = getField(entity.getClass(), fieldName);
|
||||
if (field == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
return field.get(entity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("获取字段值失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字段(包括父类的字段)
|
||||
* @param clazz 类
|
||||
* @param fieldName 字段名称
|
||||
* @return 字段对象
|
||||
*/
|
||||
private static Field getField(Class<?> clazz, String fieldName) {
|
||||
for (Class<?> superClass = clazz; superClass != Object.class; superClass = superClass.getSuperclass()) {
|
||||
try {
|
||||
return superClass.getDeclaredField(fieldName);
|
||||
} catch (NoSuchFieldException e) {
|
||||
// 继续在父类中查找
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据字段名称获取实体对象的字段值(带类型转换)
|
||||
* @param entity 实体对象
|
||||
* @param fieldName 字段名称
|
||||
* @param clazz 目标类型
|
||||
* @return 转换后的字段值
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getFieldValue(Object entity, String fieldName, Class<T> clazz) {
|
||||
Object value = getFieldValue(entity, fieldName);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (clazz.isInstance(value)) {
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
// 简单的类型转换(可根据需要扩展)
|
||||
try {
|
||||
if (clazz == String.class) {
|
||||
return (T) String.valueOf(value);
|
||||
}
|
||||
// 可以添加更多类型转换逻辑
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("类型转换失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
throw new ClassCastException("无法将 " + value.getClass() + " 转换为 " + clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取实体对象的所有字段名称
|
||||
* @param clazz 实体类
|
||||
* @return 字段名称列表
|
||||
*/
|
||||
public static List<String> getFieldNames(Class<?> clazz) {
|
||||
List<String> fieldNames = new ArrayList<>();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
fieldNames.add(field.getName());
|
||||
}
|
||||
return fieldNames;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue