| | |
| | | package com.ltkj.web.controller.system; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ltkj.common.core.domain.entity.SysUser; |
| | | import com.ltkj.common.core.domain.model.LoginUser; |
| | |
| | | import com.ltkj.hosp.domain.SysNoticeUser; |
| | | import com.ltkj.hosp.service.SysNoticeUserService; |
| | | import com.ltkj.system.service.ISysUserService; |
| | | import com.ltkj.web.websocket.ClientSessionInfo; |
| | | import com.ltkj.web.websocket.WebSockerManager; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import com.ltkj.common.enums.BusinessType; |
| | | import com.ltkj.system.domain.SysNotice; |
| | | import com.ltkj.system.service.ISysNoticeService; |
| | | import org.springframework.web.socket.TextMessage; |
| | | import org.springframework.web.socket.WebSocketSession; |
| | | |
| | | /** |
| | | * 公告 信息操作处理 |
| | |
| | | private SysNoticeUserService sysNoticeUserService; |
| | | @Autowired |
| | | private ISysUserService userService; |
| | | @Autowired |
| | | private WebSockerManager webSockerManager; |
| | | |
| | | /** |
| | | * 获取通知公告列表 |
| | |
| | | public TableDataInfo list(SysNotice notice) { |
| | | startPage(); |
| | | List<SysNotice> list = noticeService.selectNoticeList(notice); |
| | | for (SysNotice sysNotice : list) { |
| | | LambdaQueryWrapper<SysNoticeUser> wq = new LambdaQueryWrapper<>(); |
| | | wq.eq(SysNoticeUser::getNoticeId, sysNotice.getNoticeId()); |
| | | List<SysNoticeUser> sysNoticeUsers = sysNoticeUserService.list(wq); |
| | | if(null != sysNoticeUsers && !sysNoticeUsers.isEmpty()){ |
| | | List<String> longList = sysNoticeUsers.stream().map(i -> i.getUserId().toString()).collect(Collectors.toList()); |
| | | sysNotice.setUserIds(longList); |
| | | } |
| | | } |
| | | return getDataTable(list); |
| | | } |
| | | |
| | |
| | | // @PreAuthorize("@ss.hasPermi('system:notice:query')") |
| | | @GetMapping(value = "/{noticeId}") |
| | | public AjaxResult getInfo(@PathVariable Long noticeId) { |
| | | return success(noticeService.selectNoticeById(noticeId)); |
| | | SysNotice byId = noticeService.getById(noticeId); |
| | | LambdaQueryWrapper<SysNoticeUser> wq = new LambdaQueryWrapper<>(); |
| | | wq.eq(SysNoticeUser::getNoticeId, noticeId); |
| | | List<SysNoticeUser> sysNoticeUsers = sysNoticeUserService.list(wq); |
| | | if(null != sysNoticeUsers && !sysNoticeUsers.isEmpty()){ |
| | | List<String> longList = sysNoticeUsers.stream().map(i -> i.getUserId().toString()).collect(Collectors.toList()); |
| | | byId.setUserIds(longList); |
| | | } |
| | | return success(byId); |
| | | } |
| | | |
| | | /** |
| | |
| | | public AjaxResult add(@Validated @RequestBody SysNotice notice) { |
| | | notice.setCreateBy(getUsername()); |
| | | notice.setNoticeId(IdUtil.getSnowflake().nextId()); |
| | | int insertNotice = noticeService.insertNotice(notice); |
| | | if (insertNotice > 0){ |
| | | boolean insertNotice = noticeService.save(notice); |
| | | if (insertNotice){ |
| | | if (notice.getUserIds() == null || notice.getUserIds().isEmpty()){ |
| | | if (StrUtil.isBlank(notice.getDeptId())){ |
| | | notice.setUserIds(userService.list().stream().map(i -> String.valueOf(i.getUserId())).collect(Collectors.toList())); |
| | |
| | | sysNoticeUserService.save(user); |
| | | } |
| | | }else return AjaxResult.error(); |
| | | for (Map.Entry<String, ClientSessionInfo> entry : webSockerManager.userSessions.entrySet()) { |
| | | if (!notice.getUserIds().contains(entry.getKey())) continue; |
| | | WebSocketSession session = entry.getValue().getSession(); |
| | | try { |
| | | session.sendMessage(new TextMessage(JSONUtil.toJsonStr(notice))); |
| | | } catch (IOException ignored) { |
| | | } |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | |
| | | @PutMapping |
| | | public AjaxResult edit(@Validated @RequestBody SysNotice notice) { |
| | | notice.setUpdateBy(getUsername()); |
| | | return toAjax(noticeService.updateNotice(notice)); |
| | | List<String> userIds = notice.getUserIds(); |
| | | if (noticeService.updateById(notice)) { |
| | | if(null !=userIds && !userIds.isEmpty()){ |
| | | LambdaQueryWrapper<SysNoticeUser> wq = new LambdaQueryWrapper<>(); |
| | | wq.eq(SysNoticeUser::getNoticeId, notice.getNoticeId()); |
| | | sysNoticeUserService.remove(wq); |
| | | for (String userId : userIds) { |
| | | SysNoticeUser user = new SysNoticeUser(); |
| | | user.setId(IdUtil.getSnowflake().nextId()); |
| | | user.setNoticeId(notice.getNoticeId()); |
| | | user.setUserId(Long.valueOf(userId)); |
| | | sysNoticeUserService.save(user); |
| | | } |
| | | } |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | return AjaxResult.error(); |
| | | } |
| | | |
| | | /** |