Browse Source

Merge remote-tracking branch 'origin/yellow' into yellow

zyf12 2 years ago
parent
commit
d2973c69c7

+ 9 - 1
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/PostCollectionsSystemController.java

@@ -7,6 +7,8 @@ import javax.servlet.http.HttpServletResponse;
 
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.system.domain.vo.CollectionsVo;
+import com.ruoyi.system.service.IPostCollectionsService;
+import com.ruoyi.system.utils.CollectionStatusJudgment;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.security.access.prepost.PreAuthorize;
@@ -34,6 +36,8 @@ public class PostCollectionsSystemController extends BaseController
 {
     @Autowired
     private IPostCollectionsSystemService postCollectionsSystemService;
+    @Autowired
+    private IPostCollectionsService postCollectionsService;
 
     /**
      * 查询藏品套系列表
@@ -154,15 +158,19 @@ public class PostCollectionsSystemController extends BaseController
     @ApiOperation("更改套系状态(上架 /下架)")
     @PostMapping("/status/{status}")
     public AjaxResult changeStatus(@RequestParam("ids")List<Long> ids, @PathVariable String status){
-       List<PostCollectionsSystem> postCollectionsSystemList = postCollectionsSystemService.listByIds(ids);
+        List<PostCollectionsSystem> postCollectionsSystemList = postCollectionsSystemService.listByIds(ids);
 
         postCollectionsSystemList = postCollectionsSystemList.stream().map(
                 (item) ->{
                     item.setStatus(status);
+                    //更改藏品的状态
+                    CollectionStatusJudgment.JudgmentStatus(item.getId());
                     return item;
                 }
         ).collect(Collectors.toList());
 
        return toAjax(postCollectionsSystemService.updateBatchById(postCollectionsSystemList));
     }
+
+
 }

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

@@ -69,5 +69,6 @@ public interface PostCollectionsMapper
     public int selectPostCollectionsByName(PostCollectionsVo postCollectionsVo);
 
     //批量修改藏品状态status
-    Long updatePostCollectionsStatus(Long systemId);
+    Long updatePostCollectionsStatus(PostCollections postCollections);
+
 }

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

@@ -78,7 +78,7 @@ public interface PostCollectionsSystemMapper
 
     //通过ids 查询套系
     List<PostCollectionsSystem> selectPostCollectionsSystemByIds(List<Long> ids);
-
+    //通过id批量修改
     int updateBatchById(List<PostCollectionsSystem> postCollectionsSystemList);
 
     int shelvesUpdatePostCollectionsSystem(PostCollectionsSystem postCollectionsSystem);

+ 5 - 36
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PostCollectionsServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ruoyi.system.service.impl;
 
+import java.lang.reflect.Method;
 import java.util.Date;
 import java.util.List;
 import java.util.Objects;
@@ -9,6 +10,7 @@ import com.ruoyi.system.domain.PostCollectionsSystem;
 import com.ruoyi.system.domain.vo.PostCollectionsVo;
 import com.ruoyi.system.mapper.PostCollectionsSystemMapper;
 import com.ruoyi.system.service.IIssuerService;
+import com.ruoyi.system.utils.CollectionStatusJudgment;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.system.mapper.PostCollectionsMapper;
@@ -54,15 +56,9 @@ public class PostCollectionsServiceImpl implements IPostCollectionsService
     public List<PostCollections> selectPostCollectionsList(Long systemId)
     {
         PostCollections postCollections = new PostCollections();
-        String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId);
-        //判断藏品套系是否上架,如果没上架,令藏品status全部置为未上架
-        if (Objects.equals(postCollectionsSystemStatus, "0")){
-            //批量修改status
-            postCollectionsMapper.updatePostCollectionsStatus(systemId);
-        }
         //systemId是套系里的主键id
         postCollections.setSystemId(systemId);
-        return postCollectionsMapper.selectPostCollectionsList(systemId);
+        return postCollectionsMapper.selectPostCollectionsList(postCollections.getSystemId());
     }
 
     /**
@@ -74,9 +70,6 @@ public class PostCollectionsServiceImpl implements IPostCollectionsService
     @Override
     public int insertPostCollections(PostCollectionsVo postCollectionsVo)
     {
-        Date nowDate = DateUtils.getNowDate();
-        Date startTime =  postCollectionsVo.getStartTime();
-        Date endTime =  postCollectionsVo.getEndTime();
         //获取此藏品套系status
         Long systemId = postCollectionsVo.getSystemId();
         String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId);
@@ -86,32 +79,8 @@ public class PostCollectionsServiceImpl implements IPostCollectionsService
         }
         //如果套系已上架,判断以下时间线
         else {
-            //判空
-            if (null!=startTime && null!=endTime){
-
-                /**
-                 * 判断时间 (0预售 /1已售尽 /2正在售卖 /3已过期)
-                 * 根据当前时间,对比售卖时间,
-                 * 当前时间小于售卖时间,该套系藏品为预售,
-                 * 当前时间大于售卖时间为已过期,
-                 * 当前时间在售卖时间之间并且数量大于0为正在售卖
-                 * 其余情况已售尽
-                 */
-                if (nowDate.before(startTime)){
-                    postCollectionsVo.setStatus("0");//预售
-                }
-                else if (nowDate.after(endTime)){
-                    postCollectionsVo.setStatus("3");//已过期
-                }
-                else if (startTime.before(nowDate) &&
-                        endTime.after(nowDate) &&
-                        postCollectionsVo.getCollectionsNumber()>0){
-                    postCollectionsVo.setStatus("2");//正在售卖
-                }
-                else if(postCollectionsVo.getCollectionsNumber()==0){
-                    postCollectionsVo.setStatus("1");//售尽
-                }
-            }
+            //抽出一个工具类
+            CollectionStatusJudgment.JudgmentTime(postCollectionsVo);
         }
         postCollectionsVo.setCreateBy(getUsername());
         postCollectionsVo.setUpdateBy(getUsername());

