<?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.ProProjectInfoSubdeptsMapper">
    
    <resultMap type="ProProjectInfoSubdepts" id="ProProjectInfoSubdeptsResult">
        <result property="id"    column="id"    />
        <result property="comId"    column="com_id"    />
        <result property="comName"    column="com_name"    />
        <result property="projectId"    column="project_id"    />
        <result property="projectName"    column="project_name"    />
        <result property="subDeptType"    column="sub_dept_type"    />
        <result property="subDeptName"    column="sub_dept_name"    />
        <result property="subDeptCode"    column="sub_dept_code"    />
        <result property="subDeptLeaderId"    column="sub_dept_leader_id"    />
        <result property="subDeptLeaderName"    column="sub_dept_leader_name"    />
        <result property="subDeptLeaderCode"    column="sub_dept_leader_code"    />
        <result property="subDeptLeaderPhone"    column="sub_dept_leader_phone"    />
        <result property="subDeptLeaderPowerPath"    column="sub_dept_leader_power_path"    />
        <result property="businessLicensePath"    column="business_license_path"    />
        <result property="subDeptInfos"    column="sub_dept_infos"    />
        <result property="contractInfos"    column="contract_infos"    />
        <result property="useDates"    column="use_dates"    />
        <result property="useStatus"    column="use_status"    />
        <result property="approveStatus"    column="approve_status"    />
        <result property="qrCode"    column="qr_code"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectProProjectInfoSubdeptsVo">
        select ps.id, ps.com_id, sd.dept_name as com_name, ps.project_id, pi.project_name, ps.sub_dept_type, ps.sub_dept_name, ps.sub_dept_code, ps.sub_dept_leader_id, ps.sub_dept_leader_name, ps.sub_dept_leader_code, ps.sub_dept_leader_phone, ps.sub_dept_leader_power_path, ps.business_license_path, ps.sub_dept_infos, ps.contract_infos, ps.use_dates, ps.use_status, ps.approve_status, ps.qr_code, ps.is_del, ps.create_by, ps.create_time, ps.update_by, ps.update_time, ps.remark from pro_project_info_subdepts ps
        left join pro_project_info pi on pi.id = ps.project_id
        left join sys_dept sd on sd.dept_id = pi.com_id
    </sql>

    <select id="selectProProjectInfoSubdeptsList" parameterType="ProProjectInfoSubdepts" resultMap="ProProjectInfoSubdeptsResult">
        <include refid="selectProProjectInfoSubdeptsVo"/>
        <where>
            ps.is_del = 0
            <if test="comId != null "> and ps.com_id = #{comId}</if>
            <if test="projectId != null "> and ps.project_id = #{projectId}</if>
            <if test="activeComId != null "> and ps.com_id = #{activeComId}</if>
            <if test="activeProjectId != null "> and ps.project_id = #{activeProjectId}</if>
            <if test="projectName != null  and projectName != ''"> and pi.project_name like concat('%', #{projectName}, '%')</if>
            <if test="subDeptType != null  and subDeptType != ''"> and ps.sub_dept_type = #{subDeptType}</if>
            <if test="subDeptName != null  and subDeptName != ''"> and ps.sub_dept_name like concat('%', #{subDeptName}, '%')</if>
            <if test="subDeptCode != null  and subDeptCode != ''"> and ps.sub_dept_code = #{subDeptCode}</if>
            <if test="useStatus != null  and useStatus != ''"> and ps.use_status = #{useStatus}</if>
            <if test="approveStatus != null "> and ps.approve_status = #{approveStatus}</if>
        </where>
        order by ps.id desc
    </select>

    <select id="selectProProjectInfoSubdeptsById" parameterType="Long" resultMap="ProProjectInfoSubdeptsResult">
        <include refid="selectProProjectInfoSubdeptsVo"/>
        where ps.id = #{id}
    </select>
        
    <insert id="insertProProjectInfoSubdepts" parameterType="ProProjectInfoSubdepts" useGeneratedKeys="true" keyProperty="id">
        insert into pro_project_info_subdepts
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="comId != null">com_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="subDeptType != null">sub_dept_type,</if>
            <if test="subDeptName != null">sub_dept_name,</if>
            <if test="subDeptCode != null">sub_dept_code,</if>
            <if test="subDeptLeaderId != null">sub_dept_leader_id,</if>
            <if test="subDeptLeaderName != null">sub_dept_leader_name,</if>
            <if test="subDeptLeaderCode != null">sub_dept_leader_code,</if>
            <if test="subDeptLeaderPhone != null">sub_dept_leader_phone,</if>
            <if test="subDeptLeaderPowerPath != null">sub_dept_leader_power_path,</if>
            <if test="businessLicensePath != null">business_license_path,</if>
            <if test="subDeptInfos != null">sub_dept_infos,</if>
            <if test="contractInfos != null">contract_infos,</if>
            <if test="useDates != null">use_dates,</if>
            <if test="useStatus != null">use_status,</if>
            <if test="approveStatus != null">approve_status,</if>
            <if test="qrCode != null">qr_code,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="comId != null">#{comId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="subDeptType != null">#{subDeptType},</if>
            <if test="subDeptName != null">#{subDeptName},</if>
            <if test="subDeptCode != null">#{subDeptCode},</if>
            <if test="subDeptLeaderId != null">#{subDeptLeaderId},</if>
            <if test="subDeptLeaderName != null">#{subDeptLeaderName},</if>
            <if test="subDeptLeaderCode != null">#{subDeptLeaderCode},</if>
            <if test="subDeptLeaderPhone != null">#{subDeptLeaderPhone},</if>
            <if test="subDeptLeaderPowerPath != null">#{subDeptLeaderPowerPath},</if>
            <if test="businessLicensePath != null">#{businessLicensePath},</if>
            <if test="subDeptInfos != null">#{subDeptInfos},</if>
            <if test="contractInfos != null">#{contractInfos},</if>
            <if test="useDates != null">#{useDates},</if>
            <if test="useStatus != null">#{useStatus},</if>
            <if test="approveStatus != null">#{approveStatus},</if>
            <if test="qrCode != null">#{qrCode},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateProProjectInfoSubdepts" parameterType="ProProjectInfoSubdepts">
        update pro_project_info_subdepts
        <trim prefix="SET" suffixOverrides=",">
            <if test="comId != null">com_id = #{comId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="subDeptType != null">sub_dept_type = #{subDeptType},</if>
            <if test="subDeptName != null">sub_dept_name = #{subDeptName},</if>
            <if test="subDeptCode != null">sub_dept_code = #{subDeptCode},</if>
            <if test="subDeptLeaderId != null">sub_dept_leader_id = #{subDeptLeaderId},</if>
            <if test="subDeptLeaderName != null">sub_dept_leader_name = #{subDeptLeaderName},</if>
            <if test="subDeptLeaderCode != null">sub_dept_leader_code = #{subDeptLeaderCode},</if>
            <if test="subDeptLeaderPhone != null">sub_dept_leader_phone = #{subDeptLeaderPhone},</if>
            <if test="subDeptLeaderPowerPath != null">sub_dept_leader_power_path = #{subDeptLeaderPowerPath},</if>
            <if test="businessLicensePath != null">business_license_path = #{businessLicensePath},</if>
            <if test="subDeptInfos != null">sub_dept_infos = #{subDeptInfos},</if>
            <if test="contractInfos != null">contract_infos = #{contractInfos},</if>
            <if test="useDates != null">use_dates = #{useDates},</if>
            <if test="useStatus != null">use_status = #{useStatus},</if>
            <if test="approveStatus != null">approve_status = #{approveStatus},</if>
            <if test="qrCode != null">qr_code = #{qrCode},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteProProjectInfoSubdeptsById" parameterType="Long">
        update pro_project_info_subdepts set is_del=1 where id = #{id}
    </update>

    <update id="deleteProProjectInfoSubdeptsByIds" parameterType="String">
        update pro_project_info_subdepts set is_del=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>