<?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.BizProductionResourceGroupDetailMapper">

    <resultMap type="cn.ezhizao.project.business.resourceGroup.domain.BizProductionResourceGroupDetail" id="BizProductionResourceGroupDetailResult">
        <id column="id" property="id"/>
        <association property="resourceCode" column="production_resource_group_id" javaType="java.lang.String" select="getResourceCode"/>
        <association property="nickName" column="production_resource_group_id" javaType="java.lang.String" select="getNiceName"/>
    </resultMap>

    <select id="getResourceCode" resultType="java.lang.String">
        select code from biz_production_resource_group where deleted = 0 and id = #{productionResourceGroupId}
    </select>
    <select id="getList" parameterType="BizProductionResourceGroupDetail" resultMap="BizProductionResourceGroupDetailResult">
        SELECT t1.*  FROM biz_production_resource_group_detail t1
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0
            <if test="productionResourceGroupId != null  and productionResourceGroupId != ''"> AND t1.production_resource_group_id = #{productionResourceGroupId}</if>
            <if test="commonCode != null  and commonCode != ''"> AND (t1.common_code like concat('%', #{commonCode}, '%') or t1.common_name like concat('%', #{commonCode}, '%'))</if>
            <if test="commonType != null  and commonType != ''"> AND t1.common_type = #{commonType}</if>
            <if test="selStatus !=null and selStatus !=''">AND id NOT IN (SELECT id FROM biz_production_resource_group_detail WHERE deleted = 0 AND common_type = 'person' AND protem_daywork_id != "") </if>
        </trim>
        order by production_resource_group_id desc
    </select>

    <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 = #{productionResourceGroupId} and common_type = 'person'
    </select>
    <select id="getEquipmentList" parameterType="BizProductionResourceGroupDetail" resultMap="BizProductionResourceGroupDetailResult">
        SELECT * FROM biz_production_resource_group_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0 and common_type = 'equipmentDetail'
            <if test="productionResourceGroupId != null  and productionResourceGroupId != ''"> AND production_resource_group_id = #{productionResourceGroupId}</if>
            <if test="commonCode != null  and commonCode != ''"> AND common_code like concat('%', #{commonCode}, '%')</if>
            <if test="commonType != null  and commonType != ''"> AND common_type = #{commonType}</if>

        </trim>
        order by production_resource_group_id desc
    </select>

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