|
@@ -0,0 +1,102 @@
|
|
|
+package com.huimv.environ.eco.timer;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.huimv.environ.eco.entity.FeedEggDetail;
|
|
|
+import com.huimv.environ.eco.entity.FeedUsage;
|
|
|
+import com.huimv.environ.eco.entity.LayEgg;
|
|
|
+import com.huimv.environ.eco.mapper.FeedEggDetailMapper;
|
|
|
+import com.huimv.environ.eco.mapper.FeedUsageMapper;
|
|
|
+import com.huimv.environ.eco.mapper.LayEggMapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class LayEggTimer {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LayEggMapper layEggMapper;
|
|
|
+ @Autowired
|
|
|
+ private FeedEggDetailMapper feedEggDetailMapper;
|
|
|
+ @Autowired
|
|
|
+ private FeedUsageMapper feedUsageMapper;
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 5 0 * * ?")
|
|
|
+//@Scheduled(cron = "0/10 * * * * ?")
|
|
|
+ @Transactional
|
|
|
+ public void saveLayEgg(){
|
|
|
+ LocalDate localDate = LocalDate.now();
|
|
|
+ LocalDate yesterday = localDate.minusDays(1);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
|
|
+ String date = yesterday.format(formatter);
|
|
|
+ Integer count = layEggMapper.selectCount(new QueryWrapper<LayEgg>().lambda().eq(LayEgg::getDate, date));
|
|
|
+ if (count == 0){
|
|
|
+ for (int i = 1; i <= 7; i++){
|
|
|
+ LayEgg layEgg = new LayEgg();
|
|
|
+ layEgg.setDate(date);
|
|
|
+ layEgg.setUnitName(i+"舍");
|
|
|
+ layEgg.setAvgWeight(BigDecimal.ZERO);
|
|
|
+ layEgg.setEggProduction(0);
|
|
|
+ layEgg.setTotalWeight(BigDecimal.ZERO);
|
|
|
+ layEggMapper.insert(layEgg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 10 0 * * ?")
|
|
|
+// @Scheduled(cron = "0/10 * * * * ?")
|
|
|
+ @Transactional
|
|
|
+ public void saveDetail(){
|
|
|
+ LocalDate localDate = LocalDate.now();
|
|
|
+ LocalDate yesterday = localDate.minusDays(1);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
|
|
+ String date = yesterday.format(formatter);
|
|
|
+ List<LayEgg> layEggs = layEggMapper.selectList(new QueryWrapper<LayEgg>().lambda().eq(LayEgg::getDate, date).orderByAsc(LayEgg::getUnitName));
|
|
|
+ for (LayEgg layEgg : layEggs) {
|
|
|
+ FeedEggDetail feedEggDetail = new FeedEggDetail();
|
|
|
+ feedEggDetail.setDate(date);
|
|
|
+ feedEggDetail.setUnitName(layEgg.getUnitName());
|
|
|
+ String[] split = layEgg.getUnitName().split("舍");
|
|
|
+ String updatedNumber = String.valueOf(Integer.parseInt(split[0]) + 2);
|
|
|
+ String newUnitName = updatedNumber + "舍";
|
|
|
+ FeedUsage feedUsage = feedUsageMapper.selectOne(new QueryWrapper<FeedUsage>().lambda().eq(FeedUsage::getUsedDate, date).eq(FeedUsage::getUnitName, newUnitName));
|
|
|
+
|
|
|
+ feedEggDetail.setStock(feedUsage.getStock());
|
|
|
+ feedEggDetail.setEggProduction(layEgg.getEggProduction().toString());
|
|
|
+ BigDecimal rate = BigDecimal.ZERO;
|
|
|
+ BigDecimal stock = new BigDecimal(feedUsage.getStock());
|
|
|
+ BigDecimal eggProduction = new BigDecimal(layEgg.getEggProduction());
|
|
|
+ if (!feedUsage.getStock().equals("0")){
|
|
|
+ rate = eggProduction.divide(stock,4,RoundingMode.HALF_UP).multiply(new BigDecimal(100)).setScale(2);
|
|
|
+ }
|
|
|
+ feedEggDetail.setLayEggRate(rate);
|
|
|
+ feedEggDetail.setEggWeight(layEgg.getTotalWeight());
|
|
|
+ feedEggDetail.setAvgWeight(layEgg.getAvgWeight());
|
|
|
+ feedEggDetail.setFeedConsume(feedUsage.getTotalConsume());
|
|
|
+
|
|
|
+ BigDecimal ratio = BigDecimal.ZERO;
|
|
|
+ BigDecimal feedConsume = feedUsage.getTotalConsume();
|
|
|
+ if (eggProduction.compareTo(BigDecimal.ZERO) != 0){
|
|
|
+ ratio = feedConsume.divide(eggProduction).setScale(2,RoundingMode.HALF_UP);
|
|
|
+ }
|
|
|
+ feedEggDetail.setFeedEggRatio(ratio);
|
|
|
+ feedEggDetailMapper.insert(feedEggDetail);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ LocalDate localDate = LocalDate.now();
|
|
|
+ LocalDate yesterday = localDate.minusDays(1);
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
|
|
|
+ String date = yesterday.format(formatter);
|
|
|
+ System.out.println(date);
|
|
|
+ }
|
|
|
+}
|