<?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.xinyilu.system.mapper.motionprescriptioninfo.MotionPrescriptionDictMapper">

    <resultMap type="MotionPrescriptionDict" id="MotionPrescriptionDictResult">
        <result property="id" column="id"/>
        <result property="motionName" column="motion_name"/>
        <result property="motionContent" column="motion_content"/>
        <result property="applyCrowd" column="apply_crowd"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectMotionPrescriptionDictVo">
        select id, motion_name, motion_content, apply_crowd, del_flag, create_by, create_time, update_by, update_time
        from motion_prescription_dict
    </sql>

    <select id="selectMotionPrescriptionDictList" parameterType="MotionPrescriptionDict"
            resultMap="MotionPrescriptionDictResult">
        <include refid="selectMotionPrescriptionDictVo"/>
        <where>
            <if test="motionName != null  and motionName != ''">
                and motion_name like concat('%', #{motionName}, '%')
            </if>
            <if test="motionContent != null  and motionContent != ''">
                and motion_content like concat('%', #{motionContent}, '%')
            </if>
            <if test="applyCrowd != null ">
                and apply_crowd = #{applyCrowd}
            </if>
            and del_flag = 0
        </where>
        order by create_time desc
    </select>

    <select id="selectMotionPrescriptionDictById" parameterType="Long"
            resultMap="MotionPrescriptionDictResult">
        <include refid="selectMotionPrescriptionDictVo"/>
        where id = #{id} and del_flag = 0
    </select>

    <insert id="insertMotionPrescriptionDict" parameterType="MotionPrescriptionDict" useGeneratedKeys="true"
            keyProperty="id">
        insert into motion_prescription_dict
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="motionName != null">motion_name,
            </if>
            <if test="motionContent != null">motion_content,
            </if>
            <if test="applyCrowd != null">apply_crowd,
            </if>
            <if test="delFlag != null">del_flag,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="motionName != null">#{motionName},
            </if>
            <if test="motionContent != null">#{motionContent},
            </if>
            <if test="applyCrowd != null">#{applyCrowd},
            </if>
            <if test="delFlag != null">#{delFlag},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateMotionPrescriptionDict" parameterType="MotionPrescriptionDict">
        update motion_prescription_dict
        <trim prefix="SET" suffixOverrides=",">
            <if test="motionName != null">motion_name =
                #{motionName},
            </if>
            <if test="motionContent != null">motion_content =
                #{motionContent},
            </if>
            <if test="applyCrowd != null">apply_crowd =
                #{applyCrowd},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMotionPrescriptionDictById" parameterType="Long">
        delete from motion_prescription_dict where id = #{id}
    </delete>

    <delete id="deleteMotionPrescriptionDictByIds" parameterType="String">
        delete from motion_prescription_dict where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="updateMotionPrescriptionDictById" parameterType="String">
        update motion_prescription_dict set del_flag = 1, update_time = now() where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>