From 665f4b2b0926f4cf10b295724ffa06be04064a92 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 6 Jan 2023 09:25:19 +0800 Subject: [PATCH] =?UTF-8?q?mp=EF=BC=9A=E9=87=8D=E6=9E=84=20message=20?= =?UTF-8?q?=E5=8F=91=E9=80=81=E6=B6=88=E6=81=AF=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert/message/MpAutoReplyConvert.java | 27 ++++ .../mp/convert/message/MpMessageConvert.java | 40 +++--- .../mp/dal/dataobject/menu/MpMenuDO.java | 125 ++++++++++++++++-- .../dal/dataobject/message/MpAutoReplyDO.java | 1 - .../dal/dataobject/message/MpMessageDO.java | 8 +- .../mp/dal/mysql/menu/MpMenuMapper.java | 4 + .../mp/framework/mp/core/util/MpUtils.java | 75 +++++++++++ .../mp/service/handler/menu/MenuHandler.java | 26 ++-- .../message/MessageReceiveHandler.java | 2 +- .../module/mp/service/menu/MpMenuService.java | 12 ++ .../mp/service/menu/MpMenuServiceImpl.java | 53 ++++++++ .../message/MpAutoReplyServiceImpl.java | 8 +- .../mp/service/message/MpMessageService.java | 19 ++- .../service/message/MpMessageServiceImpl.java | 47 +++---- .../message/bo/MpMessageSendOutReqBO.java | 90 +++++++++++++ 15 files changed, 453 insertions(+), 84 deletions(-) create mode 100644 yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/message/MpAutoReplyConvert.java create mode 100644 yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/framework/mp/core/util/MpUtils.java create mode 100644 yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/service/message/bo/MpMessageSendOutReqBO.java diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/message/MpAutoReplyConvert.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/message/MpAutoReplyConvert.java new file mode 100644 index 000000000..a14c5fee1 --- /dev/null +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/message/MpAutoReplyConvert.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.module.mp.convert.message; + +import cn.iocoder.yudao.module.mp.dal.dataobject.message.MpAutoReplyDO; +import cn.iocoder.yudao.module.mp.service.message.bo.MpMessageSendOutReqBO; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface MpAutoReplyConvert { + + MpAutoReplyConvert INSTANCE = Mappers.getMapper(MpAutoReplyConvert.class); + + @Mappings({ + @Mapping(source = "reply.appId", target = "appId"), + @Mapping(source = "reply.responseMessageType", target = "type"), + @Mapping(source = "reply.responseContent", target = "content"), + @Mapping(source = "reply.responseMediaId", target = "mediaId"), + @Mapping(source = "reply.responseMediaUrl", target = "mediaUrl"), + @Mapping(source = "reply.responseTitle", target = "title"), + @Mapping(source = "reply.responseDescription", target = "description"), + @Mapping(source = "reply.responseArticle", target = "article"), + }) + MpMessageSendOutReqBO convert(String openid, MpAutoReplyDO reply); + +} diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/message/MpMessageConvert.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/message/MpMessageConvert.java index 9b7eae008..f440bf39b 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/message/MpMessageConvert.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/convert/message/MpMessageConvert.java @@ -1,20 +1,16 @@ package cn.iocoder.yudao.module.mp.convert.message; -import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.module.mp.controller.admin.message.vo.MpMessageRespVO; import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO; -import cn.iocoder.yudao.module.mp.dal.dataobject.message.MpAutoReplyDO; import cn.iocoder.yudao.module.mp.dal.dataobject.message.MpMessageDO; import cn.iocoder.yudao.module.mp.dal.dataobject.user.MpUserDO; +import cn.iocoder.yudao.module.mp.service.message.bo.MpMessageSendOutReqBO; import me.chanjar.weixin.common.api.WxConsts; import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage; import me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage; import me.chanjar.weixin.mp.builder.outxml.BaseBuilder; -import me.chanjar.weixin.mp.builder.outxml.TextBuilder; -import me.chanjar.weixin.mp.builder.outxml.VideoBuilder; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.Mappings; @@ -51,23 +47,27 @@ public interface MpMessageConvert { return message; } - default MpMessageDO convert(MpAutoReplyDO reply, MpAccountDO account, MpUserDO user) { + default MpMessageDO convert(MpMessageSendOutReqBO sendReqBO, MpAccountDO account, MpUserDO user) { // 构建消息 MpMessageDO message = new MpMessageDO(); - message.setType(reply.getResponseMessageType()); - // 1. 文本 - if (StrUtil.equals(reply.getResponseMessageType(), WxConsts.XmlMsgType.TEXT)) { - message.setContent(reply.getResponseContent()); - } else if (ObjectUtils.equalsAny(reply.getResponseMessageType(), WxConsts.XmlMsgType.IMAGE, // 2. 图片 - WxConsts.XmlMsgType.VOICE)) { // 3. 语音 - message.setMediaId(reply.getResponseMediaId()).setMediaUrl(reply.getResponseMediaUrl()); - } else if (StrUtil.equals(reply.getResponseMessageType(), WxConsts.XmlMsgType.VIDEO)) { // 4. 视频 - message.setMediaId(reply.getResponseMediaId()).setMediaUrl(reply.getResponseMediaUrl()) - .setTitle(reply.getResponseTitle()).setDescription(reply.getResponseDescription()); - } else if (StrUtil.equals(reply.getResponseMessageType(), WxConsts.XmlMsgType.NEWS)) { // 5. 图文 - message.setArticles(Collections.singletonList(reply.getResponseArticle())); - } else { - throw new IllegalArgumentException("不支持的消息类型:" + message.getType()); + message.setType(sendReqBO.getType()); + switch (sendReqBO.getType()) { + case WxConsts.XmlMsgType.TEXT: // 1. 文本 + message.setContent(sendReqBO.getContent()); + break; + case WxConsts.XmlMsgType.IMAGE: // 2. 图片 + case WxConsts.XmlMsgType.VOICE: // 3. 语音 + message.setMediaId(sendReqBO.getMediaId()).setMediaUrl(sendReqBO.getMediaUrl()); + break; + case WxConsts.XmlMsgType.VIDEO: // 4. 视频 + message.setMediaId(sendReqBO.getMediaId()).setMediaUrl(sendReqBO.getMediaUrl()) + .setTitle(sendReqBO.getTitle()).setDescription(sendReqBO.getDescription()); + break; + case WxConsts.XmlMsgType.NEWS: // 5. 图文 + message.setArticles(Collections.singletonList(sendReqBO.getArticle())); + break; + default: + throw new IllegalArgumentException("不支持的消息类型:" + message.getType()); } // 其它字段 diff --git a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/dal/dataobject/menu/MpMenuDO.java b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/dal/dataobject/menu/MpMenuDO.java index 3d1c2bba4..24889116c 100644 --- a/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/dal/dataobject/menu/MpMenuDO.java +++ b/yudao-module-mp/yudao-module-mp-biz/src/main/java/cn/iocoder/yudao/module/mp/dal/dataobject/menu/MpMenuDO.java @@ -1,15 +1,19 @@ package cn.iocoder.yudao.module.mp.dal.dataobject.menu; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.module.mp.dal.dataobject.account.MpAccountDO; import cn.iocoder.yudao.module.mp.dal.dataobject.message.MpMessageDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler; -import lombok.*; - -import com.baomidou.mybatisplus.annotation.*; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import me.chanjar.weixin.common.bean.menu.WxMenu; -import me.chanjar.weixin.common.bean.menu.WxMenuButton; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import me.chanjar.weixin.common.api.WxConsts; +import me.chanjar.weixin.common.api.WxConsts.MenuButtonType; import java.util.List; @@ -48,8 +52,8 @@ public class MpMenuDO extends BaseDO { /** * 按钮列表 */ - @TableField(typeHandler = WxMenuButtonTypeHandler.class) - private List buttons; + @TableField(typeHandler = ButtonTypeHandler.class) + private List