<?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.zy.asrs.mapper.MatMapper"> 
 | 
  
 | 
    <!-- 通用查询映射结果 --> 
 | 
    <resultMap id="BaseResultMap" type="com.zy.asrs.entity.Mat"> 
 | 
        <id column="id" property="id" /> 
 | 
        <result column="uuid" property="uuid" /> 
 | 
        <result column="tag_id" property="tagId" /> 
 | 
        <result column="matnr" property="matnr" /> 
 | 
        <result column="maktx" property="maktx" /> 
 | 
        <result column="name" property="name" /> 
 | 
        <result column="specs" property="specs" /> 
 | 
        <result column="model" property="model" /> 
 | 
        <result column="color" property="color" /> 
 | 
        <result column="brand" property="brand" /> 
 | 
        <result column="unit" property="unit" /> 
 | 
        <result column="price" property="price" /> 
 | 
        <result column="sku" property="sku" /> 
 | 
        <result column="units" property="units" /> 
 | 
        <result column="barcode" property="barcode" /> 
 | 
        <result column="origin" property="origin" /> 
 | 
        <result column="manu" property="manu" /> 
 | 
        <result column="manu_date" property="manuDate" /> 
 | 
        <result column="item_num" property="itemNum" /> 
 | 
        <result column="safe_qty" property="safeQty" /> 
 | 
        <result column="weight" property="weight" /> 
 | 
        <result column="length" property="length" /> 
 | 
        <result column="volume" property="volume" /> 
 | 
        <result column="three_code" property="threeCode" /> 
 | 
        <result column="supp" property="supp" /> 
 | 
        <result column="supp_code" property="suppCode" /> 
 | 
        <result column="be_batch" property="beBatch" /> 
 | 
        <result column="dead_time" property="deadTime" /> 
 | 
        <result column="dead_warn" property="deadWarn" /> 
 | 
        <result column="source" property="source" /> 
 | 
        <result column="inspect" property="inspect" /> 
 | 
        <result column="danger" property="danger" /> 
 | 
        <result column="status" property="status" /> 
 | 
        <result column="create_by" property="createBy" /> 
 | 
        <result column="create_time" property="createTime" /> 
 | 
        <result column="update_by" property="updateBy" /> 
 | 
        <result column="update_time" property="updateTime" /> 
 | 
        <result column="memo" property="memo" /> 
 | 
  
 | 
        <result column="stock" property="stock" /> 
 | 
    </resultMap> 
 | 
  
 | 
    <select id="listByPage" resultMap="BaseResultMap"> 
 | 
        SELECT 
 | 
        isnull(mld.amount,0) as stock, 
 | 
        mm.* 
 | 
        FROM man_mat mm 
 | 
        LEFT JOIN man_tag mt ON mm.tag_id = mt.id 
 | 
        LEFT JOIN ( 
 | 
        SELECT 
 | 
        matnr, 
 | 
        SUM(anfme) AS amount 
 | 
        FROM man_loc_detl 
 | 
        GROUP BY matnr 
 | 
        ) AS mld ON mld.matnr = mm.matnr 
 | 
        WHERE 1=1 
 | 
        <!-- ✅ 屏蔽 tag_id = 6 --> 
 | 
        AND mt.id != 6 
 | 
  
 | 
        <!-- ✅ 判断是否在路径中 or 本身 id 匹配 --> 
 | 
        AND (CHARINDEX(',' + #{tagId} + ',', ',' + mt.path + ',') > 0 OR mt.id = #{tagId}) 
 | 
  
 | 
        <if test="matnr != null and matnr != ''"> 
 | 
            AND mm.matnr LIKE CONCAT('%', #{matnr}, '%') 
 | 
        </if> 
 | 
        <if test="memo != null and memo != ''"> 
 | 
            AND mm.memo LIKE CONCAT('%', #{memo}, '%') 
 | 
        </if> 
 | 
        ORDER BY mm.create_time DESC 
 | 
    </select> 
 | 
  
 | 
  
 | 
    <select id="listByPage2" resultMap="BaseResultMap"> 
 | 
        SELECT 
 | 
        isnull(mld.amount,0) as stock, 
 | 
        mm.* 
 | 
        FROM man_mat mm 
 | 
        LEFT JOIN man_tag mt ON mm.tag_id = mt.id 
 | 
        LEFT JOIN ( 
 | 
        select 
 | 
        matnr, 
 | 
        sum(anfme) as amount 
 | 
        from man_loc_detl 
 | 
        group by matnr 
 | 
        ) as mld on mld.matnr = mm.matnr 
 | 
        WHERE 1=1 
 | 
        and (mm.memo is null or mm.memo != '打包上线') 
 | 
        AND (CHARINDEX(','+#{tagId}+',', ','+mt.path+',') > 0 OR mt.id = #{tagId}) 
 | 
        <if test="matnr != null and matnr != ''"> 
 | 
            and mm.matnr like concat('%',#{matnr},'%') 
 | 
        </if> 
 | 
        <if test="maktx != null and maktx != ''"> 
 | 
            and mm.maktx like concat('%',#{maktx},'%') 
 | 
        </if> 
 | 
        <if test="specs != null and specs != ''"> 
 | 
            and mm.specs like concat('%',#{specs},'%') 
 | 
        </if> 
 | 
        ORDER BY mm.create_time DESC 
 | 
    </select> 
 | 
  
 | 
    <select id="selectByMatnr" resultMap="BaseResultMap"> 
 | 
        select top 1 * from man_mat where 1=1 and matnr = #{matnr} 
 | 
    </select> 
 | 
  
 | 
    <select id="selectByMatnrLink" resultMap="BaseResultMap"> 
 | 
        select * from man_mat 
 | 
        where 1=1 
 | 
        <if test="matnr != null and matnr != ''"> 
 | 
            and mm.matnr like concat('%',#{matnr},'%') 
 | 
        </if> 
 | 
    </select> 
 | 
  
 | 
    <select id="getMatTurnPage" resultMap="BaseResultMap"> 
 | 
        select * from 
 | 
        ( 
 | 
        select top 16 
 | 
        ROW_NUMBER() over (order by a.matnr) as matNo, 
 | 
        a.* 
 | 
        from man_mat a 
 | 
        where 1=1 
 | 
        <if test="matnr!=null and matnr!='' "> 
 | 
            and a.matnr like concat('%',#{matnr},'%') 
 | 
        </if> 
 | 
        ) t where t.matNo between ((#{pageNumber}-1)*#{pageSize}+1) and (#{pageNumber}*#{pageSize}) 
 | 
    </select> 
 | 
  
 | 
  
 | 
    <select id="getBoxMemoMap" resultType="map"> 
 | 
        SELECT tag_id, memo 
 | 
        FROM man_mat 
 | 
        WHERE tag_id IN 
 | 
        <foreach item="id" collection="tagIds" open="(" close=")" separator=","> 
 | 
            #{id} 
 | 
        </foreach> 
 | 
    </select> 
 | 
  
 | 
  
 | 
    <select id="getStockOutPageCount" parameterType="java.util.Map" resultType="java.lang.Integer"> 
 | 
        select 
 | 
        count(1) 
 | 
        from man_mat a 
 | 
        where 1=1 
 | 
        <if test="matnr!=null and matnr!='' "> 
 | 
            and a.matnr = #{matnr} 
 | 
        </if> 
 | 
    </select> 
 | 
</mapper> 
 |