bug
luoyisheng
2025-02-12 61313c5dc05cf7d8be02d3e7cc8a3c89d1774b06
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
package com.sinata.web.controller.applet;
import java.util.Date;
import java.math.BigDecimal;
import java.util.*;
 
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson2.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.sinata.common.core.domain.R;
import com.sinata.common.core.domain.entity.SysDictData;
import com.sinata.common.core.domain.entity.SysUser;
import com.sinata.common.entity.PageDTO;
import com.sinata.common.utils.DateUtils;
import com.sinata.common.utils.SecurityUtils;
import com.sinata.common.utils.StringUtils;
import com.sinata.system.domain.*;
import com.sinata.system.domain.dto.*;
import com.sinata.system.domain.query.MwCollectRecordQuery;
import com.sinata.system.domain.vo.MedicalWasteProcessVO;
import com.sinata.system.domain.vo.MwCollectRecordVO;
import com.sinata.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.time.LocalDate;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 暂存间入库记录 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2024-12-02
 */
@Validated
@RestController
@Api(tags = {"医院工作人员"})
@RequiredArgsConstructor
@RequestMapping("/applet/mwCollectRecord")
 
public class AppMwCollectRecordController {
    private final MwCollectRecordService collectRecordService;
    @Autowired
    private ISysUserService userService;
    private final MwBoxService boxService;
    private final MwCheckoutRecordService checkoutRecordService;
    private final MwCheckoutRecordItemService checkoutRecordItemService;
    private final SysDepartmentService departmentService;
    private final MwDisposalRecordService disposalRecordService;
    private final MwDisposalRecordItemService disposalRecordItemService;
    private final MwDisposalHandleRecordService disposalHandleRecordService;
    private final MwDisposalHandleRecordItemService disposalHandleRecordItemService;
    private final MwStagingRoomService roomService;
    private final ISysDictDataService dictDataService;
    private final MwTransitCarService carService;
    private final MwTransitCarCollectPointService mwTransitCarCollectPointService;
    private final MwTransitRouteService transitRouteService;
 
 
    @ApiOperation(value = "新增医废记录")
    @PostMapping("/add")
    public R<?> add(@Valid @RequestBody MwCollectRecord mwCollectRecord) {
        SysUser  sysUser1 = SecurityUtils.getLoginUser().getUser();
        SysUser  sysUser = userService.getById(sysUser1.getUserId());
 
        MwBox one = boxService.lambdaQuery().eq(MwBox::getBoxNumber, mwCollectRecord.getBoxNumber()).one();
        if (one==null){
            return R.fail("当前转运箱不存在");
        }
        one.setLink(1);
        one.setLastUseTime(new Date());
        boxService.updateById(one);
        mwCollectRecord.setBoxId(one.getId());
        MwStagingRoom one1 = roomService.lambdaQuery().eq(MwStagingRoom::getDepartmentId, sysUser.getDepartmentId()).one();
        if (one1==null){
            return R.fail("当前单位没有暂存间");
        }
        mwCollectRecord.setStagingRoomId(one1.getId());
        mwCollectRecord.setDepartmentId(sysUser.getDepartmentId());
        mwCollectRecord.setBoxTime(new Date());
        mwCollectRecord.setCollectUserId(sysUser.getUserId());
 
        // 创建一个随机数生成器实例
        Random random = new Random();
 
        // 生成一个6位数范围内的随机整数(100000 到 999999)
        int randomNumber = 10000000 + random.nextInt(90000000);
        mwCollectRecord.setMedicalWasteNumber(String.valueOf(randomNumber));
 
        SysDictData medicalWasteType = dictDataService.getById(mwCollectRecord.getWasteType());
        if (medicalWasteType!=null){
            mwCollectRecord.setWasteTypeStr(medicalWasteType.getDictLabel());
        }
        collectRecordService.save(mwCollectRecord);
        return R.ok();
    }
 
