|  |  |  | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.entity.SysUser; | 
|---|
|  |  |  | import com.ruoyi.common.core.domain.entity.TDept; | 
|---|
|  |  |  | import com.ruoyi.common.enums.BusinessType; | 
|---|
|  |  |  | import com.ruoyi.system.dto.SetDeptDTO; | 
|---|
|  |  |  | import com.ruoyi.system.model.OaApproval; | 
|---|
|  |  |  | import com.ruoyi.system.model.OaNotifationUser; | 
|---|
|  |  |  | import com.ruoyi.system.model.OaNotificationUser; | 
|---|
|  |  |  | import com.ruoyi.system.model.OaNotification; | 
|---|
|  |  |  | import com.ruoyi.system.query.ApprovalListQuery; | 
|---|
|  |  |  | import com.ruoyi.system.query.NotificationListQuery; | 
|---|
|  |  |  | import com.ruoyi.system.service.*; | 
|---|
|  |  |  | import com.ruoyi.system.vo.system.*; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
|---|
|  |  |  | import org.springframework.validation.annotation.Validated; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.sql.Array; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletRequest; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @ApiOperation("消息通知分页列表") | 
|---|
|  |  |  | @PostMapping("/pageList") | 
|---|
|  |  |  | public R<PageInfo<NotificationVO>> pageList(@RequestBody NotificationListQuery query) { | 
|---|
|  |  |  | public R<PageInfo<NotificationVO>> pageList(@RequestBody NotificationListQuery query | 
|---|
|  |  |  | ) { | 
|---|
|  |  |  | return R.ok(oaNotificationService.pageList(query)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | List<String> notificationIds = Arrays.asList(ids.split(",")); | 
|---|
|  |  |  | // 删除后 将已发送的消息通知一并删除 | 
|---|
|  |  |  | oaNotificationService.removeBatchByIds(notificationIds); | 
|---|
|  |  |  | oaNotifationUserService.remove(new LambdaQueryWrapper<OaNotifationUser>() | 
|---|
|  |  |  | .in(OaNotifationUser::getNotificationId,notificationIds)); | 
|---|
|  |  |  | oaNotifationUserService.remove(new LambdaQueryWrapper<OaNotificationUser>() | 
|---|
|  |  |  | .in(OaNotificationUser::getNotificationId,notificationIds)); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Log(title = "消息通知-新增消息", businessType = BusinessType.INSERT) | 
|---|
|  |  |  | 
|---|
|  |  |  | @PostMapping(value = "/add") | 
|---|
|  |  |  | public R<Boolean> add( @RequestBody OaNotification dto) { | 
|---|
|  |  |  | oaNotificationService.save(dto); | 
|---|
|  |  |  | ArrayList<OaNotifationUser> oaNotifationUsers = new ArrayList<>(); | 
|---|
|  |  |  | ArrayList<OaNotificationUser> oaNotificationUsers = new ArrayList<>(); | 
|---|
|  |  |  | // 发送消息通知 | 
|---|
|  |  |  | if (dto.getType()){ | 
|---|
|  |  |  | // 指定人员发送 | 
|---|
|  |  |  | Arrays.asList(dto.getUserIds().split(",")) | 
|---|
|  |  |  | .forEach(userId -> { | 
|---|
|  |  |  | OaNotifationUser oaNotifationUser = new OaNotifationUser(); | 
|---|
|  |  |  | oaNotifationUser.setUserId(Integer.parseInt(userId)); | 
|---|
|  |  |  | oaNotifationUser.setNotificationId(dto.getId()); | 
|---|
|  |  |  | oaNotifationUsers.add(oaNotifationUser); | 
|---|
|  |  |  | OaNotificationUser oaNotificationUser = new OaNotificationUser(); | 
|---|
|  |  |  | oaNotificationUser.setUserId(Integer.parseInt(userId)); | 
|---|
|  |  |  | oaNotificationUser.setNotificationId(dto.getId()); | 
|---|
|  |  |  | oaNotificationUsers.add(oaNotificationUser); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | // 所有人发送 | 
|---|
|  |  |  | List<SysUser> sysUsers = sysUserService.selectAllList(); | 
|---|
|  |  |  | sysUsers.forEach(sysUser -> { | 
|---|
|  |  |  | OaNotifationUser oaNotifationUser = new OaNotifationUser(); | 
|---|
|  |  |  | oaNotifationUser.setUserId(sysUser.getUserId().intValue()); | 
|---|
|  |  |  | oaNotifationUser.setNotificationId(dto.getId()); | 
|---|
|  |  |  | oaNotifationUsers.add(oaNotifationUser); | 
|---|
|  |  |  | OaNotificationUser oaNotificationUser = new OaNotificationUser(); | 
|---|
|  |  |  | oaNotificationUser.setUserId(sysUser.getUserId().intValue()); | 
|---|
|  |  |  | oaNotificationUser.setNotificationId(dto.getId()); | 
|---|
|  |  |  | oaNotificationUsers.add(oaNotificationUser); | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | oaNotifationUserService.saveBatch(oaNotifationUsers); | 
|---|
|  |  |  | oaNotifationUserService.saveBatch(oaNotificationUsers); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @ApiOperation(value = "消息通知详情") | 
|---|
|  |  |  | 
|---|
|  |  |  | StringBuilder deptName = new StringBuilder(); | 
|---|
|  |  |  | List<TDept> tDepts = deptService.list(); | 
|---|
|  |  |  | List<SysUser> sysUsers = sysUserService.selectAllList(); | 
|---|
|  |  |  | List<OaNotifationUser> notifationUsers = oaNotifationUserService.lambdaQuery().eq(OaNotifationUser::getNotificationId, id) | 
|---|
|  |  |  | List<OaNotificationUser> notifationUsers = oaNotifationUserService.lambdaQuery().eq(OaNotificationUser::getNotificationId, id) | 
|---|
|  |  |  | .list(); | 
|---|
|  |  |  | Map<Integer, String> deptMap = tDepts.stream().collect(Collectors.toMap(TDept::getId, TDept::getDeptName)); | 
|---|
|  |  |  | Map<Long, SysUser> userMap = sysUsers.stream().collect(Collectors.toMap(SysUser::getUserId, e->e)); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | List<NotificationUserDetailVO> notificationUserDetailVOS = new ArrayList<>(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (OaNotifationUser notifationUser : notifationUsers) { | 
|---|
|  |  |  | for (OaNotificationUser notifationUser : notifationUsers) { | 
|---|
|  |  |  | NotificationUserDetailVO notificationUserDetailVO = new NotificationUserDetailVO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(notifationUser, notificationUserDetailVO); | 
|---|
|  |  |  | SysUser sysUser = userMap.get(notifationUser.getUserId().longValue()); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | notificationDetailVO.setNotificationUserDetailVOS(notificationUserDetailVOS); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | return R.ok(notificationDetailVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|