yangys
2024-04-17 3e7e8a98434731121d4a8736fd35af4cd6cb7a9e
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
<?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.qianwen.smartman.modules.trace.mapper.TraceFlowRecordMapper">
 
 
    <select id="getExportData" resultType="com.qianwen.smartman.modules.trace.vo.TraceCatalogFlowRecordExportVO">
        select
        tc.part_no AS partNo,
        tc.online_time AS onlineTime,
        tc.batch_number AS batchNumber,
        tc.qualified AS qualified,
        tc.is_rework_part AS isReworkPart,
        tc.shift_index_name AS shiftIndexName,
        tfr.flow_code AS flowCode,
        tfr.flow_display_name AS flowDisplayName,
        tfr.workstation_code AS workstationCode,
        tfr.workstation_name AS workstationName,
        tfr.workbench_name AS workbenchName,
        tfr.flow_state AS flowState,
        tfr.flow_tag AS flowTag,
        tfr.entry_time AS entryTime,
        tfr.left_time AS leftTime,
        tfs.flow_seq AS flowSeq
        FROM  blade_trace_catalog tc
        LEFT JOIN blade_trace_flow_record tfr ON tfr.part_no = tc.part_no
        <if test="searchVO.workstationId != null and searchVO.workstationId != ''">
             and tfr.workstation_id = #{searchVO.workstationId}
        </if>
        LEFT jOIN blade_trace_flow_settings tfs ON tfs.id=tfr.trace_flow_setting_id
        <where>
            <if test="searchVO.keywords != null and searchVO.keywords != ''">
                (tc.part_no like concat(#{searchVO.keywords},'%') or tc.batch_number like concat(#{searchVO.keywords},'%') )
            </if>
            <if test="searchVO.workstationGroupIds != null and searchVO.workstationGroupIds.size() > 0 ">
                AND tc.workstation_group_id in
                <foreach collection="searchVO.workstationGroupIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="searchVO.onlineStartTime != null and searchVO.onlineEndTime != null">
                and tc.online_time between #{searchVO.onlineStartTime} and #{searchVO.onlineEndTime}
            </if>
            <if test="searchVO.offlineStartTime != null and searchVO.offlineEndTime != null">
                and tc.offline_time between #{searchVO.offlineStartTime} and #{searchVO.offlineEndTime}
            </if>
        </where>
        order by tc.online_time desc
    </select>
 
    <select id="workpieceTracePage" resultType="com.qianwen.smartman.modules.trace.vo.WorkpieceTraceVO">
        select btfr.id recordId,
        btc.id traceId,
        btfr.part_no partNo,
        btc.batch_number batchNumber,
        btfr.workstation_id workstationId,
        btfr.workstation_code workstationCode,
        btfr.workstation_name workstationName,
        btfr.workbench_id workbenchId,
        btfr.workbench_name workbenchName,
        btc.shift_index_name shiftIndexName,
        btc.trace_status traceStatus,
        btc.online_time onlineTime,
        btc.offline_time offlineTime
        from blade_trace_flow_record btfr
        INNER JOIN blade_trace_catalog btc on btfr.part_no = btc.part_no
        where btfr.is_deleted = 0
        and btc.is_deleted = 0
        and btfr.flow_tag = 2
        <if test="ew != null">
            and ${ew.sqlSegment}
        </if>
        order by btc.online_time DESC
    </select>
 
    <select id="exportWorkpieceTrace" resultType="com.qianwen.smartman.modules.trace.dto.WorkpieceTraceDTO">
        select btc.batch_number batchNumber,
        btfr.part_no partNo,
        btc.online_time onlineTime,
        btc.offline_time offlineTime,
        btfr.workstation_code workstationCode,
        btfr.workstation_name workstationName,
        btfr.workbench_name workbenchName,
        btc.shift_index_name shiftIndexName,
        btc.trace_status traceStatus,
        <if test="_databaseId == 'mysql' ">
            group_concat(btrnr.reason_name) reasonCode
        </if>
        <if test="_databaseId == 'dm' ">
            wm_concat(btrnr.reason_name) reasonCode
        </if>
        <if test="_databaseId == 'oracle' ">
            LISTAGG(to_char(btrnr.reason_name), '/') WITHIN GROUP(ORDER BY btrnr.reason_name) as reasonCode
        </if>
        from blade_trace_flow_record btfr
        INNER JOIN blade_trace_catalog btc on btfr.part_no = btc.part_no
        LEFT JOIN blade_trace_record_ng_reason btrnr on btfr.id = btrnr.record_id
        where btfr.is_deleted = 0
        and btc.is_deleted = 0
        and btfr.flow_tag = 2
        <if test="ew != null">
            and ${ew.sqlSegment}
        </if>
        group by btfr.id, btc.id, btfr.part_no, btc.batch_number, btfr.workstation_id, btfr.workstation_code,
        btfr.workstation_name, btfr.workbench_id, btfr.workbench_name, btc.shift_index_name, btc.trace_status,
        btc.online_time, btc.offline_time
        order by btc.online_time desc
    </select>
 
    <select id="getNgTraceFlowRecord" resultType="com.qianwen.smartman.modules.trace.vo.WorkpieceTraceVO">
        SELECT
            tfr.id as recordId,
            tc.id traceId,
            tc.part_no as partNo
        FROM
        blade_trace_catalog tc
        INNER JOIN blade_trace_flow_record tfr ON tc.part_no = tfr.part_no     AND tfr.flow_tag = 2
        <if test="searchVO.workstationId != null and searchVO.workstationId != ''">
            and tfr.workstation_id = #{searchVO.workstationId}
        </if>
        <where>
            <if test="searchVO.keyword != null and searchVO.keyword != ''">
                (tc.part_no like concat(#{searchVO.keyword},'%') or tc.batch_number like concat(#{searchVO.keyword},'%') )
            </if>
            <if test="searchVO.groupIds != null and searchVO.groupIds.size() > 0 ">
                AND tc.workstation_group_id in
                <foreach collection="searchVO.groupIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="searchVO.startTime != null and searchVO.endTime != null">
                and tc.online_time between #{searchVO.startTime} and #{searchVO.endTime}
            </if>
        </where>
        order by tc.online_time desc
    </select>
 
    <select id="getNgFullTraceFlowRecord" resultType="com.qianwen.smartman.modules.trace.vo.WorkpieceTraceVO">
        SELECT
        tfr.id as recordId,
        tc.id traceId,
        tc.part_no as partNo,
        tc.batch_number as batchNumber,
        tfr.workstation_id as workstationId,
        tfr.workstation_code as workstationCode,
        tfr.workstation_name as workstationName,
        tfr.workbench_id workbenchId,
        tfr.workbench_name as workbenchName ,
        tc.shift_index_name as shiftIndexName,
        tc.trace_status as traceStatus,
        tc.online_time as onlineTime,
        tc.offline_time as offlineTime
        FROM
        blade_trace_flow_record tfr
        INNER JOIN     blade_trace_catalog tc  ON tc.part_no = tfr.part_no
        where tfr.id in
            <foreach collection="recordIdList" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        order by tc.online_time,tfr.entry_time
    </select>
 
    <select id="countNgTraceRecord" resultType="java.lang.Long" parameterType="com.qianwen.smartman.modules.trace.vo.WorkpieceTraceSearchVO">
        SELECT
            count(*)
        FROM
        blade_trace_catalog tc
        INNER JOIN blade_trace_flow_record tfr ON tc.part_no = tfr.part_no     AND tfr.flow_tag = 2
        <if test="searchVO.workstationId != null and searchVO.workstationId != ''">
            and tfr.workstation_id = #{searchVO.workstationId}
        </if>
        <where>
            <if test="searchVO.keyword != null and searchVO.keyword != ''">
                (tc.part_no like concat(#{searchVO.keyword},'%') or tc.batch_number like concat(#{searchVO.keyword},'%') )
            </if>
            <if test="searchVO.groupIds != null and searchVO.groupIds.size() > 0 ">
                AND tc.workstation_group_id in
                <foreach collection="searchVO.groupIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="searchVO.startTime != null and searchVO.endTime != null">
                and tc.online_time between #{searchVO.startTime} and #{searchVO.endTime}
            </if>
        </where>
        order by tc.online_time desc
    </select>
 
    <select id="exportNgTraceRecord" resultType="com.qianwen.smartman.modules.trace.dto.WorkpieceTraceDTO" parameterType="com.qianwen.smartman.modules.trace.vo.WorkpieceTraceSearchVO">
        SELECT
        tc.batch_number batchNumber,
        tfr.part_no partNo,
        tc.online_time onlineTime,
        tc.offline_time offlineTime,
        tfr.workstation_code workstationCode,
        tfr.workstation_name workstationName,
        tfr.workbench_name workbenchName,
        tc.shift_index_name shiftIndexName,
        tc.trace_status traceStatus,
        trnr.reason_name  reasonCode
        FROM
        blade_trace_catalog tc
        INNER JOIN blade_trace_flow_record tfr ON tc.part_no = tfr.part_no     AND tfr.flow_tag = 2
        <if test="searchVO.workstationId != null and searchVO.workstationId != ''">
            and tfr.workstation_id = #{searchVO.workstationId}
        </if>
        LEFT JOIN blade_trace_record_ng_reason trnr on tfr.id = trnr.record_id
        <where>
            <if test="searchVO.keyword != null and searchVO.keyword != ''">
                (tc.part_no like concat(#{searchVO.keyword},'%') or tc.batch_number like concat(#{searchVO.keyword},'%') )
            </if>
            <if test="searchVO.groupIds != null and searchVO.groupIds.size() > 0 ">
                AND tc.workstation_group_id in
                <foreach collection="searchVO.groupIds" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            <if test="searchVO.startTime != null and searchVO.endTime != null">
                and tc.online_time between #{searchVO.startTime} and #{searchVO.endTime}
            </if>
        </where>
        order by tc.online_time desc
    </select>
 
 
</mapper>