diff --git a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/DefaultDatabaseQueryTest.java b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/DefaultDatabaseQueryTest.java index 41b1dae33..1a8b3c14b 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/DefaultDatabaseQueryTest.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/test/java/cn/iocoder/yudao/module/infra/service/DefaultDatabaseQueryTest.java @@ -1,10 +1,10 @@ package cn.iocoder.yudao.module.infra.service; import cn.hutool.core.util.StrUtil; -import com.baomidou.mybatisplus.generator.IDatabaseQuery.DefaultDatabaseQuery; import com.baomidou.mybatisplus.generator.config.DataSourceConfig; import com.baomidou.mybatisplus.generator.config.builder.ConfigBuilder; import com.baomidou.mybatisplus.generator.config.po.TableInfo; +import com.baomidou.mybatisplus.generator.query.DefaultQuery; import java.util.List; @@ -19,7 +19,7 @@ public class DefaultDatabaseQueryTest { ConfigBuilder builder = new ConfigBuilder(null, dataSourceConfig, null, null, null, null); - DefaultDatabaseQuery query = new DefaultDatabaseQuery(builder); + DefaultQuery query = new DefaultQuery(builder); long time = System.currentTimeMillis(); List tableInfos = query.queryTables(); diff --git a/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java b/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java index 61e777f58..66e8ddd43 100644 --- a/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java +++ b/yudao-module-mp/yudao-module-mp-api/src/main/java/cn/iocoder/yudao/module/mp/enums/ErrorCodeConstants.java @@ -27,6 +27,10 @@ public interface ErrorCodeConstants { ErrorCode TAG_DELETE_FAIL = new ErrorCode(1006002001, "删除标签失败,原因:{}"); ErrorCode TAG_GET_FAIL = new ErrorCode(1006002001, "获得标签失败,原因:{}"); + // ========== 公众号标签 1006003000============ + ErrorCode USER_NOT_EXISTS = new ErrorCode(1006003000, "用户不存在"); + ErrorCode USER_UPDATE_TAG_FAIL = new ErrorCode(1006003001, "更新用户标签失败,原因:{}"); + // TODO 要处理下 ErrorCode COMMON_NOT_EXISTS = new ErrorCode(1006001002, "用户不存在"); diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/tag/MpTagController.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/tag/MpTagController.java index 1983568b9..1ae7751fe 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/tag/MpTagController.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/tag/MpTagController.java @@ -2,10 +2,7 @@ package cn.iocoder.yudao.module.mp.controller.admin.tag; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.mp.controller.admin.tag.vo.MpTagCreateReqVO; -import cn.iocoder.yudao.module.mp.controller.admin.tag.vo.MpTagPageReqVO; -import cn.iocoder.yudao.module.mp.controller.admin.tag.vo.MpTagRespVO; -import cn.iocoder.yudao.module.mp.controller.admin.tag.vo.MpTagUpdateReqVO; +import cn.iocoder.yudao.module.mp.controller.admin.tag.vo.*; import cn.iocoder.yudao.module.mp.convert.tag.MpTagConvert; import cn.iocoder.yudao.module.mp.dal.dataobject.tag.MpTagDO; import cn.iocoder.yudao.module.mp.service.tag.MpTagService; @@ -18,6 +15,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; +import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -62,6 +60,14 @@ public class MpTagController { return success(MpTagConvert.INSTANCE.convertPage(pageResult)); } + @GetMapping("/list-all-simple") + @ApiOperation(value = "获取公众号账号精简信息列表") + @PreAuthorize("@ss.hasPermission('mp:account:query')") + public CommonResult> getSimpleTags() { + List list = mpTagService.getTagList(); + return success(MpTagConvert.INSTANCE.convertList02(list)); + } + @PostMapping("/sync") @ApiOperation("同步公众号标签") @ApiImplicitParam(name = "accountId", value = "公众号账号的编号", required = true, dataTypeClass = Long.class) diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/tag/vo/MpTagSimpleRespVO.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/tag/vo/MpTagSimpleRespVO.java new file mode 100644 index 000000000..75f68a6c9 --- /dev/null +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/tag/vo/MpTagSimpleRespVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.mp.controller.admin.tag.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@ApiModel("管理后台 - 公众号标签精简信息 Response VO") +@Data +public class MpTagSimpleRespVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "公众号的标签编号", required = true, example = "2048") + private Long tagId; + + @ApiModelProperty(value = "标签名称", required = true, example = "快乐") + private String name; + +} diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/MpUserController.http b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/MpUserController.http index 03a14c590..7c615810f 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/MpUserController.http +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/MpUserController.http @@ -3,3 +3,16 @@ POST {{baseUrl}}/mp/user/sync?accountId=1 Content-Type: application/json Authorization: Bearer {{token}} tenant-id: {{adminTenentId}} + +### 请求 /mp/user/update 接口 => 成功 +PUT {{baseUrl}}/mp/user/update +Content-Type: application/json +Authorization: Bearer {{token}} +tenant-id: {{adminTenentId}} + +{ + "id": "3", + "nickname": "test", + "remark": "测试备注", + "tagIds": [103, 104] +} diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/MpUserController.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/MpUserController.java index fc53c8dec..d446c1cfe 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/MpUserController.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/MpUserController.java @@ -2,7 +2,9 @@ package cn.iocoder.yudao.module.mp.controller.admin.user; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.mp.controller.admin.user.vo.*; +import cn.iocoder.yudao.module.mp.controller.admin.user.vo.MpUserPageReqVO; +import cn.iocoder.yudao.module.mp.controller.admin.user.vo.MpUserRespVO; +import cn.iocoder.yudao.module.mp.controller.admin.user.vo.MpUserUpdateReqVO; import cn.iocoder.yudao.module.mp.convert.user.MpUserConvert; import cn.iocoder.yudao.module.mp.dal.dataobject.user.MpUserDO; import cn.iocoder.yudao.module.mp.service.user.MpUserService; @@ -18,7 +20,7 @@ import javax.validation.Valid; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; -@Api(tags = "管理后台 - 微信公众号粉丝") +@Api(tags = "管理后台 - 公众号粉丝") @RestController @RequestMapping("/mp/user") @Validated @@ -28,13 +30,29 @@ public class MpUserController { private MpUserService mpUserService; @GetMapping("/page") - @ApiOperation("获得微信公众号粉丝分页") + @ApiOperation("获得公众号粉丝分页") @PreAuthorize("@ss.hasPermission('mp:user:query')") public CommonResult> getUserPage(@Valid MpUserPageReqVO pageVO) { PageResult pageResult = mpUserService.getUserPage(pageVO); return success(MpUserConvert.INSTANCE.convertPage(pageResult)); } + @GetMapping("/get") + @ApiOperation("获得公众号粉丝") + @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) + @PreAuthorize("@ss.hasPermission('mp:user:query')") + public CommonResult getUser(@RequestParam("id") Long id) { + return success(MpUserConvert.INSTANCE.convert(mpUserService.getUser(id))); + } + + @PutMapping("/update") + @ApiOperation("更新公众号粉丝") + @PreAuthorize("@ss.hasPermission('mp:user:update')") + public CommonResult updateUser(@Valid @RequestBody MpUserUpdateReqVO updateReqVO) { + mpUserService.updateUser(updateReqVO); + return success(true); + } + @PostMapping("/sync") @ApiOperation("同步公众号粉丝") @ApiImplicitParam(name = "accountId", value = "公众号账号的编号", required = true, dataTypeClass = Long.class) diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserBaseVO.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserBaseVO.java deleted file mode 100644 index 96c92d0a3..000000000 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserBaseVO.java +++ /dev/null @@ -1,58 +0,0 @@ -package cn.iocoder.yudao.module.mp.controller.admin.user.vo; - -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; -import org.springframework.format.annotation.DateTimeFormat; - -import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; - -/** -* 微信公众号粉丝 Base VO,提供给添加、修改、详细的子 VO 使用 -* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 -*/ -@Data -public class MpUserBaseVO { - - @ApiModelProperty(value = "用户标识") - private String openid; - - @ApiModelProperty(value = "订阅状态,0未关注,1已关注") - private Integer subscribeStatus; - - @ApiModelProperty(value = "订阅时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private Date subscribeTime; - - @ApiModelProperty(value = "订阅时间") - @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) - private Date unsubscribeTime; - - @ApiModelProperty(value = "昵称") - private String nickname; - - @ApiModelProperty(value = "语言") - private String language; - - @ApiModelProperty(value = "国家") - private String country; - - @ApiModelProperty(value = "省份") - private String province; - - @ApiModelProperty(value = "城市") - private String city; - - @ApiModelProperty(value = "头像地址") - private String headImageUrl; - - @ApiModelProperty(value = "备注") - private String remark; - - @ApiModelProperty(value = "微信公众号ID") - private Long accountId; - - @ApiModelProperty(value = "微信公众号appid") - private String appId; - -} diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserPageReqVO.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserPageReqVO.java index 7ed1576cb..1ed34b6a7 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserPageReqVO.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserPageReqVO.java @@ -1,22 +1,28 @@ package cn.iocoder.yudao.module.mp.controller.admin.user.vo; -import lombok.*; -import io.swagger.annotations.*; import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; -@ApiModel("管理后台 - 微信公众号粉丝分页 Request VO") +import javax.validation.constraints.NotNull; + +@ApiModel("管理后台 - 公众号粉丝分页 Request VO") @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) public class MpUserPageReqVO extends PageParam { - @ApiModelProperty(value = "用户标识") - private String openid; - - @ApiModelProperty(value = "昵称") - private String nickname; - - @ApiModelProperty(value = "微信公众号 ID") + @ApiModelProperty(value = "公众号账号的编号", required = true, example = "2048") + @NotNull(message = "公众号账号的编号不能为空") private Long accountId; + @ApiModelProperty(value = "公众号用户标识", example = "o6_bmjrPTlm6_2sgVt7hMZOPfL2M", notes = "模糊匹配") + private String openid; + + @ApiModelProperty(value = "公众号用户昵称", example = "芋艿", notes = "模糊匹配") + private String nickname; + } diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserRespVO.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserRespVO.java index 009e4f550..2654cad0f 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserRespVO.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserRespVO.java @@ -1,18 +1,53 @@ package cn.iocoder.yudao.module.mp.controller.admin.user.vo; -import lombok.*; -import java.util.*; -import io.swagger.annotations.*; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; -@ApiModel("管理后台 - 微信公众号粉丝 Response VO") +import java.time.LocalDateTime; +import java.util.Date; +import java.util.List; + +@ApiModel("管理后台 - 公众号粉丝 Response VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class MpUserRespVO extends MpUserBaseVO { +public class MpUserRespVO { - @ApiModelProperty(value = "编号", required = true) + @ApiModelProperty(value = "编号", required = true, example = "1024") private Long id; + @ApiModelProperty(value = "公众号用户标识", required = true, example = "o6_bmjrPTlm6_2sgVt7hMZOPfL2M") + private String openid; + + @ApiModelProperty(value = "关注状态", required = true, example = "1", notes = "参见 CommonStatusEnum 枚举") + private Integer subscribeStatus; + @ApiModelProperty(value = "关注时间", required = true) + private LocalDateTime subscribeTime; + @ApiModelProperty(value = "取消关注时间") + private LocalDateTime unsubscribeTime; + + @ApiModelProperty(value = "昵称", example = "芋道") + private String nickname; + @ApiModelProperty(value = "头像地址", example = "https://www.iocoder.cn/1.png") + private String headImageUrl; + @ApiModelProperty(value = "语言", example = "zh_CN") + private String language; + @ApiModelProperty(value = "国家", example = "中国") + private String country; + @ApiModelProperty(value = "省份", example = "广东省") + private String province; + @ApiModelProperty(value = "城市", example = "广州市") + private String city; + @ApiModelProperty(value = "备注", example = "你是一个芋头嘛") + private String remark; + + @ApiModelProperty(value = "标签编号数组", example = "1,2,3") + private List tagIds; + + @ApiModelProperty(value = "公众号账号的编号", required = true, example = "1") + private Long accountId; + @ApiModelProperty(value = "公众号账号的 appId", required = true, example = "wx1234567890") + private String appId; + @ApiModelProperty(value = "创建时间", required = true) private Date createTime; diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserUpdateReqVO.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserUpdateReqVO.java new file mode 100644 index 000000000..e367a3ee0 --- /dev/null +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/controller/admin/user/vo/MpUserUpdateReqVO.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.mp.controller.admin.user.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotNull; +import java.util.List; + +@ApiModel("管理后台 - 公众号粉丝更新 Request VO") +@Data +public class MpUserUpdateReqVO { + + @ApiModelProperty(value = "编号", required = true, example = "1024") + @NotNull(message = "编号不能为空") + private Long id; + + @ApiModelProperty(value = "昵称", example = "芋道") + private String nickname; + + @ApiModelProperty(value = "备注", example = "你是一个芋头嘛") + private String remark; + + @ApiModelProperty(value = "标签编号数组", example = "1,2,3") + private List tagIds; + +} diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/tag/MpTagConvert.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/tag/MpTagConvert.java index 64969c83d..726291fac 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/tag/MpTagConvert.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/tag/MpTagConvert.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.mp.convert.tag; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.mp.controller.admin.tag.vo.MpTagRespVO; +import cn.iocoder.yudao.module.mp.controller.admin.tag.vo.MpTagSimpleRespVO; import cn.iocoder.yudao.module.mp.controller.admin.tag.vo.MpTagUpdateReqVO; import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO; import cn.iocoder.yudao.module.mp.dal.dataobject.tag.MpTagDO; @@ -36,4 +37,6 @@ public interface MpTagConvert { }) MpTagDO convert(WxUserTag tag, MpAccountDO account); + List convertList02(List list); + } diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/user/MpUserConvert.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/user/MpUserConvert.java index df19c285d..9ad7edf74 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/user/MpUserConvert.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/user/MpUserConvert.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.mp.controller.admin.user.vo.MpUserRespVO; +import cn.iocoder.yudao.module.mp.controller.admin.user.vo.MpUserUpdateReqVO; import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO; import cn.iocoder.yudao.module.mp.dal.dataobject.user.MpUserDO; import me.chanjar.weixin.mp.bean.result.WxMpUser; @@ -49,4 +50,6 @@ public interface MpUserConvert { return CollectionUtils.convertList(wxUsers, wxUser -> convert(account, wxUser)); } + MpUserDO convert(MpUserUpdateReqVO bean); + } diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/tag/MpTagService.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/tag/MpTagService.java index 11422468d..44dcfb0a9 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/tag/MpTagService.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/tag/MpTagService.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.mp.controller.admin.tag.vo.MpTagUpdateReqVO; import cn.iocoder.yudao.module.mp.dal.dataobject.tag.MpTagDO; import javax.validation.Valid; +import java.util.List; /** * 公众号标签 Service 接口 @@ -45,6 +46,8 @@ public interface MpTagService { */ PageResult getTagPage(MpTagPageReqVO pageReqVO); + List getTagList(); + /** * 同步公众号标签 * diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/tag/MpTagServiceImpl.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/tag/MpTagServiceImpl.java index 88d13a847..e3b0074d9 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/tag/MpTagServiceImpl.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/tag/MpTagServiceImpl.java @@ -116,6 +116,11 @@ public class MpTagServiceImpl implements MpTagService { return mpTagMapper.selectPage(pageReqVO); } + @Override + public List getTagList() { + return mpTagMapper.selectList(); + } + @Override @Transactional(rollbackFor = Exception.class) public void syncTag(Long accountId) { @@ -127,7 +132,7 @@ public class MpTagServiceImpl implements MpTagService { try { wxTags = mpService.getUserTagService().tagGet(); } catch (WxErrorException e) { - throw new RuntimeException(e); + throw exception(TAG_GET_FAIL, e.getError().getErrorMsg()); } // 第二步,合并更新回自己的数据库;由于标签只有 100 个,所以直接 for 循环操作 diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/user/MpUserService.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/user/MpUserService.java index 1796103ec..61bb4f820 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/user/MpUserService.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/user/MpUserService.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.mp.service.user; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.mp.controller.admin.user.vo.MpUserPageReqVO; +import cn.iocoder.yudao.module.mp.controller.admin.user.vo.MpUserUpdateReqVO; import cn.iocoder.yudao.module.mp.dal.dataobject.user.MpUserDO; import me.chanjar.weixin.mp.bean.result.WxMpUser; @@ -74,4 +75,11 @@ public interface MpUserService { */ void updateUserUnsubscribe(String appId, String openId); + /** + * 更新公众号粉丝 + * + * @param updateReqVO 更新信息 + */ + void updateUser(MpUserUpdateReqVO updateReqVO); + } diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/user/MpUserServiceImpl.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/user/MpUserServiceImpl.java index 8aa4d4be6..66e8d119d 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/user/MpUserServiceImpl.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/user/MpUserServiceImpl.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.mp.controller.admin.user.vo.MpUserPageReqVO; +import cn.iocoder.yudao.module.mp.controller.admin.user.vo.MpUserUpdateReqVO; import cn.iocoder.yudao.module.mp.convert.user.MpUserConvert; import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO; import cn.iocoder.yudao.module.mp.dal.dataobject.user.MpUserDO; @@ -29,6 +30,10 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.USER_NOT_EXISTS; +import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.USER_UPDATE_TAG_FAIL; + /** * 微信公众号粉丝 Service 实现类 * @@ -156,14 +161,55 @@ public class MpUserServiceImpl implements MpUserService { } @Override - public void updateUserUnsubscribe(String appId, String openId) { - MpUserDO dbUser = mpUserMapper.selectByAppIdAndOpenid(appId, openId); + public void updateUserUnsubscribe(String appId, String openid) { + MpUserDO dbUser = mpUserMapper.selectByAppIdAndOpenid(appId, openid); if (dbUser == null) { - log.error("[updateUserUnsubscribe][微信公众号粉丝 appId({}) openId({}) 不存在]", appId, openId); + log.error("[updateUserUnsubscribe][微信公众号粉丝 appId({}) openid({}) 不存在]", appId, openid); return; } mpUserMapper.updateById(new MpUserDO().setId(dbUser.getId()).setSubscribeStatus(CommonStatusEnum.DISABLE.getStatus()) - .setSubscribeTime(LocalDateTime.now())); + .setUnsubscribeTime(LocalDateTime.now())); + } + + @Override + public void updateUser(MpUserUpdateReqVO updateReqVO) { + // 校验存在 + MpUserDO user = validateUserExists(updateReqVO.getId()); + + // 第一步,更新标签到公众号 + updateUserTag(user.getAppId(), user.getOpenid(), updateReqVO.getTagIds()); + + // 第二步,更新基本信息到数据库 + MpUserDO updateObj = MpUserConvert.INSTANCE.convert(updateReqVO).setId(user.getId()); + mpUserMapper.updateById(updateObj); + } + + private MpUserDO validateUserExists(Long id) { + MpUserDO user = mpUserMapper.selectById(id); + if (user == null) { + throw exception(USER_NOT_EXISTS); + } + return user; + } + + private void updateUserTag(String appId, String openid, List tagIds) { + WxMpService mpService = mpServiceFactory.getRequiredMpService(appId); + try { + // 第一步,先取消原来的标签 + List oldTagIds = mpService.getUserTagService().userTagList(openid); + for (Long tagId : oldTagIds) { + mpService.getUserTagService().batchUntagging(tagId, new String[]{openid}); + } + // 第二步,再设置新的标签 + if (CollUtil.isEmpty(tagIds)) { + return; + } + for (Long tagId: tagIds) { + mpService.getUserTagService().batchTagging(tagId, new String[]{openid}); + } + } catch (WxErrorException e) { + throw exception(USER_UPDATE_TAG_FAIL, e.getError().getErrorMsg()); + } } } diff --git a/yudao-ui-admin/src/api/mp/tag.js b/yudao-ui-admin/src/api/mp/tag.js index b0f3b4f0f..189728864 100644 --- a/yudao-ui-admin/src/api/mp/tag.js +++ b/yudao-ui-admin/src/api/mp/tag.js @@ -43,6 +43,14 @@ export function getTagPage(query) { }) } +// 获取公众号标签精简信息列表 +export function getSimpleTags() { + return request({ + url: '/mp/tag/list-all-simple', + method: 'get', + }) +} + // 同步公众号标签 export function syncTag(accountId) { return request({ diff --git a/yudao-ui-admin/src/api/mp/user.js b/yudao-ui-admin/src/api/mp/user.js new file mode 100644 index 000000000..bde0bd215 --- /dev/null +++ b/yudao-ui-admin/src/api/mp/user.js @@ -0,0 +1,35 @@ +import request from '@/utils/request' + +// 更新公众号粉丝 +export function updateUser(data) { + return request({ + url: '/mp/user/update', + method: 'put', + data: data + }) +} + +// 获得公众号粉丝 +export function getUser(id) { + return request({ + url: '/mp/user/get?id=' + id, + method: 'get' + }) +} + +// 获得公众号粉丝分页 +export function getUserPage(query) { + return request({ + url: '/mp/user/page', + method: 'get', + params: query + }) +} + +// 同步公众号粉丝 +export function syncUser(accountId) { + return request({ + url: '/mp/tag/sync?accountId=' + accountId, + method: 'post' + }) +} diff --git a/yudao-ui-admin/src/api/wechatMp/wxAccountFans.js b/yudao-ui-admin/src/api/wechatMp/wxAccountFans.js deleted file mode 100644 index 59c5a6393..000000000 --- a/yudao-ui-admin/src/api/wechatMp/wxAccountFans.js +++ /dev/null @@ -1,54 +0,0 @@ -import request from '@/utils/request' - -// 创建微信公众号粉丝 -export function createWxAccountFans(data) { - return request({ - url: '/wechatMp/wx-account-fans/create', - method: 'post', - data: data - }) -} - -// 更新微信公众号粉丝 -export function updateWxAccountFans(data) { - return request({ - url: '/wechatMp/wx-account-fans/update', - method: 'put', - data: data - }) -} - -// 删除微信公众号粉丝 -export function deleteWxAccountFans(id) { - return request({ - url: '/wechatMp/wx-account-fans/delete?id=' + id, - method: 'delete' - }) -} - -// 获得微信公众号粉丝 -export function getWxAccountFans(id) { - return request({ - url: '/wechatMp/wx-account-fans/get?id=' + id, - method: 'get' - }) -} - -// 获得微信公众号粉丝分页 -export function getWxAccountFansPage(query) { - return request({ - url: '/wechatMp/wx-account-fans/page', - method: 'get', - params: query - }) -} - -// 导出微信公众号粉丝 Excel -export function exportWxAccountFansExcel(query) { - return request({ - url: '/wechatMp/wx-account-fans/export-excel', - method: 'get', - params: query, - responseType: 'blob' - }) -} diff --git a/yudao-ui-admin/src/views/mp/user/index.vue b/yudao-ui-admin/src/views/mp/user/index.vue new file mode 100644 index 000000000..1af2d6c85 --- /dev/null +++ b/yudao-ui-admin/src/views/mp/user/index.vue @@ -0,0 +1,235 @@ + + + diff --git a/yudao-ui-admin/src/views/wechatMp/wxAccountFans/index.vue b/yudao-ui-admin/src/views/wechatMp/wxAccountFans/index.vue deleted file mode 100644 index 23a4ebf66..000000000 --- a/yudao-ui-admin/src/views/wechatMp/wxAccountFans/index.vue +++ /dev/null @@ -1,334 +0,0 @@ - - -