<?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.xinelu.manage.mapper.poserInfo.PoserInfoMapper">

    <resultMap type="PoserInfo" id="PoserInfoResult">
        <result property="id" column="id"/>
        <result property="nurseStationId" column="nurse_station_id"/>
        <result property="nurseItemId" column="nurse_item_id"/>
        <result property="poserName" column="poser_name"/>
        <result property="poserCode" column="poser_code"/>
        <result property="posterIntroduce" column="poster_introduce"/>
        <result property="posterPictureUrl" column="poster_picture_url"/>
        <result property="posterVideoUrl" column="poster_video_url"/>
        <result property="moduleType" column="module_type"/>
        <result property="poserSort" column="poser_sort"/>
        <result property="jumpLink" column="jump_link"/>
        <result property="jumpType" column="jump_type"/>
        <result property="jumpDictId" column="jump_dict_id"/>
        <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="selectPoserInfoVo">
        select id,
               nurse_station_id,
               nurse_item_id,
               poser_name,
               poser_code,
               poster_introduce,
               poster_picture_url,
               poster_video_url,
               module_type,
               poser_sort,
               jump_link,
               jump_type,
               jump_dict_id,
               create_by,
               create_time,
               update_by,
               update_time
        from poser_info
    </sql>

    <select id="selectPoserInfoList" parameterType="com.xinelu.manage.vo.poserInfo.PoserInfoVO"
            resultType="com.xinelu.manage.vo.poserInfo.PoserInfoVO">
        SELECT
        ns.nurse_station_name,
        nsi.nurse_item_name,
        pi.id,
        pi.nurse_station_id,
        pi.nurse_item_id,
        pi.poser_name,
        pi.poser_code,
        pi.poster_introduce,
        pi.poster_picture_url,
        pi.poster_video_url,
        pi.module_type,
        pi.poser_sort,
        pi.jump_link,
        pi.jump_type,
        pi.jump_dict_id,
        pi.create_by,
        pi.create_time,
        pi.update_by,
        pi.update_time
        FROM
        poser_info pi
        LEFT JOIN nurse_station ns ON pi.nurse_station_id = ns.id
        LEFT JOIN nurse_station_item nsi ON pi.nurse_item_id = nsi.id
        <where>
            <if test="nurseStationId != null ">
                and pi.nurse_station_id = #{nurseStationId}
            </if>
            <if test="nurseItemId != null ">
                and pi.nurse_item_id = #{nurseItemId}
            </if>
            <if test="poserName != null  and poserName != ''">
                and pi.poser_name like concat('%', #{poserName}, '%')
            </if>
            <if test="poserCode != null  and poserCode != ''">
                and pi.poser_code = #{poserCode}
            </if>
            <if test="posterIntroduce != null  and posterIntroduce != ''">
                and pi.poster_introduce = #{posterIntroduce}
            </if>
            <if test="posterPictureUrl != null  and posterPictureUrl != ''">
                and pi.poster_picture_url = #{posterPictureUrl}
            </if>
            <if test="posterVideoUrl != null  and posterVideoUrl != ''">
                and pi.poster_video_url = #{posterVideoUrl}
            </if>
            <if test="moduleType != null  and moduleType != ''">
                and pi.module_type = #{moduleType}
            </if>
            <if test="poserSort != null ">
                and pi.poser_sort = #{poserSort}
            </if>
            <if test="jumpLink != null  and jumpLink != ''">
                and pi.jump_link = #{jumpLink}
            </if>
            <if test="jumpType != null  and jumpType != ''">
                and pi.jump_type = #{jumpType}
            </if>
        </where>
        GROUP BY pi.nurse_station_id, pi.nurse_item_id, pi.module_type
        ORDER BY pi.id DESC
    </select>

    <select id="getPoserInfoList" parameterType="com.xinelu.manage.vo.poserInfo.PoserInfoVO"
            resultType="com.xinelu.manage.vo.poserInfo.PoserInfoVO">
        SELECT
        ns.nurse_station_name,
        nsi.nurse_item_name,
        pi.id,
        pi.nurse_station_id,
        pi.nurse_item_id,
        pi.poser_name,
        pi.poser_code,
        pi.poster_introduce,
        pi.poster_picture_url,
        pi.poster_video_url,
        pi.module_type,
        pi.poser_sort,
        pi.jump_link,
        pi.jump_dict_id,
        pi.create_by,
        pi.create_time,
        pi.update_by,
        pi.update_time,
        (select dict_value from sys_dict_data where dict_code = pi.jump_dict_id) jump_type
        FROM
        poser_info pi
        LEFT JOIN nurse_station ns ON pi.nurse_station_id = ns.id
        LEFT JOIN nurse_station_item nsi ON pi.nurse_item_id = nsi.id
        <where>
            <if test="nurseStationId != null ">
                and pi.nurse_station_id = #{nurseStationId}
            </if>
            <if test="nurseItemId != null ">
                and pi.nurse_item_id = #{nurseItemId}
            </if>
            <if test="poserName != null  and poserName != ''">
                and pi.poser_name like concat('%', #{poserName}, '%')
            </if>
            <if test="poserCode != null  and poserCode != ''">
                and pi.poser_code = #{poserCode}
            </if>
            <if test="posterIntroduce != null  and posterIntroduce != ''">
                and pi.poster_introduce = #{posterIntroduce}
            </if>
            <if test="posterPictureUrl != null  and posterPictureUrl != ''">
                and pi.poster_picture_url = #{posterPictureUrl}
            </if>
            <if test="posterVideoUrl != null  and posterVideoUrl != ''">
                and pi.poster_video_url = #{posterVideoUrl}
            </if>
            <if test="moduleType != null  and moduleType != ''">
                and pi.module_type = #{moduleType}
            </if>
            <if test="poserSort != null ">
                and pi.poser_sort = #{poserSort}
            </if>
            <if test="jumpLink != null  and jumpLink != ''">
                and pi.jump_link = #{jumpLink}
            </if>
            <if test="jumpType != null  and jumpType != ''">
                and pi.jump_type = #{jumpType}
            </if>
        </where>
    </select>

    <select id="selectPoserInfoById" parameterType="Long"
            resultType="com.xinelu.manage.vo.poserInfo.PoserInfoVO">
        SELECT ns.nurse_station_name,
               nsi.nurse_item_name,
               pi.id,
               pi.nurse_station_id,
               pi.nurse_item_id,
               pi.poser_name,
               pi.poser_code,
               pi.poster_introduce,
               pi.poster_picture_url,
               pi.poster_video_url,
               pi.module_type,
               pi.poser_sort,
               pi.jump_link,
               pi.jump_type,
               pi.jump_dict_id,
               pi.create_by,
               pi.create_time,
               pi.update_by,
               pi.update_time
        FROM poser_info pi
                 LEFT JOIN nurse_station ns ON pi.nurse_station_id = ns.id
                 LEFT JOIN nurse_station_item nsi ON pi.nurse_item_id = nsi.id
        where pi.id = #{id}
    </select>

    <insert id="insertPoserInfo" parameterType="com.xinelu.manage.dto.poserInfo.PoserInfoDTO" useGeneratedKeys="true"
            keyProperty="id">
        insert into poser_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nurseStationId != null">nurse_station_id,
            </if>
            <if test="nurseItemId != null">nurse_item_id,
            </if>
            <if test="poserName != null">poser_name,
            </if>
            <if test="poserCode != null">poser_code,
            </if>
            <if test="posterIntroduce != null">poster_introduce,
            </if>
            <if test="posterPictureUrl != null">poster_picture_url,
            </if>
            <if test="posterVideoUrl != null">poster_video_url,
            </if>
            <if test="moduleType != null">module_type,
            </if>
            <if test="poserSort != null">poser_sort,
            </if>
            <if test="jumpLink != null">jump_link,
            </if>
            <if test="jumpType != null">jump_type,
            </if>
            <if test="jumpDictId != null">jump_dict_id,
            </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="nurseStationId != null">#{nurseStationId},
            </if>
            <if test="nurseItemId != null">#{nurseItemId},
            </if>
            <if test="poserName != null">#{poserName},
            </if>
            <if test="poserCode != null">#{poserCode},
            </if>
            <if test="posterIntroduce != null">#{posterIntroduce},
            </if>
            <if test="posterPictureUrl != null">#{posterPictureUrl},
            </if>
            <if test="posterVideoUrl != null">#{posterVideoUrl},
            </if>
            <if test="moduleType != null">#{moduleType},
            </if>
            <if test="poserSort != null">#{poserSort},
            </if>
            <if test="jumpLink != null">#{jumpLink},
            </if>
            <if test="jumpType != null">#{jumpType},
            </if>
            <if test="jumpDictId != null">#{jumpDictId},
            </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="updatePoserInfo" parameterType="com.xinelu.manage.dto.poserInfo.PoserInfoDTO">
        update poser_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="nurseStationId != null">nurse_station_id =
                #{nurseStationId},
            </if>
            <if test="nurseItemId != null">nurse_item_id =
                #{nurseItemId},
            </if>
            <if test="poserName != null">poser_name =
                #{poserName},
            </if>
            <if test="poserCode != null">poser_code =
                #{poserCode},
            </if>
            poster_introduce = #{posterIntroduce},
            <if test="posterPictureUrl != null">poster_picture_url =
                #{posterPictureUrl},
            </if>
            <if test="posterVideoUrl != null">poster_video_url =
                #{posterVideoUrl},
            </if>
            <if test="moduleType != null">module_type =
                #{moduleType},
            </if>
            <if test="poserSort != null">poser_sort =
                #{poserSort},
            </if>
            jump_link = #{jumpLink},
            <if test="jumpType != null">jump_type =
                #{jumpType},
            </if>
            jump_dict_id = #{jumpDictId},
            <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="deletePoserInfoById" parameterType="Long">
        delete
        from poser_info
        where id = #{id}
    </delete>

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


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

    <insert id="insertPoserInfoList">
        insert into poser_info(
        nurse_station_id,
        nurse_item_id,
        poser_name,
        poser_code,
        poster_introduce,
        poster_picture_url,
        poster_video_url,
        module_type,
        poser_sort,
        jump_link,
        jump_type,
        jump_dict_id,
        create_by,
        create_time,
        update_by,
        update_time
        ) values
        <foreach item="insertPoserInfoList" index="index" collection="list" separator=",">
            (
            #{insertPoserInfoList.nurseStationId},
            #{insertPoserInfoList.nurseItemId},
            #{insertPoserInfoList.poserName},
            #{insertPoserInfoList.poserCode},
            #{insertPoserInfoList.posterIntroduce},
            #{insertPoserInfoList.posterPictureUrl},
            #{insertPoserInfoList.posterVideoUrl},
            #{insertPoserInfoList.moduleType},
            #{insertPoserInfoList.poserSort},
            #{insertPoserInfoList.jumpLink},
            #{insertPoserInfoList.jumpType},
            #{insertPoserInfoList.jumpDictId},
            #{insertPoserInfoList.createBy},
            #{insertPoserInfoList.createTime},
            #{insertPoserInfoList.updateBy},
            #{insertPoserInfoList.updateTime}
            )
        </foreach>
    </insert>

    <select id="selectPoserInfoByModuleType" parameterType="com.xinelu.manage.vo.poserInfo.PoserInfoVO"
            resultType="com.xinelu.manage.vo.poserInfo.PoserInfoVO">
        SELECT ns.nurse_station_name,
        nsi.nurse_item_name,
        pi.id,
        pi.nurse_station_id,
        pi.nurse_item_id,
        pi.poser_name,
        pi.poser_code,
        pi.poster_introduce,
        pi.poster_picture_url,
        pi.poster_video_url,
        pi.module_type,
        pi.poser_sort,
        pi.jump_link,
        pi.jump_type,
        pi.jump_dict_id,
        pi.create_by,
        pi.create_time,
        pi.update_by,
        pi.update_time
        FROM poser_info pi
        LEFT JOIN nurse_station ns ON pi.nurse_station_id = ns.id
        LEFT JOIN nurse_station_item nsi ON pi.nurse_item_id = nsi.id
        <where>
            <if test="moduleType != null  and moduleType != ''">
                and pi.module_type = #{moduleType}
            </if>
        </where>
        GROUP BY pi.module_type
    </select>

    <select id="selectPoserInfoByModuleTypeList" parameterType="com.xinelu.manage.vo.poserInfo.PoserInfoVO"
            resultType="com.xinelu.manage.vo.poserInfo.PoserInfoVO">
        SELECT ns.nurse_station_name,
        nsi.nurse_item_name,
        pi.id,
        pi.nurse_station_id,
        pi.nurse_item_id,
        pi.poser_name,
        pi.poser_code,
        pi.poster_introduce,
        IFNULL(pi.poster_picture_url, '') poster_picture_url,
        IFNULL(pi.poster_video_url, '') poster_video_url,
        pi.module_type,
        pi.poser_sort,
        pi.jump_link,
        pi.jump_type,
        pi.jump_dict_id,
        pi.create_by,
        pi.create_time,
        pi.update_by,
        pi.update_time
        FROM poser_info pi
        LEFT JOIN nurse_station ns ON pi.nurse_station_id = ns.id
        LEFT JOIN nurse_station_item nsi ON pi.nurse_item_id = nsi.id
        <where>
            <if test="moduleType != null  and moduleType != ''">
                and pi.module_type = #{moduleType}
            </if>
            <if test="nurseStationId != null ">
                and pi.nurse_station_id = #{nurseStationId}
            </if>
            <if test="nurseItemId != null ">
                and pi.nurse_item_id = #{nurseItemId}
            </if>
        </where>
    </select>

    <select id="getPoserInfoByModuleTypeAndId" resultType="int">
        select count(1) from poser_info
        <where>
            <if test="moduleType != null and moduleType != ''">
                and module_type = #{moduleType}
            </if>
            <if test="stationId != null">
                and nurse_station_id = #{stationId}
            </if>
            <if test="itemId != null">
                and nurse_item_id = #{itemId}
            </if>
        </where>
    </select>

    <select id="selectPoserList" parameterType="PoserInfo" resultMap="PoserInfoResult">
        <include refid="selectPoserInfoVo"/>
        <where>
            <if test="nurseStationId != null ">
                and nurse_station_id = #{nurseStationId}
            </if>
            <if test="nurseItemId != null ">
                and nurse_item_id = #{nurseItemId}
            </if>
            <if test="poserName != null  and poserName != ''">
                and poser_name like concat('%', #{poserName}, '%')
            </if>
            <if test="poserCode != null  and poserCode != ''">
                and poser_code = #{poserCode}
            </if>
            <if test="posterIntroduce != null  and posterIntroduce != ''">
                and poster_introduce = #{posterIntroduce}
            </if>
            <if test="posterPictureUrl != null  and posterPictureUrl != ''">
                and poster_picture_url = #{posterPictureUrl}
            </if>
            <if test="posterVideoUrl != null  and posterVideoUrl != ''">
                and poster_video_url = #{posterVideoUrl}
            </if>
            <if test="moduleType != null  and moduleType != ''">
                and module_type = #{moduleType}
            </if>
            <if test="poserSort != null ">
                and poser_sort = #{poserSort}
            </if>
            <if test="jumpLink != null  and jumpLink != ''">
                and jump_link = #{jumpLink}
            </if>
            <if test="jumpType != null  and jumpType != ''">
                and jump_type = #{jumpType}
            </if>
        </where>
    </select>

    <select id="selectPoserListByModuleTyp" resultType="com.xinelu.manage.domain.poserInfo.PoserInfo">
        <include refid="selectPoserInfoVo"/>
        <where>
            <if test="moduleType != null  and moduleType != ''">
                and module_type = #{moduleType}
            </if>
        </where>
    </select>

    <select id="selectPosterImageJump" parameterType="String" resultType="SysDictData">
        SELECT sdd.dict_code,
        sdd.dict_label,
        sdd.dict_value,
        sdd.dict_type
        FROM
        sys_dict_data sdd
        <where>
            <if test="dictType != null and dictType != ''">
                AND sdd.dict_type = #{dictType}
            </if>
        </where>
    </select>
</mapper>
