xkrs_ms/stdiet-custom/src/main/resources/mapper/custom/SysNutritionQuestionMapper.xml
2021-04-20 18:17:49 +08:00

132 lines
6.2 KiB
XML

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stdiet.custom.mapper.SysNutritionQuestionMapper">
<resultMap type="SysNutritionQuestion" id="SysNutritionQuestionResult">
<result property="id" column="id" />
<result property="title" column="title" />
<result property="content" column="content" />
<result property="key" column="key" />
<result property="titleContentIndex" column="title_content_index" />
<result property="showFlag" column="show_flag" />
<result property="createTime" column="create_time" />
<result property="createBy" column="create_by" />
<result property="updateTime" column="update_time" />
<result property="updateBy" column="update_by" />
<result property="delFlag" column="del_flag" />
</resultMap>
<!-- 部分字段resultMap -->
<resultMap type="com.stdiet.custom.dto.response.NutritionQuestionResponse" id="SysNutritionQuestionResultExtended">
<result property="id" column="id" />
<result property="title" column="title" />
<result property="content" column="content" />
<result property="key" column="key" />
<result property="key" column="key" />
<result property="showFlag" column="show_flag" />
<result property="createTime" column="create_time" />
</resultMap>
<sql id="selectSysNutritionQuestionVo">
select id, title, content, `key`, title_content_index, show_flag, create_time, create_by, update_time, update_by, del_flag from sys_nutrition_question
</sql>
<select id="selectSysNutritionQuestionList" parameterType="SysNutritionQuestion" resultMap="SysNutritionQuestionResult">
<include refid="selectSysNutritionQuestionVo"/> where del_flag = 0
</select>
<select id="selectSysNutritionQuestionById" parameterType="Long" resultMap="SysNutritionQuestionResult">
<include refid="selectSysNutritionQuestionVo"/>
where id = #{id} and del_flag = 0
</select>
<insert id="insertSysNutritionQuestion" parameterType="SysNutritionQuestion" useGeneratedKeys="true" keyProperty="id">
insert into sys_nutrition_question
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="title != null">title,</if>
<if test="content != null">content,</if>
<if test="key != null and key != ''">`key`,</if>
<if test="titleContentIndex != null">title_content_index,</if>
<if test="showFlag != null">show_flag,</if>
<if test="createTime != null">create_time,</if>
<if test="createBy != null">create_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="delFlag != null">del_flag,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="title != null">#{title},</if>
<if test="content != null">#{content},</if>
<if test="key != null and key != ''">#{key},</if>
<if test="titleContentIndex != null">#{titleContentIndex},</if>
<if test="showFlag != null">#{showFlag},</if>
<if test="createTime != null">#{createTime},</if>
<if test="createBy != null">#{createBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="delFlag != null">#{delFlag},</if>
</trim>
</insert>
<update id="updateSysNutritionQuestion" parameterType="SysNutritionQuestion">
update sys_nutrition_question
<trim prefix="SET" suffixOverrides=",">
<if test="title != null">title = #{title},</if>
<if test="content != null">content = #{content},</if>
<if test="key != null and key != ''">`key` = #{key},</if>
<if test="titleContentIndex != null">title_content_index = #{titleContentIndex},</if>
<if test="showFlag != null">show_flag = #{showFlag},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
</trim>
where id = #{id}
</update>
<update id="deleteSysNutritionQuestionById" parameterType="Long">
update sys_nutrition_question set del_flag = 1 where id = #{id}
</update>
<update id="deleteSysNutritionQuestionByIds" parameterType="String">
update sys_nutrition_question set del_flag = 1 where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
<!-- 根据关键词查询对应知识问题 -->
<select id="getNutritionQuestionListByKey" parameterType="SysNutritionQuestion" resultMap="SysNutritionQuestionResultExtended">
select id, title, `key`, content, show_flag, create_time where del_flag = 0
<if test="showFlag != null "> and show_flag = #{showFlag}</if>
<if test="key != null and key != ''">
and (title like CONCAT('%',#{key},'%') or key like CONCAT('%',#{key},'%') or titleContentIndex like CONCAT('%',#{key},'%'))
</if>
order by id desc
</select>
<!-- 查询总数 -->
<select id="getNutritionQuestionCount" resultType="int">
select count(id) from sys_nutrition_question where del_flag = 0
</select>
<!-- 分页查询-->
<select id="getNutritionQuestionListByPage" resultMap="SysNutritionQuestionResult">
select * from sys_nutrition_question where del_flag = 0 order by id asc limit #{start},#{pageSize}
</select>
<update id="updateWxShowByIds">
update sys_nutrition_question set show_flag = #{wxShow} where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</update>
</mapper>