<?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.lz.modules.sys.dao.app.ResultRecordMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.sys.entity.app.ResultRecord">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="month_time" property="monthTime"/>
        <result column="status" property="status"/>
        <result column="last_score" property="lastScore"/>
        <result column="all_score" property="allScore"/>
        <result column="remark" property="remark"/>
        <result column="staff_id" property="staffId"/>
        <result column="type" property="type"/>
        <result column="init_role_id" property="initRoleId"/>
        <result column="current_flow_staff_id" property="currentFlowStaffId"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, month_time AS monthTime, status AS status, last_score AS lastScore, all_score AS allScore, remark AS remark, staff_id AS staffId, type AS type, init_role_id AS initRoleId, current_flow_staff_id AS currentFlowStaffId
    </sql>

    <select id="selectResultRecordById" resultType="ResultRecord" >
        select * from lz_result_record  where id=#{id} and is_delete = 0 limit 1
    </select>


    <insert id="insertResultRecord" parameterType="ResultRecord" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_result_record(
        <if test="monthTime != null">month_time, </if>
        <if test="status != null">status, </if>
        <if test="lastScore != null">last_score, </if>
        <if test="allScore != null">all_score, </if>
        <if test="remark != null">remark, </if>
        <if test="staffId != null">staff_id, </if>
        <if test="type != null">type, </if>
        <if test="initRoleId != null">init_role_id, </if>
        <if test="currentFlowStaffId != null">current_flow_staff_id, </if>
        is_delete,
        gmt_create,
        gmt_modified
        )values(
        <if test="monthTime != null">#{ monthTime}, </if>
        <if test="status != null">#{ status}, </if>
        <if test="lastScore != null">#{ lastScore}, </if>
        <if test="allScore != null">#{ allScore}, </if>
        <if test="remark != null">#{ remark}, </if>
        <if test="staffId != null">#{ staffId}, </if>
        <if test="type != null">#{ type}, </if>
        <if test="initRoleId != null">#{ initRoleId}, </if>
        <if test="currentFlowStaffId != null">#{ currentFlowStaffId}, </if>
        0,
        now(),
        now()
        )
    </insert>


    <update id="updateResultRecordById" parameterType="ResultRecord" >
        update
        lz_result_record
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="monthTime != null">month_time = #{monthTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="lastScore != null">last_score = #{lastScore},</if>
            <if test="allScore != null">all_score = #{allScore},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="initRoleId != null">init_role_id = #{initRoleId},</if>
            <if test="currentFlowStaffId != null">current_flow_staff_id = #{currentFlowStaffId}</if>
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverResultRecordById" parameterType="ResultRecord" >
        update
            lz_result_record
        set
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            month_time = #{monthTime},
            status = #{status},
            last_score = #{lastScore},
            all_score = #{allScore},
            remark = #{remark},
            staff_id = #{staffId},
            type = #{type},
            init_role_id = #{initRoleId},
            current_flow_staff_id = #{currentFlowStaffId}
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteResultRecordById" parameterType="java.lang.Long">
        update lz_result_record set is_delete = 1 where id=#{id} limit 1  
    </update>


    <select id="selectByCondition" resultType="com.lz.modules.sys.entity.app.ResultRecord">
        select * from lz_result_record  where  is_delete = 0
        <if test="req.monthBeginDate != null and req.monthBeginDate != '' ">
            AND DATE_FORMAT(month_time, '%Y-%m-%d %H:%i:%S')  <![CDATA[ >= ]]> DATE_FORMAT(#{req.monthBeginDate}, '%Y-%m-%d %H:%i:%S')
        </if>
        <if test="req.monthEndDate != null and req.monthEndDate != '' ">
            AND DATE_FORMAT(month_time, '%Y-%m-%d %H:%i:%S')  <![CDATA[ >= ]]> DATE_FORMAT(#{req.monthEndDate}, '%Y-%m-%d %H:%i:%S')
        </if>
        <if test="req.status != null">
            and status = #{req.status}
        </if>
        <if test="req.remark != null and req.remark !='' ">
            AND remark LIKE CONCAT('%',#{req.remark},'%')
        </if>
        <if test="req.departmentStaffIds != null and req.departmentStaffIds.size() > 0 ">
            and staff_id in
            <foreach collection="req.departmentStaffIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        <if test="req.staffIds != null and req.staffIds.size() > 0 ">
            and staff_id in
            <foreach collection="req.staffIds" item="item" index="index" separator="," open="(" close=")">
                #{item}
            </foreach>
        </if>
        order by id desc
    </select>



    <select id="selectByConditionTest" resultType="com.lz.modules.sys.entity.app.ResultRecord">
        select * from lz_result_record  where  is_delete = 0
        <if test="monthBeginDate != null and monthBeginDate != '' ">
            AND DATE_FORMAT(month_time, '%Y-%m-%d %H:%i:%S')  <![CDATA[ >= ]]> DATE_FORMAT(#{monthBeginDate}, '%Y-%m-%d %H:%i:%S')
        </if>

        <if test="monthEndDate != null and monthEndDate != '' ">
            AND DATE_FORMAT(month_time, '%Y-%m-%d %H:%i:%S')  <![CDATA[ >= ]]> DATE_FORMAT(#{monthEndDate}, '%Y-%m-%d %H:%i:%S')
        </if>
        order by id desc
    </select>


</mapper>

