Browse Source

完善新增套系

zyf12 2 years ago
parent
commit
8fe29982e9

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

@@ -80,4 +80,9 @@ public interface PostCollectionsSystemMapper
     List<PostCollectionsSystem> selectPostCollectionsSystemByIds(List<Long> ids);
 
     int updateBatchById(List<PostCollectionsSystem> postCollectionsSystemList);
+
+    int shelvesUpdatePostCollectionsSystem(PostCollectionsSystem postCollectionsSystem);
+
+    Date getEndTime(Long id);
+
 }

+ 4 - 0
ruoyi-system/src/main/java/com/ruoyi/system/service/IPostCollectionsSystemService.java

@@ -80,6 +80,9 @@ public interface IPostCollectionsSystemService
      */
     public int getCopies(Long id);
 
+    public Date getEndTime(Long id);
+
+
     /**
      *  用套系名称进行查询
      * @param postCollectionsSystem
@@ -100,6 +103,7 @@ public interface IPostCollectionsSystemService
      * @return
      */
     int updateBatchById(List<PostCollectionsSystem> postCollectionsSystemList);
+
 }
 
 

+ 33 - 24
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/PostCollectionsSystemServiceImpl.java

@@ -20,6 +20,8 @@ import com.ruoyi.system.mapper.PostCollectionsSystemMapper;
 import com.ruoyi.system.domain.PostCollectionsSystem;
 import com.ruoyi.system.service.IPostCollectionsSystemService;
 
+import javax.xml.bind.annotation.XmlEnumValue;
+
 import static com.ruoyi.common.utils.SecurityUtils.getUsername;
 
 /**
@@ -108,38 +110,39 @@ public class PostCollectionsSystemServiceImpl implements IPostCollectionsSystemS
         //补充字段
         postCollectionsSystem.setUpdateBy(getUsername());
         postCollectionsSystem.setUpdateTime(DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS,DateUtils.getTime()));
-        /*SimpleDateFormat formatter= new SimpleDateFormat("YYYY_MM_DD_HH_MM_SS");
-        Date localDate = new Date(System.currentTimeMillis());
-        Date startDate=postCollectionsSystem.getStartTime();
-        Date endDate=postCollectionsSystem.getEndTime();
-        if(localDate.after(startDate)){
-            postCollectionsSystem.setType(Long.valueOf(1));
-        }else if(startDate.after(localDate)&&endDate.after(localDate)){
-            postCollectionsSystem.setType(Long.valueOf(0));
-        }else {
-            postCollectionsSystem.setType(Long.valueOf(2));
-        }*/
         /**
          * 判断时间 (在售0/预售1/已过期2)
          * 根据当前时间,对比套系时间,当前小于套系时间,该套系藏品为“以过期”,
          * 当前时间大于套系时间为“预售”
          */
-        Date nowDate = DateUtils.getNowDate();
-        Date startTime = postCollectionsSystem.getStartTime();
-        Date endTime = postCollectionsSystem.getEndTime();
-        //当前时间早于套系时间 ->预售
-        if (null!=startTime && null!=endTime){
-            if (nowDate.before(startTime)){
-                postCollectionsSystem.setType((long) 1);
-            }
-            else if (nowDate.after(endTime)){
-                postCollectionsSystem.setType((long) 2);
+        String status = postCollectionsSystemMapper.selectPostCollectionsSystemByStatus(postCollectionsSystem.getId());
+        //未上架什么都可以改
+        int row=0;
+        if(status.equals("0")) {
+            Date nowDate = DateUtils.getNowDate();
+            Date startTime = postCollectionsSystem.getStartTime();
+            Date endTime = postCollectionsSystem.getEndTime();
+            //当前时间早于套系时间 ->预售
+            if (null != startTime && null != endTime) {
+                if (nowDate.before(startTime)) {
+                    postCollectionsSystem.setType((long) 1);
+                } else if (nowDate.after(endTime)) {
+                    postCollectionsSystem.setType((long) 2);
+                } else {
+                    postCollectionsSystem.setType((long) 0);
+                }
             }
-            else {
-                postCollectionsSystem.setType((long) 0);
+            row=postCollectionsSystemMapper.updatePostCollectionsSystem(postCollectionsSystem);
+        }
+        //已上架“时间”只允许修改截止时间,且只能可以向当前截止时间之后设置
+        else {
+            Date originEndTime=postCollectionsSystemMapper.getEndTime(postCollectionsSystem.getId());
+            Date endTime = postCollectionsSystem.getEndTime();
+            if(endTime.after(originEndTime)) {
+                row = postCollectionsSystemMapper.shelvesUpdatePostCollectionsSystem(postCollectionsSystem);
             }
         }
-        return postCollectionsSystemMapper.updatePostCollectionsSystem(postCollectionsSystem);
+        return row;
     }
 
     /**
@@ -211,6 +214,12 @@ public class PostCollectionsSystemServiceImpl implements IPostCollectionsSystemS
         return postCollectionsSystemMapper.getCopiesById(id);
     }
 
+    @Override
+    public Date getEndTime(Long id) {
+        return postCollectionsSystemMapper.getEndTime(id);
+    }
+
+
     @Override
     public List<CollectionsVo> selectPostCollectionsSystemListPage(PostCollectionsSystem postCollectionsSystem) {
         List<PostCollectionsSystem> list = postCollectionsSystemMapper.selectPostCollectionsSystemList(postCollectionsSystem);

+ 25 - 0
ruoyi-system/src/main/resources/mapper/system/PostCollectionsSystemMapper.xml

@@ -130,6 +130,8 @@
     <select id="selectPostCollectionsSystemByStatus" parameterType="Long" resultType="String">
         select status from post_collections_system  where id = #{systemId}
     </select>
+
+
     <!--通过ids 查询套系-->
     <select id="selectPostCollectionsSystemByIds" parameterType="String" resultMap="PostCollectionsSystemResult">
         <include refid="selectPostCollectionsSystemVo"/>
@@ -166,4 +168,27 @@
         </foreach>
     </update>
 
+    <update id="shelvesUpdatePostCollectionsSystem" parameterType="PostCollectionsSystem">
+        update post_collections_system
+        <trim prefix="SET" suffixOverrides=",">
+            <if test="name != null">name = #{name},</if>
+            <if test="endTime != null">end_time = #{endTime},</if>
+            <if test="image != null">image = #{image},</if>
+            <if test="giftExchange != null">gift_exchange = #{giftExchange},</if>
+            <if test="updateTime != null">update_time = #{updateTime},</if>
+            <if test="createBy != null">create_by = #{createBy},</if>
+            <if test="updateBy != null">update_by = #{updateBy},</if>
+            <if test="delFlag != null">del_flag = #{delFlag},</if>
+        </trim>
+        where id = #{id}
+    </update>
+
+    <!--获取套系id 所对应截至时间-->
+    <select id="getEndTime" parameterType="Long" resultType="Date">
+        SELECT end_time FROM post_collections_system where id= #{id}
+    </select>
+
+
+
+
 </mapper>