|
@@ -4,16 +4,16 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.huimv.acquisition.entity.EartagDataEntity;
|
|
|
import com.huimv.acquisition.entity.EartagRegisterEntity;
|
|
|
+import com.huimv.acquisition.entity.MovePigpenEntity;
|
|
|
import com.huimv.acquisition.mapper.*;
|
|
|
import com.huimv.acquisition.service.EartagRegisterService;
|
|
|
import com.huimv.acquisition.service.MovePigpenService;
|
|
|
import com.huimv.acquisition.socket.eartagrecive.util.DateUtilsPublic;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.text.DateFormat;
|
|
|
-import java.text.DecimalFormat;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -26,6 +26,8 @@ import java.util.Map;
|
|
|
* @Version 1.0.1
|
|
|
*/
|
|
|
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
public class RefreshEartagRegiest {
|
|
|
|
|
|
@Autowired
|
|
@@ -35,7 +37,7 @@ public class RefreshEartagRegiest {
|
|
|
private BasePigpenDao basePigpenDao;
|
|
|
|
|
|
@Autowired
|
|
|
- private CollectorRegisterDao collectorRegisterDao ;
|
|
|
+ private CollectorRegisterDao collectorRegisterDao;
|
|
|
|
|
|
@Autowired
|
|
|
private MovePigpenService movePigpenService;
|
|
@@ -49,33 +51,117 @@ public class RefreshEartagRegiest {
|
|
|
private EartagRegisterDao eartagRegisterDao;
|
|
|
|
|
|
|
|
|
- @Scheduled(cron = "0 0 2 * * ?")
|
|
|
- private void Settingregisting() {
|
|
|
+ //造数据---对于没有绑定的设备进行绑定
|
|
|
+ // 首先找注册了了但是没有绑定设备的进行绑定
|
|
|
+ //还要
|
|
|
+ //每天中午12点触发------处理开始上传但是从未注册过的耳标数据
|
|
|
|
|
|
-
|
|
|
- /*LambdaQueryWrapper<EartagRegisterEntity> lambdaQuery1 = Wrappers.lambdaQuery();
|
|
|
- //过滤时间
|
|
|
- lambdaQuery1.between(EartagRegisterEntity::getRegisterDate, new Date(), DateUtilsPublic.addDateHour(new Date(), 20));
|
|
|
+ @Scheduled(cron = "0 0 12 * * ?")
|
|
|
+ private void settingRegisting() {
|
|
|
+ LambdaQueryWrapper<EartagRegisterEntity> lambdaQuery1 = Wrappers.lambdaQuery();
|
|
|
+ //过滤时间--抓出时间段内所有这个数据
|
|
|
+ lambdaQuery1.between(EartagRegisterEntity::getRegisterDate, new Date(), DateUtilsPublic.addDateHour(new Date(), 24));
|
|
|
List<EartagRegisterEntity> eartagDateEntities1 = eartagRegisterDao.selectList(lambdaQuery1);
|
|
|
- //最近四小时
|
|
|
-
|
|
|
+ //最近二十小时数据--如果注册信息为空--那么说明这一条是还没有进行基站绑定的耳标
|
|
|
for (EartagRegisterEntity eartagRegisterEntity : eartagDateEntities1) {
|
|
|
-
|
|
|
if (eartagRegisterEntity.getDeviceCode() == null) {//为空开始绑定注册
|
|
|
+ LambdaQueryWrapper<EartagDataEntity> lambdaQuery2 = Wrappers.lambdaQuery();
|
|
|
+ //过滤时间----最近四小时的数据--耳标号为
|
|
|
+ lambdaQuery2.eq(EartagDataEntity::getEartagNo, eartagRegisterEntity.getEartagNo() );//--对应上耳标号和时间
|
|
|
+ lambdaQuery2.between(EartagDataEntity::getTime, new Date(), DateUtilsPublic.addDateHour(new Date(), 24));
|
|
|
+ List<EartagDataEntity> eartagDateEntities2 = eartagDataDao.selectList(lambdaQuery2);
|
|
|
+ Map<String, Integer> map = new HashMap<>();
|
|
|
+ for (EartagDataEntity eartagDataEntity : eartagDateEntities2) {
|
|
|
+ //对机器id进行分组
|
|
|
+ if (map.containsKey(eartagDataEntity.getDeviceCode())) {
|
|
|
+ Integer integer = map.get(eartagDataEntity.getDeviceCode());
|
|
|
+ map.put(eartagDataEntity.getDeviceCode(), integer + 1);
|
|
|
+ }
|
|
|
+ map.put(eartagDataEntity.getDeviceCode(), 1);
|
|
|
+ }
|
|
|
+ int a = 0;
|
|
|
+ String deviceCode =null;
|
|
|
+ //存在一个问题----假如由于两个基站相隔较近,数据绑定最多的机器反复切换,反复生成转舍记录应该如何处理(之前是通过上传的机器编码切换来实现转舍记录的展示的)
|
|
|
+ //上面的问题通过判断基站编码是否相近来处理
|
|
|
+ for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
|
|
+ //打印出来这个值,取出出现数量最多的机器,将其设置为绑定id
|
|
|
+ System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
|
|
|
+ if (a >= entry.getValue()) {
|
|
|
+
|
|
|
+ a = entry.getValue() ; //遍历出来最大的A 同时给B赋值到最新的entity
|
|
|
+ deviceCode = entry.getKey();//----上传最多的机器的机器id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //取到未注册的(耳标注册条) 开始填写上耳标号
|
|
|
+ eartagRegisterEntity.setDeviceCode(deviceCode);
|
|
|
+ eartagRegisterService.save(eartagRegisterEntity); //上面的计算获得出现次数最高的deviceCode 并且赋值给他--保存;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ //通过转舍记录来处理--如果转舍记录中的机器编码和注册表中的不相同就进行处理
|
|
|
+ //每天中午15点触发------处理开始上传但是从未注册过的耳标数据
|
|
|
+ @Scheduled(cron = "0 0 15 * * ?")
|
|
|
+ private void changeRegistingByMovePenRecord() {
|
|
|
+ LambdaQueryWrapper<MovePigpenEntity> lambdaQuery1 = Wrappers.lambdaQuery();
|
|
|
+ //过滤时间--抓出时间段内所有这个数据
|
|
|
+ lambdaQuery1.between(MovePigpenEntity::getMoveDate, new Date(), DateUtilsPublic.addDateHour(new Date(), 24));
|
|
|
+ List<MovePigpenEntity> MovePenEntities1 = movePigpenDao.selectList(lambdaQuery1);
|
|
|
|
|
|
+ //最近二十小时数据--如果有转舍情况发生--时间段内的转舍后机器id与注册表中的是否相同,不相同则说明有问题,进行校准
|
|
|
+ //需要更新转舍记录和注册表中的两个数据--
|
|
|
+
|
|
|
+ for (MovePigpenEntity movePenEntity : MovePenEntities1) {
|
|
|
+ LambdaQueryWrapper<EartagRegisterEntity> lambdaQuery8 = Wrappers.lambdaQuery();
|
|
|
+ //过滤时间--抓出时间段内所有这个数据
|
|
|
+ lambdaQuery8.eq(EartagRegisterEntity::getEartagNo, movePenEntity.getEartagNo() );
|
|
|
+ EartagRegisterEntity eartagRegisterEntity = eartagRegisterDao.selectOne(lambdaQuery8);
|
|
|
+
|
|
|
+ if (eartagRegisterEntity.getDeviceCode()!= movePenEntity.getDeviceCode()) {//为空开始绑定注册
|
|
|
LambdaQueryWrapper<EartagDataEntity> lambdaQuery2 = Wrappers.lambdaQuery();
|
|
|
- //过滤时间----最近四小时的数据
|
|
|
- lambdaQuery2.between(EartagDataEntity::getTime, new Date(), DateUtilsPublic.addDateHour(new Date(), 20));
|
|
|
+ //过滤时间----最近四小时的数据--耳标号为
|
|
|
+ lambdaQuery2.eq(EartagDataEntity::getEartagNo, eartagRegisterEntity.getEartagNo() );//--对应上耳标号和时间
|
|
|
+ lambdaQuery2.between(EartagDataEntity::getTime, new Date(), DateUtilsPublic.addDateHour(new Date(), 24));
|
|
|
List<EartagDataEntity> eartagDateEntities2 = eartagDataDao.selectList(lambdaQuery2);
|
|
|
- Map map = new HashMap();
|
|
|
- for (EartagDataEntity Map map = new HashMap(); :eartagDateEntities2){
|
|
|
+ Map<String, Integer> map = new HashMap<>();
|
|
|
+ for (EartagDataEntity eartagDataEntity : eartagDateEntities2) {
|
|
|
//对机器id进行分组
|
|
|
-
|
|
|
-*/
|
|
|
+ if (map.containsKey(eartagDataEntity.getDeviceCode())) {
|
|
|
+ Integer integer = map.get(eartagDataEntity.getDeviceCode());
|
|
|
+ map.put(eartagDataEntity.getDeviceCode(), integer + 1);
|
|
|
+ }
|
|
|
+ map.put(eartagDataEntity.getDeviceCode(), 1);
|
|
|
}
|
|
|
+ int a = 0;
|
|
|
+ String deviceCode =null;
|
|
|
+ //存在一个问题----假如由于两个基站相隔较近,数据绑定最多的机器反复切换,反复生成转舍记录应该如何处理(之前是通过上传的机器编码切换来实现转舍记录的展示的)
|
|
|
+ //上面的问题通过判断基站编码是否相近来处理
|
|
|
+ for (Map.Entry<String, Integer> entry : map.entrySet()) {
|
|
|
+ //打印出来这个值,取出出现数量最多的机器,将其设置为绑定id
|
|
|
+ System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue());
|
|
|
+ if (a >= entry.getValue()) {
|
|
|
+ a = entry.getValue() ; //遍历出来最大的A 同时给B赋值到最新的entity
|
|
|
+ deviceCode = entry.getKey();//----上传最多的机器的机器id
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //更新存储的编码
|
|
|
+ movePenEntity.setDeviceCode(deviceCode);
|
|
|
+ movePigpenService.save(movePenEntity);
|
|
|
+
|
|
|
+ //取到未注册的(耳标注册条) 开始填写上耳标号
|
|
|
+ eartagRegisterEntity.setDeviceCode(deviceCode);
|
|
|
+ eartagRegisterService.save(eartagRegisterEntity); //上面的计算获得出现次数最高的deviceCode 并且赋值给他--保存;
|
|
|
+
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
|
|