+ 7 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PostCollectionsSystemServiceImpl.java

@@ -10,6 +10,8 @@ import java.util.stream.Collectors;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.system.domain.vo.CollectionsVo;
+import com.ruoyi.system.mapper.PostCollectionsMapper;
+import com.ruoyi.system.service.IPostCollectionsService;
 import org.apache.commons.lang3.builder.ToStringExclude;
 import org.apache.ibatis.type.LocalDateTimeTypeHandler;
 import org.springframework.beans.BeanUtils;
@@ -249,6 +251,11 @@ public class PostCollectionsSystemServiceImpl implements IPostCollectionsSystemS
 
     @Override
     public int updateBatchById(List<PostCollectionsSystem> postCollectionsSystemList) {
+        for (int i = 0; i < postCollectionsSystemList.size(); i++) {
+            //补充字段
+            postCollectionsSystemList.get(i). setUpdateBy(getUsername());
+            postCollectionsSystemList.get(i).setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
+        }
         return postCollectionsSystemMapper.updateBatchById(postCollectionsSystemList);
     }
 }

+ 100 - 0
ruoyi-system/src/main/java/com/ruoyi/system/utils/CollectionStatusJudgment.java

@@ -0,0 +1,100 @@
+package com.ruoyi.system.utils;
+
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.system.domain.PostCollections;
+import com.ruoyi.system.domain.vo.PostCollectionsVo;
+import com.ruoyi.system.mapper.PostCollectionsMapper;
+import com.ruoyi.system.mapper.PostCollectionsSystemMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.Date;
+import java.util.Objects;
+
+import static com.ruoyi.common.utils.SecurityUtils.getUsername;
+
+@Component
+public class CollectionStatusJudgment {
+
+    private static PostCollectionsSystemMapper postCollectionsSystemMapper;
+
+    private static PostCollectionsMapper postCollectionsMapper;
+
+    @Autowired
+    public void setPostCollectionsSystemMapper(PostCollectionsSystemMapper postCollectionsSystemMapper) {
+        CollectionStatusJudgment.postCollectionsSystemMapper = postCollectionsSystemMapper;
+    }
+
+    @Autowired
+    public void setPostCollectionsMapper(PostCollectionsMapper postCollectionsMapper) {
+        CollectionStatusJudgment.postCollectionsMapper = postCollectionsMapper;
+    }
+
+    /**
+     * 如果已经上架,判断藏品状态时间
+     *
+     * @param postCollectionsVo
+     * @return 结果
+     */
+    public static void JudgmentTime(PostCollectionsVo postCollectionsVo) {
+
+        Date nowDate = DateUtils.getNowDate();
+        Date startTime = postCollectionsVo.getStartTime();
+        Date endTime = postCollectionsVo.getEndTime();
+        //获取此藏品套系status
+        Long systemId = postCollectionsVo.getSystemId();
+
+        String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId);
+        if (Objects.equals(postCollectionsSystemStatus, "1")) {
+            //判空
+            if (null != startTime && null != endTime) {
+
+                /**
+                 * 判断时间 (0预售 /1已售尽 /2正在售卖 /3已过期)
+                 * 根据当前时间,对比售卖时间,
+                 * 当前时间小于售卖时间,该套系藏品为预售,
+                 * 当前时间大于售卖时间为已过期,
+                 * 当前时间在售卖时间之间并且数量大于0为正在售卖
+                 * 其余情况已售尽
+                 */
+                if (nowDate.before(startTime)) {
+                    postCollectionsVo.setStatus("0");//预售
+                } else if (nowDate.after(endTime)) {
+                    postCollectionsVo.setStatus("3");//已过期
+                } else if (startTime.before(nowDate) &&
+                        endTime.after(nowDate) &&
+                        postCollectionsVo.getCollectionsNumber() > 0) {
+                    postCollectionsVo.setStatus("2");//正在售卖
+                } else if (postCollectionsVo.getCollectionsNumber() == 0) {
+                    postCollectionsVo.setStatus("1");//售尽
+                }
+            }
+        }
+
+    }
+
+    /**
+     * 如果未上架,令藏品状态为未上架
+     *
+     * @param systemId
+     * @return 结果
+     */
+    public static void JudgmentStatus(Long systemId) {
+        PostCollections postCollections = new PostCollections();
+        String postCollectionsSystemStatus = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(systemId);
+        //判断藏品套系是否上架,如果没上架,令藏品status全部置为未上架
+        if (null != postCollectionsSystemStatus) {
+            if (Objects.equals(postCollectionsSystemStatus, "0")) {
+                postCollections.setUpdateBy(getUsername());
+                postCollections.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getTime()));
+                postCollections.setSystemId(systemId);
+                //批量修改status,动态查询藏品列表
+                postCollectionsMapper.updatePostCollectionsStatus(postCollections);
+            } else {
+                //上架
+            }
+
+        }
+
+    }
+}

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

@@ -30,7 +30,7 @@
     <select id="selectPostCollectionsList" parameterType="PostCollections" resultMap="PostCollectionsResult">
         <include refid="selectPostCollectionsVo"/>
         <where>
-            <if test="systemId != null "> and system_id = #{id}</if><!--条件套系id等于前端传过来的id-->
+            <if test="systemId != null "> and system_id = #{systemId}</if><!--条件套系id等于前端传过来的id-->
             and del_flag = '0'
         </where>
     </select>
@@ -118,8 +118,8 @@
         select COUNT(name) FROM post_collections where name =  #{name} and del_flag = '0'
     </select>
     <!--批量修改藏品状态status-->
-    <update id="updatePostCollectionsStatus"  parameterType="Long">
-        update post_collections set status = '4' where system_id=#{systemId} and del_flag = '0'
+    <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>
 
 </mapper>