mp:完善公众号的账号管理

pull/2/head
YunaiV 2023-01-01 20:39:47 +08:00
parent 48520a456b
commit 627cb39517
26 changed files with 256 additions and 471 deletions

View File

@ -0,0 +1,71 @@
package cn.iocoder.yudao.module.mp.controller.admin.account;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.*;
import cn.iocoder.yudao.module.mp.convert.account.MpAccountConvert;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import cn.iocoder.yudao.module.mp.service.account.WxAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
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.validation.Valid;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Api(tags = "管理后台 - 公众号账户")
@RestController
@RequestMapping("/mp/account")
@Validated
public class MpAccountController {
@Resource
private WxAccountService wxAccountService;
@PostMapping("/create")
@ApiOperation("创建公众号账户")
@PreAuthorize("@ss.hasPermission('mp:account:create')")
public CommonResult<Long> createWxAccount(@Valid @RequestBody MpAccountCreateReqVO createReqVO) {
return success(wxAccountService.createAccount(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新公众号账户")
@PreAuthorize("@ss.hasPermission('mp:account:update')")
public CommonResult<Boolean> updateWxAccount(@Valid @RequestBody MpAccountUpdateReqVO updateReqVO) {
wxAccountService.updateAccount(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@ApiOperation("删除公众号账户")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('mp:account:delete')")
public CommonResult<Boolean> deleteWxAccount(@RequestParam("id") Long id) {
wxAccountService.deleteAccount(id);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得公众号账户")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('mp:account:query')")
public CommonResult<MpAccountRespVO> getWxAccount(@RequestParam("id") Long id) {
MpAccountDO wxAccount = wxAccountService.getAccount(id);
return success(MpAccountConvert.INSTANCE.convert(wxAccount));
}
@GetMapping("/page")
@ApiOperation("获得公众号账户分页")
@PreAuthorize("@ss.hasPermission('mp:account:query')")
public CommonResult<PageResult<MpAccountRespVO>> getWxAccountPage(@Valid MpAccountPageReqVO pageVO) {
PageResult<MpAccountDO> pageResult = wxAccountService.getAccountPage(pageVO);
return success(MpAccountConvert.INSTANCE.convertPage(pageResult));
}
}

View File

@ -1,102 +0,0 @@
package cn.iocoder.yudao.module.mp.controller.admin.account;
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.account.vo.*;
import cn.iocoder.yudao.module.mp.convert.account.WxAccountConvert;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import cn.iocoder.yudao.module.mp.service.account.WxAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
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 java.io.IOException;
import java.util.Collection;
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/account")
@Validated
public class WxAccountController {
@Resource
private WxAccountService wxAccountService;
@PostMapping("/create")
@ApiOperation("创建公众号账户")
@PreAuthorize("@ss.hasPermission('wechatMp:account:create')")
public CommonResult<Long> createWxAccount(@Valid @RequestBody WxAccountCreateReqVO createReqVO) {
return success(wxAccountService.createWxAccount(createReqVO));
}
@PutMapping("/update")
@ApiOperation("更新公众号账户")
@PreAuthorize("@ss.hasPermission('wechatMp:account:update')")
public CommonResult<Boolean> updateWxAccount(@Valid @RequestBody WxAccountUpdateReqVO updateReqVO) {
wxAccountService.updateWxAccount(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@ApiOperation("删除公众号账户")
@ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('wechatMp:account:delete')")
public CommonResult<Boolean> deleteWxAccount(@RequestParam("id") Long id) {
wxAccountService.deleteWxAccount(id);
return success(true);
}
@GetMapping("/get")
@ApiOperation("获得公众号账户")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@PreAuthorize("@ss.hasPermission('wechatMp:account:query')")
public CommonResult<WxAccountRespVO> getWxAccount(@RequestParam("id") Long id) {
WxAccountDO wxAccount = wxAccountService.getWxAccount(id);
return success(WxAccountConvert.INSTANCE.convert(wxAccount));
}
@GetMapping("/list")
@ApiOperation("获得公众号账户列表")
@ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
@PreAuthorize("@ss.hasPermission('wechatMp:account:query')")
public CommonResult<List<WxAccountRespVO>> getWxAccountList(@RequestParam("ids") Collection<Long> ids) {
List<WxAccountDO> list = wxAccountService.getWxAccountList(ids);
return success(WxAccountConvert.INSTANCE.convertList(list));
}
@GetMapping("/page")
@ApiOperation("获得公众号账户分页")
@PreAuthorize("@ss.hasPermission('wechatMp:account:query')")
public CommonResult<PageResult<WxAccountRespVO>> getWxAccountPage(@Valid WxAccountPageReqVO pageVO) {
PageResult<WxAccountDO> pageResult = wxAccountService.getWxAccountPage(pageVO);
return success(WxAccountConvert.INSTANCE.convertPage(pageResult));
}
@GetMapping("/export-excel")
@ApiOperation("导出公众号账户 Excel")
@PreAuthorize("@ss.hasPermission('wechatMp:account:export')")
@OperateLog(type = EXPORT)
public void exportWxAccountExcel(@Valid WxAccountExportReqVO exportReqVO,
HttpServletResponse response) throws IOException {
List<WxAccountDO> list = wxAccountService.getWxAccountList(exportReqVO);
// 导出 Excel
List<WxAccountExcelVO> datas = WxAccountConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "公众号账户.xls", "数据", WxAccountExcelVO.class, datas);
}
}

View File

@ -12,7 +12,7 @@ import javax.validation.constraints.NotNull;
* @author fengdan
*/
@Data
public class WxAccountBaseVO {
public class MpAccountBaseVO {
@ApiModelProperty(value = "公众号名称", required = true)
@NotNull(message = "公众号名称不能为空")
@ -22,15 +22,15 @@ public class WxAccountBaseVO {
@NotNull(message = "公众号账户不能为空")
private String account;
@ApiModelProperty(value = "公众号appid", required = true)
@NotNull(message = "公众号appid不能为空")
@ApiModelProperty(value = "公众号 appid", required = true)
@NotNull(message = "公众号 appid 不能为空")
private String appId;
@ApiModelProperty(value = "公众号密钥", required = true)
@NotNull(message = "公众号密钥不能为空")
private String appSecret;
@ApiModelProperty(value = "公众号token")
@ApiModelProperty(value = "公众号 token", required = true)
private String token;
@ApiModelProperty(value = "加密密钥")

View File

@ -5,13 +5,10 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
/**
* @author fengdan
*/
@ApiModel("管理后台 - 公众号账户创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WxAccountCreateReqVO extends WxAccountBaseVO {
public class MpAccountCreateReqVO extends MpAccountBaseVO {
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.mp.controller.admin.account.vo;
import lombok.*;
import io.swagger.annotations.*;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
@ApiModel("管理后台 - 公众号账户分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class MpAccountPageReqVO extends PageParam {
@ApiModelProperty(value = "公众号名称", notes = "模糊匹配")
private String name;
@ApiModelProperty(value = "公众号账户", notes = "模糊匹配")
private String account;
@ApiModelProperty(value = "公众号 appid", notes = "模糊匹配")
private String appId;
}

View File

@ -15,14 +15,11 @@ import java.util.Date;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WxAccountRespVO extends WxAccountBaseVO {
public class MpAccountRespVO extends MpAccountBaseVO {
@ApiModelProperty(value = "编号", required = true)
private Long id;
@ApiModelProperty(value = "公众号url")
private String url;
@ApiModelProperty(value = "二维码图片URL")
private String qrCodeUrl;
@ -31,4 +28,5 @@ public class WxAccountRespVO extends WxAccountBaseVO {
@ApiModelProperty(value = "公众号密钥", required = true)
private String appSecret;
}

View File

@ -11,7 +11,7 @@ import javax.validation.constraints.*;
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WxAccountUpdateReqVO extends WxAccountBaseVO {
public class MpAccountUpdateReqVO extends MpAccountBaseVO {
@ApiModelProperty(value = "编号", required = true)
@NotNull(message = "编号不能为空")

View File

@ -1,46 +0,0 @@
package cn.iocoder.yudao.module.mp.controller.admin.account.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.util.Date;
/**
* Excel VO
*
* @author
*/
@Data
public class WxAccountExcelVO {
@ExcelProperty("编号")
private Long id;
@ExcelProperty("公众号名称")
private String name;
@ExcelProperty("公众号账户")
private String account;
@ExcelProperty("公众号appid")
private String appId;
@ExcelProperty("公众号url")
private String url;
@ExcelProperty("公众号token")
private String token;
@ExcelProperty("加密密钥")
private String aesKey;
@ExcelProperty("二维码图片URL")
private String qrCodeUrl;
@ExcelProperty("备注")
private String remark;
@ExcelProperty("创建时间")
private Date createTime;
}

View File

@ -1,34 +0,0 @@
package cn.iocoder.yudao.module.mp.controller.admin.account.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;
/**
* @author fengdan
*/
@ApiModel(value = "管理后台 - 公众号账户 Excel 导出 Request VO", description = "参数和 WxAccountPageReqVO 是一致的")
@Data
public class WxAccountExportReqVO {
@ApiModelProperty(value = "公众号名称")
private String name;
@ApiModelProperty(value = "公众号账户")
private String account;
@ApiModelProperty(value = "公众号appid")
private String appId;
@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;
}

View File

@ -1,35 +0,0 @@
package cn.iocoder.yudao.module.mp.controller.admin.account.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;
/**
* @author fengdan
*/
@ApiModel("管理后台 - 公众号账户分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class WxAccountPageReqVO extends PageParam {
@ApiModelProperty(value = "公众号名称")
private String name;
@ApiModelProperty(value = "公众号账户")
private String account;
@ApiModelProperty(value = "公众号appid")
private String appId;
@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;
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.mp.convert.account;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountCreateReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountRespVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountUpdateReqVO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface MpAccountConvert {
MpAccountConvert INSTANCE = Mappers.getMapper(MpAccountConvert.class);
MpAccountDO convert(MpAccountCreateReqVO bean);
MpAccountDO convert(MpAccountUpdateReqVO bean);
MpAccountRespVO convert(MpAccountDO bean);
List<MpAccountRespVO> convertList(List<MpAccountDO> list);
PageResult<MpAccountRespVO> convertPage(PageResult<MpAccountDO> page);
}

View File

@ -1,36 +0,0 @@
package cn.iocoder.yudao.module.mp.convert.account;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountCreateReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountExcelVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountRespVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountUpdateReqVO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
/**
* Convert
*
* @author
*/
@Mapper
public interface WxAccountConvert {
WxAccountConvert INSTANCE = Mappers.getMapper(WxAccountConvert.class);
WxAccountDO convert(WxAccountCreateReqVO bean);
WxAccountDO convert(WxAccountUpdateReqVO bean);
WxAccountRespVO convert(WxAccountDO bean);
List<WxAccountRespVO> convertList(List<WxAccountDO> list);
PageResult<WxAccountRespVO> convertPage(PageResult<WxAccountDO> page);
List<WxAccountExcelVO> convertList02(List<WxAccountDO> list);
}

View File

@ -10,21 +10,20 @@ import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
// TODO 亚洲:这个模块的相关类,使用 Mp 作为前缀哈
/**
* DO
*
* @author
*/
@TableName("wx_account")
@KeySequence("wx_account_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@TableName("mp_account")
@KeySequence("mp_account_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WxAccountDO extends BaseDO {
public class MpAccountDO extends BaseDO {
/**
*
@ -47,10 +46,6 @@ public class WxAccountDO extends BaseDO {
*
*/
private String appSecret;
/**
* url
*/
private String url;
/**
* token
*/
@ -68,6 +63,7 @@ public class WxAccountDO extends BaseDO {
*/
private String remark;
// TODO 芋艿:需要迁移走
public WxMpConfigStorage toWxMpConfigStorage(RedisTemplateWxRedisOps redisTemplateWxRedisOps, WxMpProperties wxMpProperties) {
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisTemplateWxRedisOps, wxMpProperties.getConfigStorage().getKeyPrefix());
wxMpRedisConfig.setAppId(appId);

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.mp.dal.mysql.account;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountPageReqVO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MpAccountMapper extends BaseMapperX<MpAccountDO> {
default PageResult<MpAccountDO> selectPage(MpAccountPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MpAccountDO>()
.likeIfPresent(MpAccountDO::getName, reqVO.getName())
.likeIfPresent(MpAccountDO::getAccount, reqVO.getAccount())
.likeIfPresent(MpAccountDO::getAppId, reqVO.getAppId())
.orderByDesc(MpAccountDO::getId));
}
}

View File

@ -1,39 +0,0 @@
package cn.iocoder.yudao.module.mp.dal.mysql.account;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountExportReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountPageReqVO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* Mapper
*
* @author
*/
@Mapper
public interface WxAccountMapper extends BaseMapperX<WxAccountDO> {
default PageResult<WxAccountDO> selectPage(WxAccountPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<WxAccountDO>()
.likeIfPresent(WxAccountDO::getName, reqVO.getName())
.eqIfPresent(WxAccountDO::getAccount, reqVO.getAccount())
.eqIfPresent(WxAccountDO::getAppId, reqVO.getAppId())
.betweenIfPresent(WxAccountDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(WxAccountDO::getId));
}
default List<WxAccountDO> selectList(WxAccountExportReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<WxAccountDO>()
.likeIfPresent(WxAccountDO::getName, reqVO.getName())
.eqIfPresent(WxAccountDO::getAccount, reqVO.getAccount())
.eqIfPresent(WxAccountDO::getAppId, reqVO.getAppId())
.betweenIfPresent(WxAccountDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
.orderByDesc(WxAccountDO::getId));
}
}

View File

@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.infra.api.file.FileApi;
import cn.iocoder.yudao.module.mp.builder.TextBuilder;
import cn.iocoder.yudao.module.mp.controller.admin.fansmsg.vo.WxFansMsgCreateReqVO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import cn.iocoder.yudao.module.mp.service.account.WxAccountService;
import cn.iocoder.yudao.module.mp.service.fansmsg.WxFansMsgService;
import lombok.extern.slf4j.Slf4j;
@ -55,7 +55,7 @@ public class MsgHandler implements WxMpMessageHandler {
WxMpUser wxmpUser = weixinService.getUserService()
.userInfo(wxMessage.getFromUser(), null);
if (wxmpUser != null) {
WxAccountDO wxAccount = wxAccountService.findBy(WxAccountDO::getAccount, wxMessage.getToUser());
MpAccountDO wxAccount = wxAccountService.findBy(MpAccountDO::getAccount, wxMessage.getToUser());
if (wxAccount != null) {
if (wxMessage.getMsgType().equals(WxConsts.XmlMsgType.TEXT)) {

View File

@ -5,7 +5,7 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.module.mp.builder.TextBuilder;
import cn.iocoder.yudao.module.mp.controller.admin.accountfans.vo.WxAccountFansCreateReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.accountfans.vo.WxAccountFansUpdateReqVO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.accountfans.WxAccountFansDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.subscribetext.WxSubscribeTextDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.texttemplate.WxTextTemplateDO;
@ -60,7 +60,7 @@ public class SubscribeHandler implements WxMpMessageHandler {
.userInfo(wxMessage.getFromUser(), null);
if (wxmpUser != null) {
// 可以添加关注用户到本地数据库
WxAccountDO wxAccount = wxAccountService.findBy(WxAccountDO::getAccount, wxMessage.getToUser());
MpAccountDO wxAccount = wxAccountService.findBy(MpAccountDO::getAccount, wxMessage.getToUser());
if (wxAccount != null) {
WxAccountFansDO wxAccountFans = wxAccountFansService.findBy(WxAccountFansDO::getOpenid, wxmpUser.getOpenId());
if (wxAccountFans == null) {//insert
@ -128,7 +128,7 @@ public class SubscribeHandler implements WxMpMessageHandler {
try {
String content = "感谢关注!";//默认
WxAccountDO wxAccount = wxAccountService.findBy(WxAccountDO::getAccount, wxMessage.getToUser());
MpAccountDO wxAccount = wxAccountService.findBy(MpAccountDO::getAccount, wxMessage.getToUser());
if (wxAccount != null) {
WxSubscribeTextDO wxSubscribeText = wxSubscribeTextService.findBy(WxSubscribeTextDO::getWxAccountId, String.valueOf(wxAccount.getId()));
if (wxSubscribeText != null) {

View File

@ -1,7 +1,7 @@
package cn.iocoder.yudao.module.mp.handler;
import cn.iocoder.yudao.module.mp.controller.admin.accountfans.vo.WxAccountFansUpdateReqVO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.accountfans.WxAccountFansDO;
import cn.iocoder.yudao.module.mp.service.account.WxAccountService;
import cn.iocoder.yudao.module.mp.service.accountfans.WxAccountFansService;
@ -34,7 +34,7 @@ public class UnsubscribeHandler implements WxMpMessageHandler {
log.info("取消关注用户 OPENID: " + openId);
// TODO 可以更新本地数据库为取消关注状态
WxAccountDO wxAccountDO = wxAccountService.findBy(WxAccountDO::getAccount, wxMessage.getToUser());
MpAccountDO wxAccountDO = wxAccountService.findBy(MpAccountDO::getAccount, wxMessage.getToUser());
if (wxAccountDO != null) {
WxAccountFansDO wxAccountFansDO = wxAccountFansService.findBy(WxAccountFansDO::getOpenid, openId);
if (wxAccountFansDO != null) {

View File

@ -1,16 +1,13 @@
package cn.iocoder.yudao.module.mp.service.account;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountCreateReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountExportReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountPageReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountUpdateReqVO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountCreateReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountPageReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountUpdateReqVO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
/**
* Service
@ -25,21 +22,21 @@ public interface WxAccountService {
* @param createReqVO
* @return
*/
Long createWxAccount(@Valid WxAccountCreateReqVO createReqVO);
Long createAccount(@Valid MpAccountCreateReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updateWxAccount(@Valid WxAccountUpdateReqVO updateReqVO);
void updateAccount(@Valid MpAccountUpdateReqVO updateReqVO);
/**
*
*
* @param id
*/
void deleteWxAccount(Long id);
void deleteAccount(Long id);
/**
*
@ -47,15 +44,7 @@ public interface WxAccountService {
* @param id
* @return
*/
WxAccountDO getWxAccount(Long id);
/**
*
*
* @param ids
* @return
*/
List<WxAccountDO> getWxAccountList(Collection<Long> ids);
MpAccountDO getAccount(Long id);
/**
*
@ -63,16 +52,9 @@ public interface WxAccountService {
* @param pageReqVO
* @return
*/
PageResult<WxAccountDO> getWxAccountPage(WxAccountPageReqVO pageReqVO);
/**
* , Excel
*
* @param exportReqVO
* @return
*/
List<WxAccountDO> getWxAccountList(WxAccountExportReqVO exportReqVO);
PageResult<MpAccountDO> getAccountPage(MpAccountPageReqVO pageReqVO);
// TODO 芋艿:去除这样的方法
/**
*
*
@ -80,7 +62,7 @@ public interface WxAccountService {
* @param val
* @return
*/
WxAccountDO findBy(SFunction<WxAccountDO, ?> field, Object val);
MpAccountDO findBy(SFunction<MpAccountDO, ?> field, Object val);
/**
*

View File

@ -3,13 +3,12 @@ package cn.iocoder.yudao.module.mp.service.account;
import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountCreateReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountExportReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountPageReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.WxAccountUpdateReqVO;
import cn.iocoder.yudao.module.mp.convert.account.WxAccountConvert;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import cn.iocoder.yudao.module.mp.dal.mysql.account.WxAccountMapper;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountCreateReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountPageReqVO;
import cn.iocoder.yudao.module.mp.controller.admin.account.vo.MpAccountUpdateReqVO;
import cn.iocoder.yudao.module.mp.convert.account.MpAccountConvert;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import cn.iocoder.yudao.module.mp.dal.mysql.account.MpAccountMapper;
import cn.iocoder.yudao.module.mp.enums.ErrorCodeConstants;
import cn.iocoder.yudao.module.mp.mq.producer.WxMpConfigDataProducer;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
@ -27,7 +26,6 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -44,8 +42,9 @@ import java.util.Map;
public class WxAccountServiceImpl implements WxAccountService {
private static final long SCHEDULER_PERIOD = 5 * 60 * 1000L;
@Resource
private WxAccountMapper wxAccountMapper;
private MpAccountMapper wxAccountMapper;
@Resource
private WxMpConfigDataProducer wxMpConfigDataProducer;
@Resource
@ -59,31 +58,39 @@ public class WxAccountServiceImpl implements WxAccountService {
private WxAccountService self;
@Override
public Long createWxAccount(WxAccountCreateReqVO createReqVO) {
public Long createAccount(MpAccountCreateReqVO createReqVO) {
// TODO 芋艿:校验唯一性
// 插入
WxAccountDO wxAccount = WxAccountConvert.INSTANCE.convert(createReqVO);
MpAccountDO wxAccount = MpAccountConvert.INSTANCE.convert(createReqVO);
wxAccountMapper.insert(wxAccount);
// TODO 芋艿:刷新的方式
wxMpConfigDataProducer.sendDictDataRefreshMessage();
// 返回
return wxAccount.getId();
}
@Override
public void updateWxAccount(WxAccountUpdateReqVO updateReqVO) {
public void updateAccount(MpAccountUpdateReqVO updateReqVO) {
// TODO 芋艿:校验唯一性
// 校验存在
this.validateWxAccountExists(updateReqVO.getId());
validateWxAccountExists(updateReqVO.getId());
// 更新
WxAccountDO updateObj = WxAccountConvert.INSTANCE.convert(updateReqVO);
MpAccountDO updateObj = MpAccountConvert.INSTANCE.convert(updateReqVO);
wxAccountMapper.updateById(updateObj);
// TODO 芋艿:刷新的方式
wxMpConfigDataProducer.sendDictDataRefreshMessage();
}
@Override
public void deleteWxAccount(Long id) {
public void deleteAccount(Long id) {
// 校验存在
this.validateWxAccountExists(id);
validateWxAccountExists(id);
// 删除
wxAccountMapper.deleteById(id);
// TODO 芋艿:刷新的方式
wxMpConfigDataProducer.sendDictDataRefreshMessage();
}
@ -94,27 +101,17 @@ public class WxAccountServiceImpl implements WxAccountService {
}
@Override
public WxAccountDO getWxAccount(Long id) {
public MpAccountDO getAccount(Long id) {
return wxAccountMapper.selectById(id);
}
@Override
public List<WxAccountDO> getWxAccountList(Collection<Long> ids) {
return wxAccountMapper.selectBatchIds(ids);
}
@Override
public PageResult<WxAccountDO> getWxAccountPage(WxAccountPageReqVO pageReqVO) {
public PageResult<MpAccountDO> getAccountPage(MpAccountPageReqVO pageReqVO) {
return wxAccountMapper.selectPage(pageReqVO);
}
@Override
public List<WxAccountDO> getWxAccountList(WxAccountExportReqVO exportReqVO) {
return wxAccountMapper.selectList(exportReqVO);
}
@Override
public WxAccountDO findBy(SFunction<WxAccountDO, ?> field, Object val) {
public MpAccountDO findBy(SFunction<MpAccountDO, ?> field, Object val) {
return wxAccountMapper.selectOne(field, val);
}
@ -122,7 +119,8 @@ public class WxAccountServiceImpl implements WxAccountService {
@TenantIgnore
@Override
public void initLoadWxMpConfigStorages() {
List<WxAccountDO> wxAccountList = this.wxAccountMapper.selectList();
// TODO 芋艿:刷新的方式
List<MpAccountDO> wxAccountList = this.wxAccountMapper.selectList();
if (CollectionUtils.isEmpty(wxAccountList)) {
log.info("未读取到公众号配置,请在管理后台添加");
return;
@ -137,7 +135,7 @@ public class WxAccountServiceImpl implements WxAccountService {
*
* @param account
*/
private synchronized void addAccountToRuntime(WxAccountDO account, RedisTemplateWxRedisOps redisOps) {
private synchronized void addAccountToRuntime(MpAccountDO account, RedisTemplateWxRedisOps redisOps) {
String appId = account.getAppId();
WxMpConfigStorage wxMpRedisConfig = account.toWxMpConfigStorage(redisOps, wxMpProperties);
try {

View File

@ -4,7 +4,7 @@ import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.mp.controller.admin.accountfanstag.vo.*;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.accountfanstag.WxAccountFansTagDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
@ -70,5 +70,5 @@ public interface WxAccountFansTagService {
*/
List<WxAccountFansTagDO> getWxAccountFansTagList(WxAccountFansTagExportReqVO exportReqVO);
void processFansTags(WxAccountDO wxAccount, WxMpUser wxmpUser);
void processFansTags(MpAccountDO wxAccount, WxMpUser wxmpUser);
}

View File

@ -1,7 +1,6 @@
package cn.iocoder.yudao.module.mp.service.accountfanstag;
import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.springframework.stereotype.Service;
@ -86,7 +85,7 @@ public class WxAccountFansTagServiceImpl implements WxAccountFansTagService {
}
@Override
public void processFansTags(WxAccountDO wxAccountDO, WxMpUser wxmpUser) {
public void processFansTags(MpAccountDO wxAccountDO, WxMpUser wxmpUser) {
WxAccountFansTagExportReqVO wxAccountFansTagTpl = new WxAccountFansTagExportReqVO();
wxAccountFansTagTpl.setOpenid(wxmpUser.getOpenId());
List<WxAccountFansTagDO> wxAccountFansTagList = this.getWxAccountFansTagList(wxAccountFansTagTpl);

View File

@ -4,7 +4,6 @@ import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.mp.controller.admin.subscribetext.vo.*;
import cn.iocoder.yudao.module.mp.dal.dataobject.account.WxAccountDO;
import cn.iocoder.yudao.module.mp.dal.dataobject.subscribetext.WxSubscribeTextDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;

View File

@ -3,7 +3,7 @@ import request from '@/utils/request'
// 创建公众号账户
export function createAccount(data) {
return request({
url: '/wechatMp/account/create',
url: '/mp/account/create',
method: 'post',
data: data
})
@ -12,7 +12,7 @@ export function createAccount(data) {
// 更新公众号账户
export function updateAccount(data) {
return request({
url: '/wechatMp/account/update',
url: '/mp/account/update',
method: 'put',
data: data
})
@ -21,7 +21,7 @@ export function updateAccount(data) {
// 删除公众号账户
export function deleteAccount(id) {
return request({
url: '/wechatMp/account/delete?id=' + id,
url: '/mp/account/delete?id=' + id,
method: 'delete'
})
}
@ -29,7 +29,7 @@ export function deleteAccount(id) {
// 获得公众号账户
export function getAccount(id) {
return request({
url: '/wechatMp/account/get?id=' + id,
url: '/mp/account/get?id=' + id,
method: 'get'
})
}
@ -37,7 +37,7 @@ export function getAccount(id) {
// 获得公众号账户分页
export function getAccountPage(query) {
return request({
url: '/wechatMp/account/page',
url: '/mp/account/page',
method: 'get',
params: query
})
@ -46,7 +46,7 @@ export function getAccountPage(query) {
// 导出公众号账户 Excel
export function exportAccountExcel(query) {
return request({
url: '/wechatMp/account/export-excel',
url: '/mp/account/export-excel',
method: 'get',
params: query,
responseType: 'blob'

View File

@ -4,13 +4,9 @@
<!-- 搜索工作栏 -->
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="名称" prop="name">
<el-input v-model="queryParams.name" placeholder="请输入公众号名称" clearable
<el-input v-model="queryParams.name" placeholder="请输入名称" clearable
@keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker v-model="dateRangeCreateTime" style="width: 240px" value-format="yyyy-MM-dd"
type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" @click="handleQuery"></el-button>
<el-button icon="el-icon-refresh" @click="resetQuery"></el-button>
@ -21,13 +17,7 @@
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
v-hasPermi="['wechatMp:account:create']">新增
</el-button>
</el-col>
<el-col :span="1.5">
<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
:loading="exportLoading"
v-hasPermi="['wechatMp:account:export']">导出
v-hasPermi="['mp:account:create']">新增
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
@ -35,13 +25,12 @@
<!-- 列表 -->
<el-table v-loading="loading" :data="list">
<el-table-column label="编号" align="center" prop="id"/>
<el-table-column label="名称" align="center" prop="name"/>
<el-table-column label="微信原始ID" align="center" prop="account"/>
<el-table-column label="appId" align="center" prop="appId"/>
<el-table-column label="url" align="center" prop="url"/>
<el-table-column label="微信" align="center" prop="account" width="180"/>
<el-table-column label="appId" align="center" prop="appId" width="180"/>
<el-table-column label="appSecret" align="center" prop="appSecret" width="180"/>
<el-table-column label="Token" align="center" prop="token"/>
<el-table-column label="加密密钥" align="center" prop="aesKey"/>
<el-table-column label="密钥" align="center" prop="aesKey"/>
<el-table-column label="二维码" align="center" prop="qrCodeUrl"/>
<el-table-column label="备注" align="center" prop="remark"/>
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
@ -52,10 +41,10 @@
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
v-hasPermi="['wechatMp:account:update']">修改
v-hasPermi="['mp:account:update']">修改
</el-button>
<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
v-hasPermi="['wechatMp:account:delete']">删除
v-hasPermi="['mp:account:delete']">删除
</el-button>
</template>
</el-table-column>
@ -66,35 +55,37 @@
<!-- 对话框(添加 / 修改) -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="公众号名称" prop="name">
<el-input v-model="form.name" placeholder="请输入公众号名称"/>
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-form-item label="名称" prop="name">
<el-input v-model="form.name" placeholder="请输入名称"/>
</el-form-item>
<el-form-item label="微信号" prop="account">
<span slot="label">
<el-tooltip content="在微信公众平台mp.weixin.qq.com的菜单【设置】-【公众号设置】-【帐号详情】中能找到原始ID" placement="top">
<i class="el-icon-question" />
</el-tooltip>
微信号
</span>
<el-input v-model="form.account" placeholder="请输入微信号"/>
</el-form-item>
<el-form-item label="appId" prop="appId">
<span slot="label">
<el-tooltip content="在微信公众平台mp.weixin.qq.com的菜单【开发】-【基本配置】中能找到 appId" placement="top">
<i class="el-icon-question" />
</el-tooltip>
appId
</span>
<el-input v-model="form.appId" placeholder="请输入公众号 appId"/>
</el-form-item>
<el-form-item label="密钥" prop="appSecret">
<span slot="label">
<el-tooltip content="在微信公众平台mp.weixin.qq.com的菜单【开发】-【基本配置】中能找到密钥" placement="top">
<i class="el-icon-question" />
</el-tooltip>
密钥
</span>
<el-input v-model="form.appSecret" placeholder="请输入公众号 appSecret"/>
</el-form-item>
<el-tooltip class="item" effect="dark"
content="在微信公众平台mp.weixin.qq.com的菜单【设置】-【公众号设置】-【帐号详情】中能找到原始ID"
placement="right">
<el-form-item label="微信原始ID" prop="account">
<el-input v-model="form.account" placeholder="请输入微信原始ID" :disabled='disabled'/>
</el-form-item>
</el-tooltip>
<el-tooltip class="item" effect="dark"
content="在微信公众平台mp.weixin.qq.com的菜单【开发】-【基本配置】中能找到AppID "
placement="right">
<el-form-item label="AppID" prop="appId">
<el-input v-model="form.appId" placeholder="请输入公众号appId" :disabled='disabled'/>
</el-form-item>
</el-tooltip>
<el-tooltip class="item" effect="dark"
content="在微信公众平台mp.weixin.qq.com的菜单【开发】-【基本配置】中能找到AppSecret"
placement="right">
<el-form-item label="AppSecret" prop="appSecret">
<el-input v-model="form.appSecret" placeholder="请输入公众号密钥" :disabled='disabled'/>
</el-form-item>
</el-tooltip>
<el-form-item label="token" prop="token">
<el-input v-model="form.token" placeholder="请输入公众号token"/>
</el-form-item>
@ -114,17 +105,10 @@
</template>
<script>
import {
createAccount,
deleteAccount,
exportAccountExcel,
getAccount,
getAccountPage,
updateAccount
} from '@/api/wechatMp/wxAccount'
import { createAccount, deleteAccount, getAccount, getAccountPage, updateAccount} from '@/api/mp/account'
export default {
name: 'wxAccount',
name: 'mpAccount',
components: {},
data() {
return {
@ -142,7 +126,6 @@ export default {
title: '',
//
open: false,
dateRangeCreateTime: [],
//
queryParams: {
pageNo: 1,
@ -155,10 +138,11 @@ export default {
form: {},
//
rules: {
name: [{required: true, message: '公众号名称不能为空', trigger: 'blur'}],
name: [{required: true, message: '名称不能为空', trigger: 'blur'}],
account: [{required: true, message: '公众号账户不能为空', trigger: 'blur'}],
appId: [{required: true, message: '公众号appid不能为空', trigger: 'blur'}],
appId: [{required: true, message: '公众号 appId 不能为空', trigger: 'blur'}],
appSecret: [{required: true, message: '公众号密钥不能为空', trigger: 'blur'}],
token: [{required: true, message: '公众号 token 不能为空', trigger: 'blur'}],
},
//
disabled: false,
@ -173,7 +157,6 @@ export default {
this.loading = true
//
let params = {...this.queryParams}
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime')
//
getAccountPage(params).then(response => {
this.list = response.data.list
@ -255,7 +238,7 @@ export default {
/** 删除按钮操作 */
handleDelete(row) {
const id = row.id
this.$modal.confirm('是否确认删除公众号账户编号为"' + id + '"的数据项?').then(function () {
this.$modal.confirm('是否确认删除公众号账户编号为"' + row.name + '"的数据项?').then(function () {
return deleteAccount(id)
}).then(() => {
this.getList()
@ -263,23 +246,6 @@ export default {
}).catch(() => {
})
},
/** 导出按钮操作 */
handleExport() {
//
let params = {...this.queryParams}
params.pageNo = undefined
params.pageSize = undefined
this.addBeginAndEndTime(params, this.dateRangeCreateTime, 'createTime')
//
this.$modal.confirm('是否确认导出所有公众号账户数据项?').then(() => {
this.exportLoading = true
return exportAccountExcel(params)
}).then(response => {
this.$download.excel(response, '公众号账户.xls')
this.exportLoading = false
}).catch(() => {
})
}
}
}
</script>

View File

@ -104,7 +104,7 @@ import {
getWxFansTagList,
updateWxFansTag
} from '@/api/wechatMp/wxFansTag'
import {getAccountPage} from '@/api/wechatMp/wxAccount'
import {getAccountPage} from '@/api/mp/account'
export default {
name: 'WxFansTag',