Browse Source

feat(log): log结合当前登录人

huey 2 năm trước cách đây
mục cha
commit
2008afe6a5

+ 5 - 0
src/main/java/com/dragon/tj/portal/auth/web/mapper/SysUserMapper.java

@@ -3,6 +3,10 @@ package com.dragon.tj.portal.auth.web.mapper;
 import com.dragon.tj.portal.auth.web.entity.SysUser;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+import java.util.Set;
 
 /**
  * <p>
@@ -15,4 +19,5 @@ import org.apache.ibatis.annotations.Mapper;
 @Mapper
 public interface SysUserMapper extends BaseMapper<SysUser> {
 
+    Set<String> getUserIds(@Param("itemCodes") List<String> itemCodes);
 }

+ 4 - 0
src/main/java/com/dragon/tj/portal/auth/web/service/SysDeptService.java

@@ -3,6 +3,8 @@ package com.dragon.tj.portal.auth.web.service;
 import com.dragon.tj.portal.auth.web.entity.SysDept;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import java.util.Set;
+
 /**
  * <p>
  * 部门表 服务类
@@ -13,4 +15,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface SysDeptService extends IService<SysDept> {
 
+
+    Set<String> getAllUserIds(Set<String> orgCode,boolean cascade);
 }

+ 24 - 1
src/main/java/com/dragon/tj/portal/auth/web/service/impl/SysDeptServiceImpl.java

@@ -1,11 +1,19 @@
 package com.dragon.tj.portal.auth.web.service.impl;
 
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.dragon.tj.portal.auth.web.entity.SysDept;
 import com.dragon.tj.portal.auth.web.mapper.SysDeptMapper;
+import com.dragon.tj.portal.auth.web.mapper.SysUserMapper;
 import com.dragon.tj.portal.auth.web.service.SysDeptService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+import java.util.Set;
+
 /**
  * <p>
  * 部门表 服务实现类
@@ -17,4 +25,19 @@ import org.springframework.stereotype.Service;
 @Service
 public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> implements SysDeptService {
 
+    @Autowired
+    private SysUserMapper sysUserMapper;
+
+    @Override
+    public Set<String> getAllUserIds(Set<String> orgCodeSet, boolean cascade) {
+        List<String> orgCodeList = Lists.newArrayList(orgCodeSet);
+        List<List<String>> codeSplit = CollUtil.split(orgCodeList, 800);
+
+        Set<String> userIdListRst = Sets.newHashSet();
+        for (List<String> itemCodes : codeSplit) {
+            Set<String> userIds = sysUserMapper.getUserIds(itemCodes);
+            userIdListRst.addAll(userIds);
+        }
+        return userIdListRst;
+    }
 }

+ 1 - 1
src/main/java/com/dragon/tj/portal/component/message/SseController.java

@@ -56,7 +56,7 @@ public class SseController {
         log.info("sseController req param is {}", JSON.toJSONString(messageInfoReq));
         LoginUser loginUser = tokenService.getLoginUser(request);
         log.info("sseController current people is {}", JSON.toJSONString(loginUser));
-        return messageInfoService.push(messageInfoReq);
+        return messageInfoService.push(messageInfoReq,loginUser);
     }
 
 

+ 2 - 1
src/main/java/com/dragon/tj/portal/service/MessageInfoService.java

@@ -1,5 +1,6 @@
 package com.dragon.tj.portal.service;
 
+import com.dragon.tj.portal.auth.model.LoginUser;
 import com.dragon.tj.portal.common.base.R;
 import com.dragon.tj.portal.common.dto.message.MessageInfoReq;
 import com.dragon.tj.portal.entity.MessageInfo;
@@ -15,5 +16,5 @@ import com.baomidou.mybatisplus.extension.service.IService;
  */
 public interface MessageInfoService extends IService<MessageInfo> {
 
-    R push(MessageInfoReq messag);
+    R push(MessageInfoReq messag, LoginUser loginUser);
 }

