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

    <resultMap type="PostAssessmentRatingOtherInfo" id="PostAssessmentRatingOtherInfoResult">
        <result property="id"    column="id"    />
        <result property="ratingOtherId"    column="rating_other_id"    />
        <result property="dutyType"    column="duty_type"    />
        <result property="scoreWeight"    column="score_weight"    />
        <result property="rule"    column="rule"    />
        <result property="byDeptId"    column="by_dept_id"    />
        <result property="byDeptName"    column="by_dept_name"    />
        <result property="byDeptScore"    column="by_dept_score"    />
        <result property="improvementSuggestions"    column="improvement_suggestions"    />
        <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="selectPostAssessmentRatingOtherInfoVo">
        select
            id, rating_other_id, duty_type,
            score_weight, rule, by_dept_id, by_dept_name, by_dept_score, improvement_suggestions,
            create_user_id, remark, del_flag, create_time, create_by, update_time, update_by
        from post_assessment_rating_other_info
    </sql>

    <select id="selectPostAssessmentRatingOtherInfoList" parameterType="PostAssessmentRatingOtherInfo" resultMap="PostAssessmentRatingOtherInfoResult">
        <!--<include refid="selectPostAssessmentRatingOtherInfoVo"/>-->
        select
            info.id,
            info.rating_other_id,
            info.duty_type,
            info.score_weight,
            info.rule,
            info.by_dept_id,
            info.by_dept_name,
            info.by_dept_score,
            info.improvement_suggestions,
            info.create_user_id,
            info.remark,
            info.del_flag,
            info.create_time,
            info.create_by,
            info.update_time,
            info.update_by
        from post_assessment_rating_other_info info
        LEFT JOIN "sys_dept" sd ON sd."dept_id" = info."by_dept_id"
        <where>
            <if test="ratingOtherId != null "> and rating_other_id = #{ratingOtherId}</if>
            <if test="dutyType != null "> and duty_type = #{dutyType}</if>
            <if test="scoreWeight != null "> and score_weight = #{scoreWeight}</if>
            <if test="rule != null  and rule != ''"> and rule = #{rule}</if>
            <if test="byDeptId != null "> and by_dept_id = #{byDeptId}</if>
            <if test="byDeptScore != null "> and by_dept_score = #{byDeptScore}</if>
            <if test="improvementSuggestions != null  and improvementSuggestions != ''"> and improvement_suggestions = #{improvementSuggestions}</if>
            <if test="createUserId != null "> and create_user_id = #{createUserId}</if>
        </where>
        ORDER BY info.duty_type, sd.order_num, info.by_dept_id
    </select>

    <select id="selectPostAssessmentRatingOtherInfoById" parameterType="Long" resultMap="PostAssessmentRatingOtherInfoResult">
        <include refid="selectPostAssessmentRatingOtherInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertPostAssessmentRatingOtherInfo" parameterType="PostAssessmentRatingOtherInfo">
        insert into post_assessment_rating_other_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="ratingOtherId != null">rating_other_id,</if>
            <if test="dutyType != null">duty_type,</if>
            <if test="scoreWeight != null">score_weight,</if>
            <if test="rule != null">rule,</if>
            <if test="byDeptId != null">by_dept_id,</if>
            <if test="byDeptName != null and byDeptName != ''">by_dept_name,</if>
            <if test="byDeptScore != null">by_dept_score,</if>
            <if test="improvementSuggestions != null">improvement_suggestions,</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">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="ratingOtherId != null">#{ratingOtherId},</if>
            <if test="dutyType != null">#{dutyType},</if>
            <if test="scoreWeight != null">#{scoreWeight},</if>
            <if test="rule != null">#{rule},</if>
            <if test="byDeptId != null">#{byDeptId},</if>
            <if test="byDeptName != null and byDeptName != ''">#{byDeptName},</if>
            <if test="byDeptScore != null">#{byDeptScore},</if>
            <if test="improvementSuggestions != null">#{improvementSuggestions},</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">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updatePostAssessmentRatingOtherInfo" parameterType="PostAssessmentRatingOtherInfo">
        update post_assessment_rating_other_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="ratingOtherId != null">rating_other_id = #{ratingOtherId},</if>
            <if test="dutyType != null">duty_type = #{dutyType},</if>
            <if test="scoreWeight != null">score_weight = #{scoreWeight},</if>
            <if test="rule != null">rule = #{rule},</if>
            <if test="byDeptId != null">by_dept_id = #{byDeptId},</if>
            <if test="byDeptName != null and byDeptName != ''">by_dept_name = #{byDeptName},</if>
            <if test="byDeptScore != null">by_dept_score = #{byDeptScore},</if>
            <if test="improvementSuggestions != null">improvement_suggestions = #{improvementSuggestions},</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">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePostAssessmentRatingOtherInfoById" parameterType="Long">
        delete from post_assessment_rating_other_info where id = #{id}
    </delete>

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