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

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


    <select id="getList" parameterType="BizStorageRetrieval" resultMap="BizStorageRetrievalResult">
        SELECT t1.*,t2.dept_name,(select nick_name from sys_user where t1.storager_id = user_id) as storagerName,(select user_name from sys_user where t1.storager_id = user_id) as storagerUserName,(select nick_name from sys_user where t1.retrievaler_id = user_id) as retrievalerName FROM biz_storage_retrieval t1
        left join sys_dept t2 on t1.dept_id = t2.dept_id
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            t1.deleted = 0
            <if test="productDescription != null  and productDescription != ''"> AND t1.product_description like concat('%',#{productDescription},'%')</if>
            <if test="drawingNumber != null  and drawingNumber != ''"> AND t1.drawing_number like concat('%',#{drawingNumber},'%')</if>
            <if test="lotCode != null  and lotCode != ''"> AND t1.lot_code like concat('%',#{lotCode},'%') </if>
            <if test="technologyVersion != null  and technologyVersion != ''"> AND t1.technology_version = #{technologyVersion}</if>
            <if test="deptId != 0  "> AND t1.dept_id = #{deptId}</if>
            <if test="status != null "> AND t1.status = #{status}</if>
            <if test="retrievalLotCode != null  and retrievalLotCode != ''"> AND t1.retrieval_lot_code like concat('%',#{retrievalLotCode},'%')</if>
            <if test="retrievalerName != null"> AND exists(select 1 from sys_user t3 where t3.user_id = t1.retrieval_id and t3.nick_name like concat('%',#{retrievalerName},'%'))</if>
            <if test="storagerName != null"> AND exists(select 1 from sys_user t4 where t4.user_id = t1.storager_id and t4.nick_name like concat('%',#{storagerName},'%'))</if>
            <if test="storagerUserName != null"> AND exists(select 1 from sys_user t5 where t5.user_id = t1.storager_id and t5.user_name like concat('%',#{storagerUserName},'%'))</if>
            <if test="startStorageTime != null ">AND t1.create_time &gt; #{startStorageTime}</if>
            <if test="endStorageTime != null ">AND t1.create_time &lt; #{endStorageTime}</if>
            <if test="startRetrievalTime != null ">AND t1.retrieval_time &gt; #{startRetrievalTime}</if>
            <if test="endRetrievalTime != null ">AND t1.retrieval_time &lt; #{endRetrievalTime}</if>
            <if test="type != null ">AND t1.type = #{type}</if>
        </trim>
        order by t1.status, t1.create_time
    </select>

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