v3.0.0 springboot3+jdk17版本
This commit is contained in:
1 parent
3aa2c942dc
commit
b3ee447f8e
3676 files changed
+64366
-370384
No files matched your search
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>yshop-module-message</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>yshop-module-message-api</module>
|
||||
<module>yshop-module-message-biz</module>
|
||||
</modules>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
message 模块
|
||||
</description>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yshop-module-message</artifactId>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>yshop-module-message-api</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
message 模块 API,暴露给其它模块调用
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 参数校验 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- DB 相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-mybatis</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package co.yixiang.yshop.module.message.enums;
|
||||
|
||||
import co.yixiang.yshop.framework.common.exception.ErrorCode;
|
||||
|
||||
public interface ErrorCodeConstants {
|
||||
ErrorCode WECHAT_TEMPLATE_NOT_EXISTS = new ErrorCode(1008011000, "微信模板不存在");
|
||||
}
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2022
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.yshop.module.message.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author hupeng
|
||||
* 微信公众号模板枚举
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum WechatTempateEnum {
|
||||
PAY_SUCCESS("pay_success","支付成功通知"),
|
||||
DELIVERY_SUCCESS("delivery_success","发货成功通知"),
|
||||
REFUND_SUCCESS("refund_success","退款成功通知"),
|
||||
RECHARGE_SUCCESS("recharge_success","充值成功通知"),
|
||||
TEMPLATES("template","公众号模板消息"),
|
||||
SUBSCRIBE("subscribe","小程序订阅消息");
|
||||
|
||||
private String value; //模板编号
|
||||
private String desc; //模板id
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yshop-module-message</artifactId>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>yshop-module-message-biz</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>${project.artifactId}</name>
|
||||
<description>
|
||||
message 模块,模板消息 websocket 推送消息等等
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-message-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-module-member-biz</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- 业务组件 -->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>co.yixiang.boot</groupId>-->
|
||||
<!-- <artifactId>yshop-spring-boot-starter-biz-operatelog</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-biz-tenant</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Web 相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- 消息队列相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-mq</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Test 测试相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- 工具类相关 -->
|
||||
<dependency>
|
||||
<groupId>co.yixiang.boot</groupId>
|
||||
<artifactId>yshop-spring-boot-starter-excel</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package co.yixiang.yshop.module.message.controller.admin.wechattemplate;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.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 jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.framework.common.pojo.CommonResult;
|
||||
import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import co.yixiang.yshop.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo.*;
|
||||
import co.yixiang.yshop.module.message.dal.dataobject.wechattemplate.WechatTemplateDO;
|
||||
import co.yixiang.yshop.module.message.convert.wechattemplate.WechatTemplateConvert;
|
||||
import co.yixiang.yshop.module.message.service.wechattemplate.WechatTemplateService;
|
||||
|
||||
@Tag(name = "管理后台 - 微信模板")
|
||||
@RestController
|
||||
@RequestMapping("/message/wechat-template")
|
||||
@Validated
|
||||
public class WechatTemplateController {
|
||||
|
||||
@Resource
|
||||
private WechatTemplateService wechatTemplateService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建微信模板")
|
||||
@PreAuthorize("@ss.hasPermission('message:wechat-template:create')")
|
||||
public CommonResult<Integer> createWechatTemplate(@Valid @RequestBody WechatTemplateCreateReqVO createReqVO) {
|
||||
return success(wechatTemplateService.createWechatTemplate(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新微信模板")
|
||||
@PreAuthorize("@ss.hasPermission('message:wechat-template:update')")
|
||||
public CommonResult<Boolean> updateWechatTemplate(@Valid @RequestBody WechatTemplateUpdateReqVO updateReqVO) {
|
||||
wechatTemplateService.updateWechatTemplate(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除微信模板")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('message:wechat-template:delete')")
|
||||
public CommonResult<Boolean> deleteWechatTemplate(@RequestParam("id") Integer id) {
|
||||
wechatTemplateService.deleteWechatTemplate(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得微信模板")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('message:wechat-template:query')")
|
||||
public CommonResult<WechatTemplateRespVO> getWechatTemplate(@RequestParam("id") Integer id) {
|
||||
WechatTemplateDO wechatTemplate = wechatTemplateService.getWechatTemplate(id);
|
||||
return success(WechatTemplateConvert.INSTANCE.convert(wechatTemplate));
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得微信模板列表")
|
||||
@Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
|
||||
@PreAuthorize("@ss.hasPermission('message:wechat-template:query')")
|
||||
public CommonResult<List<WechatTemplateRespVO>> getWechatTemplateList(@RequestParam("ids") Collection<Integer> ids) {
|
||||
List<WechatTemplateDO> list = wechatTemplateService.getWechatTemplateList(ids);
|
||||
return success(WechatTemplateConvert.INSTANCE.convertList(list));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得微信模板分页")
|
||||
@PreAuthorize("@ss.hasPermission('message:wechat-template:query')")
|
||||
public CommonResult<PageResult<WechatTemplateRespVO>> getWechatTemplatePage(@Valid WechatTemplatePageReqVO pageVO) {
|
||||
PageResult<WechatTemplateDO> pageResult = wechatTemplateService.getWechatTemplatePage(pageVO);
|
||||
return success(WechatTemplateConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出微信模板 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('message:wechat-template:export')")
|
||||
public void exportWechatTemplateExcel(@Valid WechatTemplateExportReqVO exportReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
List<WechatTemplateDO> list = wechatTemplateService.getWechatTemplateList(exportReqVO);
|
||||
// 导出 Excel
|
||||
List<WechatTemplateExcelVO> datas = WechatTemplateConvert.INSTANCE.convertList02(list);
|
||||
ExcelUtils.write(response, "微信模板.xls", "数据", WechatTemplateExcelVO.class, datas);
|
||||
}
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
/**
|
||||
* 微信模板 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class WechatTemplateBaseVO {
|
||||
|
||||
@Schema(description = "模板编号", required = true)
|
||||
@NotNull(message = "模板编号不能为空")
|
||||
private String tempkey;
|
||||
|
||||
@Schema(description = "模板名", required = true, example = "张三")
|
||||
@NotNull(message = "模板名不能为空")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "回复内容", required = true)
|
||||
private String content;
|
||||
|
||||
@Schema(description = "模板ID", example = "15656")
|
||||
private String tempid;
|
||||
|
||||
@Schema(description = "状态", required = true, example = "1")
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Byte status;
|
||||
|
||||
@Schema(description = "类型:template:模板消息 subscribe:订阅消息", example = "1")
|
||||
private String type;
|
||||
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 微信模板创建 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class WechatTemplateCreateReqVO extends WechatTemplateBaseVO {
|
||||
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
|
||||
/**
|
||||
* 微信模板 Excel VO
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Data
|
||||
public class WechatTemplateExcelVO {
|
||||
|
||||
@ExcelProperty("模板id")
|
||||
private Integer id;
|
||||
|
||||
@ExcelProperty("模板编号")
|
||||
private String tempkey;
|
||||
|
||||
@ExcelProperty("模板名")
|
||||
private String name;
|
||||
|
||||
@ExcelProperty("回复内容")
|
||||
private String content;
|
||||
|
||||
@ExcelProperty("模板ID")
|
||||
private String tempid;
|
||||
|
||||
@ExcelProperty("添加时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@ExcelProperty("状态")
|
||||
private Byte status;
|
||||
|
||||
@ExcelProperty("类型:template:模板消息 subscribe:订阅消息")
|
||||
private String type;
|
||||
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageParam;
|
||||
import java.time.LocalDateTime;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 微信模板 Excel 导出 Request VO,参数和 WechatTemplatePageReqVO 是一致的")
|
||||
@Data
|
||||
public class WechatTemplateExportReqVO {
|
||||
|
||||
@Schema(description = "模板编号")
|
||||
private String tempkey;
|
||||
|
||||
@Schema(description = "模板名", example = "张三")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "回复内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "模板ID", example = "15656")
|
||||
private String tempid;
|
||||
|
||||
@Schema(description = "添加时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
private Byte status;
|
||||
|
||||
@Schema(description = "类型:template:模板消息 subscribe:订阅消息", example = "1")
|
||||
private String type;
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static co.yixiang.yshop.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 WechatTemplatePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "模板编号")
|
||||
private String tempkey;
|
||||
|
||||
@Schema(description = "模板名", example = "张三")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "回复内容")
|
||||
private String content;
|
||||
|
||||
@Schema(description = "模板ID", example = "15656")
|
||||
private String tempid;
|
||||
|
||||
@Schema(description = "添加时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
|
||||
@Schema(description = "状态", example = "1")
|
||||
private Byte status;
|
||||
|
||||
@Schema(description = "类型:template:模板消息 subscribe:订阅消息", example = "1")
|
||||
private String type;
|
||||
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 微信模板 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class WechatTemplateRespVO extends WechatTemplateBaseVO {
|
||||
|
||||
@Schema(description = "模板id", required = true, example = "8445")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "添加时间", required = true)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 微信模板更新 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class WechatTemplateUpdateReqVO extends WechatTemplateBaseVO {
|
||||
|
||||
@Schema(description = "模板id", required = true, example = "8445")
|
||||
@NotNull(message = "模板id不能为空")
|
||||
private Integer id;
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package co.yixiang.yshop.module.message.convert.wechattemplate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
import co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo.*;
|
||||
import co.yixiang.yshop.module.message.dal.dataobject.wechattemplate.WechatTemplateDO;
|
||||
|
||||
/**
|
||||
* 微信模板 Convert
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Mapper
|
||||
public interface WechatTemplateConvert {
|
||||
|
||||
WechatTemplateConvert INSTANCE = Mappers.getMapper(WechatTemplateConvert.class);
|
||||
|
||||
WechatTemplateDO convert(WechatTemplateCreateReqVO bean);
|
||||
|
||||
WechatTemplateDO convert(WechatTemplateUpdateReqVO bean);
|
||||
|
||||
WechatTemplateRespVO convert(WechatTemplateDO bean);
|
||||
|
||||
List<WechatTemplateRespVO> convertList(List<WechatTemplateDO> list);
|
||||
|
||||
PageResult<WechatTemplateRespVO> convertPage(PageResult<WechatTemplateDO> page);
|
||||
|
||||
List<WechatTemplateExcelVO> convertList02(List<WechatTemplateDO> list);
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package co.yixiang.yshop.module.message.dal.dataobject.wechattemplate;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import co.yixiang.yshop.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 微信模板 DO
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@TableName("yshop_wechat_template")
|
||||
@KeySequence("yshop_wechat_template_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class WechatTemplateDO extends BaseDO {
|
||||
|
||||
/**
|
||||
* 模板id
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 模板编号
|
||||
*/
|
||||
private String tempkey;
|
||||
/**
|
||||
* 模板名
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 回复内容
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 模板ID
|
||||
*/
|
||||
private String tempid;
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
private Byte status;
|
||||
/**
|
||||
* 类型:template:模板消息 subscribe:订阅消息
|
||||
*/
|
||||
private String type;
|
||||
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package co.yixiang.yshop.module.message.dal.mysql.wechattemplate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import co.yixiang.yshop.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import co.yixiang.yshop.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import co.yixiang.yshop.module.message.dal.dataobject.wechattemplate.WechatTemplateDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo.*;
|
||||
|
||||
/**
|
||||
* 微信模板 Mapper
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Mapper
|
||||
public interface WechatTemplateMapper extends BaseMapperX<WechatTemplateDO> {
|
||||
|
||||
default PageResult<WechatTemplateDO> selectPage(WechatTemplatePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<WechatTemplateDO>()
|
||||
.eqIfPresent(WechatTemplateDO::getTempkey, reqVO.getTempkey())
|
||||
.likeIfPresent(WechatTemplateDO::getName, reqVO.getName())
|
||||
.eqIfPresent(WechatTemplateDO::getContent, reqVO.getContent())
|
||||
.eqIfPresent(WechatTemplateDO::getTempid, reqVO.getTempid())
|
||||
.betweenIfPresent(WechatTemplateDO::getCreateTime, reqVO.getCreateTime())
|
||||
.eqIfPresent(WechatTemplateDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(WechatTemplateDO::getType, reqVO.getType())
|
||||
.orderByDesc(WechatTemplateDO::getId));
|
||||
}
|
||||
|
||||
default List<WechatTemplateDO> selectList(WechatTemplateExportReqVO reqVO) {
|
||||
return selectList(new LambdaQueryWrapperX<WechatTemplateDO>()
|
||||
.eqIfPresent(WechatTemplateDO::getTempkey, reqVO.getTempkey())
|
||||
.likeIfPresent(WechatTemplateDO::getName, reqVO.getName())
|
||||
.eqIfPresent(WechatTemplateDO::getContent, reqVO.getContent())
|
||||
.eqIfPresent(WechatTemplateDO::getTempid, reqVO.getTempid())
|
||||
.betweenIfPresent(WechatTemplateDO::getCreateTime, reqVO.getCreateTime())
|
||||
.eqIfPresent(WechatTemplateDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(WechatTemplateDO::getType, reqVO.getType())
|
||||
.orderByDesc(WechatTemplateDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package co.yixiang.yshop.module.message.mq.consumer;
|
||||
|
||||
|
||||
import co.yixiang.yshop.framework.mq.redis.core.stream.AbstractRedisStreamMessageListener;
|
||||
import co.yixiang.yshop.module.message.enums.WechatTempateEnum;
|
||||
import co.yixiang.yshop.module.message.mq.message.WeixinNoticeMessage;
|
||||
import co.yixiang.yshop.module.message.supply.WeiXinSubscribeService;
|
||||
import co.yixiang.yshop.module.message.supply.WeixinTemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
|
||||
/**
|
||||
* 消息队列处理消息推送
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class WeixinNoticeConsumer extends AbstractRedisStreamMessageListener<WeixinNoticeMessage> {
|
||||
|
||||
@Resource
|
||||
private WeiXinSubscribeService weiXinSubscribeService;
|
||||
@Resource
|
||||
private WeixinTemplateService weixinTemplateService;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onMessage(WeixinNoticeMessage message) {
|
||||
log.info("[onMessage][消息内容({})]", message);
|
||||
//公众号
|
||||
if(WechatTempateEnum.TEMPLATES.getValue().equals(message.getType())) {
|
||||
if(WechatTempateEnum.PAY_SUCCESS.getValue().equals(message.getTempkey())){
|
||||
weixinTemplateService.paySuccessNotice(message.getOrderId(),message.getPrice(),message.getUid());
|
||||
}else if(WechatTempateEnum.DELIVERY_SUCCESS.getValue().equals(message.getTempkey())){
|
||||
weixinTemplateService.deliverySuccessNotice(message.getOrderId(),message.getDeliveryName(),
|
||||
message.getDeliveryId(),message.getUid());
|
||||
} else if(WechatTempateEnum.REFUND_SUCCESS.getValue().equals(message.getTempkey())){
|
||||
weixinTemplateService.refundSuccessNotice("您的订单退款申请被通过,钱款将很快还至您的支付账户。",
|
||||
message.getOrderId(),message.getDeliveryName(),message.getUid(),message.getTime());
|
||||
}
|
||||
|
||||
}else if(WechatTempateEnum.SUBSCRIBE.getValue().equals(message.getType())){
|
||||
//小程序
|
||||
if(WechatTempateEnum.PAY_SUCCESS.getValue().equals(message.getTempkey())){
|
||||
weiXinSubscribeService.paySuccessNotice(message.getNumberId().toString(),message.getProductName()
|
||||
,message.getShopName(),message.getUid(),message.getId(),message.getOrderId());
|
||||
}else if(WechatTempateEnum.DELIVERY_SUCCESS.getValue().equals(message.getTempkey())){
|
||||
weiXinSubscribeService.deliverySuccessNotice(message.getOrderId(),message.getDeliveryName(),
|
||||
message.getDeliveryId(),message.getUid());
|
||||
} else if(WechatTempateEnum.REFUND_SUCCESS.getValue().equals(message.getTempkey())){
|
||||
weiXinSubscribeService.refundSuccessNotice(message.getOrderId(),message.getDeliveryName(),
|
||||
message.getUid(),message.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package co.yixiang.yshop.module.message.mq.message;
|
||||
|
||||
|
||||
import co.yixiang.yshop.framework.mq.redis.core.stream.AbstractRedisStreamMessage;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WeixinNoticeMessage extends AbstractRedisStreamMessage {
|
||||
|
||||
/**
|
||||
* 模板编号
|
||||
*/
|
||||
private String tempkey;
|
||||
|
||||
//消息类型
|
||||
private String type;
|
||||
|
||||
//订单好
|
||||
private String orderId;
|
||||
|
||||
//价格
|
||||
private String price;
|
||||
|
||||
//用户
|
||||
private Long uid;
|
||||
|
||||
//时间
|
||||
private String time;
|
||||
|
||||
// 快递公司
|
||||
private String deliveryName;
|
||||
|
||||
// 快递单号
|
||||
private String deliveryId;
|
||||
|
||||
//订单ID
|
||||
private Long id;
|
||||
|
||||
//取餐号
|
||||
private Integer numberId;
|
||||
|
||||
//产品名称
|
||||
private String productName;
|
||||
|
||||
//门店名称
|
||||
private String shopName;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getStreamKey() {
|
||||
return "weixin.msg.notice";
|
||||
}
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package co.yixiang.yshop.module.message.mq.producer;
|
||||
|
||||
import co.yixiang.yshop.framework.mq.redis.core.RedisMQTemplate;
|
||||
import co.yixiang.yshop.module.message.mq.message.WeixinNoticeMessage;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class WeixinNoticeProducer {
|
||||
@Resource
|
||||
private RedisMQTemplate redisMQTemplate;
|
||||
|
||||
/**
|
||||
* 发送消息
|
||||
* @param tempkey 订单编号
|
||||
* @param type 类型
|
||||
*/
|
||||
public void sendNoticeMessage( Long uid,String tempkey,String type,String orderId,String price,
|
||||
String time,String deliveryName,String deliveryId,
|
||||
Long id,Integer numberId,String productName,String shopName) {
|
||||
WeixinNoticeMessage weixinNoticeMessage = new WeixinNoticeMessage()
|
||||
.setTempkey(tempkey).setType(type).setOrderId(orderId).setUid(uid)
|
||||
.setPrice(price).setDeliveryId(deliveryId).setTime(time).setDeliveryName(deliveryName)
|
||||
.setId(id).setNumberId(numberId).setProductName(productName).setShopName(shopName);
|
||||
redisMQTemplate.send(weixinNoticeMessage);
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package co.yixiang.yshop.module.message.service.wechattemplate;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
|
||||
import co.yixiang.yshop.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo.*;
|
||||
import co.yixiang.yshop.module.message.dal.dataobject.wechattemplate.WechatTemplateDO;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* 微信模板 Service 接口
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
public interface WechatTemplateService extends IService<WechatTemplateDO> {
|
||||
|
||||
/**
|
||||
* 创建微信模板
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createWechatTemplate(@Valid WechatTemplateCreateReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新微信模板
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateWechatTemplate(@Valid WechatTemplateUpdateReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除微信模板
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteWechatTemplate(Integer id);
|
||||
|
||||
/**
|
||||
* 获得微信模板
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 微信模板
|
||||
*/
|
||||
WechatTemplateDO getWechatTemplate(Integer id);
|
||||
|
||||
/**
|
||||
* 获得微信模板列表
|
||||
*
|
||||
* @param ids 编号
|
||||
* @return 微信模板列表
|
||||
*/
|
||||
List<WechatTemplateDO> getWechatTemplateList(Collection<Integer> ids);
|
||||
|
||||
/**
|
||||
* 获得微信模板分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 微信模板分页
|
||||
*/
|
||||
PageResult<WechatTemplateDO> getWechatTemplatePage(WechatTemplatePageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得微信模板列表, 用于 Excel 导出
|
||||
*
|
||||
* @param exportReqVO 查询条件
|
||||
* @return 微信模板列表
|
||||
*/
|
||||
List<WechatTemplateDO> getWechatTemplateList(WechatTemplateExportReqVO exportReqVO);
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package co.yixiang.yshop.module.message.service.wechattemplate;
|
||||
|
||||
import co.yixiang.yshop.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import co.yixiang.yshop.module.member.dal.mysql.user.MemberUserMapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import co.yixiang.yshop.module.message.controller.admin.wechattemplate.vo.*;
|
||||
import co.yixiang.yshop.module.message.dal.dataobject.wechattemplate.WechatTemplateDO;
|
||||
import co.yixiang.yshop.framework.common.pojo.PageResult;
|
||||
|
||||
import co.yixiang.yshop.module.message.convert.wechattemplate.WechatTemplateConvert;
|
||||
import co.yixiang.yshop.module.message.dal.mysql.wechattemplate.WechatTemplateMapper;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.module.message.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 微信模板 Service 实现类
|
||||
*
|
||||
* @author yshop
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class WechatTemplateServiceImpl extends ServiceImpl<WechatTemplateMapper, WechatTemplateDO> implements WechatTemplateService {
|
||||
|
||||
@Resource
|
||||
private WechatTemplateMapper wechatTemplateMapper;
|
||||
|
||||
@Override
|
||||
public Integer createWechatTemplate(WechatTemplateCreateReqVO createReqVO) {
|
||||
// 插入
|
||||
WechatTemplateDO wechatTemplate = WechatTemplateConvert.INSTANCE.convert(createReqVO);
|
||||
wechatTemplateMapper.insert(wechatTemplate);
|
||||
// 返回
|
||||
return wechatTemplate.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateWechatTemplate(WechatTemplateUpdateReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateWechatTemplateExists(updateReqVO.getId());
|
||||
// 更新
|
||||
WechatTemplateDO updateObj = WechatTemplateConvert.INSTANCE.convert(updateReqVO);
|
||||
wechatTemplateMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteWechatTemplate(Integer id) {
|
||||
// 校验存在
|
||||
validateWechatTemplateExists(id);
|
||||
// 删除
|
||||
wechatTemplateMapper.deleteById(id);
|
||||
}
|
||||
|
||||
private void validateWechatTemplateExists(Integer id) {
|
||||
if (wechatTemplateMapper.selectById(id) == null) {
|
||||
throw exception(WECHAT_TEMPLATE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WechatTemplateDO getWechatTemplate(Integer id) {
|
||||
return wechatTemplateMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WechatTemplateDO> getWechatTemplateList(Collection<Integer> ids) {
|
||||
return wechatTemplateMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<WechatTemplateDO> getWechatTemplatePage(WechatTemplatePageReqVO pageReqVO) {
|
||||
return wechatTemplateMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<WechatTemplateDO> getWechatTemplateList(WechatTemplateExportReqVO exportReqVO) {
|
||||
return wechatTemplateMapper.selectList(exportReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
package co.yixiang.yshop.module.message.supply;
|
||||
|
||||
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.yshop.framework.common.constant.ShopConstants;
|
||||
import co.yixiang.yshop.framework.common.enums.ShopCommonEnum;
|
||||
import co.yixiang.yshop.framework.common.exception.ErrorCode;
|
||||
import co.yixiang.yshop.framework.tenant.core.aop.TenantIgnore;
|
||||
import co.yixiang.yshop.framework.tenant.core.util.TenantUtils;
|
||||
import co.yixiang.yshop.module.member.api.user.dto.WechatUserDto;
|
||||
import co.yixiang.yshop.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import co.yixiang.yshop.module.member.service.user.MemberUserService;
|
||||
import co.yixiang.yshop.module.message.dal.dataobject.wechattemplate.WechatTemplateDO;
|
||||
import co.yixiang.yshop.module.message.enums.WechatTempateEnum;
|
||||
import co.yixiang.yshop.module.message.service.wechattemplate.WechatTemplateService;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static co.yixiang.yshop.module.system.enums.ErrorCodeConstants.USER_USERNAME_EXISTS;
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* 小程序订阅消息通知
|
||||
*/
|
||||
@Service
|
||||
public class WeiXinSubscribeService {
|
||||
|
||||
@Resource
|
||||
private MemberUserService userService;
|
||||
@Resource
|
||||
private WechatTemplateService wechatTemplateService;
|
||||
@Resource
|
||||
private WxMaService wxMaService;
|
||||
|
||||
|
||||
/**
|
||||
* 充值成功通知
|
||||
* @param time 时间
|
||||
* @param price 金额
|
||||
* @param uid uid
|
||||
*/
|
||||
public void rechargeSuccessNotice(String time,String price,Long uid){
|
||||
String openid = this.getUserOpenid(uid);
|
||||
|
||||
if(StrUtil.isBlank(openid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("first","您的账户金币发生变动,详情如下:");
|
||||
map.put("keyword1","充值");
|
||||
map.put("keyword2",time);
|
||||
map.put("keyword3",price);
|
||||
map.put("remark", ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
|
||||
String tempId = this.getTempId(WechatTempateEnum.RECHARGE_SUCCESS.getValue());
|
||||
if(StrUtil.isNotBlank(tempId)) {
|
||||
this.sendSubscribeMsg( openid, tempId, "/user/account",map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付成功通知
|
||||
* @param numberId 取餐号
|
||||
* @param productName 商品名称
|
||||
* @param shopName 门店名称
|
||||
* @param uid uid
|
||||
* @param id 订单ID
|
||||
*/
|
||||
public void paySuccessNotice(String numberId,String productName,String shopName,Long uid,Long id,String orderId){
|
||||
TenantUtils.executeIgnore(() -> {
|
||||
String openid = this.getUserOpenid(uid);
|
||||
if(StrUtil.isBlank(openid)) {
|
||||
return;
|
||||
}
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
|
||||
Map<String,String> map = new HashMap<>();
|
||||
//取餐号
|
||||
map.put("character_string1",numberId);
|
||||
//商品名
|
||||
map.put("thing2", productName);
|
||||
map.put("time3",simpleDateFormat.format(new Date()));
|
||||
//下单门店
|
||||
map.put("thing4",shopName);
|
||||
map.put("thing5","意向点餐系统为您服务!");
|
||||
String tempId = this.getTempId(WechatTempateEnum.PAY_SUCCESS.getValue());
|
||||
if(StrUtil.isNotBlank(tempId)) {
|
||||
this.sendSubscribeMsg( openid,tempId, "/pages/components/pages/orders/detail?id="+orderId,map);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款成功通知
|
||||
* @param orderId 订单号
|
||||
* @param price 金额
|
||||
* @param uid uid
|
||||
* @param time 时间
|
||||
*/
|
||||
public void refundSuccessNotice(String orderId,String price,Long uid,String time){
|
||||
|
||||
TenantUtils.executeIgnore(() -> {
|
||||
String openid = this.getUserOpenid(uid);
|
||||
|
||||
if(StrUtil.isBlank(openid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("first","您的订单退款申请被通过,钱款将很快还至您的支付账户。");
|
||||
//订单号
|
||||
map.put("keyword1",orderId);
|
||||
map.put("keyword2",price);
|
||||
map.put("keyword3", time);
|
||||
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
|
||||
String tempId = this.getTempId(WechatTempateEnum.REFUND_SUCCESS.getValue());
|
||||
if(StrUtil.isNotBlank(tempId)) {
|
||||
this.sendSubscribeMsg( openid,tempId, "/order/detail/"+orderId,map);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 发货成功通知
|
||||
* @param orderId 单号
|
||||
* @param deliveryName 快递公司
|
||||
* @param deliveryId 快递单号
|
||||
* @param uid uid
|
||||
*/
|
||||
public void deliverySuccessNotice(String orderId,String deliveryName,
|
||||
String deliveryId,Long uid){
|
||||
|
||||
TenantUtils.executeIgnore(() -> {
|
||||
String openid = this.getUserOpenid(uid);
|
||||
|
||||
if(StrUtil.isEmpty(openid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("first","亲,宝贝已经启程了,好想快点来到你身边。");
|
||||
map.put("keyword2",deliveryName);
|
||||
map.put("keyword1",orderId);
|
||||
map.put("keyword3",deliveryId);
|
||||
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
|
||||
String tempId = this.getTempId(WechatTempateEnum.DELIVERY_SUCCESS.getValue());
|
||||
if(StrUtil.isNotBlank(tempId)) {
|
||||
this.sendSubscribeMsg( openid,tempId, "/order/detail/"+orderId,map);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建小程序一次性订阅消息
|
||||
* @param openId 单号
|
||||
* @param templateId 模板id
|
||||
* @param page 跳转页面
|
||||
* @param map map内容
|
||||
* @return String
|
||||
*/
|
||||
private void sendSubscribeMsg(String openId, String templateId, String page, Map<String,String> map){
|
||||
WxMaSubscribeMessage wxMaSubscribeMessage = WxMaSubscribeMessage.builder()
|
||||
.toUser(openId)
|
||||
.templateId(templateId)
|
||||
.page(page)
|
||||
.build();
|
||||
map.forEach( (k,v)-> { wxMaSubscribeMessage.addData(new WxMaSubscribeMessage.MsgData(k, v));} );
|
||||
// WxMaService wxMaService = WxMaConfiguration.getWxMaService();
|
||||
try {
|
||||
wxMaService.getMsgService().sendSubscribeMsg(wxMaSubscribeMessage);
|
||||
} catch (WxErrorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板消息id
|
||||
* @param key 模板key
|
||||
* @return string
|
||||
*/
|
||||
@TenantIgnore
|
||||
private String getTempId(String key){
|
||||
WechatTemplateDO yxWechatTemplate = wechatTemplateService.lambdaQuery()
|
||||
.eq(WechatTemplateDO::getType,"subscribe")
|
||||
.eq(WechatTemplateDO::getTempkey,key)
|
||||
.one();
|
||||
if (yxWechatTemplate == null) {
|
||||
throw exception(new ErrorCode(9999999,"请后台配置key:" + key + "订阅消息id"));
|
||||
}
|
||||
if(ShopCommonEnum.IS_STATUS_0.getValue().equals(yxWechatTemplate.getStatus())){
|
||||
return "";
|
||||
}
|
||||
return yxWechatTemplate.getTempid();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取openid
|
||||
* @param uid uid
|
||||
* @return String
|
||||
*/
|
||||
@TenantIgnore
|
||||
private String getUserOpenid(Long uid){
|
||||
MemberUserDO yxUser = userService.getById(uid);
|
||||
if(yxUser == null) {
|
||||
return "";
|
||||
}
|
||||
if(StrUtil.isBlank(yxUser.getRoutineOpenid())) {
|
||||
return "";
|
||||
}
|
||||
return yxUser.getRoutineOpenid();
|
||||
|
||||
}
|
||||
}
|
||||
+241
@@ -0,0 +1,241 @@
|
||||
/**
|
||||
* Copyright (C) 2018-2022
|
||||
* All rights reserved, Designed By www.yixiang.co
|
||||
* 注意:
|
||||
* 本软件为www.yixiang.co开发研制,未经购买不得使用
|
||||
* 购买后可获得全部源代码(禁止转卖、分享、上传到码云、github等开源平台)
|
||||
* 一经发现盗用、分享等行为,将追究法律责任,后果自负
|
||||
*/
|
||||
package co.yixiang.yshop.module.message.supply;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import co.yixiang.yshop.framework.common.constant.ShopConstants;
|
||||
import co.yixiang.yshop.framework.common.enums.ShopCommonEnum;
|
||||
import co.yixiang.yshop.framework.common.exception.ErrorCode;
|
||||
import co.yixiang.yshop.module.member.api.user.dto.WechatUserDto;
|
||||
import co.yixiang.yshop.module.member.dal.dataobject.user.MemberUserDO;
|
||||
import co.yixiang.yshop.module.member.service.user.MemberUserService;
|
||||
import co.yixiang.yshop.module.message.dal.dataobject.wechattemplate.WechatTemplateDO;
|
||||
import co.yixiang.yshop.module.message.enums.WechatTempateEnum;
|
||||
import co.yixiang.yshop.module.message.service.wechattemplate.WechatTemplateService;
|
||||
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.template.WxMpTemplateData;
|
||||
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static co.yixiang.yshop.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
|
||||
/**
|
||||
* @ClassName 微信公众号模板通知
|
||||
* @Author hupeng <610796224@qq.com>
|
||||
* @Date 2020/6/27
|
||||
**/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class WeixinTemplateService {
|
||||
|
||||
|
||||
@Resource
|
||||
private MemberUserService userService;
|
||||
@Resource
|
||||
private WechatTemplateService wechatTemplateService;
|
||||
@Resource
|
||||
private WxMpService wxMpService;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 充值成功通知
|
||||
* @param time 时间
|
||||
* @param price 金额
|
||||
* @param uid uid
|
||||
*/
|
||||
public void rechargeSuccessNotice(String time,String price,Long uid){
|
||||
String openid = this.getUserOpenid(uid);
|
||||
|
||||
if(StrUtil.isBlank(openid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("first","您的账户金币发生变动,详情如下:");
|
||||
map.put("keyword1","充值");
|
||||
map.put("keyword2",time);
|
||||
map.put("keyword3",price);
|
||||
map.put("remark", ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
|
||||
String tempId = this.getTempId(WechatTempateEnum.RECHARGE_SUCCESS.getValue());
|
||||
if(StrUtil.isNotBlank(tempId)) {
|
||||
this.sendWxMpTemplateMessage( openid, tempId, "https://www.yixiang.co",map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付成功通知
|
||||
* @param orderId 订单号
|
||||
* @param price 金额
|
||||
* @param uid uid
|
||||
*/
|
||||
public void paySuccessNotice(String orderId,String price,Long uid){
|
||||
|
||||
String openid = this.getUserOpenid(uid);
|
||||
|
||||
if(StrUtil.isBlank(openid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("first","您的订单已支付成功,我们会尽快为您发货。");
|
||||
//订单号
|
||||
map.put("keyword1",orderId);
|
||||
map.put("keyword2",price);
|
||||
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
|
||||
String tempId = this.getTempId(WechatTempateEnum.PAY_SUCCESS.getValue());
|
||||
if(StrUtil.isNotBlank(tempId)) {
|
||||
this.sendWxMpTemplateMessage( openid,tempId, "https://www.yixiang.co",map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 退款成功通知
|
||||
* @param orderId 订单号
|
||||
* @param price 金额
|
||||
* @param uid uid
|
||||
* @param time 时间
|
||||
*/
|
||||
public void refundSuccessNotice(String title,String orderId,String price,Long uid,String time){
|
||||
|
||||
String openid = this.getUserOpenid(uid);
|
||||
|
||||
if(StrUtil.isBlank(openid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("first",title);
|
||||
//订单号
|
||||
map.put("keyword1",orderId);
|
||||
map.put("keyword2",price);
|
||||
map.put("keyword3", time);
|
||||
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
|
||||
String tempId = this.getTempId(WechatTempateEnum.REFUND_SUCCESS.getValue());
|
||||
if(StrUtil.isNotBlank(tempId)) {
|
||||
this.sendWxMpTemplateMessage( openid,tempId, "https://www.yixiang.co",map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发货成功通知
|
||||
* @param orderId 单号
|
||||
* @param deliveryName 快递公司
|
||||
* @param deliveryId 快递单号
|
||||
* @param uid uid
|
||||
*/
|
||||
public void deliverySuccessNotice(String orderId,String deliveryName,
|
||||
String deliveryId,Long uid){
|
||||
|
||||
String openid = this.getUserOpenid(uid);
|
||||
|
||||
if(StrUtil.isEmpty(openid)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("first","亲,宝贝已经启程了,好想快点来到你身边。");
|
||||
map.put("keyword2",deliveryName);
|
||||
map.put("keyword1",orderId);
|
||||
map.put("keyword3",deliveryId);
|
||||
map.put("remark",ShopConstants.YSHOP_WECHAT_PUSH_REMARK);
|
||||
String tempId = this.getTempId(WechatTempateEnum.DELIVERY_SUCCESS.getValue());
|
||||
if(StrUtil.isNotBlank(tempId)) {
|
||||
this.sendWxMpTemplateMessage( openid,tempId, "https://www.yixiang.co",map);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建微信模板通知
|
||||
* @param openId 单号
|
||||
* @param templateId 模板id
|
||||
* @param url 跳转url
|
||||
* @param map map内容
|
||||
* @return String
|
||||
*/
|
||||
private String sendWxMpTemplateMessage(String openId, String templateId, String url, Map<String,String> map){
|
||||
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
|
||||
.toUser(openId)
|
||||
.templateId(templateId)
|
||||
.url(url)
|
||||
.build();
|
||||
map.forEach( (k,v)-> { templateMessage.addData(new WxMpTemplateData(k, v, "#000000"));} );
|
||||
String msgId = null;
|
||||
try {
|
||||
msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
|
||||
} catch (WxErrorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return msgId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取模板消息id
|
||||
* @param key 模板key
|
||||
* @return string
|
||||
*/
|
||||
private String getTempId(String key){
|
||||
WechatTemplateDO yxWechatTemplate = wechatTemplateService.lambdaQuery()
|
||||
.eq(WechatTemplateDO::getType,"template")
|
||||
.eq(WechatTemplateDO::getTempkey,key)
|
||||
.one();
|
||||
if (yxWechatTemplate == null) {
|
||||
throw exception(new ErrorCode(9999999,"请后台配置key:" + key + "订阅消息id"));
|
||||
}
|
||||
|
||||
if(ShopCommonEnum.IS_STATUS_0.getValue().equals(yxWechatTemplate.getStatus())){
|
||||
return "";
|
||||
}
|
||||
|
||||
return yxWechatTemplate.getTempid();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取openid
|
||||
* @param uid uid
|
||||
* @return String
|
||||
*/
|
||||
private String getUserOpenid(Long uid){
|
||||
MemberUserDO yxUser = userService.getById(uid);
|
||||
if(yxUser == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
WechatUserDto wechatUserDto = yxUser.getWxProfile();
|
||||
if(wechatUserDto == null) {
|
||||
return "";
|
||||
}
|
||||
if(StrUtil.isBlank(wechatUserDto.getOpenid())) {
|
||||
return "";
|
||||
}
|
||||
return wechatUserDto.getOpenid();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+12
@@ -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="co.yixiang.yshop.module.message.dal.mysql.wechattemplate.WechatTemplateMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.yixiang.co/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in new issue
Block a user