Эх сурвалжийг харах

更加套系状态动态变换藏品状态

chenzhengming 2 жил өмнө
parent
commit
e1131c65ae

+ 5 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/PostCollectionsSystemController.java

@@ -1,5 +1,6 @@
 package com.ruoyi.web.controller.system;
 package com.ruoyi.web.controller.system;
 
 
+import java.util.Collections;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
@@ -152,19 +153,19 @@ public class PostCollectionsSystemController extends BaseController
     /**
     /**
      *  更改套系状态(上架 /下架)
      *  更改套系状态(上架 /下架)
      * @param status
      * @param status
-     * @param ids
+     * @param id
      * @return
      * @return
      */
      */
     @ApiOperation("更改套系状态(上架 /下架)")
     @ApiOperation("更改套系状态(上架 /下架)")
     @PostMapping("/status/{status}")
     @PostMapping("/status/{status}")
-    public AjaxResult changeStatus(@RequestParam("ids")List<Long> ids, @PathVariable String status){
-        List<PostCollectionsSystem> postCollectionsSystemList = postCollectionsSystemService.listByIds(ids);
+    public AjaxResult changeStatus(@RequestBody List<Long> id, @PathVariable String status){
+        List<PostCollectionsSystem> postCollectionsSystemList = postCollectionsSystemService.listByIds(id);
 
 
         postCollectionsSystemList = postCollectionsSystemList.stream().map(
         postCollectionsSystemList = postCollectionsSystemList.stream().map(
                 (item) ->{
                 (item) ->{
                     item.setStatus(status);
                     item.setStatus(status);
                     //更改藏品的状态
                     //更改藏品的状态
-                    CollectionStatusJudgment.JudgmentStatus(item.getId());
+                    CollectionStatusJudgment.JudgmentStatus(id,status);
                     return item;
                     return item;
                 }
                 }
         ).collect(Collectors.toList());
         ).collect(Collectors.toList());

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

@@ -68,9 +68,10 @@ public interface PostCollectionsMapper
      */
      */
     public int selectPostCollectionsByName(PostCollectionsVo postCollectionsVo);
     public int selectPostCollectionsByName(PostCollectionsVo postCollectionsVo);
 
 
-    //批量修改藏品状态status
+    //批量修改藏品未上架时状态status
     Long updatePostCollectionsStatus(PostCollections postCollections);
     Long updatePostCollectionsStatus(PostCollections postCollections);
-
+    //批量更新上架时的状态
+    public void updatePostCollectionsStatus1(PostCollections postCollections );
 
 
     void deletePostCollectionsBySystemIds(Long[] ids);
     void deletePostCollectionsBySystemIds(Long[] ids);
 }
 }

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/mapper/PostCollectionsSystemMapper.java

@@ -2,6 +2,8 @@ package com.ruoyi.system.mapper;
 
 
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
+
+import com.ruoyi.system.domain.PostCollections;
 import com.ruoyi.system.domain.PostCollectionsSystem;
 import com.ruoyi.system.domain.PostCollectionsSystem;
 import org.apache.ibatis.annotations.Param;
 import org.apache.ibatis.annotations.Param;
 
 
@@ -86,4 +88,6 @@ public interface PostCollectionsSystemMapper
     Date getEndTime(Long id);
     Date getEndTime(Long id);
 
 
     public List<PostCollectionsSystem>  selectListEqStatus(Long[] ids);
     public List<PostCollectionsSystem>  selectListEqStatus(Long[] ids);
+    //查询多个套系
+    List<PostCollectionsSystem> selectPostCollectionsSystemByIdList(List<Long> systemId);
 }
 }

+ 40 - 9
ruoyi-system/src/main/java/com/ruoyi/system/utils/CollectionStatusJudgment.java

@@ -2,6 +2,7 @@ package com.ruoyi.system.utils;
 
 
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.system.domain.PostCollections;
 import com.ruoyi.system.domain.PostCollections;
