|
@@ -0,0 +1,100 @@
|
|
|
|
+package com.huimv.guowei.admin.timer;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.huimv.guowei.admin.common.utils.NumberUtils;
|
|
|
|
+import com.huimv.guowei.admin.entity.*;
|
|
|
|
+import com.huimv.guowei.admin.entity.vo.FeedingVo;
|
|
|
|
+import com.huimv.guowei.admin.mapper.BaseDuckInfoMapper;
|
|
|
|
+import com.huimv.guowei.admin.mapper.EnvDeviceMapper;
|
|
|
|
+import com.huimv.guowei.admin.mapper.EnvRegularCallEggMapper;
|
|
|
|
+import com.huimv.guowei.admin.mapper.EnvRegularCallFeedingMapper;
|
|
|
|
+import com.huimv.guowei.admin.service.IBaseDuckInfoService;
|
|
|
|
+import com.huimv.guowei.admin.service.IEnvDeviceOnlineService;
|
|
|
|
+import com.huimv.guowei.admin.service.IEnvDeviceService;
|
|
|
|
+import com.huimv.guowei.admin.service.IRawDataService;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+@Component
|
|
|
|
+@EnableScheduling
|
|
|
|
+public class ProcudeFeed {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private EnvRegularCallFeedingMapper feedingMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EnvRegularCallEggMapper eggMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private EnvDeviceMapper deviceMapper;
|
|
|
|
+ @Autowired
|
|
|
|
+ private BaseDuckInfoMapper infoMapper;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // @Scheduled(cron = "*/5 * * * * ?")
|
|
|
|
+ @Scheduled(cron = "0 0 9 * * ?")
|
|
|
|
+ private void saveOnlineDevice() {
|
|
|
|
+ QueryWrapper<EnvDevice> queryWrapper = new QueryWrapper<>();
|
|
|
|
+ queryWrapper.eq("farm_id", 21).eq("device_type", 3);
|
|
|
|
+ List<EnvDevice> devices = deviceMapper.selectList(queryWrapper);
|
|
|
|
+ for (EnvDevice device : devices) {
|
|
|
|
+ QueryWrapper<EnvRegularCallFeeding> queryWrapper1 = new QueryWrapper<>();
|
|
|
|
+ queryWrapper1.eq("farm_id", 21).ge("call_date", new Date())
|
|
|
|
+ .eq("call_code", device.getDeviceCode());
|
|
|
|
+ FeedingVo feedingVo = feedingMapper.FeedTime(queryWrapper1);
|
|
|
|
+ if (ObjectUtil.isEmpty(feedingVo) || feedingVo.getDuckWeight().compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
+ QueryWrapper<BaseDuckInfo> queryWrapper2 = new QueryWrapper<>();
|
|
|
|
+ queryWrapper2.eq("farm_id", 21).eq("unit_id", device.getUnitId())
|
|
|
|
+ .eq("is_cage", 0);
|
|
|
|
+ BaseDuckInfo duckInfo = infoMapper.selectOne(queryWrapper2);
|
|
|
|
+ EnvRegularCallFeeding feeding = new EnvRegularCallFeeding();
|
|
|
|
+ feeding.setCallName(device.getDeviceName());
|
|
|
|
+ feeding.setCallCode(device.getDeviceCode());
|
|
|
|
+ feeding.setDuckNum(duckInfo.getDuckNum());
|
|
|
|
+ String num = NumberUtils.getNum(220, 230, 1);
|
|
|
|
+ feeding.setDuckWeight(Double.valueOf(num));
|
|
|
|
+ feeding.setDuckFeedingOriginal(0);
|
|
|
|
+ feeding.setCallDate(new Date());
|
|
|
|
+ feeding.setFarmId(21);
|
|
|
|
+ feeding.setDuckId(duckInfo.getId());
|
|
|
|
+ feeding.setBattery("8.0");
|
|
|
|
+ feeding.setUnitId(device.getUnitId());
|
|
|
|
+ feeding.setUnitName(device.getUnitName());
|
|
|
|
+ feeding.setEventType(0);
|
|
|
|
+ feeding.setChiNum(duckInfo.getChiNum());
|
|
|
|
+ feeding.setJiaoNum(duckInfo.getJiaoNum());
|
|
|
|
+ feeding.setBatchNum(duckInfo.getBatchNum());
|
|
|
|
+ feedingMapper.insert(feeding);
|
|
|
|
+
|
|
|
|
+ EnvRegularCallEgg egg = new EnvRegularCallEgg();
|
|
|
|
+ egg.setCallName(device.getDeviceName());
|
|
|
|
+ egg.setCallCode(device.getDeviceCode());
|
|
|
|
+ egg.setDuckNum(duckInfo.getDuckNum());
|
|
|
|
+ String num1 = NumberUtils.getNum(60, 70, 1);
|
|
|
|
+ egg.setDuckWeight(Double.valueOf(num1));
|
|
|
|
+ egg.setDuckFeedingOriginal(0);
|
|
|
|
+ egg.setEggNum(1);
|
|
|
|
+ egg.setCallDate(new Date());
|
|
|
|
+ egg.setFarmId(21);
|
|
|
|
+ egg.setDuckId(duckInfo.getId());
|
|
|
|
+ egg.setBattery("8.0");
|
|
|
|
+ egg.setUnitId(device.getUnitId());
|
|
|
|
+ egg.setUnitName(device.getUnitName());
|
|
|
|
+ egg.setChiNum(duckInfo.getChiNum());
|
|
|
|
+ egg.setJiaoNum(duckInfo.getJiaoNum());
|
|
|
|
+ egg.setBatchNum(duckInfo.getBatchNum());
|
|
|
|
+ eggMapper.insert(egg);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|