无关风月
1 天以前 b2e3d6532dbbb3929e01a598dcef7eb07f39b826
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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
package com.ruoyi.web.controller.api;
 
 
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.BaseModel;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.applet.dto.*;
import com.ruoyi.system.applet.query.*;
import com.ruoyi.system.applet.vo.*;
import com.ruoyi.system.dto.KnowledgeDTO;
import com.ruoyi.system.dto.TTaskAuditBatchDTO;
import com.ruoyi.system.dto.TTaskAuditDTO;
import com.ruoyi.system.dto.TTaskDTO;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.InsepectorListQuery;
import com.ruoyi.system.query.KnowledgeListQuery;
import com.ruoyi.system.query.TaskListQuery;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.system.*;
import com.sun.jna.platform.win32.LMAccess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 任务记录 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-05-28
 */
@Api(tags = "个人中心")
@RestController
@RequestMapping("/t-user")
public class TUserController {
    @Resource
    private TTaskCleanService taskCleanerService;
 
    @Resource
    private TTaskDetailService taskDetailService;
 
 
    @Resource
    private TLocationTypeService locationTypeService;
    @Resource
    private TLocationService locationService;
    @Resource
    private TProjectDeptService projectDeptService;
 
    @Resource
    private TTaskDetailService tTaskDetailService;
    @Resource
    private TDeptService deptService;
    @Resource
    private ISysUserService sysUserService;
    @Resource
    private ISysRoleService roleService;
    @Resource
    private TDictDataService dictDataService;
    @Resource
    private TLeaveService leaveService;
    @Resource
    private TLeaveAuditService leaveAuditService;
    @Resource
    private TokenService tokenService;
    @Resource
    private TAppealService appealService;
    @Resource
    private TInspectorService inspectorService;
    @Resource
    private TFeedbackService feedbackService;
    @Resource
    private TProblemEscalationService problemEscalationService;
    @Resource
    private TNoticeService noticeService;
 
    @ApiOperation(value = "消息通知列表")
    @PostMapping(value = "/noticeList")
    public R<PageInfo<NoticeListVO>> noticeList(@RequestBody NoticeListQuery query) {
        Long userId = tokenService.getLoginUserApplet().getUserId();
        query.setUserId(userId + "");
        PageInfo<NoticeListVO> noticeListVOPageInfo = noticeService.noticeList(query);
        List<NoticeListVO> records = noticeListVOPageInfo.getRecords();
        List<NoticeListVO> noticeListVOS = new ArrayList<>(records);
        for (NoticeListVO noticeListVO : noticeListVOS) {
            noticeListVO.setStatus(2);
            noticeService.updateById(noticeListVO);
        }
        return R.ok(noticeListVOPageInfo);
    }
 
