<?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.mapper.BizProductionPlanDetailSubDetailEquipmentMapper">

    <resultMap type="cn.ezhizao.project.business.domain.BizProductionPlanDetailSubDetailEquipment" id="BizProductionPlanDetailSubDetailEquipmentResult">
        <id column="id" property="id"/>
        <result column="equipment_detail_id" property="equipmentDetailId"/>
        <association property="equipmentCode" javaType="java.lang.String"  column="equipment_detail_id" select="getEquipmentCode"/>
        <association property="equipmentName" javaType="java.lang.String"  column="equipment_detail_id" select="getEquipmentName"/>
    </resultMap>
    <select id="getEquipmentName" resultType="java.lang.String">
        select equipment_name from biz_equipment where deleted = 0 and id =(select equipment_id from biz_equipment_detail where deleted = 0 and id = #{equipment_detail_id})
    </select>
    <select id="getEquipmentCode" resultType="java.lang.String">
        select equipment_code from biz_equipment_detail where id = #{equipment_detail_id}
    </select>
    <select id="getList" resultMap="BizProductionPlanDetailSubDetailEquipmentResult">
        SELECT
            t1.*,
            GROUP_CONCAT(t2.nick_name SEPARATOR ',') AS user_nick_names
        FROM biz_production_plan_detail_sub_detail_equipment t1
        LEFT JOIN biz_production_plan_detail_sub_detail_equipment_user t2 ON t1.id = t2.production_plan_detail_sub_detail_equipment_id and t2.deleted = 0
        WHERE
            t1.deleted = 0

          <if test="productionPlanDetailSubDetailId != null and productionPlanDetailSubDetailId != ''">
            AND t1.production_plan_detail_sub_detail_id = #{productionPlanDetailSubDetailId} </if>
            <if test="technologicalProcessId != null and technologicalProcessId !=''">
            AND t1.technological_process_id = #{technologicalProcessId}
            </if>
        <if test="deptId != null"> AND t1.dept_id = #{deptId}</if>

        <if test="processId!= null and processId!=''">
            AND t1.process_id = #{processId}
            </if>
        <if test="tenantId != null  and tenantId != 0"> AND t1.tenant_id = #{tenantId}</if>
        GROUP BY
            t1.id
    </select>

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