Selaa lähdekoodia

乐器sql修改,查询加入逻辑删除标识限制

weifanli 3 vuotta sitten
vanhempi
commit
6fe2e35618

+ 36 - 38
cooleshow-user/user-biz/src/main/resources/config/mybatis/SubjectMapper.xml

@@ -19,16 +19,17 @@
 
     <!-- 根据主键查询一条记录 -->
     <select id="get" resultMap="Subject">
-		SELECT * FROM subject WHERE id_ = #{id}
+		SELECT * FROM subject WHERE del_flag_ = 0 and id_ = #{id}
 	</select>
 
     <!-- 全查询 -->
     <select id="findAll" resultMap="Subject">
-		SELECT * FROM subject ORDER BY id_
+		SELECT * FROM subject where del_flag_ = 0 and ORDER BY id_
 	</select>
 
     <!-- 向数据库增加一条记录 -->
-    <insert id="insert" parameterType="com.yonge.cooleshow.biz.dal.entity.Subject" useGeneratedKeys="true" keyColumn="id"
+    <insert id="insert" parameterType="com.yonge.cooleshow.biz.dal.entity.Subject" useGeneratedKeys="true"
+            keyColumn="id"
             keyProperty="id">
         INSERT INTO subject (id_,name_,code_,parent_subject_id_,img_,create_time_,update_time_,desc_)
         VALUES(#{id},#{name},#{code},#{parentSubjectId},#{img},now(),now(),#{desc})
@@ -68,6 +69,10 @@
         UPDATE `subject` SET del_flag_ = 1 WHERE id_ = #{id} OR parent_subject_id_ = #{id}
 	</update>
 
+    <delete id="deleteById">
+		update subject set del_flag_ = 1 where id_ = #{id} or parent_subject_id_ = #{id}
+	</delete>
+
     <!-- 分页查询 -->
     <select id="queryPage" resultMap="Subject" parameterType="map">
         SELECT * FROM subject
@@ -78,39 +83,35 @@
 
     <!-- 查询当前表的总记录数 -->
     <select id="queryCount" resultType="int">
-		SELECT COUNT(*) FROM subject <include refid="querySubPageSql"/>
-	</select>
+        SELECT COUNT(*) FROM subject
+        <include refid="querySubPageSql"/>
+    </select>
 
     <select id="findByParentId" resultMap="Subject">
         SELECT * FROM subject
-        <where>
-            <if test="parentId != null">
-                AND parent_subject_id_ = #{parentId}
-            </if>
-            <if test="delFlag != null">
-                AND del_flag_ = #{delFlag}
-            </if>
-        </where>
+        where del_flag_ = 0
+        <if test="parentId != null">
+            AND parent_subject_id_ = #{parentId}
+        </if>
     </select>
 
     <sql id="querySubPageSql">
-        <where>
-            <if test="parentId != null">
-                AND parent_subject_id_ = #{parentId}
-            </if>
-            <if test="delFlag != null">
-                AND del_flag_ = #{delFlag}
-            </if>
-            <if test="search != null and search != ''">
-                AND (id_ like concat('%',#{search},'%') or name_ like concat('%',#{search},'%'))
-            </if>
-            <if test="queryType != null and queryType == 'category'">
-            	and (parent_subject_id_ = 0 or parent_subject_id_ is null)
-            </if>
-            <if test="queryType != null and queryType == 'list'">
-            	and parent_subject_id_ > 0
-            </if>
-        </where>
+        where del_flag_ = 0
+        <if test="parentId != null">
+            AND parent_subject_id_ = #{parentId}
+        </if>
+        <if test="delFlag != null">
+            AND del_flag_ = #{delFlag}
+        </if>
+        <if test="search != null and search != ''">
+            AND (id_ like concat('%',#{search},'%') or name_ like concat('%',#{search},'%'))
+        </if>
+        <if test="queryType != null and queryType == 'category'">
+            and (parent_subject_id_ = 0 or parent_subject_id_ is null)
+        </if>
+        <if test="queryType != null and queryType == 'list'">
+            and parent_subject_id_ > 0
+        </if>
     </sql>
 
     <select id="findBySubjectByIdList" resultMap="Subject">
@@ -118,17 +119,14 @@
     </select>
 
     <select id="findBySubjectIds" resultMap="Subject">
-      SELECT * FROM subject WHERE id_ IN
-      <foreach collection="subjectIds" item="subjectId" separator="," open="(" close=")">
-          #{subjectId}
-      </foreach>
+        SELECT * FROM subject WHERE del_flag_ = 0 and id_ IN
+        <foreach collection="subjectIds" item="subjectId" separator="," open="(" close=")">
+            #{subjectId}
+        </foreach>
     </select>
     <select id="selectSubjectById" resultType="com.yonge.cooleshow.biz.dal.entity.Subject"
             parameterType="java.lang.String">
-        SELECT * FROM subject WHERE id_=#{lessonSubject}
+        SELECT * FROM subject WHERE del_flag_ = 0 and id_=#{lessonSubject}
     </select>
 
-    <delete id="deleteById">
-		update subject set del_flag_ = 1 where id_ = #{id} or parent_subject_id_ = #{id}
-	</delete>
 </mapper>