From 53d014edd19f57125c355abe71ec5b478500e610 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期二, 05 八月 2025 09:57:40 +0800
Subject: [PATCH] 保洁巡检所有代码

---
 ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TUserController.java |  550 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 444 insertions(+), 106 deletions(-)

diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TUserController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TUserController.java
index d5284d1..a78e71c 100644
--- a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TUserController.java
+++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TUserController.java
@@ -5,11 +5,14 @@
 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.AjaxResult;
 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.redis.service.RedisService;
+import com.ruoyi.common.utils.CodeGenerateUtils;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.framework.web.service.TokenService;
@@ -25,12 +28,25 @@
 import com.ruoyi.system.query.KnowledgeListQuery;
 import com.ruoyi.system.query.TaskListQuery;
 import com.ruoyi.system.service.*;
+import com.ruoyi.system.utils.TemplateMessageSendUtil;
+import com.ruoyi.system.utils.wx.body.resp.Code2SessionRespBody;
+import com.ruoyi.system.utils.wx.body.resq.Code2SessionResqBody;
+import com.ruoyi.system.utils.wx.model.WeixinProperties;
+import com.ruoyi.system.utils.wx.pojo.AppletUserDecodeData;
+import com.ruoyi.system.utils.wx.pojo.AppletUserEncrypteData;
+import com.ruoyi.system.utils.wx.tools.WxAppletTools;
+import com.ruoyi.system.utils.wx.tools.WxUtils;
 import com.ruoyi.system.vo.system.*;
+import com.ruoyi.web.controller.tool.EmailUtils;
+import com.ruoyi.web.controller.tool.MsgUtils;
 import com.sun.jna.platform.win32.LMAccess;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
 
 import javax.annotation.Resource;
 import javax.validation.Valid;
@@ -52,6 +68,7 @@
  * @author xiaochen
  * @since 2025-05-28
  */
+@Slf4j
 @Api(tags = "个人中心")
 @RestController
 @RequestMapping("/t-user")
@@ -81,6 +98,8 @@
     @Resource
     private TDictDataService dictDataService;
     @Resource
+    private TNoticeSetService noticeSetService;
+    @Resource
     private TLeaveService leaveService;
     @Resource
     private TLeaveAuditService leaveAuditService;
@@ -96,6 +115,37 @@
     private TProblemEscalationService problemEscalationService;
     @Resource
     private TNoticeService noticeService;
+    @Autowired
+    private RestTemplate wxRestTemplate;
+    @Autowired
+    private WeixinProperties weixinProperties;
+    @Resource
+    private RedisService redisService;
+    @Resource
+    private MsgUtils msgUtils;
+    @Resource
+    private TemplateMessageSendUtil templateMessageSendUtil;
+    @Resource
+    private TInspectorDetailService inspectorDetailService;
+    @ApiOperation(value = "通过code获得openid,获取用户信息",tags = {"微信小程序登录"})
+    @GetMapping("/openIdByJsCode")
+    public R<String> openIdByJsCode(@RequestParam String code) {
+        Long userId = tokenService.getLoginUserApplet().getUserId();
+        SysUser sysUser = sysUserService.selectUserById(userId);
+        if(Objects.isNull(sysUser)){
+            return R.fail("未查询到当前登录用户信息");
+        }
+        if(StringUtils.hasLength(sysUser.getOpenId())){
+            return R.ok();
+        }
+        log.info("<<<<<<<<换取openid开始<<<<<<<<:{}", code);
+        WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, weixinProperties, redisService);
+        Code2SessionRespBody body = appletTools.getOpenIdByJscode2session(new Code2SessionResqBody().build(code));
+        String openid = body.getOpenid();
+        sysUser.setOpenId(openid);
+        sysUserService.updateUser(sysUser);
+        return R.ok();
+    }
 
     @ApiOperation(value = "消息通知列表")
     @PostMapping(value = "/noticeList")
@@ -330,70 +380,151 @@
     @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());
