MaterialWarningMapper.xml
3.93 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
<?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.config.materialWarnning.mapper.MaterialWarningMapper">
<resultMap type="com.huaheng.pc.config.materialWarnning.domain.MaterialWarning" id="materialWarningResult">
<result property="id" column="id" />
<result property="alarmType" column="alarmType" />
<result property="warehouseCode" column="warehouseCode" />
<result property="companyCode" column="companyCode" />
<result property="materialCode" column="materialCode" />
<result property="materialName" column="materialName" />
<result property="materialSpec" column="materialSpec" />
<result property="materialUnit" column="materialUnit" />
<result property="max" column="max" />
<result property="min" column="min" />
<result property="upper" column="upper" />
<result property="lower" column="lower" />
<result property="remark" column="remark" />
<result property="created" column="created" />
<result property="createdBy" column="createdBy" />
<result property="lastUpdated" column="lastUpdated" />
<result property="lastUpdatedBy" column="lastUpdatedBy" />
<result property="userId" column="userId" />
<result property="userName" column="userName" />
<result property="email" column="email" />
</resultMap>
<sql id="selectmaterialWarningVo">
select id, alarmType, warehouseCode, companyCode, materialCode, materialName, materialSpec, materialUnit, max, min, upper, lower, remark, created, createdBy, lastUpdated, lastUpdatedBy, userId, userName, email from material_warning
</sql>
<select id="selectMaterialWarningList" resultType="com.huaheng.api.tv.domain.MaterialWarningList">
<![CDATA[select m.qty,m.materialCode,mw.materialName,"预警" as type
from
(SELECT sum(qty) as qty,materialCode
FROM inventory_detail
GROUP BY materialCode) m
left join material_warning mw
on mw.materialCode=m.materialCode
where m.qty>mw.upper or m.qty>mw.max
union
select m.qty,m.materialCode,mw.materialName,"缺料" as type
from
(SELECT sum(qty) as qty,materialCode
FROM inventory_detail
GROUP BY materialCode) m
left join material_warning mw
on mw.materialCode=m.materialCode
where m.qty<mw.min or m.qty<mw.lower
union
(select inventory.qty,m.code as materialCode,m.name as materialName,"正常" as type
from
(SELECT sum(qty) as qty,materialCode
FROM inventory_detail
GROUP BY materialCode) inventory
left join material m
on m.code=inventory.materialCode
left join material_warning mw
on mw.materialCode=m.code
where
inventory.qty>IFNULL(mw.min,0) or inventory.qty>IFNULL(mw.lower,0)
)
]]>
</select>
<select id="selectWarningQuantity" resultType="java.lang.Integer">
select if(sum(m.qty)is null,0,sum(m.qty))
from
(SELECT sum(qty) as qty,materialCode
FROM inventory_detail
GROUP BY materialCode) m
left join material_warning mw
on mw.materialCode=m.materialCode
where m.qty>mw.upper or m.qty>mw.max
</select>
</mapper>