+import com.ruoyi.system.domain.PostCollectionsSystem;
 import com.ruoyi.system.domain.vo.PostCollectionsVo;
 import com.ruoyi.system.domain.vo.PostCollectionsVo;
 import com.ruoyi.system.mapper.PostCollectionsMapper;
 import com.ruoyi.system.mapper.PostCollectionsMapper;
 import com.ruoyi.system.mapper.PostCollectionsSystemMapper;
 import com.ruoyi.system.mapper.PostCollectionsSystemMapper;
@@ -9,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 
 
 import java.util.Date;
 import java.util.Date;
+import java.util.List;
 import java.util.Objects;
 import java.util.Objects;
 
 
 import static com.ruoyi.common.utils.SecurityUtils.getUsername;
 import static com.ruoyi.common.utils.SecurityUtils.getUsername;
@@ -43,8 +45,8 @@ public class CollectionStatusJudgment {
         Date endTime = postCollectionsVo.getEndTime();
         Date endTime = postCollectionsVo.getEndTime();
         //获取此藏品套系status
         //获取此藏品套系status
         Long systemId = postCollectionsVo.getSystemId();
         Long systemId = postCollectionsVo.getSystemId();
-
         String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId);
         String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId);
+
         if (Objects.equals(postCollectionsSystemStatus, "1")) {
         if (Objects.equals(postCollectionsSystemStatus, "1")) {
             //判空
             //判空
             if (null != startTime && null != endTime) {
             if (null != startTime && null != endTime) {
@@ -79,22 +81,51 @@ public class CollectionStatusJudgment {
      * @param systemId
      * @param systemId
      * @return 结果
      * @return 结果
      */
      */
-    public static void JudgmentStatus(Long systemId) {
+    public static void JudgmentStatus(List<Long> systemId,String status) {
         PostCollections postCollections = new PostCollections();
         PostCollections postCollections = new PostCollections();
-        String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId);
+        List<PostCollectionsSystem> postCollectionsSystemList = postCollectionsSystemMapper.selectPostCollectionsSystemByIdList(systemId);
         //判断藏品套系是否上架,如果没上架,令藏品status全部置为未上架
         //判断藏品套系是否上架,如果没上架,令藏品status全部置为未上架
-        if (null != postCollectionsSystemStatus) {
-            if (Objects.equals(postCollectionsSystemStatus, "0")) {
+        for (int i = 0; i < postCollectionsSystemList.size(); i++) {
+            //判断套系是否status=0
+            if (Objects.equals(status, "0")) {
                 postCollections.setUpdateBy(getUsername());
                 postCollections.setUpdateBy(getUsername());
                 postCollections.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getTime()));
                 postCollections.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getTime()));
-                postCollections.setSystemId(systemId);
+                postCollections.setSystemId(postCollectionsSystemList.get(i).getId());
                 //批量修改status,动态查询藏品列表
                 //批量修改status,动态查询藏品列表
                 postCollectionsMapper.updatePostCollectionsStatus(postCollections);
                 postCollectionsMapper.updatePostCollectionsStatus(postCollections);
             } else {
             } else {
                 //上架
                 //上架
-            }
-
+                Long id = postCollectionsSystemList.get(i).getId();
+                List<PostCollections> postCollectionsList = postCollectionsMapper.selectPostCollectionsList(id);//获取藏品列表根据套系id
+                for (int j = 0; j < postCollectionsList.size(); j++) {
+                    postCollectionsList.get(j).setUpdateBy(getUsername());
+                    postCollectionsList.get(j).setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getTime()));
+                    postCollectionsList.get(j).setSystemId(postCollectionsSystemList.get(i).getId());
+                    //获取时间线
+                    Date nowDate = DateUtils.getNowDate();
+                    Date startTime = postCollectionsList.get(j).getStartTime();
+                    Date endTime = postCollectionsList.get(j).getEndTime();
+                    //判空
+                    if (null != startTime && null != endTime) {
+                        if (nowDate.before(startTime)) {
+                            postCollectionsList.get(j).setStatus("0");//预售
+                        }else if (nowDate.after(endTime)) {
+                            postCollectionsList.get(j).setStatus("3");//已过期
+                        }else if (startTime.before(nowDate) &&
+                                endTime.after(nowDate) &&
+                                null!=postCollectionsList.get(j).getCollectionsNumber()&&
+                                postCollectionsList.get(j).getCollectionsNumber() > 0) {
+                            postCollectionsList.get(j).setStatus("2");//正在售卖
+                        } else if (startTime.before(nowDate) &&
+                                endTime.after(nowDate) &&
+                                null!=postCollectionsList.get(j).getCollectionsNumber()&&
+                                postCollectionsList.get(j).getCollectionsNumber() == 0) {
+                            postCollectionsList.get(j).setStatus("1");//售尽
+                        }
+                        }
+                    postCollectionsMapper.updatePostCollectionsStatus1(postCollectionsList.get(j));
+                }
+                }
         }
         }