    /**
     * 生成数据
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "测试接口不要调")
 
    @GetMapping(value = "/testData")
    public R<AppealDetailVO> testData(@RequestParam String id) {
//        List<TAppeal> tAppeals = new ArrayList<>();
//        for (int i = 0; i < 25; i++) {
//            TAppeal tAppeal = new TAppeal();
//            tAppeal.setTaskId("1938536771253641217");
//            tAppeal.setAppealPerson("152");
//            tAppeal.setStatus(1);
//            tAppeal.setAppealContent("申诉");
//            tAppeal.setPictures("https://bjxj.oss-cn-guangzhou.aliyuncs.com/bjxj/88d2d5614fe6492bba5666a7ab01e76b.png");
//            tAppeals.add(tAppeal);
//        }
//        appealService.saveBatch(tAppeals);
//        List<TAppeal> tAppeals1 = new ArrayList<>();
//        for (int i = 0; i < 25; i++) {
//            TAppeal tAppeal = new TAppeal();
//            tAppeal.setTaskId("1938536771253641217");
//            tAppeal.setAppealPerson("152");
//            tAppeal.setStatus(2);
//            tAppeal.setAppealContent("申诉");
//            tAppeal.setPictures("https://bjxj.oss-cn-guangzhou.aliyuncs.com/bjxj/88d2d5614fe6492bba5666a7ab01e76b.png");
//            tAppeal.setAuditPerson("162");
//            tAppeal.setAuditRemark("备注");
//            tAppeal.setAuditTime(LocalDateTime.now());
//            tAppeals1.add(tAppeal);
//        }
//        appealService.saveBatch(tAppeals1);
//        List<TAppeal> tAppeals2 = new ArrayList<>();
//        for (int i = 0; i < 25; i++) {
//            TAppeal tAppeal = new TAppeal();
//            tAppeal.setTaskId("1938536771253641217");
//            tAppeal.setAppealPerson("152");
//            tAppeal.setStatus(3);
//            tAppeal.setAppealContent("申诉");
//            tAppeal.setPictures("https://bjxj.oss-cn-guangzhou.aliyuncs.com/bjxj/88d2d5614fe6492bba5666a7ab01e76b.png");
//            tAppeal.setAuditPerson("162");
//            tAppeal.setAuditRemark("备注");
//            tAppeal.setAuditTime(LocalDateTime.now());
//            tAppeals2.add(tAppeal);
//        }
//        appealService.saveBatch(tAppeals2);
//        List<TAppeal> tAppeals3 = new ArrayList<>();
//        for (int i = 0; i < 25; i++) {
//            TAppeal tAppeal = new TAppeal();
//            tAppeal.setTaskId("1938536771253641217");
//            tAppeal.setAppealPerson("152");
//            tAppeal.setStatus(4);
//            tAppeal.setAppealContent("申诉");
//            tAppeal.setPictures("https://bjxj.oss-cn-guangzhou.aliyuncs.com/bjxj/88d2d5614fe6492bba5666a7ab01e76b.png");
//
//            tAppeals3.add(tAppeal);
//
//        }
//        appealService.saveBatch(tAppeals3);
        return R.ok();
    }
 
    @ApiOperation(value = "个人中心-首页")
    @PostMapping(value = "/userIndex")
    public R<UserIndexVO> userIndex() {
        UserIndexVO userIndexVO = new UserIndexVO();
        List<SysUser> userAll = sysUserService.selectAllList();
        List<SysUser> users = userAll.stream().filter(e -> e.getUserId() != 1).collect(Collectors.toList());
 
        Long userId = tokenService.getLoginUserApplet().getUserId();
        SysUser sysUser = sysUserService.selectUserById(userId);
        userIndexVO.setAvatar(sysUser.getAvatar());
        userIndexVO.setNickName(sysUser.getNickName());
        userIndexVO.setPhonenumber(sysUser.getPhonenumber());
        if (sysUser.getDeptType() == 1) {
            TProjectDept tProjectDept = projectDeptService.getById(sysUser.getDeptId());
            if (!tProjectDept.getParentId().equals("0")) {
                TProjectDept tProjectDept1 = projectDeptService.getById(tProjectDept.getParentId());
                userIndexVO.setDeptName(tProjectDept1.getProjectName() + ">" + tProjectDept.getProjectName());
            } else {
                userIndexVO.setDeptName(tProjectDept.getProjectName());
            }
        } else {
            TDept tDept = deptService.getById(sysUser.getDeptId());
            if (tDept != null) {
                userIndexVO.setDeptName(tDept.getDeptName());
            }
        }
        // 查询请假状态
        List<TLeave> list = leaveService.lambdaQuery().eq(TLeave::getLeavePerson, userId)
                .eq(TLeave::getAuditStatus, 2)
                .list();
        userIndexVO.setIsLeave(0);
        for (TLeave tLeave : list) {
            LocalDate now = LocalDate.now();
            LocalDate startDate = tLeave.getStartTime().toLocalDate();
            LocalDate endDate = tLeave.getStartTime().toLocalDate();
            if (now.isAfter(startDate) && now.isBefore(endDate)) {
                userIndexVO.setIsLeave(1);
            } else if (now.isEqual(startDate) || now.isEqual(endDate)) {
                userIndexVO.setIsLeave(1);
            }
        }
        // 获取本月第一天凌晨00:00:00 和本月最后一天23:59:59 类型为LocalDateTime
        // 获取当前日期
        LocalDate now = LocalDate.now();
        // 本月第一天
        LocalDate firstDayOfMonth = now.withDayOfMonth(1);
        // 本月最后一天
        LocalDate lastDayOfMonth = now.withDayOfMonth(now.lengthOfMonth());
        // 转换为 LocalDateTime:第一天的 00:00:00
        LocalDateTime startOfMonth = LocalDateTime.of(firstDayOfMonth, LocalTime.MIN);
        // 转换为 LocalDateTime:最后一天的 23:59:59
        LocalDateTime endOfMonth = LocalDateTime.of(lastDayOfMonth, LocalTime.MAX);
        List<TTask> finishTask = taskCleanerService.lambdaQuery().eq(TTask::getPatrolInspector, userId)
                .ge(TTask::getImplementTime, startOfMonth)
                .le(TTask::getImplementTime, endOfMonth).list();
        List<String> taskIds = finishTask.stream().map(TTask::getId).collect(Collectors.toList());
        if (taskIds.isEmpty()){
            taskIds.add("-1");
        }
        List<TTaskDetail> taskDetails = taskDetailService.lambdaQuery()
                .in(TTaskDetail::getTaskId, taskIds)
                .eq(TTaskDetail::getAuditStatus, 1)
 
                .isNotNull(TTaskDetail::getClearStatus)
                .groupBy(TTaskDetail::getTaskId)
                .orderByDesc(TTaskDetail::getCreateTime).list();
 
        int size = (int) finishTask.stream().filter(e -> e.getStatus() == 5 || e.getStatus() == 6).count();
        userIndexVO.setFinishCount(size);
        List<TTaskDetail> status1 = taskDetails.stream().filter(e -> e.getClearStatus() == 1).collect(Collectors.toList());
        List<TTaskDetail> status2 = taskDetails.stream().filter(e -> e.getClearStatus() == 2).collect(Collectors.toList());
        if (!status1.isEmpty()) {
            BigDecimal divide = new BigDecimal(status1.size() + status2.size())
                    .divide(new BigDecimal(status1.size()), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100));
            userIndexVO.setRate(divide);
        } else {
            userIndexVO.setRate(new BigDecimal(0));
        }
 
        // 判断时间
        String startTime = "";
        String endTime = "";
        Map<String, Date> monthDate = DateUtils.getMonthDate(new Date());
        startTime = new SimpleDateFormat("yyyy-MM-dd").format((monthDate.get("first"))) + " 00:00:00";
        endTime = new SimpleDateFormat("yyyy-MM-dd").format((monthDate.get("last"))) + " 23:59:59";
        List<TTask> taskRank = taskCleanerService.lambdaQuery().between(TTask::getImplementTime, startTime, endTime).list();
        List<String> taskIdsRank = taskRank.stream().map(TTask::getId).collect(Collectors.toList());
        if (taskIdsRank.isEmpty()){
            userIndexVO.setRanking(0);
        }else{
            List<TTaskDetail> taskDetailsRank = taskDetailService.lambdaQuery().in(TTaskDetail::getTaskId)
                    .eq(TTaskDetail::getAuditStatus, 1)
                    .isNotNull(TTaskDetail::getClearStatus)
                    .groupBy(TTaskDetail::getTaskId)
                    .orderByDesc(TTaskDetail::getCreateTime).list();
            for (SysUser user : users) {
                int finishCount = (int) taskRank.stream().filter(e->e.getPatrolInspector().equals(user.getUserId()+"")&&e.getStatus() == 5 || e.getStatus() == 6).count();
                int totalCount = (int) taskRank.stream().filter(e->e.getPatrolInspector().equals(user.getUserId()+"")).count();
                if (totalCount!=0){
                    user.setFinish(new BigDecimal(finishCount).divide(new BigDecimal(totalCount),2, RoundingMode.HALF_DOWN));
                }else{
                    user.setFinish(BigDecimal.ZERO);
                }
                List<TTaskDetail> status1User = taskDetails.stream().filter(e -> e.getClearStatus() == 1).collect(Collectors.toList());
                List<TTaskDetail> status2User = taskDetails.stream().filter(e -> e.getClearStatus() == 2).collect(Collectors.toList());
                if (!status1User.isEmpty()) {
                    BigDecimal divide = new BigDecimal(status1User.size() + status2User.size())
                            .divide(new BigDecimal(status1User.size()), 2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100));
                    user.setRate(divide);
                } else {
                    user.setRate(new BigDecimal(0));
                }
            }
            // 将users进行排序,优先根据rate倒叙排序,如果rate相同 再finish倒叙排序
            users.sort((o1, o2) -> {
                if (o1.getRate().compareTo(o2.getRate()) == 0) {
                    return o2.getFinish().compareTo(o1.getFinish());
                } else {
                    return o2.getRate().compareTo(o1.getRate());
                }
            });
            // 查询当前登陆人处于哪一个排名
            for (int i = 0; i < users.size(); i++) {
                if (users.get(i).getUserId().equals(userId)) {
                    userIndexVO.setRanking(i + 1);
                    break;
                }
            }
 
        }
        return R.ok(userIndexVO);
    }
 
    @ApiOperation(value = "任务记录分页列表")
    @PostMapping(value = "/taskList")
    public R<PageInfo<TaskUserListVO>> pageList(@RequestBody TaskUserListQuery query) {
        Long userId = tokenService.getLoginUserApplet().getUserId();
        query.setUserId(userId + "");
        return R.ok(taskCleanerService.pageListUser(query));
    }
 
    @ApiOperation(value = "详情任务")
    @GetMapping(value = "/detail")
    public R<TaskDetailVO> detail(@RequestParam String id) {
        List<TTaskDetail> list = taskDetailService.lambdaQuery().eq(TTaskDetail::getTaskId, id)
                .orderByDesc(BaseModel::getCreateTime).list();
        TaskDetailVO taskDetailVO = new TaskDetailVO();
        TTask byId = taskCleanerService.getById(id);
        BeanUtils.copyProperties(byId, taskDetailVO);
        TLocation byId1 = locationService.getById(byId.getLocationId());
        TLocationType byId2 = locationTypeService.getById(byId1.getLocationType());
        taskDetailVO.setLocationName(byId1.getLocationName());
        taskDetailVO.setLocationAddress(byId1.getLocationAddress());
        taskDetailVO.setLocationAddressEnd(byId1.getLocationAddressEnd());
        taskDetailVO.setLocationIcon(byId2.getLocationIcon());
        taskDetailVO.setLocationTypeName(byId2.getLocationName());
        TTaskDetail tTaskDetail = list.stream().filter(e -> e.getHandleType() == 1).findFirst().orElse(null);
        TTaskDetail tTaskDetailFinish = list.stream().filter(e -> e.getHandleType() == 2).findFirst().orElse(null);
        if (tTaskDetail != null && tTaskDetail.getUnqualified() != null) {
            TDictData byId3 = dictDataService.getById(tTaskDetail.getUnqualified());
            if (byId3 != null) {
                tTaskDetail.setUnqualifiedName(byId3.getDataContent());
            }
        }
        if (tTaskDetailFinish != null) {
            tTaskDetailFinish.setFinishTime(tTaskDetailFinish.getCreateTime());
        }
        taskDetailVO.setTaskDetail(tTaskDetail);
        taskDetailVO.setRecords(list);
        return R.ok(taskDetailVO);
    }
 
    @ApiOperation(value = "详情任务-操作记录-详情")
    @GetMapping(value = "/detailRecord")
    public R<TaskRecordDetailVO> detailRecord(@RequestParam String id) {
        TaskRecordDetailVO taskDetailVO = new TaskRecordDetailVO();
        TTaskDetail byId4 = taskDetailService.getById(id);
        TTask byId = taskCleanerService.getById(byId4.getTaskId());
        BeanUtils.copyProperties(byId, taskDetailVO);
        TLocation byId1 = locationService.getById(byId.getLocationId());
        TLocationType byId2 = locationTypeService.getById(byId1.getLocationType());
        taskDetailVO.setLocationAddress(byId1.getLocationAddress());
        taskDetailVO.setLocationIcon(byId2.getLocationIcon());
        taskDetailVO.setLocationName(byId2.getLocationName());
        if (byId4.getUnqualified() != null) {
            TDictData byId3 = dictDataService.getById(byId4.getUnqualified());
            if (byId3 != null) {
                byId4.setUnqualifiedName(byId3.getDataContent());
            }
        }
        SysUser sysUser = sysUserService.selectUserById(Long.valueOf(byId4.getAuditPerson()));
        if (sysUser != null) {
            byId4.setAuditPersonName(sysUser.getUserName());
        }
        taskDetailVO.setTaskDetail(byId4);
        return R.ok(taskDetailVO);
    }
 
    @ApiOperation(value = "申诉记录分页列表")
    @PostMapping(value = "/appealList")
    public R<PageInfo<AppealListVO>> pageListUser(@RequestBody AppealListQuery query) {
        query.setUserId(tokenService.getLoginUserApplet().getUserId() + "");
        return R.ok(appealService.pageListUser(query));
    }
 
    @ApiOperation(value = "详情申诉记录")
    @GetMapping(value = "/appealDetail")
    public R<AppealDetailVO> appealDetail(@RequestParam String id) {
        AppealDetailVO appealDetailVO = new AppealDetailVO();
        TAppeal appeal = appealService.getById(id);
        BeanUtils.copyProperties(appeal, appealDetailVO);
        TTask byId = taskCleanerService.getById(appeal.getTaskId());
        TLocation byId1 = locationService.getById(byId.getLocationId());
        TLocationType byId2 = locationTypeService.getById(byId1.getLocationType());
        appealDetailVO.setLocationAddress(byId1.getLocationAddress());
        appealDetailVO.setLocationIcon(byId2.getLocationIcon());
        appealDetailVO.setLocationName(byId2.getLocationName());
        appealDetailVO.setTaskId(byId.getId());
        if (StringUtils.hasLength(appeal.getAuditPerson())) {
            SysUser sysUser = sysUserService.selectUserById(Long.valueOf(appeal.getAuditPerson()));
            if (sysUser != null) {
                appealDetailVO.setAuditPersonName(sysUser.getUserName());
            }
        }
        appealDetailVO.setTaskName(byId.getTaskName());
        appealDetailVO.setTaskCode(byId.getTaskCode());
        return R.ok(appealDetailVO);
    }
 
    @Log(title = "取消申诉记录", businessType = BusinessType.OTHER)
    @ApiOperation(value = "取消申诉记录")
    @GetMapping(value = "/cancelAppeal")
    public R<Boolean> cancelAppeal(@RequestParam String id) {
        TAppeal byId = appealService.getById(id);
        byId.setStatus(4);
        appealService.updateById(byId);
        return R.ok();
    }
 
    @ApiOperation(value = "获取距离最近的任务列表")
    @PostMapping(value = "/listAllTask")
    public R<List<TaskListAllVO>> listAllTask(@RequestBody AppealListDTO appealListDTO) {
        appealListDTO.setUserId(tokenService.getLoginUserApplet().getUserId() + "");
        List<TaskListAllVO> res = appealService.listAllTask(appealListDTO);
        return R.ok(res);
    }
 
    @ApiOperation(value = "不合格原因列表")
    @PostMapping(value = "/unqualifiedList")
    public R<List<TDictData>> unqualifiedList() {
        List<TDictData> list = dictDataService.list(
                new LambdaQueryWrapper<TDictData>()
                        .eq(TDictData::getDataType, 2)
        );
        return R.ok(list);
    }
 
    @ApiOperation(value = "上传督察任务")
    @PostMapping(value = "/addInspector")
    public R<Boolean> addInspector(@RequestBody InspectorAddDTO dto) {
        TTask task = taskCleanerService.getById(dto.getTaskId());
        TLocation location = locationService.getById(task.getLocationId());
        SysUser sysUser = sysUserService.selectUserById(Long.valueOf(task.getPatrolInspector()));
        dto.setCommitPerson(tokenService.getLoginUserApplet().getUserId() + "");
        if (dto.getClearStatus() == 1) {
            dto.setStatus(4);
        } else {
            dto.setStatus(1);
            TNotice tNotice = new TNotice();
            tNotice.setUserId(sysUser.getUserId()+"");
            tNotice.setNoticeContent("【"+location.getLocationName()+"】任务督察不合格,请及时整改!");
            tNotice.setStatus(1);
            tNotice.setDataId(dto.getTaskId());
            tNotice.setNoticeType(8);
            noticeService.save(tNotice);
        }
        inspectorService.save(dto);
        return R.ok();
    }
 
    @ApiOperation(value = "上传意见反馈")
    @PostMapping(value = "/addFeedback")
    public R<Boolean> addFeedback(@RequestBody FeedbackDTO dto) {
        dto.setFeedbackPerson(tokenService.getLoginUserApplet().getUserId() + "");
        feedbackService.save(dto);
        return R.ok();
    }
 
    @ApiOperation(value = "上传问题上报")
    @PostMapping(value = "/addProblem")
    public R<Boolean> addProblem(@RequestBody ProblemDTO dto) {
        dto.setEscalationId(tokenService.getLoginUserApplet().getUserId() + "");
        problemEscalationService.save(dto);
        return R.ok();
    }
 
    @ApiOperation(value = "问题类型列表")
    @PostMapping(value = "/problemList")
    public R<List<TDictData>> problemList() {
        List<TDictData> list = dictDataService.list(
                new LambdaQueryWrapper<TDictData>()
                        .eq(TDictData::getDataType, 3)
        );
        return R.ok(list);
    }
 
 
    @Resource
    private TKnowledgeService knowledgeService;
 
 
    @ApiOperation(value = "环卫知识分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<KnowledgeVO>> pageList(@RequestBody KnowledgeListUserQuery query) {
 
 
        return R.ok(knowledgeService.pageListUser(query));
    }
 
    @ApiOperation(value = "详情环卫知识")
    @GetMapping(value = "/detailKnowledge")
    public R<TKnowledge> detailKnowledge(@RequestParam String id) {
        TKnowledge byId = knowledgeService.getById(id);
        int i = byId.getViews() + 1;
        byId.setViews(i);
        knowledgeService.updateById(byId);
        return R.ok(byId);
    }
 
    @ApiOperation(value = "发起请假-获取审批流程")
    @GetMapping(value = "/leaveAuditList")
    public R<LeaveAuditListVO> leaveAuditList() {
        LeaveAuditListVO res = new LeaveAuditListVO();
        Long userId = tokenService.getLoginUserApplet().getUserId();
        SysUser user = sysUserService.selectUserById(userId);
        Long userRole = sysUserService.getUserRole(userId);
        SysRole sysRole = roleService.selectRoleById(userRole);
        List<SysUser> sysUsers = sysUserService.selectAllList();
        SysUser auditPerson = sysUserService.selectUserById(999L);
        //项目部负责人、部门负责人、公司成员提交由最终审批人审批;
        if (user.getDeptType() == 2 || sysRole.getRoleName().contains("项目部负责人") || sysRole.getRoleName().contains("部门负责人")) {
            LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
            tLeaveAudit.setAvatar(auditPerson.getAvatar());
            tLeaveAudit.setNickName(auditPerson.getNickName());
            res.setAuditPerson(tLeaveAudit);
            res.setAuditPersonId("999");
        } else if (!sysRole.getRoleName().equals("部门助理")) {
            // 审批人根据当前角色类型来
            if (sysRole.getRoleName().contains("片区负责人") || sysRole.getRoleName().contains("组长/队长")||sysRole.getRoleName().contains("项目部助理")) {
                List<SysUser> collect = sysUsers.stream().filter(e -> e.getDeptType() == 1 &&
                        e.getDeptId().equals(user.getDeptId())).collect(Collectors.toList());
                for (SysUser sysUser : collect) {
                    Long userRole1 = sysUserService.getUserRole(sysUser.getUserId());
                    SysRole sysRole1 = roleService.selectRoleById(userRole1);
                    if (sysRole1 != null && sysRole1.getRoleName().equals("项目部负责人")) {
                        LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
                        tLeaveAudit.setAvatar(sysUser.getAvatar());
                        tLeaveAudit.setNickName(sysUser.getNickName());
                        res.setAuditPerson(tLeaveAudit);
                        res.setAuditPersonId(sysUser.getUserId() + "");
                        break;
                    }
                }
            }
        } else {
            List<SysUser> collect = sysUsers.stream().filter(e -> e.getDeptType() == 1 &&
                    e.getDeptId().equals(user.getDeptId())).collect(Collectors.toList());
            for (SysUser sysUser : collect) {
                Long userRole1 = sysUserService.getUserRole(sysUser.getUserId());
                SysRole sysRole1 = roleService.selectRoleById(userRole1);
                if (sysRole1 != null && sysRole1.getRoleName().contains("部门负责人")) {
                    LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
                    tLeaveAudit.setAvatar(sysUser.getAvatar());
                    tLeaveAudit.setNickName(sysUser.getNickName());
                    res.setAuditPerson(tLeaveAudit);
                    res.setAuditPersonId(sysUser.getUserId() + "");
                    break;
                }
            }
        }
        List<LeaveAuditVO> leaveAuditVOS = new ArrayList<>();
        // 当前登陆人-抄送人
        LeaveAuditVO leaveAuditVO1 = new LeaveAuditVO();
        leaveAuditVO1.setAvatar(user.getAvatar());
        leaveAuditVO1.setNickName(user.getNickName());
        // 最终审核人-抄送人
        LeaveAuditVO leaveAuditVO = new LeaveAuditVO();
        leaveAuditVO.setAvatar(auditPerson.getAvatar());
        leaveAuditVO.setNickName(auditPerson.getNickName());
        leaveAuditVOS.add(leaveAuditVO);
        leaveAuditVOS.add(leaveAuditVO1);
        res.setCopyPerson(leaveAuditVOS);
        return R.ok(res);
    }
 
    public static void main(String[] args) {
        String temp = "2025-06-30 00:00:00";
        // 轉化爲localdateTime
        LocalDateTime parse = LocalDateTime.parse(temp, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(parse);
    }
 
    @ApiOperation(value = "发起请假")
    @PostMapping(value = "/addLeave")
    public R addLeave(@RequestBody LeaveDTO leaveDTO) {
//        String startTime1 = leaveDTO.getStartTime1();
//        // 轉化爲LocalDateTime類型
//        leaveDTO.setStartTime(LocalDateTime.parse(startTime1, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//        String endTime1 = leaveDTO.getEndTime1();
//        // 轉化爲LocalDateTime類型
//        leaveDTO.setStartTime(LocalDateTime.parse(endTime1, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        Long userId = tokenService.getLoginUserApplet().getUserId();
        SysUser user = sysUserService.selectUserById(userId);
        Long userRole = sysUserService.getUserRole(userId);
        SysRole sysRole = roleService.selectRoleById(userRole);
        List<SysUser> sysUsers = sysUserService.selectAllList();
        SysUser auditPerson = sysUserService.selectUserById(999L);
        leaveDTO.setAuditStatus(1);
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        // 生成随机数字6位
        String format = simpleDateFormat.format(date);
        leaveDTO.setCode(format + RandomUtil.randomNumbers(6));
        leaveDTO.setTemplateId(user.getTemplateId());
        leaveDTO.setLeavePerson(userId + "");
        leaveService.save(leaveDTO);
        //项目部负责人、部门负责人、公司成员提交由最终审批人审批;
        if (user.getDeptType() == 2 || sysRole.getRoleName().contains("项目部负责人") || sysRole.getRoleName().contains("部门负责人")) {
            TLeaveAudit tLeaveAudit1 = new TLeaveAudit();
            tLeaveAudit1.setLeaveId(leaveDTO.getId());
            tLeaveAudit1.setAuditStatus(1);
            tLeaveAudit1.setAuditId(auditPerson.getUserId() + "");
            tLeaveAudit1.setAuditType(1);
            leaveAuditService.save(tLeaveAudit1);
        } else if (!sysRole.getRoleName().equals("部门助理")) {
            // 审批人根据当前角色类型来
            if (sysRole.getRoleName().contains("片区负责人") || sysRole.getRoleName().contains("组长/队长")||sysRole.getRoleName().contains("项目部助理")) {
                List<SysUser> collect = sysUsers.stream().filter(e -> e.getDeptType() == 1 &&
                        e.getDeptId().equals(user.getDeptId())).collect(Collectors.toList());
                for (SysUser sysUser : collect) {
                    Long userRole1 = sysUserService.getUserRole(sysUser.getUserId());
                    SysRole sysRole1 = roleService.selectRoleById(userRole1);
                    if (sysRole1 != null && sysRole1.getRoleName().equals("项目部负责人")) {
                        TLeaveAudit tLeaveAudit1 = new TLeaveAudit();
                        tLeaveAudit1.setLeaveId(leaveDTO.getId());
                        tLeaveAudit1.setAuditStatus(1);
                        tLeaveAudit1.setAuditId(sysUser.getUserId() + "");
                        tLeaveAudit1.setAuditType(1);
                        leaveAuditService.save(tLeaveAudit1);
                    }
                }
            }
        } else {
            List<SysUser> collect = sysUsers.stream().filter(e -> e.getDeptType() == 1 &&
                    e.getDeptId().equals(user.getDeptId())).collect(Collectors.toList());
            for (SysUser sysUser : collect) {
                Long userRole1 = sysUserService.getUserRole(sysUser.getUserId());
                SysRole sysRole1 = roleService.selectRoleById(userRole1);
                if (sysRole1 != null && sysRole1.getRoleName().contains("部门负责人")) {
                    TLeaveAudit tLeaveAudit1 = new TLeaveAudit();
                    tLeaveAudit1.setLeaveId(leaveDTO.getId());
                    tLeaveAudit1.setAuditStatus(1);
                    tLeaveAudit1.setAuditId(sysUser.getUserId() + "");
                    tLeaveAudit1.setAuditType(1);
                    leaveAuditService.save(tLeaveAudit1);
                }
            }
        }
        TLeaveAudit tLeaveAudit2 = new TLeaveAudit();
        tLeaveAudit2.setLeaveId(leaveDTO.getId());
        tLeaveAudit2.setAuditStatus(2);
        tLeaveAudit2.setAuditId(user.getUserId() + "," + auditPerson.getUserId());
        tLeaveAudit2.setAuditType(2);
        tLeaveAudit2.setAuditTime(LocalDateTime.now());
        leaveAuditService.save(tLeaveAudit2);
        // 新增消息
        TNotice tNotice = new TNotice();
        tNotice.setUserId(leaveDTO.getAuditId());
        tNotice.setNoticeContent(user.getNickName() + "提交了请假申请,请尽快审核");
        tNotice.setStatus(1);
        tNotice.setDataId(leaveDTO.getId());
        tNotice.setNoticeType(6);
        noticeService.save(tNotice);
        return R.ok();
    }
 
    @ApiOperation(value = "我的审批-我的申请")
    @PostMapping(value = "/leaveList")
    public R<PageInfo<LeaveUserListVO>> leaveList(@RequestBody LeaveListUserQuery query) {
        query.setUserId(tokenService.getLoginUserApplet().getUserId() + "");
        return R.ok(leaveService.leaveList(query));
    }
 
    @ApiOperation(value = "我的审批-审批")
    @PostMapping(value = "/auditLeave")
    public R<Boolean> auditLeave(@RequestBody LeaveAuditDTO dto) {
 
        dto.setAuditId(tokenService.getLoginUserApplet().getUserId() + "");
        dto.setAuditTime(LocalDateTime.now());
        leaveService.updateById(dto);
        SysUser sysUser = sysUserService.selectUserById(Long.valueOf(dto.getLeavePerson()));
        TLeaveAudit leaveAudit = leaveAuditService.lambdaQuery().eq(TLeaveAudit::getLeaveId, dto.getId())
                .eq(TLeaveAudit::getAuditType, 2).one();
        TNotice tNotice = new TNotice();
        tNotice.setUserId(leaveAudit.getAuditId().split(",")[0]);
        tNotice.setNoticeContent(sysUser.getNickName()+"的请假申请已审核,请查收");
        tNotice.setStatus(1);
        tNotice.setDataId(dto.getId());
        tNotice.setNoticeType(7);
        noticeService.save(tNotice);
        TNotice tNotice1 = new TNotice();
        tNotice1.setUserId(leaveAudit.getAuditId().split(",")[1]);
        tNotice1.setNoticeContent(sysUser.getNickName()+"的请假申请已审核,请查收");
        tNotice1.setStatus(1);
        tNotice1.setDataId(dto.getId());
        tNotice1.setNoticeType(7);
        noticeService.save(tNotice1);
        return R.ok();
    }
 
    @ApiOperation(value = "我的审批-详情")
    @GetMapping(value = "/leaveDetail")
    public  R<LeaveUserDetailVO> leaveDetail(@RequestParam String id) {
        TLeave leave = leaveService.getById(id);
        LeaveUserDetailVO leaveUserDetailVO = new LeaveUserDetailVO();
        SysUser sysUser = sysUserService.selectUserById(Long.parseLong(leave.getLeavePerson()));
        Long userRole = sysUserService.getUserRole(sysUser.getUserId());
        SysRole sysRole = roleService.selectRoleById(userRole);
        if (sysRole.getRoleName().contains("片区负责人") || sysRole.getRoleName().equals("组长/队长")||sysRole.getRoleName().contains("项目部助理")) {
            if (sysUser.getDeptType() == 1) {
                TProjectDept tProjectDept = projectDeptService.getById(sysUser.getDeptId());
                if (!tProjectDept.getParentId().equals("0")) {
                    TProjectDept tProjectDept1 = projectDeptService.getById(tProjectDept.getParentId());
                    leaveUserDetailVO.setDeptName(tProjectDept1.getProjectName() + ">" + tProjectDept.getProjectName());
                } else {
                    leaveUserDetailVO.setDeptName(tProjectDept.getProjectName());
                }
            } else {
                TDept tDept = deptService.getById(sysUser.getDeptId());
                leaveUserDetailVO.setDeptName(tDept.getDeptName());
            }
        } else if (sysRole.getRoleName().contains("项目部负责人")) {
            TProjectDept tProjectDept = projectDeptService.getById(sysUser.getDeptId());
            leaveUserDetailVO.setDeptName(tProjectDept.getProjectName());
        }
        if (sysUser.getDeptType() == 2) {
            TDept byId = deptService.getById(sysUser.getDeptId());
            leaveUserDetailVO.setDeptName(byId.getDeptName());
        }
        if (sysUser.getDeptType()==1){
            TProjectDept projectDept = projectDeptService.getById(sysUser.getDeptId());
            if (projectDept.getParentId().equals("0")){
                leaveUserDetailVO.setDeptName(projectDept.getProjectName());
            }else{
                TProjectDept projectDept1 = projectDeptService.getById(projectDept.getParentId());
                leaveUserDetailVO.setDeptName(projectDept1.getProjectName()+">"+projectDept.getProjectName());
            }
        }
        leaveUserDetailVO.setLeavePersonName(sysUser.getNickName());
        LeaveAuditListVO leaveAuditListVO = new LeaveAuditListVO();
        List<TLeaveAudit> list = leaveAuditService.list(new LambdaQueryWrapper<TLeaveAudit>()
                .eq(TLeaveAudit::getLeaveId, leave.getId()));
        for (TLeaveAudit tLeaveAudit : list) {
            if (tLeaveAudit.getAuditType() == 1) {
                LeaveAuditVO leaveAuditVO = new LeaveAuditVO();
                SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(tLeaveAudit.getAuditId()));
                if (sysUser1 != null) {
                    leaveAuditVO.setAvatar(sysUser1.getAvatar());
                    leaveAuditVO.setNickName(sysUser1.getNickName());
                }
                leaveAuditVO.setCreateTime(tLeaveAudit.getAuditTime());
                leaveAuditVO.setAuditStatus(tLeaveAudit.getAuditStatus());
                leaveAuditListVO.setAuditPerson(leaveAuditVO);
            } else {
                List<LeaveAuditVO> leaveAuditVOS = new ArrayList<>();
                // 抄送人
                LeaveAuditVO leaveAuditVO = new LeaveAuditVO();
                SysUser sysUser1 = sysUserService.selectUserById(Long.valueOf(tLeaveAudit.getAuditId().split(",")[0]));
                leaveAuditVO.setAvatar(sysUser1.getAvatar());
                leaveAuditVO.setNickName(sysUser1.getNickName());
                leaveAuditVO.setCreateTime(tLeaveAudit.getCreateTime());
                leaveAuditVO.setAuditStatus(tLeaveAudit.getAuditStatus());
                leaveAuditVOS.add(leaveAuditVO);
                LeaveAuditVO leaveAuditVO1 = new LeaveAuditVO();
                SysUser sysUser2 = sysUserService.selectUserById(Long.valueOf(tLeaveAudit.getAuditId().split(",")[1]));
                leaveAuditVO1.setAvatar(sysUser2.getAvatar());
                leaveAuditVO1.setNickName(sysUser2.getNickName());
                leaveAuditVO1.setCreateTime(tLeaveAudit.getCreateTime());
                leaveAuditVO1.setAuditStatus(tLeaveAudit.getAuditStatus());
                leaveAuditVOS.add(leaveAuditVO1);
                leaveAuditListVO.setCopyPerson(leaveAuditVOS);
            }
        }
        leaveUserDetailVO.setAudit(leaveAuditListVO);
        leaveUserDetailVO.setId(leave.getId());
        leaveUserDetailVO.setLeavePerson(leave.getLeavePerson());
        leaveUserDetailVO.setStartTime(leave.getStartTime());
        leaveUserDetailVO.setEndTime(leave.getEndTime());
        leaveUserDetailVO.setLeaveType(leave.getLeaveType());
        leaveUserDetailVO.setLeaveDay(leave.getLeaveDay());
        leaveUserDetailVO.setLeaveCause(leave.getLeaveCause());
        leaveUserDetailVO.setPictures(leave.getPictures());
        leaveUserDetailVO.setAuditStatus(leave.getAuditStatus());
        leaveUserDetailVO.setAuditId(leave.getAuditId());
        leaveUserDetailVO.setAuditTime(leave.getAuditTime());
        leaveUserDetailVO.setAuditRemark(leave.getAuditRemark());
        leaveUserDetailVO.setCode(leave.getCode());
        return R.ok(leaveUserDetailVO);
    }
}