diff --git a/src/main/java/com/lanhai/service/ISurvHisdataLivestockwaterService.java b/src/main/java/com/lanhai/service/ISurvHisdataLivestockwaterService.java index 697ea39..21eb470 100644 --- a/src/main/java/com/lanhai/service/ISurvHisdataLivestockwaterService.java +++ b/src/main/java/com/lanhai/service/ISurvHisdataLivestockwaterService.java @@ -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 { - SurvTransdataLivestockwater genData(String deployCode); + SurvTransdataLivestockwater genData(SurvDeviceDeploy deploy); } diff --git a/src/main/java/com/lanhai/service/ISurvHisdataOrientwaterService.java b/src/main/java/com/lanhai/service/ISurvHisdataOrientwaterService.java index 3d9d30a..64d67e9 100644 --- a/src/main/java/com/lanhai/service/ISurvHisdataOrientwaterService.java +++ b/src/main/java/com/lanhai/service/ISurvHisdataOrientwaterService.java @@ -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 { - SurvTransdataOrientwater genData(String deployCode); + SurvTransdataOrientwater genData(SurvDeviceDeploy deploy); } diff --git a/src/main/java/com/lanhai/service/Impl/SurvHisdataLivestockwaterServiceImpl.java b/src/main/java/com/lanhai/service/Impl/SurvHisdataLivestockwaterServiceImpl.java index c4ce093..d032e74 100644 --- a/src/main/java/com/lanhai/service/Impl/SurvHisdataLivestockwaterServiceImpl.java +++ b/src/main/java/com/lanhai/service/Impl/SurvHisdataLivestockwaterServiceImpl.java @@ -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.*; /** *

@@ -33,13 +36,32 @@ public class SurvHisdataLivestockwaterServiceImpl extends ServiceImpl zhibiaos = zhibiaoService.getListByEquid(deploy.getId()); + Map 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 ServiceImpl10){ + 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 @@ -41,12 +44,29 @@ public class SurvHisdataOrientwaterServiceImpl extends ServiceImpl zhibiaos = zhibiaoService.getListByEquid(deploy.getId()); + Map 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 ServiceImpl10){ -// 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 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 getFieldValue(Object entity, String fieldName, Class 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 getFieldNames(Class clazz) { + List fieldNames = new ArrayList<>(); + Field[] fields = clazz.getDeclaredFields(); + for (Field field : fields) { + fieldNames.add(field.getName()); + } + return fieldNames; + } + }