-        taskDetailVO.setLocationLon(byId1.getLocationLon());
-        taskDetailVO.setLocationLat(byId1.getLocationLat());
-        taskDetailVO.setLocationLatEnd(byId1.getLocationLatEnd());
-        taskDetailVO.setLocationLonEnd(byId1.getLocationLonEnd());
-        TTaskDetail tTaskDetail = list.stream().filter(e -> e.getHandleType() == 1).findFirst().orElse(null);
-        if (tTaskDetail != null && tTaskDetail.getUnqualified() != null) {
-            TDictData byId3 = dictDataService.getById(tTaskDetail.getUnqualified());
-            if (byId3 != null) {
-                tTaskDetail.setUnqualifiedName(byId3.getDataContent());
+        TInspector inspector = inspectorService.getById(id);
+
+        if (byId!=null){
+            List<TTaskDetail> list = taskDetailService.lambdaQuery().eq(TTaskDetail::getTaskId, id)
+                    .orderByDesc(BaseModel::getCreateTime).list();
+            TaskDetailVO taskDetailVO = new TaskDetailVO();
+            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());
+            taskDetailVO.setLocationLon(byId1.getLocationLon());
+            taskDetailVO.setLocationLat(byId1.getLocationLat());
+            taskDetailVO.setLocationLatEnd(byId1.getLocationLatEnd());
+            taskDetailVO.setLocationLonEnd(byId1.getLocationLonEnd());
+            TTaskDetail tTaskDetail = list.stream().filter(e -> e.getHandleType() == 1).findFirst().orElse(null);
+            if (tTaskDetail != null && tTaskDetail.getUnqualified() != null) {
+                TDictData byId3 = dictDataService.getById(tTaskDetail.getUnqualified());
+                if (byId3 != null) {
+                    tTaskDetail.setUnqualifiedName(byId3.getDataContent());
+                }
             }
-        }
-        if (tTaskDetail != null) {
-            tTaskDetail.setFinishTime(tTaskDetail.getCreateTime());
-        }
-        taskDetailVO.setTaskDetail(tTaskDetail);
-        taskDetailVO.setRecords(list);
-        if (byId.getStatus()==4){
-            TTaskDetail reject = taskDetailService.lambdaQuery().eq(TTaskDetail::getTaskId, id)
-                    .eq(TTaskDetail::getHandleType,3)
-                    .orderByDesc(BaseModel::getCreateTime).last("limit 1").one();
-            if (reject!=null){
-                taskDetailVO.setRejectRemark(reject.getAuditRemark());
+            if (tTaskDetail != null) {
+                tTaskDetail.setFinishTime(tTaskDetail.getCreateTime());
             }
+            taskDetailVO.setTaskDetail(tTaskDetail);
+            taskDetailVO.setRecords(list);
+            if (byId.getStatus()==4){
+                TTaskDetail reject = taskDetailService.lambdaQuery().eq(TTaskDetail::getTaskId, id)
+                        .eq(TTaskDetail::getHandleType,3)
+                        .orderByDesc(BaseModel::getCreateTime).last("limit 1").one();
+                if (reject!=null){
+                    taskDetailVO.setRejectRemark(reject.getAuditRemark());
+                }
+            }
+            return R.ok(taskDetailVO);
+
+        }else{
+            List<TInspectorDetail> list = inspectorDetailService.lambdaQuery().eq(TInspectorDetail::getInspectorId, id)
+                    .orderByDesc(BaseModel::getCreateTime).list();
+            TaskDetailVO taskDetailVO = new TaskDetailVO();
+            BeanUtils.copyProperties(inspector, taskDetailVO);
+            TLocation byId1 = locationService.getById(inspector.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());
+            taskDetailVO.setLocationLon(byId1.getLocationLon());
+            taskDetailVO.setLocationLat(byId1.getLocationLat());
+            taskDetailVO.setLocationLatEnd(byId1.getLocationLatEnd());
+            taskDetailVO.setLocationLonEnd(byId1.getLocationLonEnd());
+            TInspectorDetail inspectorDetail = list.stream().filter(e -> e.getHandleType() == 1).findFirst().orElse(null);
+            if (inspectorDetail != null && inspectorDetail.getUnqualified() != null) {
+                TTaskDetail temp = new TTaskDetail();
+                BeanUtils.copyProperties(inspectorDetail, temp);
+                taskDetailVO.setTaskDetail(temp);
+
+                TDictData byId3 = dictDataService.getById(inspectorDetail.getUnqualified());
+                if (byId3 != null) {
+                    inspectorDetail.setUnqualifiedName(byId3.getDataContent());
+                }
+            }
+            if (inspectorDetail != null) {
+                inspectorDetail.setFinishTime(inspectorDetail.getCreateTime());
+            }
+            List<TTaskDetail> tTaskDetails = new ArrayList<>();
+            for (TInspectorDetail tInspectorDetail : list) {
+                TTaskDetail tTaskDetail = new TTaskDetail();
+                BeanUtils.copyProperties(tInspectorDetail, tTaskDetail);
+                tTaskDetails.add(tTaskDetail);
+            }
+            taskDetailVO.setRecords(tTaskDetails);
+            if (inspector.getStatus()==2){
+                TInspectorDetail reject = inspectorDetailService.lambdaQuery().eq(TInspectorDetail::getInspectorId, id)
+                        .eq(TInspectorDetail::getHandleType,3)
+                        .orderByDesc(BaseModel::getCreateTime).last("limit 1").one();
+                if (reject!=null){
+                    taskDetailVO.setRejectRemark(reject.getAuditRemark());
+                }
+            }
+            return R.ok(taskDetailVO);
         }
-        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());
+        TTaskDetail taskDetail = taskDetailService.getById(id);
+        TInspectorDetail inspectorDetail = inspectorDetailService.getById(id);
+
+        if (taskDetail!=null){
+            TTask byId = taskCleanerService.getById(taskDetail.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 (taskDetail.getUnqualified() != null) {
+                TDictData byId3 = dictDataService.getById(taskDetail.getUnqualified());
+                if (byId3 != null) {
+                    taskDetail.setUnqualifiedName(byId3.getDataContent());
+                }
             }
+            taskDetail.setFinishTime(taskDetail.getCreateTime());
+            SysUser sysUser = sysUserService.selectUserById(Long.valueOf(taskDetail.getAuditPerson()));
+            if (sysUser != null) {
+                taskDetail.setAuditPersonName(sysUser.getUserName());
+            }
+            taskDetailVO.setTaskDetail(taskDetail);
+            return R.ok(taskDetailVO);
+        }else{
+            TInspector byId = inspectorService.getById(inspectorDetail.getInspectorId());
+            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 (inspectorDetail.getUnqualified() != null) {
+                TDictData byId3 = dictDataService.getById(inspectorDetail.getUnqualified());
+                if (byId3 != null) {
+                    inspectorDetail.setUnqualifiedName(byId3.getDataContent());
+                }
+            }
+            inspectorDetail.setFinishTime(inspectorDetail.getCreateTime());
+            SysUser sysUser = sysUserService.selectUserById(Long.valueOf(inspectorDetail.getAuditPerson()));
+            if (sysUser != null) {
+                inspectorDetail.setAuditPersonName(sysUser.getUserName());
+            }
+            TTaskDetail tTaskDetail = new TTaskDetail();
+            BeanUtils.copyProperties(inspectorDetail, tTaskDetail);
+            taskDetailVO.setTaskDetail(tTaskDetail);
+            return R.ok(taskDetailVO);
         }
-        byId4.setFinishTime(byId4.getCreateTime());
-        SysUser sysUser = sysUserService.selectUserById(Long.valueOf(byId4.getAuditPerson()));
-        if (sysUser != null) {
-            byId4.setAuditPersonName(sysUser.getUserName());
-        }
-        taskDetailVO.setTaskDetail(byId4);
-        return R.ok(taskDetailVO);
+
     }
 
     @ApiOperation(value = "申诉记录分页列表")
@@ -443,14 +574,19 @@
     public R<List<TaskListAllVO>> listAllTask(@RequestBody AppealListDTO appealListDTO) {
         appealListDTO.setUserId(tokenService.getLoginUserApplet().getUserId() + "");
         SysUser sysUser = sysUserService.selectUserById(tokenService.getLoginUserApplet().getUserId());
-        if (sysUser.getDeptType()==2){
-            // 公司部门查询所有任务
-            appealListDTO.setUserId(null);
-        }
+//        if (sysUser.getDeptType()==2){
+//            // 公司部门查询所有任务
+//            appealListDTO.setUserId(null);
+//        }
         List<TaskListAllVO> res = appealService.listAllTask(appealListDTO);
         return R.ok(res);
     }
-
+    @ApiOperation(value = "点位列表")
+    @PostMapping(value = "/locationList")
+    public R<List<TaskListAllVO>> locationList(@RequestBody AppealListDTO appealListDTO) {
+        List<TaskListAllVO> locations = appealService.locationList(appealListDTO);
+        return R.ok(locations);
+    }
     @ApiOperation(value = "不合格原因列表")
     @PostMapping(value = "/unqualifiedList")
     public R<List<TDictData>> unqualifiedList() {
@@ -461,26 +597,48 @@
         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()));