+ 74 - 38
src/main/java/com/dragon/tj/portal/service/impl/MessageInfoServiceImpl.java

@@ -3,11 +3,16 @@ package com.dragon.tj.portal.service.impl;
 import cn.hutool.core.collection.CollUtil;
 import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.dragon.tj.portal.auth.model.LoginUser;
+import com.dragon.tj.portal.auth.web.service.SysDeptService;
 import com.dragon.tj.portal.common.base.R;
 import com.dragon.tj.portal.common.constants.BusinessConstants;
+import com.dragon.tj.portal.common.convert.MessageReqConvert;
 import com.dragon.tj.portal.common.dto.message.MessageInfoReq;
 import com.dragon.tj.portal.common.dto.message.MessageInfoSend;
+import com.dragon.tj.portal.common.enums.MessageInfoErrorEnums;
 import com.dragon.tj.portal.common.enums.ScopeEnums;
+import com.dragon.tj.portal.component.exception.message.MessageInfoException;
 import com.dragon.tj.portal.component.message.KafkaInitialConfiguration;
 import com.dragon.tj.portal.component.message.MessageProducer;
 import com.dragon.tj.portal.entity.MessageInfo;
@@ -40,8 +45,14 @@ public class MessageInfoServiceImpl extends ServiceImpl<MessageInfoMapper, Messa
     @Autowired
     private MessageInfoScopeService messageInfoScopeService;
 
+    @Autowired
+    private SysDeptService sysDeptService;
+
+    @Autowired
+    private MessageReqConvert messageReqConvert;
+
     @Override
