|
@@ -70,6 +70,12 @@ public class EartagServiceImpl implements IEartagService {
|
|
|
private EartagEartagRegister2EntityRepo eartagEartagRegister2EntityRepo;
|
|
|
@Autowired
|
|
|
private EartagOnlineStatusEntityRepo eartagOnlineStatusEntityRepo;
|
|
|
+ @Autowired
|
|
|
+ private EartagHourActEntityRepo eartagHourActEntityRepo;
|
|
|
+ @Autowired
|
|
|
+ private EartagResetEntityRepo eartagResetEntityRepo;
|
|
|
+ @Autowired
|
|
|
+ private EartagResetCountEntityRepo eartagResetCountEntityRepo;
|
|
|
|
|
|
@Override
|
|
|
public void handleEartag(JSONObject dataJo) throws ParseException {
|
|
@@ -88,6 +94,9 @@ public class EartagServiceImpl implements IEartagService {
|
|
|
//获取牧场id
|
|
|
String farmId = deviceService.getFarmIdByDeviceCode(deviceCode);
|
|
|
if (farmId != null) {
|
|
|
+ //{计算小时运动量}
|
|
|
+ countHourAct(dataJo,nowTimestamp, todayDate, farmId);
|
|
|
+
|
|
|
//{保存耳标流水(所有耳标数据,可能重复上传)}
|
|
|
saveEartagFlow(dataJo, nowTimestamp, todayDate, farmId);
|
|
|
|
|
@@ -97,6 +106,9 @@ public class EartagServiceImpl implements IEartagService {
|
|
|
//{更新设备注册信息}
|
|
|
updateDeviceRegister(deviceCode, nowTimestamp, todayDate, farmId);
|
|
|
|
|
|
+ //{计算小时运动量}
|
|
|
+// countHourAct(dataJo,nowTimestamp, todayDate, farmId);
|
|
|
+
|
|
|
//{更新耳标注册信息}
|
|
|
// updateEartagRegister(earmark, deviceCode, bat, nowTimestamp, todayDate, farmId);
|
|
|
|
|
@@ -128,6 +140,98 @@ public class EartagServiceImpl implements IEartagService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 计算小时运动量
|
|
|
+ private void countHourAct(JSONObject eartagJo, Timestamp nowTimestamp, java.sql.Date todayDate, String farmId) {
|
|
|
+ DateUtil du = new DateUtil();
|
|
|
+ int nowHour = du.getNowHour();
|
|
|
+
|
|
|
+ int eartagOffLineTime = 24;
|
|
|
+ Optional<SysBaseConfigEntity> optionalConfig = sysBaseConfigEntityRepo.getConfigValue("dropDataEartagOffLineTime");
|
|
|
+ if (optionalConfig.isPresent()) {
|
|
|
+ eartagOffLineTime = Integer.parseInt(optionalConfig.get().getConfigValue());
|
|
|
+ log.info("耳标离线过程丢弃数据时长=" + eartagOffLineTime);
|
|
|
+ } else {
|
|
|
+ log.error("耳标离线过程丢弃数据时长属性未配置.");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String earmark = eartagJo.getString("earmark");
|
|
|
+ int act = Integer.parseInt(eartagJo.getString("act"));
|
|
|
+ System.out.println("本次运动量="+act);
|
|
|
+ //
|
|
|
+ Optional<EartagData2Entity> optionEartagData = eartagData2Repo.getLastByEarmark(earmark,farmId);
|
|
|
+ if(!optionEartagData.isPresent()){
|
|
|
+ log.info("该耳标号无相关数据.["+earmark+"]");
|
|
|
+ }
|
|
|
+ EartagData2Entity eartagData2Entity = optionEartagData.get();
|
|
|
+ Integer lastAct = eartagData2Entity.getAct();
|
|
|
+ System.out.println("上次运动量="+lastAct);
|
|
|
+ Timestamp lastAddTime = eartagData2Entity.getAddTime();
|
|
|
+ long timeDiff = nowTimestamp.getTime() - lastAddTime.getTime();
|
|
|
+ if(timeDiff/(1000*60*60) < eartagOffLineTime){
|
|
|
+ int act1 = 0;
|
|
|
+ boolean resetStatus = false;
|
|
|
+ if(act < lastAct){
|
|
|
+ act1 = act;
|
|
|
+ resetStatus = true;
|
|
|
+ }else{
|
|
|
+ act1 = act - lastAct;
|
|
|
+ }
|
|
|
+ System.out.println("本次运动量增量="+act1);
|
|
|
+ //{保存耳标小时运动量}
|
|
|
+ saveEartagHourAct(farmId,earmark,act1,nowHour,todayDate);
|
|
|
+ //{保存耳标复位记录}
|
|
|
+ saveEartagReset(resetStatus,farmId,earmark,nowTimestamp,todayDate);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //{保存耳标复位记录}
|
|
|
+ private void saveEartagReset(boolean resetStatus, String farmId, String earmark, Timestamp nowTimestamp, java.sql.Date todayDate) {
|
|
|
+ if(resetStatus){
|
|
|
+ // 保存复位记录
|
|
|
+ EartagResetEntity eartagResetEntity = new EartagResetEntity();
|
|
|
+ eartagResetEntity.setEarmark(earmark);
|
|
|
+ eartagResetEntity.setAddDate(todayDate);
|
|
|
+ eartagResetEntity.setResetTime(nowTimestamp);
|
|
|
+ eartagResetEntity.setFarmCode(farmId);
|
|
|
+ eartagResetEntityRepo.save(eartagResetEntity);
|
|
|
+
|
|
|
+ // 泊村复位统计次数
|
|
|
+ EartagResetCountEntity eartagResetCountEntity = new EartagResetCountEntity();
|
|
|
+ eartagResetCountEntity.setEarmark(earmark);
|
|
|
+ eartagResetCountEntity.setFarmCode(farmId);
|
|
|
+ eartagResetCountEntity.setAddDate(todayDate);
|
|
|
+ Example<EartagResetCountEntity> example = Example.of(eartagResetCountEntity);
|
|
|
+ Optional<EartagResetCountEntity> optionEartagResetCountEntity = eartagResetCountEntityRepo.findOne(example);
|
|
|
+ if(!optionEartagResetCountEntity.isPresent()){
|
|
|
+ eartagResetCountEntity.setTimes(1);
|
|
|
+ eartagResetCountEntityRepo.save(eartagResetCountEntity);
|
|
|
+ }else{
|
|
|
+ EartagResetCountEntity existEartagResetCountEntity = optionEartagResetCountEntity.get();
|
|
|
+ existEartagResetCountEntity.setTimes(existEartagResetCountEntity.getTimes()+1);
|
|
|
+ eartagResetCountEntityRepo.save(existEartagResetCountEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // {保存耳标小时运动量}
|
|
|
+ private void saveEartagHourAct(String farmId, String earmark, int act1, int nowHour, java.sql.Date todayDate) {
|
|
|
+ Optional<EartagHourActEntity> optionalHourAct = eartagHourActEntityRepo.findByFarmIdAndEarmarkAndHourAndDate(farmId,earmark,nowHour,todayDate);
|
|
|
+ if(!optionalHourAct.isPresent()){
|
|
|
+ EartagHourActEntity newEartagHourActEntity = new EartagHourActEntity();
|
|
|
+ newEartagHourActEntity.setFarmCode(farmId);
|
|
|
+ newEartagHourActEntity.setEarmark(earmark);
|
|
|
+ newEartagHourActEntity.setAddDate(todayDate);
|
|
|
+ newEartagHourActEntity.setHour(nowHour);
|
|
|
+ newEartagHourActEntity.setAct(act1);
|
|
|
+ eartagHourActEntityRepo.save(newEartagHourActEntity);
|
|
|
+ }else{
|
|
|
+ EartagHourActEntity eartagHourActEntity = optionalHourAct.get();
|
|
|
+ eartagHourActEntity.setAct(eartagHourActEntity.getAct()+act1);
|
|
|
+ eartagHourActEntityRepo.save(eartagHourActEntity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 更新耳标连线状态
|
|
|
private void updateEartagLiveStatus(String earmark, String deviceCode, String todayDateText, java.sql.Date todayDate, Timestamp nowTimestamp, JSONObject dataJo, String farmId) {
|
|
|
// 通过耳标注册表查找耳标所属单元
|
|
@@ -680,21 +784,14 @@ public class EartagServiceImpl implements IEartagService {
|
|
|
*/
|
|
|
public void updateEartagRegister2(String earmark, String deviceCode, String bat, Timestamp nowTimestamp, java.sql.Date todayDate, String farmId, JSONObject eartagJo) {
|
|
|
System.out.println(" ============================ 更新耳标编码 ============================ ");
|
|
|
- if (deviceCode.trim().equalsIgnoreCase("330112002000002")) {
|
|
|
- System.out.println("deviceCode=" + deviceCode + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
|
- }
|
|
|
EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getByDeviceCode(deviceCode);
|
|
|
Integer unitId = deviceRegisterEntity.getUnitId();
|
|
|
Integer pigpenId = deviceRegisterEntity.getPigpenId();
|
|
|
- System.out.println("unitId>>" + unitId);
|
|
|
- System.out.println("pigpenId>>" + pigpenId);
|
|
|
List<BasePigpenEntity> basePigpenEntityList = basePigpenRepo.getPigpenByPigpenIdAndUnitId(pigpenId, unitId);
|
|
|
- System.out.println("basePigpenEntityList.size>>" + basePigpenEntityList.size());
|
|
|
if (basePigpenEntityList.size() == 0) {
|
|
|
log.error("栋舍不存在[" + pigpenId + "," + unitId + "].");
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
//-- 获取栋舍名称--//
|
|
|
String pigpenName = "";
|
|
|
String unitName = "";
|
|
@@ -709,12 +806,8 @@ public class EartagServiceImpl implements IEartagService {
|
|
|
stageCode = basePigpenEntity.getStageCode();
|
|
|
}
|
|
|
}
|
|
|
- System.out.println("pigpenName>>" + pigpenName);
|
|
|
- System.out.println("unitName>>" + unitName);
|
|
|
- System.out.println("stageCode>>" + stageCode);
|
|
|
//-- 获取阶段名称 --//
|
|
|
Optional<BizBaseStageEntity> optionalBizBaseStageEntity = bizBaseStageRepo.getStageByStageCode(stageCode);
|
|
|
- System.out.println("optionalBizBaseStageEntity.isPresent()>>" + optionalBizBaseStageEntity.isPresent());
|
|
|
if (!optionalBizBaseStageEntity.isPresent()) {
|
|
|
log.error("该阶段不存在[" + stageCode + "].");
|
|
|
return;
|
|
@@ -728,18 +821,11 @@ public class EartagServiceImpl implements IEartagService {
|
|
|
Integer registerType = 1;
|
|
|
Integer activeStatus = 1;
|
|
|
Integer liveStatus = 1; //
|
|
|
- System.out.println("deviceCode=" + deviceCode);
|
|
|
- System.out.println("earmark=" + earmark);
|
|
|
- System.out.println("farmId=" + farmId);
|
|
|
-// EartagEartagRegister2Entity eartagRegisterEntity = eartagEartagRegister2EntityRepo.getOneByEarmark(earmark, farmId);
|
|
|
EartagEartagRegister2Entity eartagRegisterEntity = eartagEartagRegister2EntityRepo.getOneByEarmark2(earmark);
|
|
|
- System.out.println("判断是否有耳标注册信息 eartagRegisterEntity=" + eartagRegisterEntity.toString());
|
|
|
if (eartagRegisterEntity == null) {
|
|
|
- System.out.println("新建耳标数据...");
|
|
|
//{新建耳标注册信息}
|
|
|
newEartagRegister2(earmark, nowTimestamp, deviceCode, registerType, activeStatus, liveStatus, bat, todayDate, farmId, eartagJo, stageCode, stageName, pigpenId, pigpenName, unitId, unitName, deviceRegisterEntity);
|
|
|
} else {
|
|
|
- System.out.println("更新耳标数据...");
|
|
|
eartagRegisterEntity.setLastTime(nowTimestamp);
|
|
|
eartagRegisterEntity.setLastDevice(deviceCode);
|
|
|
eartagRegisterEntity.setActiveStatus(activeStatus);
|
|
@@ -759,7 +845,6 @@ public class EartagServiceImpl implements IEartagService {
|
|
|
eartagRegisterEntity.setOther(eartagJo.getString("other"));
|
|
|
eartagRegisterEntity.setFarmId(farmId);
|
|
|
eartagRegisterEntity.setLiveStatus(1);
|
|
|
-
|
|
|
eartagEartagRegister2EntityRepo.saveAndFlush(eartagRegisterEntity);
|
|
|
//更新耳标注册消息缓存
|
|
|
cacheService.putEartagRegister(earmark, eartagRegisterEntity);
|
|
@@ -999,7 +1084,7 @@ public class EartagServiceImpl implements IEartagService {
|
|
|
//更新耳标注册表中的运动量数据
|
|
|
EartagEartagRegister2Entity eartagRegister2Entity = eartagEartagRegister2EntityRepo.getOneByEarmark(earmark, farmId);
|
|
|
if (eartagRegister2Entity != null) {
|
|
|
- System.out.println("更新耳标=" + earmark + "," + act1);
|
|
|
+// System.out.println("更新耳标=" + earmark + "," + act1);
|
|
|
eartagRegister2Entity.setAct(act1);
|
|
|
eartagEartagRegister2EntityRepo.saveAndFlush(eartagRegister2Entity);
|
|
|
}
|