+    public R<Boolean> addInspector(@RequestBody InspectorAddDTO dto) throws Exception {
+//        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);
+//
+//        }
+//        inspectorService.save(dto);
+//        return R.ok();
+
+        TLocation location = locationService.getById(dto.getLocationId());
+        SysUser sysUser = sysUserService.selectUserById(Long.valueOf(location.getLocationLeader()));
         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);
+            dto.setStatus(2);
+
         }
+        String nameAndCode = CodeGenerateUtils.generateVolumeSn();
+        dto.setTaskCode(nameAndCode);
+        dto.setTaskName(nameAndCode);
         inspectorService.save(dto);
+        TInspectorDetail tInspectorDetail = new TInspectorDetail();
+        tInspectorDetail.setInspectorId(dto.getId());
+        tInspectorDetail.setClearStatus(dto.getClearStatus());
+        tInspectorDetail.setUnqualified(dto.getUnqualified());
+        tInspectorDetail.setRemark(dto.getRemark());
+        tInspectorDetail.setPicture(dto.getPicture());
+        tInspectorDetail.setAudioUrl(dto.getAudioUrl());
+        tInspectorDetail.setHandleType(1);
+
+        inspectorDetailService.save(tInspectorDetail);
         return R.ok();
     }
 
@@ -562,16 +720,37 @@
                 for (SysUser sysUser : collect) {
                     Long userRole1 = sysUserService.getUserRole(sysUser.getUserId());
                     SysRole sysRole1 = roleService.selectRoleById(userRole1);
-
+//                    if (sysRole1 != null && sysRole1.getRoleName().equals("项目部负责人")) {
+//                        if (userDept.getId().equals(sysUser.getDeptId())){
+//                            LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
+//                            tLeaveAudit.setAvatar(sysUser.getAvatar());
+//                            tLeaveAudit.setNickName(sysUser.getNickName());
+//                            res.setAuditPerson(tLeaveAudit);
+//                            res.setAuditPersonId(sysUser.getUserId() + "");
+//                            break;
+//                        }
+//                    }
                     if (sysRole1 != null && sysRole1.getRoleName().equals("项目部负责人")) {
-                        if (userDept.getParentId().equals(sysUser.getDeptId())){
-                            LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
-                            tLeaveAudit.setAvatar(sysUser.getAvatar());
-                            tLeaveAudit.setNickName(sysUser.getNickName());
-                            res.setAuditPerson(tLeaveAudit);
-                            res.setAuditPersonId(sysUser.getUserId() + "");
-                            break;
+                        if (!sysRole.getRoleName().contains("项目部助理")){
+                            if (userDept.getParentId().equals(sysUser.getDeptId())){
+                                LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
+                                tLeaveAudit.setAvatar(sysUser.getAvatar());
+                                tLeaveAudit.setNickName(sysUser.getNickName());
+                                res.setAuditPerson(tLeaveAudit);
+                                res.setAuditPersonId(sysUser.getUserId() + "");
+                                break;
+                            }
+                        }else{
+                            if (userDept.getId().equals(sysUser.getDeptId())){
+                                LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
+                                tLeaveAudit.setAvatar(sysUser.getAvatar());
+                                tLeaveAudit.setNickName(sysUser.getNickName());
+                                res.setAuditPerson(tLeaveAudit);
+                                res.setAuditPersonId(sysUser.getUserId() + "");
+                                break;
+                            }
                         }
+
                     }
                 }
             }