-    public R push(MessageInfoReq messageInfoReq) {
+    public R push(MessageInfoReq messageInfoReq, LoginUser loginUser) {
         return R.ok(this.doMessage(messageInfoReq));
     }
 
@@ -58,59 +69,84 @@ public class MessageInfoServiceImpl extends ServiceImpl<MessageInfoMapper, Messa
 
     /**
      * @author huey China.
-     * @Description : TODO 跟进选中范围 填充不同信息类型的用户标识messageClientIds
+     * @Description :
      * @Date Created in 2023/6/16 11:44
      */
     private boolean transferIds(MessageInfoReq messageInfoReq) {
-
+        // 120101510000 120000450200
+        //120222197001010001 120222197001010002
         boolean isSend = false;
         Integer messageType = messageInfoReq.getMessageType();
         Set<String> scopeIds = messageInfoReq.getScopeIds();
+        Set<String> messageClientIds = this.getMessageClientIds(messageType, scopeIds);
 
-        //登录人标识
-        Set<String> messageClientIds = Sets.newHashSet();
-
-        //测试联系人1
-        if (messageType.equals(BusinessConstants.DICT_ITEM_ID_2) && scopeIds.contains("1")) {
-            messageClientIds.add("c1");
-            messageClientIds.add("c2");
+        if (CollUtil.isNotEmpty(messageClientIds)) {
+            MessageInfoSend messageInfoSend = this.doSaveMessageInfo(messageInfoReq, messageClientIds);
+            isSend = producer.send(KafkaInitialConfiguration.sseTopic, JSON.toJSONString(messageInfoSend));
         }
+        return isSend;
+    }
+
+    private MessageInfoSend doSaveMessageInfo(MessageInfoReq messageInfoReq, Set<String> messageClientIds) {
+        Integer messageType = messageInfoReq.getMessageType();
         ScopeEnums scopeEnums = ScopeEnums.ofMessageType(messageType);
-        if (CollUtil.isNotEmpty(messageClientIds)) {
+        List<MessageInfoScope> insertList = Lists.newArrayList();
+        MessageInfoSend messageInfoSend = new MessageInfoSend();
+        messageInfoSend.setMessageInfoReq(messageInfoReq);
+        messageInfoSend.setClientIds(messageClientIds);
+        messageClientIds.forEach(e -> {
+            MessageInfoScope messageInfoScope = new MessageInfoScope();
+            messageInfoScope.setScopeId(e);
+            messageInfoScope.setScopeType(scopeEnums.value());
+            //messageInfoScope.setScopeLevel("");
+            insertList.add(messageInfoScope);
+        });
+
+        MessageInfo messageInfo = messageReqConvert.reqToInfo(messageInfoReq);
+        // 存储
+        boolean isSaveBatchSuccess = false;
+        try {
+            isSaveBatchSuccess = this.save(messageInfo);
+            isSaveBatchSuccess = messageInfoScopeService.saveBatch(insertList);
+        } catch (Exception e) {
+            log.warn("消息中心 saveBatch 存储失败 {}");
+        }
 
-            List<MessageInfoScope> insertList = Lists.newArrayList();
-            MessageInfoSend messageInfoSend = new MessageInfoSend();
-            messageInfoSend.setMessageInfoReq(messageInfoReq);
-            messageInfoSend.setClientIds(messageClientIds);
-            messageClientIds.forEach(e->{
-                MessageInfoScope messageInfoScope = new MessageInfoScope();
-                messageInfoScope.setScopeId(e);
-                messageInfoScope.setScopeType(scopeEnums.value());
-                //messageInfoScope.setScopeLevel("");
-                insertList.add(messageInfoScope);
-            });
-
-
-            // 存储
-            boolean isSaveBatchSuccess = false;
+        // 批量存储失败,则逐个存储
+        if (!isSaveBatchSuccess) {
             try {
+                this.save(messageInfo);
+                insertList.forEach(e -> {
+                    messageInfoScopeService.save(e);
+                });
             } catch (Exception e) {
-                log.warn("消息中心 saveBatch 存储失败 {}");
+                log.warn("消息中心 存储失败 {}");
             }
+        }
+        return messageInfoSend;
+    }
 
-            // 批量存储失败,则逐个存储
-            if (!isSaveBatchSuccess) {
-                try {
-
-                } catch (Exception e) {
-                    log.warn("消息中心 存储失败 {}");
-                }
+    private Set<String> getMessageClientIds(Integer messageType, Set<String> scopeIds) {
+        //登录人标识
+        Set<String> messageClientIds = Sets.newHashSet();
+        if (CollUtil.isEmpty(scopeIds)) {
+            if (messageType.equals(BusinessConstants.DICT_ITEM_ID_2)) {
+                throw new MessageInfoException(MessageInfoErrorEnums.Code.MESSAGE_CONTRACTS_EMPTY);
+            } else {
+                throw new MessageInfoException(MessageInfoErrorEnums.Code.MESSAGE_DEPT_EMPTY);
             }
-
-
-            isSend = producer.send(KafkaInitialConfiguration.sseTopic, JSON.toJSONString(messageInfoSend));
         }
-        return isSend;
+        //测试联系人1
+        if (messageType.equals(BusinessConstants.DICT_ITEM_ID_2) && scopeIds.contains("1")) {
+            messageClientIds.add("c1");
+            messageClientIds.add("c2");
+        } else {
+            Set<String> allUserIds = sysDeptService.getAllUserIds(scopeIds, false);
+            if (CollUtil.isNotEmpty(allUserIds)) {
+                messageClientIds.addAll(allUserIds);
+            }
+        }
+        return messageClientIds;
     }
 
 

+ 7 - 0
src/main/resources/mapper/auth/web/SysUserMapper.xml

@@ -35,5 +35,12 @@
     <sql id="Base_Column_List">
         idcard, name, police_number, org_code, org_name, user_type, deleted, update_time, rank, title, man_type, police_category, police_business, sex, birth, nation, address, phone, mobile_work, mobile_private, qq_account, email, wx_account, post_type, job_type
     </sql>
+    <select id="getUserIds" resultType="java.lang.String">
+        select idcard from sys_user
+        where org_code in
+            <foreach collection="itemCodes" index="index" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+    </select>
 
 </mapper>