<?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.PostAssessmentRatingOtherMapper">

    <resultMap type="PostAssessmentRatingOther" id="PostAssessmentRatingOtherResult">
        <result property="id"    column="id"    />
        <result property="type"    column="type"    />
        <result property="batchId"    column="batch_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="status"    column="status"    />
        <result property="deptId"    column="dept_id"    />
        <result property="completeTime"    column="complete_time"    />
        <result property="scoreUserId"    column="score_user_id"    />
        <result property="scoreUserName"    column="score_user_name"    />
        <result property="createUserId"    column="create_user_id"    />
        <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"    />
    </resultMap>

    <sql id="selectPostAssessmentRatingOtherVo">
        select id, type, batch_id, start_time, status, dept_id, complete_time, score_user_id, score_user_name, create_user_id, remark, del_flag, create_time, create_by, update_time, update_by from post_assessment_rating_other
    </sql>

    <select id="selectPostAssessmentRatingOtherList" parameterType="PostAssessmentRatingOther" resultMap="PostAssessmentRatingOtherResult">
        <include refid="selectPostAssessmentRatingOtherVo"/>
        <where>
            <if test="type != null "> and type = #{type}</if>
            <if test="batchId != null  and batchId != ''"> and batch_id = #{batchId}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="completeTime != null "> and complete_time = #{completeTime}</if>
            <if test="scoreUserId != null "> and score_user_id = #{scoreUserId}</if>
            <if test="scoreUserName != null  and scoreUserName != ''"> and score_user_name like concat('%', #{scoreUserName}, '%')</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
        </where>
    </select>

    <select id="selectPostAssessmentRatingOtherById" parameterType="Long" resultMap="PostAssessmentRatingOtherResult">
        <include refid="selectPostAssessmentRatingOtherVo"/>
        where id = #{id}
    </select>

    <insert id="insertPostAssessmentRatingOther" parameterType="PostAssessmentRatingOther">
        insert into post_assessment_rating_other
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="type != null">type,</if>
            <if test="batchId != null and batchId != ''">batch_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="status != null">status,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="completeTime != null">complete_time,</if>
            <if test="scoreUserId != null">score_user_id,</if>
            <if test="scoreUserName != null">score_user_name,</if>
            <if test="createUserId != null">create_user_id,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="type != null">#{type},</if>
            <if test="batchId != null and batchId != ''">#{batchId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="status != null">#{status},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="completeTime != null">#{completeTime},</if>
            <if test="scoreUserId != null">#{scoreUserId},</if>
            <if test="scoreUserName != null">#{scoreUserName},</if>
            <if test="createUserId != null">#{createUserId},</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>
         </trim>
    </insert>

    <update id="updatePostAssessmentRatingOther" parameterType="PostAssessmentRatingOther">
        update post_assessment_rating_other
        <trim prefix="SET" suffixOverrides=",">
            <if test="type != null">type = #{type},</if>
            <if test="batchId != null and batchId != ''">batch_id = #{batchId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="completeTime != null">complete_time = #{completeTime},</if>
            <if test="scoreUserId != null">score_user_id = #{scoreUserId},</if>
            <if test="scoreUserName != null">score_user_name = #{scoreUserName},</if>
            <if test="createUserId != null">create_user_id = #{createUserId},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePostAssessmentRatingOtherById" parameterType="Long">
        delete from post_assessment_rating_other where id = #{id}
    </delete>

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

    <select id="getDeptIdList" resultType="java.lang.Long">
        SELECT "dept_id"
        FROM "public"."sys_dept" where "dept_id" != #{id};
    </select>



    <select id="selectPostAssessmentRatingOtherListGroup"
            resultType="com.ruoyi.postCheck.domain.PostAssessmentRatingOther">
        select
        max("id") id,
        max("type") "type",
        max("batch_id") batch_id,
        max("start_time") start_time,
        max("status") status,
        max("dept_id") dept_id,
        max("complete_time") complete_time,
        max("score_user_id") score_user_id,
        max("score_user_name") score_user_name,
        max("create_user_id") create_user_id,
        max("remark") remark,
        max("del_flag") del_flag,
        max("create_time") create_time,
        max("create_by") create_by,
        max("update_time") update_time from post_assessment_rating_other
        <where>
            <if test="type != null ">
                and type = #{type}
            </if>
            <if test="batchId != null  and batchId != ''">
                and batch_id = #{batchId}
            </if>
            <if test="startTime != null ">
                and start_time = #{startTime}
            </if>
            <if test="status != null ">
                and status = #{status}
            </if>
            <if test="deptId != null ">
                and dept_id = #{deptId}
            </if>
            <if test="completeTime != null ">
                and complete_time = #{completeTime}
            </if>
            <if test="scoreUserId != null ">
                and score_user_id = #{scoreUserId}
            </if>
            <if test="scoreUserName != null  and scoreUserName != ''">
                and score_user_name like concat('%', #{scoreUserName}, '%')
            </if>
            <if test="createUserId != null ">
                and create_user_id = #{createUserId}
            </if>
        </where>
        group by batch_id
    </select>

    <select id="getDeptIdListByType" resultType="java.util.Map">
        SELECT "dept_id" as deptId,"dept_name" as deptName FROM "public"."sys_dept" where "type" = #{type};
    </select>
</mapper>
