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

    <resultMap type="cn.ezhizao.project.business.domain.BizTechnologicalProcessDetailDrawing" id="BizTechnologicalProcessDetailDrawingResult">
        <id column="id" property="id"/>
        <association property="processAlias" column="process_code" javaType="java.lang.String" select="getProcessAlias"/>
    </resultMap>
    <select id="getProcessAlias" resultType="java.lang.String">
        select process_alias from biz_process where deleted = 0 and process_code = #{processCode}
    </select>
    <select id="getList" parameterType="BizTechnologicalProcessDetailDrawing" resultMap="BizTechnologicalProcessDetailDrawingResult">
        SELECT t1.* FROM biz_technological_process_detail_drawing t1
        left join biz_technological_process_detail t2 on t1.technological_process_detail_id = t2.id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0 and t1.abandoned = 0 and t1.status = 2
            <if test="url != null  and url != ''"> AND t1.url = #{url}</if>
            <if test="productId != null">and t1.product_id = #{productId} </if>
            <if test="productVersion != null and productVersion !=''">AND t1.product_version = #{productVersion}</if>
            <if test="processCode != null and processCode != ''">AND t1.process_code = #{processCode}</if>
            <if test="processCodes != null and processCodes.size > 0">
                <foreach collection="processCodes" item="item" open="AND t1.process_code IN (" close=")" separator=",">
                    #{item}
                </foreach>
            </if>
            <if test="drawingName != null  and drawingName != ''"> AND t1.drawing_name = #{drawingName}</if>
            <if test="technologicalProcessId !=null and technologicalProcessId !=''">AND t1.technological_process_detail_id IN (select id from biz_technological_process_detail where deleted = 0  AND technological_process_id = #{technologicalProcessId})</if>
        </trim>
        order by t2.process_step_number, t1.create_time desc
    </select>

    <select id="getDrawingList" parameterType="BizTechnologicalProcessDetailDrawing" resultMap="BizTechnologicalProcessDetailDrawingResult">
        SELECT * FROM biz_technological_process_detail_drawing
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="url != null  and url != ''"> AND url = #{url}</if>
            <if test="status != null ">AND status = #{status}</if>
            <if test="technologicalProcessDetailId != null  and technologicalProcessDetailId != ''"> AND technological_process_detail_id = #{technologicalProcessDetailId}</if>
            <if test="drawingName != null  and drawingName != ''"> AND drawing_name = #{drawingName}</if>
            <if test="drawingNumber != null and drawingNumber != ''">AND technological_process_detail_id IN (select id from biz_technological_process_detail where deleted = 0 and product_id IN (select id from biz_product where deleted = 0 and drawing_number  like concat('%', #{drawingNumber}, '%'))) </if>
            <if test="companyAlias != null and companyAlias != ''">AND technological_process_detail_id IN (select id from biz_technological_process_detail where deleted = 0 and product_id IN (select id from biz_product where deleted = 0 and company_alias  like concat('%', #{companyAlias}, '%'))) </if>
            <if test="specification != null and specification != ''">AND technological_process_detail_id IN (select id from biz_technological_process_detail where deleted = 0 and product_id IN (select id from biz_product where deleted = 0 and specification  like concat('%', #{specification}, '%'))) </if>
            <if test="description != null and description != ''">AND technological_process_detail_id IN (select id from biz_technological_process_detail where deleted = 0 and product_id IN (select id from biz_product where deleted = 0 and description  like concat('%', #{description}, '%'))) </if>
            <if test="technologyVersion !=null and technologyVersion !=''">AND technological_process_detail_id IN(select id from biz_technological_process_detail where deleted = 0 and  technology_version  like concat('%', #{technologyVersion}, '%')) </if>
            <if test="processAlias !=null and processAlias !=''">AND technological_process_detail_id IN(select id from biz_technological_process_detail where deleted = 0 and  process_alias  like concat('%', #{processAlias}, '%')) </if>
            <if test="pattern != null and pattern != ''">AND pattern like concat('%', #{pattern}, '%')</if>
            <if test="technologicalProcessId !=null and technologicalProcessId !=''">AND technological_process_detail_id IN (select id from biz_technological_process_detail where deleted = 0  AND technological_process_id = #{technologicalProcessId})</if>
        </trim>
        order by create_time desc
    </select>

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