<?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.ximai.mes.md.mapper.MdWorkunitWorkerMapper">

    <resultMap type="MdWorkunitWorker" id="MdWorkunitWorkerResult">
        <result property="id" column="id"/>
        <result property="workunitId" column="workunit_id"/>
        <result property="postId" column="post_id"/>
        <result property="postName" column="post_name"/>
        <result property="userId" column="user_id"/>
        <result property="userName" column="user_name"/>
        <result property="nickName" column="nick_name"/>
        <result property="remark" column="remark"/>
        <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="selectMdWorkunitWorkerVo">
        select t1.id,
               t1.workunit_id,
               t1.post_id,
               t1.post_name,
               t1.user_id,
               t1.user_name,
               t1.nick_name,
               t1.remark,
               t1.create_by,
               t1.create_time,
               t1.update_by,
               t2.workunit_name,
               t1.update_time
        from md_workunit_worker t1
                 inner join md_workunit t2 on t1.workunit_id = t2.workunit_id

    </sql>

    <select id="selectMdWorkunitWorkerList" parameterType="MdWorkunitWorker" resultMap="MdWorkunitWorkerResult">
        <include refid="selectMdWorkunitWorkerVo"/>
        <where>
            <if test="workunitId != null ">and t1.workunit_id = #{workunitId}</if>
            <if test="postId != null ">and post_id = #{postId}</if>
            <if test="postName != null  and postName != ''">and post_name like concat('%', #{postName}, '%')</if>
            <if test="userId != null ">and user_id = #{userId}</if>
            <if test="userName != null  and userName != ''">and user_name like concat('%', #{userName}, '%')</if>
            <if test="nickName != null  and nickName != ''">and nick_name like concat('%', #{nickName}, '%')</if>
        </where>
    </select>

    <select id="selectMdWorkunitWorkerById" parameterType="Long" resultMap="MdWorkunitWorkerResult">
        <include refid="selectMdWorkunitWorkerVo"/>
        where id = #{id}
    </select>

    <insert id="insertMdWorkunitWorker" parameterType="MdWorkunitWorker" useGeneratedKeys="true" keyProperty="id">
        insert into md_workunit_worker
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workunitId != null">workunit_id,</if>
            <if test="postId != null">post_id,</if>
            <if test="postName != null">post_name,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="nickName != null">nick_name,</if>
            <if test="remark != null">remark,</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="workunitId != null">#{workunitId},</if>
            <if test="postId != null">#{postId},</if>
            <if test="postName != null">#{postName},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="nickName != null">#{nickName},</if>
            <if test="remark != null">#{remark},</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="updateMdWorkunitWorker" parameterType="MdWorkunitWorker">
        update md_workunit_worker
        <trim prefix="SET" suffixOverrides=",">
            <if test="workunitId != null">workunit_id = #{workunitId},</if>
            <if test="postId != null">post_id = #{postId},</if>
            <if test="postName != null">post_name = #{postName},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="remark != null">remark = #{remark},</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="deleteMdWorkunitWorkerById" parameterType="Long">
        delete
        from md_workunit_worker
        where id = #{id}
    </delete>

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