<?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="cn.ezhizao.project.business.resourceGroup.mapper.BizProductionResourceGroupMapper">

    <resultMap type="cn.ezhizao.project.business.resourceGroup.domain.BizProductionResourceGroup" id="BizProductionResourceGroupResult">
        <id column="id" property="id"/>
        <association property="nickName" column="id" javaType="java.lang.String" select="getNiceName"/>
        <collection property="groupDetailList" column="id" ofType="cn.ezhizao.project.business.resourceGroup.domain.BizProductionResourceGroupDetail" select="getGroupDetailList"/>
        <collection property="groupEquipmentList" column="id" ofType="cn.ezhizao.project.business.resourceGroup.domain.BizProductionResourceGroupDetail" select="getGroupEquipmentList"/>
    </resultMap>
    <resultMap type="cn.ezhizao.project.business.resourceGroup.domain.BizProductionResourceGroupDetail" id="BizProductionResourceGroupDetailResult">
        <id column="id" property="id"/>
    </resultMap>
    <select id="getNiceName" resultType="java.lang.String">
        select  GROUP_CONCAT( common_name SEPARATOR ', ' ) as nickName from biz_production_resource_group_detail where deleted = 0 and production_resource_group_id = #{id} and common_type = 'person' and protem_daywork_id = 0
    </select>

    <select id="getGroupEquipmentList" resultMap="BizProductionResourceGroupDetailResult">
        select * from biz_production_resource_group_detail where  deleted = 0 and production_resource_group_id = #{id} and common_type = 'equipmentDetail'
    </select>
    <select id="getGroupDetailList" resultMap="BizProductionResourceGroupDetailResult">
        select * from biz_production_resource_group_detail where  deleted = 0 and production_resource_group_id = #{id}
    </select>
    <select id="getList" parameterType="BizProductionResourceGroup" resultMap="BizProductionResourceGroupResult">
        SELECT * FROM biz_production_resource_group
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="id != null  and id != ''"> AND id = #{id}</if>
            <if test="code != null  and code != ''"> AND code like concat('%',#{code},'%')</if>
            <if test="deptId != null  and deptId != ''"> AND dept_id = #{deptId}</if>
        </trim>
    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_production_resource_group
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
