chenzhengming 2 år sedan
förälder
incheckning
75c69c9a6b

+ 1 - 1
ruoyi-admin/src/main/java/com/ruoyi/RuoYiApplication.java

@@ -4,13 +4,13 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.transaction.annotation.EnableTransactionManagement;
-import springfox.documentation.swagger2.annotations.EnableSwagger2;
 
 /**
  * 启动程序
  * 
  * @author ruoyi
  */
+
 @EnableTransactionManagement//事务
 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
 public class RuoYiApplication

+ 5 - 3
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PostCollectionsMapper.java

@@ -1,9 +1,9 @@
 package com.ruoyi.system.mapper;
 
-import java.util.List;
-
-import com.ruoyi.system.domain.vo.PostCollectionsVo;
 import com.ruoyi.system.domain.PostCollections;
+import com.ruoyi.system.domain.vo.PostCollectionsVo;
+
+import java.util.List;
 
 /**
  * 藏品Mapper接口
@@ -74,4 +74,6 @@ public interface PostCollectionsMapper
     public void updatePostCollectionsStatus1(PostCollections postCollections );
 
     void deletePostCollectionsBySystemIds(Long[] ids);
+    //根据SystemId和id修改
+    public void updatePostCollectionsBySysetmIdAndId(PostCollections postCollections);
 }

+ 59 - 13
ruoyi-system/src/main/java/com/ruoyi/system/utils/SpringTaskConfig.java

@@ -1,11 +1,10 @@
 package com.ruoyi.system.utils;
 
 import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.system.domain.PostCollections;
 import com.ruoyi.system.domain.PostCollectionsSystem;
-import com.ruoyi.system.domain.vo.CollectionsVo;
+import com.ruoyi.system.mapper.PostCollectionsMapper;
 import com.ruoyi.system.mapper.PostCollectionsSystemMapper;
-import com.ruoyi.system.service.IPostCollectionsSystemService;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableScheduling;
@@ -15,32 +14,31 @@ import java.util.Date;
 import java.util.List;
 import java.util.stream.Collectors;
 
-import static com.ruoyi.common.utils.SecurityUtils.getUsername;
-
 @Configuration
 @EnableScheduling
 public class SpringTaskConfig {
     @Autowired
     private PostCollectionsSystemMapper postCollectionsSystemMapper;
     @Autowired
-    private IPostCollectionsSystemService postCollectionsSystemService;
+    private PostCollectionsMapper postCollectionsMapper;
 
+    /**
+     * 每10秒查询数据库修改type的状态
+     */
     @Scheduled(cron = "0/10 * * * * ?")
     private void cron() {
         Date nowDate = DateUtils.getNowDate();
         PostCollectionsSystem postCollectionsSystem = new PostCollectionsSystem();
         List<PostCollectionsSystem> postCollectionsSystemList = postCollectionsSystemMapper.selectPostCollectionsSystemList(postCollectionsSystem);
-        postCollectionsSystemList = postCollectionsSystemList.stream().map((item)->{
+        postCollectionsSystemList = postCollectionsSystemList.stream().map((item) -> {
             Date startTime = item.getStartTime();
             Date endTime = item.getEndTime();
-            if (null!=startTime && null!=endTime){
-                if (nowDate.before(startTime)){
+            if (null != startTime && null != endTime) {
+                if (nowDate.before(startTime)) {
                     item.setType((long) 1);
-                }
-                else if (nowDate.after(endTime)){
+                } else if (nowDate.after(endTime)) {
                     item.setType((long) 2);
-                }
-                else {
+                } else {
                     item.setType((long) 0);
                 }
             }
@@ -48,4 +46,52 @@ public class SpringTaskConfig {
         }).collect(Collectors.toList());
         postCollectionsSystemMapper.updateBatchById(postCollectionsSystemList);
     }
+    /**
+     * 每10秒查询数据库藏品套系的时间,根据套系时间自动修改藏品状态
+     */
+    @Scheduled(cron = "0/10 * * * * ?")
+    private void cronA() {
+        Date nowDate = DateUtils.getNowDate();
+        PostCollectionsSystem postCollectionsSystem = new PostCollectionsSystem();
+        List<PostCollectionsSystem> postCollectionsSystemList = postCollectionsSystemMapper.selectPostCollectionsSystemList(postCollectionsSystem);
+        postCollectionsSystemList = postCollectionsSystemList.stream().map((item) -> {
+            Long systemId = item.getId();
+            Date startTime = item.getStartTime();
+            Date endTime = item.getEndTime();
+            return item;
+        }).collect(Collectors.toList());
+        for (int i = 0; i < postCollectionsSystemList.size(); i++) {
+            Date startTime = postCollectionsSystemList.get(i).getStartTime();
+            Date endTime = postCollectionsSystemList.get(i).getEndTime();
+            List<PostCollections> postCollectionsList = postCollectionsMapper.selectPostCollectionsList(postCollectionsSystemList.get(i).getId());
+            for (int j = 0; j < postCollectionsList.size(); j++) {
+                PostCollections postCollections = new PostCollections();
+                postCollections.setId(postCollectionsList.get(j).getId());
+                postCollections.setSystemId(postCollectionsSystemList.get(i).getId());
+                postCollections.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getTime()));
+
+                if (null!=startTime&&null!=endTime){
+                    if (nowDate.before(startTime)){
+                        postCollections.setStatus("0");
+                    }
+                    if (nowDate.after(endTime)){
+                        postCollections.setStatus("3");
+                    }
+                    if(startTime.before(nowDate)&&endTime.after(nowDate)&&
+                            null!=postCollectionsList.get(j).getCollectionsNumber()&&
+                            postCollectionsList.get(j).getCollectionsNumber() > 0 ) {
+                        postCollections.setStatus("2");
+                    }
+                    if(startTime.before(nowDate)&&endTime.after(nowDate)&&
+                            null!=postCollectionsList.get(j).getCollectionsNumber()&&
+                            postCollectionsList.get(j).getCollectionsNumber() == 0 ) {
+                        postCollections.setStatus("1");
+                    }
+                }
+                postCollectionsMapper.updatePostCollectionsBySysetmIdAndId(postCollections);
+            }
+
+        }
+
+    }
 }

+ 3 - 0
ruoyi-system/src/main/resources/mapper/system/PostCollectionsMapper.xml

@@ -133,4 +133,7 @@
         </foreach>
     </delete>
 
+    <update id="updatePostCollectionsBySysetmIdAndId"  parameterType="PostCollections">
+        update post_collections set status = #{status},update_time = #{updateTime}, update_by = #{updateBy} where id=#{id} and system_id=#{systemId} and del_flag = '0'
+    </update>
 </mapper>