<?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="com.jeeplus.pubmodules.wareHouse.mapper.WarehouseUpHiMapper">

    <resultMap id="BaseResultMap" type="com.jeeplus.pubmodules.wareHouse.domain.WarehouseUpHi">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="createById" column="create_by_id" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateById" column="update_by_id" jdbcType="VARCHAR"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
            <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
            <result property="remarks" column="remarks" jdbcType="VARCHAR"/>
            <result property="warehouseId" column="warehouse_id" jdbcType="VARCHAR"/>
            <result property="jsonData" column="json_data" jdbcType="VARCHAR"/>
            <result property="endflag" column="endFlag" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="HI_Column_List">
        hi.id,
        hi.create_by_id,
        hi.create_time,
        hi.update_by_id,
        hi.update_time,
        hi.del_flag,
        hi.remarks,
        hi.warehouse_id,
        hi.json_data,
        hi.endFlag,
        hi.update_user,
        hi.update_trade_name,
        hi.update_trade_type
    </sql>

    <select id="getSourceData" resultType="java.lang.String">
        select
            hi.json_data
        from material_management_warehouse_up_hi hi
        where hi.del_flag = '0' and hi.warehouse_id = #{warehouseId} and hi.endFlag = '0'
    </select>

    <select id="findHiById" resultType="com.jeeplus.pubmodules.wareHouse.domain.WarehouseUpHi">
        select
        <include refid="HI_Column_List"></include>,
        su.name as updateUser
        from material_management_warehouse_up_hi hi
        left join sys_user su on su.id = hi.update_user
        where hi.del_flag = '0' and hi.warehouse_id = #{id} and (hi.endFlag = '1' or hi.endFlag = '2')
        order by hi.create_time desc
    </select>
    <select id="findHiByHiId" resultType="com.jeeplus.pubmodules.wareHouse.domain.WarehouseUpHi">
        select
        <include refid="HI_Column_List"></include>
        from material_management_warehouse_up_hi hi
        where hi.del_flag = '0' and hi.id = #{hiId}
    </select>

    <select id="findLastHiByid" resultType="com.jeeplus.pubmodules.wareHouse.domain.WarehouseUpHi">
        select
        <include refid="HI_Column_List"></include>
        from material_management_warehouse_up_hi hi
        where hi.del_flag = '0' and hi.warehouse_id = #{warehouseId}
        order by hi.create_time desc
        limit 1
    </select>
</mapper>