@@ -615,7 +794,7 @@
 
     @ApiOperation(value = "发起请假")
     @PostMapping(value = "/addLeave")
-    public R addLeave(@RequestBody LeaveDTO leaveDTO) {
+    public R addLeave(@RequestBody LeaveDTO leaveDTO) throws Exception {
 //        String startTime1 = leaveDTO.getStartTime1();
 //        // 轉化爲LocalDateTime類型
 //        leaveDTO.setStartTime(LocalDateTime.parse(startTime1, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
@@ -636,7 +815,18 @@
         leaveDTO.setCode(format + RandomUtil.randomNumbers(6));
         leaveDTO.setTemplateId(user.getTemplateId());
         leaveDTO.setLeavePerson(userId + "");
+        LocalDateTime endTime1 = leaveDTO.getEndTime();
+        endTime1.withHour(23);
+        endTime1.withMinute(59);
+        endTime1.withSecond(59);
+        leaveDTO.setEndTime(endTime1);
         leaveService.save(leaveDTO);
+        TNoticeSet noticeSet = noticeSetService.lambdaQuery().eq(TNoticeSet::getType, 2).last("limit 1")
+                .one();
+        // 邮箱
+        TDictData email = dictDataService.lambdaQuery().eq(TDictData::getDataType,4).one();
+        // 授权码
+        TDictData code = dictDataService.lambdaQuery().eq(TDictData::getDataType,5).one();
         //项目部负责人、部门负责人、公司成员提交由最终审批人审批;
         if (user.getDeptType() == 2 || sysRole.getRoleName().contains("项目部负责人") || sysRole.getRoleName().contains("部门负责人")) {
             TLeaveAudit tLeaveAudit1 = new TLeaveAudit();
@@ -645,6 +835,13 @@
             tLeaveAudit1.setAuditId(auditPerson.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);
         } else if (!sysRole.getRoleName().equals("部门助理")) {
             // 审批人根据当前角色类型来
             if (sysRole.getRoleName().contains("片区负责人") || sysRole.getRoleName().contains("组长")|| sysRole.getRoleName().contains("队长")
@@ -657,25 +854,102 @@
                     SysRole sysRole1 = roleService.selectRoleById(userRole1);
 
                     if (sysRole1 != null && sysRole1.getRoleName().equals("项目部负责人")) {
-                        if (userDept.getParentId().equals(sysUser.getDeptId())){
-                            LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
-                            tLeaveAudit.setAvatar(sysUser.getAvatar());
-                            tLeaveAudit.setNickName(sysUser.getNickName());
-                            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() + "," + sysUser.getUserId());
-                            tLeaveAudit2.setAuditType(2);
-                            tLeaveAudit2.setAuditTime(LocalDateTime.now());
-                            leaveAuditService.save(tLeaveAudit2);
-                            break;
-                        }
+                       if (!sysRole.getRoleName().contains("项目部助理")){
+                           if (userDept.getParentId().equals(sysUser.getDeptId())){
+                               LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
+                               tLeaveAudit.setAvatar(sysUser.getAvatar());
+                               tLeaveAudit.setNickName(sysUser.getNickName());
+                               TLeaveAudit tLeaveAudit1 = new TLeaveAudit();
+                               tLeaveAudit1.setLeaveId(leaveDTO.getId());
+                               tLeaveAudit1.setAuditStatus(1);
+                               tLeaveAudit1.setAuditId(sysUser.getUserId() + "");
+                               tLeaveAudit1.setAuditType(1);
+                               leaveAuditService.save(tLeaveAudit1);
+                               // 新增消息
+                               TNotice tNotice = new TNotice();
+                               tNotice.setUserId(sysUser.getUserId()+"");
+                               tNotice.setNoticeContent(user.getNickName() + "提交了请假申请,请尽快审核");
+                               tNotice.setStatus(1);
+                               tNotice.setDataId(leaveDTO.getId());
+                               tNotice.setNoticeType(6);
+
+                               switch (noticeSet.getNoticeType()) {
+                                   case 1:
+                                       msgUtils.sendMsg4(sysUser.getPhonenumber());
+                                       break;
+                                   case 2:
+                                       if (StringUtils.hasLength(email.getDataContent()) && StringUtils.hasLength(code.getDataContent())) {
+                                           EmailUtils.sendEmail(sysUser.getEmail(), email.getDataContent(), code.getDataContent(), "你有一条请假申请待处理,请登录沿海市政质管小程序处理。");
+                                       }
+                                       break;
+                                   case 3:
+                                       if (StringUtils.hasLength(sysUser.getOpenId())){
+                                           Date date1 = new Date();
+                                           SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+                                           SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                                           String format1 = simpleDateFormat1.format(date1);
+                                           String startTime = simpleDateFormat2.format(leaveDTO.getStartTime());
+                                           String endTime = simpleDateFormat2.format(leaveDTO.getStartTime());
+                                           templateMessageSendUtil.wxTemplatePendApprovalRequest(sysUser.getOpenId(),
+                                                   user.getNickName(),format1,"员工请假",
+                                                   startTime,endTime);
+                                       }
+                                       break;
+                               }
+
+
+                               noticeService.save(tNotice);
+                               TLeaveAudit tLeaveAudit2 = new TLeaveAudit();
+                               tLeaveAudit2.setLeaveId(leaveDTO.getId());
+                               tLeaveAudit2.setAuditStatus(2);
+                               tLeaveAudit2.setAuditId(user.getUserId() + "," + sysUser.getUserId());
+                               tLeaveAudit2.setAuditType(2);
+                               tLeaveAudit2.setAuditTime(LocalDateTime.now());
+                               leaveAuditService.save(tLeaveAudit2);
+                               break;
+                           }
+                       }else{
+                           if (userDept.getId().equals(sysUser.getDeptId())){
+                               LeaveAuditVO tLeaveAudit = new LeaveAuditVO();
+                               tLeaveAudit.setAvatar(sysUser.getAvatar());
+                               tLeaveAudit.setNickName(sysUser.getNickName());
+                               TLeaveAudit tLeaveAudit1 = new TLeaveAudit();
+                               tLeaveAudit1.setLeaveId(leaveDTO.getId());
+                               tLeaveAudit1.setAuditStatus(1);
+                               tLeaveAudit1.setAuditId(sysUser.getUserId() + "");
+                               tLeaveAudit1.setAuditType(1);
+                               leaveAuditService.save(tLeaveAudit1);
+                               // 新增消息
+                               TNotice tNotice = new TNotice();
+                               tNotice.setUserId(sysUser.getUserId()+"");
+                               tNotice.setNoticeContent(user.getNickName() + "提交了请假申请,请尽快审核");
+                               tNotice.setStatus(1);
+                               tNotice.setDataId(leaveDTO.getId());
+                               tNotice.setNoticeType(6);
+                               noticeService.save(tNotice);
+                               switch (noticeSet.getNoticeType()) {
+                                   case 1:
+                                       msgUtils.sendMsg4(sysUser.getPhonenumber());
+                                       break;
+                                   case 2:
+                                       if (StringUtils.hasLength(email.getDataContent()) && StringUtils.hasLength(code.getDataContent())) {
+                                           EmailUtils.sendEmail(sysUser.getEmail(), email.getDataContent(), code.getDataContent(), "你有一条请假申请待处理,请登录沿海市政质管小程序处理。");
+                                       }
+                                       break;
+                                   case 3:
+                                       break;
+                               }
+                               TLeaveAudit tLeaveAudit2 = new TLeaveAudit();
+                               tLeaveAudit2.setLeaveId(leaveDTO.getId());
+                               tLeaveAudit2.setAuditStatus(2);
+                               tLeaveAudit2.setAuditId(user.getUserId() + "," + sysUser.getUserId());
+                               tLeaveAudit2.setAuditType(2);
+                               tLeaveAudit2.setAuditTime(LocalDateTime.now());
+                               leaveAuditService.save(tLeaveAudit2);
+                               break;
+                           }
+                       }
+
                     }
                 }
             }
@@ -692,6 +966,26 @@
                     tLeaveAudit1.setAuditId(sysUser.getUserId() + "");
                     tLeaveAudit1.setAuditType(1);
                     leaveAuditService.save(tLeaveAudit1);
+                    // 新增消息
+                    TNotice tNotice = new TNotice();
+                    tNotice.setUserId(sysUser.getUserId()+"");
+                    tNotice.setNoticeContent(user.getNickName() + "提交了请假申请,请尽快审核");
+                    tNotice.setStatus(1);
+                    tNotice.setDataId(leaveDTO.getId());
+                    tNotice.setNoticeType(6);
+                    noticeService.save(tNotice);
+                    switch (noticeSet.getNoticeType()) {
+                        case 1:
+                            msgUtils.sendMsg4(sysUser.getPhonenumber());
+                            break;
+                        case 2:
+                            if (StringUtils.hasLength(email.getDataContent()) && StringUtils.hasLength(code.getDataContent())) {
+                                EmailUtils.sendEmail(sysUser.getEmail(), email.getDataContent(), code.getDataContent(), "你有一条请假申请待处理,请登录沿海市政质管小程序处理。");
+                            }
+                            break;
+                        case 3:
+                            break;
+                    }
                     TLeaveAudit tLeaveAudit2 = new TLeaveAudit();
                     tLeaveAudit2.setLeaveId(leaveDTO.getId());
                     tLeaveAudit2.setAuditStatus(2);
@@ -703,14 +997,7 @@
             }
         }
 
