yxh
6 天以前 68ff33beff11310e830b0615b5a81f83fad0f683
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
package cn.lihu.jh.module.ecg.controller.admin.devrent;
 
 
 
import cn.lihu.jh.framework.security.core.util.SecurityFrameworkUtils;
 
import cn.lihu.jh.module.ecg.dal.dataobject.appointment.AppointmentDO;
 
import cn.lihu.jh.module.ecg.dal.dataobject.devmanage.DeviceDO;
 
import cn.lihu.jh.module.ecg.enums.DevStateEnum;
 
import cn.lihu.jh.module.ecg.annotation.RequireBedOwner;
 
import cn.lihu.jh.module.ecg.service.appointment.AppointmentService;
 
 
import cn.lihu.jh.module.ecg.service.devmanage.DeviceService;
 
 
import cn.lihu.jh.module.ecg.service.queue.QueueService;
 
import lombok.extern.slf4j.Slf4j;
 
import org.springframework.web.bind.annotation.*;
 
import org.springframework.validation.annotation.Validated;
 
import org.springframework.security.access.prepost.PreAuthorize;
 
import io.swagger.v3.oas.annotations.tags.Tag;
 
import io.swagger.v3.oas.annotations.Parameter;
 
import io.swagger.v3.oas.annotations.Operation;
 
 
 
import java.util.*;
 
import java.io.IOException;
 
 
 
import cn.lihu.jh.framework.common.pojo.PageParam;
 
import cn.lihu.jh.framework.common.pojo.PageResult;
 
import cn.lihu.jh.framework.common.pojo.CommonResult;
 
import cn.lihu.jh.framework.common.util.object.BeanUtils;
 
 
 
import cn.lihu.jh.framework.excel.core.util.ExcelUtils;
 
 
 
import cn.lihu.jh.framework.apilog.core.annotation.ApiAccessLog;
 
 
 
import static cn.lihu.jh.framework.apilog.core.enums.OperateTypeEnum.*;
 
 
 
import cn.lihu.jh.module.ecg.controller.admin.devrent.vo.*;
 
import cn.lihu.jh.module.ecg.dal.dataobject.devrent.DevRentDO;
 
 
import cn.lihu.jh.module.ecg.service.devrent.DevRentService;
 
 
 
import javax.annotation.Resource;
 
import javax.servlet.http.HttpServletResponse;
 
import javax.validation.Valid;
 
 
 
@Tag(name = "装机拆机")
 
@RestController
 
@RequestMapping("/ecg/dev-rent")
 
@Validated
 
@Slf4j
 
public class DevRentController {
 
 
 
    @Resource
 
    private DevRentService devRentService;
 
 
 
    @Resource
 
    private DeviceService deviceService;
 
 
 
    @Resource
 
    private QueueService queueService;
 
 
 
    @Resource
 
    private AppointmentService appointmentService;
 
    /** 【主/围观】写操作的工位主人校验(只带患者信息的接口在方法里显式调用) */
    @Resource
 
    private cn.lihu.jh.module.ecg.service.room.RoomService roomService;
 
 
 
    // 常规检查 完成
 
    @RequireBedOwner("检查完成")
 
    @PostMapping("/routine-finish")
 
    @Operation(summary = "常规检查完成")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> routineFinish(@Valid @RequestBody RoutineFinishReqVO routineFinishReqVO) {
 
        CommonResult<Long> result = devRentService.routineFinishOperation(routineFinishReqVO);
 
 
 
        try {
 
            String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
 
            String userHisId = SecurityFrameworkUtils.getLoginUserHisId();
 
            // 【缺陷修复】优先用**服务返回的 rentId**(= 本次完成实际写入的检查单 id):
            //   · 普通患者:请求里带了 id,两者相同;
            //   · 紧急加做患者:请求里没有 id(没签到过),服务会新建检查单 ——
            //     原实现用 routineFinishReqVO.getId()(null)去确费,必然失败(且被 catch 吞掉),
            //     现场表现为"加急患者检查完成后没有确费"。
            Long rentId = null != result && null != result.getData()
                    ? result.getData() : routineFinishReqVO.getId();
 
            devRentService.feeConfirm(rentId, userHisId, userNickname, true);  // 故意 不检查返回值
 
        } catch (Exception e) {
 
            log.error("常规检查完成, 自动确费失败", e);
 
        }
 
 
 
        return result;
 
    }
 
 
 
    @RequireBedOwner("设备领用完成")
 
    @PostMapping("/dev-ready")
 
