3 天以前 09d3c4a46e1b67415a716251acea7a1c592c8af7
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
<?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.pro.workorder.MesProWorkOrderMapper">
 
    <select id="selectSchedulePage" resultType="cn.iocoder.yudao.module.mes.dal.dataobject.pro.workorder.MesProWorkOrderDO">
        SELECT
            t.*
        FROM
            mes_pro_work_order t
        <where>
            t.deleted = 0
            <if test="pageReqVO.code != null and pageReqVO.code != ''">
                AND t.code LIKE CONCAT('%', #{pageReqVO.code}, '%')
            </if>
            <if test="pageReqVO.name != null and pageReqVO.name != ''">
                AND t.name LIKE CONCAT('%', #{pageReqVO.name}, '%')
            </if>
            <if test="pageReqVO.type != null">
                AND t.type = #{pageReqVO.type}
            </if>
            <if test="pageReqVO.orderSourceCode != null and pageReqVO.orderSourceCode != ''">
                AND t.order_source_code LIKE CONCAT('%', #{pageReqVO.orderSourceCode}, '%')
            </if>
            <if test="pageReqVO.productId != null">
                AND t.product_id = #{pageReqVO.productId}
            </if>
            <if test="pageReqVO.clientId != null">
                AND t.client_id = #{pageReqVO.clientId}
            </if>
            <if test="pageReqVO.status != null">
                AND t.status = #{pageReqVO.status}
            </if>
            <if test="pageReqVO.requestDate != null and pageReqVO.requestDate.length > 0">
                AND t.request_date >= #{pageReqVO.requestDate[0]}
                <if test="pageReqVO.requestDate.length > 1">
                    AND t.request_date &lt;= #{pageReqVO.requestDate[1]}
                </if>
            </if>
            
            <if test="permittedClientIds != null">
                <choose>
                    <when test="permittedClientIds.size() > 0">
                        AND (t.client_id IN
                        <foreach collection="permittedClientIds" item="id" open="(" separator="," close=")">
                            #{id}
                        </foreach>
                        OR t.client_id IS NULL)
                    </when>
                    <otherwise>
                        AND 1 = 0
                    </otherwise>
                </choose>
            </if>
            
            <if test="pageReqVO.scheduleStatus != null">
                <choose>
                    <!-- scheduleStatus: 1=已完成 (工单状态=4 或者 (有工序 且 所有工序都有任务 且 所有任务已完成)) -->
                    <when test="pageReqVO.scheduleStatus == 1">
                        AND (
                            t.status = 2
                            OR (
                                t.status != 4
                                AND EXISTS (SELECT 1 FROM mes_pro_work_order_process wp WHERE wp.work_order_id = t.id AND wp.deleted = 0)
                                AND NOT EXISTS (
                                    SELECT 1 FROM mes_pro_work_order_process wp 
                                    WHERE wp.work_order_id = t.id AND wp.deleted = 0 
                                    AND NOT EXISTS (
                                        SELECT 1 FROM mes_pro_task task 
                                        WHERE task.work_order_id = t.id AND task.process_id = wp.process_id AND task.deleted = 0
                                    )
                                )
                                AND NOT EXISTS (
                                    SELECT 1 FROM mes_pro_task task 
                                    WHERE task.work_order_id = t.id AND task.deleted = 0 
                                    AND IFNULL(task.produced_quantity, 0) &lt; IFNULL(task.quantity, 0)
                                )
                            )
                        )
                    </when>
                    <!-- scheduleStatus: 0=未完成 (工单状态!=4 并且 (无工序 或 有某工序无任务 或 存在未完成的任务)) -->
                    <when test="pageReqVO.scheduleStatus == 0">
                        AND (
                            t.status in (1)
                            AND (
                                NOT EXISTS (SELECT 1 FROM mes_pro_work_order_process wp WHERE wp.work_order_id = t.id AND wp.deleted = 0)
                                OR EXISTS (
                                    SELECT 1 FROM mes_pro_work_order_process wp 
                                    WHERE wp.work_order_id = t.id AND wp.deleted = 0 
                                    AND NOT EXISTS (
                                        SELECT 1 FROM mes_pro_task task 
                                        WHERE task.work_order_id = t.id AND task.process_id = wp.process_id AND task.deleted = 0
                                    )
                                )
                                OR EXISTS (
                                    SELECT 1 FROM mes_pro_task task 
                                    WHERE task.work_order_id = t.id AND task.deleted = 0 
                                    AND IFNULL(task.produced_quantity, 0) &lt; IFNULL(task.quantity, 0)
                                )
                            )
                        )
                    </when>
                </choose>
            </if>
        </where>
        ORDER BY t.id DESC
    </select>
 
</mapper>