<?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.iocoder.yudao.module.stockTransfer.mapper.DlRepairStiMapper">

    <resultMap id="BaseResultMap" type="cn.iocoder.yudao.module.stockTransfer.entity.DlRepairSti">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="stId" column="st_id" jdbcType="VARCHAR"/>
        <result property="goodsId" column="goods_id" jdbcType="VARCHAR"/>
        <result property="goodsCount" column="goods_count" jdbcType="INTEGER"/>
        <result property="goodsPrice" column="goods_price" jdbcType="DECIMAL"/>
        <result property="remark" column="remark" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_SQL">
        select sti.id as id,
               st_id,
               goods_id,
               goods_count,
               goods_price,
               sti.remark as remark
        from dl_repair_sti sti
                 left join dl_repair_st st on sti.st_id = st.id
                 left join dl_repair_wares drw on sti.goods_id = drw.id
        where sti.deleted = '0'
          and st.st_status != '04'
    </sql>

    <select id="getStiPage" resultMap="BaseResultMap">
        <include refid="Base_SQL"/>
        <if test="map.searchTimeArray != null and map.searchTimeArray.length > 0">
            and (st.st_time between #{map.searchTimeArray[0]} and #{map.searchTimeArray[1]})
        </if>
        <if test="map.query != null and map.query != ''">
            and (
            st.st_no like concat('%', #{map.query}, '%')
            or
            drw.name like concat('%', #{map.query}, '%')
            or
            drw.code like concat('%', #{map.query}, '%')
            or
            drw.model like concat('%', #{map.query}, '%')
            )
        </if>
        <if test="map.inCorpId != null and map.inCorpId != ''">
            and st.in_corp_id = #{map.inCorpId}
        </if>
        <if test="map.outCorpId != null and map.outCorpId != ''">
            and st.out_corp_id = #{map.outCorpId}
        </if>
    </select>
</mapper>
