李林
2023-10-07 658d4927d468c47208fd012d9128b09249c07eff
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
<?xml version="1.0" encoding="UTF-8"?>
 
<!--
  ~
  ~      Copyright (c) 2018-2025, ztt All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the pig4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: ztt
  ~
  -->
 
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 
<mapper namespace="com.chinaztt.mes.plan.mapper.MasterProductionScheduleMapper">
 
    <resultMap id="masterProductionScheduleMap" type="com.chinaztt.mes.plan.dto.MasterProductionScheduleDTO">
        <id property="id" column="id"/>
        <result property="factoryId" column="factory_id"/>
        <result property="mpsNo" column="mps_no"/>
        <result property="requiredDate" column="required_date"/>
        <result property="remark" column="remark"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="createUser" column="create_user"/>
        <result property="updateUser" column="update_user"/>
        <result property="partId" column="part_id"/>
        <result property="qtyRequired" column="qty_required"/>
        <result property="state" column="state"/>
        <result property="partNo" column="part_no"/>
        <result property="partName" column="part_name"/>
        <result property="partDescription" column="part_description"/>
        <result property="unit" column="unit"/>
        <result property="inventoryReservedQuantity" column="inventory_reserved_quantity"/>
        <result property="outsourcingNumber" column="outsourcing_number"/>
        <result property="manufacturingQuantity" column="manufacturing_quantity"/>
        <result property="customerOrderNo" column="customer_order_no"/>
        <result property="outerColor" column="outer_color"/>
        <result property="lengthRequirement" column="length_requirement"/>
        <result property="orderRemark" column="order_remark"/>
        <result property="printRequirement" column="print_requirement"/>
        <result property="source" column="source"/>
        <result property="isAudit" column="is_audit"/>
        <result property="technologyDocumentId" column="technology_document_id"/>
        <result property="docNumber" column="doc_number"/>
        <result property="manufactureAttr" column="manufacture_attr"/>
        <result property="promisedDeliveryDate" column="promised_delivery_date"/>
    </resultMap>
 
    <select id="getDtoById" resultType="com.chinaztt.mes.plan.dto.MasterProductionScheduleDTO">
        SELECT * FROM plan_master_production_schedule where ID = #{id}
    </select>
 
    <select id="getMasterProductionSchedulePage" resultMap="masterProductionScheduleMap">
        select
            D.id,
            D.factory_id,
            D.mps_no,
            D.required_date,
            D.remark,
            D.create_time,
            D.update_time,
            D.create_user,
            D.update_user,
            D.part_id,
            D.qty_required,
            D.state,
            D.part_no,
            D.unit,
            D.part_name,
            D.part_description,
            D.inventory_reserved_quantity,
            D.outsourcing_number,
            D.manufacturing_quantity,
            D.customer_order_no,
            D.outer_color,
            D.length_requirement,
            D.order_remark,
            D.print_requirement,
            D.source,
            D.is_audit,
            D.technology_document_id,
            D.doc_number,
            D.manufacture_attr,
            D.promised_delivery_date
        FROM (
                 select
                     pmps.*,
                     bp.part_no,
                     bp.part_name,
                     bp.description   part_description,
                     bp.unit,
                     pco.customer_order_no,
                     pco.outer_color,
                     pcop."value"  as length_requirement,
                     pcop2."value" as order_remark,
                     pcop3."value" as print_requirement,
                     (
                         SELECT coalesce(sum(wjso.reserved_quantity), 0)
                         from
                             warehouse_join_stock_order wjso
                                 left join plan_customer_order pco on pco."id" = wjso.customer_order_id
                                 left join plan_join_model_customer pjmc on pjmc.customer_order_id = pco."id" AND pjmc.model = 'plan_master_production_schedule'
                         where wjso.type = '客户订单预留'
                           and status = '02confirmed'
                           and pjmc.model_id = pmps.id
                     )                inventory_reserved_quantity,
                     (
                         SELECT coalesce(sum(poo.qty_required), 0)
                         from plan_outsourcing_order poo
                         where poo.mps_id = pmps.id
                     )                outsourcing_number,
                     (
                         SELECT coalesce(sum(pmo.qty_required), 0)
                         from plan_manufacturing_order pmo
                         where pmo.mps_id = pmps.id AND pmo.part_id = pmps.part_id
                     )                manufacturing_quantity
                 from plan_master_production_schedule pmps
                          left join basic_part bp on bp."id" = pmps.part_id
                          left join plan_join_model_customer pjmc on pjmc.model_id = pmps.id and pjmc.model = 'plan_master_production_schedule'
                          left join plan_customer_order pco on pco.id = pjmc.customer_order_id
                          left join plan_customer_order_param pcop on pcop.order_id = pco.id and pcop.field = 'LengthRequirement'
                          left join plan_customer_order_param pcop2 on pcop2.order_id = pco.id and pcop2.field = 'Remark'
                          left join plan_customer_order_param pcop3 on pcop3.order_id = pco.id and pcop3.field = 'PrintRequirement'
             ) D
        <if test="ew.emptyOfWhere == false">
            ${ew.customSqlSegment}
        </if>
    </select>
 
    <update id="updateRequiredDateBySource">
        update plan_master_production_schedule pmps
        set required_date=(select min(pmr.required_date)
                           from plan_mps_requirements pmr
                                    left join plan_mps_source pms on pms.mps_requ_id = pmr."id"
                           where pms.mps_id = pmps."id")
        where exists(select 1 from plan_mps_source pms where pms.mps_id = pmps."id" and pms.mps_requ_id = #{param.id})
    </update>
    <select id="getPlanProduction" resultMap="masterProductionScheduleMap">
        select *
        FROM plan_master_production_schedule a
        where a.part_id = #{id}
          AND to_char(create_time, 'yyyy-MM-dd') = #{date}
    </select>
 
    <select id="getByIdExt" resultMap="masterProductionScheduleMap">
        select
            D.id,
            D.factory_id,
            D.mps_no,
            D.required_date,
            D.remark,
            D.create_time,
            D.update_time,
            D.create_user,
            D.update_user,
            D.part_id,
            D.qty_required,
            D.state,
            D.part_no,
            D.unit,
            D.part_name,
            D.part_description,
            D.inventory_reserved_quantity,
            D.outsourcing_number,
            D.manufacturing_quantity,
            D.source,
            D.is_audit,
            D.technology_document_id,
            D.doc_number,
            D.manufacture_attr,
            D.promised_delivery_date
        FROM (
                 select
                     pmps.*,
                     bp.part_no,
                     bp.part_name,
                     bp.description part_description,
                     bp.unit,
                     (
                         SELECT coalesce(sum(wjso.reserved_quantity), 0)
                         from
                             warehouse_join_stock_order wjso
                                 left join plan_customer_order pco on pco."id" = wjso.customer_order_id
                                 left join plan_join_model_customer pjmc on pjmc.customer_order_id = pco."id" AND pjmc.model = 'plan_master_production_schedule'
                         where wjso.type = '客户订单预留'
                           and status = '02confirmed'
                           and pjmc.model_id = pmps.id
                     )              inventory_reserved_quantity,
                     (
                         SELECT coalesce(sum(poo.qty_required), 0)
                         from plan_outsourcing_order poo
                         where poo.mps_id = pmps.id
                     )              outsourcing_number,
                     (
                         SELECT coalesce(sum(pmo.qty_required), 0)
                         from plan_manufacturing_order pmo
                         where pmo.mps_id = pmps.id
                     )              manufacturing_quantity
                 from plan_master_production_schedule pmps
                          left join basic_part bp on bp."id" = pmps.part_id
                 where pmps.id = #{id}
             ) D
    </select>
 
    <update id="rejectHandleDocument">
        UPDATE plan_master_production_schedule
        SET doc_number             = NULL,
            technology_document_id = NULL
        WHERE id = #{id};
    </update>
</mapper>