Преглед изворни кода

2021/5/26 创建定时任务&接口优化

yinhao пре 4 година
родитељ
комит
f15bbd06b5

+ 5 - 14
huimv-smart-apiservice/src/main/java/com/huimv/apiservice/task/CreateEverydayDataTask.java

@@ -8,12 +8,10 @@ import com.huimv.apiservice.entity.IndoorEnvironmentEntity;
 import com.huimv.apiservice.entity.OutdoorEnvironmentEntity;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
-import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.transaction.support.TransactionTemplate;
 
 import java.math.BigDecimal;
 import java.util.ArrayList;
@@ -35,20 +33,13 @@ import java.util.Random;
 public class CreateEverydayDataTask {
 
     @Autowired
-    private JdbcTemplate jdbcTemplate;
-
-    @Autowired
-    private TransactionTemplate transactionTemplate;
-
-    @Autowired
     private IndoorEnvironmentDao indoorEnvironmentDao;
 
     @Autowired
     private OutdoorEnvironmentDao outdoorEnvironmentDao;
 
     @Async
-    //@Scheduled(cron = "1 0 0 * * ?")
-    @Scheduled(cron = "0 52 18 * * ?")
+    @Scheduled(cron = "1 0 0 * * ?")
     void createTodayIndoorEnvData() {
 
         System.out.println("createTodayIndoorEnvData begin------->");
@@ -87,8 +78,8 @@ public class CreateEverydayDataTask {
     }
 
     @Async
-    //@Scheduled(cron = "1 0 0 * * ?")
-    @Scheduled(cron = "1 52 18 * * ?")
+    @Scheduled(cron = "1 0 0 * * ?")
+    //@Scheduled(cron = "1 52 18 * * ?")
     void createTodayOutdoorEnvData() {
 
         System.out.println("createTodayOutdoorEnvData begin------->");
@@ -126,8 +117,8 @@ public class CreateEverydayDataTask {
     }
 
     @Async
-    //@Scheduled(cron = "1 0 0 * * ?")
-    @Scheduled(cron = "1 52 18 * * ?")
+    @Scheduled(cron = "1 0 0 * * ?")
+    //@Scheduled(cron = "1 52 18 * * ?")
     void callPigHealthData() {
         System.out.println("callPigHealthData begin------->");
         indoorEnvironmentDao.callPigHealthData();

+ 64 - 64
huimv-smart-apiservice/src/test/java/com/huimv/apiservice/HuimvSmartApiserviceApplicationTests.java

@@ -77,7 +77,7 @@ class HuimvSmartApiserviceApplicationTests {
             entity.setGas(gas.get(random.nextInt(5)));
             entity.setCollectTime(collectTime);
             collectTime = DateUtil.offsetMinute(collectTime,5);
-            System.out.println(entity);
+//            System.out.println(entity);
             list.add(entity);
         }
 
@@ -127,69 +127,69 @@ class HuimvSmartApiserviceApplicationTests {
     }
 
 
-    @Test
-    void createPigData() {
-
-        String[] breeds = {"黑猪","金华两头乌","杜巴嘉","巴嘉","杜洛克","嘉兴黑猪","大白猪"};
-        String[] originPlace = {"金华","杭州"};
-
-        List<YearPigBaseEntity> all = new ArrayList<>();
-        List<YearPigBaseEntity> mothers = new ArrayList<>();
-        List<YearPigBaseEntity> fathers = new ArrayList<>();
-
-        Random random = new Random();
-        for (int i = 5; i < 2001; i++) {
-            YearPigBaseEntity entity = new YearPigBaseEntity();
-            String number = String.valueOf(i);
-            String earTag = "N00000".substring(0, 6 - number.length()) + number;
-            entity.setEartag(earTag);
-            int dayAge = random.nextInt(200) + 50;
-            entity.setDayAge(dayAge);
-            entity.setUnitId(random.nextInt(4) + 1);
-            BigDecimal bigDecimal = new BigDecimal(dayAge);
-            BigDecimal weight = bigDecimal.multiply(new BigDecimal(0.8)).setScale(2, BigDecimal.ROUND_HALF_UP);
-            entity.setWeight(weight.doubleValue());
-            entity.setBreed(breeds[random.nextInt(breeds.length)]);
-            String sex = i % 2 == 0 ? "公" : "母";
-            entity.setSex(sex);
-            if (dayAge >= 150 && "母".equals(sex)) {
-                mothers.add(entity);
-            }
-            if (dayAge >= 150 && "公".equals(sex)) {
-                fathers.add(entity);
-            }
-            entity.setBirthday(DateUtil.offsetDay(DateUtil.date(),i % 200));
-            entity.setOriginPlace(originPlace[random.nextInt(2)]);
-            //System.out.println(entity.getDayAge() + " " + " " + entity.getUnitId() + " " +  entity.getWeight());
-            entity.setPigstyId(random.nextInt(4) + 1);
-            entity.setPeriodId(1);
-            entity.setInFenceTime(DateUtil.offsetDay(DateUtil.parseDate("2021-01-01"),random.nextInt(91) - 30));
-            all.add(entity);
-        }
-
-        for (YearPigBaseEntity yearPigBaseEntity : all) {
-            if (yearPigBaseEntity.getDayAge() < 150) {
-                yearPigBaseEntity.setMotherEartag(mothers.get(random.nextInt(mothers.size())).getEartag());
-                yearPigBaseEntity.setFatherEartag(fathers.get(random.nextInt(fathers.size())).getEartag());
-            }
-        }
-        pigDao.batchInsertData(all);
-
-        List<SowChildbirthEntity> sowChildbirthEntityList = new ArrayList<>();
-        for (YearPigBaseEntity mother : mothers) {
-            SowChildbirthEntity entity = new SowChildbirthEntity();
-            entity.setEartag(mother.getEartag());
-            entity.setChildbirthWeight(mother.getWeight());
-            entity.setPregnancyDate(DateUtil.offsetMonth(mother.getInFenceTime(),3));
-            entity.setChildbirthCount(random.nextInt(10) + 5);
-            sowChildbirthEntityList.add(entity);
-        }
-        sowChildbirthDao.batchInsertData(sowChildbirthEntityList);
-
-
-
-
-    }
+//    @Test
+//    void createPigData() {
+//
+//        String[] breeds = {"黑猪","金华两头乌","杜巴嘉","巴嘉","杜洛克","嘉兴黑猪","大白猪"};
+//        String[] originPlace = {"金华","杭州"};
+//
+//        List<YearPigBaseEntity> all = new ArrayList<>();
+//        List<YearPigBaseEntity> mothers = new ArrayList<>();
+//        List<YearPigBaseEntity> fathers = new ArrayList<>();
+//
+//        Random random = new Random();
+//        for (int i = 5; i < 2001; i++) {
+//            YearPigBaseEntity entity = new YearPigBaseEntity();
+//            String number = String.valueOf(i);
+//            String earTag = "N00000".substring(0, 6 - number.length()) + number;
+//            entity.setEartag(earTag);
+//            int dayAge = random.nextInt(200) + 50;
+//            entity.setDayAge(dayAge);
+//            entity.setUnitId(random.nextInt(4) + 1);
+//            BigDecimal bigDecimal = new BigDecimal(dayAge);
+//            BigDecimal weight = bigDecimal.multiply(new BigDecimal(0.8)).setScale(2, BigDecimal.ROUND_HALF_UP);
+//            entity.setWeight(weight.doubleValue());
+//            entity.setBreed(breeds[random.nextInt(breeds.length)]);
+//            String sex = i % 2 == 0 ? "公" : "母";
+//            entity.setSex(sex);
+//            if (dayAge >= 150 && "母".equals(sex)) {
+//                mothers.add(entity);
+//            }
+//            if (dayAge >= 150 && "公".equals(sex)) {
+//                fathers.add(entity);
+//            }
+//            entity.setBirthday(DateUtil.offsetDay(DateUtil.date(),i % 200));
+//            entity.setOriginPlace(originPlace[random.nextInt(2)]);
+//            //System.out.println(entity.getDayAge() + " " + " " + entity.getUnitId() + " " +  entity.getWeight());
+//            entity.setPigstyId(random.nextInt(4) + 1);
+//            entity.setPeriodId(1);
+//            entity.setInFenceTime(DateUtil.offsetDay(DateUtil.parseDate("2021-01-01"),random.nextInt(91) - 30));
+//            all.add(entity);
+//        }
+//
+//        for (YearPigBaseEntity yearPigBaseEntity : all) {
+//            if (yearPigBaseEntity.getDayAge() < 150) {
+//                yearPigBaseEntity.setMotherEartag(mothers.get(random.nextInt(mothers.size())).getEartag());
+//                yearPigBaseEntity.setFatherEartag(fathers.get(random.nextInt(fathers.size())).getEartag());
+//            }
+//        }
+//        pigDao.batchInsertData(all);
+//
+//        List<SowChildbirthEntity> sowChildbirthEntityList = new ArrayList<>();
+//        for (YearPigBaseEntity mother : mothers) {
+//            SowChildbirthEntity entity = new SowChildbirthEntity();
+//            entity.setEartag(mother.getEartag());
+//            entity.setChildbirthWeight(mother.getWeight());
+//            entity.setPregnancyDate(DateUtil.offsetMonth(mother.getInFenceTime(),3));
+//            entity.setChildbirthCount(random.nextInt(10) + 5);
+//            sowChildbirthEntityList.add(entity);
+//        }
+//        sowChildbirthDao.batchInsertData(sowChildbirthEntityList);
+//
+//
+//
+//
+//    }
 
 
 

+ 2 - 2
renren-fast/src/main/resources/application-dev.yml

@@ -3,9 +3,9 @@ spring:
         type: com.alibaba.druid.pool.DruidDataSource
         druid:
             driver-class-name: com.mysql.cj.jdbc.Driver
-            url: jdbc:mysql://192.168.1.54:3306/huimv_smart_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
+            url: jdbc:mysql://192.168.1.7:3306/huimv_smart_admin?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
             username: root
-            password: root
+            password: hm123456
             initial-size: 10
             max-active: 100
             min-idle: 10