Crunchy
2025-06-14 b2f31607cbe26d721cd7514b619162b3e355b1aa
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
<?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.wms_admin.server.mapper.OrderInformationMapper">
 
    <resultMap id="SelectOutProductPageMap" type="com.wms_admin.server.entity.OrderInformation">
        <result property="id" column="id"/>
        <result property="orderNumber" column="order_number"/>
        <result property="customerOrderNumber" column="customer_order_number"/>
        <result property="createTime" column="create_time"/>
        <result property="customerName" column="customer_name"/>
        <result property="consignor" column="consignor"/>
        <!--自定义字段-->
        <result property="productName" jdbcType="VARCHAR" column="productName"/>
        <result property="productModel" jdbcType="VARCHAR" column="productModel"/>
        <result property="productUnit" jdbcType="VARCHAR" column="productUnit"/>
        <result property="outQuantity" jdbcType="INTEGER" column="outQuantity"/>
    </resultMap>
    <select id="SelectOutProductPage" resultMap="SelectOutProductPageMap">
        SELECT i.`id`, i.`order_number`, i.`customer_order_number`, i.`create_time`, i.`customer_name`, i.`consignor`,
        o.`unit` productUnit, o.`outbound_quantity` outQuantity, n.`product_name` productName, m.`product_model` productModel
        FROM order_information i, out_product o, product_name n, product_model m
        WHERE o.`order_information_id` = i.`id`
        AND o.`product_name_id` = n.`id`
        AND o.`product_model_id` = m.`id`
        <if test="startTime != null">
            AND i.create_time >= #{startTime}
        </if>
        <if test="endTime != null">
            -- 在mybatis中小于号不能使用,需要使用方法转义:<![CDATA[<=]]>
            AND i.create_time <![CDATA[<=]]> #{endTime}
        </if>
        <if test="customerName != null">
            AND i.`customer_name` = #{customerName}
        </if>
    </select>
 
    <resultMap id="SelectOutProductExcelMap" type="com.wms_admin.excel.ExcelOrderInformation">
        <result property="id" column="id"/>
        <result property="orderNumber" column="order_number"/>
        <result property="customerOrderNumber" column="customer_order_number"/>
        <result property="createTime" column="create_time"/>
        <result property="customerName" column="customer_name"/>
        <result property="consignor" column="consignor"/>
        <!--自定义字段-->
        <result property="productName" jdbcType="VARCHAR" column="productName"/>
        <result property="productModel" jdbcType="VARCHAR" column="productModel"/>
        <result property="productUnit" jdbcType="VARCHAR" column="productUnit"/>
        <result property="outQuantity" jdbcType="INTEGER" column="outQuantity"/>
    </resultMap>
    <select id="SelectOutProductExcel" resultMap="SelectOutProductExcelMap">
        SELECT i.*,
        n.`product_name` productName, m.`product_model` productModel, o.`unit` productUnit, o.`outbound_quantity` outQuantity
        FROM order_information i, out_product o, product_name n, product_model m
        WHERE i.`id` = o.`order_information_id`
        AND o.`product_name_id` = n.`id`
        AND o.`product_model_id` = m.`id`
        <if test="startTime != null">
            AND i.create_time >= #{startTime}
        </if>
        <if test="endTime != null">
            -- 在mybatis中小于号不能使用,需要使用方法转义:<![CDATA[<=]]>
            AND i.create_time <![CDATA[<=]]> #{endTime}
        </if>
        <if test="customerName != null">
            AND i.`customer_name` = #{customerName}
        </if>
    </select>
 
    <resultMap id="SendingAndStoringManagementMap" type="com.wms_admin.excel.ExcelSendAndStoringUtil">
        <result property="id" column="id"/>
        <result property="productCode" column="product_code"/>
        <result property="productName" column="product_name"/>
        <result property="productModel" column="product_model"/>
        <result property="productUnit" column="unit"/>
        <result property="beginningInventory" column="beginningInventory"/>
        <result property="currentPeriod" column="currentPeriod"/>
        <result property="issueInCurrentPeriod" column="issueInCurrentPeriod"/>
        <result property="closingInventory" column="closingInventory"/>
    </resultMap>
    <select id="SendingAndStoringManagement" resultMap="SendingAndStoringManagementMap">
        SELECT *
        from product
