chenlu
2024-03-07 de18cca83738bdf6b279046e34b910ccd5b73a84
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
<?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.example.erp.mapper.pp.ReportingWorkMapper">
    <resultMap id="reportingWorkMap" type="com.example.erp.entity.pp.ReportingWork">
        <result property="orderId" column="order_id"/>
        <result property="productionId" column="production_id"/>
        <result property="previousProcess" column="previous_process"/>
        <result property="nextProcess" column="next_process"/>
        <result property="thisProcess" column="this_process"/>
        <association property="order" javaType="com.example.erp.entity.sd.Order">
            <result property="customerId" column="customer_id"/>
            <result property="customerName" column="customer_name"/>
            <result property="project" column="project"/>
        </association>
        <association property="flowCard" javaType="com.example.erp.entity.pp.FlowCard">
            <result property="orderId" column="order_id"/>
            <result property="productionId" column="production_id"/>
            <result property="quantity" column="quantity"/>
        </association>
        <association property="reportingWorkDetail" javaType="com.example.erp.entity.pp.ReportingWorkDetail">
            <result property="completedQuantity" column="completed_quantity"/>
        </association>
 
    </resultMap>
 
    <select id="AddSelectLastWorkMp" resultMap="reportingWorkMap">
        select o.order_id,
               fc.production_id,
               o.customer_id,
               o.customer_name,
               o.project,
               SUM(fc.quantity)   as quantity,
               #{previousProcess} as previous_process,
               #{nextProcess}     as next_process,
               #{process} as  this_process
        from sd.order as o
                 left join flow_card as fc on fc.order_id = o.order_id
        where fc.process_id = #{processIdStr}
          and position(fc.technology_number in #{technologyStr})
        GROUP BY fc.process_id
    </select>
 
    <select id="SelectWorkBasicDeviceMp">
        SELECT bdp.id,bdp.basic_type,bdp.basic_name, bd.basic_name as basic_category FROM  sd.basic_data as bd left join  `basic_data_produce` as bdp
                                                                                                                          on bd.id=bdp.basic_category
        where bd.basic_category="process" and bdp.basic_type="device" and bd.basic_name = #{process}
    </select>
 
    <select id="SelectWorkBasicTeamsMp">
        SELECT bdp.id,bdp.basic_type,bdp.basic_name, bd.basic_name as basic_category FROM  sd.basic_data as bd left join  `basic_data_produce` as bdp
                                                                                                                          on bd.id=bdp.basic_category
        where bd.basic_category="process" and bdp.basic_type="teamsgroups" and bd.basic_name = #{process}
    </select>
 
    <!--    查询流程卡工艺流程-->
    <select id="SelectTechnologicalProcess">
        select ogd.process
        from sd.order_glass_detail as ogd
        where ogd.production_id = LEFT(#{processIdStr}, 11)
        limit 1
 
    </select>
 
    <select id="SelectWorkTechnologyMp">
        select GROUP_CONCAT(distinct fc.technology_number)
        from flow_card as fc
        where fc.process_id = #{processIdStr}
    </select>
 
<!--    第一道工序报工明细查询-->
    <select id="SelectTechnologicalNumMp">
        SELECT
            fc.order_number,
            ogd.glass_child,
            ogd.technology_number,
            ogd.glass_address,
            fc.quantity AS quantity_card,
            ogd.child_width,
            ogd.child_height,
            od.shape,
            fc.quantity -odpd.reporting_work_num as quantity,
            odpd.reporting_work_num_count as completed,
            odpd.broken_num as onceBroken
        FROM
            sd.order_detail AS od
        LEFT JOIN sd.order_glass_detail AS ogd
            ON od.order_id = ogd.order_id
            AND od.order_number = ogd.order_number
        LEFT JOIN flow_card AS fc
            ON fc.order_id = ogd.order_id
            and fc.production_id=ogd.production_id
            AND fc.order_number = ogd.order_number
            AND fc.technology_number = ogd.technology_number
        left join sd.order_process_detail as odpd
            ON  odpd.order_id = fc.order_id
            AND odpd.order_number = fc.order_number
            AND odpd.technology_number = fc.technology_number
        WHERE
            fc.process_id = #{processIdStr}
          AND fc.technology_number = #{technologyStr}
          AND odpd.process = #{process}
        order by fc.order_number
    </select>
 
<!--    非第一道工序报工明细查询-->
    <select id="SelectReworlDetailMp">
        SELECT fc.order_number,
               ogd.glass_child,
               ogd.technology_number,
               ogd.glass_address,
               fc.quantity as quantity_card,
               ogd.child_width,
               ogd.child_height,
               od.shape,
               reporting_work_num -IFNULL(rwd.completed_quantity,0)-IFNULL(rwd.breakage_quantity,0)-IFNULL((rwd.wait_rework_quantity),0) as quantity
        FROM sd.order_detail as od
                 left join sd.order_glass_detail as ogd
                           on od.order_id = ogd.order_id and od.order_number = ogd.order_number
                 left join sd.order_process_detail as opd
                           on opd.order_id = ogd.order_id and opd.order_number = ogd.order_number and
                              opd.technology_number = ogd.technology_number
 
                 left join flow_card as fc on opd.order_id = fc.order_id and opd.order_number = fc.order_number and
                                              opd.technology_number = fc.technology_number
                 left join reporting_work as rw on rw.order_id=fc.order_id and
                                                   rw.production_id=fc.production_id and rw.process_id=fc.process_id and rw.this_process = #{previousProcess}
                 left join reporting_work_detail as rwd on rwd.reporting_work_id=rw.reporting_work_id and
                                                           rwd.order_number=fc.order_number and rwd.technology_number=fc.technology_number
        where fc.process_id = #{processIdStr}
          and opd.process = #{previousProcess}
          and position(ogd.technology_number in #{technologyStr})
 
        order by fc.order_number
    </select>
 
    <select id="SelectProcessMp">
        select * from sd.basic_data where basic_type='product' and basic_category='process'
 
    </select>
 
    <select id="historyProcessMp">
        select ifnull(GROUP_CONCAT(distinct rw.this_process),'') from reporting_work as rw where rw.process_id=#{processIdStr}
    </select>
 
    <select id="historyDeviceMp">
        SELECT
            bdp.id,
            bdp.basic_type,
            bdp.basic_name,
            bd.basic_name AS basic_category
        FROM
            sd.basic_data AS bd
                LEFT JOIN `basic_data_produce` AS bdp ON bd.id = bdp.basic_category
        WHERE
            bd.basic_category = 'process'
          AND bdp.basic_type = 'device'
          AND POSITION(bd.basic_name in CONCAT(#{historyProcess},#{process}))
    </select>
 
    <select id="historyTeamsMp">
        SELECT
            bdp.id,
            bdp.basic_type,
            bdp.basic_name,
            bd.basic_name,bd.id AS basic_category,
            rw.process
        FROM
            sd.basic_data AS bd
        LEFT JOIN `basic_data_produce` AS bdp
            ON bd.id = bdp.basic_category
        right join (
                    select distinct process from
                        (   select distinct rw.this_process as  process
                            from reporting_work as rw where rw.process_id=#{processIdStr}
                            UNION
                            select #{process}
                        ) as t
                    ) as  rw
        on rw.process=bd.basic_name
        WHERE
           bdp.basic_type = 'teamsgroups'
    </select>
 
    <select id="SelectHistoryProcessMp">
        SELECT
            distinct
            bd.basic_name AS basic_category
        FROM
            sd.basic_data AS bd
                LEFT JOIN `basic_data_produce` AS bdp ON bd.id = bdp.basic_category
        WHERE
            bd.basic_category = 'process'
          AND bdp.basic_type = 'teamsgroups'
          AND POSITION(bd.basic_name in CONCAT(#{historyProcess},#{process}))
    </select>
 
    <select id="selectBasicNameByType">
        select * from `basic_data_produce` as a where a.basic_type  = #{type}
    </select>
 
    <select id="selectMaxReportingWorkId">
        select
            ifnull(SUBSTR(max(reporting_work_id) from 9),0)
        from
            reporting_work as a
        where
            date(a.create_time) = curdate()
        order by id desc,reporting_work_id    desc limit  1
    </select>
 
</mapper>