<?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.yanzhu.manage.mapper.AttendanceCfgMapper">
    
    <resultMap type="AttendanceCfg" id="AttendanceCfgResult">
        <result property="id"    column="id"    />
        <result property="comId"    column="com_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="vendorsCode"    column="vendors_code"    />
        <result property="vendorsParameter"    column="vendors_parameter"    />
        <result property="enabled"    column="enabled"    />
        <result property="state"    column="state"    />
        <result property="remark"    column="remark"    />
        <result property="isDel"    column="is_del"    />
        <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="compName" column="comp_name"/>
        <result property="projectName" column="project_name"/>
        <result property="vendorsName" column="vendors_name"/>
    </resultMap>

    <sql id="selectAttendanceCfgVo">
        SELECT ac.id, ac.com_id, ac.project_id, ac.vendors_code, ac.vendors_parameter, ac.enabled, ac.state, ac.remark, ac.is_del, ac.create_by, ac.create_time, ac.update_by
             , ac.update_time,dp.`dept_name` comp_name,pp.`project_name`,dic.`dict_label` vendors_name
        FROM attendance_cfg ac
                 LEFT JOIN sys_dept dp ON ac.`com_id`=dp.`dept_id`
                 LEFT JOIN pro_project_info pp ON ac.`project_id`=pp.`id`
                 LEFT JOIN sys_dict_data dic ON ac.`vendors_code`=dic.`dict_value` AND dic.`dict_type`='attendance_vendors'
    </sql>

    <select id="selectAttendanceCfgList" parameterType="AttendanceCfg" resultMap="AttendanceCfgResult">
        <include refid="selectAttendanceCfgVo"/>
        <where>  
            <if test="comId != null "> and ac.com_id = #{comId}</if>
            <if test="projectId != null "> and ac.project_id = #{projectId}</if>
            <if test="vendorsCode != null  and vendorsCode != ''"> and ac.vendors_code = #{vendorsCode}</if>
            <if test="vendorsParameter != null  and vendorsParameter != ''"> and ac.vendors_parameter = #{vendorsParameter}</if>
            <if test="enabled != null "> and ac.enabled = #{enabled}</if>
            <if test="state != null "> and ac.state = #{state}</if>
            <if test="isDel != null "> and ac.is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectAttendanceCfgById" parameterType="Long" resultMap="AttendanceCfgResult">
        <include refid="selectAttendanceCfgVo"/>
        where ac.id = #{id}
    </select>
        
    <insert id="insertAttendanceCfg" parameterType="AttendanceCfg" useGeneratedKeys="true" keyProperty="id">
        insert into attendance_cfg
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="comId != null">com_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="vendorsCode != null">vendors_code,</if>
            <if test="vendorsParameter != null">vendors_parameter,</if>
            <if test="enabled != null">enabled,</if>
            <if test="state != null">state,</if>
            <if test="remark != null">remark,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="comId != null">#{comId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="vendorsCode != null">#{vendorsCode},</if>
            <if test="vendorsParameter != null">#{vendorsParameter},</if>
            <if test="enabled != null">#{enabled},</if>
            <if test="state != null">#{state},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateAttendanceCfg" parameterType="AttendanceCfg">
        update attendance_cfg
        <trim prefix="SET" suffixOverrides=",">
            <if test="comId != null">com_id = #{comId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="vendorsCode != null">vendors_code = #{vendorsCode},</if>
            <if test="vendorsParameter != null">vendors_parameter = #{vendorsParameter},</if>
            <if test="enabled != null">enabled = #{enabled},</if>
            <if test="state != null">state = #{state},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isDel != null">is_del = #{isDel},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAttendanceCfgById" parameterType="Long">
        delete from attendance_cfg where id = #{id}
    </delete>

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