<?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.ruoyi.postCheck.mapper.PostCheckedMapper">

    <resultMap type="PostChecked" id="PostCheckedResult">
        <result property="id"    column="id"/>
        <result property="postCode"    column="post_code"/>
        <result property="checkWorkgroupId"    column="check_workgroup_id"    />
        <result property="checkGroupId"    column="check_group_id"    />

        <result property="checkedDeptId"    column="checked_dept_id"    />
        <result property="checkedDeptType"    column="checked_dept_type"    />
        <result property="checkedDeptName"    column="checked_dept_name"    />

        <result property="checkedPostId"    column="checked_post_id"    />
        <result property="checkedPostName"    column="checked_post_name"    />

        <result property="printUserId"    column="print_user_id"    />
        <result property="printTime"    column="print_time"    />
        <result property="checkedImg"    column="checked_img"    />
        <result property="checkedUserName"    column="checked_user_name"    />
        <result property="checkedTime"    column="checked_time"    />
        <result property="uploadUserId"    column="upload_user_id"    />
        <result property="uploadTime"    column="upload_time"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_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="createUserId"    column="create_user_id"    />

        <result property="status"    column="status"    />
        <result property="statusByUserId"    column="status_by_user_id"    />
        <result property="statusByUserName"    column="status_by_user_name"    />
        <result property="reason"    column="reason"    />
        <result property="statusApproveTime"    column="status_approve_time"    />
        <result property="checkedType"    column="checked_type"    />
        <result property="versionNo"    column="version_no"/>
    </resultMap>

    <sql id="selectPostCheckedVo">
        SELECT
            t1.id,
            t1.post_code,
            t1.check_workgroup_id,
            t1.check_group_id,
            t1.checked_dept_id,
            t1.checked_dept_type,
            t1.checked_dept_name,
            t1.checked_post_id,
            t1.checked_post_name,
            t1.print_user_id,
            t1.print_time,
            t1.checked_img,
            t1.checked_user_name,
            t1.checked_time,
            t1.upload_user_id,
            t1.upload_time,
            t1.remark,
            t1.del_flag,
            t1.create_time,
            t1.create_by,
            t1.update_time,
            t1.update_by,
            t1.create_user_id,
            t1.status,
            t1.status_by_user_id,
            t1.status_by_user_name,
            t1.reason,
            t1.status_approve_time,
            t1.checked_type,
            t1.version_no,
            pt1.name AS checkWorkgroupName,
            pt2.name AS checkGroupName,
            case t1.checked_dept_type
             when 1 then '职能部门'
             when 2 then '生产部门'
             else 'Other'
             end  AS checkedDeptTypeView
        FROM post_checked t1
        LEFT JOIN post_team pt1 ON pt1.id = t1.check_workgroup_id
        LEFT JOIN post_team pt2 ON pt2.id = t1.check_group_id
        <!--
        LEFT JOIN sys_dept sd ON sd.dept_id = t1.checked_dept_id
        LEFT JOIN sys_post sp ON sp.post_id = t1.checked_post_id
        -->
    </sql>

    <select id="selectPostCheckedList" parameterType="PostChecked" resultMap="PostCheckedResult">
        <include refid="selectPostCheckedVo"/>
        <where>
            <if test="checkWorkgroupId != null "> and t1.check_workgroup_id = #{checkWorkgroupId}</if>
            <if test="checkGroupId != null "> and t1.check_group_id = #{checkGroupId}</if>
            <if test="checkedDeptType != null "> and t1.checked_dept_type = #{checkedDeptType}</if>
            <if test="checkedDeptId != null "> and t1.checked_dept_id = #{checkedDeptId}</if>
            <if test="checkedPostId != null "> and t1.checked_post_id = #{checkedPostId}</if>
            <if test="checkedPostName != null and checkedPostName != ''">and t1.post_name like concat('%', #{checkedPostName}, '%')</if>
            <if test="printUserId != null "> and t1.print_user_id = #{printUserId}</if>
            <if test="printTime != null "> and t1.print_time = #{printTime}</if>
            <if test="checkedImg != null  and checkedImg != ''"> and t1.checked_img = #{checkedImg}</if>
            <if test="checkedUserName != null  and checkedUserName != ''"> and t1.checked_user_name like concat('%', #{checkedUserName}, '%')</if>
            <if test="checkedTime != null "> and t1.checked_time = #{checkedTime}</if>
            <if test="uploadUserId != null "> and t1.upload_user_id = #{uploadUserId}</if>
            <if test="uploadTime != null "> and t1.upload_time = #{uploadTime}</if>
            <if test="createUserId != null "> and t1.create_user_id = #{createUserId}</if>

            <if test="postCode != null  and postCode != ''"> and t1.post_code like concat('%', #{postCode}, '%')</if>
            <if test="checkedDeptName != null  and checkedDeptName != ''"> and t1.checked_dept_name like concat('%', #{checkedDeptName}, '%')</if>
            <if test="checkWorkgroupName != null  and checkWorkgroupName != ''"> and pt1."name" like concat('%', #{checkWorkgroupName}, '%')</if>
            <if test="checkGroupName != null  and checkGroupName != ''"> and pt2."name" like concat('%', #{checkGroupName}, '%')</if>

            <if test="status != null "> and t1.status = #{status}</if>
            <if test="statusByUserId != null "> and status_by_user_id = #{statusByUserId}</if>
            <if test="statusByUserName != null  and statusByUserName != ''"> and status_by_user_name like concat('%', #{statusByUserName}, '%')</if>
            <if test="reason != null  and reason != ''"> and t1.reason like concat('%', #{reason}, '%')</if>
            <if test="checkedType != null "> and t1.checked_type = #{checkedType}</if>


             <if test="deptIdList != null and deptIdList.size() > 0">
                 AND t1.checked_dept_id in
                 <foreach collection="deptIdList" item="item" open="(" separator="," close=")">
                     #{item}
                 </foreach>
             </if>

             <if test="idList != null and idList.size() > 0">
                 AND t1.id in
                 <foreach collection="idList" item="item" open="(" separator="," close=")">
                     #{item}
                 </foreach>
             </if>

            <if test="statusList != null  and statusList.size != 0">
                and t1.status IN
                <foreach collection="statusList" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="selectPostCheckedById" parameterType="Long" resultMap="PostCheckedResult">
        <include refid="selectPostCheckedVo"/>
        where t1.id = #{id}
    </select>

    <insert id="insertPostChecked" parameterType="PostChecked">
        insert into post_checked
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            post_code,
            <if test="checkWorkgroupId != null">check_workgroup_id,</if>
            <if test="checkGroupId != null">check_group_id,</if>

            <if test="checkedDeptType != null">checked_dept_type,</if>
            <if test="checkedDeptId != null">checked_dept_id,</if>
            <if test="checkedDeptName != null">checked_dept_name,</if>
            <if test="checkedPostId != null">checked_post_id,</if>
            <if test="checkedPostName != null">checked_post_name,</if>

            <if test="printUserId != null">print_user_id,</if>
            <if test="printTime != null">print_time,</if>
            <if test="checkedImg != null">checked_img,</if>
            <if test="checkedUserName != null">checked_user_name,</if>
            <if test="checkedTime != null">checked_time,</if>
            <if test="uploadUserId != null">upload_user_id,</if>
            <if test="uploadTime != null">upload_time,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null and updateBy != ''">update_by,</if>
            <if test="createUserId != null">create_user_id,</if>
            <if test="status != null">status,</if>
            <if test="statusByUserId != null">status_by_user_id,</if>
            <if test="statusByUserName != null">status_by_user_name,</if>
            <if test="reason != null">reason,</if>
            <if test="statusApproveTime != null">status_approve_time,</if>
            <if test="checkedType != null">checked_type,</if>
            <if test="versionNo != null and versionNo != ''">version_no,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            #{postCode},
            <if test="checkWorkgroupId != null">#{checkWorkgroupId},</if>
            <if test="checkGroupId != null">#{checkGroupId},</if>
            <if test="checkedDeptType != null">#{checkedDeptType},</if>
            <if test="checkedDeptId != null">#{checkedDeptId},</if>
            <if test="checkedDeptName != null">#{checkedDeptName},</if>
            <if test="checkedPostId != null">#{checkedPostId},</if>
            <if test="checkedPostName != null">#{checkedPostName},</if>
            <if test="printUserId != null">#{printUserId},</if>
            <if test="printTime != null">#{printTime},</if>
            <if test="checkedImg != null">#{checkedImg},</if>
            <if test="checkedUserName != null">#{checkedUserName},</if>
            <if test="checkedTime != null">#{checkedTime},</if>
            <if test="uploadUserId != null">#{uploadUserId},</if>
            <if test="uploadTime != null">#{uploadTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null and updateBy != ''">#{updateBy},</if>
            <if test="createUserId != null">#{createUserId},</if>

            <if test="status != null">#{status},</if>
            <if test="statusByUserId != null">#{statusByUserId},</if>
            <if test="statusByUserName != null">#{statusByUserName},</if>
            <if test="reason != null">#{reason},</if>
            <if test="statusApproveTime != null">#{statusApproveTime},</if>
            <if test="checkedType != null">#{checkedType},</if>
            <if test="versionNo != null and versionNo != ''">#{versionNo},</if>
         </trim>
    </insert>

    <update id="updatePostChecked" parameterType="PostChecked">
        update post_checked
        <trim prefix="SET" suffixOverrides=",">
            <if test="checkWorkgroupId != null">check_workgroup_id = #{checkWorkgroupId},</if>
            <if test="checkGroupId != null">check_group_id = #{checkGroupId},</if>
            <if test="checkedDeptType != null">checked_dept_type = #{checkedDeptType},</if>
            <if test="checkedDeptId != null">checked_dept_id = #{checkedDeptId},</if>
            <if test="checkedDeptName != null">checked_dept_name = #{checkedDeptName},</if>
            <if test="checkedPostId != null">checked_post_id = #{checkedPostId},</if>
            <if test="checkedPostName != null">checked_post_name = #{checkedPostName},</if>
            <if test="printUserId != null">print_user_id = #{printUserId},</if>
            <if test="printTime != null">print_time = #{printTime},</if>
            <if test="checkedImg != null">checked_img = #{checkedImg},</if>
            <if test="checkedUserName != null">checked_user_name = #{checkedUserName},</if>
            <if test="checkedTime != null">checked_time = #{checkedTime},</if>
            <if test="uploadUserId != null">upload_user_id = #{uploadUserId},</if>
            <if test="uploadTime != null">upload_time = #{uploadTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</if>

            <if test="status != null">status = #{status},</if>
            <if test="statusByUserId != null">status_by_user_id = #{statusByUserId},</if>
            <if test="statusByUserName != null">status_by_user_name = #{statusByUserName},</if>
            <if test="reason != null and reason != ''">reason = #{reason},</if>
            <if test="statusApproveTime != null">status_approve_time = #{statusApproveTime},</if>
            <if test="checkedType != null">checked_type = #{checkedType},</if>
            <if test="versionNo != null and versionNo != ''">version_no = #{versionNo},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePostCheckedById" parameterType="Long">
        delete from post_checked where id = #{id}
    </delete>

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