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

    <resultMap type="cn.ezhizao.project.business.domain.BizTechnologicalProcessDetail" id="BizTechnologicalProcessDetailResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="BizTechnologicalProcessDetail" resultMap="BizTechnologicalProcessDetailResult">
        SELECT * FROM biz_technological_process_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="technologicalProcessId !=null and technologicalProcessId !=''"> AND technological_process_id = #{technologicalProcessId}</if>
            <if test="technologyVersion != null  and technologyVersion != ''"> AND technology_version = #{technologyVersion}</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="productCode != null  and productCode != ''"> AND product_code = #{productCode}</if>
            <if test="processStepNumber != null  and processStepNumber != ''"> AND process_step_number = #{processStepNumber}</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>
        </trim>
    </select>

    <select id="getProcessDetailsByTechnicalProcessId" parameterType="Long" resultMap="BizTechnologicalProcessDetailResult">
        SELECT * FROM biz_technological_process_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0 and tenant_id != 9
            <if test="technologicalProcessId!= null"> AND technological_process_id = #{technologicalProcessId}</if>
        </trim>
        order by process_step_number
    </select>

    <select id="getProcessList" parameterType="Long" resultMap="BizTechnologicalProcessDetailResult">
        SELECT * FROM biz_technological_process_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0 and tenant_id != 9
            <if test="tenantId != null and tenantId != 0" > AND tenant_id = #{tenantId}</if>
            <if test="technologicalProcessId!= null"> AND technological_process_id = #{technologicalProcessId}</if>
            <if test="processStepNumber != null and processStepNumber!=''">AND process_step_number > #{processStepNumber}</if>
            <if test="keyword != null  and keyword != ''">AND (process_key LIKE concat('%', #{keyword}, '%')or
                process_alias LIKE concat('%', #{keyword}, '%'))
            </if>
        </trim>
        order by process_step_number
    </select>


    <select id="getById" parameterType="Long" resultMap="BizTechnologicalProcessDetailResult">
        SELECT * FROM biz_technological_process_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="id!= null"> AND id = #{id}</if>
        </trim>
    </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>