-
     }
     }
 }
 }

+ 5 - 2
ruoyi-system/src/main/resources/mapper/system/PostCollectionsMapper.xml

@@ -117,11 +117,14 @@
     <select id="selectPostCollectionsByName" parameterType="PostCollectionsVo" resultType="int">
     <select id="selectPostCollectionsByName" parameterType="PostCollectionsVo" resultType="int">
         select COUNT(name) FROM post_collections where name =  #{name} and del_flag = '0'
         select COUNT(name) FROM post_collections where name =  #{name} and del_flag = '0'
     </select>
     </select>
-    <!--批量修改藏品状态status-->
+    <!--如果套系未上架,批量修改藏品状态status=‘4’-->
     <update id="updatePostCollectionsStatus"  parameterType="PostCollections">
     <update id="updatePostCollectionsStatus"  parameterType="PostCollections">
         update post_collections set status = '4',update_time = #{updateTime}, update_by = #{updateBy} where system_id=#{systemId} and del_flag = '0'
         update post_collections set status = '4',update_time = #{updateTime}, update_by = #{updateBy} where system_id=#{systemId} and del_flag = '0'
     </update>
     </update>
-
+    <!--如果套系已上架,根据返回值批量修改藏品状态status-->
+    <update id="updatePostCollectionsStatus1" parameterType="PostCollections">
+        update post_collections set status = #{status},update_time = #{updateTime}, update_by = #{updateBy} where system_id=#{systemId} and id=#{id} and del_flag = '0'
+    </update>
     <!--通过套系id 进行批量删除-->
     <!--通过套系id 进行批量删除-->
     <delete id="deletePostCollectionsBySystemIds" parameterType="String">
     <delete id="deletePostCollectionsBySystemIds" parameterType="String">
         UPDATE post_collections SET del_flag = '1'  WHERE del_flag = '0' AND system_id in
         UPDATE post_collections SET del_flag = '1'  WHERE del_flag = '0' AND system_id in

+ 9 - 3
ruoyi-system/src/main/resources/mapper/system/PostCollectionsSystemMapper.xml

@@ -147,7 +147,7 @@
     <update id="updateBatchById" parameterType="list">
     <update id="updateBatchById" parameterType="list">
         <foreach collection="list" item="item" separator=";">
         <foreach collection="list" item="item" separator=";">
             update
             update
-            `post_collections_system`
+            post_collections_system
             <trim prefix="SET" suffixOverrides=",">
             <trim prefix="SET" suffixOverrides=",">
                 <if test="item.type != null">type = #{item.type},</if>
                 <if test="item.type != null">type = #{item.type},</if>
                 <if test="item.name != null">name = #{item.name},</if>
                 <if test="item.name != null">name = #{item.name},</if>
@@ -200,7 +200,13 @@
             and del_flag = '0'
             and del_flag = '0'
         </where>
         </where>
     </select>
     </select>
-
-
+    <!--查询多个套系-->
+    <select id="selectPostCollectionsSystemByIdList" parameterType="Long" resultMap="PostCollectionsSystemResult">
+        <include refid="selectPostCollectionsSystemVo"/>
+        where del_flag = '0' AND id in
+        <foreach collection="list" open="(" close=")" separator="," item="id">
+        #{id}
+        </foreach>
+    </select>
 
 
 </mapper>
 </mapper>