<?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.shzg.project.worn.mapper.WornTechnicalAppraisalMapper">
    
    <resultMap type="WornTechnicalAppraisal" id="WornTechnicalAppraisalResult">
        <result property="id"    column="id"    />
        <result property="appraisalNo"    column="appraisal_no"    />
        <result property="billId"    column="bill_id"    />
        <result property="billNo"    column="bill_no"    />
        <result property="projectId"    column="project_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="appraisalDesc"    column="appraisal_desc"    />
        <result property="status"    column="status"    />
        <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"    />
        <result property="isDelete"    column="is_delete"    />
    </resultMap>

    <sql id="selectWornTechnicalAppraisalVo">
        select id, appraisal_no, bill_id, bill_no, project_id, user_id, user_name, appraisal_desc, status, remark, create_by, create_time, update_by, update_time, is_delete from worn_technical_appraisal
    </sql>

    <select id="selectWornTechnicalAppraisalList" parameterType="WornTechnicalAppraisal" resultMap="WornTechnicalAppraisalResult">
        select *
        from worn_technical_appraisal
        <where>
            (is_delete = '0' or is_delete is null)
            <if test="billNo != null and billNo != ''">
                and bill_no = #{billNo}
            </if>
            <if test="appraisalNo != null and appraisalNo != ''">
                and appraisal_no = #{appraisalNo}
            </if>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
        </where>
        order by id desc
    </select>

    <select id="selectWornTechnicalAppraisalById" parameterType="Long" resultMap="WornTechnicalAppraisalResult">
        select
            id,
            appraisal_no,
            bill_id,
            bill_no,
            project_id,
            user_id,
            user_name,
            appraisal_desc,
            status,
            remark,
            create_by,
            create_time,
            update_by,
            update_time,
            is_delete
        from worn_technical_appraisal
        where id = #{id}
          and (is_delete = '0' or is_delete is null)
            limit 1
    </select>

    <insert id="insertWornTechnicalAppraisal" parameterType="WornTechnicalAppraisal" useGeneratedKeys="true" keyProperty="id">
        insert into worn_technical_appraisal
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appraisalNo != null and appraisalNo != ''">appraisal_no,</if>
            <if test="billId != null">bill_id,</if>
            <if test="billNo != null and billNo != ''">bill_no,</if>
            <if test="projectId != null">project_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null and userName != ''">user_name,</if>
            <if test="appraisalDesc != null and appraisalDesc != ''">appraisal_desc,</if>
            <if test="status != null and status != ''">status,</if>
            <if test="remark != null and remark != ''">remark,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="isDelete != null and isDelete != ''">is_delete,</if>
        </trim>

        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="appraisalNo != null and appraisalNo != ''">#{appraisalNo},</if>
            <if test="billId != null">#{billId},</if>
            <if test="billNo != null and billNo != ''">#{billNo},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null and userName != ''">#{userName},</if>
            <if test="appraisalDesc != null and appraisalDesc != ''">#{appraisalDesc},</if>
            <if test="status != null and status != ''">#{status},</if>
            <if test="remark != null and remark != ''">#{remark},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="isDelete != null and isDelete != ''">#{isDelete},</if>
        </trim>
    </insert>

    <update id="updateWornTechnicalAppraisal" parameterType="WornTechnicalAppraisal">
        update worn_technical_appraisal
        <trim prefix="SET" suffixOverrides=",">
            <if test="appraisalNo != null and appraisalNo != ''">appraisal_no = #{appraisalNo},</if>
            <if test="billId != null">bill_id = #{billId},</if>
            <if test="billNo != null">bill_no = #{billNo},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="appraisalDesc != null">appraisal_desc = #{appraisalDesc},</if>
            <if test="status != null">status = #{status},</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>
            <if test="isDelete != null">is_delete = #{isDelete},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="removeWornTechnicalAppraisalById" parameterType="WornTechnicalAppraisal">
        update worn_technical_appraisal
        set is_delete = #{isDelete},
            update_by = #{updateBy},
            update_time = #{updateTime}
        where id = #{id}
    </update>
    <delete id="deleteWornTechnicalAppraisalById" parameterType="Long">
        delete from worn_technical_appraisal where id = #{id}
    </delete>

    <delete id="deleteWornTechnicalAppraisalByIds" parameterType="String">
        delete from worn_technical_appraisal where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectMyTechnicalAppraisalList" parameterType="WornTechnicalAppraisal" resultMap="WornTechnicalAppraisalResult">
        select
        id,
        appraisal_no,
        bill_id,
        bill_no,
        project_id,
        user_id,
        user_name,
        appraisal_desc,
        status,
        remark,
        create_by,
        create_time,
        update_by,
        update_time,
        is_delete
        from worn_technical_appraisal
        <where>
            (is_delete = '0' or is_delete is null)
            and user_id = #{userId}

            <if test="appraisalNo != null and appraisalNo != ''">
                and appraisal_no like concat('%', #{appraisalNo}, '%')
            </if>
            <if test="billNo != null and billNo != ''">
                and bill_no like concat('%', #{billNo}, '%')
            </if>
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
        </where>
        order by create_time desc, id desc
    </select>
</mapper>