Forráskód Böngészése

解决演示数据2边不同步的问题。

wukai 1 hónapja
szülő
commit
c229584444

+ 8 - 7
jjt-biz/src/main/java/com/jjt/biz/controller/ApiAllController.java

@@ -2,6 +2,7 @@ package com.jjt.biz.controller;
 
 import com.jjt.biz.service.IApiAllService;
 import com.jjt.biz.vo.TwinAllVO;
+import com.jjt.common.constant.CacheConstants;
 import com.jjt.common.core.controller.BaseController;
 import com.jjt.common.core.domain.R;
 import com.jjt.common.core.redis.RedisCache;
@@ -34,13 +35,13 @@ public class ApiAllController extends BaseController {
     @CrossOrigin(origins = "*")
     @ResponseBody
     public R<?> data() {
-        TwinAllVO vo = new TwinAllVO();
-        vo.setStock(service.stock());
-        vo.setAvgMonth(service.avgMonth());
-        vo.setCurrYield(service.currYield());
-        vo.setProdTrade(service.prodTrade());
-        vo.setEnergyTrade(service.energyTrade());
-
+//        TwinAllVO vo = new TwinAllVO();
+//        vo.setStock(service.stock());
+//        vo.setAvgMonth(service.avgMonth());
+//        vo.setCurrYield(service.currYield());
+//        vo.setProdTrade(service.prodTrade());
+//        vo.setEnergyTrade(service.energyTrade());
+        TwinAllVO vo = redisCache.getCacheObject(CacheConstants.ALL_MOCK);
         return R.ok(vo);
     }
 

+ 2 - 22
jjt-biz/src/main/java/com/jjt/biz/controller/ApiYrController.java

@@ -1,9 +1,8 @@
 package com.jjt.biz.controller;
 
 import com.jjt.biz.service.IApiYrService;
-import com.jjt.biz.vo.YrProdEfficiencyVO;
-import com.jjt.biz.vo.YrProdLineStatusVO;
 import com.jjt.biz.vo.YrTwinVO;
+import com.jjt.common.constant.CacheConstants;
 import com.jjt.common.core.controller.BaseController;
 import com.jjt.common.core.domain.R;
 import com.jjt.common.core.redis.RedisCache;
@@ -16,10 +15,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.List;
-import java.util.Random;
 
 /**
  * swagger 用户测试方法
@@ -40,22 +35,7 @@ public class ApiYrController extends BaseController {
     @CrossOrigin(origins = "*")
     @ResponseBody
     public R<?> data() {
-        YrTwinVO vo = new YrTwinVO();
-        YrProdLineStatusVO status = service.status();
-        vo.setStatus(status);
-        List<YrProdEfficiencyVO> effList = service.eff();
-        for (YrProdEfficiencyVO eff : effList) {
-            if (eff.getLine() == 0) {
-                status.setWeight(eff.getWeight().setScale(0, RoundingMode.HALF_UP));
-                status.setLength(eff.getLength().setScale(0, RoundingMode.HALF_UP));
-                Random random = new Random();
-                BigDecimal baiPi = eff.getLength().multiply(BigDecimal.valueOf(0.5 + random.nextDouble())).setScale(0, RoundingMode.HALF_UP);
-                status.setBaiPei(baiPi);
-            }
-        }
-        vo.setEff(effList);
-        vo.setProdTrade(service.prodTrade());
-        vo.setEnergyTrade(service.energyTrade());
+        YrTwinVO vo = redisCache.getCacheObject(CacheConstants.RZ_MOCK);
         return R.ok(vo);
     }
 

+ 5 - 0
jjt-biz/src/main/java/com/jjt/biz/service/IApiAllService.java

@@ -49,4 +49,9 @@ public interface IApiAllService {
      */
     List<EnergyTradeVO> energyTrade();
 
+    /**
+     * 模拟数据
+     */
+    void mock();
+
 }

+ 5 - 0
jjt-biz/src/main/java/com/jjt/biz/service/IApiYrService.java

@@ -40,4 +40,9 @@ public interface IApiYrService {
      * @return 结果
      */
     List<YrEnergyTradeVO> energyTrade();
+
+    /**
+     * 模拟数据定时任务
+     */
+    void mock();
 }

+ 20 - 0
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiAllServiceImpl.java

@@ -186,6 +186,7 @@ public class ApiAllServiceImpl implements IApiAllService {
         return list;
     }
 
+
     private List<ProdTradeVO> mockProd() {
         List<ProdTradeVO> list = new ArrayList<>();
         LocalDate end = LocalDate.now().minusDays(1);
@@ -239,4 +240,23 @@ public class ApiAllServiceImpl implements IApiAllService {
         } while (!start.isAfter(end));
     }
 
+
+    /**
+     * 模拟数据
+     */
+    @Override
+    public void mock() {
+        YrTwinVO rzVO = redisCache.getCacheObject(CacheConstants.RZ_MOCK);
+        TwinAllVO vo = new TwinAllVO();
+        vo.setStock(stock());
+        vo.setAvgMonth(avgMonth());
+        CurrYieldVO currYieldVO = currYield();
+        CurrYieldVO.RZ rz = currYieldVO.getRz();
+        rz.setYield(rzVO.getStatus().getLength());
+        vo.setCurrYield(currYieldVO);
+        vo.setProdTrade(prodTrade());
+        vo.setEnergyTrade(energyTrade());
+        redisCache.setCacheObject(CacheConstants.ALL_MOCK, vo);
+    }
+
 }

+ 27 - 4
jjt-biz/src/main/java/com/jjt/biz/service/impl/ApiYrServiceImpl.java

@@ -1,10 +1,8 @@
 package com.jjt.biz.service.impl;
 
 import com.jjt.biz.service.IApiYrService;
-import com.jjt.biz.vo.YrEnergyTradeVO;
-import com.jjt.biz.vo.YrProdEfficiencyVO;
-import com.jjt.biz.vo.YrProdLineStatusVO;
-import com.jjt.biz.vo.YrProdTradeVO;
+import com.jjt.biz.vo.*;
+import com.jjt.common.constant.CacheConstants;
 import com.jjt.common.core.redis.RedisCache;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
@@ -15,6 +13,7 @@ import java.math.RoundingMode;
 import java.time.LocalDate;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Random;
 
 /**
  * 首页统计数据
@@ -101,6 +100,30 @@ public class ApiYrServiceImpl implements IApiYrService {
         return mockEnergy();
     }
 
+    /**
+     * 模拟数据定时任务
+     */
+    @Override
+    public void mock() {
+        YrTwinVO vo = new YrTwinVO();
+        YrProdLineStatusVO status = status();
+        vo.setStatus(status);
+        List<YrProdEfficiencyVO> effList = eff();
+        for (YrProdEfficiencyVO eff : effList) {
+            if (eff.getLine() == 0) {
+                status.setWeight(eff.getWeight().setScale(0, RoundingMode.HALF_UP));
+                status.setLength(eff.getLength().setScale(0, RoundingMode.HALF_UP));
+                Random random = new Random();
+                BigDecimal baiPi = eff.getLength().multiply(BigDecimal.valueOf(0.5 + random.nextDouble())).setScale(0, RoundingMode.HALF_UP);
+                status.setBaiPei(baiPi);
+            }
+        }
+        vo.setEff(effList);
+        vo.setProdTrade(prodTrade());
+        vo.setEnergyTrade(energyTrade());
+        redisCache.setCacheObject(CacheConstants.RZ_MOCK, vo);
+    }
+
     private List<YrProdTradeVO> mockProd() {
         List<YrProdTradeVO> list = new ArrayList<>();
         LocalDate end = LocalDate.now().minusDays(1);

+ 8 - 0
jjt-biz/src/main/java/com/jjt/task/IndexTask.java

@@ -1,6 +1,8 @@
 package com.jjt.task;
 
+import com.jjt.biz.service.IApiAllService;
 import com.jjt.biz.service.IApiService;
+import com.jjt.biz.service.IApiYrService;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
@@ -15,6 +17,10 @@ import javax.annotation.Resource;
 public class IndexTask {
     @Resource
     private IApiService apiService;
+    @Resource
+    private IApiAllService apiAllService;
+    @Resource
+    private IApiYrService apiYrService;
 
     /**
      * 统计当前数据
@@ -28,6 +34,8 @@ public class IndexTask {
      */
 
     public void today() {
+        apiYrService.mock();
+        apiAllService.mock();
         apiService.today();
     }
 

+ 5 - 0
jjt-common/src/main/java/com/jjt/common/constant/CacheConstants.java

@@ -66,6 +66,11 @@ public class CacheConstants {
      * 能耗趋势
      */
     public static final String ENERGY_TRADE = TWIN + "energyTrade";
+    /**
+     * 染整演示数据
+     */
+    public static final String RZ_MOCK = TWIN + "rzMock";
+    public static final String ALL_MOCK = TWIN + "allMock";
 
     /**
      * iot token