3 天以前 1ba0dbfde5634c8bf2ec20891d6b226b996f6b59
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
<?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.mes.dal.mysql.home.MesBagCodeHomeStatisticsMapper">
 
    <!-- ========== 基础数据 ========== -->
 
    <!-- 统计品种总数(mdm_item) -->
    <select id="selectMdmItemCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mdm_item
        WHERE deleted = 0
    </select>
 
    <!-- 统计 MES 品种数(mes_md_item) -->
    <select id="selectMesItemCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_md_item
        WHERE deleted = 0
    </select>
 
    <!-- 统计品种分类数(mes_md_item_type) -->
    <select id="selectItemTypeCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_md_item_type
        WHERE deleted = 0
    </select>
 
    <!-- 统计计量单位数(mdm_unit_measure) -->
    <select id="selectUnitMeasureCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mdm_unit_measure
        WHERE deleted = 0
    </select>
 
    <!-- ========== 一袋一码 ========== -->
 
    <!-- 统计产线数(mes_pro_line) -->
    <select id="selectLineCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_pro_line
        WHERE deleted = 0
    </select>
 
    <!-- 统计批次总数(mes_pro_batch) -->
    <select id="selectBatchCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_pro_batch
        WHERE deleted = 0
    </select>
 
    <!-- 统计袋码总数(mes_pro_bag_code) -->
    <select id="selectBagCodeCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_pro_bag_code
        WHERE deleted = 0
    </select>
 
    <!-- 统计托盘码总数(mes_pro_pallet) -->
    <select id="selectPalletCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_pro_pallet
        WHERE deleted = 0
    </select>
 
    <!-- ========== 出库流通 / 仓储 / 质量 ========== -->
 
    <!-- 统计发货通知单数(mes_wm_sales_notice) -->
    <select id="selectSalesNoticeCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_wm_sales_notice
        WHERE deleted = 0
    </select>
 
    <!-- 统计销售出库单数(mes_wm_product_sales) -->
    <select id="selectProductSalesCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_wm_product_sales
        WHERE deleted = 0
    </select>
 
    <!-- 统计销售退货单数(mes_wm_return_sales) -->
    <select id="selectReturnSalesCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_wm_return_sales
        WHERE deleted = 0
    </select>
 
    <!-- 统计未处理库存预警数(mes_wm_stock_warning.status=10) -->
    <select id="selectStockWarningPendingCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_wm_stock_warning
        WHERE deleted = 0
          AND status = 10
    </select>
 
    <!-- 统计待评审不合格品单数(mes_qc_ncr.status=0) -->
    <select id="selectNcrPendingCount" resultType="java.lang.Long">
        SELECT COUNT(*)
        FROM mes_qc_ncr
        WHERE deleted = 0
          AND status = 0
    </select>
 
    <!-- ========== 状态分布 ========== -->
 
    <!-- 按状态统计批次数量 -->
    <select id="selectBatchCountGroupByStatus" resultType="java.util.Map">
        SELECT status, COUNT(*) AS count
        FROM mes_pro_batch
        WHERE deleted = 0
        GROUP BY status
    </select>
 
    <!-- 按状态统计袋码数量 -->
    <select id="selectBagCodeCountGroupByStatus" resultType="java.util.Map">
        SELECT status, COUNT(*) AS count
        FROM mes_pro_bag_code
        WHERE deleted = 0
        GROUP BY status
    </select>
 
    <!-- 按天聚合袋码生成量 -->
    <select id="selectDailyBagCodeTrend" resultType="java.util.Map">
        SELECT DATE_FORMAT(create_time, '%Y-%m-%d') AS date,
               COUNT(*)                              AS count
        FROM mes_pro_bag_code
        WHERE deleted = 0
          AND create_time >= #{beginTime}
          <if test="endTime != null">
              AND create_time &lt; #{endTime}
          </if>
        GROUP BY DATE_FORMAT(create_time, '%Y-%m-%d')
        ORDER BY date
    </select>
 
</mapper>