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

    <resultMap type="cn.ezhizao.project.business.technologicalProcessDetail.domain.BizTechnologicalProcessDetail" id="BizTechnologicalProcessDetailResult">
        <id column="id" property="id"/>
        <result column="process_code" property="processCode"/>
        <result column="product_id" property="productId"/>
        <result column="technology_version" property="technologyVersion"/>
        <association property="drawingNum" column="{productId=product_id,productVersion=technology_version,processCode=process_code}" select="getDrawingNum"/>
    </resultMap>
    <resultMap type="cn.ezhizao.project.business.technologicalProcessDetail.domain.BizTechnologicalProcessDetail" id="DetailResult">
        <id column="id" property="id"/>
        </resultMap>
    <select id="getDrawingNum" resultType="integer">
        select count(1) from biz_technological_process_detail_drawing where deleted = 0  and abandoned = 0 and status &lt;3  and product_id = #{productId} and product_version = #{productVersion} and process_code = #{processCode}
    </select>

    <select id="getList" parameterType="BizTechnologicalProcessDetail" resultMap="BizTechnologicalProcessDetailResult">
        SELECT id,tenant_id,technological_process_id,technology_version,product_id,product_code,process_step_number,process_id,process_key,process_code,process_alias,product_shaft_category,product_shaft_category_name,product_description,create_time,creator_id,update_time,updater_id,deleted,version
        FROM biz_technological_process_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="productCode != null  and productCode != ''"> AND product_code = #{productCode}</if>
            <if test="processStepNumber != null  and processStepNumber != ''"> AND process_step_number = #{processStepNumber}</if>
#             <if test="deptId !=null and deptId !=''">AND process_id in (select process_id from biz_dept_process where deleted = 0 and dept_id = #{deptId})</if>

            <if test="technologicalProcessId != null  and technologicalProcessId != ''"> AND technological_process_id = #{technologicalProcessId}</if>
            <if test="processCode != null  and processCode != ''"> AND process_code = #{processCode}</if>
            <if test="processAlias != null  and processAlias != ''"> AND process_alias = #{processAlias}</if>
            <if test="productShaftCategory != null  and productShaftCategory != ''"> AND product_shaft_category = #{productShaftCategory}</if>
            <if test="productShaftCategoryName != null  and productShaftCategoryName != ''"> AND product_shaft_category_name like concat('%', #{productShaftCategoryName}, '%')</if>
            <if test="productDescription != null  and productDescription != ''"> AND product_description = #{productDescription}</if>
<!--            <if test="drawingFile != null  and drawingFile != ''"> AND drawing_file = #{drawingFile}</if>-->
            <if test="technologicalProcessId != null  and technologicalProcessId != ''"> AND technological_process_id = #{technologicalProcessId}</if>
            <if test="tenantId != null  and tenantId != 0"> AND tenant_id = #{tenantId}</if>
        </trim>
        order by  process_step_number
    </select>

    <select id="getTechnologicalProcessDetails"  parameterType="BizTechnologicalProcessDetail" resultMap="DetailResult">
        SELECT process_alias as Label,id as `Value`, process_code as `Code`,process_id as processId FROM biz_technological_process_detail where deleted = 0 and product_id = #{productId} and technology_version = #{technologyVersion} and technological_process_id in (select id from biz_technological_process where deleted = 0 and  is_history = 0)
    </select>
    <delete id="physicalDelete">
        DELETE FROM biz_technological_process_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
