浏览代码

对接微信消息模板

Yangzw 11 月之前
父节点
当前提交
6908b430f6

+ 96 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/messagelog/MessageLogController.java

@@ -0,0 +1,96 @@
+package cn.newfeifan.mall.module.trade.controller.admin.messagelog;
+
+import cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo.MessageLogPageReqVO;
+import cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo.MessageLogRespVO;
+import cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo.MessageLogSaveReqVO;
+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.v3.oas.annotations.tags.Tag;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Operation;
+
+import javax.validation.*;
+import javax.servlet.http.*;
+import java.util.*;
+import java.io.IOException;
+
+import cn.newfeifan.mall.framework.common.pojo.PageParam;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+import cn.newfeifan.mall.framework.common.pojo.CommonResult;
+import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
+import static cn.newfeifan.mall.framework.common.pojo.CommonResult.success;
+
+import cn.newfeifan.mall.framework.excel.core.util.ExcelUtils;
+
+import cn.newfeifan.mall.framework.operatelog.core.annotations.OperateLog;
+import static cn.newfeifan.mall.framework.operatelog.core.enums.OperateTypeEnum.*;
+
+import cn.newfeifan.mall.module.trade.dal.dal.dataobject.messagelog.MessageLogDO;
+import cn.newfeifan.mall.module.trade.service.messagelog.MessageLogService;
+
+@Tag(name = "管理后台 - 微信消息记录")
+@RestController
+@RequestMapping("/wechat/message-log")
+@Validated
+public class MessageLogController {
+
+    @Resource
+    private MessageLogService messageLogService;
+
+    @PostMapping("/create")
+    @Operation(summary = "创建微信消息记录")
+    @PreAuthorize("@ss.hasPermission('wechat:message-log:create')")
+    public CommonResult<Long> createMessageLog(@Valid @RequestBody MessageLogSaveReqVO createReqVO) {
+        return success(messageLogService.createMessageLog(createReqVO));
+    }
+
+    @PutMapping("/update")
+    @Operation(summary = "更新微信消息记录")
+    @PreAuthorize("@ss.hasPermission('wechat:message-log:update')")
+    public CommonResult<Boolean> updateMessageLog(@Valid @RequestBody MessageLogSaveReqVO updateReqVO) {
+        messageLogService.updateMessageLog(updateReqVO);
+        return success(true);
+    }
+
+    @DeleteMapping("/delete")
+    @Operation(summary = "删除微信消息记录")
+    @Parameter(name = "id", description = "编号", required = true)
+    @PreAuthorize("@ss.hasPermission('wechat:message-log:delete')")
+    public CommonResult<Boolean> deleteMessageLog(@RequestParam("id") Long id) {
+        messageLogService.deleteMessageLog(id);
+        return success(true);
+    }
+
+    @GetMapping("/get")
+    @Operation(summary = "获得微信消息记录")
+    @Parameter(name = "id", description = "编号", required = true, example = "1024")
+    @PreAuthorize("@ss.hasPermission('wechat:message-log:query')")
+    public CommonResult<MessageLogRespVO> getMessageLog(@RequestParam("id") Long id) {
+        MessageLogDO messageLog = messageLogService.getMessageLog(id);
+        return success(BeanUtils.toBean(messageLog, MessageLogRespVO.class));
+    }
+
+    @GetMapping("/page")
+    @Operation(summary = "获得微信消息记录分页")
+    @PreAuthorize("@ss.hasPermission('wechat:message-log:query')")
+    public CommonResult<PageResult<MessageLogRespVO>> getMessageLogPage(@Valid MessageLogPageReqVO pageReqVO) {
+        PageResult<MessageLogDO> pageResult = messageLogService.getMessageLogPage(pageReqVO);
+        return success(BeanUtils.toBean(pageResult, MessageLogRespVO.class));
+    }
+
+    @GetMapping("/export-excel")
+    @Operation(summary = "导出微信消息记录 Excel")
+    @PreAuthorize("@ss.hasPermission('wechat:message-log:export')")
+    @OperateLog(type = EXPORT)
+    public void exportMessageLogExcel(@Valid MessageLogPageReqVO pageReqVO,
+              HttpServletResponse response) throws IOException {
+        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
+        List<MessageLogDO> list = messageLogService.getMessageLogPage(pageReqVO).getList();
+        // 导出 Excel
+        ExcelUtils.write(response, "微信消息记录.xls", "数据", MessageLogRespVO.class,
+                        BeanUtils.toBean(list, MessageLogRespVO.class));
+    }
+
+}

