Browse Source

获取藏品数量sql

sjx 2 years ago
parent
commit
919cc9ed55

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

@@ -65,4 +65,6 @@ public interface PostCollectionsSystemMapper
     List<PostCollectionsSystem> selectPostListByTitleOrTime(@Param("title") String title,
                                                             @Param("timeLeft") Date timeLeft,
                                                             @Param("timeRight") Date timeRight);
+
+    Integer getCopiesById(Long id);
 }

+ 10 - 1
ruoyi-system/src/main/java/com/ruoyi/system/service/IPostCollectionsSystemService.java

@@ -2,6 +2,8 @@ package com.ruoyi.system.service;
 
 import java.util.Date;
 import java.util.List;
+
+import com.ruoyi.system.domain.PostCollections;
 import com.ruoyi.system.domain.PostCollectionsSystem;
 
 /**
@@ -60,5 +62,12 @@ public interface IPostCollectionsSystemService
      */
     public int deletePostCollectionsSystemById(Long id);
     //搜索功能
-    List<PostCollectionsSystem> selectByTitleAndTime(String title, Date timeLeft, Date timeRight);
+    public List<PostCollectionsSystem> selectByTitleAndTime(String title, Date timeLeft, Date timeRight);
+
+    /**
+     *  获取藏品数量
+     * @param postCollections
+     * @return 该套系下藏品数量
+     */
+    public int getCopies(Long id);
 }

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

@@ -156,4 +156,14 @@ public class PostCollectionsSystemServiceImpl implements IPostCollectionsSystemS
         PostCollectionsSystem post = new PostCollectionsSystem();
         return postCollectionsSystemMapper.selectPostCollectionsSystemList(post);
     }
+
+    /**
+     *  获取该套系下 藏品数量
+     * @param id
+     * @return
+     */
+    @Override
+    public int getCopies(Long id) {
+        return postCollectionsSystemMapper.getCopiesById(id);
+    }
 }

+ 4 - 1
ruoyi-system/src/main/resources/mapper/system/PostCollectionsSystemMapper.xml

@@ -111,10 +111,13 @@
     <select id="selectPostListByTitleOrTime" resultType="PostCollectionsSystem" resultMap="PostCollectionsSystemResult">
         <include refid="selectPostCollectionsSystemVo"/>
         <where>
-            <if test="title != null  and title != ''"> and name LIKE '%${title}%'</if>
+            <if test="title != null  and title != ''"> and name LIKE CONCAT(CONCAT('%',#{title},'%'))</if>
             <if test="timeLeft != null and timeRight != null "> and create_time between #{timeLeft} AND #{timeRight}</if>
             and del_flag = '0'
         </where>
     </select>
 
+    <select id="getCopiesById" parameterType="Long" resultType="Integer">
+       SELECT SUM(collections_number) FROM post_collections where system_id = #{id}
+    </select>
 </mapper>