Procházet zdrojové kódy

优化外部群查询列表
添加用戶列表

hxl13994548489 před 7 měsíci
rodič
revize
bc9775bee4

+ 2 - 0
linkwe-service/src/main/java/com/linkwechat/domain/weGroupFission/dto/DistDto.java

@@ -24,4 +24,6 @@ public class DistDto {
     @ApiModelProperty(value = "名称")
     private String name;
 
+    @ApiModelProperty(value = "unionid")
+    private String unionid;
 }

+ 69 - 0
linkwe-service/src/main/java/com/linkwechat/domain/weGroupFission/entity/WeExternalChat.java

@@ -0,0 +1,69 @@
+package com.linkwechat.domain.weGroupFission.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.linkwechat.common.annotation.Excel;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * @Description: 外部群基础信息表
+ * @Author: jeecg-boot
+ * @Date:   2026-02-10
+ * @Version: V1.0
+ */
+@Data
+@TableName("we_external_chat")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="we_external_chat对象", description="外部群基础信息表")
+public class WeExternalChat {
+    
+	/**主键*/
+	@TableId(type = IdType.ASSIGN_ID)
+    @ApiModelProperty(value = "主键")
+	private String id;
+	/**外部群ID*/
+	@Excel(name = "外部群ID", width = 15)
+    @ApiModelProperty(value = "外部群ID")
+	private String chatId;
+	/**群名称*/
+	@Excel(name = "群名称", width = 15)
+    @ApiModelProperty(value = "群名称")
+	private String chatName;
+	/**建群人企业微信ID*/
+	@Excel(name = "建群人企业微信ID", width = 15)
+    @ApiModelProperty(value = "建群人企业微信ID")
+	private String createUserId;
+	/**建群时间*/
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "建群时间")
+	private Date createTime;
+	/**建群场景:1=手动,2=接口*/
+	@Excel(name = "建群场景:1=手动,2=接口", width = 15)
+    @ApiModelProperty(value = "建群场景:1=手动,2=接口")
+	private String createScene;
+	/**是否解散:0=否,1=是*/
+	@Excel(name = "是否解散:0=否,1=是", width = 15)
+    @ApiModelProperty(value = "是否解散:0=否,1=是")
+	private String dismissFlag;
+	/**解散时间*/
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "解散时间")
+	private Date dismissTime;
+	/**修改时间*/
+	@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+	private Date updateTime;
+}

+ 17 - 0
linkwe-service/src/main/java/com/linkwechat/mapper/WeExternalChatMapper.java

@@ -0,0 +1,17 @@
+package com.linkwechat.mapper;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.linkwechat.domain.weGroupFission.entity.WeExternalChat;
+
+
+/**
+ * @Description: 外部群基础信息表
+ * @Author: jeecg-boot
+ * @Date:   2026-02-10
+ * @Version: V1.0
+ */
+@DS("master")
+public interface WeExternalChatMapper extends BaseMapper<WeExternalChat> {
+
+}

+ 16 - 0
linkwe-service/src/main/java/com/linkwechat/service/IWeExternalChatService.java

@@ -0,0 +1,16 @@
+package com.linkwechat.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.linkwechat.domain.weGroupFission.entity.WeExternalChat;
+
+
+/**
+ * @Description: 外部群基础信息表
+ * @Author: jeecg-boot
+ * @Date:   2026-02-10
+ * @Version: V1.0
+ */
+
+public interface IWeExternalChatService extends IService<WeExternalChat> {
+
+}

+ 20 - 0
linkwe-service/src/main/java/com/linkwechat/service/impl/WeExternalChatServiceImpl.java

@@ -0,0 +1,20 @@
+package com.linkwechat.service.impl;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.linkwechat.domain.weGroupFission.entity.WeExternalChat;
+import com.linkwechat.mapper.WeExternalChatMapper;
+import com.linkwechat.service.IWeExternalChatService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Description: 外部群基础信息表
+ * @Author: jeecg-boot
+ * @Date:   2026-02-10
+ * @Version: V1.0
+ */
+@DS("master")
+@Service
+public class WeExternalChatServiceImpl extends ServiceImpl<WeExternalChatMapper, WeExternalChat> implements IWeExternalChatService {
+
+}

+ 35 - 8
linkwe-service/src/main/java/com/linkwechat/service/impl/WeGroupFissionServiceImpl.java

@@ -2,9 +2,12 @@ package com.linkwechat.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
 import com.linkwechat.common.core.domain.AjaxResult;
 import com.linkwechat.common.core.domain.entity.SysUser;
 import com.linkwechat.common.core.domain.model.LoginUser;