    @Operation(summary = "设备领用完成")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> devReady(@Valid @RequestBody DevRentSaveReqVO createReqVO) {
 
        String userHisId = SecurityFrameworkUtils.getLoginUserHisId();
 
        String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
 
        createReqVO.setOperater(userNickname);
 
        CommonResult<Long> result = devRentService.readyOperation(createReqVO);
 
 
 
        try {
 
            Long rentId = createReqVO.getId();
 
            devRentService.feeConfirm(rentId, userHisId, userNickname, true);  // 故意 不检查返回值
 
        } catch (Exception e) {
 
            log.error("设备领用完成, 自动确费失败", e);
 
        }
 
 
 
        return result;
 
    }
 
 
 
    @RequireBedOwner("装机完成")
 
    @PostMapping("/dev-install")
 
    @Operation(summary = "装机")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> devInstall(@Valid @RequestBody DevRentSaveReqVO createReqVO) {
 
        return devRentService.installOperation(createReqVO);
 
    }
 
 
 
    @RequireBedOwner("拆机")
 
    @PostMapping("/dev-dismantle")
 
    @Operation(summary = "拆机")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> devDismantle(@Valid @RequestBody DevRentSaveReqVO createReqVO) {
 
        devRentService.dismantleOperation(createReqVO);
 
        return CommonResult.success(0L);
 
    }
 
 
 
    @RequireBedOwner("数据录入")
 
    @PostMapping("/dev-data-entry")
 
    @Operation(summary = "数据录入")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> devDataEntry(@Valid @RequestBody DevRentSaveReqVO createReqVO) {
 
        devRentService.dataEntryOperation(createReqVO);
 
        return CommonResult.success(0L);
 
    }
 
 
 
    @PostMapping("/routine-check-cancel")
 
    @Operation(summary = "取消常规检查")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> routineCheckCancel(@Valid @RequestBody DevCancelReqVO cancelReqVO) {
 
        // 【主/围观】该接口没有 roomId/bedNo,按「患者 + 检查项目」反查其所在工位再校验主人身份
        roomService.assertBedOwnerByPatient(cancelReqVO.getPatId(), cancelReqVO.getCheckType());
 
        return devRentService.cancelRoutineOperation(cancelReqVO);
 
    }
 
 
 
    @PostMapping("/dev-ready-cancel")
 
    @Operation(summary = "取消领用")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> devReadyCancel(@Valid @RequestBody DevCancelReqVO cancelReqVO) {
 
        // 【主/围观】按「患者 + 检查项目」反查工位再校验主人身份
        roomService.assertBedOwnerByPatient(cancelReqVO.getPatId(), cancelReqVO.getCheckType());
 
        return devRentService.cancelReadyOperation(cancelReqVO);
 
    }
 
 
 
    @PostMapping("/dev-install-cancel")
 
    @Operation(summary = "取消装机")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> devInstallCancel(@Valid @RequestBody DevCancelReqVO cancelReqVO) {
 
        // 【主/围观】按「患者 + 检查项目」反查工位再校验主人身份
        roomService.assertBedOwnerByPatient(cancelReqVO.getPatId(), cancelReqVO.getCheckType());
 
        return devRentService.cancelInstallOperation(cancelReqVO);
 
    }
 
 
 
    @RequireBedOwner("设备遗失")
 
    @PostMapping("/dev-lose")
 
    @Operation(summary = "遗失")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> devLose(@Valid @RequestBody DevRentSaveReqVO loseReqVO) {
 
        loseReqVO.setState(DevStateEnum.LOST.getState());
 
        return devRentService.dismantleExceptionOperation(loseReqVO);
 
    }
 
 
 
    @RequireBedOwner("设备损坏")
 
    @PostMapping("/dev-damage")
 
    @Operation(summary = "损坏")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> devDamage(@Valid @RequestBody DevRentSaveReqVO damageReqVO) {
 
        damageReqVO.setState(DevStateEnum.DAMAGED.getState());
 
        return devRentService.dismantleExceptionOperation(damageReqVO);
 
    }
 
 
 
    @PostMapping("/create")
 
    @Operation(summary = "创建装机拆机")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Long> createDevRent(@Valid @RequestBody DevRentSaveReqVO createReqVO) {
 
        return CommonResult.success(devRentService.createDevRent(createReqVO));
 
    }
 
 
 
    @PutMapping("/update")
 
