InventoryDetailMapper.xml
12.6 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
<?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.huaheng.pc.inventory.inventoryDetail.mapper.InventoryDetailMapper">
<resultMap id="BaseResultMap" type="com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail">
<!--@mbg.generated-->
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="inventoryHeaderId" jdbcType="INTEGER" property="inventoryHeaderId"/>
<result column="warehouseCode" jdbcType="VARCHAR" property="warehouseCode"/>
<result column="companyCode" jdbcType="VARCHAR" property="companyCode"/>
<result column="locationCode" jdbcType="VARCHAR" property="locationCode"/>
<result column="containerCode" jdbcType="VARCHAR" property="containerCode"/>
<result column="materialCode" jdbcType="VARCHAR" property="materialCode"/>
<result column="materialName" jdbcType="VARCHAR" property="materialName"/>
<result column="materialSpec" jdbcType="VARCHAR" property="materialSpec"/>
<result column="materialUnit" jdbcType="VARCHAR" property="materialUnit"/>
<result column="qty" jdbcType="DECIMAL" property="qty"/>
<result column="taskQty" jdbcType="DECIMAL" property="taskQty"/>
<result column="lockedQty" jdbcType="DECIMAL" property="lockedQty"/>
<result column="inventorySts" jdbcType="VARCHAR" property="inventorySts"/>
<result column="supplierCode" jdbcType="VARCHAR" property="supplierCode"/>
<result column="referCode" jdbcType="VARCHAR" property="referCode"/>
<result column="shipmentReferCode" jdbcType="VARCHAR" property="shipmentReferCode"/>
<result column="referDetailId" jdbcType="VARCHAR" property="referDetailId"/>
<result column="batch" jdbcType="VARCHAR" property="batch"/>
<result column="lot" jdbcType="VARCHAR" property="lot"/>
<result column="projectNo" jdbcType="VARCHAR" property="projectNo"/>
<result column="qcCheck" jdbcType="VARCHAR" property="qcCheck"/>
<result column="weight" jdbcType="VARCHAR" property="weight"/>
<result column="manufactureDate" jdbcType="DATE" property="manufactureDate"/>
<result column="expirationDate" jdbcType="DATE" property="expirationDate"/>
<result column="agingDate" jdbcType="DATE" property="agingDate"/>
<result column="attributeId" jdbcType="VARCHAR" property="attributeId"/>
<result column="attribute1" jdbcType="VARCHAR" property="attribute1"/>
<result column="attribute2" jdbcType="VARCHAR" property="attribute2"/>
<result column="attribute3" jdbcType="VARCHAR" property="attribute3"/>
<result column="lockCode" jdbcType="VARCHAR" property="lockCode"/>
<result column="lastCycleCountDate" jdbcType="TIMESTAMP" property="lastCycleCountDate"/>
<result column="created" jdbcType="TIMESTAMP" property="created"/>
<result column="createdBy" jdbcType="VARCHAR" property="createdBy"/>
<result column="lastUpdated" jdbcType="TIMESTAMP" property="lastUpdated"/>
<result column="lastUpdatedBy" jdbcType="VARCHAR" property="lastUpdatedBy"/>
<result column="userDef1" jdbcType="VARCHAR" property="userDef1"/>
<result column="userDef2" jdbcType="VARCHAR" property="userDef2"/>
<result column="userDef3" jdbcType="VARCHAR" property="userDef3"/>
<result column="processStamp" jdbcType="VARCHAR" property="processStamp"/>
<result column="receiptCode" jdbcType="VARCHAR" property="receiptCode"/>
<result column="receiptDetailId" jdbcType="INTEGER" property="receiptDetailId"/>
<result column="locationNoX" jdbcType="INTEGER" property="locationNoX"/>
<result column="locationNoY" jdbcType="INTEGER" property="locationNoY"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
id, inventoryHeaderId, warehouseCode, companyCode, locationCode, containerCode, materialCode,
materialName, materialSpec, materialUnit, qty, taskQty, lockedQty, inventorySts,
supplierCode, referCode, referDetailId, batch, lot, projectNo, qcCheck, weight, manufactureDate,
expirationDate, agingDate, attributeId, attribute1, attribute2, attribute3, lockCode,
lastCycleCountDate, created, createdBy, lastUpdated, lastUpdatedBy, userDef1, userDef2,
userDef3, processStamp, receiptCode, receiptDetailId,locationNoX,locationNoY,shipmentReferCode
</sql>
<select id="selectBysql" parameterType="String"
resultType="com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail">
${value}
</select>
<select id="getSumQty" resultType="java.math.BigDecimal">
SELECT ifnull(sum(qty-taskQty),0) qty from inventory_detail where materialCode=#{materialCode} and
warehouseCode=#{warehouseCode} and inventorySts=#{inventorySts}
<if test="companyCode != null and companyCode != ''">
and companyCode = #{companyCode}
</if>
</select>
<select id="getWarehouseInventoryStatus" resultType="java.lang.String">
SELECT ifnull(
CONVERT(
(SELECT count(1)
FROM inventory_detail
WHERE TIMESTAMPDIFF(MONTH, created, CURDATE()) >= #{a}
and TIMESTAMPDIFF(MONTH, created, CURDATE()) < #{b}
AND warehouseCode = #{warehouseCode}) /
(SELECT count(1) FROM inventory_detail WHERE warehouseCode = #{warehouseCode}),
DECIMAL (15, 2)
),
0
) scale
FROM DUAL
</select>
<select id="getWarehouseInventoryStatuss" resultType="java.lang.String">
SELECT ifnull(
CONVERT(
(SELECT count(1)
FROM inventory_detail
WHERE TIMESTAMPDIFF(MONTH, created, CURDATE()) >= #{a}
AND warehouseCode = #{warehouseCode}) /
(SELECT count(1) FROM inventory_detail WHERE warehouseCode = #{warehouseCode}),
DECIMAL (15, 2)
),
0
) scale
FROM DUAL
</select>
<select id="getCompanyInventoryStatus" resultType="java.lang.String">
SELECT ifnull(
CONVERT(
(SELECT count(1)
FROM inventory_detail
WHERE TIMESTAMPDIFF(MONTH, created, CURDATE()) >= #{a}
and TIMESTAMPDIFF(MONTH, created, CURDATE()) < #{b}
AND companyCode = #{companyCode}) /
(SELECT count(1) FROM inventory_detail WHERE companyCode = #{companyCode}),
DECIMAL (15, 2)
),
0
) scale
FROM DUAL
</select>
<select id="getCompanyInventoryStatuss" resultType="java.lang.String">
SELECT ifnull(
CONVERT(
(SELECT count(1)
FROM inventory_detail
WHERE TIMESTAMPDIFF(MONTH, created, CURDATE()) >= #{a}
AND companyCode = #{companyCode}) /
(SELECT count(1) FROM inventory_detail WHERE companyCode = #{companyCode}),
DECIMAL (15, 2)
),
0
) scale
FROM DUAL
</select>
<select id="getWarehouseInventoryProp" resultType="java.util.LinkedHashMap">
-- SELECT w.name,a.name,ifnull(a.total,0) total from warehouse w
-- left join
-- (SELECT m.name name,sum(i.qty) total,i.warehouseCode warehouseCode from inventory i
-- inner join material m on i.materialCode = m.`code` and i.warehouseId = m.warehouseId
-- GROUP BY m.name,i.warehouseCode) a on w.code=a.warehouseCode ORDER BY total desc
SELECT m.name name, sum(i.qty) total
from inventory_detail i
inner join material m on i.materialCode = m.`code` and i.warehouseCode = m.warehouseCode and
i.warehouseCode = #{warehouseCode}
GROUP BY m.code
ORDER BY total desc limit 10
</select>
<select id="getCompanyInventoryProp" resultType="java.util.LinkedHashMap">
-- SELECT c.name,a.name,ifnull(a.total,0) total from company c
-- left join
-- (SELECT m.name name,sum(i.qty) total,i.companyId companyId from inventory i
-- inner join material m on i.materialCode = m.`code` and i.companyId = m.companyId
-- GROUP BY m.name,i.companyId) a on c.id=a.companyId ORDER BY total desc
SELECT m.name name, sum(i.qty) total
from inventory_detail i
inner join material m on i.materialCode = m.`code` and i.companyCode = m.companyCode and
i.companyCode = #{companyCode}
GROUP BY m.code
ORDER BY total desc limit 10
</select>
<select id="getUsableByMaterialCodeAndOrderCode"
resultType="com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail">
SELECT id,
inventoryHeaderId,
warehouseCode,
companyCode,
zoneCode,
locationCode,
containerCode,
materialCode,
materialName,
materialSpec,
materialUnit,
qty,
taskQty,
inventorySts,
supplierCode,
weight,
created,
orderCode,
shipmentReferCode
FROM inventory_detail
WHERE materialCode = #{materialCode}
AND orderCode = #{orderCode}
AND (shipmentReferCode is NULL or shipmentReferCode = '')
AND qty != taskQty
order by created
</select>
<select id="getHeaderIdsOfMaterial" resultType="java.lang.Integer">
select distinct inventoryHeaderId
from inventory_detail i
where i.materialCode = #{materialCode}
</select>
<select id="getInventoryExpireWarning"
resultType="com.huaheng.pc.inventory.inventoryDetail.domain.InventoryExpireWarning">
SELECT
i.materialCode,
i.materialName,
i.qty,
i.batch,
i.materialSpec,
i.materialUnit,
i.locationCode,
i.containerCode,
i.created,
TO_DAYS(NOW())-TO_DAYS(i.created) as age,
i.locationNoX,
i.locationNoY,
CONCAT(i.locationNoX,', ',i.locationNoY) as xy,
t.maxday,
0
FROM inventory_detail i,
material m, material_warning t
WHERE t.maxday>0 and
i.materialCode = m.code and m.code=t.materialCode
and TO_DAYS(NOW())-TO_DAYS(i.created) >= t.maxday
<if test="materialCode != null and materialCode != ''">
and i.materialCode = #{materialCode}
</if>
</select>
<select id="getInventoryLevelWarning"
resultType="com.huaheng.pc.inventory.inventoryDetail.domain.InventoryLevelWarning">
SELECT w.*, i.qtySum FROM (
SELECT materialcode, sum( qty ) AS qtySum FROM inventory_detail WHERE
inventorysts = 1 AND materialcode IN ( SELECT materialcode FROM material_warning where `upper`> 0 and `lower`>
0)
GROUP BY materialcode
) i Inner JOIN material_warning w ON i.materialcode = w.materialcode
<where>
<if test="materialCode != null and materialCode != ''">
and w.materialcode = #{materialCode}
</if>
</where>
</select>
<select id="getInventoryPowerWarning"
resultType="com.huaheng.pc.inventory.inventoryDetail.domain.InventoryPowerWarning">
SELECT z.*, i.weight
FROM zone z
LEFT JOIN (SELECT zoneCode, sum(weight) AS weight FROM inventory_detail GROUP BY zoneCode) i
ON z.CODE = i.zoneCode
</select>
</mapper>