    @ApiOperation(value = "扫描箱号获取医废",tags = "运输人员")
    @PostMapping("/box/list")
    public R<List<CollectDto>> boxlist(@RequestParam String boxNumber) {
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStatus,1).eq(MwCollectRecord::getBoxNumber, boxNumber).list();
        if (list.isEmpty()){
            return R.ok();
        }
        Long departmentId = list.get(0).getDepartmentId();
        List<CollectDto> collectDtos =  collectRecordService.getGroup1(boxNumber,departmentId);
        for (CollectDto collectDto : collectDtos) {
            collectDto.setDepartmentName(departmentService.getById(departmentId).getDepartmentName());
        }
        return R.ok(collectDtos);
    }
 
    @ApiOperation(value = "装车",tags = "运输人员")
    @PostMapping("/box/collect")
    public R<List<CollectDto>> collect(@RequestBody SignCollectDto signCollectDto) {
        SysUser  sysUser1 = SecurityUtils.getLoginUser().getUser();
        SysUser sysUser = userService.getById(sysUser1.getUserId());
        //将收集记录的状态改变
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStatus,1).in(MwCollectRecord::getBoxNumber, signCollectDto.getBoxNumbers()).list();
       if (list.isEmpty()){
           return R.ok();
       }
        Set<String> boxes = new HashSet<>();
        BigDecimal sum = new BigDecimal(0);
        for (MwCollectRecord mwCollectRecord : list) {
            mwCollectRecord.setStatus(2);
            mwCollectRecord.setCheckoutUserId(sysUser.getUserId());
            mwCollectRecord.setCheckoutTime(new Date());
            mwCollectRecord.setDriverId(sysUser.getUserId());
            mwCollectRecord.setCarId(sysUser.getCarId());
            boxes.add(mwCollectRecord.getBoxNumber());
            sum= sum.add(mwCollectRecord.getWeight());
        }
        //插入入库记录以及中间表数据
        MwCheckoutRecord mwCheckoutRecord = new MwCheckoutRecord();
        mwCheckoutRecord.setCheckoutTime(new Date());
        mwCheckoutRecord.setDepartmentId(list.get(0).getDepartmentId());
        mwCheckoutRecord.setHospitalName(list.get(0).getHospitalName());
        mwCheckoutRecord.setStagingRoomId(list.get(0).getStagingRoomId());
        mwCheckoutRecord.setHospitalSignature(signCollectDto.getSignUrl());
        mwCheckoutRecord.setDriverId(sysUser.getUserId());
        mwCheckoutRecord.setCarId(sysUser.getCarId());
        mwCheckoutRecord.setBoxNum(boxes.size());
        mwCheckoutRecord.setBagNum(list.size());
        mwCheckoutRecord.setTotalWeight(sum);
        checkoutRecordService.save(mwCheckoutRecord);
        //插入中间表数据
        List<MwCheckoutRecordItem> recordItems = new ArrayList<>();
        for (MwCollectRecord mwCollectRecord : list) {
            MwCheckoutRecordItem mwCheckoutRecordItem = new MwCheckoutRecordItem();
            mwCheckoutRecordItem.setCollectRecordId(mwCollectRecord.getId());
            mwCheckoutRecordItem.setCheckoutRecordId(mwCheckoutRecord.getId());
            recordItems.add(mwCheckoutRecordItem);
        }
        checkoutRecordItemService.saveBatch(recordItems);
        collectRecordService.updateBatchById(list);
        MwBox byId = boxService.getById(list.get(0).getStagingRoomId());
        byId.setLink(2);
        boxService.updateById(byId);
 
        //查询当前医废收集路线
        Long departmentId = list.get(0).getDepartmentId();
        MwTransitRoute route = transitRouteService.queryRouteByDepartmentId(departmentId);
        if (Objects.nonNull(route)){
            //查询当前车辆已运输路线记录
            MwTransitCarCollectPoint carCollectPoint = mwTransitCarCollectPointService.lambdaQuery().eq(MwTransitCarCollectPoint::getCarId, sysUser.getCarId())
                    .eq(MwTransitCarCollectPoint::getRouteId, route.getId())
                    .eq(MwTransitCarCollectPoint::getTransitDate, DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN))
                    .last("LIMIT 1").one();
            List<Long> departmentIdList = new ArrayList<>();
            //如果当前收集医院不是第一家且当前收集医院未被记录
            if (Objects.nonNull(carCollectPoint) && !carCollectPoint.getPointList().contains(departmentId.toString())){
                departmentIdList = JSONArray.parseArray(carCollectPoint.getPointList(), Long.class);
                departmentIdList.add(departmentId);
            }else if (Objects.isNull(carCollectPoint) ){//当前医院为第一个收集的医院
                carCollectPoint = new MwTransitCarCollectPoint();
                carCollectPoint.setCarId(carCollectPoint.getCarId());
                carCollectPoint.setRouteId(route.getId());
                carCollectPoint.setTransitDate(new Date());
                departmentIdList.add(departmentId);
            }
            carCollectPoint.setPointList(JSONArray.toJSONString(departmentIdList));
            mwTransitCarCollectPointService.saveOrUpdate(carCollectPoint);
        }
 
        return R.ok();
 
    }
 
    @ApiOperation(value = "运输统计上",tags = "运输人员")
    @PostMapping("/trans/collect/total")
    public R<List<CollectTotalUpDto>> tanscollecttotal1(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        return R.ok(collectRecordService.collectTotal1(date,sysUser.getUserId(),null));
    }
 
    @ApiOperation(value = "运输统计上(医院数量)",tags = "运输人员")
    @PostMapping("/trans/collect/hospital/count")
    public R<Long> tanscollecttotal12(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        Long count = collectRecordService.lambdaQuery().eq(date!=null,MwCollectRecord::getCheckoutTime,date).eq(MwCollectRecord::getCheckoutUserId, sysUser.getUserId()).groupBy(MwCollectRecord::getDepartmentId).count();
        return R.ok(count);
    }
 
    @ApiOperation(value = "运输统计下",tags = "运输人员")
    @PostMapping("/trans/down/collect/total")
    public R<List<HospitalCollectTotalUpDto>> tanscollecttotal2(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        //先获取医院ids
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(date!=null,MwCollectRecord::getCheckoutTime,date).eq(MwCollectRecord::getCheckoutUserId, sysUser.getUserId()).groupBy(MwCollectRecord::getDepartmentId).list();
        //循环医院,然后放入
        List<HospitalCollectTotalUpDto> list1 = new ArrayList<>();
        for (MwCollectRecord mwCollectRecord : list) {
            List<CollectTotalUpDto> collectTotalUpDtos = collectRecordService.collectTotal1(date, sysUser.getUserId(), mwCollectRecord.getDepartmentId());
            HospitalCollectTotalUpDto hospitalCollectTotalUpDto = new HospitalCollectTotalUpDto();
            hospitalCollectTotalUpDto.setHospitalName(mwCollectRecord.getHospitalName());
            hospitalCollectTotalUpDto.setCollectTotalUpDtos(collectTotalUpDtos);
            list1.add(hospitalCollectTotalUpDto);
        }
        return R.ok(list1);
    }
 
    @ApiOperation(value = "扫码接收列表",tags = "处置人员")
    @PostMapping("/end/down/collect/total")
    public R<List<HospitalCollectTotalUp1Dto>> tanscollecttotal3(String boxNum) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        MwCollectRecord one = collectRecordService.lambdaQuery().eq(MwCollectRecord::getBoxNumber, boxNum).eq(MwCollectRecord::getStatus, 2).last("limit 1").one();
        if (one==null){
            return R.ok();
        }
        //先获取医院ids
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStatus,2).eq(MwCollectRecord::getCheckoutUserId, one.getCheckoutUserId()).groupBy(MwCollectRecord::getDepartmentId).list();
        //循环医院,然后放入
        List<HospitalCollectTotalUp1Dto> list1 = new ArrayList<>();
        for (MwCollectRecord mwCollectRecord : list) {
            List<CollectDto> collectTotalUpDtos = collectRecordService.getGroup2(null, mwCollectRecord.getDepartmentId());
            HospitalCollectTotalUp1Dto hospitalCollectTotalUpDto = new HospitalCollectTotalUp1Dto();
            hospitalCollectTotalUpDto.setHospitalName(mwCollectRecord.getHospitalName());
            hospitalCollectTotalUpDto.setCollectTotalUpDtos(collectTotalUpDtos);
            list1.add(hospitalCollectTotalUpDto);
        }
        return R.ok(list1);
    }
 
    @ApiOperation(value = "获取车辆",tags = "处置人员")
    @PostMapping("/end/down/collect/car")
    public R<CarDto> tanscollecttotal7(String boxNum) {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        MwCollectRecord one = collectRecordService.lambdaQuery().eq(MwCollectRecord::getBoxNumber, boxNum).eq(MwCollectRecord::getStatus, 2).last("limit 1").one();
        if (one == null) {
            return R.ok();
        }
        MwTransitCar byId = carService.getById(one.getCarId());
        SysUser one1 = userService.lambdaQuery().eq(SysUser::getCarId, byId.getId()).one();
        CarDto carDto = new CarDto();
        carDto.setLicensePlateNumber(byId.getLicensePlateNumber());
        carDto.setUserName(one1.getUserName());
        return R.ok(carDto);
    }
 
 
    @ApiOperation(value = "扫码接收列表上获取医院",tags = "处置人员")
    @PostMapping("/end/down/collect/up")
    public R<SysDepartment> tanscollecttotal4(String boxNum) {
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        MwCollectRecord one = collectRecordService.lambdaQuery().eq(MwCollectRecord::getBoxNumber, boxNum).eq(MwCollectRecord::getStatus, 2).last("limit 1").one();
        if (one == null) {
            return R.ok();
        }
        SysDepartment byId = departmentService.getById(one.getDepartmentId());
        return R.ok(byId);
    }
 
    @ApiOperation(value = "确认接受",tags = "处置人员")
    @PostMapping("/end/down/collect/confirm")
    public R tanscollecttotal4(@RequestBody BoxListDto boxListDto) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysDepartment byId = departmentService.getById(sysUser.getDepartmentId());
        //将record变为已接受
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStatus,2).in(MwCollectRecord::getBoxNumber, boxListDto.getBoxNum()).list();
      if (list.isEmpty()){
          return R.ok();
      }
 
        Set<String> boxes = new HashSet<>();
        BigDecimal receiveQuantity = BigDecimal.ZERO;
        for (MwCollectRecord mwCollectRecord : list) {
            mwCollectRecord.setStatus(3);
            boxes.add(mwCollectRecord.getBoxNumber());
            mwCollectRecord.setReceiveUserId(sysUser.getUserId());
            mwCollectRecord.setReceiveTime(new Date());
            mwCollectRecord.setReceiveDepartmentId(sysUser.getDepartmentId());
            receiveQuantity = receiveQuantity.add(mwCollectRecord.getWeight());
        }
        collectRecordService.updateBatchById(list);
        //插入接收记录以及子表
        MwDisposalRecord mwDisposalRecord = new MwDisposalRecord();
        mwDisposalRecord.setDepartmentId(sysUser.getDepartmentId());
        mwDisposalRecord.setDisposalUnitName(byId.getDepartmentName());
        mwDisposalRecord.setReceiveQuantity(boxes.size());
        mwDisposalRecord.setReceiveTime(new Date());
        mwDisposalRecord.setReceiveWeight(receiveQuantity);
        mwDisposalRecord.setReceiverId(sysUser.getUserId());
        mwDisposalRecord.setUnloadQuantity(boxes.size());
        mwDisposalRecord.setUnloadWeight(receiveQuantity);
        mwDisposalRecord.setTotalHandledQuantity(list.size());
        mwDisposalRecord.setDisposalFlag(0);
        mwDisposalRecord.setTotalHandledWeight(receiveQuantity);
        mwDisposalRecord.setDriverId(list.get(0).getDriverId());
        mwDisposalRecord.setCarId(list.get(0).getCarId());
        disposalRecordService.save(mwDisposalRecord);
        //插入子表
        List<MwDisposalRecordItem> items = new ArrayList<>();
        for (MwCollectRecord mwCollectRecord : list) {
            MwDisposalRecordItem mwDisposalRecordItem = new MwDisposalRecordItem();
            mwDisposalRecordItem.setCollectRecordId(mwCollectRecord.getId());
            mwDisposalRecordItem.setDisposalRecordId(mwDisposalRecord.getId());
            items.add(mwDisposalRecordItem);
        }
        disposalRecordItemService.saveBatch(items);
        MwTransitRoute route = transitRouteService.queryRouteByDepartmentId(list.get(0).getDepartmentId());
        if (Objects.nonNull(route)) {
            //查询当前车辆已运输路线记录
            MwTransitCarCollectPoint carCollectPoint = mwTransitCarCollectPointService.lambdaQuery().eq(MwTransitCarCollectPoint::getCarId, sysUser.getCarId())
                    .eq(MwTransitCarCollectPoint::getRouteId, route.getId())
                    .eq(MwTransitCarCollectPoint::getTransitDate, DateUtil.format(new Date(), DatePattern.NORM_DATE_PATTERN))
                    .last("LIMIT 1").one();
            List<Long> departmentIdList = new ArrayList<>();
            if (Objects.nonNull(carCollectPoint)) {
                departmentIdList = JSONArray.parseArray(carCollectPoint.getPointList(), Long.class);
                departmentIdList.add(byId.getId());
                carCollectPoint.setPointList(JSONArray.toJSONString(departmentIdList));
                mwTransitCarCollectPointService.updateById(carCollectPoint);
            }
        }
        return R.ok();
    }
 
    @ApiOperation(value = "待处置列表",tags = "处置人员")
    @PostMapping("/wait/list")
    public R<List<CollectDto>> list1(String boxNumber) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysUser byId = userService.getById(sysUser.getUserId());
        List<CollectDto> collectDtos =  collectRecordService.getGroupWithStatus(boxNumber,byId.getDepartmentId(),3);
        return R.ok(collectDtos);
    }
    @ApiOperation(value = "处置操作",tags = "处置人员")
    @PostMapping("/wait/out")
    public R<List<CollectDto>> list2(@RequestBody BoxListDto boxListDto) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysDepartment byId = departmentService.getById(sysUser.getDepartmentId());
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getStatus, 3).in(MwCollectRecord::getBoxNumber, boxListDto.getBoxNum()).list();
        if (list.isEmpty()){
            return R.ok();
        }
        //新增处置记录
        MwDisposalHandleRecord mwDisposalHandleRecord  = new MwDisposalHandleRecord();
        mwDisposalHandleRecord.setDepartmentId(byId.getId());
        mwDisposalHandleRecord.setDisposalUnitName(byId.getDepartmentName());
        mwDisposalHandleRecord.setDisposalTime(new Date());
        mwDisposalHandleRecord.setDisposalUserId(sysUser.getUserId());
        mwDisposalHandleRecord.setDriverId(list.get(0).getDriverId());
        mwDisposalHandleRecord.setCarId(list.get(0).getCarId());
        disposalHandleRecordService.save(mwDisposalHandleRecord);
        List<Long> collectIdList = list.stream().map(MwCollectRecord::getId).collect(Collectors.toList());
        //查询收集记录对应的接收记录
        List<MwDisposalRecordItem> disposalRecordItems = disposalRecordItemService.lambdaQuery().in(MwDisposalRecordItem::getCollectRecordId, collectIdList).list();
        Map<Long, Long> disposalRecordItemMap = disposalRecordItems.stream().collect(Collectors.toMap(MwDisposalRecordItem::getCollectRecordId, MwDisposalRecordItem::getDisposalRecordId));
 
        //将收集记录以及子表改变为已处置
        if (!list.isEmpty()) {
            List<Long> ids = new ArrayList<>();
            List<MwDisposalHandleRecordItem> mwDisposalHandleRecordItems = new ArrayList<>();
            for (MwCollectRecord mwCollectRecord : list) {
                ids.add(mwCollectRecord.getId());
                mwCollectRecord.setStatus(4);
                mwCollectRecord.setDisposalUserId(sysUser.getUserId());
                mwCollectRecord.setDisposalTime(new Date());
                MwDisposalHandleRecordItem mwDisposalHandleRecordItem = new MwDisposalHandleRecordItem();
                mwDisposalHandleRecordItem.setCollectRecordId(mwCollectRecord.getId());
                mwDisposalHandleRecordItem.setDisposalHandleRecordId(mwDisposalHandleRecord.getId());
                mwDisposalHandleRecordItem.setDisposalRecordId(disposalRecordItemMap.getOrDefault(mwCollectRecord.getId(), null));
                mwDisposalHandleRecordItems.add(mwDisposalHandleRecordItem);
            }
            disposalHandleRecordItemService.saveBatch(mwDisposalHandleRecordItems);
            collectRecordService.updateBatchById(list);
        }
