<?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.jh.project.mapper.SurProjectAttendanceCfgMapper">
    
    <resultMap type="SurProjectAttendanceCfg" id="SurProjectAttendanceCfgResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="subDeptId"    column="sub_dept_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="projectName" column="projectName"/>
        <result property="deptName" column="dept_name"/>
        <result property="unitName" column="unitName"/>
        <result property="vendorName" column="vendorName"/>
    </resultMap>

    <sql id="selectSurProjectAttendanceCfgVo">
        select *
        from (
                SELECT a.*,sp.projectName,pu.unitName,sdd1.dict_label vendorName FROM sur_project_attendance_cfg  a
                LEFT JOIN sur_project sp ON a.project_id = sp.id
                LEFT JOIN sur_project_unit_info pu ON a.sub_dept_id=pu.unitId AND a.project_id=pu.projectId
                LEFT JOIN sys_dict_data sdd1 ON sdd1.dict_type = 'attendance_vendors' AND sdd1.dict_value = a.vendors_code
        )  sur_project_attendance_cfg
    </sql>

    <select id="selectSurProjectAttendanceCfgList" parameterType="SurProjectAttendanceCfg" resultMap="SurProjectAttendanceCfgResult">
        <include refid="selectSurProjectAttendanceCfgVo"/>
        <where>  
            <if test="projectId != null "> and project_id = #{projectId}</if>
            <if test="subDeptId != null "> and sub_dept_id = #{subDeptId}</if>
            <if test="vendorsCode != null  and vendorsCode != ''"> and vendors_code = #{vendorsCode}</if>
            <if test="vendorsParameter != null  and vendorsParameter != ''"> and vendors_parameter = #{vendorsParameter}</if>
            <if test="enabled != null "> and enabled = #{enabled}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
        </where>
    </select>


    <select id="selectSurProjectAttendanceCfgListForAllInfo" parameterType="SurProjectAttendanceCfg" resultMap="SurProjectAttendanceCfgResult">
        SELECT a.*,b.projectName,c.dept_name
        FROM sur_project_attendance_cfg a,sur_project b,sys_dept c WHERE c.dept_id=a.sub_dept_id AND a.project_id=b.id
        <if test="id != null "> and a.id = #{id}</if>
    </select>
    
    <select id="selectSurProjectAttendanceCfgById" parameterType="Long" resultMap="SurProjectAttendanceCfgResult">
        <include refid="selectSurProjectAttendanceCfgVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSurProjectAttendanceCfg" parameterType="SurProjectAttendanceCfg" useGeneratedKeys="true" keyProperty="id">
        insert into sur_project_attendance_cfg
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="subDeptId != null">sub_dept_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="projectId != null">#{projectId},</if>
            <if test="subDeptId != null">#{subDeptId},</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="updateSurProjectAttendanceCfg" parameterType="SurProjectAttendanceCfg">
        update sur_project_attendance_cfg
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="subDeptId != null">sub_dept_id = #{subDeptId},</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="deleteSurProjectAttendanceCfgById" parameterType="Long">
        delete from sur_project_attendance_cfg where id = #{id}
    </delete>

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