提交 9068bf4c 作者: 沈振路

刷新既不在“全量用户”也不在“小程序用户”标签下的用户标签刷为“全量用户”的测试类接口

上级 01c33dd5
...@@ -3,3 +3,5 @@ ...@@ -3,3 +3,5 @@
/customer-service/ /customer-service/
/test-customer-service/ /test-customer-service/
/.idea/ /.idea/
/.cursor
/.claude
\ No newline at end of file
package com.yaoyaozw.customer.dto.wechat;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 批量更新用户标签请求体
*/
@Data
public class BatchTaggingDTO implements Serializable {
private static final long serialVersionUID = 1L;
private List<String> openid_list;
private Integer tagid;
}
package com.yaoyaozw.customer.dto.wechat;
import lombok.Data;
import java.io.Serializable;
/**
* 查询标签下用户列表请求体
*/
@Data
public class TagUserQueryDTO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer tagid;
private String next_openid;
}
package com.yaoyaozw.customer.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.yaoyaozw.customer.vo.wechat.AuthorizerFullUserTagVO;
import com.yaoyaozw.customer.vo.wechat.PendingAuthAccountVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 公众号用户标签清洗
*/
@Repository
@DS("material")
public interface WeChatTagCleanMapper {
/**
* 查询待处理的公众号列表
*/
List<PendingAuthAccountVO> getPendingAuthAccounts();
/**
* 批量查询指定授权方下多个标签在微信侧的 id(循环外一次查询)
*
* @param authorizerIds 授权方 id 列表(与 PendingAuthAccountVO#getAuthId 一致)
* @param tagNames 标签名称列表
* @return 每个授权方每条标签对应一条可用的 wechat_tag 记录
*/
List<AuthorizerFullUserTagVO> listFullUserWechatTagByAuthorizers(
@Param("authorizerIds") List<Long> authorizerIds,
@Param("tagNames") List<String> tagNames);
}
package com.yaoyaozw.customer.utils;
import cn.hutool.json.JSONUtil;
import com.yaoyaozw.customer.dto.wechat.BatchTaggingDTO;
import com.yaoyaozw.customer.dto.wechat.TagUserQueryDTO;
import com.yaoyaozw.customer.service.wechat.entity.WeChatResponseEntity;
import com.yaoyaozw.customer.vo.wechat.AllUserListVO;
import com.yaoyaozw.customer.vo.wechat.TagUserListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* 公众号标签相关接口封装
*/
@Slf4j
@Component
public class WeChatTagRest {
private static final String TAG_USER_LIST_URL = "https://api.weixin.qq.com/cgi-bin/user/tag/get";
private static final String ALL_USER_LIST_URL = "https://api.weixin.qq.com/cgi-bin/user/get";
private static final String BATCH_TAGGING_URL = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging";
/**
* 查询标签下用户列表
*/
public TagUserListVO getTagUserList(String accessToken, Integer tagid, String nextOpenid) {
Map<String, String> params = new HashMap<>(2);
params.put("access_token", accessToken);
TagUserQueryDTO body = new TagUserQueryDTO();
body.setTagid(tagid);
body.setNext_openid(nextOpenid == null ? "" : nextOpenid);
String result = HttpClientUtil.doPostJson(TAG_USER_LIST_URL, JSONUtil.toJsonStr(body), params);
return JSONUtil.toBean(result, TagUserListVO.class);
}
/**
* 查询公众号下所有用户列表
*/
public AllUserListVO getAllUserList(String accessToken, String nextOpenid) {
Map<String, String> params = new HashMap<>(2);
params.put("access_token", accessToken);
if (nextOpenid != null && !nextOpenid.isEmpty()) {
params.put("next_openid", nextOpenid);
}
String result = HttpClientUtil.doGet(ALL_USER_LIST_URL, params);
return JSONUtil.toBean(result, AllUserListVO.class);
}
/**
* 批量更新用户标签
*/
public WeChatResponseEntity batchTagging(String accessToken, BatchTaggingDTO body) {
Map<String, String> params = new HashMap<>(2);
params.put("access_token", accessToken);
String result = HttpClientUtil.doPostJson(BATCH_TAGGING_URL, JSONUtil.toJsonStr(body), params);
return JSONUtil.toBean(result, WeChatResponseEntity.class);
}
}
package com.yaoyaozw.customer.vo.wechat;
import lombok.Data;
import java.io.Serializable;
/**
* 查询公众号下所有用户列表响应
*/
@Data
public class AllUserListVO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer total;
private Integer count;
private OpenidDataVO data;
private String next_openid;
private Integer errcode;
private String errmsg;
}
package com.yaoyaozw.customer.vo.wechat;
import lombok.Data;
import java.io.Serializable;
/**
* 公众号「全量用户」标签在库中的映射,用于批量打标签时获取微信标签 id
*
* @author wgh
* @since 2026-05-18
*/
@Data
public class AuthorizerFullUserTagVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 授权方主体 id(与 pending 账号列表中的 authId 一致)
*/
private Long authorizerId;
/**
* 微信侧标签 id,对应接口 batch_tagging 的 tagid
*/
private Integer wechatTagId;
/**
* 标签名称
*/
private String tagName;
}
package com.yaoyaozw.customer.vo.wechat;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* openid数据
*/
@Data
public class OpenidDataVO implements Serializable {
private static final long serialVersionUID = 1L;
private List<String> openid;
}
package com.yaoyaozw.customer.vo.wechat;
import lombok.Data;
import java.io.Serializable;
/**
* 待处理公众号信息
*/
@Data
public class PendingAuthAccountVO implements Serializable {
private static final long serialVersionUID = 1L;
private Long authId;
private String appid;
private String nickName;
private String authorizerAccessToken;
}
package com.yaoyaozw.customer.vo.wechat;
import lombok.Data;
import java.io.Serializable;
/**
* 查询标签下用户列表响应
*/
@Data
public class TagUserListVO implements Serializable {
private static final long serialVersionUID = 1L;
private Integer count;
private OpenidDataVO data;
private String next_openid;
private Integer errcode;
private String errmsg;
}
<?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.yaoyaozw.customer.mapper.WeChatTagCleanMapper">
<select id="getPendingAuthAccounts" resultType="com.yaoyaozw.customer.vo.wechat.PendingAuthAccountVO">
SELECT
ai.id AS authId,
ai.appid AS appid,
ai.nick_name AS nickName,
atk.authorizer_access_token AS authorizerAccessToken
FROM authorizer_info ai
LEFT JOIN authorizer_token atk ON atk.authorizer_appid = ai.appid
WHERE ai.store_type IN (
'YANG_GUANG','TOMATO','YUE_WEN_1'
)
AND atk.create_time >= DATE_ADD(CURRENT_DATE,INTERVAL -1 DAY)
</select>
<select id="listFullUserWechatTagByAuthorizers"
resultType="com.yaoyaozw.customer.vo.wechat.AuthorizerFullUserTagVO">
SELECT
authorizer_id AS authorizerId,
wechat_tag_id AS wechatTagId,
tag_name AS tagName
FROM
`wechat_tag`
WHERE
tag_name IN
<foreach collection="tagNames" item="name" open="(" separator="," close=")">
#{name}
</foreach>
AND is_deleted = 0
AND authorizer_id IN
<foreach collection="authorizerIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论