|
@@ -0,0 +1,287 @@
|
|
|
+package com.lantone.security.facade;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.lantone.common.dto.GetHospitalTreeDTO;
|
|
|
+import com.lantone.common.dto.GetHospitalUserPageDTO;
|
|
|
+import com.lantone.common.dto.GetMyNoticeListDTO;
|
|
|
+import com.lantone.common.dto.GetNoticeInfoByIdDTO;
|
|
|
+import com.lantone.common.dto.ListManagePageDTO;
|
|
|
+import com.lantone.common.dto.SendToTopicDTO;
|
|
|
+import com.lantone.common.enums.IsDeleteEnum;
|
|
|
+import com.lantone.common.enums.StatusEnum;
|
|
|
+import com.lantone.common.exception.Asserts;
|
|
|
+import com.lantone.common.util.DateUtil;
|
|
|
+import com.lantone.common.util.ListUtil;
|
|
|
+import com.lantone.common.util.SysUserUtils;
|
|
|
+import com.lantone.common.vo.AddNoticeVO;
|
|
|
+import com.lantone.common.vo.GetHospitalUserVO;
|
|
|
+import com.lantone.common.vo.GetMyNoticeListVO;
|
|
|
+import com.lantone.common.vo.ListManagePageVO;
|
|
|
+import com.lantone.dblayermbg.entity.Dept;
|
|
|
+import com.lantone.dblayermbg.entity.DeptUser;
|
|
|
+import com.lantone.dblayermbg.entity.HospitalUser;
|
|
|
+import com.lantone.dblayermbg.entity.Notice;
|
|
|
+import com.lantone.dblayermbg.entity.NoticeUser;
|
|
|
+import com.lantone.dblayermbg.entity.User;
|
|
|
+import com.lantone.dblayermbg.facade.DeptFacade;
|
|
|
+import com.lantone.dblayermbg.facade.DeptUserFacade;
|
|
|
+import com.lantone.dblayermbg.facade.DictionaryInfoFacade;
|
|
|
+import com.lantone.dblayermbg.facade.HospitalFacade;
|
|
|
+import com.lantone.dblayermbg.facade.HospitalUserFacade;
|
|
|
+import com.lantone.dblayermbg.facade.NoticeFacade;
|
|
|
+import com.lantone.dblayermbg.facade.NoticeUserFacade;
|
|
|
+import com.lantone.dblayermbg.facade.UserFacade;
|
|
|
+import com.lantone.dblayermbg.service.impl.NoticeUserServiceImpl;
|
|
|
+import com.lantone.security.enums.DictionaryEnum;
|
|
|
+import com.lantone.security.enums.ReadTypeEnum;
|
|
|
+import com.lantone.security.enums.ReceiveTypeEnum;
|
|
|
+import com.lantone.security.enums.ReturnTypeEnum;
|
|
|
+import com.lantone.security.service.MessageService;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description: 站内通知管理-业务处理类
|
|
|
+ * @author: songxl
|
|
|
+ * @time: 2021/9/10 13:39
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class NoticeManagementFacade {
|
|
|
+ @Autowired
|
|
|
+ private NoticeUserFacade noticeUserFacade;
|
|
|
+ @Autowired
|
|
|
+ private UserFacade userFacade;
|
|
|
+ @Autowired
|
|
|
+ private NoticeFacade noticeFacade;
|
|
|
+ @Autowired
|
|
|
+ private HospitalFacade hospitalFacade;
|
|
|
+ @Autowired
|
|
|
+ private HospitalUserFacade hospitalUserFacade;
|
|
|
+ @Autowired
|
|
|
+ private DeptUserFacade deptUserFacade;
|
|
|
+ @Autowired
|
|
|
+ private DeptFacade deptFacade;
|
|
|
+ @Autowired
|
|
|
+ private DictionaryInfoFacade dictionaryInfoFacade;
|
|
|
+ @Autowired
|
|
|
+ private MessageService messageService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param getMyNoticeListVO
|
|
|
+ * @Description我的通知列表页
|
|
|
+ * @Return com.baomidou.mybatisplus.core.metadata.IPage<com.lantone.common.dto.GetMyNoticeListDTO>
|
|
|
+ */
|
|
|
+ public IPage<GetMyNoticeListDTO> listPage(GetMyNoticeListVO getMyNoticeListVO) {
|
|
|
+ getMyNoticeListVO.setId(SysUserUtils.getCurrentPrincipleId());
|
|
|
+ return noticeUserFacade.getBaseMapper().listPage(getMyNoticeListVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param listManagePageVO
|
|
|
+ * @Description通知管理列表页
|
|
|
+ * @Return com.baomidou.mybatisplus.core.metadata.IPage<com.lantone.common.dto.GetMyNoticeListDTO>
|
|
|
+ */
|
|
|
+ public IPage<ListManagePageDTO> listManagePage(ListManagePageVO listManagePageVO) {
|
|
|
+ listManagePageVO.setId(SysUserUtils.getCurrentPrincipleId());
|
|
|
+ return noticeFacade.getBaseMapper().listPage(listManagePageVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param addNoticeVO
|
|
|
+ * @Description添加通知
|
|
|
+ * @Return java.lang.Boolean
|
|
|
+ */
|
|
|
+ public Boolean add(AddNoticeVO addNoticeVO) {
|
|
|
+ addNoticeVO.setCreator(SysUserUtils.getCurrentPrincipleId());
|
|
|
+ User user = userFacade.getById(SysUserUtils.getCurrentPrincipleId());
|
|
|
+ if (user != null) {
|
|
|
+ addNoticeVO.setCreatorName(user.getName());
|
|
|
+ }
|
|
|
+ Notice notice = new Notice();
|
|
|
+ BeanUtils.copyProperties(addNoticeVO, notice);
|
|
|
+ notice.setCreator(SysUserUtils.getCurrentPrincipleId() + "");
|
|
|
+ notice.setGmtCreate(DateUtil.now());
|
|
|
+ //根据通知类型查询通知用户
|
|
|
+ Set<Long> userIds = new HashSet<>();
|
|
|
+ if (ReceiveTypeEnum.ALL.getKey().equals(addNoticeVO.getReceiveType())) {
|
|
|
+ //获取当前登录用户管理的医院
|
|
|
+ List<Long> hospitals = hospitalFacade.getBaseMapper()
|
|
|
+ .getHospitalTreeInfo(SysUserUtils.getCurrentHospitalId(), StatusEnum.Enable.getKey()).stream()
|
|
|
+ .map(GetHospitalTreeDTO::getHospitalId).collect(Collectors.toList());
|
|
|
+ //获取这些组织的用户
|
|
|
+ getUserByHospitals(hospitals, userIds);
|
|
|
+ } else if (ReceiveTypeEnum.CUSTOM.getKey().equals(addNoticeVO.getReceiveType())) {
|
|
|
+ if (ListUtil.isEmpty(addNoticeVO.getSendHospitals()) &&
|
|
|
+ ListUtil.isEmpty(addNoticeVO.getSendDepts()) &&
|
|
|
+ ListUtil.isEmpty(addNoticeVO.getSendUsers())) {
|
|
|
+ Asserts.fail("选择发送的用户为空~");
|
|
|
+ }
|
|
|
+ //获取通知的医院-转成用户
|
|
|
+ if (ListUtil.isNotEmpty(addNoticeVO.getSendHospitals())) {
|
|
|
+ getUserByHospitals(addNoticeVO.getSendHospitals(), userIds);
|
|
|
+ }
|
|
|
+ //获取通知的科室-转成用户
|
|
|
+ if (ListUtil.isNotEmpty(addNoticeVO.getSendDepts())) {
|
|
|
+ getUserByDepts(addNoticeVO.getSendDepts(), userIds);
|
|
|
+ }
|
|
|
+ if (ListUtil.isNotEmpty(addNoticeVO.getSendUsers())) {
|
|
|
+ userIds.addAll(addNoticeVO.getSendUsers());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Asserts.fail("接收类型不存在,请检查重新输入~");
|
|
|
+ }
|
|
|
+ if (userIds.isEmpty()) {
|
|
|
+ Asserts.fail("通知用户为空,请联系管理员~");
|
|
|
+ }
|
|
|
+ if (noticeFacade.save(notice)) {
|
|
|
+ //发送通知
|
|
|
+ return sendNotice(userIds, notice.getId());
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param userIds
|
|
|
+ * @param id
|
|
|
+ * @Description发送通知
|
|
|
+ * @Return java.lang.Boolean
|
|
|
+ */
|
|
|
+ private Boolean sendNotice(Set<Long> userIds, Long id) {
|
|
|
+ List<NoticeUser> noticeUsers = new ArrayList<>();
|
|
|
+ List<SendToTopicDTO> sendToTopics = new ArrayList<>();
|
|
|
+ userIds.stream().forEach(userId -> {
|
|
|
+ NoticeUser noticeUser = new NoticeUser();
|
|
|
+ noticeUser.setUserId(userId);
|
|
|
+ noticeUser.setNoticeId(id);
|
|
|
+ noticeUsers.add(noticeUser);
|
|
|
+ SendToTopicDTO sendToTopicDTO = new SendToTopicDTO();
|
|
|
+ sendToTopicDTO.setMessage("+1");
|
|
|
+ sendToTopicDTO.setTopic(userId+"");
|
|
|
+ sendToTopics.add(sendToTopicDTO);
|
|
|
+ });
|
|
|
+ messageService.sendToTopic(sendToTopics);
|
|
|
+ return new NoticeUserServiceImpl().saveBatch(noticeUsers);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param hospitals
|
|
|
+ * @param userIds
|
|
|
+ * @Description获取医院的用户
|
|
|
+ * @Return void
|
|
|
+ */
|
|
|
+ private void getUserByHospitals(List<Long> hospitals, Set<Long> userIds) {
|
|
|
+
|
|
|
+ if (ListUtil.isEmpty(hospitals)) {
|
|
|
+ Asserts.fail("当前管理员发送通知的组织集合为空,请联系管理员~");
|
|
|
+ }
|
|
|
+ //获取该医院的用户
|
|
|
+ userIds.addAll(hospitalUserFacade.list(new QueryWrapper<HospitalUser>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("hospital_id", hospitals)).stream().map(HospitalUser::getUserId).collect(Collectors.toSet()));
|
|
|
+
|
|
|
+ //获取医院的科室
|
|
|
+ getUserByDepts(deptFacade.list(new QueryWrapper<Dept>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("hospital_id", hospitals)).stream().map(Dept::getId).collect(Collectors.toList()), userIds);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param depts
|
|
|
+ * @param userIds
|
|
|
+ * @Description获取科室的用户
|
|
|
+ * @Return void
|
|
|
+ */
|
|
|
+ private void getUserByDepts(List<Long> depts, Set<Long> userIds) {
|
|
|
+ if (ListUtil.isEmpty(depts)) {
|
|
|
+ Asserts.fail("当前管理员发送通知的组织集合为空,请联系管理员~");
|
|
|
+ }
|
|
|
+ //获取该医院的用户
|
|
|
+ userIds.addAll(deptUserFacade.list(new QueryWrapper<DeptUser>()
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .in("dept_id", depts)).stream().map(DeptUser::getUserId).collect(Collectors.toSet()));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param id
|
|
|
+ * @param type
|
|
|
+ * @Description获取通知详情
|
|
|
+ * @Return com.lantone.common.dto.GetNoticeInfoByIdDTO
|
|
|
+ */
|
|
|
+ public GetNoticeInfoByIdDTO getNoticeInfoById(Long id, String type) {
|
|
|
+
|
|
|
+ GetNoticeInfoByIdDTO getNoticeInfoByIdDTO = new GetNoticeInfoByIdDTO();
|
|
|
+ //获取字典类型
|
|
|
+ Map<String, String> noticeType = dictionaryInfoFacade.getOneDicMap(ReturnTypeEnum.INTERFACE.getKey(),
|
|
|
+ DictionaryEnum.NOTICE_TYPE.getKey() + "");
|
|
|
+ Notice notice = noticeFacade.getById(id);
|
|
|
+ if (notice == null) {
|
|
|
+ Asserts.fail("通知不存在,请联系管理员~");
|
|
|
+ }
|
|
|
+ BeanUtils.copyProperties(notice, getNoticeInfoByIdDTO);
|
|
|
+ getNoticeInfoByIdDTO.setTypeName(noticeType.get(getNoticeInfoByIdDTO.getType()));
|
|
|
+ //我的通知点击查看要更新通知状态为已读
|
|
|
+ if ("1".equals(type)) {
|
|
|
+ if (!noticeUserFacade.update(new UpdateWrapper<NoticeUser>()
|
|
|
+ .set("status", ReadTypeEnum.READ.getKey())
|
|
|
+ .eq("user_id", SysUserUtils.getCurrentPrincipleId())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())
|
|
|
+ .eq("notice_id", notice.getId()))) {
|
|
|
+ Asserts.fail("通知已读状态更新失败,请联系管理员~");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return getNoticeInfoByIdDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param id
|
|
|
+ * @Description删除通知
|
|
|
+ * @Return boolean
|
|
|
+ */
|
|
|
+ public boolean deleteNoticeInfo(Long id) {
|
|
|
+ if (noticeFacade.update(new UpdateWrapper<Notice>()
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
+ .eq("id", id)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()))) {
|
|
|
+ return noticeUserFacade.update(new UpdateWrapper<NoticeUser>()
|
|
|
+ .set("is_deleted", IsDeleteEnum.Y.getKey())
|
|
|
+ .in("notice_id", id)
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey()));
|
|
|
+
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param
|
|
|
+ * @Description获取未读信息数量
|
|
|
+ * @Return java.lang.Integer
|
|
|
+ */
|
|
|
+ public Map<String, Integer> getNotNoticeCount() {
|
|
|
+ Map<String, Integer> out = new HashMap<>();
|
|
|
+ out.put("count", noticeUserFacade.count(new QueryWrapper<NoticeUser>()
|
|
|
+ .eq("user_id", SysUserUtils.getCurrentPrincipleId())
|
|
|
+ .eq("status", ReadTypeEnum.NOT_READ.getKey())
|
|
|
+ .eq("is_deleted", IsDeleteEnum.N.getKey())));
|
|
|
+ return out;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param getHospitalUserVO
|
|
|
+ * @Description获取用户列表
|
|
|
+ * @Return com.baomidou.mybatisplus.core.metadata.IPage<com.lantone.common.dto.GetHospitalUserPageDTO>
|
|
|
+ */
|
|
|
+ public IPage<GetHospitalUserPageDTO> getHospitalUser(GetHospitalUserVO getHospitalUserVO) {
|
|
|
+ return hospitalUserFacade.getBaseMapper().getHospitalUser(getHospitalUserVO);
|
|
|
+ }
|
|
|
+}
|