-        // 新增消息
-        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();
     }
 
@@ -723,14 +1010,21 @@
 
     @ApiOperation(value = "我的审批-审批")
     @PostMapping(value = "/auditLeave")
-    public R<Boolean> auditLeave(@RequestBody LeaveAuditDTO dto) {
+    public R<Boolean> auditLeave(@RequestBody LeaveAuditDTO dto) throws Exception {
 
         dto.setAuditId(tokenService.getLoginUserApplet().getUserId() + "");
         dto.setAuditTime(LocalDateTime.now());
         leaveService.updateById(dto);
+        List<SysUser> sysUsers = sysUserService.selectAllList();
         SysUser sysUser = sysUserService.selectUserById(Long.valueOf(dto.getLeavePerson()));
         TLeaveAudit leaveAudit = leaveAuditService.lambdaQuery().eq(TLeaveAudit::getLeaveId, dto.getId())
                 .eq(TLeaveAudit::getAuditType, 2).one();
+        TNoticeSet noticeSet = noticeSetService.lambdaQuery().eq(TNoticeSet::getType, 2).last("limit 1")
+                .one();
+        // 邮箱
+        TDictData email = dictDataService.lambdaQuery().eq(TDictData::getDataType,4).one();
+        // 授权码
+        TDictData code = dictDataService.lambdaQuery().eq(TDictData::getDataType,5).one();
         TNotice tNotice = new TNotice();
         tNotice.setUserId(leaveAudit.getAuditId().split(",")[0]);
         tNotice.setNoticeContent(sysUser.getNickName()+"的请假申请已审核,请查收");
@@ -738,6 +1032,36 @@
         tNotice.setDataId(dto.getId());
         tNotice.setNoticeType(7);
         noticeService.save(tNotice);
+        LocalDateTime startTime = dto.getStartTime();
+        LocalDateTime endTime = dto.getEndTime();
+        SysUser sysUser1 = sysUsers.stream().filter(e -> e.getUserId().equals(Long.valueOf(leaveAudit.getAuditId().split(",")[0])))
+                .findFirst().orElse(null);
+        SysUser sysUser2 = sysUsers.stream().filter(e -> e.getUserId().equals(Long.valueOf(leaveAudit.getAuditId().split(",")[1])))
+                .findFirst().orElse(null);
+        // 转化为yyyy-MM-dd 格式字符串
+        String leaveTime = startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))+"至"+endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        if (sysUser1!=null){
+            switch (noticeSet.getNoticeType()) {
+                case 1:
+                    msgUtils.sendMsg5(sysUser1.getPhonenumber(),sysUser1.getNickName(),leaveTime);
+                    break;
+                case 2:
+                    if (StringUtils.hasLength(email.getDataContent())&&StringUtils.hasLength(code.getDataContent())){
+                        EmailUtils.sendEmail(sysUser1.getEmail(),email.getDataContent(),code.getDataContent(),sysUser1.getNickName()+"的请假申请已审核,请查收");
+                    }
+                    break;
+                case 3:
+                    if (StringUtils.hasLength(sysUser.getOpenId())){
+                        Date date = new Date();
+                        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+                        String startTime1 = simpleDateFormat2.format(date);
+                        templateMessageSendUtil.wxTemplateMakeCopyRequest(sysUser1.getOpenId(),
+                                sysUser1.getNickName(),startTime1,"请假审批");
+                    }
+                    break;
+            }
+        }
+
         TNotice tNotice1 = new TNotice();
         tNotice1.setUserId(leaveAudit.getAuditId().split(",")[1]);
         tNotice1.setNoticeContent(sysUser.getNickName()+"的请假申请已审核,请查收");
@@ -745,6 +1069,20 @@
         tNotice1.setDataId(dto.getId());
         tNotice1.setNoticeType(7);
         noticeService.save(tNotice1);
+        if (sysUser2!=null) {
+            switch (noticeSet.getNoticeType()) {
+                case 1:
+                    msgUtils.sendMsg5(sysUser2.getPhonenumber(), sysUser2.getNickName(), leaveTime);
+                    break;
+                case 2:
+                    if (StringUtils.hasLength(email.getDataContent()) && StringUtils.hasLength(code.getDataContent())) {
+                        EmailUtils.sendEmail(sysUser2.getEmail(), email.getDataContent(), code.getDataContent(), sysUser2.getNickName() + "的请假申请已审核,请查收");
+                    }
+                    break;
+                case 3:
+                    break;
+            }
+        }
         return R.ok();
     }
 

--
Gitblit v1.7.1