//            //将接收记录以及子表变为已处置
//            List<MwDisposalRecordItem> list1 = disposalRecordItemService.lambdaQuery().in(MwDisposalRecordItem::getCollectRecordId, ids).list();
//            if (!list1.isEmpty()){
//                List<Long> ids2 = new ArrayList<>();
//                for (MwDisposalRecordItem mwDisposalRecordItem : list1) {
//                    mwDisposalRecordItem.setDisposalFlag(1);
//                    mwDisposalRecordItem.setDisposalUserId(sysUser.getUserId());
//                    mwDisposalRecordItem.setDisposalTime(new Date());
//                    ids2.add(mwDisposalRecordItem.getId());
//                }
//                disposalRecordItemService.updateBatchById(list1);
//                List<MwDisposalRecord> list2 = disposalRecordService.lambdaQuery().in(MwDisposalRecord::getId, ids2).list();
//                for (MwDisposalRecord mwDisposalRecord : list2) {
//                    mwDisposalRecord.setDisposalFlag(1);
//                    mwDisposalRecord.setDisposalTime(new Date());
//                    mwDisposalRecord.setDisposalUserId(sysUser.getUserId());
//                }
//                disposalRecordService.updateBatchById(list2);
//            }
//        }
//        MwBox byId1 = boxService.getById(list.get(0).getStagingRoomId());
//        byId1.setLink(4);
//        boxService.updateById(byId1);
        return R.ok();
    }
 
 
 
 
    @ApiOperation(value = "已装车列表",tags = "运输人员")
    @PostMapping("/box/has/collect")
    public R<List<CollectCarTotalUpDto>> hascollect(String name) {
        //获取车辆id
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysUser byId = userService.getById(sysUser.getUserId());
        //通过车辆id查询列表
        List<CollectCarTotalUpDto> list = collectRecordService.carGroup(byId.getCarId(),name);
        return R.ok(list);
    }
 
    @ApiOperation(value = "已装车列表详情",tags = "运输人员")
    @PostMapping("/box/has/collect/detail")
    public R<List<CollectDto>> hascollectdetail(@RequestParam Long hospitalId) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysUser byId = userService.getById(sysUser.getUserId());
        List<CollectDto> collectDtos =  collectRecordService.getGroup3(null,hospitalId,byId.getCarId());
        return R.ok(collectDtos);
    }
 
    @ApiOperation("库存信息")
    @PostMapping("/list")
    public R<List<CollectDto>> list(String boxNumber) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        List<CollectDto> collectDtos =  collectRecordService.getGroup(boxNumber,sysUser.getDepartmentId());
        return R.ok(collectDtos);
    }
    @ApiOperation("收集详情")
    @PostMapping("/record")
    public R<List<MwCollectRecord>> record(@RequestParam String boxNumber) {
        List<MwCollectRecord> list = collectRecordService.lambdaQuery().eq(MwCollectRecord::getBoxNumber, boxNumber).orderByDesc(MwCollectRecord::getCollectTime).list();
        return R.ok(list);
    }
 
    @ApiOperation("收集统计上")
    @PostMapping("/collect/total")
    public R<List<CollectTotalUpDto>> collecttotal1(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysUser byId = userService.getById(sysUser.getUserId());
        if (date==null){
            date = LocalDate.now();
        }
        return R.ok(collectRecordService.collectTotal(date,byId.getDepartmentId()));
    }
    @ApiOperation("收集统计下")
    @PostMapping("/collect/down/total")
    public R<Page<MwCollectRecord>> collecttotal2(@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)LocalDate date,@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysUser byId = userService.getById(sysUser.getUserId());
        Page<MwCollectRecord> page = collectRecordService.lambdaQuery()
                .ge(MwCollectRecord::getCreateTime, date.atStartOfDay())
                .le(MwCollectRecord::getCreateTime, date.atTime(23,59,59))
            .eq(MwCollectRecord::getDepartmentId, byId.getDepartmentId())
            .orderByDesc(MwCollectRecord::getCollectTime)
            .page(Page.of(pageNum, pageSize));
        return R.ok(page);
    }
 
 
    @ApiOperation("库存信息底部统计")
    @PostMapping("/total")
    public R<CollectTotalDto> total(String boxNumber) {
        SysUser  sysUser = SecurityUtils.getLoginUser().getUser();
        SysUser byId = userService.getById(sysUser.getUserId());
        CollectTotalDto collectTotalDto = new CollectTotalDto();
        List<CollectDto> collectDtos =  collectRecordService.getGroup(boxNumber,byId.getDepartmentId());
        for (CollectDto collectDto : collectDtos) {
            collectTotalDto.setBoxNum(collectTotalDto.getBoxNum()+1);
            collectTotalDto.setCarNum(collectTotalDto.getCarNum()+collectDto.getNum());
            collectTotalDto.setWeight(collectTotalDto.getWeight().add(collectDto.getWeight()));
        }
        return R.ok(collectTotalDto);
    }
 
}