commit
3f68c25540
@ -1,165 +0,0 @@
|
||||
package cn.iocoder.yudao.module.mp.config;
|
||||
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountExportReqVO;
|
||||
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
|
||||
import cn.iocoder.yudao.module.mp.handler.*;
|
||||
import cn.iocoder.yudao.module.mp.service.account.WxAccountService;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
|
||||
import me.chanjar.weixin.mp.constant.WxMpEventConstants;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// TODO @芋艿:思考有没更好的处理方式
|
||||
@Component
|
||||
@EnableConfigurationProperties(WxMpProperties.class)
|
||||
@Slf4j
|
||||
public class WxMpConfig implements InitializingBean {
|
||||
|
||||
private static Map<String, WxMpMessageRouter> routers = Maps.newHashMap();
|
||||
private static Map<String, WxMpService> mpServices = Maps.newHashMap();
|
||||
|
||||
@Autowired
|
||||
private WxAccountService wxAccountService;
|
||||
@Autowired
|
||||
private WxMpProperties wxMpProperties;
|
||||
|
||||
private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L;
|
||||
|
||||
/**
|
||||
* 初始化公众号配置
|
||||
*/
|
||||
public synchronized void initWxConfig() {
|
||||
WxAccountExportReqVO req = new WxAccountExportReqVO();
|
||||
List<WxAccountDO> wxAccountList = wxAccountService.getWxAccountList(req);
|
||||
if (CollectionUtils.isEmpty(wxAccountList)) {
|
||||
return;
|
||||
}
|
||||
WxMpConfig.init(wxAccountList, wxMpProperties);
|
||||
log.info("加载公众号配置成功");
|
||||
}
|
||||
|
||||
|
||||
@Scheduled(fixedDelay = SCHEDULER_PERIOD, initialDelay = SCHEDULER_PERIOD)
|
||||
public void schedulePeriodicRefresh() {
|
||||
initWxConfig();
|
||||
}
|
||||
|
||||
public static void init(List<WxAccountDO> wxAccountDOS, WxMpProperties properties) {
|
||||
mpServices = wxAccountDOS.stream().map(wxAccountDO -> {
|
||||
// TODO 亚洲:使用 WxMpInMemoryConfigStorage 的话,多节点会不会存在 accessToken 冲突
|
||||
|
||||
WxMpDefaultConfigImpl configStorage;
|
||||
if (properties.isUseRedis()) {
|
||||
final WxMpProperties.RedisConfig redisConfig = properties.getRedisConfig();
|
||||
JedisPoolConfig poolConfig = new JedisPoolConfig();
|
||||
JedisPool jedisPool = new JedisPool(poolConfig, redisConfig.getHost(), redisConfig.getPort(),
|
||||
redisConfig.getTimeout(), redisConfig.getPassword());
|
||||
configStorage = new WxMpRedisConfigImpl(new JedisWxRedisOps(jedisPool), wxAccountDO.getAppId());
|
||||
} else {
|
||||
configStorage = new WxMpDefaultConfigImpl();
|
||||
}
|
||||
|
||||
configStorage.setAppId(wxAccountDO.getAppId());
|
||||
configStorage.setSecret(wxAccountDO.getAppSecret());
|
||||
configStorage.setToken(wxAccountDO.getToken());
|
||||
configStorage.setAesKey(wxAccountDO.getAesKey());
|
||||
|
||||
WxMpService service = new WxMpServiceImpl();
|
||||
service.setWxMpConfigStorage(configStorage);
|
||||
routers.put(wxAccountDO.getAppId(), newRouter(service));
|
||||
return service;
|
||||
}).collect(Collectors.toMap(s -> s.getWxMpConfigStorage().getAppId(), a -> a, (o, n) -> o));
|
||||
}
|
||||
|
||||
public static Map<String, WxMpMessageRouter> getRouters() {
|
||||
return routers;
|
||||
}
|
||||
|
||||
public static Map<String, WxMpService> getMpServices() {
|
||||
return mpServices;
|
||||
}
|
||||
|
||||
private static WxMpMessageRouter newRouter(WxMpService wxMpService) {
|
||||
final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService);
|
||||
// 记录所有事件的日志 (异步执行)
|
||||
newRouter.rule().handler(SpringUtil.getBean(LogHandler.class)).next();
|
||||
|
||||
// 接收客服会话管理事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxMpEventConstants.CustomerService.KF_CREATE_SESSION)
|
||||
.handler(SpringUtil.getBean(KfSessionHandler.class)).end();
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxMpEventConstants.CustomerService.KF_CLOSE_SESSION)
|
||||
.handler(SpringUtil.getBean(KfSessionHandler.class))
|
||||
.end();
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxMpEventConstants.CustomerService.KF_SWITCH_SESSION)
|
||||
.handler(SpringUtil.getBean(KfSessionHandler.class)).end();
|
||||
|
||||
// 门店审核事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxMpEventConstants.POI_CHECK_NOTIFY)
|
||||
.handler(SpringUtil.getBean(StoreCheckNotifyHandler.class)).end();
|
||||
|
||||
// 自定义菜单事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.MenuButtonType.CLICK).handler(SpringUtil.getBean(MenuHandler.class)).end();
|
||||
|
||||
// 点击菜单连接事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.MenuButtonType.VIEW).handler(SpringUtil.getBean(NullHandler.class)).end();
|
||||
|
||||
// 关注事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.SUBSCRIBE).handler(SpringUtil.getBean(SubscribeHandler.class))
|
||||
.end();
|
||||
|
||||
// 取消关注事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.UNSUBSCRIBE)
|
||||
.handler(SpringUtil.getBean(UnsubscribeHandler.class)).end();
|
||||
|
||||
// 上报地理位置事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.LOCATION).handler(SpringUtil.getBean(LocationHandler.class))
|
||||
.end();
|
||||
|
||||
// 接收地理位置消息
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.LOCATION)
|
||||
.handler(SpringUtil.getBean(LocationHandler.class)).end();
|
||||
|
||||
// 扫码事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.SCAN).handler(SpringUtil.getBean(ScanHandler.class)).end();
|
||||
|
||||
// 默认
|
||||
newRouter.rule().async(false).handler(SpringUtil.getBean(MsgHandler.class)).end();
|
||||
|
||||
return newRouter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
initWxConfig();
|
||||
}
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
package cn.iocoder.yudao.module.mp.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* wechat mp properties
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "wx.mp")
|
||||
public class WxMpProperties {
|
||||
/**
|
||||
* 是否使用redis存储access token
|
||||
*/
|
||||
private boolean useRedis;
|
||||
|
||||
private String defaultContent;
|
||||
|
||||
/**
|
||||
* redis 配置
|
||||
*/
|
||||
private RedisConfig redisConfig;
|
||||
|
||||
@Data
|
||||
public static class RedisConfig {
|
||||
/**
|
||||
* redis服务器 主机地址
|
||||
*/
|
||||
private String host;
|
||||
|
||||
/**
|
||||
* redis服务器 端口号
|
||||
*/
|
||||
private Integer port;
|
||||
|
||||
/**
|
||||
* redis服务器 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* redis 服务连接超时时间
|
||||
*/
|
||||
private Integer timeout;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
package cn.iocoder.yudao.module.mp.controller.admin.fanstag;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.*;
|
||||
import cn.iocoder.yudao.module.mp.convert.fanstag.WxFansTagConvert;
|
||||
import cn.iocoder.yudao.module.mp.service.tag.FansTagService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
|
||||
|
||||
/**
|
||||
* @author fengdan
|
||||
*/
|
||||
@Api(tags = "管理后台 - 粉丝标签")
|
||||
@RestController
|
||||
@RequestMapping("/wechatMp/fans-tag")
|
||||
@Validated
|
||||
public class FansTagController {
|
||||
|
||||
@Resource
|
||||
private FansTagService fansTagService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建粉丝标签")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:fans-tag:create')")
|
||||
public CommonResult<WxUserTag> createWxFansTag(@Valid @RequestBody FansTagCreateReqVO createReqVO) throws WxErrorException {
|
||||
return success(fansTagService.createWxFansTag(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("更新粉丝标签")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:fans-tag:update')")
|
||||
public CommonResult<Boolean> updateWxFansTag(@Valid @RequestBody FansTagUpdateReqVO updateReqVO) throws WxErrorException {
|
||||
return success(fansTagService.updateWxFansTag(updateReqVO));
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除粉丝标签")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:fans-tag:delete')")
|
||||
public CommonResult<Boolean> deleteWxFansTag(@RequestParam("id") Long id,
|
||||
@RequestParam("appId") String appId) throws WxErrorException {
|
||||
return success(fansTagService.deleteWxFansTag(id, appId));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获取公众号已创建的标签")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:fans-tag:query')")
|
||||
public CommonResult<List<FansTagRespVO>> getWxFansTagList(@NotEmpty(message = "公众号appId不能为空")
|
||||
@RequestParam("appId") String appId) throws WxErrorException {
|
||||
List<WxUserTag> list = fansTagService.getWxFansTagList(appId);
|
||||
return success(WxFansTagConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获取公众号已创建的标签")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:fans-tag:query')")
|
||||
public CommonResult<PageResult<FansTagRespVO>> page() throws WxErrorException {
|
||||
PageResult<WxUserTag> page = new PageResult<>();
|
||||
return success(WxFansTagConvert.INSTANCE.convertPage(page));
|
||||
}
|
||||
|
||||
@GetMapping("/tagListUser")
|
||||
@ApiOperation("获取标签下粉丝列表")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:fans-tag:query')")
|
||||
public CommonResult<String> tagListUser(@Valid FansTagPageReqVO pageVO) {
|
||||
return success("");
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@ApiOperation("导出粉丝标签 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:fans-tag:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportWxFansTagExcel(@Valid FansTagExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<WxUserTag> list = fansTagService.getWxFansTagList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<FansTagExcelVO> datas = WxFansTagConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "粉丝标签.xls", "数据", FansTagExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,103 +0,0 @@
|
||||
package cn.iocoder.yudao.module.mp.controller.admin.fanstag;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
|
||||
|
||||
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.*;
|
||||
import cn.iocoder.yudao.module.mp.dal.dataobject.fanstag.WxFansTagDO;
|
||||
import cn.iocoder.yudao.module.mp.convert.fanstag.WxFansTagConvert;
|
||||
import cn.iocoder.yudao.module.mp.service.fanstag.WxFansTagService;
|
||||
|
||||
@Api(tags = "管理后台 - 粉丝标签")
|
||||
@RestController
|
||||
@RequestMapping("/wechatMp/wx-fans-tag")
|
||||
@Validated
|
||||
public class WxFansTagController {
|
||||
|
||||
@Resource
|
||||
private WxFansTagService wxFansTagService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建粉丝标签")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:wx-fans-tag:create')")
|
||||
public CommonResult<Integer> createWxFansTag(@Valid @RequestBody WxFansTagCreateReqVO createReqVO) {
|
||||
return success(wxFansTagService.createWxFansTag(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@ApiOperation("更新粉丝标签")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:wx-fans-tag:update')")
|
||||
public CommonResult<Boolean> updateWxFansTag(@Valid @RequestBody WxFansTagUpdateReqVO updateReqVO) {
|
||||
wxFansTagService.updateWxFansTag(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@ApiOperation("删除粉丝标签")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Integer.class)
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:wx-fans-tag:delete')")
|
||||
public CommonResult<Boolean> deleteWxFansTag(@RequestParam("id") Integer id) {
|
||||
wxFansTagService.deleteWxFansTag(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@ApiOperation("获得粉丝标签")
|
||||
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Integer.class)
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:wx-fans-tag:query')")
|
||||
public CommonResult<WxFansTagRespVO> getWxFansTag(@RequestParam("id") Integer id) {
|
||||
WxFansTagDO wxFansTag = wxFansTagService.getWxFansTag(id);
|
||||
return success(WxFansTagConvert.INSTANCE.convert(wxFansTag));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("获得粉丝标签列表")
|
||||
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:wx-fans-tag:query')")
|
||||
public CommonResult<List<WxFansTagRespVO>> getWxFansTagList(@RequestParam("ids") Collection<Integer> ids) {
|
||||
List<WxFansTagDO> list = wxFansTagService.getWxFansTagList(ids);
|
||||
return success(WxFansTagConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("获得粉丝标签分页")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:wx-fans-tag:query')")
|
||||
public CommonResult<PageResult<WxFansTagRespVO>> getWxFansTagPage(@Valid WxFansTagPageReqVO pageVO) {
|
||||
PageResult<WxFansTagDO> pageResult = wxFansTagService.getWxFansTagPage(pageVO);
|
||||
return success(WxFansTagConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@ApiOperation("导出粉丝标签 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('wechatMp:wx-fans-tag:export')")
|
||||
@OperateLog(type = EXPORT)
|
||||
public void exportWxFansTagExcel(@Valid WxFansTagExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<WxFansTagDO> list = wxFansTagService.getWxFansTagList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<WxFansTagExcelVO> datas = WxFansTagConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "粉丝标签.xls", "数据", WxFansTagExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
/**
|
||||
* @author fengdan
|
||||
*/
|
||||
@ApiModel("管理后台 - 粉丝标签创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class FansTagCreateReqVO extends FansTagBaseVO {
|
||||
@NotBlank(message = "公众号appId不能为空")
|
||||
@ApiModelProperty("微信公众号appId")
|
||||
private String appId;
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo;
|
||||
|
||||
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;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
/**
|
||||
* @author fengdan
|
||||
*/
|
||||
@ApiModel("管理后台 - 粉丝标签分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class FansTagPageReqVO extends PageParam {
|
||||
|
||||
@NotEmpty(message = "公众号appId不能为空")
|
||||
@ApiModelProperty("微信公众号appId")
|
||||
private String appId;
|
||||
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
package cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo;
|
||||
|
||||
import lombok.*;
|
||||
import io.swagger.annotations.*;
|
||||
|
||||
@ApiModel("管理后台 - 粉丝标签创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class WxFansTagCreateReqVO extends WxFansTagBaseVO {
|
||||
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
package cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import io.swagger.annotations.*;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("管理后台 - 粉丝标签分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class WxFansTagPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "标签名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "粉丝数量")
|
||||
private Integer count;
|
||||
|
||||
@ApiModelProperty(value = "微信账号ID")
|
||||
private String wxAccountId;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "开始创建时间")
|
||||
private Date beginCreateTime;
|
||||
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
@ApiModelProperty(value = "结束创建时间")
|
||||
private Date endCreateTime;
|
||||
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
package cn.iocoder.yudao.module.mp.dal.dataobject.fanstag;
|
||||
|
||||
import lombok.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 粉丝标签 DO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName("wx_fans_tag")
|
||||
@KeySequence("wx_fans_tag_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WxFansTagDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 粉丝数量
|
||||
*/
|
||||
private Integer count;
|
||||
/**
|
||||
* 微信账号ID
|
||||
*/
|
||||
private String wxAccountId;
|
||||
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
package cn.iocoder.yudao.module.mp.dal.mysql.fanstag;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.mp.dal.dataobject.fanstag.WxFansTagDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.*;
|
||||
|
||||
/**
|
||||
* 粉丝标签 Mapper
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Mapper
|
||||
public interface WxFansTagMapper extends BaseMapperX<WxFansTagDO> {
|
||||
|
||||
default PageResult<WxFansTagDO> selectPage(WxFansTagPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<WxFansTagDO>()
|
||||
.likeIfPresent(WxFansTagDO::getName, reqVO.getName())
|
||||
.eqIfPresent(WxFansTagDO::getCount, reqVO.getCount())
|
||||
.eqIfPresent(WxFansTagDO::getWxAccountId, reqVO.getWxAccountId())
|
||||
.betweenIfPresent(WxFansTagDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
|
||||
.orderByDesc(WxFansTagDO::getId));
|
||||
}
|
||||
|
||||
default List<WxFansTagDO> selectList(WxFansTagExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<WxFansTagDO>()
|
||||
.likeIfPresent(WxFansTagDO::getName, reqVO.getName())
|
||||
.eqIfPresent(WxFansTagDO::getCount, reqVO.getCount())
|
||||
.eqIfPresent(WxFansTagDO::getWxAccountId, reqVO.getWxAccountId())
|
||||
.betweenIfPresent(WxFansTagDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
|
||||
.orderByDesc(WxFansTagDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
/**
|
||||
* @date 2022/6/20
|
||||
* @author feng-dan
|
||||
* @version 1.0
|
||||
*/
|
||||
package cn.iocoder.yudao.module.mp.framework;
|
||||
@ -0,0 +1,106 @@
|
||||
package cn.iocoder.yudao.module.mp.framework.weixin;
|
||||
|
||||
|
||||
import cn.iocoder.yudao.module.mp.handler.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.constant.WxMpEventConstants;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* @author fengdan
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class WxMpMessageRouterConfiguration {
|
||||
|
||||
@Resource
|
||||
private WxMpService wxMpService;
|
||||
@Resource
|
||||
private LogHandler logHandler;
|
||||
@Resource
|
||||
private KfSessionHandler kfSessionHandler;
|
||||
@Resource
|
||||
private StoreCheckNotifyHandler storeCheckNotifyHandler;
|
||||
@Resource
|
||||
private MenuHandler menuHandler;
|
||||
@Resource
|
||||
private NullHandler nullHandler;
|
||||
@Resource
|
||||
private SubscribeHandler subscribeHandler;
|
||||
@Resource
|
||||
private UnsubscribeHandler unsubscribeHandler;
|
||||
@Resource
|
||||
private LocationHandler locationHandler;
|
||||
@Resource
|
||||
private ScanHandler scanHandler;
|
||||
@Resource
|
||||
private MsgHandler msgHandler;
|
||||
|
||||
@Bean
|
||||
public WxMpMessageRouter messageRouter() {
|
||||
final WxMpMessageRouter newRouter = new WxMpMessageRouter(wxMpService);
|
||||
// 记录所有事件的日志 (异步执行)
|
||||
newRouter.rule().handler(logHandler).next();
|
||||
|
||||
// 接收客服会话管理事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxMpEventConstants.CustomerService.KF_CREATE_SESSION)
|
||||
.handler(kfSessionHandler).end();
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxMpEventConstants.CustomerService.KF_CLOSE_SESSION)
|
||||
.handler(kfSessionHandler)
|
||||
.end();
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxMpEventConstants.CustomerService.KF_SWITCH_SESSION)
|
||||
.handler(kfSessionHandler).end();
|
||||
|
||||
// 门店审核事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxMpEventConstants.POI_CHECK_NOTIFY)
|
||||
.handler(storeCheckNotifyHandler).end();
|
||||
|
||||
// 自定义菜单事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.MenuButtonType.CLICK).handler(menuHandler).end();
|
||||
|
||||
// 点击菜单连接事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.MenuButtonType.VIEW).handler(nullHandler).end();
|
||||
|
||||
// 关注事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.SUBSCRIBE).handler(subscribeHandler)
|
||||
.end();
|
||||
|
||||
// 取消关注事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.UNSUBSCRIBE)
|
||||
.handler(unsubscribeHandler).end();
|
||||
|
||||
// 上报地理位置事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.LOCATION).handler(locationHandler)
|
||||
.end();
|
||||
|
||||
// 接收地理位置消息
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.LOCATION)
|
||||
.handler(locationHandler).end();
|
||||
|
||||
// 扫码事件
|
||||
newRouter.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT)
|
||||
.event(WxConsts.EventType.SCAN).handler(scanHandler).end();
|
||||
|
||||
// 默认
|
||||
newRouter.rule().async(false).handler(msgHandler).end();
|
||||
|
||||
return newRouter;
|
||||
}
|
||||
}
|
||||
@ -1,71 +0,0 @@
|
||||
package cn.iocoder.yudao.module.mp.service.fanstag;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.*;
|
||||
import cn.iocoder.yudao.module.mp.dal.dataobject.fanstag.WxFansTagDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 粉丝标签 Service 接口
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
public interface WxFansTagService {
|
||||
|
||||
/**
|
||||
* 创建粉丝标签
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createWxFansTag(@Valid WxFansTagCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新粉丝标签
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateWxFansTag(@Valid WxFansTagUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除粉丝标签
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteWxFansTag(Integer id);
|
||||
|
||||
/**
|
||||
* 获得粉丝标签
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 粉丝标签
|
||||
*/
|
||||
WxFansTagDO getWxFansTag(Integer id);
|
||||
|
||||
/**
|
||||
* 获得粉丝标签列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 粉丝标签列表
|
||||
*/
|
||||
List<WxFansTagDO> getWxFansTagList(Collection<Integer> ids);
|
||||
|
||||
/**
|
||||
* 获得粉丝标签分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 粉丝标签分页
|
||||
*/
|
||||
PageResult<WxFansTagDO> getWxFansTagPage(WxFansTagPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得粉丝标签列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 粉丝标签列表
|
||||
*/
|
||||
List<WxFansTagDO> getWxFansTagList(WxFansTagExportReqVO exportReqVO);
|
||||
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
package cn.iocoder.yudao.module.mp.service.fanstag;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.*;
|
||||
import cn.iocoder.yudao.module.mp.dal.dataobject.fanstag.WxFansTagDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
|
||||
import cn.iocoder.yudao.module.mp.convert.fanstag.WxFansTagConvert;
|
||||
import cn.iocoder.yudao.module.mp.dal.mysql.fanstag.WxFansTagMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 粉丝标签 Service 实现类
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class WxFansTagServiceImpl implements WxFansTagService {
|
||||
|
||||
@Resource
|
||||
private WxFansTagMapper wxFansTagMapper;
|
||||
|
||||
@Override
|
||||
public Integer createWxFansTag(WxFansTagCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
WxFansTagDO wxFansTag = WxFansTagConvert.INSTANCE.convert(createReqVO);
|
||||
wxFansTagMapper.insert(wxFansTag);
|
||||
// 返回
|
||||
return wxFansTag.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWxFansTag(WxFansTagUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
this.validateWxFansTagExists(updateReqVO.getId());
|
||||
// 更新
|
||||
WxFansTagDO updateObj = WxFansTagConvert.INSTANCE.convert(updateReqVO);
|
||||
wxFansTagMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteWxFansTag(Integer id) {
|
||||
// 校验存在
|
||||
this.validateWxFansTagExists(id);
|
||||
// 删除
|
||||
wxFansTagMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateWxFansTagExists(Integer id) {
|
||||
if (wxFansTagMapper.selectById(id) == null) {
|
||||
throw exception(COMMON_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxFansTagDO getWxFansTag(Integer id) {
|
||||
return wxFansTagMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxFansTagDO> getWxFansTagList(Collection<Integer> ids) {
|
||||
return wxFansTagMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<WxFansTagDO> getWxFansTagPage(WxFansTagPageReqVO pageReqVO) {
|
||||
return wxFansTagMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxFansTagDO> getWxFansTagList(WxFansTagExportReqVO exportReqVO) {
|
||||
return wxFansTagMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.mp.service.tag;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.FansTagCreateReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.FansTagExportReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.FansTagPageReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.FansTagUpdateReqVO;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 粉丝标签 Service 接口
|
||||
*
|
||||
* @author fengdan
|
||||
*/
|
||||
public interface FansTagService {
|
||||
|
||||
/**
|
||||
* 创建粉丝标签
|
||||
*
|
||||
* @param createReqVO 创建标签信息
|
||||
* @return {@link WxUserTag} 用户标签对象
|
||||
* @throws WxErrorException 微信异常
|
||||
*/
|
||||
WxUserTag createWxFansTag(FansTagCreateReqVO createReqVO) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 更新粉丝标签
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
* @return {@link Boolean}
|
||||
* @throws WxErrorException 微信异常
|
||||
*/
|
||||
Boolean updateWxFansTag(@Valid FansTagUpdateReqVO updateReqVO) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 删除粉丝标签
|
||||
*
|
||||
* @param id 编号
|
||||
* @param appId 公众号appId
|
||||
* @return {@link Boolean}
|
||||
* @throws WxErrorException 微信异常
|
||||
*/
|
||||
Boolean deleteWxFansTag(Long id, String appId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取公众号已创建的标签
|
||||
*
|
||||
* @param appId 公众号appId
|
||||
* @return 粉丝标签列表
|
||||
* @throws WxErrorException 微信异常
|
||||
*/
|
||||
List<WxUserTag> getWxFansTagList(String appId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获得粉丝标签分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 粉丝标签分页
|
||||
*/
|
||||
PageResult<WxUserTag> getWxFansTagPage(FansTagPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得粉丝标签列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 粉丝标签列表
|
||||
*/
|
||||
List<WxUserTag> getWxFansTagList(FansTagExportReqVO exportReqVO);
|
||||
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package cn.iocoder.yudao.module.mp.service.tag;
|
||||
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.FansTagCreateReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.FansTagExportReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.FansTagPageReqVO;
|
||||
import cn.iocoder.yudao.module.mp.controller.admin.fanstag.vo.FansTagUpdateReqVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.bean.tag.WxUserTag;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 粉丝标签 Service 实现类
|
||||
*
|
||||
* @author fengdan
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Validated
|
||||
public class FansTagServiceImpl implements FansTagService {
|
||||
@Resource
|
||||
private WxMpService wxMpService;
|
||||
|
||||
@Override
|
||||
public WxUserTag createWxFansTag(FansTagCreateReqVO createReqVO) throws WxErrorException {
|
||||
// TODO 切换公众号操作 调整为 aop 或者 过滤器\拦截器 处理
|
||||
wxMpService.switchover(createReqVO.getAppId());
|
||||
return wxMpService.getUserTagService().tagCreate(createReqVO.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateWxFansTag(FansTagUpdateReqVO updateReqVO) throws WxErrorException {
|
||||
wxMpService.switchover(updateReqVO.getAppId());
|
||||
return wxMpService.getUserTagService().tagUpdate(updateReqVO.getId(), updateReqVO.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWxFansTag(Long id, String appId) throws WxErrorException {
|
||||
wxMpService.switchover(appId);
|
||||
return wxMpService.getUserTagService().tagDelete(id);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<WxUserTag> getWxFansTagList(String appId) throws WxErrorException {
|
||||
wxMpService.switchover(appId);
|
||||
return wxMpService.getUserTagService().tagGet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<WxUserTag> getWxFansTagPage(FansTagPageReqVO pageReqVO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WxUserTag> getWxFansTagList(FansTagExportReqVO exportReqVO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue