wangyc 8 лет назад
Родитель
Сommit
eba5b72429

+ 36 - 0
src/main/java/com/uas/platform/b2c/prod/product/common/CommonTask.java

@@ -0,0 +1,36 @@
+package com.uas.platform.b2c.prod.product.common;
+
+import com.uas.platform.b2c.prod.product.common.dao.CommonCountDao;
+import com.uas.platform.b2c.prod.product.common.model.CommonCount;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * 通用模块任务
+ *
+ * @version 2017/10/21 18:03 wangyc
+ */
+@Component("CommonTask")
+public class CommonTask {
+
+    private final CommonCountDao commonCountDao;
+
+    private final JdbcTemplate jdbcTemplate;
+
+    @Autowired
+    public CommonTask(CommonCountDao commonCountDao, JdbcTemplate jdbcTemplate) {
+        this.commonCountDao = commonCountDao;
+        this.jdbcTemplate = jdbcTemplate;
+    }
+
+    public void updateCount() {
+        List<CommonCount> commonCounts = commonCountDao.findByStatusOrderByDetno((short) 1);
+        for (CommonCount commonCount : commonCounts) {
+            commonCount.setCount(jdbcTemplate.queryForLong(commonCount.getSql()));
+        }
+        commonCountDao.save(commonCounts);
+    }
+}

+ 0 - 4
src/main/java/com/uas/platform/b2c/prod/product/common/service/impl/CommonCountServiceImpl.java

@@ -4,7 +4,6 @@ import com.uas.platform.b2c.prod.product.common.dao.CommonCountDao;
 import com.uas.platform.b2c.prod.product.common.model.CommonCount;
 import com.uas.platform.b2c.prod.product.common.service.CommonCountService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.stereotype.Service;
 
 import java.util.List;
@@ -18,9 +17,6 @@ public class CommonCountServiceImpl implements CommonCountService{
     @Autowired
     private CommonCountDao commonCountDao;
 
-    @Autowired
-    private JdbcTemplate jdbcTemplate;
-
     @Override
     public List<CommonCount> findByStatus(Short status) {
         List<CommonCount> commonCounts = commonCountDao.findByStatusOrderByDetno(status);

+ 3 - 0
src/main/resources/spring/task.xml

@@ -10,5 +10,8 @@
     <task:scheduled-tasks>
         <task:scheduled ref="OrderTask" method="autoConfirmOrderRevice" cron="0 0 1 * * ?"/>
     </task:scheduled-tasks>
+    <task:scheduled-tasks>
+        <task:scheduled ref="CommonTask" method="updateCount" cron="0 0 1 * * ?"/>
+    </task:scheduled-tasks>
     <context:annotation-config />
 </beans>