+ 49 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/messagelog/vo/MessageLogPageReqVO.java

@@ -0,0 +1,49 @@
+package cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo;
+
+import lombok.*;
+import io.swagger.v3.oas.annotations.media.Schema;
+import cn.newfeifan.mall.framework.common.pojo.PageParam;
+import org.springframework.format.annotation.DateTimeFormat;
+import java.time.LocalDateTime;
+
+import static cn.newfeifan.mall.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
+
+@Schema(description = "管理后台 - 微信消息记录分页 Request VO")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+public class MessageLogPageReqVO extends PageParam {
+
+    @Schema(description = "接收消息用户的openid", example = "20952")
+    private String openid;
+
+    @Schema(description = "会员用户ID", example = "16486")
+    private Long memberUserId;
+
+    @Schema(description = "系统用户ID", example = "13077")
+    private Long systemUserId;
+
+    @Schema(description = "微信消息模板ID", example = "13313")
+    private Long wechatMsgTemplateId;
+
+    @Schema(description = "微信消息模板参数")
+    private String wechatMsgTemplateParams;
+
+    @Schema(description = "对应的业务对象ID,如订单ID、售后订单ID", example = "30167")
+    private Long objectId;
+
+    @Schema(description = "发送时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] sendTime;
+
+    @Schema(description = "微信返回的消息发送状态", example = "1")
+    private Boolean sendStatus;
+
+    @Schema(description = "微信返回的消息响应结果")
+    private String responseResult;
+
+    @Schema(description = "创建时间")
+    @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
+    private LocalDateTime[] createTime;
+
+}

+ 57 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/messagelog/vo/MessageLogRespVO.java

@@ -0,0 +1,57 @@
+package cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import java.time.LocalDateTime;
+import com.alibaba.excel.annotation.*;
+
+@Schema(description = "管理后台 - 微信消息记录 Response VO")
+@Data
+@ExcelIgnoreUnannotated
+public class MessageLogRespVO {
+
+    @Schema(description = "消息记录ID,自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "20647")
+    @ExcelProperty("消息记录ID,自增主键")
+    private Long id;
+
+    @Schema(description = "接收消息用户的openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "20952")
+    @ExcelProperty("接收消息用户的openid")
+    private String openid;
+
+    @Schema(description = "会员用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "16486")
+    @ExcelProperty("会员用户ID")
+    private Long memberUserId;
+
+    @Schema(description = "系统用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "13077")
+    @ExcelProperty("系统用户ID")
+    private Long systemUserId;
+
+    @Schema(description = "微信消息模板ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "13313")
+    @ExcelProperty("微信消息模板ID")
+    private Long wechatMsgTemplateId;
+
+    @Schema(description = "微信消息模板参数")
+    @ExcelProperty("微信消息模板参数")
+    private String wechatMsgTemplateParams;
+
+    @Schema(description = "对应的业务对象ID,如订单ID、售后订单ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30167")
+    @ExcelProperty("对应的业务对象ID,如订单ID、售后订单ID")
+    private Long objectId;
+
+    @Schema(description = "发送时间")
+    @ExcelProperty("发送时间")
+    private LocalDateTime sendTime;
+
+    @Schema(description = "微信返回的消息发送状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
+    @ExcelProperty("微信返回的消息发送状态")
+    private Boolean sendStatus;
+
+    @Schema(description = "微信返回的消息响应结果")
+    @ExcelProperty("微信返回的消息响应结果")
+    private String responseResult;
+
+    @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
+    @ExcelProperty("创建时间")
+    private LocalDateTime createTime;
+
+}

+ 49 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/controller/admin/messagelog/vo/MessageLogSaveReqVO.java

@@ -0,0 +1,49 @@
+package cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.*;
+import javax.validation.constraints.*;
+import java.time.LocalDateTime;
+
+@Schema(description = "管理后台 - 微信消息记录新增/修改 Request VO")
+@Data
+@Builder
+public class MessageLogSaveReqVO {
+
+    @Schema(description = "消息记录ID,自增主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "20647")
+    private Long id;
+
+    @Schema(description = "接收消息用户的openid", requiredMode = Schema.RequiredMode.REQUIRED, example = "20952")
+    @NotEmpty(message = "接收消息用户的openid不能为空")
+    private String openid;
+
+    @Schema(description = "会员用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "16486")
+    @NotNull(message = "会员用户ID不能为空")
+    private Long memberUserId;
+
+    @Schema(description = "系统用户ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "13077")
+    @NotNull(message = "系统用户ID不能为空")
+    private Long systemUserId;
+
+    @Schema(description = "微信消息模板ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "13313")
+    @NotNull(message = "微信消息模板ID不能为空")
+    private Long wechatMsgTemplateId;
+
+    @Schema(description = "微信消息模板参数")
+    private String wechatMsgTemplateParams;
+
+    @Schema(description = "对应的业务对象ID,如订单ID、售后订单ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30167")
+    @NotNull(message = "对应的业务对象ID,如订单ID、售后订单ID不能为空")
+    private Long objectId;
+
+    @Schema(description = "发送时间")
+    private LocalDateTime sendTime;
+
+    @Schema(description = "微信返回的消息发送状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
+    @NotNull(message = "微信返回的消息发送状态不能为空")
+    private Boolean sendStatus;
+
+    @Schema(description = "微信返回的消息响应结果")
+    private String responseResult;
+
+}

+ 65 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/dal/dataobject/messagelog/MessageLogDO.java

@@ -0,0 +1,65 @@
+package cn.newfeifan.mall.module.trade.dal.dal.dataobject.messagelog;
+
+import lombok.*;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.*;
+import cn.newfeifan.mall.framework.mybatis.core.dataobject.BaseDO;
+
+/**
+ * 微信消息记录 DO
+ *
+ * @author 非繁人
+ */
+@TableName("wechat_message_log")
+@KeySequence("wechat_message_log_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class MessageLogDO extends BaseDO {
+
+    /**
+     * 消息记录ID,自增主键
+     */
+    @TableId
+    private Long id;
+    /**
+     * 接收消息用户的openid
+     */
+    private String openid;
+    /**
+     * 会员用户ID
+     */
+    private Long memberUserId;
+    /**
+     * 系统用户ID
+     */
+    private Long systemUserId;
+    /**
+     * 微信消息模板ID
+     */
+    private Long wechatMsgTemplateId;
+    /**
+     * 微信消息模板参数
+     */
+    private String wechatMsgTemplateParams;
+    /**
+     * 对应的业务对象ID,如订单ID、售后订单ID
+     */
+    private Long objectId;
+    /**
+     * 发送时间
+     */
+    private LocalDateTime sendTime;
+    /**
+     * 微信返回的消息发送状态
+     */
+    private Boolean sendStatus;
+    /**
+     * 微信返回的消息响应结果
+     */
+    private String responseResult;
+
+}

+ 33 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/dal/dal/mysql/messagelog/MessageLogMapper.java

@@ -0,0 +1,33 @@
+package cn.newfeifan.mall.module.trade.dal.dal.mysql.messagelog;
+
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.newfeifan.mall.framework.mybatis.core.mapper.BaseMapperX;
+import cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo.MessageLogPageReqVO;
+import cn.newfeifan.mall.module.trade.dal.dal.dataobject.messagelog.MessageLogDO;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 微信消息记录 Mapper
+ *
+ * @author 非繁人
+ */
+@Mapper
+public interface MessageLogMapper extends BaseMapperX<MessageLogDO> {
+
+    default PageResult<MessageLogDO> selectPage(MessageLogPageReqVO reqVO) {
+        return selectPage(reqVO, new LambdaQueryWrapperX<MessageLogDO>()
+                .eqIfPresent(MessageLogDO::getOpenid, reqVO.getOpenid())
+                .eqIfPresent(MessageLogDO::getMemberUserId, reqVO.getMemberUserId())
+                .eqIfPresent(MessageLogDO::getSystemUserId, reqVO.getSystemUserId())
+                .eqIfPresent(MessageLogDO::getWechatMsgTemplateId, reqVO.getWechatMsgTemplateId())
+                .eqIfPresent(MessageLogDO::getWechatMsgTemplateParams, reqVO.getWechatMsgTemplateParams())
+                .eqIfPresent(MessageLogDO::getObjectId, reqVO.getObjectId())
+                .betweenIfPresent(MessageLogDO::getSendTime, reqVO.getSendTime())
+                .eqIfPresent(MessageLogDO::getSendStatus, reqVO.getSendStatus())
+                .eqIfPresent(MessageLogDO::getResponseResult, reqVO.getResponseResult())
+                .betweenIfPresent(MessageLogDO::getCreateTime, reqVO.getCreateTime())
+                .orderByDesc(MessageLogDO::getId));
+    }
+
+}

+ 55 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/messagelog/MessageLogService.java

@@ -0,0 +1,55 @@
+package cn.newfeifan.mall.module.trade.service.messagelog;
+
+import javax.validation.*;
+
+import cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo.MessageLogPageReqVO;
+import cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo.MessageLogSaveReqVO;
+import cn.newfeifan.mall.module.trade.dal.dal.dataobject.messagelog.MessageLogDO;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+
+/**
+ * 微信消息记录 Service 接口
+ *
+ * @author 非繁人
+ */
+public interface MessageLogService {
+
+    /**
+     * 创建微信消息记录
+     *
+     * @param createReqVO 创建信息
+     * @return 编号
+     */
+    Long createMessageLog(@Valid MessageLogSaveReqVO createReqVO);
+
+    /**
+     * 更新微信消息记录
+     *
+     * @param updateReqVO 更新信息
+     */
+    void updateMessageLog(@Valid MessageLogSaveReqVO updateReqVO);
+
+    /**
+     * 删除微信消息记录
+     *
+     * @param id 编号
+     */
+    void deleteMessageLog(Long id);
+
+    /**
+     * 获得微信消息记录
+     *
+     * @param id 编号
+     * @return 微信消息记录
+     */
+    MessageLogDO getMessageLog(Long id);
+
+    /**
+     * 获得微信消息记录分页
+     *
+     * @param pageReqVO 分页查询
+     * @return 微信消息记录分页
+     */
+    PageResult<MessageLogDO> getMessageLogPage(MessageLogPageReqVO pageReqVO);
+
+}

+ 72 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/java/cn/newfeifan/mall/module/trade/service/messagelog/MessageLogServiceImpl.java

@@ -0,0 +1,72 @@
+package cn.newfeifan.mall.module.trade.service.messagelog;
+
+import cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo.MessageLogPageReqVO;
+import cn.newfeifan.mall.module.trade.controller.admin.messagelog.vo.MessageLogSaveReqVO;
+import org.springframework.stereotype.Service;
+import javax.annotation.Resource;
+import org.springframework.validation.annotation.Validated;
+
+import cn.newfeifan.mall.module.trade.dal.dal.dataobject.messagelog.MessageLogDO;
+import cn.newfeifan.mall.framework.common.pojo.PageResult;
+import cn.newfeifan.mall.framework.common.util.object.BeanUtils;
+
+import cn.newfeifan.mall.module.trade.dal.dal.mysql.messagelog.MessageLogMapper;
+
+import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
+import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.MESSAGE_LOG_NOT_EXISTS;
+
+/**
+ * 微信消息记录 Service 实现类
+ *
+ * @author 非繁人
+ */
+@Service
+@Validated
+public class MessageLogServiceImpl implements MessageLogService {
+
+    @Resource
+    private MessageLogMapper messageLogMapper;
+
+    @Override
+    public Long createMessageLog(MessageLogSaveReqVO createReqVO) {
+        // 插入
+        MessageLogDO messageLog = BeanUtils.toBean(createReqVO, MessageLogDO.class);
+        messageLogMapper.insert(messageLog);
+        // 返回
+        return messageLog.getId();
+    }
+
+    @Override
+    public void updateMessageLog(MessageLogSaveReqVO updateReqVO) {
+        // 校验存在
+        validateMessageLogExists(updateReqVO.getId());
+        // 更新
+        MessageLogDO updateObj = BeanUtils.toBean(updateReqVO, MessageLogDO.class);
+        messageLogMapper.updateById(updateObj);
+    }
+
+    @Override
+    public void deleteMessageLog(Long id) {
+        // 校验存在
+        validateMessageLogExists(id);
+        // 删除
+        messageLogMapper.deleteById(id);
+    }
+
+    private void validateMessageLogExists(Long id) {
+        if (messageLogMapper.selectById(id) == null) {
+            throw exception(MESSAGE_LOG_NOT_EXISTS);
+        }
+    }
+
+    @Override
+    public MessageLogDO getMessageLog(Long id) {
+        return messageLogMapper.selectById(id);
+    }
+
+    @Override
+    public PageResult<MessageLogDO> getMessageLogPage(MessageLogPageReqVO pageReqVO) {
+        return messageLogMapper.selectPage(pageReqVO);
+    }
+
+}

+ 12 - 0
feifan-module-mall/feifan-module-trade-biz/src/main/resources/mapper/messagelog/MessageLogMapper.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.newfeifan.mall.module.wechat.dal.mysql.messagelog.MessageLogMapper">
+
+    <!--
+        一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
+        无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
+        代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
+        文档可见:https://www.zhongxing.cn/MyBatis/x-plugins/
+     -->
+
+</mapper>