@@ -19,6 +22,7 @@ import com.linkwechat.domain.weGroupFission.bdsh.LotteryActivity;
 import com.linkwechat.domain.weGroupFission.dto.DistDto;
 import com.linkwechat.domain.weGroupFission.dto.WeGroupFissionDetailDto;
 import com.linkwechat.domain.weGroupFission.dto.WeGroupFissionDto;
+import com.linkwechat.domain.weGroupFission.entity.WeExternalChat;
 import com.linkwechat.domain.weGroupFission.entity.WeGroupFission;
 import com.linkwechat.domain.weGroupFission.entity.WeGroupFissionExtraRecord;
 import com.linkwechat.domain.weGroupFission.entity.WeGroupFissionStepRecord;
@@ -41,6 +45,7 @@ import me.chanjar.weixin.cp.api.WxCpUserService;
 import me.chanjar.weixin.cp.bean.WxCpUser;
 import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatInfo;
 import me.chanjar.weixin.cp.bean.external.WxCpUserExternalGroupChatList;
+import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -84,6 +89,9 @@ public class WeGroupFissionServiceImpl extends ServiceImpl<WeGroupFissionMapper,
     @Autowired
     private  WxCpService wxCpService;
 
+    @Autowired
+    private IWeExternalChatService weExternalChatService;
+
 
     /**
      *  @version
@@ -426,12 +434,23 @@ public class WeGroupFissionServiceImpl extends ServiceImpl<WeGroupFissionMapper,
      *  @version
      *  @author: hxl
      *  @Date: 2026/1/28 16:42
-     *  @Description: 获取企业微信群列表
+     *  @Description: 获取企业微信群列表  优化
      */
     @Override
     public List<DistDto> getWecomGroupList() {
         List<DistDto> list = new ArrayList<>();
-        //获取企业微信群列表
+
+        List<WeExternalChat> chatList = weExternalChatService.list(new QueryWrapper<WeExternalChat>().eq("dismiss_flag", "0").orderByDesc("create_time"));
+
+        if(chatList!=null && !chatList.isEmpty()){
+            for (WeExternalChat weExternalChat : chatList) {
+                DistDto dto = new DistDto();
+                dto.setVal(weExternalChat.getChatId());
+                dto.setName(weExternalChat.getChatName());
+                list.add(dto);
+            }
+        }
+       /* //获取企业微信群列表
         WxCpExternalContactService externalContactService = wxCpService.getExternalContactService();
         try{
             // 调用获取客户群列表接口
@@ -452,9 +471,11 @@ public class WeGroupFissionServiceImpl extends ServiceImpl<WeGroupFissionMapper,
         }catch (Exception e){
              log.error(e.getMessage());
              return new ArrayList<>();
-        }
+        }*/
         return list;
     }
+    // 企微原生API - 用户详情
+    private static final String API_USER_DETAIL_GET = "https://qyapi.weixin.qq.com/cgi-bin/user/get?userid=%s";
     /**
      *  @version
      *  @author: hxl
@@ -463,28 +484,34 @@ public class WeGroupFissionServiceImpl extends ServiceImpl<WeGroupFissionMapper,
      */
     @Override
     public List<DistDto> getWecomEmployeeList() {
-        List<DistDto> list = new ArrayList<>();
+       /* List<DistDto> list = new ArrayList<>();
         //获取外部联系人列表
         WxCpExternalContactService externalContactService = wxCpService.getExternalContactService();
         try{
             List<String> followerUserIdList = externalContactService.listFollowers();
             // 4. 补充成员详情(沿用 4.1.0 版本支持的 getUserService())
             WxCpUserService userService = wxCpService.getUserService();
+            String accessToken = wxCpService.getAccessToken();
             for (String userId : followerUserIdList) {
-                WxCpUser userDetail = userService.getById(userId);
+                // WxCpUser userDetail = userService.getById(userId);
+                String requestUrl = String.format(API_USER_DETAIL_GET, userId);
+                String response = wxCpService.get(requestUrl,null);
+                JsonObject userDetail = JsonParser.parseString(response).getAsJsonObject();
+
                 if (userDetail == null) {
                     continue;
                 }
                 DistDto dto = new DistDto();
                 dto.setVal(userId);
-                dto.setName(userDetail.getName());
+                dto.setName(userDetail.get("name").getAsString());
+                dto.setUnionid(userDetail.get("unionid")!=null ?userDetail.get("unionid").getAsString():null);
                 list.add(dto);
             }
         }catch (Exception e){
             log.error(e.getMessage());
             return new ArrayList<>();
-        }
-        return list;
+        }*/
+        return getUserDictDtos();
     }
     /**
      *  @version

+ 5 - 0
linkwe-service/src/main/resources/mapper/wecom/WeExternalChatMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.linkwechat.mapper.WeExternalChatMapper">
+
+</mapper>