#
Junjie
2024-01-05 1d87fc5ed3d35dcaf3c5ebba51c98b0c3498ed48
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<?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.common.wms.mapper.LocDetlMapper">
 
    <sql id="batchSeq">
        <choose>
            <when test="batch != null and batch != ''">
                and batch = #{batch}
            </when>
            <otherwise>
                and (batch IS NULL OR batch = '')
            </otherwise>
        </choose>
    </sql>
 
    <sql id="stockOutCondition">
        <if test="map.loc_no!=null and map.loc_no!='' ">
            and a.loc_no like '%' + #{map.loc_no} + '%'
        </if>
        <if test="map.matnr!=null and map.matnr!='' ">
            and a.matnr like '%' + #{map.matnr} + '%'
        </if>
        <if test="map.maktx!=null and map.maktx!='' ">
            and a.maktx like '%' + #{map.maktx} + '%'
        </if>
        <if test="map.batch!=null and map.batch!='' ">
            and a.batch like '%' + #{map.batch} + '%'
        </if>
        <if test="map.anfme!=null and map.anfme!='' ">
            and a.anfme like '%' + #{map.anfme} + '%'
        </if>
        <if test="map.startTime!=null and map.endTime!=null">
            and a.modi_time between #{map.startTime} and #{map.endTime}
        </if>
        <if test="map.memo!=null and map.memo!='' and map.memo!='all'">
            and a.memo like '%' + #{map.memo} + '%'
        </if>
        <if test="map.memo!=null and map.memo!='' and map.memo=='all'">
            and a.memo is not null
            and a.memo !=''
        </if>
    </sql>
 
    <select id="getStockStatis" resultType="com.zy.asrs.common.wms.entity.LocDetl">
        select
        a.matnr
        , sum(a.anfme) as anfme
        from wms_loc_detl a
        where 1=1
        <include refid="stockOutCondition"></include>
        group by a.matnr
    </select>
 
    <select id="sum" resultType="java.lang.Integer">
        SELECT SUM(anfme) FROM wms_loc_detl
    </select>
 
    <select id="queryStock" resultType="com.zy.asrs.common.wms.entity.LocDetl">
        select
        a.*
        from wms_loc_detl a
        left join common_loc_mast b on a.loc_no = b.loc_no
        where 1=1
        <if test="no!=null and no == 1">
            and b.row1 >= 31
            and b.row1 &lt;= 32
        </if>
        <if test="no!=null and no == 2">
            and b.row1 >= 2
            and b.row1 &lt;= 17
        </if>
        <if test="no!=null and no == 3">
            and b.row1 >= 18
            and b.row1 &lt;= 30
        </if>
        and a.matnr = #{matnr}
        and b.bay1 = #{bay}
        and b.loc_sts = 'F'
        order by b.row1
        <if test="orderBy != null and orderBy != '' and orderBy == 'false'">
            desc
        </if>
    </select>
 
    <select id="queryStockPre" resultType="com.zy.asrs.common.domain.dto.QueryStockPreDo">
        select
            *
        from
            (
                select
                    no = 1,
                    orderBy = 'true',
                    b.bay1 as bay,
                    sum(anfme) as count
                from wms_loc_detl a
                    left join common_loc_mast b on a.loc_no = b.loc_no
                where 1=1
                  and b.loc_sts = 'F'
                  and a.matnr = #{matnr}
                  and b.row1 >= 31
                  and b.row1 &lt;= 32
                group by b.bay1
                union
                select
                    no = 2,
                    orderBy = 'true',
                    b.bay1 as bay,
                    sum(anfme) as count
                from wms_loc_detl a
                    left join common_loc_mast b on a.loc_no = b.loc_no
                where 1=1
                  and b.loc_sts = 'F'
                  and a.matnr = #{matnr}
                  and b.row1 >= 2
                  and b.row1 &lt;= 17
                group by b.bay1
                union
                select
                    no = 3,
                    orderBy = 'false',
                    b.bay1 as bay,
                    sum(anfme) as count
                from wms_loc_detl a
                    left join common_loc_mast b on a.loc_no = b.loc_no
                where 1=1
                  and b.loc_sts = 'F'
                  and a.matnr = #{matnr}
                  and b.row1 >= 18
                  and b.row1 &lt;= 30
                group by b.bay1
            ) a
        order by no, count desc
    </select>
 
    <select id="selectItem" resultType="com.zy.asrs.common.wms.entity.LocDetl">
        select top 1 *
        from wms_loc_detl
        where 1=1
        and loc_no = #{locNo}
        and matnr = #{matnr}
        and host_id = #{hostId}
        <include refid="batchSeq"></include>
    </select>
 
    <delete id="deleteItem">
        delete from wms_loc_detl
        where 1=1
        and loc_no = #{locNo}
        and matnr = #{matnr}
        and host_id = #{hostId}
        <include refid="batchSeq"></include>
    </delete>
 
    <update id="updateAnfme">
        update wms_loc_detl
        set anfme = #{anfme}
        , modi_time = getdate()
        where 1=1
        and loc_no = #{locNo}
        and matnr = #{matnr}
        and host_id = #{hostId}
        <include refid="batchSeq"></include>
    </update>
 
    <select id="getStockOutPage" resultType="com.zy.asrs.common.wms.entity.LocDetl">
        select
        a.*
        from wms_loc_detl a
        left join common_loc_mast b on a.loc_no = b.loc_no and a.host_id = b.host_id
        where 1=1
        and b.loc_sts = 'F'
        and b.host_id = #{map.hostId}
        <include refid="stockOutCondition"></include>
    </select>
 
</mapper>