<!--        IFNULL(beginningInventory.sumData, 0) 'beginningInventory', IFNULL(currentPeriod.sumData, 0) 'currentPeriod',-->
<!--        IFNULL(issueInCurrentPeriod.sumData, 0) 'issueInCurrentPeriod', IFNULL(closingInventory.sumData, 0) 'closingInventory'-->
<!--        FROM (out_product o, product_name n, product_model m)-->
<!--        <choose>-->
<!--            <when test="startTime != null">-->
<!--                LEFT JOIN (-->
<!--                SELECT p.`product_model_id` model_id, SUM(p.incoming_quantity) sumData-->
<!--                FROM product p-->
<!--                WHERE p.`create_time` <![CDATA[<=]]> #{startTime}-->
<!--                GROUP BY p.`product_model_id`-->
<!--                ) beginningInventory ON beginningInventory.model_id = o.`product_model_id`-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                LEFT JOIN (-->
<!--                SELECT p.`product_model_id` model_id, SUM(p.incoming_quantity) sumData-->
<!--                FROM product p-->
<!--                WHERE p.`create_time` <![CDATA[<=]]> (SELECT DATE_SUB(DATE_SUB(DATE_FORMAT(NOW(),'%y-%m-%d'),INTERVAL EXTRACT(DAY FROM NOW())-1 DAY),INTERVAL 0 MONTH) first_day)-->
<!--                GROUP BY p.`product_model_id`-->
<!--                ) beginningInventory ON beginningInventory.model_id = o.`product_model_id`-->
<!--            </otherwise>-->
<!--        </choose>-->
<!--        <choose>-->
<!--            <when test="startTime != null">-->
<!--                LEFT JOIN (-->
<!--                SELECT model_id, SUM(currentPeriod) sumData-->
<!--                FROM (-->
<!--                    SELECT p.`product_model_id` model_id, SUM(p.`incoming_quantity`) currentPeriod-->
<!--                    FROM product p-->
<!--                    WHERE p.`create_time` >= #{startTime}-->
<!--                    AND p.`create_time` <![CDATA[<=]]> #{endTime}-->
<!--                    GROUP BY p.`product_model_id`-->
<!--                    UNION-->
<!--                    SELECT o.`product_model_id` model_id, SUM(o.`outbound_quantity`) currentPeriod-->
<!--                    FROM out_product o-->
<!--                    WHERE o.`create_time` >= #{startTime}-->
<!--                    AND o.`create_time` <![CDATA[<=]]> #{endTime}-->
<!--                    GROUP BY o.`product_model_id`-->
<!--                ) AS temp-->
<!--                GROUP BY model_id-->
<!--                ) currentPeriod ON currentPeriod.model_id = o.`product_model_id`-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                LEFT JOIN (-->
<!--                SELECT model_id, SUM(currentPeriod) sumData-->
<!--                FROM (-->
<!--                SELECT p.`product_model_id` model_id, SUM(p.`incoming_quantity`) currentPeriod-->
<!--                FROM product p-->
<!--                WHERE DATE_FORMAT(p.`create_time`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')-->
<!--                GROUP BY p.`product_model_id`-->
<!--                UNION-->
<!--                SELECT o.`product_model_id` model_id, SUM(o.`outbound_quantity`) currentPeriod-->
<!--                FROM out_product o-->
<!--                WHERE DATE_FORMAT(o.`add_Time`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')-->
<!--                GROUP BY o.`product_model_id`-->
<!--                ) AS temp-->
<!--                GROUP BY model_id-->
<!--                ) currentPeriod ON currentPeriod.model_id = o.`product_model_id`-->
<!--            </otherwise>-->
<!--        </choose>-->
<!--        <choose>-->
<!--            <when test="startTime != null">-->
<!--                LEFT JOIN (-->
<!--                SELECT o.`product_model_id` model_id, SUM(o.`outbound_quantity`) sumData-->
<!--                FROM out_product o-->
<!--                WHERE o.`create_time` >= #{startTime}-->
<!--                AND o.`create_time` <![CDATA[<=]]> #{endTime}-->
<!--                GROUP BY o.`product_model_id`-->
<!--                ) issueInCurrentPeriod ON issueInCurrentPeriod.model_id = o.`product_model_id`-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                LEFT JOIN (-->
<!--                SELECT o.`product_model_id` model_id, SUM(o.`outbound_quantity`) sumData-->
<!--                FROM out_product o-->
<!--                WHERE DATE_FORMAT(o.`create_time`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m')-->
<!--                GROUP BY o.`product_model_id`-->
<!--                ) issueInCurrentPeriod ON issueInCurrentPeriod.model_id = o.`product_model_id`-->
<!--            </otherwise>-->
<!--        </choose>-->
<!--        <choose>-->
<!--            <when test="endTime != null">-->
<!--                LEFT JOIN (-->
<!--                SELECT p.`product_model_id` model_id, SUM(p.`incoming_quantity`) sumData-->
<!--                FROM product p-->
<!--                WHERE p.`create_time` >= #{endTime}-->
<!--                ) closingInventory ON closingInventory.model_id = o.`product_model_id`-->
<!--            </when>-->
<!--            <otherwise>-->
<!--                LEFT JOIN (-->
<!--                SELECT p.`product_model_id` model_id, SUM(p.`incoming_quantity`) sumData-->
<!--                FROM product p-->
<!--                WHERE p.`create_time` >= (-->
<!--                SELECT DATE_SUB(DATE_SUB(DATE_FORMAT(NOW(),'%y-%m-%d'),INTERVAL EXTRACT(DAY FROM NOW())-1 DAY),INTERVAL 0 MONTH))-->
<!--                AND p.`create_time` <![CDATA[<=]]> NOW()-->
<!--                ) closingInventory ON closingInventory.model_id = o.`product_model_id`-->
<!--            </otherwise>-->
<!--        </choose>-->
<!--        WHERE o.`product_name_id` = n.`id`-->
<!--        AND o.`product_model_id` = m.`id`-->
<!--        GROUP BY o.`product_model_id`-->
    </select>
</mapper>