<?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.ProProjectInfoSubdeptsGroupMapper">
    
    <resultMap type="ProProjectInfoSubdeptsGroup" id="ProProjectInfoSubdeptsGroupResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="projectName"    column="project_name"    />
        <result property="subDeptId"    column="sub_dept_id"    />
        <result property="subDeptType"    column="sub_dept_type"    />
        <result property="subDeptName"    column="sub_dept_name"    />
        <result property="subDeptCode"    column="sub_dept_code"    />
        <result property="groupName"    column="group_name"    />
        <result property="groupCode"    column="group_code"    />
        <result property="craftType"    column="craft_type"    />
        <result property="craftPost"    column="craft_post"    />
        <result property="groupLeaderName"    column="group_leader_name"    />
        <result property="groupLeaderCode"    column="group_leader_code"    />
        <result property="groupLeaderPhone"    column="group_leader_phone"    />
        <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="selectProProjectInfoSubdeptsGroupVo">
        select psg.id, psg.project_id, pi.project_name, psg.sub_dept_id, psg.sub_dept_type, psg.sub_dept_name, psg.sub_dept_code, psg.group_name, psg.group_code, psg.craft_type, psg.craft_post, psg.group_leader_name, psg.group_leader_code, psg.group_leader_phone, psg.use_status, psg.approve_status, psg.qr_code, psg.is_del, psg.create_by, psg.create_time, psg.update_by, psg.update_time, psg.remark from pro_project_info_subdepts_group psg
        left join pro_project_info pi on pi.id = psg.project_id
        left join sys_dept sd on sd.dept_id = pi.dept_id
    </sql>

    <select id="selectProProjectInfoSubdeptsGroupList" parameterType="ProProjectInfoSubdeptsGroup" resultMap="ProProjectInfoSubdeptsGroupResult">
        <include refid="selectProProjectInfoSubdeptsGroupVo"/>
        <where>
            <if test="activeDeptId != null "> and sd.dept_id = #{activeDeptId}</if>
            <if test="projectId != null "> and psg.project_id = #{projectId}</if>
            <if test="projectName != null  and projectName != ''"> and pi.project_name like concat('%', #{projectName}, '%')</if>
            <if test="subDeptId != null "> and psg.sub_dept_id = #{subDeptId}</if>
            <if test="subDeptType != null  and subDeptType != ''"> and psg.sub_dept_type = #{subDeptType}</if>
            <if test="subDeptName != null  and subDeptName != ''"> and psg.sub_dept_name like concat('%', #{subDeptName}, '%')</if>
            <if test="subDeptCode != null  and subDeptCode != ''"> and psg.sub_dept_code = #{subDeptCode}</if>
            <if test="groupName != null  and groupName != ''"> and psg.group_name like concat('%', #{groupName}, '%')</if>
            <if test="groupCode != null  and groupCode != ''"> and psg.group_code = #{groupCode}</if>
            <if test="craftType != null  and craftType != ''"> and psg.craft_type = #{craftType}</if>
            <if test="craftPost != null  and craftPost != ''"> and psg.craft_post = #{craftPost}</if>
            <if test="groupLeaderName != null  and groupLeaderName != ''"> and psg.group_leader_name like concat('%', #{groupLeaderName}, '%')</if>
            <if test="groupLeaderCode != null  and groupLeaderCode != ''"> and psg.group_leader_code = #{groupLeaderCode}</if>
            <if test="groupLeaderPhone != null  and groupLeaderPhone != ''"> and psg.group_leader_phone = #{groupLeaderPhone}</if>
            <if test="useStatus != null  and useStatus != ''"> and psg.use_status = #{useStatus}</if>
            <if test="approveStatus != null "> and psg.approve_status = #{approveStatus}</if>
            <if test="isDel != null "> and psg.is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectProProjectInfoSubdeptsGroupById" parameterType="Long" resultMap="ProProjectInfoSubdeptsGroupResult">
        <include refid="selectProProjectInfoSubdeptsGroupVo"/>
        where psg.id = #{id}
    </select>
        
    <insert id="insertProProjectInfoSubdeptsGroup" parameterType="ProProjectInfoSubdeptsGroup" useGeneratedKeys="true" keyProperty="id">
        insert into pro_project_info_subdepts_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="projectId != null">project_id,</if>
            <if test="subDeptId != null">sub_dept_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="groupName != null">group_name,</if>
            <if test="groupCode != null">group_code,</if>
            <if test="craftType != null">craft_type,</if>
            <if test="craftPost != null">craft_post,</if>
            <if test="groupLeaderName != null">group_leader_name,</if>
            <if test="groupLeaderCode != null">group_leader_code,</if>
            <if test="groupLeaderPhone != null">group_leader_phone,</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="projectId != null">#{projectId},</if>
            <if test="subDeptId != null">#{subDeptId},</if>
            <if test="subDeptType != null">#{subDeptType},</if>
            <if test="subDeptName != null">#{subDeptName},</if>
            <if test="subDeptCode != null">#{subDeptCode},</if>
            <if test="groupName != null">#{groupName},</if>
            <if test="groupCode != null">#{groupCode},</if>
            <if test="craftType != null">#{craftType},</if>
            <if test="craftPost != null">#{craftPost},</if>
            <if test="groupLeaderName != null">#{groupLeaderName},</if>
            <if test="groupLeaderCode != null">#{groupLeaderCode},</if>
            <if test="groupLeaderPhone != null">#{groupLeaderPhone},</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="updateProProjectInfoSubdeptsGroup" parameterType="ProProjectInfoSubdeptsGroup">
        update pro_project_info_subdepts_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="subDeptId != null">sub_dept_id = #{subDeptId},</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="groupName != null">group_name = #{groupName},</if>
            <if test="groupCode != null">group_code = #{groupCode},</if>
            <if test="craftType != null">craft_type = #{craftType},</if>
            <if test="craftPost != null">craft_post = #{craftPost},</if>
            <if test="groupLeaderName != null">group_leader_name = #{groupLeaderName},</if>
            <if test="groupLeaderCode != null">group_leader_code = #{groupLeaderCode},</if>
            <if test="groupLeaderPhone != null">group_leader_phone = #{groupLeaderPhone},</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>

    <delete id="deleteProProjectInfoSubdeptsGroupById" parameterType="Long">
        delete from pro_project_info_subdepts_group where id = #{id}
    </delete>

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