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

    <resultMap type="cn.ezhizao.project.business.technologicalProcessDetailDrawingRecords.domain.BizTechnologicalProcessDetailDrawingRecords" id="BizTechnologicalProcessDetailDrawingRecordsResult">
        <id column="id" property="id"/>
        <result column="product_id" property="productId"/>
        <result column="process_code" property="processCode"/>
        <association property="userName" column="user_id" select="getUserName"/>
        <association property="productDescription" column="product_id" select="getProductDescription"/>
        <association property="processAlias" column="process_code" select="getProcessAlias"/>
    </resultMap>
    <resultMap id="BizTechnologicalProcessDetailResult" type="cn.ezhizao.project.business.technologicalProcessDetail.domain.BizTechnologicalProcessDetail">
        <id column="id" property="id"/>
    </resultMap>

    <select id="getProductDescription" resultType="String">
        select description from biz_product where id = #{productId} and deleted = 0
    </select>
    <select id="getProcessAlias" resultType="String">
        select process_alias from biz_process where process_code = #{processCode} and deleted = 0
    </select>


    <select id="getList" parameterType="BizTechnologicalProcessDetailDrawingRecords" resultMap="BizTechnologicalProcessDetailDrawingRecordsResult">
        SELECT * FROM biz_technological_process_detail_drawing_records
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="type != null  and type != ''"> AND type = #{type}</if>
            <if test="productId != null">and product_id = #{productId} </if>
            <if test="productVersion != null and productVersion !=''">AND product_version = #{productVersion}</if>
            <if test="drawingName != null  and drawingName != ''"> AND drawing_name like concat('%', #{drawingName}, '%')</if>
        </trim>
        order by create_time desc
    </select>

    <select id="getUserName" resultType="String">
        select nick_name as userName from sys_user where user_id = #{user_id}
    </select>
    <delete id="physicalDelete">
        DELETE FROM biz_technological_process_detail_drawing_records
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
