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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?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.dy.pipIrrGlobal.daoOp.OpeWorkOrderMapper">
  <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoOp.OpeWorkOrder">
    <!--@mbg.generated-->
    <!--@Table ope_work_order-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="dispatcher_id" jdbcType="BIGINT" property="dispatcherId" />
    <result column="inspector_id" jdbcType="BIGINT" property="inspectorId" />
    <result column="task_type_id" jdbcType="BIGINT" property="taskTypeId" />
    <result column="task_content" jdbcType="VARCHAR" property="taskContent" />
    <result column="complete_criteria" jdbcType="VARCHAR" property="completeCriteria" />
    <result column="dead_line" jdbcType="TIMESTAMP" property="deadLine" />
    <result column="complete_time" jdbcType="TIMESTAMP" property="completeTime" />
    <result column="dispatch_time" jdbcType="TIMESTAMP" property="dispatchTime" />
    <result column="client_report_id" jdbcType="BIGINT" property="clientReportId" />
    <result column="inspector_report_id" jdbcType="BIGINT" property="inspectorReportId" />
    <result column="state" jdbcType="TINYINT" property="state" />
    <result column="reject_times" jdbcType="INTEGER" property="rejectTimes" />
    <result column="deleted" jdbcType="BIGINT" property="deleted" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, dispatcher_id, inspector_id, task_type_id, task_content, complete_criteria, dead_line, 
    complete_time, dispatch_time, client_report_id, inspector_report_id, `state`, reject_times, 
    deleted
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--@mbg.generated-->
    select 
    <include refid="Base_Column_List" />
    from ope_work_order
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--@mbg.generated-->
    delete from ope_work_order
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoOp.OpeWorkOrder">
    <!--@mbg.generated-->
    insert into ope_work_order (id, dispatcher_id, inspector_id, 
      task_type_id, task_content, complete_criteria, 
      dead_line, complete_time, dispatch_time, 
      client_report_id, inspector_report_id, `state`, 
      reject_times, deleted)
    values (#{id,jdbcType=BIGINT}, #{dispatcherId,jdbcType=BIGINT}, #{inspectorId,jdbcType=BIGINT}, 
      #{taskTypeId,jdbcType=BIGINT}, #{taskContent,jdbcType=VARCHAR}, #{completeCriteria,jdbcType=VARCHAR}, 
      #{deadLine,jdbcType=TIMESTAMP}, #{completeTime,jdbcType=TIMESTAMP}, #{dispatchTime,jdbcType=TIMESTAMP}, 
      #{clientReportId,jdbcType=BIGINT}, #{inspectorReportId,jdbcType=BIGINT}, #{state,jdbcType=TINYINT}, 
      #{rejectTimes,jdbcType=INTEGER}, #{deleted,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoOp.OpeWorkOrder">
    <!--@mbg.generated-->
    insert into ope_work_order
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="dispatcherId != null">
        dispatcher_id,
      </if>
      <if test="inspectorId != null">
        inspector_id,
      </if>
      <if test="taskTypeId != null">
        task_type_id,
      </if>
      <if test="taskContent != null">
        task_content,
      </if>
      <if test="completeCriteria != null">
        complete_criteria,
      </if>
      <if test="deadLine != null">
        dead_line,
      </if>
      <if test="completeTime != null">
        complete_time,
      </if>
      <if test="dispatchTime != null">
        dispatch_time,
      </if>
      <if test="clientReportId != null">
        client_report_id,
      </if>
      <if test="inspectorReportId != null">
        inspector_report_id,
      </if>
      <if test="state != null">
        `state`,
      </if>
      <if test="rejectTimes != null">
        reject_times,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="dispatcherId != null">
        #{dispatcherId,jdbcType=BIGINT},
      </if>
      <if test="inspectorId != null">
        #{inspectorId,jdbcType=BIGINT},
      </if>
      <if test="taskTypeId != null">
        #{taskTypeId,jdbcType=BIGINT},
      </if>
      <if test="taskContent != null">
        #{taskContent,jdbcType=VARCHAR},
      </if>
      <if test="completeCriteria != null">
        #{completeCriteria,jdbcType=VARCHAR},
      </if>
      <if test="deadLine != null">
        #{deadLine,jdbcType=TIMESTAMP},
      </if>
      <if test="completeTime != null">
        #{completeTime,jdbcType=TIMESTAMP},
      </if>
      <if test="dispatchTime != null">
        #{dispatchTime,jdbcType=TIMESTAMP},
      </if>
      <if test="clientReportId != null">
        #{clientReportId,jdbcType=BIGINT},
      </if>
      <if test="inspectorReportId != null">
        #{inspectorReportId,jdbcType=BIGINT},
      </if>
      <if test="state != null">
        #{state,jdbcType=TINYINT},
      </if>
      <if test="rejectTimes != null">
        #{rejectTimes,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        #{deleted,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoOp.OpeWorkOrder">
    <!--@mbg.generated-->
    update ope_work_order
    <set>
      <if test="dispatcherId != null">
        dispatcher_id = #{dispatcherId,jdbcType=BIGINT},
      </if>
      <if test="inspectorId != null">
        inspector_id = #{inspectorId,jdbcType=BIGINT},
      </if>
      <if test="taskTypeId != null">
        task_type_id = #{taskTypeId,jdbcType=BIGINT},
      </if>
      <if test="taskContent != null">
        task_content = #{taskContent,jdbcType=VARCHAR},
      </if>
      <if test="completeCriteria != null">
        complete_criteria = #{completeCriteria,jdbcType=VARCHAR},
      </if>
      <if test="deadLine != null">
        dead_line = #{deadLine,jdbcType=TIMESTAMP},
      </if>
      <if test="completeTime != null">
        complete_time = #{completeTime,jdbcType=TIMESTAMP},
      </if>
      <if test="dispatchTime != null">
        dispatch_time = #{dispatchTime,jdbcType=TIMESTAMP},
      </if>
      <if test="clientReportId != null">
        client_report_id = #{clientReportId,jdbcType=BIGINT},
      </if>
      <if test="inspectorReportId != null">
        inspector_report_id = #{inspectorReportId,jdbcType=BIGINT},
      </if>
      <if test="state != null">
        `state` = #{state,jdbcType=TINYINT},
      </if>
      <if test="rejectTimes != null">
        reject_times = #{rejectTimes,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        deleted = #{deleted,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoOp.OpeWorkOrder">
    <!--@mbg.generated-->
    update ope_work_order
    set dispatcher_id = #{dispatcherId,jdbcType=BIGINT},
      inspector_id = #{inspectorId,jdbcType=BIGINT},
      task_type_id = #{taskTypeId,jdbcType=BIGINT},
      task_content = #{taskContent,jdbcType=VARCHAR},
      complete_criteria = #{completeCriteria,jdbcType=VARCHAR},
      dead_line = #{deadLine,jdbcType=TIMESTAMP},
      complete_time = #{completeTime,jdbcType=TIMESTAMP},
      dispatch_time = #{dispatchTime,jdbcType=TIMESTAMP},
      client_report_id = #{clientReportId,jdbcType=BIGINT},
      inspector_report_id = #{inspectorReportId,jdbcType=BIGINT},
      `state` = #{state,jdbcType=TINYINT},
      reject_times = #{rejectTimes,jdbcType=INTEGER},
      deleted = #{deleted,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
 
  <!--根据主键获取工单视图对象-->
  <select id="getWorkOrderById" resultType="com.dy.pipIrrGlobal.voOp.VoWorkOrder">
    SELECT
        ord.id AS workOrderId,
        ord.dispatcher_id AS dispatcherId,
        us1.name AS dispatcher,
        ord.inspector_id AS inspectorId,
        us2.name AS inspector,
        typ.task_type AS taskType,
        ord.task_content AS taskContent,
        ord.complete_criteria AS completeCriteria,
        ord.dead_line AS deadLine,
        ord.client_report_id AS clientReportId,
        ord.inspector_report_id AS inspectorReportId,
        ord.complete_time AS completeTime,
        ord.dispatch_time AS dispatchTime,
        ord.reject_times AS rejectTimes,
        res.id AS proResultId,
        IFNULL(res.state,0) AS proResultStateId,
        CASE
            WHEN ord.state = 1 THEN '未完成'
            WHEN ord.state = 2 THEN '已完成'
        END AS state,
        CASE
            WHEN IFNULL(res.state,0) = 0 THEN    '未上报'
            WHEN res.state = 1 THEN    '待审核'
            WHEN res.state = 2 THEN    '已通过'
            WHEN res.state = 3 THEN    '被驳回'
            ELSE '未上报'
        END AS processingState
    FROM ope_work_order ord
        INNER JOIN ba_user us1 ON us1.id = ord.dispatcher_id
        INNER JOIN ba_user us2 ON us2.id = ord.inspector_id
        INNER JOIN ope_task_type typ ON typ.id = ord.task_type_id
        LEFT JOIN (SELECT * FROM `ope_processing_result` WHERE deleted = 0) res ON res.work_order_id = ord.id
    WHERE ord.deleted = 0 AND ord.id = #{workOrderId}
  </select>
 
  <!--获取指定派单人的、未上报的指定未删除工单,删除工单前判断使用使用-->
  <select id="getWorkOrder" resultType="com.dy.pipIrrGlobal.pojoOp.OpeWorkOrder">
    SELECT
        *
    FROM ope_work_order ord
    WHERE deleted = 0
        AND NOT EXISTS(SELECT * FROM ope_processing_result res WHERE res.work_order_id = ord.id)
        AND id = #{workOrderId} AND dispatcher_id = #{dispatcherId} LIMIT 1
  </select>
 
  <!--逻辑删除一个未删除的工单-->
  <update id="deleteWorkOrder">
    UPDATE ope_work_order SET deleted = UNIX_TIMESTAMP() WHERE deleted = 0 AND id = #{workOrderId}
  </update>
 
<!--  根据指定条件获取工单数量-->
  <select id="getWorkOrdersCount" resultType="java.lang.Long">
    select
      COUNT(*) AS recordCount
    FROM ope_work_order ord
    INNER JOIN ba_user us1 ON us1.id = ord.dispatcher_id
    INNER JOIN ba_user us2 ON us2.id = ord.inspector_id
    INNER JOIN ope_task_type typ ON typ.id = ord.task_type_id
    LEFT JOIN (SELECT * FROM `ope_processing_result` WHERE deleted = 0) res ON res.work_order_id = ord.id
    <where>
      AND ord.deleted = 0
 
      <if test = "dispatcherId != null">
        AND ord.dispatcher_id = #{dispatcherId}
      </if>
 
      <if test = "inspectorId != null">
        AND ord.inspector_id = #{inspectorId}
      </if>
 
      <if test = "dispatcher != null and dispatcher !=''">
        AND us1.name like CONCAT('%',#{dispatcher},'%')
      </if>
 
      <if test = "inspector != null and inspector !=''">
        AND us2.name like CONCAT('%',#{inspector},'%')
      </if>
 
      <if test = "state != null">
        AND ord.state = #{state}
      </if>
 
      <if test = "timeStart != null and timeStop != null">
        AND ord.dispatch_time BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
  </select>
 
  <select id="getWorkOrders" resultType="com.dy.pipIrrGlobal.voOp.VoWorkOrder">
    SELECT
        ord.id AS workOrderId,
        ord.dispatcher_id AS dispatcherId,
        us1.name AS dispatcher,
        ord.inspector_id AS inspectorId,
        us2.name AS inspector,
        typ.task_type AS taskType,
        ord.task_content AS taskContent,
        ord.complete_criteria AS completeCriteria,
        ord.dead_line AS deadLine,
        ord.client_report_id AS clientReportId,
        ord.inspector_report_id AS inspectorReportId,
        ord.complete_time AS completeTime,
        ord.dispatch_time AS dispatchTime,
        ord.reject_times AS rejectTimes,
        IFNULL(res.state,0) AS proResultStateId,
        CASE
            WHEN ord.state = 1 THEN '未完成'
            WHEN ord.state = 2 THEN '已完成'
        END AS state,
        CASE
            WHEN IFNULL(res.state,0) = 0 THEN    '未上报'
            WHEN res.state = 1 THEN    '待审核'
            WHEN res.state = 2 THEN    '已通过'
            WHEN res.state = 3 THEN    '被驳回'
            ELSE '未上报'
        END AS processingState,
        res.id AS proResultId
    FROM ope_work_order ord
        INNER JOIN ba_user us1 ON us1.id = ord.dispatcher_id
        INNER JOIN ba_user us2 ON us2.id = ord.inspector_id
        INNER JOIN ope_task_type typ ON typ.id = ord.task_type_id
        LEFT JOIN (SELECT * FROM `ope_processing_result` WHERE deleted = 0) res ON res.work_order_id = ord.id
    <where>
      AND ord.deleted = 0
 
      <if test = "dispatcherId != null">
        AND ord.dispatcher_id = #{dispatcherId}
      </if>
 
      <if test = "inspectorId != null">
        AND ord.inspector_id = #{inspectorId}
      </if>
 
      <if test = "dispatcher != null and dispatcher !=''">
        AND us1.name like CONCAT('%',#{dispatcher},'%')
      </if>
 
      <if test = "inspector != null and inspector !=''">
        AND us2.name like CONCAT('%',#{inspector},'%')
      </if>
 
      <if test = "state != null">
        AND ord.state = #{state}
      </if>
 
      <if test = "timeStart != null and timeStop != null">
        AND ord.dispatch_time BETWEEN #{timeStart} AND #{timeStop}
      </if>
    </where>
    ORDER BY ord.dispatch_time DESC
    <trim prefix="limit " >
      <if test="start != null and count != null">
        #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER}
      </if>
    </trim>
  </select>
</mapper>