    @Operation(summary = "更新装机拆机")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Boolean> updateDevRent(@Valid @RequestBody DevRentSaveReqVO updateReqVO) {
 
        devRentService.updateDevRent(updateReqVO);
 
        return CommonResult.success(true);
 
    }
 
 
 
    @DeleteMapping("/delete")
 
    @Operation(summary = "删除装机拆机")
 
    @Parameter(name = "id", description = "编号", required = true)
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Boolean> deleteDevRent(@RequestParam("id") Long id) {
 
        devRentService.deleteDevRent(id);
 
        return CommonResult.success(true);
 
    }
 
 
 
    @GetMapping("/get")
 
    @Operation(summary = "获得装机拆机")
 
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<DevRentRespVO> getDevRent(@RequestParam("id") Long id) {
 
        DevRentDO devRent = devRentService.getDevRent(id);
 
 
 
        DevRentRespVO devRentRespVO = BeanUtils.toBean(devRent, DevRentRespVO.class);
 
 
 
        DeviceDO deviceDO = deviceService.getDevice(devRent.getDevId());
 
        if (null != deviceDO) {
 
            devRentRespVO.setCategory(deviceDO.getCategory());
 
            devRentRespVO.setBrand(deviceDO.getBrand());
 
            devRentRespVO.setModel(deviceDO.getModel());
 
            devRentRespVO.setDevState(deviceDO.getState());
 
        }
 
        return CommonResult.success(devRentRespVO);
 
    }
 
 
 
    @GetMapping("/page")
 
    @Operation(summary = "获得装机拆机分页")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<PageResult<DevRentRespVO>> getDevRentPage(@Valid DevRentPageReqVO pageReqVO) {
 
        PageResult<DevRentDO> pageResult = devRentService.getDevRentPage(pageReqVO);
 
        return CommonResult.success(BeanUtils.toBean(pageResult, DevRentRespVO.class));
 
    }
 
 
 
    @GetMapping("/export-excel")
 
    @Operation(summary = "导出装机拆机 Excel")
 
    @PreAuthorize("@ss.hasPermission('ecg:dev-rent:export')")
 
    @ApiAccessLog(operateType = EXPORT)
 
    public void exportDevRentExcel(@Valid DevRentPageReqVO pageReqVO, HttpServletResponse response) throws IOException {
 
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
 
        List<DevRentDO> list = devRentService.getDevRentPage(pageReqVO).getList();
 
        // 导出 Excel
 
        ExcelUtils.write(response, "装机拆机.xls", "数据", DevRentRespVO.class, BeanUtils.toBean(list, DevRentRespVO.class));
 
    }
 
 
 
    @GetMapping("/get-free-rent")
 
    @Operation(summary = "根据患者或设备, 获取已领取租赁情况")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<DevRentRespVO> getFreeRent(@Valid DevRentSearchReqVO searchReqVO) {
 
        DevRentDO devRent = devRentService.getFreeRent(searchReqVO);
 
        if (null == devRent) {
 
            return CommonResult.success(null);
 
        }
 
 
 
        DevRentRespVO devRentRespVO = BeanUtils.toBean(devRent, DevRentRespVO.class);
 
        return CommonResult.success(devRentRespVO);
 
    }
 
 
 
    @GetMapping("/get-ready-rent")
 
    @Operation(summary = "获取已领取租赁情况")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<DevRentRespVO> getReadyRent(@Valid DevRentSearchReqVO searchReqVO) {
 
        DevRentDO devRent = devRentService.getReadyOrCancelledRent(searchReqVO);
 
        if (null == devRent) {
 
            return CommonResult.success(null);
 
        }
 
 
 
        DevRentRespVO devRentRespVO = BeanUtils.toBean(devRent, DevRentRespVO.class);
 
 
 
        DeviceDO deviceDO = deviceService.getDevice(devRent.getDevId());
 
        if (null != deviceDO) {
 
            devRentRespVO.setCategory(deviceDO.getCategory());
 
            devRentRespVO.setBrand(deviceDO.getBrand());
 
            devRentRespVO.setModel(deviceDO.getModel());
 
            devRentRespVO.setDevState(deviceDO.getState());
 
        }
 
        return CommonResult.success(devRentRespVO);
 
    }
 
 
 
    @GetMapping("/get-existing-rent")
 
