huminmin
5 天以前 de4ca61aa27d7f284a03aebd801bcc3d6a75bc6a
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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?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.ruoyi.production.mapper.ProductionOrderMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.production.pojo.ProductionOrder">
        <id column="id" property="id" />
        <result column="production_plan_ids" property="productionPlanIds" />
        <result column="product_model_id" property="productModelId" />
        <result column="nps_no" property="npsNo" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="technology_routing_id" property="technologyRoutingId" />
        <result column="quantity" property="quantity" />
        <result column="complete_quantity" property="completeQuantity" />
        <result column="start_time" property="startTime" />
        <result column="end_time" property="endTime" />
        <result column="create_user" property="createUser" />
        <result column="dept_id" property="deptId" />
        <result column="plan_complete_time" property="planCompleteTime" />
        <result column="status" property="status" />
    </resultMap>
 
    <resultMap id="ProductionOrderVoResultMap" type="com.ruoyi.production.bean.vo.ProductionOrderVo" extends="BaseResultMap">
        <result column="salesContractNo" property="salesContractNo" />
        <result column="customerName" property="customerName" />
        <result column="productName" property="productName" />
        <result column="model" property="model" />
        <result column="processRouteCode" property="processRouteCode" />
        <result column="returned" property="returned" />
    </resultMap>
 
    <sql id="ProductionOrderVoColumns">
        po.id,
        po.production_plan_ids,
        po.product_model_id,
        po.nps_no,
        po.create_time,
        po.update_time,
        po.technology_routing_id,
        po.quantity,
        po.complete_quantity,
        po.start_time,
        po.end_time,
        po.create_user,
        po.dept_id,
        po.plan_complete_time,
        po.status,
        po_sales.salesContractNo,
        po_sales.customerName,
        p.product_name as productName,
        pm.model as model,
        po.is_end_order as endOrder,
        tr.process_route_code as processRouteCode,
        ROUND(po.complete_quantity / po.quantity * 100, 2) AS completionStatus,
        tb.bom_no as bomNo,
        pop_return.returned as returned
    </sql>
 
    <sql id="ProductionOrderVoFrom">
        from production_order po
                 left join (
            select po2.id as orderId,
                   group_concat(distinct sl2.sales_contract_no order by sl2.sales_contract_no separator ',') as salesContractNo,
                   group_concat(distinct sl2.customer_name order by sl2.customer_name separator ',') as customerName,
                   group_concat(distinct sl2.project_name order by sl2.project_name separator ',') as projectName,
                   min(sl2.delivery_date) as deliveryDate
            from production_order po2
                     left join production_plan pp2
                               on find_in_set(pp2.id, replace(replace(replace(po2.production_plan_ids, '[', ''), ']', ''), ' ', '')) > 0
                     left join sales_ledger sl2 on sl2.id = pp2.sales_ledger_id
            group by po2.id
        ) po_sales on po_sales.orderId = po.id
                 left join product_model pm on po.product_model_id = pm.id
                 left join product p on pm.product_id = p.id
                 left join technology_routing tr on po.technology_routing_id = tr.id
                 left join technology_bom tb on tb.id = tr.bom_id
                 left join (
            select production_order_id as productionOrderId,
                   if(max(case when ifnull(is_returned, 0) = 1 then 1 else 0 end) = 1, true, false) as returned
            from production_order_pick
            group by production_order_id
        ) pop_return on pop_return.productionOrderId = po.id
    </sql>
 
    <sql id="ProductionOrderWhere">
        <where>
            <if test="c != null">
                <if test="c.id != null">
                    and po.id = #{c.id}
                </if>
                <if test="c.productName != null and c.productName != ''">
                    and p.product_name like concat('%', #{c.productName}, '%')
                </if>
                <if test="c.model != null and c.model != ''">
                    and pm.model like concat('%', #{c.model}, '%')
                </if>
                <if test="c.productModelId != null">
                    and po.product_model_id = #{c.productModelId}
                </if>
                <if test="c.technologyRoutingId != null">
                    and po.technology_routing_id = #{c.technologyRoutingId}
                </if>
                <if test="c.status != null">
                    and po.status = #{c.status}
                </if>
                <if test="c.createUser != null">
                    and po.create_user = #{c.createUser}
                </if>
                <if test="c.deptId != null">
                    and po.dept_id = #{c.deptId}
                </if>
                <if test="c.npsNo != null and c.npsNo != ''">
                    and po.nps_no like concat('%', #{c.npsNo}, '%')
                </if>
                <if test="c.productionPlanIds != null and c.productionPlanIds != ''">
                    and po.production_plan_ids like concat('%', #{c.productionPlanIds}, '%')
                </if>
                <if test="c.planCompleteTime != null">
                    and po.plan_complete_time = #{c.planCompleteTime}
                </if>
                <if test="c.startTime != null">
                    and po.start_time &gt;= #{c.startTime}
                </if>
                <if test="c.endTime != null">
                    and po.end_time &lt;= #{c.endTime}
                </if>
            </if>
        </where>
    </sql>
 
    <select id="pageProductionOrder" resultMap="ProductionOrderVoResultMap">
        select
        <include refid="ProductionOrderVoColumns" />
        <include refid="ProductionOrderVoFrom" />
        <include refid="ProductionOrderWhere" />
        order by po.id desc
    </select>
 
    <select id="listProductionOrder" resultMap="ProductionOrderVoResultMap">
        select
        <include refid="ProductionOrderVoColumns" />
        <include refid="ProductionOrderVoFrom" />
        <include refid="ProductionOrderWhere" />
        order by po.id desc
    </select>
 
    <select id="getProductionOrderInfo" resultMap="ProductionOrderVoResultMap">
        select
        <include refid="ProductionOrderVoColumns" />
        <include refid="ProductionOrderVoFrom" />
        where po.id = #{id}
        limit 1
    </select>
 
    <select id="selectProgressOrders" resultType="com.ruoyi.home.dto.ProductionProgressOrderDto">
        select po.nps_no,
               po_sales.salesContractNo,
               po_sales.projectName,
               po_sales.customerName,
               p.product_name as productCategory,
               pm.model as specificationModel,
               tr.process_route_code as processRouteCode,
               po.quantity,
               ifnull(po.complete_quantity, 0) as completeQuantity,
               round(ifnull(po.complete_quantity, 0) / nullif(po.quantity, 0) * 100, 2) as completionStatus,
               tb.bom_no,
               datediff(po_sales.deliveryDate, curdate()) as deliveryDaysDiff,
               po_sales.deliveryDate as deliveryDate,
               false as isFh
        from production_order po
                 left join (
            select po2.id as orderId,
                   group_concat(distinct sl2.sales_contract_no order by sl2.sales_contract_no separator ',') as salesContractNo,
                   group_concat(distinct sl2.customer_name order by sl2.customer_name separator ',') as customerName,
                   group_concat(distinct sl2.project_name order by sl2.project_name separator ',') as projectName,
                   min(sl2.delivery_date) as deliveryDate
            from production_order po2
                     left join production_plan pp2
                               on find_in_set(pp2.id, replace(replace(replace(po2.production_plan_ids, '[', ''), ']', ''), ' ', '')) > 0
                     left join sales_ledger sl2 on sl2.id = pp2.sales_ledger_id
            group by po2.id
        ) po_sales on po_sales.orderId = po.id
                 left join product_model pm on po.product_model_id = pm.id
                 left join product p on pm.product_id = p.id
                 left join technology_routing tr on po.technology_routing_id = tr.id
                 left join technology_bom tb on tr.bom_id = tb.id
        where po.create_time between #{startTime} and #{endTime}
        order by po.create_time desc
    </select>
 
    <select id="countCreated" resultType="java.lang.Integer">
        select count(1)
        from production_order
        where create_time &gt;= #{startDate}
          and create_time &lt;= #{endDate}
    </select>
 
    <select id="countCompleted" resultType="java.lang.Integer">
        select count(1)
        from production_order
        where end_time &gt;= #{startDate}
          and end_time &lt;= #{endDate}
          and ifnull(complete_quantity, 0) &gt;= quantity
    </select>
 
    <select id="countPending" resultType="java.lang.Integer">
        select count(1)
        from production_order
        where create_time &gt;= #{startDate}
          and create_time &lt;= #{endDate}
          and ifnull(complete_quantity, 0) &lt; quantity
    </select>
 
    <select id="selectHomeOrderProgressPage" resultType="java.util.Map">
        select po.nps_no as orderNo,
               p.product_name as productName,
               ifnull(po.quantity, 0) as plannedQuantity,
               ifnull(po.complete_quantity, 0) as completedQuantity,
               round(ifnull(po.complete_quantity, 0) / nullif(po.quantity, 0) * 100, 2) as completionRate,
               po.plan_complete_time as dueDate,
               po.status as status
        from production_order po
                 left join product_model pm on po.product_model_id = pm.id
                 left join product p on pm.product_id = p.id
        <where>
            <if test="status != null">
                and po.status = #{status}
            </if>
            <if test="startTime != null and endTime != null">
                and po.create_time &gt;= #{startTime}
                and po.create_time &lt; #{endTime}
            </if>
        </where>
        order by po.id desc
        limit #{offset}, #{size}
    </select>
 
    <select id="countHomeOrderProgress" resultType="java.lang.Long">
        select count(1)
        from production_order po
        <where>
            <if test="status != null">
                and po.status = #{status}
            </if>
            <if test="startTime != null and endTime != null">
                and po.create_time &gt;= #{startTime}
                and po.create_time &lt; #{endTime}
            </if>
        </where>
    </select>
 
    <select id="countHomeOrderProgressByStatus" resultType="java.util.Map">
        select po.status as status, count(1) as cnt
        from production_order po
        where po.status in (1, 2, 3, 4)
        <if test="startTime != null and endTime != null">
            and po.create_time &gt;= #{startTime}
            and po.create_time &lt; #{endTime}
        </if>
        group by po.status
    </select>
 
    <select id="selectHomeTodayProductionPlan" resultType="java.util.Map">
        select po.nps_no as orderNo,
               p.product_name as productName,
               ifnull(po.quantity, 0) as plannedQuantity,
               po.plan_complete_time as dueDate,
               po.status as status
        from production_order po
                 left join product_model pm on po.product_model_id = pm.id
                 left join product p on pm.product_id = p.id
        <where>
            po.status in (1, 2)
            <if test="planStart != null and planEnd != null">
                and po.plan_complete_time &gt;= #{planStart}
                and po.plan_complete_time &lt; #{planEnd}
            </if>
        </where>
        order by case when po.status = 2 then 0 else 1 end, po.id desc
        limit #{size}
    </select>
 
    <select id="countHomeTodayProductionPlan" resultType="java.lang.Long">
        select count(1)
        from production_order po
        <where>
            po.status in (1, 2)
            <if test="planStart != null and planEnd != null">
                and po.plan_complete_time &gt;= #{planStart}
                and po.plan_complete_time &lt; #{planEnd}
            </if>
        </where>
    </select>
 
</mapper>