    @Operation(summary = "获取已安装、已领用的租赁情况")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<DevRentRespVO> getInstalledRent(@Valid DevRentSearchReqVO searchReqVO) {
 
        DevRentDO devRent = devRentService.getExistingRent(searchReqVO);
 
        if (null == devRent) {
 
            return CommonResult.success(null);
 
        }
 
 
 
        DeviceDO deviceDO = deviceService.getDevice(devRent.getDevId());
 
 
 
        DevRentRespVO devRentRespVO = BeanUtils.toBean(devRent, DevRentRespVO.class);
 
        devRentRespVO.setCategory(deviceDO.getCategory());
 
        devRentRespVO.setBrand(deviceDO.getBrand());
 
        devRentRespVO.setModel(deviceDO.getModel());
 
        devRentRespVO.setDevState(devRent.getState());
 
        return CommonResult.success(devRentRespVO);
 
    }
 
 
 
    @GetMapping("/get-dismantled-rent")
 
    @Operation(summary = "获取已拆卸租赁情况")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<DevRentRespVO> getDismantledRent(@Valid DevRentSearchReqVO searchReqVO) {
 
        DevRentDO devRent = devRentService.getDismantledRent(searchReqVO);
 
        if (null == devRent) {
 
            return CommonResult.success(null);
 
        }
 
 
 
        DeviceDO deviceDO = deviceService.getDevice(devRent.getDevId());
 
 
 
        DevRentRespVO devRentRespVO = BeanUtils.toBean(devRent, DevRentRespVO.class);
 
        devRentRespVO.setCategory(deviceDO.getCategory());
 
        devRentRespVO.setBrand(deviceDO.getBrand());
 
        devRentRespVO.setModel(deviceDO.getModel());
 
        return CommonResult.success(devRentRespVO);
 
    }
 
 
 
    // 确费
 
    @GetMapping("/fee-confirm")
 
    @Operation(summary = "确费")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Integer> feeConfirm(@Valid Long rentId) {
 
        Long userId = SecurityFrameworkUtils.getLoginUserId();
 
        String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
 
        String userHisId = SecurityFrameworkUtils.getLoginUserHisId();
 
 
 
        // 【主/围观】确费也要拦围观人:按该租赁单的患者反查其当前工位并校验主人身份。
        // 用 Soft 版本:确费常在流程末端调用,患者可能已不在队列上,查不到工位时只记警告放行。
        assertRentBedOwnerSoft(rentId);
 
        Integer result = devRentService.feeConfirm(rentId, userHisId, userNickname, true);
 
        if (1 == result) return CommonResult.error(result, "确费失败");
 
 
 
        return CommonResult.success(result);
 
    }
 
 
 
    // 取消确费
 
    @GetMapping("/fee-cancel")
 
    @Operation(summary = "取消确费")
 
    @PreAuthorize("@ss.hasPermission('ecg:doctor:task')")
 
    public CommonResult<Integer> feeCancel(@Valid Long rentId) {
 
        Long userId = SecurityFrameworkUtils.getLoginUserId();
 
        String userNickname = SecurityFrameworkUtils.getLoginUserNickname();
 
        String userHisId = SecurityFrameworkUtils.getLoginUserHisId();
 
 
 
        // 【主/围观】取消确费同样要拦围观人(Soft:查不到工位只记警告)
        assertRentBedOwnerSoft(rentId);
 
        Integer result = devRentService.feeConfirm(rentId, userHisId, userNickname, false);
 
        if (1 == result) return CommonResult.error(result, "取消确费失败");
 
 
 
        return CommonResult.success(result);
 
    }
 
    /**
     * 【主/围观】确费 / 取消确费的主人校验。
     *
     * <p>接口只带 rentId,拿不到 roomId/bedNo,因此先按租赁单找到患者,
     * 再由 {@link cn.lihu.jh.module.ecg.service.room.RoomService#assertBedOwnerByPatientSoft}
     * 按患者当前所在工位校验主人身份(查不到工位时只记警告放行,避免误伤末端流程)。
     *
     * <p>注意:只包住"读租赁单"这一步,**不能**把主人校验的异常也吞掉,否则等于没有校验。
     */
    private void assertRentBedOwnerSoft(Long rentId) {
        cn.lihu.jh.module.ecg.dal.dataobject.devrent.DevRentDO rent;
        try {
            rent = devRentService.getDevRent(rentId);
        } catch (Exception e) {
            log.error("[assertRentBedOwnerSoft] 读取租赁单失败,跳过主人校验. rentId={}", rentId, e);
            return;
        }
        roomService.assertBedOwnerByPatientSoft(null == rent ? null : rent.getPatId(),
                null == rent ? null : rent.getCheckType());
    }
 
}