From f4e2bb11c8eaec32b1628c79c501bc1be13c2927 Mon Sep 17 00:00:00 2001 From: guming Date: Wed, 30 Jul 2025 18:15:52 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BB=A3=E7=90=86=E5=95=86=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hake-module-agent-api/pom.xml | 45 ++++++ .../hake/module/agent/api/package-info.java | 4 + .../hake/module/agent/enums/ApiConstants.java | 23 +++ .../agent/enums/ErrorCodeConstants.java | 9 ++ .../agent/enums/agent/AuditStatusEnum.java | 92 +++++++++++ .../agent/enums/agent/JudgeFlagEnum.java | 67 ++++++++ .../hake-module-agent-server/Dockerfile | 19 +++ .../hake-module-agent-server/pom.xml | 135 +++++++++++++++++ .../module/agent/AgentServerApplication.java | 19 +++ .../admin/agent/AgentController.java | 110 ++++++++++++++ .../admin/agent/vo/AgentPageReqVO.java | 104 +++++++++++++ .../admin/agent/vo/AgentRespVO.java | 137 +++++++++++++++++ .../admin/agent/vo/AgentSaveReqVO.java | 104 +++++++++++++ .../admin/agent/vo/AuditRespVO.java | 25 +++ .../agent/dal/dataobject/agent/AgentDO.java | 143 ++++++++++++++++++ .../agent/dal/mysql/agent/AgentMapper.java | 51 +++++++ .../module/agent/framework/package-info.java | 6 + .../rpc/config/RpcConfiguration.java | 10 ++ .../agent/framework/rpc/package-info.java | 4 + .../config/SecurityConfiguration.java | 39 +++++ .../framework/security/core/package-info.java | 4 + .../hake/module/agent/package-info.java | 10 ++ .../agent/service/agent/AgentService.java | 67 ++++++++ .../agent/service/agent/AgentServiceImpl.java | 134 ++++++++++++++++ .../src/main/resources/application-dev.yaml | 110 ++++++++++++++ .../src/main/resources/application-local.yaml | 135 +++++++++++++++++ .../src/main/resources/application.yaml | 124 +++++++++++++++ .../src/main/resources/logback-spring.xml | 76 ++++++++++ .../resources/mapper/agent/AgentMapper.xml | 12 ++ hake-module-agent/pom.xml | 23 +++ pom.xml | 1 + 31 files changed, 1842 insertions(+) create mode 100644 hake-module-agent/hake-module-agent-api/pom.xml create mode 100644 hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/api/package-info.java create mode 100644 hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/ApiConstants.java create mode 100644 hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/ErrorCodeConstants.java create mode 100644 hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/agent/AuditStatusEnum.java create mode 100644 hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/agent/JudgeFlagEnum.java create mode 100644 hake-module-agent/hake-module-agent-server/Dockerfile create mode 100644 hake-module-agent/hake-module-agent-server/pom.xml create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/AgentServerApplication.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/AgentController.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentPageReqVO.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentRespVO.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentSaveReqVO.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AuditRespVO.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/dal/dataobject/agent/AgentDO.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/dal/mysql/agent/AgentMapper.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/package-info.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/rpc/config/RpcConfiguration.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/rpc/package-info.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/security/config/SecurityConfiguration.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/security/core/package-info.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/package-info.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/service/agent/AgentService.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/service/agent/AgentServiceImpl.java create mode 100644 hake-module-agent/hake-module-agent-server/src/main/resources/application-dev.yaml create mode 100644 hake-module-agent/hake-module-agent-server/src/main/resources/application-local.yaml create mode 100644 hake-module-agent/hake-module-agent-server/src/main/resources/application.yaml create mode 100644 hake-module-agent/hake-module-agent-server/src/main/resources/logback-spring.xml create mode 100644 hake-module-agent/hake-module-agent-server/src/main/resources/mapper/agent/AgentMapper.xml create mode 100644 hake-module-agent/pom.xml diff --git a/hake-module-agent/hake-module-agent-api/pom.xml b/hake-module-agent/hake-module-agent-api/pom.xml new file mode 100644 index 0000000..043f989 --- /dev/null +++ b/hake-module-agent/hake-module-agent-api/pom.xml @@ -0,0 +1,45 @@ + + + + cn.iocoder.cloud + hake-module-agent + ${revision} + + 4.0.0 + hake-module-agent-api + jar + + ${project.artifactId} + + agent 模块 API,暴露给其它模块调用 + + + + + cn.iocoder.cloud + hake-common + + + + + org.springframework.boot + spring-boot-starter-validation + true + + + + + central + Central Repository + http://192.168.1.200:19081/repository/maven-hake/ + + + snapshots + Nexus Snapshot Repository + http://192.168.1.200:19081/repository/maven-snapshots/ + + + + \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/api/package-info.java b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/api/package-info.java new file mode 100644 index 0000000..e1f3a0c --- /dev/null +++ b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/api/package-info.java @@ -0,0 +1,4 @@ +/** + * agent API 包,定义暴露给其它模块的 API + */ +package cn.iocoder.hake.module.erp.api; diff --git a/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/ApiConstants.java b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/ApiConstants.java new file mode 100644 index 0000000..daf4e01 --- /dev/null +++ b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/ApiConstants.java @@ -0,0 +1,23 @@ +package cn.iocoder.hake.module.agent.enums; + +import cn.iocoder.hake.framework.common.enums.RpcConstants; + +/** + * API 相关的枚举 + * + * @author hake + */ +public class ApiConstants { + + /** + * 服务名 + * + * 注意,需要保证和 spring.application.name 保持一致 + */ + public static final String NAME = "agent-server"; + + public static final String PREFIX = RpcConstants.RPC_API_PREFIX + "/agent"; + + public static final String VERSION = "1.0.0"; + +} diff --git a/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/ErrorCodeConstants.java b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/ErrorCodeConstants.java new file mode 100644 index 0000000..55d2d18 --- /dev/null +++ b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/ErrorCodeConstants.java @@ -0,0 +1,9 @@ +package cn.iocoder.hake.module.agent.enums; + +import cn.iocoder.hake.framework.common.exception.ErrorCode; +public interface ErrorCodeConstants { + // TODO 待办:请将下面的错误码复制到 hake-module-agent 模块的 ErrorCodeConstants 类中。注意,请给“TODO 补充编号”设置一个错误码编号!!! +// ========== 代理商管理 TODO 补充编号 ========== + ErrorCode AGENT_NOT_EXISTS = new ErrorCode(1_050_100_000, "代理商不存在"); + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/agent/AuditStatusEnum.java b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/agent/AuditStatusEnum.java new file mode 100644 index 0000000..22c8dfb --- /dev/null +++ b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/agent/AuditStatusEnum.java @@ -0,0 +1,92 @@ +package cn.iocoder.hake.module.agent.enums.agent; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 代理商审核状态的枚举值 + * + * @author hake + */ +@Getter +/** + * 审核状态枚举类 + * 定义了系统中各种审核相关的状态 + */ +public enum AuditStatusEnum { + /** + * 禁用状态 + */ + DISABLED(0, "禁用"), + + /** + * 未认证状态 + */ + UNVERIFIED(1, "未认证"), + + /** + * 审核中状态 + */ + UNDER_REVIEW(2, "审核中"), + + /** + * 审核驳回状态 + */ + REJECTED(3, "审核驳回"), + + /** + * 启用状态 + */ + ENABLED(4, "启用"); + + /** + * 状态编码 + */ + private final Integer code; + + /** + * 状态描述 + */ + private final String description; + + /** + * 构造方法 + * @param code 状态编码 + * @param description 状态描述 + */ + AuditStatusEnum(Integer code, String description) { + this.code = code; + this.description = description; + } + + /** + * 获取状态编码 + * @return 状态编码 + */ + public Integer getCode() { + return code; + } + + /** + * 获取状态描述 + * @return 状态描述 + */ + public String getDescription() { + return description; + } + + /** + * 根据编码获取枚举实例 + * @param code 状态编码 + * @return 对应的枚举实例,如果没有匹配的则返回null + */ + public static AuditStatusEnum getByCode(Integer code) { + for (AuditStatusEnum status : values()) { + if (status.code == code) { + return status; + } + } + return null; + } +} + diff --git a/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/agent/JudgeFlagEnum.java b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/agent/JudgeFlagEnum.java new file mode 100644 index 0000000..01ce6d7 --- /dev/null +++ b/hake-module-agent/hake-module-agent-api/src/main/java/cn/iocoder/hake/module/agent/enums/agent/JudgeFlagEnum.java @@ -0,0 +1,67 @@ +package cn.iocoder.hake.module.agent.enums.agent; + +import lombok.Getter; + + +@Getter +/** + * 是否允许枚举值:0-否;1-是 + * + * @author hake + */ +public enum JudgeFlagEnum { +// 是否允许发展下级:0-否;1-是 + IS_FLAG(0, "是"), + NO_FLAG(1, "否"); + + /** + * 状态编码 + */ + private final Integer code; + + /** + * 状态描述 + */ + private final String description; + + /** + * 构造方法 + * @param code 状态编码 + * @param description 状态描述 + */ + JudgeFlagEnum(Integer code, String description) { + this.code = code; + this.description = description; + } + + /** + * 获取状态编码 + * @return 状态编码 + */ + public Integer getCode() { + return code; + } + + /** + * 获取状态描述 + * @return 状态描述 + */ + public String getDescription() { + return description; + } + + /** + * 根据编码获取枚举实例 + * @param code 状态编码 + * @return 对应的枚举实例,如果没有匹配的则返回null + */ + public static JudgeFlagEnum getByCode(Integer code) { + for (JudgeFlagEnum status : values()) { + if (status.code == code) { + return status; + } + } + return null; + } +} + diff --git a/hake-module-agent/hake-module-agent-server/Dockerfile b/hake-module-agent/hake-module-agent-server/Dockerfile new file mode 100644 index 0000000..b5cfe47 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/Dockerfile @@ -0,0 +1,19 @@ +## AdoptOpenJDK 停止发布 OpenJDK 二进制,而 Eclipse Temurin 是它的延伸,提供更好的稳定性 +## 感谢复旦核博士的建议!灰子哥,牛皮! +FROM eclipse-temurin:8-jre + +## 创建目录,并使用它作为工作目录 +RUN mkdir -p /hake-module-agent-server +WORKDIR /hake-module-agent-server +## 将后端项目的 Jar 文件,复制到镜像中 +COPY ./target/hake-module-agent-server.jar app.jar + +## 设置 TZ 时区 +## 设置 JAVA_OPTS 环境变量,可通过 docker run -e "JAVA_OPTS=" 进行覆盖 +ENV TZ=Asia/Shanghai JAVA_OPTS="-Xms512m -Xmx512m" + +## 暴露后端项目的 48088 端口 +EXPOSE 48090 + +## 启动后端项目 +CMD java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar app.jar diff --git a/hake-module-agent/hake-module-agent-server/pom.xml b/hake-module-agent/hake-module-agent-server/pom.xml new file mode 100644 index 0000000..ba56d44 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/pom.xml @@ -0,0 +1,135 @@ + + + + cn.iocoder.cloud + hake-module-agent + ${revision} + + 4.0.0 + hake-module-agent-server + + ${project.artifactId} + + agent 包下,代理商管理 + + + + + + cn.iocoder.cloud + hake-spring-boot-starter-env + + + + + cn.iocoder.cloud + hake-module-system-api + ${revision} + + + cn.iocoder.cloud + hake-module-agent-api + ${revision} + + + + + cn.iocoder.cloud + hake-spring-boot-starter-biz-tenant + + + + + cn.iocoder.cloud + hake-spring-boot-starter-security + + + + + cn.iocoder.cloud + hake-spring-boot-starter-mybatis + + + + cn.iocoder.cloud + hake-spring-boot-starter-redis + + + + + cn.iocoder.cloud + hake-spring-boot-starter-rpc + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-discovery + + + + + com.alibaba.cloud + spring-cloud-starter-alibaba-nacos-config + + + + + cn.iocoder.cloud + hake-spring-boot-starter-excel + + + + + cn.iocoder.cloud + hake-spring-boot-starter-monitor + + + + + cn.iocoder.cloud + hake-spring-boot-starter-test + + + + + + central + Central Repository + http://192.168.1.200:19081/repository/maven-hake/ + + + snapshots + Nexus Snapshot Repository + http://192.168.1.200:19081/repository/maven-snapshots/ + + + + + + ${project.artifactId} + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring.boot.version} + + agent +../../packge + + + + + + repackage + + + + + + + + \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/AgentServerApplication.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/AgentServerApplication.java new file mode 100644 index 0000000..9879c94 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/AgentServerApplication.java @@ -0,0 +1,19 @@ +package cn.iocoder.hake.module.agent; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * 项目的启动类 + * + * @author hake + */ +@SpringBootApplication +public class AgentServerApplication { + + public static void main(String[] args) { + + SpringApplication.run(AgentServerApplication.class, args); + } + +} diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/AgentController.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/AgentController.java new file mode 100644 index 0000000..573b114 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/AgentController.java @@ -0,0 +1,110 @@ +package cn.iocoder.hake.module.agent.controller.admin.agent; + +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.iocoder.hake.framework.common.pojo.PageParam; +import cn.iocoder.hake.framework.common.pojo.PageResult; +import cn.iocoder.hake.framework.common.pojo.CommonResult; +import cn.iocoder.hake.framework.common.util.object.BeanUtils; +import static cn.iocoder.hake.framework.common.pojo.CommonResult.success; + +import cn.iocoder.hake.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.hake.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.hake.framework.apilog.core.enums.OperateTypeEnum.*; + +import cn.iocoder.hake.module.agent.controller.admin.agent.vo.*; +import cn.iocoder.hake.module.agent.dal.dataobject.agent.AgentDO; +import cn.iocoder.hake.module.agent.service.agent.AgentService; + +@Tag(name = "管理后台 - 代理商管理") +@RestController +@RequestMapping("/agent/agent") +@Validated +public class AgentController { + + @Resource + private AgentService agentService; + + @PostMapping("/create") + @Operation(summary = "创建代理商管理") + @PreAuthorize("@ss.hasPermission('agent:info:create')") + public CommonResult createAgent(@Valid @RequestBody AgentSaveReqVO createReqVO) { + return success(agentService.createAgent(createReqVO)); + } + + @PostMapping("/updateStatus") + @Operation(summary = "代理商审核") + @PreAuthorize("@ss.hasPermission('agent:info:audit')") + public CommonResult updateAgentStatus(@Valid @RequestBody AuditRespVO auditRespVO) { + return success(agentService.updateAgentStatus(auditRespVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新代理商管理") + @PreAuthorize("@ss.hasPermission('agent:info:update')") + public CommonResult updateAgent(@Valid @RequestBody AgentSaveReqVO updateReqVO) { + agentService.updateAgent(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除代理商管理") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('agent:info:delete')") + public CommonResult deleteAgent(@RequestParam("id") Long id) { + agentService.deleteAgent(id); + return success(true); + } + + @DeleteMapping("/delete-list") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除代理商管理") + @PreAuthorize("@ss.hasPermission('agent:info:delete')") + public CommonResult deleteAgentList(@RequestParam("ids") List ids) { + agentService.deleteAgentListByIds(ids); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得代理商管理") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('agent:info:query')") + public CommonResult getAgent(@RequestParam("id") Long id) { + AgentDO agent = agentService.getAgent(id); + return success(BeanUtils.toBean(agent, AgentRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得代理商管理分页") + @PreAuthorize("@ss.hasPermission('agent:info:query')") + public CommonResult> getAgentPage(@Valid AgentPageReqVO pageReqVO) { + PageResult pageResult = agentService.getAgentPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, AgentRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出代理商管理 Excel") + @PreAuthorize("@ss.hasPermission('agent:info:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportAgentExcel(@Valid AgentPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = agentService.getAgentPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "代理商管理.xls", "数据", AgentRespVO.class, + BeanUtils.toBean(list, AgentRespVO.class)); + } + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentPageReqVO.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentPageReqVO.java new file mode 100644 index 0000000..d09a7a8 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentPageReqVO.java @@ -0,0 +1,104 @@ +package cn.iocoder.hake.module.agent.controller.admin.agent.vo; + +import lombok.*; + +import java.time.LocalDate; + +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.hake.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.hake.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 代理商管理分页 Request VO") +@Data +public class AgentPageReqVO extends PageParam { + + @Schema(description = "代理商登陆名", example = "哈客") + private String agentName; + + @Schema(description = "代理商编码(系统自动生成,格式如AGT+日期+序号,用于业务标识)") + private String agentCode; + + @Schema(description = "代理商全称(需与营业执照一致)", example = "哈客") + private String agentNickname; + + @Schema(description = "代理商简称(用于日常展示)", example = "李四") + private String agentShortNickname; + + @Schema(description = "审核状态(枚举:0-禁用;1-未认证;2-待审核;3-审核中;4-审核驳回;05-启用;)", example = "2") + private Integer status; + + @Schema(description = "是否允许发展下级代理:0-否;1-是") + private Integer childAgentFlag; + + @Schema(description = "是否允许发展下级商户:0-否;1-是") + private Integer childMchFlag; + + @Schema(description = "是否发送开通提醒:0-否;1-是") + private Integer informFlag; + + @Schema(description = "代理商类型(枚举:1-个人代理;2-企业代理)", example = "2") + private Integer agentType; + + @Schema(description = "代理商等级(枚举:1-一级;2-二级)") + private Integer agentLevel; + + @Schema(description = "上级代理商ID(自关联agent_id,用于多级代理体系,无上级则为空)", example = "29314") + private Long parentAgentId; + + @Schema(description = "主要联系人(日常对接人)") + private String contactPerson; + + @Schema(description = "联系电话(必填,用于系统通知和业务沟通)") + private String contactPhone; + + @Schema(description = "联系邮箱(用于合同发送、对账通知等)") + private String contactEmail; + + @Schema(description = "联系人或法人身份证人像面照片的URL路径") + private String cardFrontPhoto; + + @Schema(description = "联系人或法人身份证国徽面照片的URL路径;与上一字段关联,需同时上传") + private String cardReversePhoto; + + @Schema(description = "联系人或法人手持承诺函照片的URL路径") + private String commitmentPhoto; + + @Schema(description = "营业执照照片的URL路径") + private String businessLicensePhoto; + + @Schema(description = "开户许可证照片的URL路径") + private String bankAccountPermit; + + @Schema(description = "合作状态(枚举:0-待合作;1-合作中;2-暂停合作;3-终止合作)", example = "2") + private Integer cooperationStatus; + + @Schema(description = "收款账户类型(枚举:1 - 银行卡;2 - 支付宝;3 - 微信支付)", example = "1") + private Integer receiveAccountType; + + @Schema(description = "账户姓名(需与证件姓名一致,用于收款账户实名校验)", example = "赵六") + private String accountName; + + @Schema(description = "支付宝账号(当receive_account_type=2时必填,格式为手机号或邮箱)", example = "1677") + private String alipayAccount; + + @Schema(description = "开户银行名称(当receive_account_type=1时必填,如 中国工商银行)", example = "赵六") + private String bankName; + + @Schema(description = "收款账号(银行卡号或对公账户号,当receive_account_type=1时必填)", example = "13854") + private String bankAccount; + + @Schema(description = "开户行支行名称(当receive_account_type=1时必填,如 北京朝阳支行)") + private String bankBranch; + + @Schema(description = "签约日期(合同签订时间)") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDate[] signDate; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentRespVO.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentRespVO.java new file mode 100644 index 0000000..70f539b --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentRespVO.java @@ -0,0 +1,137 @@ +package cn.iocoder.hake.module.agent.controller.admin.agent.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 代理商管理 Response VO") +@Data +@ExcelIgnoreUnannotated +public class AgentRespVO { + + @Schema(description = "代理商唯一标识(自增ID,建议用雪花算法确保分布式系统唯一性)", requiredMode = Schema.RequiredMode.REQUIRED, example = "16582") + @ExcelProperty("代理商唯一标识(自增ID,建议用雪花算法确保分布式系统唯一性)") + private Long id; + + @Schema(description = "代理商登陆名", requiredMode = Schema.RequiredMode.REQUIRED, example = "哈客") + @ExcelProperty("代理商登陆名") + private String agentName; + + @Schema(description = "代理商编码(系统自动生成,格式如AGT+日期+序号,用于业务标识)", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("代理商编码(系统自动生成,格式如AGT+日期+序号,用于业务标识)") + private String agentCode; + + @Schema(description = "代理商全称(需与营业执照一致)", example = "哈客") + @ExcelProperty("代理商全称(需与营业执照一致)") + private String agentNickname; + + @Schema(description = "代理商简称(用于日常展示)", example = "李四") + @ExcelProperty("代理商简称(用于日常展示)") + private String agentShortNickname; + + @Schema(description = "审核状态(枚举:0-禁用;1-未认证;2-待审核;3-审核中;4-审核驳回;05-启用;)", example = "2") + @ExcelProperty("审核状态(枚举:0-禁用;1-未认证;2-待审核;3-审核中;4-审核驳回;05-启用;)") + private Integer status; + + @Schema(description = "是否允许发展下级代理:0-否;1-是") + @ExcelProperty("是否允许发展下级代理:0-否;1-是") + private Integer childAgentFlag; + + @Schema(description = "是否允许发展下级商户:0-否;1-是") + @ExcelProperty("是否允许发展下级商户:0-否;1-是") + private Integer childMchFlag; + + @Schema(description = "是否发送开通提醒:0-否;1-是") + @ExcelProperty("是否发送开通提醒:0-否;1-是") + private Integer informFlag; + + @Schema(description = "代理商类型(枚举:1-个人代理;2-企业代理)", example = "2") + @ExcelProperty("代理商类型(枚举:1-个人代理;2-企业代理)") + private Integer agentType; + + @Schema(description = "代理商等级(枚举:1-一级;2-二级)") + @ExcelProperty("代理商等级(枚举:1-一级;2-二级)") + private Integer agentLevel; + + @Schema(description = "上级代理商ID(自关联agent_id,用于多级代理体系,无上级则为空)", example = "29314") + @ExcelProperty("上级代理商ID(自关联agent_id,用于多级代理体系,无上级则为空)") + private Long parentAgentId; + + @Schema(description = "主要联系人(日常对接人)") + @ExcelProperty("主要联系人(日常对接人)") + private String contactPerson; + + @Schema(description = "联系电话(必填,用于系统通知和业务沟通)") + @ExcelProperty("联系电话(必填,用于系统通知和业务沟通)") + private String contactPhone; + + @Schema(description = "联系邮箱(用于合同发送、对账通知等)") + @ExcelProperty("联系邮箱(用于合同发送、对账通知等)") + private String contactEmail; + + @Schema(description = "联系人或法人身份证人像面照片的URL路径") + @ExcelProperty("联系人或法人身份证人像面照片的URL路径") + private String cardFrontPhoto; + + @Schema(description = "联系人或法人身份证国徽面照片的URL路径;与上一字段关联,需同时上传") + @ExcelProperty("联系人或法人身份证国徽面照片的URL路径;与上一字段关联,需同时上传") + private String cardReversePhoto; + + @Schema(description = "联系人或法人手持承诺函照片的URL路径") + @ExcelProperty("联系人或法人手持承诺函照片的URL路径") + private String commitmentPhoto; + + @Schema(description = "营业执照照片的URL路径") + @ExcelProperty("营业执照照片的URL路径") + private String businessLicensePhoto; + + @Schema(description = "开户许可证照片的URL路径") + @ExcelProperty("开户许可证照片的URL路径") + private String bankAccountPermit; + + @Schema(description = "合作状态(枚举:0-待合作;1-合作中;2-暂停合作;3-终止合作)", example = "2") + @ExcelProperty("合作状态(枚举:0-待合作;1-合作中;2-暂停合作;3-终止合作)") + private Integer cooperationStatus; + + @Schema(description = "收款账户类型(枚举:1 - 银行卡;2 - 支付宝;3 - 微信支付)", example = "1") + @ExcelProperty("收款账户类型(枚举:1 - 银行卡;2 - 支付宝;3 - 微信支付)") + private Integer receiveAccountType; + + @Schema(description = "账户姓名(需与证件姓名一致,用于收款账户实名校验)", example = "赵六") + @ExcelProperty("账户姓名(需与证件姓名一致,用于收款账户实名校验)") + private String accountName; + + @Schema(description = "支付宝账号(当receive_account_type=2时必填,格式为手机号或邮箱)", example = "1677") + @ExcelProperty("支付宝账号(当receive_account_type=2时必填,格式为手机号或邮箱)") + private String alipayAccount; + + @Schema(description = "开户银行名称(当receive_account_type=1时必填,如 中国工商银行)", example = "赵六") + @ExcelProperty("开户银行名称(当receive_account_type=1时必填,如 中国工商银行)") + private String bankName; + + @Schema(description = "收款账号(银行卡号或对公账户号,当receive_account_type=1时必填)", example = "13854") + @ExcelProperty("收款账号(银行卡号或对公账户号,当receive_account_type=1时必填)") + private String bankAccount; + + @Schema(description = "开户行支行名称(当receive_account_type=1时必填,如 北京朝阳支行)") + @ExcelProperty("开户行支行名称(当receive_account_type=1时必填,如 北京朝阳支行)") + private String bankBranch; + + @Schema(description = "签约日期(合同签订时间)") + @ExcelProperty("签约日期(合同签订时间)") + private LocalDate signDate; + + + @Schema(description = "这是审核备注信息") + @ExcelProperty("审核备注") + + private String auditRemark; + + @Schema(description = "创建时间") + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentSaveReqVO.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentSaveReqVO.java new file mode 100644 index 0000000..ee08b24 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AgentSaveReqVO.java @@ -0,0 +1,104 @@ +package cn.iocoder.hake.module.agent.controller.admin.agent.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; + +import java.time.LocalDate; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 代理商管理新增/修改 Request VO") +@Data +public class AgentSaveReqVO { + + @Schema(description = "代理商唯一标识(自增ID,建议用雪花算法确保分布式系统唯一性)", requiredMode = Schema.RequiredMode.REQUIRED, example = "16582") + private Long id; + + @Schema(description = "代理商登陆名", requiredMode = Schema.RequiredMode.REQUIRED, example = "哈客") + @NotEmpty(message = "代理商登陆名不能为空") + private String agentName; + + @Schema(description = "代理商编码(系统自动生成,格式如 AGT+日期+序号,用于业务标识)", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "代理商编码(系统自动生成,格式如AGT+日期+序号,用于业务标识)不能为空") + private String agentCode; + + @Schema(description = "代理商全称(需与营业执照一致)", example = "哈客") + private String agentNickname; + + @Schema(description = "代理商简称(用于日常展示)", example = "李四") + private String agentShortNickname; + + @Schema(description = "审核状态(枚举:0-禁用;1-未认证;2-待审核;3-审核中;4-审核驳回;05-启用;)", example = "2") + private Integer status; + + @Schema(description = "是否允许发展下级代理:0-否;1-是") + private Integer childAgentFlag; + + @Schema(description = "是否允许发展下级商户:0-否;1-是") + private Integer childMchFlag; + + @Schema(description = "是否发送开通提醒:0-否;1-是") + private Integer informFlag; + + @Schema(description = "代理商类型(枚举:1-个人代理;2-企业代理)", example = "2") + private Integer agentType; + + @Schema(description = "代理商等级(枚举:1-一级;2-二级)") + private Integer agentLevel; + + @Schema(description = "上级代理商ID(自关联agent_id,用于多级代理体系,无上级则为空)", example = "29314") + private Long parentAgentId; + + @Schema(description = "主要联系人(日常对接人)") + private String contactPerson; + + @Schema(description = "联系电话(必填,用于系统通知和业务沟通)") + private String contactPhone; + + @Schema(description = "联系邮箱(用于合同发送、对账通知等)") + private String contactEmail; + + @Schema(description = "联系人或法人身份证人像面照片的URL路径") + private String cardFrontPhoto; + + @Schema(description = "联系人或法人身份证国徽面照片的URL路径;与上一字段关联,需同时上传") + private String cardReversePhoto; + + @Schema(description = "联系人或法人手持承诺函照片的URL路径") + private String commitmentPhoto; + + @Schema(description = "营业执照照片的URL路径") + private String businessLicensePhoto; + + @Schema(description = "开户许可证照片的URL路径") + private String bankAccountPermit; + + @Schema(description = "合作状态(枚举:0-待合作;1-合作中;2-暂停合作;3-终止合作)", example = "2") + private Integer cooperationStatus; + + @Schema(description = "收款账户类型(枚举:1 - 银行卡;2 - 支付宝;3 - 微信支付)", example = "1") + private Integer receiveAccountType; + + @Schema(description = "账户姓名(需与证件姓名一致,用于收款账户实名校验)", example = "赵六") + private String accountName; + + @Schema(description = "支付宝账号(当receive_account_type=2时必填,格式为手机号或邮箱)", example = "1677") + private String alipayAccount; + + @Schema(description = "开户银行名称(当receive_account_type=1时必填,如 中国工商银行)", example = "赵六") + private String bankName; + + @Schema(description = "收款账号(银行卡号或对公账户号,当receive_account_type=1时必填)", example = "13854") + private String bankAccount; + + @Schema(description = "开户行支行名称(当receive_account_type=1时必填,如 北京朝阳支行)") + private String bankBranch; + + @Schema(description = "这是审核备注信息") + private String auditRemark; + + @Schema(description = "签约日期(合同签订时间)") + private LocalDate signDate; + + + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AuditRespVO.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AuditRespVO.java new file mode 100644 index 0000000..8dc3726 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/controller/admin/agent/vo/AuditRespVO.java @@ -0,0 +1,25 @@ +package cn.iocoder.hake.module.agent.controller.admin.agent.vo; + +import com.alibaba.excel.annotation.ExcelIgnoreUnannotated; +import com.alibaba.excel.annotation.ExcelProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +@Schema(description = "管理后台 - 代理商审核 Response VO") +@Data +public class AuditRespVO { + + @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "16582") + private Long id; + + + @Schema(description = "审核状态(枚举:0-禁用;1-未认证;2-待审核;3-审核中;4-审核驳回;05-启用;)", example = "2") + private Integer status; + + @Schema(description = "这是审核备注信息") + private String auditRemark; + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/dal/dataobject/agent/AgentDO.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/dal/dataobject/agent/AgentDO.java new file mode 100644 index 0000000..332cfae --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/dal/dataobject/agent/AgentDO.java @@ -0,0 +1,143 @@ +package cn.iocoder.hake.module.agent.dal.dataobject.agent; + +import lombok.*; + +import java.time.LocalDate; + +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.hake.framework.mybatis.core.dataobject.BaseDO; + +/** + * 代理商管理 DO + * + * @author hake + */ +@TableName("agent_info") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class AgentDO extends BaseDO { + + /** + * 代理商唯一标识(自增ID,建议用雪花算法确保分布式系统唯一性) + */ + @TableId + private Long id; + /** + * 代理商登陆名 + */ + private String agentName; + /** + * 代理商编码(系统自动生成,格式如"AGT+日期+序号",用于业务标识) + */ + private String agentCode; + /** + * 代理商全称(需与营业执照一致) + */ + private String agentNickname; + /** + * 代理商简称(用于日常展示) + */ + private String agentShortNickname; + /** + * 审核状态(枚举:0-禁用;1-未认证;2-待审核;3-审核中;4-审核驳回;05-启用;) + */ + private Integer status; + /** + * 是否允许发展下级代理:0-否;1-是 + */ + private Integer childAgentFlag; + /** + * 是否允许发展下级商户:0-否;1-是 + */ + private Integer childMchFlag; + /** + * 是否发送开通提醒:0-否;1-是 + */ + private Integer informFlag; + /** + * 代理商类型(枚举:1-个人代理;2-企业代理) + */ + private Integer agentType; + /** + * 代理商等级(枚举:1-一级;2-二级) + */ + private Integer agentLevel; + /** + * 上级代理商ID(自关联agent_id,用于多级代理体系,无上级则为空) + */ + private Long parentAgentId; + /** + * 主要联系人(日常对接人) + */ + private String contactPerson; + /** + * 联系电话(必填,用于系统通知和业务沟通) + */ + private String contactPhone; + /** + * 联系邮箱(用于合同发送、对账通知等) + */ + private String contactEmail; + /** + * 联系人或法人身份证人像面照片的URL路径 + */ + private String cardFrontPhoto; + /** + * 联系人或法人身份证国徽面照片的URL路径;与上一字段关联,需同时上传 + */ + private String cardReversePhoto; + /** + * 联系人或法人手持承诺函照片的URL路径 + */ + private String commitmentPhoto; + /** + * 营业执照照片的URL路径 + */ + private String businessLicensePhoto; + /** + * 开户许可证照片的URL路径 + */ + private String bankAccountPermit; + /** + * 合作状态(枚举:0-待合作;1-合作中;2-暂停合作;3-终止合作) + */ + private Integer cooperationStatus; + /** + * 收款账户类型(枚举:1 - 银行卡;2 - 支付宝;3 - 微信支付) + */ + private Integer receiveAccountType; + /** + * 账户姓名(需与证件姓名一致,用于收款账户实名校验) + */ + private String accountName; + /** + * 支付宝账号(当receive_account_type=2时必填,格式为手机号或邮箱) + */ + private String alipayAccount; + /** + * 开户银行名称(当receive_account_type=1时必填,如 "中国工商银行") + */ + private String bankName; + /** + * 收款账号(银行卡号或对公账户号,当receive_account_type=1时必填) + */ + private String bankAccount; + /** + * 开户行支行名称(当receive_account_type=1时必填,如 "北京朝阳支行") + */ + private String bankBranch; + /** + * 签约日期(合同签订时间) + */ + private LocalDate signDate; + + /** + * 这是审核备注信息 + */ + private String auditRemark; + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/dal/mysql/agent/AgentMapper.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/dal/mysql/agent/AgentMapper.java new file mode 100644 index 0000000..f1bab17 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/dal/mysql/agent/AgentMapper.java @@ -0,0 +1,51 @@ +package cn.iocoder.hake.module.agent.dal.mysql.agent; + +import cn.iocoder.hake.framework.common.pojo.PageResult; +import cn.iocoder.hake.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.hake.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.hake.module.agent.dal.dataobject.agent.AgentDO; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.hake.module.agent.controller.admin.agent.vo.*; + +/** + * 代理商管理 Mapper + * + * @author hake + */ +@Mapper +public interface AgentMapper extends BaseMapperX { + + default PageResult selectPage(AgentPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .likeIfPresent(AgentDO::getAgentName, reqVO.getAgentName()) + .eqIfPresent(AgentDO::getAgentCode, reqVO.getAgentCode()) + .likeIfPresent(AgentDO::getAgentNickname, reqVO.getAgentNickname()) + .likeIfPresent(AgentDO::getAgentShortNickname, reqVO.getAgentShortNickname()) + .eqIfPresent(AgentDO::getStatus, reqVO.getStatus()) + .eqIfPresent(AgentDO::getChildAgentFlag, reqVO.getChildAgentFlag()) + .eqIfPresent(AgentDO::getChildMchFlag, reqVO.getChildMchFlag()) + .eqIfPresent(AgentDO::getInformFlag, reqVO.getInformFlag()) + .eqIfPresent(AgentDO::getAgentType, reqVO.getAgentType()) + .eqIfPresent(AgentDO::getAgentLevel, reqVO.getAgentLevel()) + .eqIfPresent(AgentDO::getParentAgentId, reqVO.getParentAgentId()) + .eqIfPresent(AgentDO::getContactPerson, reqVO.getContactPerson()) + .eqIfPresent(AgentDO::getContactPhone, reqVO.getContactPhone()) + .eqIfPresent(AgentDO::getContactEmail, reqVO.getContactEmail()) + .eqIfPresent(AgentDO::getCardFrontPhoto, reqVO.getCardFrontPhoto()) + .eqIfPresent(AgentDO::getCardReversePhoto, reqVO.getCardReversePhoto()) + .eqIfPresent(AgentDO::getCommitmentPhoto, reqVO.getCommitmentPhoto()) + .eqIfPresent(AgentDO::getBusinessLicensePhoto, reqVO.getBusinessLicensePhoto()) + .eqIfPresent(AgentDO::getBankAccountPermit, reqVO.getBankAccountPermit()) + .eqIfPresent(AgentDO::getCooperationStatus, reqVO.getCooperationStatus()) + .eqIfPresent(AgentDO::getReceiveAccountType, reqVO.getReceiveAccountType()) + .likeIfPresent(AgentDO::getAccountName, reqVO.getAccountName()) + .eqIfPresent(AgentDO::getAlipayAccount, reqVO.getAlipayAccount()) + .likeIfPresent(AgentDO::getBankName, reqVO.getBankName()) + .eqIfPresent(AgentDO::getBankAccount, reqVO.getBankAccount()) + .eqIfPresent(AgentDO::getBankBranch, reqVO.getBankBranch()) + .betweenIfPresent(AgentDO::getSignDate, reqVO.getSignDate()) + .betweenIfPresent(AgentDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(AgentDO::getId)); + } + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/package-info.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/package-info.java new file mode 100644 index 0000000..10f099c --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/package-info.java @@ -0,0 +1,6 @@ +/** + * 属于 erp 模块的 framework 封装 + * + * @author hake + */ +package cn.iocoder.hake.module.agent.framework; diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/rpc/config/RpcConfiguration.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/rpc/config/RpcConfiguration.java new file mode 100644 index 0000000..3abf87d --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/rpc/config/RpcConfiguration.java @@ -0,0 +1,10 @@ +package cn.iocoder.hake.module.agent.framework.rpc.config; + +import cn.iocoder.hake.module.system.api.user.AdminUserApi; +import org.springframework.cloud.openfeign.EnableFeignClients; +import org.springframework.context.annotation.Configuration; + +@Configuration(value = "agentRpcConfiguration", proxyBeanMethods = false) +@EnableFeignClients(clients = AdminUserApi.class) +public class RpcConfiguration { +} diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/rpc/package-info.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/rpc/package-info.java new file mode 100644 index 0000000..9c6b738 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/rpc/package-info.java @@ -0,0 +1,4 @@ +/** + * 占位 + */ +package cn.iocoder.hake.module.agent.framework.rpc; diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/security/config/SecurityConfiguration.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/security/config/SecurityConfiguration.java new file mode 100644 index 0000000..cabaa4f --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/security/config/SecurityConfiguration.java @@ -0,0 +1,39 @@ +package cn.iocoder.hake.module.agent.framework.security.config; + +import cn.iocoder.hake.framework.security.config.AuthorizeRequestsCustomizer; +import cn.iocoder.hake.module.agent.enums.ApiConstants; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configurers.AuthorizeHttpRequestsConfigurer; + +/** + * Erp 模块的 Security 配置 + */ +@Configuration("agentSecurityConfiguration") +public class SecurityConfiguration { + + @Bean("agentAuthorizeRequestsCustomizer") + public AuthorizeRequestsCustomizer authorizeRequestsCustomizer() { + return new AuthorizeRequestsCustomizer() { + + @Override + public void customize(AuthorizeHttpRequestsConfigurer.AuthorizationManagerRequestMatcherRegistry registry) { + // Swagger 接口文档 + registry.requestMatchers("/v3/api-docs/**").permitAll() + .requestMatchers("/webjars/**").permitAll() + .requestMatchers("/swagger-ui").permitAll() + .requestMatchers("/swagger-ui/**").permitAll(); + // Spring Boot Actuator 的安全配置 + registry.requestMatchers("/actuator").permitAll() + .requestMatchers("/actuator/**").permitAll(); + // Druid 监控 + registry.requestMatchers("/druid/**").permitAll(); + // RPC 服务的安全配置 + registry.requestMatchers(ApiConstants.PREFIX + "/**").permitAll(); + } + + }; + } + +} diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/security/core/package-info.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/security/core/package-info.java new file mode 100644 index 0000000..f663785 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/framework/security/core/package-info.java @@ -0,0 +1,4 @@ +/** + * 占位 + */ +package cn.iocoder.hake.module.agent.framework.security.core; diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/package-info.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/package-info.java new file mode 100644 index 0000000..eef5b1e --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/package-info.java @@ -0,0 +1,10 @@ +/** + * erp 包下,企业资源管理(Enterprise Resource Planning)。 + * 例如说:采购、销售、库存、财务、产品等等 + * + * 1. Controller URL:以 /erp/ 开头,避免和其它 Module 冲突 + * 2. DataObject 表名:以 erp_ 开头,方便在数据库中区分 + * + * 注意,由于 Erp 模块下,容易和其它模块重名,所以类名都加载 Erp 的前缀~ + */ +package cn.iocoder.hake.module.agent; diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/service/agent/AgentService.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/service/agent/AgentService.java new file mode 100644 index 0000000..21cf0e6 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/service/agent/AgentService.java @@ -0,0 +1,67 @@ +package cn.iocoder.hake.module.agent.service.agent; + +import java.util.*; +import javax.validation.*; +import cn.iocoder.hake.module.agent.controller.admin.agent.vo.*; +import cn.iocoder.hake.module.agent.dal.dataobject.agent.AgentDO; +import cn.iocoder.hake.framework.common.pojo.PageResult; + +/** + * 代理商管理 Service 接口 + * + * @author hake + */ +public interface AgentService { + + /** + * 创建代理商管理 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createAgent(@Valid AgentSaveReqVO createReqVO); + + /** + * 代理商审核 + * @return + */ + Long updateAgentStatus(@Valid AuditRespVO auditRespVO); + + /** + * 更新代理商管理 + * + * @param updateReqVO 更新信息 + */ + void updateAgent(@Valid AgentSaveReqVO updateReqVO); + + /** + * 删除代理商管理 + * + * @param id 编号 + */ + void deleteAgent(Long id); + + /** + * 批量删除代理商管理 + * + * @param ids 编号 + */ + void deleteAgentListByIds(List ids); + + /** + * 获得代理商管理 + * + * @param id 编号 + * @return 代理商管理 + */ + AgentDO getAgent(Long id); + + /** + * 获得代理商管理分页 + * + * @param pageReqVO 分页查询 + * @return 代理商管理分页 + */ + PageResult getAgentPage(AgentPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/service/agent/AgentServiceImpl.java b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/service/agent/AgentServiceImpl.java new file mode 100644 index 0000000..07fa72b --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/java/cn/iocoder/hake/module/agent/service/agent/AgentServiceImpl.java @@ -0,0 +1,134 @@ +package cn.iocoder.hake.module.agent.service.agent; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.hake.module.agent.enums.agent.AuditStatusEnum; +import org.springframework.stereotype.Service; +import javax.annotation.Resource; +import org.springframework.validation.annotation.Validated; + +import java.text.SimpleDateFormat; +import java.util.*; +import cn.iocoder.hake.module.agent.controller.admin.agent.vo.*; +import cn.iocoder.hake.module.agent.dal.dataobject.agent.AgentDO; +import cn.iocoder.hake.framework.common.pojo.PageResult; + +import cn.iocoder.hake.framework.common.util.object.BeanUtils; + +import cn.iocoder.hake.module.agent.dal.mysql.agent.AgentMapper; + +import static cn.iocoder.hake.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.hake.module.agent.enums.ErrorCodeConstants.*; + +/** + * 代理商管理 Service 实现类 + * + * @author hake + */ +@Service +@Validated +public class AgentServiceImpl implements AgentService { + + @Resource + private AgentMapper agentMapper; + + @Override + public Long createAgent(AgentSaveReqVO createReqVO) { + // 插入 + AgentDO agent = BeanUtils.toBean(createReqVO, AgentDO.class); + agent.setStatus(AuditStatusEnum.UNVERIFIED.getCode()); + agent.setAgentCode(erateAgentCode(new StringBuilder("AGT"))); + agentMapper.insert(agent); + // 返回 + return agent.getId(); + } + + /** + * 生成代理商编码 + * @return 格式如"AGT202507301234"的代理商编码 + */ + public static String erateAgentCode(StringBuilder codeHeadStr) { + if(codeHeadStr == null || codeHeadStr.length() == 0) { + codeHeadStr=new StringBuilder("ST"); + } + // 固定前缀 + StringBuilder codeBuilder = new StringBuilder(codeHeadStr); + // 添加当前日期(yyyyMMdd格式) + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd"); + String dateStr = dateFormat.format(new Date()); + codeBuilder.append(dateStr); + + // 生成4个随机数(0000-9999) + Random random = new Random(); + // 生成0-9999的随机数,并补全为4位数字 + int randomNum = random.nextInt(10000); + codeBuilder.append(String.format("%04d", randomNum)); + return codeBuilder.toString(); + } + + @Override + public Long updateAgentStatus( AuditRespVO auditRespVO) { + // 校验存在 + validateagentExists(auditRespVO.getId()); + // 更新 + AgentDO updateObj = BeanUtils.toBean(auditRespVO, AgentDO.class); + agentMapper.updateById(updateObj); + return auditRespVO.getId(); + } + + + @Override + public void updateAgent(AgentSaveReqVO updateReqVO) { + // 校验存在 + AgentDO agentDO =validateagentExists(updateReqVO.getId()); + //如果当前为未认证、审核驳回的状态,再次修改提交后应该变成待审核状态 + if(Objects.equals(agentDO.getStatus(), AuditStatusEnum.REJECTED.getCode()) || Objects.equals(agentDO.getStatus(), AuditStatusEnum.UNVERIFIED.getCode())) { + updateReqVO.setStatus(AuditStatusEnum.UNDER_REVIEW.getCode()); + } + // 更新 + AgentDO updateObj = BeanUtils.toBean(updateReqVO, AgentDO.class); + agentMapper.updateById(updateObj); + } + + + @Override + public void deleteAgent(Long id) { + // 校验存在 + validateagentExists(id); + // 删除 + agentMapper.deleteById(id); + } + + @Override + public void deleteAgentListByIds(List ids) { + // 校验存在 + validateAgentExists(ids); + // 删除 + agentMapper.deleteByIds(ids); + } + + private void validateAgentExists(List ids) { + List list = agentMapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(AGENT_NOT_EXISTS); + } + } + + private AgentDO validateagentExists(Long id) { + AgentDO agentDO =agentMapper.selectById(id); + if (agentDO == null) { + throw exception(AGENT_NOT_EXISTS); + } + return agentDO; + } + + @Override + public AgentDO getAgent(Long id) { + return agentMapper.selectById(id); + } + + @Override + public PageResult getAgentPage(AgentPageReqVO pageReqVO) { + return agentMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/resources/application-dev.yaml b/hake-module-agent/hake-module-agent-server/src/main/resources/application-dev.yaml new file mode 100644 index 0000000..0fd2849 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/resources/application-dev.yaml @@ -0,0 +1,110 @@ +--- #################### 注册中心 + 配置中心相关配置 #################### + +spring: + cloud: + nacos: + server-addr: 192.168.1.16:8848 # Nacos 服务器地址 + username: nacos# Nacos 账号 + password: nacos# Nacos 密码 + discovery: # 【配置中心】配置项 + namespace: dev # 命名空间。这里使用 dev 开发环境 + group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP + metadata: + version: 1.0.0 # 服务实例的版本号,可用于灰度发布 + config: # 【注册中心】配置项 + namespace: dev # 命名空间。这里使用 dev 开发环境 + group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP + +--- #################### 数据库相关配置 #################### +spring: + # 数据源配置项 + autoconfigure: + exclude: + datasource: + druid: # Druid 【监控】相关的全局配置 + web-stat-filter: + enabled: true + stat-view-servlet: + enabled: true + allow: # 设置白名单,不填则允许所有访问 + url-pattern: /druid/* + login-username: # 控制台管理用户名和密码 + login-password: + filter: + stat: + enabled: true + log-slow-sql: true # 慢 SQL 记录 + slow-sql-millis: 100 + merge-sql: true + wall: + config: + multi-statement-allow: true + dynamic: # 多数据源配置 + druid: # Druid 【连接池】相关的全局配置 + initial-size: 5 # 初始连接数 + min-idle: 10 # 最小连接池数量 + max-active: 20 # 最大连接池数量 + max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒 + time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位:毫秒 + min-evictable-idle-time-millis: 300000 # 配置一个连接在池中最小生存的时间,单位:毫秒 + max-evictable-idle-time-millis: 900000 # 配置一个连接在池中最大生存的时间,单位:毫秒 + validation-query: SELECT 1 FROM DUAL # 配置检测连接是否有效 + test-while-idle: true + test-on-borrow: false + test-on-return: false + primary: master + datasource: + master: + url: jdbc:mysql://192.168.1.16:3306/hake?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例 + username: haketest + password: test1234 + slave: # 模拟从库,可根据自己需要修改 # 模拟从库,可根据自己需要修改 + lazy: true # 开启懒加载,保证启动速度 + url: jdbc:mysql://192.168.1.16:3306/hake?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例 + username: haketest + password: test1234 + + # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 + redis: + host: 192.168.1.16 # 地址 + port: 6379 # 端口 + database: 0 # 数据库索引 + # password: 123456 # 密码,建议生产环境开启 + +--- #################### MQ 消息队列相关配置 #################### + +--- #################### 定时任务相关配置 #################### + +--- #################### 服务保障相关配置 #################### + +# Lock4j 配置项 +lock4j: + acquire-timeout: 3000 # 获取分布式锁超时时间,默认为 3000 毫秒 + expire: 30000 # 分布式锁的超时时间,默认为 30 毫秒 + +--- #################### 监控相关配置 #################### + +# Actuator 监控端点的配置项 +management: + endpoints: + web: + base-path: /actuator # Actuator 提供的 API 接口的根目录。默认为 /actuator + exposure: + include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。 + +# Spring Boot Admin 配置项 +spring: + boot: + admin: + # Spring Boot Admin Client 客户端的相关配置 + client: + instance: + service-host-type: IP # 注册实例时,优先使用 IP [IP, HOST_NAME, CANONICAL_HOST_NAME] + +--- #################### 哈客相关配置 #################### + +# 哈客配置项,设置当前项目所有自定义的配置 +hake: + access-log: # 访问日志的配置项 + enable: false + demo: false # 关闭演示模式 diff --git a/hake-module-agent/hake-module-agent-server/src/main/resources/application-local.yaml b/hake-module-agent/hake-module-agent-server/src/main/resources/application-local.yaml new file mode 100644 index 0000000..e9e29b0 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/resources/application-local.yaml @@ -0,0 +1,135 @@ +--- #################### 注册中心 + 配置中心相关配置 #################### + +spring: + cloud: + nacos: + server-addr: 127.0.0.1:8848 # Nacos 服务器地址 + username: nacos# Nacos 账号 + password: nacos# Nacos 密码 + discovery: # 【配置中心】配置项 + namespace: dev # 命名空间。这里使用 dev 开发环境 + group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP + metadata: + version: 1.0.0 # 服务实例的版本号,可用于灰度发布 + config: # 【注册中心】配置项 + namespace: dev # 命名空间。这里使用 dev 开发环境 + group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP + +--- #################### 数据库相关配置 #################### +spring: + # 数据源配置项 + autoconfigure: + exclude: + - de.codecentric.boot.admin.client.config.SpringBootAdminClientAutoConfiguration # 禁用 Spring Boot Admin 的 Client 的自动配置 + datasource: + druid: # Druid 【监控】相关的全局配置 + web-stat-filter: + enabled: true + stat-view-servlet: + enabled: true + allow: # 设置白名单,不填则允许所有访问 + url-pattern: /druid/* + login-username: # 控制台管理用户名和密码 + login-password: + filter: + stat: + enabled: true + log-slow-sql: true # 慢 SQL 记录 + slow-sql-millis: 100 + merge-sql: true + wall: + config: + multi-statement-allow: true + dynamic: # 多数据源配置 + druid: # Druid 【连接池】相关的全局配置 + initial-size: 1 # 初始连接数 + min-idle: 1 # 最小连接池数量 + max-active: 20 # 最大连接池数量 + max-wait: 600000 # 配置获取连接等待超时的时间,单位:毫秒 + time-between-eviction-runs-millis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位:毫秒 + min-evictable-idle-time-millis: 300000 # 配置一个连接在池中最小生存的时间,单位:毫秒 + max-evictable-idle-time-millis: 900000 # 配置一个连接在池中最大生存的时间,单位:毫秒 + validation-query: SELECT 1 FROM DUAL # 配置检测连接是否有效 + test-while-idle: true + test-on-borrow: false + test-on-return: false + primary: master + datasource: + master: + url: jdbc:mysql://127.0.0.1:3306/hake?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true # MySQL Connector/J 8.X 连接的示例 + # url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true # MySQL Connector/J 5.X 连接的示例 + # url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例 + # url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例 + # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ruoyi-vue-pro # SQLServer 连接的示例 + # url: jdbc:dm://10.211.55.4:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 + username: haketest + password: test1234 + # username: sa # SQL Server 连接的示例 + # password: JSm:g(*%lU4ZAkz06cd52KqT3)i1?H7W # SQL Server 连接的示例 + # username: SYSDBA # DM 连接的示例 + # password: SYSDBA # DM 连接的示例 + slave: # 模拟从库,可根据自己需要修改 + lazy: true # 开启懒加载,保证启动速度 + url: jdbc:mysql://127.0.0.1:3306/hake?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true&rewriteBatchedStatements=true + username: root + password: 123456 + + # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 + redis: + host: 127.0.0.1 # 地址 + port: 6379 # 端口 + database: 0 # 数据库索引 +# password: 123456 # 密码,建议生产环境开启 + +--- #################### MQ 消息队列相关配置 #################### + +--- #################### 定时任务相关配置 #################### +xxl: + job: + enabled: false # 是否开启调度中心,默认为 true 开启 + admin: + addresses: http://127.0.0.1:9090/xxl-job-admin # 调度中心部署跟地址 + +--- #################### 服务保障相关配置 #################### + +# Lock4j 配置项 +lock4j: + acquire-timeout: 3000 # 获取分布式锁超时时间,默认为 3000 毫秒 + expire: 30000 # 分布式锁的超时时间,默认为 30 毫秒 + +--- #################### 监控相关配置 #################### + +# Actuator 监控端点的配置项 +management: + endpoints: + web: + base-path: /actuator # Actuator 提供的 API 接口的根目录。默认为 /actuator + exposure: + include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。 + +# Spring Boot Admin 配置项 +spring: + boot: + admin: + # Spring Boot Admin Client 客户端的相关配置 + client: + instance: + service-host-type: IP # 注册实例时,优先使用 IP [IP, HOST_NAME, CANONICAL_HOST_NAME] + +# 日志文件配置 +logging: + level: + # 配置自己写的 MyBatis Mapper 打印日志 + cn.iocoder.hake.module.agent.dal.mysql: debug + org.springframework.context.support.PostProcessorRegistrationDelegate: ERROR # TODO 哈客:先禁用,Spring Boot 3.X 存在部分错误的 WARN 提示 + +--- #################### 哈客相关配置 #################### + +# 哈客配置项,设置当前项目所有自定义的配置 +hake: + env: # 多环境的配置项 + tag: ${HOSTNAME} + security: + mock-enable: true + access-log: # 访问日志的配置项 + enable: false \ No newline at end of file diff --git a/hake-module-agent/hake-module-agent-server/src/main/resources/application.yaml b/hake-module-agent/hake-module-agent-server/src/main/resources/application.yaml new file mode 100644 index 0000000..f8c0d65 --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/resources/application.yaml @@ -0,0 +1,124 @@ +spring: + application: + name: agent-server + + profiles: + active: dev + + main: + allow-circular-references: true # 允许循环依赖,因为项目是三层架构,无法避免这个情况。 + allow-bean-definition-overriding: true # 允许 Bean 覆盖,例如说 Feign 等会存在重复定义的服务 + + config: + import: + - optional:classpath:application-${spring.profiles.active}.yaml # 加载【本地】配置 + - optional:nacos:${spring.application.name}-${spring.profiles.active}.yaml # 加载【Nacos】的配置 + + # Servlet 配置 + servlet: + # 文件上传相关配置项 + multipart: + max-file-size: 16MB # 单个文件大小 + max-request-size: 32MB # 设置总上传的文件大小 + + # Jackson 配置项 + jackson: + serialization: + write-dates-as-timestamps: true # 设置 LocalDateTime 的格式,使用时间戳 + write-date-timestamps-as-nanoseconds: false # 设置不使用 nanoseconds 的格式。例如说 1611460870.401,而是直接 1611460870401 + write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳 + fail-on-empty-beans: false # 允许序列化无属性的 Bean + + # Cache 配置项 + cache: + type: REDIS + redis: + time-to-live: 1h # 设置过期时间为 1 小时 + +server: + port: 48090 + +logging: + file: + name: ${user.home}/logs/${spring.application.name}.log # 日志文件名,全路径 + +--- #################### 接口文档配置 #################### + +springdoc: + api-docs: + enabled: true # 1. 是否开启 Swagger 接文档的元数据 + path: /v3/api-docs + swagger-ui: + enabled: true # 2.1 是否开启 Swagger 文档的官方 UI 界面 + path: /swagger-ui + default-flat-param-object: true # 参见 https://doc.xiaominfo.com/docs/faq/v4/knife4j-parameterobject-flat-param 文档 + +knife4j: + enable: false # TODO 哈客:需要关闭增强,具体原因见:https://github.com/xiaoymin/knife4j/issues/874 + setting: + language: zh_cn + +# MyBatis Plus 的配置项 +mybatis-plus: + configuration: + map-underscore-to-camel-case: true # 虽然默认为 true ,但是还是显示去指定下。 + global-config: + db-config: + id-type: NONE # “智能”模式,基于 IdTypeEnvironmentPostProcessor + 数据源的类型,自动适配成 AUTO、INPUT 模式。 + # id-type: AUTO # 自增 ID,适合 MySQL 等直接自增的数据库 + # id-type: INPUT # 用户输入 ID,适合 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库 + # id-type: ASSIGN_ID # 分配 ID,默认使用雪花算法。注意,Oracle、PostgreSQL、Kingbase、DB2、H2 数据库时,需要去除实体类上的 @KeySequence 注解 + logic-delete-value: 1 # 逻辑已删除值(默认为 1) + logic-not-delete-value: 0 # 逻辑未删除值(默认为 0) + banner: false # 关闭控制台的 Banner 打印 + type-aliases-package: ${hake.info.base-package}.dal.dataobject + encryptor: + password: XDV71a+xqStEA3WH # 加解密的秘钥,可使用 https://www.imaegoo.com/2020/aes-key-generator/ 网站生成 + +mybatis-plus-join: + banner: false # 关闭控制台的 Banner 打印 + +# Spring Data Redis 配置 +spring: + data: + redis: + repositories: + enabled: false # 项目未使用到 Spring Data Redis 的 Repository,所以直接禁用,保证启动速度 + +# VO 转换(数据翻译)相关 +easy-trans: + is-enable-global: true # 启用全局翻译(拦截所有 SpringMVC ResponseBody 进行自动翻译 )。如果对于性能要求很高可关闭此配置,或通过 @IgnoreTrans 忽略某个接口 + +--- #################### MQ 消息队列相关配置 #################### + +--- #################### 定时任务相关配置 #################### + +xxl: + job: + executor: + appname: ${spring.application.name} # 执行器 AppName + logpath: ${user.home}/logs/xxl-job/${spring.application.name} # 执行器运行日志文件存储磁盘路径 + accessToken: default_token # 执行器通讯TOKEN + +--- #################### 哈客相关配置 #################### + +hake: + info: + version: 1.0.0 + base-package: cn.iocoder.hake.module.agent + web: + admin-ui: + url: http://dashboard.hake.iocoder.cn # Admin 管理后台 UI 的地址 + xss: + enable: false + exclude-urls: # 如下 url,仅仅是为了演示,去掉配置也没关系 + - ${management.endpoints.web.base-path}/** # 不处理 Actuator 的请求 + swagger: + title: 管理后台 + description: 提供管理员管理的所有功能 + version: ${hake.info.version} + tenant: # 多租户相关配置项 + enable: true + ignore-urls: + +debug: false diff --git a/hake-module-agent/hake-module-agent-server/src/main/resources/logback-spring.xml b/hake-module-agent/hake-module-agent-server/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..e4cf06d --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/resources/logback-spring.xml @@ -0,0 +1,76 @@ + + + + + + + + + +       + + + ${PATTERN_DEFAULT} + + + + + + + + + + ${PATTERN_DEFAULT} + + + + ${LOG_FILE} + + + ${LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN:-${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz} + + ${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false} + + ${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-10MB} + + ${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-0} + + ${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-30} + + + + + + 0 + + 256 + + + + + + + + ${PATTERN_DEFAULT} + + + + + + + + + + + + + + + + + + + + + + diff --git a/hake-module-agent/hake-module-agent-server/src/main/resources/mapper/agent/AgentMapper.xml b/hake-module-agent/hake-module-agent-server/src/main/resources/mapper/agent/AgentMapper.xml new file mode 100644 index 0000000..dfcfc3c --- /dev/null +++ b/hake-module-agent/hake-module-agent-server/src/main/resources/mapper/agent/AgentMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/hake-module-agent/pom.xml b/hake-module-agent/pom.xml new file mode 100644 index 0000000..7722a8b --- /dev/null +++ b/hake-module-agent/pom.xml @@ -0,0 +1,23 @@ + + + + cn.iocoder.cloud + hake + ${revision} + + + hake-module-agent-api + hake-module-agent-server + + 4.0.0 + hake-module-agent + pom + + ${project.artifactId} + + erp 包下,代理商管理 + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index e4a0bf7..96b9cd1 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ hake-module-erp hake-module-crm hake-module-op + hake-module-agent ${project.artifactId} From ac3978a40478bdac16974265038d1429ef7997aa Mon Sep 17 00:00:00 2001 From: duanyuqing <1697807853@qq.com> Date: Thu, 31 Jul 2025 11:54:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Date:2025-07-31=20author:Duanyuqing=20comme?= =?UTF-8?q?nt:=E6=96=B0=E5=A2=9E=E5=95=86=E6=88=B7=E6=B1=87=E4=BB=98?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E4=BF=A1=E6=81=AF=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/pay/enums/ErrorCodeConstants.java | 5 + .../ServiceRegistController.java | 110 ++++ .../vo/ServiceRegistPageReqVO.java | 47 ++ .../serviceregist/vo/ServiceRegistRespVO.java | 59 ++ .../vo/ServiceRegistSaveReqVO.java | 50 ++ .../serviceregist/ServiceRegistDO.java | 65 ++ .../serviceregist/ServiceRegistMapper.java | 41 ++ .../pay/config/HuifuClientConfig.java | 69 ++ .../client/impl/huifu/HuifuPayClient.java | 597 ++++++++++++++++++ .../serviceregist/ServiceRegistService.java | 72 +++ .../ServiceRegistServiceImpl.java | 113 ++++ sql/mysql/pay.sql | 52 +- 12 files changed, 1266 insertions(+), 14 deletions(-) create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/ServiceRegistController.java create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistPageReqVO.java create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistRespVO.java create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistSaveReqVO.java create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/dal/dataobject/serviceregist/ServiceRegistDO.java create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/dal/mysql/serviceregist/ServiceRegistMapper.java create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/config/HuifuClientConfig.java create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/core/client/impl/huifu/HuifuPayClient.java create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/service/serviceregist/ServiceRegistService.java create mode 100644 hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/service/serviceregist/ServiceRegistServiceImpl.java diff --git a/hake-module-pay/hake-module-pay-api/src/main/java/cn/iocoder/hake/module/pay/enums/ErrorCodeConstants.java b/hake-module-pay/hake-module-pay-api/src/main/java/cn/iocoder/hake/module/pay/enums/ErrorCodeConstants.java index 7f11682..eb0cfc7 100644 --- a/hake-module-pay/hake-module-pay-api/src/main/java/cn/iocoder/hake/module/pay/enums/ErrorCodeConstants.java +++ b/hake-module-pay/hake-module-pay-api/src/main/java/cn/iocoder/hake/module/pay/enums/ErrorCodeConstants.java @@ -94,4 +94,9 @@ public interface ErrorCodeConstants { ErrorCode DEMO_WITHDRAW_UPDATE_STATUS_FAIL_PAY_CHANNEL_NOT_MATCH = new ErrorCode(1_007_901_005, "更新示例提现单状态失败,支付转账单渠道不匹配"); ErrorCode DEMO_WITHDRAW_TRANSFER_FAIL_STATUS_NOT_WAITING_OR_CLOSED = new ErrorCode(1_007_901_008, "发起转账失败,原因:示例提现单状态不是【等待提现】或【提现关闭】"); + // ========== 商户服务注册 1-007-010-000 ========== + ErrorCode SERVICE_REGIST_NOT_EXISTS = new ErrorCode(1-007-010-000, "商户服务注册不存在"); + ErrorCode SERVICE_REGIST_EXISTS = new ErrorCode(1-007-010-001, "商户服务注册已存在"); + ErrorCode SERVICE_REGIST_PARAM_ERROR = new ErrorCode(1-007-010-002, "商户服务注册参数错误: "); + } diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/ServiceRegistController.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/ServiceRegistController.java new file mode 100644 index 0000000..75e6f92 --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/ServiceRegistController.java @@ -0,0 +1,110 @@ +package cn.iocoder.hake.module.pay.controller.admin.serviceregist; + +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.iocoder.hake.framework.common.pojo.PageParam; +import cn.iocoder.hake.framework.common.pojo.PageResult; +import cn.iocoder.hake.framework.common.pojo.CommonResult; +import cn.iocoder.hake.framework.common.util.object.BeanUtils; + +import static cn.iocoder.hake.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.hake.framework.common.pojo.CommonResult.success; + +import cn.iocoder.hake.framework.excel.core.util.ExcelUtils; + +import cn.iocoder.hake.framework.apilog.core.annotation.ApiAccessLog; +import static cn.iocoder.hake.framework.apilog.core.enums.OperateTypeEnum.*; +import static cn.iocoder.hake.module.pay.enums.ErrorCodeConstants.SERVICE_REGIST_EXISTS; + +import cn.iocoder.hake.module.pay.controller.admin.serviceregist.vo.*; +import cn.iocoder.hake.module.pay.dal.dataobject.serviceregist.ServiceRegistDO; +import cn.iocoder.hake.module.pay.service.serviceregist.ServiceRegistService; + +@Tag(name = "管理后台 - 商户服务注册") +@RestController +@RequestMapping("/mch/service-regist") +@Validated +public class ServiceRegistController { + + @Resource + private ServiceRegistService serviceRegistService; + + @PostMapping("/create") + @Operation(summary = "创建商户服务注册") + @PreAuthorize("@ss.hasPermission('mch:service-regist:create')") + public CommonResult createServiceRegist(@Valid @RequestBody ServiceRegistSaveReqVO createReqVO) { + ServiceRegistDO serviceRegistDO = serviceRegistService.getServiceRegist(createReqVO.getAppId(),createReqVO.getChannelId(),createReqVO.getMchNo()); + if (serviceRegistDO == null) { + throw exception(SERVICE_REGIST_EXISTS); + } + return success(serviceRegistService.createServiceRegist(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新商户服务注册") + @PreAuthorize("@ss.hasPermission('mch:service-regist:update')") + public CommonResult updateServiceRegist(@Valid @RequestBody ServiceRegistSaveReqVO updateReqVO) { + serviceRegistService.updateServiceRegist(updateReqVO); + return success(true); + } + + @DeleteMapping("/delete") + @Operation(summary = "删除商户服务注册") + @Parameter(name = "id", description = "编号", required = true) + @PreAuthorize("@ss.hasPermission('mch:service-regist:delete')") + public CommonResult deleteServiceRegist(@RequestParam("id") Long id) { + serviceRegistService.deleteServiceRegist(id); + return success(true); + } + + @DeleteMapping("/delete-list") + @Parameter(name = "ids", description = "编号", required = true) + @Operation(summary = "批量删除商户服务注册") + @PreAuthorize("@ss.hasPermission('mch:service-regist:delete')") + public CommonResult deleteServiceRegistList(@RequestParam("ids") List ids) { + serviceRegistService.deleteServiceRegistListByIds(ids); + return success(true); + } + + @GetMapping("/get") + @Operation(summary = "获得商户服务注册") + @Parameter(name = "id", description = "编号", required = true, example = "1024") + @PreAuthorize("@ss.hasPermission('mch:service-regist:query')") + public CommonResult getServiceRegist(@RequestParam("id") Long id) { + ServiceRegistDO serviceRegist = serviceRegistService.getServiceRegist(id); + return success(BeanUtils.toBean(serviceRegist, ServiceRegistRespVO.class)); + } + + @GetMapping("/page") + @Operation(summary = "获得商户服务注册分页") + @PreAuthorize("@ss.hasPermission('mch:service-regist:query')") + public CommonResult> getServiceRegistPage(@Valid ServiceRegistPageReqVO pageReqVO) { + PageResult pageResult = serviceRegistService.getServiceRegistPage(pageReqVO); + return success(BeanUtils.toBean(pageResult, ServiceRegistRespVO.class)); + } + + @GetMapping("/export-excel") + @Operation(summary = "导出商户服务注册 Excel") + @PreAuthorize("@ss.hasPermission('mch:service-regist:export')") + @ApiAccessLog(operateType = EXPORT) + public void exportServiceRegistExcel(@Valid ServiceRegistPageReqVO pageReqVO, + HttpServletResponse response) throws IOException { + pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); + List list = serviceRegistService.getServiceRegistPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "商户服务注册.xls", "数据", ServiceRegistRespVO.class, + BeanUtils.toBean(list, ServiceRegistRespVO.class)); + } + +} \ No newline at end of file diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistPageReqVO.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistPageReqVO.java new file mode 100644 index 0000000..7d825a7 --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistPageReqVO.java @@ -0,0 +1,47 @@ +package cn.iocoder.hake.module.pay.controller.admin.serviceregist.vo; + +import lombok.*; +import java.util.*; +import io.swagger.v3.oas.annotations.media.Schema; +import cn.iocoder.hake.framework.common.pojo.PageParam; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; + +import static cn.iocoder.hake.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 商户服务注册分页 Request VO") +@Data +public class ServiceRegistPageReqVO extends PageParam { + + @Schema(description = "应用ID", example = "25229") + private String appId; + + @Schema(description = "应用名称", example = "王五") + private String appName; + + @Schema(description = "渠道编号", example = "6018") + private String channelId; + + @Schema(description = "商户号") + private String mchNo; + + @Schema(description = "商户名称", example = "张三") + private String mchName; + + @Schema(description = "应用状态: 0-停用, 1-正常") + private Integer state; + + @Schema(description = "应用公钥") + private String appPubKey; + + @Schema(description = "应用私钥") + private String appSecret; + + @Schema(description = "备注", example = "你说的对") + private String remark; + + @Schema(description = "创建时间") + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + private LocalDateTime[] createTime; + +} \ No newline at end of file diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistRespVO.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistRespVO.java new file mode 100644 index 0000000..e22e2bc --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistRespVO.java @@ -0,0 +1,59 @@ +package cn.iocoder.hake.module.pay.controller.admin.serviceregist.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import org.springframework.format.annotation.DateTimeFormat; +import java.time.LocalDateTime; +import com.alibaba.excel.annotation.*; + +@Schema(description = "管理后台 - 商户服务注册 Response VO") +@Data +@ExcelIgnoreUnannotated +public class ServiceRegistRespVO { + + @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1663") + @ExcelProperty("id") + private Long id; + + @Schema(description = "应用ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25229") + @ExcelProperty("应用ID") + private String appId; + + @Schema(description = "应用名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") + @ExcelProperty("应用名称") + private String appName; + + @Schema(description = "渠道编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "6018") + @ExcelProperty("渠道编号") + private String channelId; + + @Schema(description = "商户号", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("商户号") + private String mchNo; + + @Schema(description = "商户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") + @ExcelProperty("商户名称") + private String mchName; + + @Schema(description = "应用状态: 0-停用, 1-正常", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("应用状态: 0-停用, 1-正常") + private Integer state; + + @Schema(description = "应用公钥", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("应用公钥") + private String appPubKey; + + @Schema(description = "应用私钥", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("应用私钥") + private String appSecret; + + @Schema(description = "备注", example = "你说的对") + @ExcelProperty("备注") + private String remark; + + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) + @ExcelProperty("创建时间") + private LocalDateTime createTime; + +} \ No newline at end of file diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistSaveReqVO.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistSaveReqVO.java new file mode 100644 index 0000000..edf7a57 --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/controller/admin/serviceregist/vo/ServiceRegistSaveReqVO.java @@ -0,0 +1,50 @@ +package cn.iocoder.hake.module.pay.controller.admin.serviceregist.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.*; +import java.util.*; +import javax.validation.constraints.*; + +@Schema(description = "管理后台 - 商户服务注册新增/修改 Request VO") +@Data +public class ServiceRegistSaveReqVO { + + @Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1663") + private Long id; + + @Schema(description = "应用ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "25229") + @NotEmpty(message = "应用ID不能为空") + private String appId; + + @Schema(description = "应用名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "王五") + @NotEmpty(message = "应用名称不能为空") + private String appName; + + @Schema(description = "渠道编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "6018") + @NotEmpty(message = "渠道编号不能为空") + private String channelId; + + @Schema(description = "商户号", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "商户号不能为空") + private String mchNo; + + @Schema(description = "商户名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "张三") + @NotEmpty(message = "商户名称不能为空") + private String mchName; + + @Schema(description = "应用状态: 0-停用, 1-正常", requiredMode = Schema.RequiredMode.REQUIRED) + @NotNull(message = "应用状态: 0-停用, 1-正常不能为空") + private Integer state; + + @Schema(description = "应用公钥", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "应用公钥不能为空") + private String appPubKey; + + @Schema(description = "应用私钥", requiredMode = Schema.RequiredMode.REQUIRED) + @NotEmpty(message = "应用私钥不能为空") + private String appSecret; + + @Schema(description = "备注", example = "你说的对") + private String remark; + +} \ No newline at end of file diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/dal/dataobject/serviceregist/ServiceRegistDO.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/dal/dataobject/serviceregist/ServiceRegistDO.java new file mode 100644 index 0000000..0266a80 --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/dal/dataobject/serviceregist/ServiceRegistDO.java @@ -0,0 +1,65 @@ +package cn.iocoder.hake.module.pay.dal.dataobject.serviceregist; + +import lombok.*; +import com.baomidou.mybatisplus.annotation.*; +import cn.iocoder.hake.framework.mybatis.core.dataobject.BaseDO; + +/** + * 商户服务注册 DO + * + * @author hake + */ +@TableName("mch_service_regist") +@KeySequence("mch_service_regist_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class ServiceRegistDO extends BaseDO { + + /** + * id + */ + @TableId + private Long id; + /** + * 应用ID + */ + private String appId; + /** + * 应用名称 + */ + private String appName; + /** + * 渠道编号 + */ + private String channelId; + /** + * 商户号 + */ + private String mchNo; + /** + * 商户名称 + */ + private String mchName; + /** + * 应用状态: 0-停用, 1-正常 + */ + private Integer state; + /** + * 应用公钥 + */ + private String appPubKey; + /** + * 应用私钥 + */ + private String appSecret; + /** + * 备注 + */ + private String remark; + + +} \ No newline at end of file diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/dal/mysql/serviceregist/ServiceRegistMapper.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/dal/mysql/serviceregist/ServiceRegistMapper.java new file mode 100644 index 0000000..f3224df --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/dal/mysql/serviceregist/ServiceRegistMapper.java @@ -0,0 +1,41 @@ +package cn.iocoder.hake.module.pay.dal.mysql.serviceregist; + +import cn.iocoder.hake.framework.common.pojo.PageResult; +import cn.iocoder.hake.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.hake.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.hake.module.pay.dal.dataobject.serviceregist.ServiceRegistDO; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import org.apache.ibatis.annotations.Mapper; +import cn.iocoder.hake.module.pay.controller.admin.serviceregist.vo.*; + +/** + * 商户服务注册 Mapper + * + * @author hake + */ +@Mapper +public interface ServiceRegistMapper extends BaseMapperX { + + default PageResult selectPage(ServiceRegistPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(ServiceRegistDO::getAppId, reqVO.getAppId()) + .likeIfPresent(ServiceRegistDO::getAppName, reqVO.getAppName()) + .eqIfPresent(ServiceRegistDO::getChannelId, reqVO.getChannelId()) + .eqIfPresent(ServiceRegistDO::getMchNo, reqVO.getMchNo()) + .likeIfPresent(ServiceRegistDO::getMchName, reqVO.getMchName()) + .eqIfPresent(ServiceRegistDO::getState, reqVO.getState()) + .eqIfPresent(ServiceRegistDO::getAppPubKey, reqVO.getAppPubKey()) + .eqIfPresent(ServiceRegistDO::getAppSecret, reqVO.getAppSecret()) + .eqIfPresent(ServiceRegistDO::getRemark, reqVO.getRemark()) + .betweenIfPresent(ServiceRegistDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(ServiceRegistDO::getId)); + } + + default ServiceRegistDO selectByCondition(String appId, String channelId, String mchNo) { + return selectOne(Wrappers.lambdaQuery() + .eq(ServiceRegistDO::getAppId, appId) + .eq(ServiceRegistDO::getChannelId, channelId) + .eq(ServiceRegistDO::getMchNo, mchNo)); + } + +} \ No newline at end of file diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/config/HuifuClientConfig.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/config/HuifuClientConfig.java new file mode 100644 index 0000000..7d37a81 --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/config/HuifuClientConfig.java @@ -0,0 +1,69 @@ +package cn.iocoder.hake.module.pay.framework.pay.config; + +import cn.iocoder.hake.module.pay.framework.pay.core.client.PayClientConfig; +import lombok.Data; +import org.springframework.beans.factory.annotation.Value; + +import javax.validation.Validator; + +/** + * 汇付支付的 PayClientConfig 实现类 + * 属性主要来自 {@link com.huifu.bspay.sdk.opps.core.config.MerConfig} 的必要属性 + * + * @author duanyuqing + */ +@Data +public class HuifuClientConfig implements PayClientConfig { + + @Value("${profiles.active}") + private String active; + + /** + * debug 模式,开启后有详细的日志 + */ + private boolean debug; + + /** + * prodMode 模式,默认为生产模式 + * MODE_PROD = "prod"; // 生产环境 + * MODE_TEST = "test"; // 线上联调环境(针对商户联调测试) + */ + private String prodMode; + + + //产品编号 + @Value("${huifu.procutId}") + private String procutId; + + //系统编号 + @Value("${huifu.sysId}") + private String sysId; + + //私钥 + @Value("${huifu.rsaPrivateKey}") + private String rsaPrivateKey; + + //公钥 + @Value("${huifu.rsaPublicKey}") + private String rsaPublicKey; + + //自定义超时时间 + @Value("${huifu.customConnectTimeout}") + private String customSocketTimeout; + + @Value("${huifu.customConnectTimeout}") + private String customConnectTimeout; + + @Value("${huifu.customConnectionRequestTimeout}") + private String customConnectionRequestTimeout; + + + @Override + + public void validate(Validator validator) { + //读取环境配置,调用汇付接口 + prodMode = active.equals("prod") ? "MODE_PROD" : "MODE_TEST"; + debug = active.equals("prod") ? false : true; + } + +} diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/core/client/impl/huifu/HuifuPayClient.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/core/client/impl/huifu/HuifuPayClient.java new file mode 100644 index 0000000..2586a7b --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/core/client/impl/huifu/HuifuPayClient.java @@ -0,0 +1,597 @@ +package cn.iocoder.hake.module.pay.framework.pay.core.client.impl.huifu; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.codec.Base64; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.date.TemporalAccessorUtil; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.hake.framework.common.util.io.FileUtils; +import cn.iocoder.hake.framework.common.util.json.JsonUtils; +import cn.iocoder.hake.framework.common.util.object.ObjectUtils; +import cn.iocoder.hake.module.pay.enums.order.PayOrderStatusEnum; +import cn.iocoder.hake.module.pay.framework.pay.config.HuifuClientConfig; +import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.order.PayOrderRespDTO; +import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; +import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.refund.PayRefundRespDTO; +import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; +import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.transfer.PayTransferRespDTO; +import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO; +import cn.iocoder.hake.module.pay.framework.pay.core.client.impl.AbstractPayClient; +import com.github.binarywang.wxpay.bean.notify.*; +import com.github.binarywang.wxpay.bean.request.*; +import com.github.binarywang.wxpay.bean.result.*; +import com.github.binarywang.wxpay.bean.transfer.TransferBillsGetResult; +import com.github.binarywang.wxpay.bean.transfer.TransferBillsNotifyResult; +import com.github.binarywang.wxpay.bean.transfer.TransferBillsRequest; +import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult; +import com.github.binarywang.wxpay.config.WxPayConfig; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; +import lombok.extern.slf4j.Slf4j; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Map; +import java.util.Objects; + +import static cn.hutool.core.date.DatePattern.*; +import static cn.iocoder.hake.module.pay.framework.pay.core.client.impl.weixin.WxPayClientConfig.API_VERSION_V2; +import static cn.iocoder.hake.module.pay.framework.pay.core.client.impl.weixin.WxPayClientConfig.API_VERSION_V3; + +/** + * 汇付天下支付抽象类 + * + * @author duanyuqing + */ +@Slf4j +public abstract class HuifuPayClient extends AbstractPayClient { + + protected TradePaymentMicropayRequest client; + + public HuifuPayClient(Long channelId, String channelCode, HuifuClientConfig config) { + super(channelId, channelCode, config); + } + + /** + * 初始化 client 客户端 + * + * @param tradeType 交易类型 + */ + protected void doInit(String tradeType) { + // 创建 config 配置 + WxPayConfig payConfig = new WxPayConfig(); + BeanUtil.copyProperties(config, payConfig, "keyContent", "privateKeyContent", "publicKeyContent"); + payConfig.setTradeType(tradeType); + // weixin-pay-java 无法设置内容,只允许读取文件,所以这里要创建临时文件来解决 + if (Objects.equals(config.getApiVersion(), API_VERSION_V2)) { + payConfig.setKeyPath(FileUtils.createTempFile(Base64.decode(config.getKeyContent())).getPath()); + } else if (Objects.equals(config.getApiVersion(), API_VERSION_V3)) { + payConfig.setPrivateKeyPath(FileUtils.createTempFile(config.getPrivateKeyContent()).getPath()); + payConfig.setPublicKeyPath(FileUtils.createTempFile(config.getPublicKeyContent()).getPath()); + // 特殊:强制使用微信公用模式,避免灰度期间的问题!!! + payConfig.setStrictlyNeedWechatPaySerial(true); + } + + // 创建 client 客户端 + client = new WxPayServiceImpl(); + client.setConfig(payConfig); + } + + // ============ 支付相关 ========== + + @Override + protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) throws Exception { + try { + switch (config.getApiVersion()) { + case API_VERSION_V2: + return doUnifiedOrderV2(reqDTO); + case API_VERSION_V3: + // TODO @哈客:【可能是 wxjava 的 bug】参考 https://github.com/binarywang/WxJava/issues/1557 + client.getConfig().setApiV3HttpClient(null); + return doUnifiedOrderV3(reqDTO); + default: + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); + } + } catch (WxPayException e) { + log.error("[doUnifiedOrder][支付({}) 发起微信支付异常", reqDTO, e); + String errorCode = getErrorCode(e); + String errorMessage = getErrorMessage(e); + return PayOrderRespDTO.closedOf(errorCode, errorMessage, + reqDTO.getOutTradeNo(), e.getXmlString()); + } + } + + /** + * 【V2】调用支付渠道,统一下单 + * + * @param reqDTO 下单信息 + * @return 各支付渠道的返回结果 + */ + protected abstract PayOrderRespDTO doUnifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) + throws Exception; + + /** + * 【V3】调用支付渠道,统一下单 + * + * @param reqDTO 下单信息 + * @return 各支付渠道的返回结果 + */ + protected abstract PayOrderRespDTO doUnifiedOrderV3(PayOrderUnifiedReqDTO reqDTO) + throws WxPayException; + + /** + * 【V2】创建微信下单请求 + * + * @param reqDTO 下信息 + * @return 下单请求 + */ + protected WxPayUnifiedOrderRequest buildPayUnifiedOrderRequestV2(PayOrderUnifiedReqDTO reqDTO) { + return WxPayUnifiedOrderRequest.newBuilder() + .outTradeNo(reqDTO.getOutTradeNo()) + .body(reqDTO.getSubject()) + .detail(reqDTO.getBody()) + .totalFee(reqDTO.getPrice()) // 单位分 + .timeExpire(formatDateV2(reqDTO.getExpireTime())) + .spbillCreateIp(reqDTO.getUserIp()) + .notifyUrl(reqDTO.getNotifyUrl()) + .build(); + } + + /** + * 【V3】创建微信下单请求 + * + * @param reqDTO 下信息 + * @return 下单请求 + */ + protected WxPayUnifiedOrderV3Request buildPayUnifiedOrderRequestV3(PayOrderUnifiedReqDTO reqDTO) { + WxPayUnifiedOrderV3Request request = new WxPayUnifiedOrderV3Request(); + request.setOutTradeNo(reqDTO.getOutTradeNo()); + request.setDescription(reqDTO.getSubject()); + request.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(reqDTO.getPrice())); // 单位分 + request.setTimeExpire(formatDateV3(reqDTO.getExpireTime())); + request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); + request.setNotifyUrl(reqDTO.getNotifyUrl()); + return request; + } + + @Override + public PayOrderRespDTO doParseOrderNotify(Map params, String body, Map headers) throws WxPayException { + switch (config.getApiVersion()) { + case API_VERSION_V2: + return doParseOrderNotifyV2(body); + case API_VERSION_V3: + return doParseOrderNotifyV3(body, headers); + default: + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); + } + } + + private PayOrderRespDTO doParseOrderNotifyV2(String body) throws WxPayException { + // 1. 解析回调 + WxPayOrderNotifyResult response = client.parseOrderNotifyResult(body); + // 2. 构建结果 + // V2 微信支付的回调,只有 SUCCESS 支付成功、CLOSED 支付失败两种情况,无需像支付宝一样解析的比较复杂 + Integer status = Objects.equals(response.getResultCode(), "SUCCESS") ? + PayOrderStatusEnum.SUCCESS.getStatus() : PayOrderStatusEnum.CLOSED.getStatus(); + return PayOrderRespDTO.of(status, response.getTransactionId(), response.getOpenid(), parseDateV2(response.getTimeEnd()), + response.getOutTradeNo(), body); + } + + private PayOrderRespDTO doParseOrderNotifyV3(String body, Map headers) throws WxPayException { + // 1. 解析回调 + SignatureHeader signatureHeader = getRequestHeader(headers); + WxPayNotifyV3Result response = client.parseOrderNotifyV3Result(body, signatureHeader); + WxPayNotifyV3Result.DecryptNotifyResult result = response.getResult(); + // 2. 构建结果 + Integer status = parseStatus(result.getTradeState()); + String openid = result.getPayer() != null ? result.getPayer().getOpenid() : null; + return PayOrderRespDTO.of(status, result.getTransactionId(), openid, parseDateV3(result.getSuccessTime()), + result.getOutTradeNo(), body); + } + + @Override + protected PayOrderRespDTO doGetOrder(String outTradeNo) throws Throwable { + try { + switch (config.getApiVersion()) { + case API_VERSION_V2: + return doGetOrderV2(outTradeNo); + case API_VERSION_V3: + return doGetOrderV3(outTradeNo); + default: + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); + } + } catch (WxPayException e) { + if (ObjectUtils.equalsAny(e.getErrCode(), "ORDERNOTEXIST", "ORDER_NOT_EXIST")) { + String errorCode = getErrorCode(e); + String errorMessage = getErrorMessage(e); + return PayOrderRespDTO.closedOf(errorCode, errorMessage, + outTradeNo, e.getXmlString()); + } + throw e; + } + } + + private PayOrderRespDTO doGetOrderV2(String outTradeNo) throws WxPayException { + // 构建 WxPayUnifiedOrderRequest 对象 + WxPayOrderQueryRequest request = WxPayOrderQueryRequest.newBuilder() + .outTradeNo(outTradeNo).build(); + // 执行请求 + WxPayOrderQueryResult response = client.queryOrder(request); + + // 转换结果 + Integer status = parseStatus(response.getTradeState()); + return PayOrderRespDTO.of(status, response.getTransactionId(), response.getOpenid(), parseDateV2(response.getTimeEnd()), + outTradeNo, response); + } + + private PayOrderRespDTO doGetOrderV3(String outTradeNo) throws WxPayException { + fixV3HttpClientConnectionPoolShutDown(); + // 构建 WxPayUnifiedOrderRequest 对象 + WxPayOrderQueryV3Request request = new WxPayOrderQueryV3Request() + .setOutTradeNo(outTradeNo); + // 执行请求 + WxPayOrderQueryV3Result response = client.queryOrderV3(request); + + // 转换结果 + Integer status = parseStatus(response.getTradeState()); + String openid = response.getPayer() != null ? response.getPayer().getOpenid() : null; + return PayOrderRespDTO.of(status, response.getTransactionId(), openid, parseDateV3(response.getSuccessTime()), + outTradeNo, response); + } + + private static Integer parseStatus(String tradeState) { + switch (tradeState) { + case "NOTPAY": + case "USERPAYING": // 支付中,等待用户输入密码(条码支付独有) + return PayOrderStatusEnum.WAITING.getStatus(); + case "SUCCESS": + return PayOrderStatusEnum.SUCCESS.getStatus(); + case "REFUND": + return PayOrderStatusEnum.REFUND.getStatus(); + case "CLOSED": + case "REVOKED": // 已撤销(刷卡支付独有) + case "PAYERROR": // 支付失败(其它原因,如银行返回失败) + return PayOrderStatusEnum.CLOSED.getStatus(); + default: + throw new IllegalArgumentException(StrUtil.format("未知的支付状态({})", tradeState)); + } + } + + // ============ 退款相关 ========== + + @Override + protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable { + try { + switch (config.getApiVersion()) { + case API_VERSION_V2: + return doUnifiedRefundV2(reqDTO); + case API_VERSION_V3: + return doUnifiedRefundV3(reqDTO); + default: + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); + } + } catch (WxPayException e) { + String errorCode = getErrorCode(e); + String errorMessage = getErrorMessage(e); + return PayRefundRespDTO.failureOf(errorCode, errorMessage, + reqDTO.getOutRefundNo(), e.getXmlString()); + } + } + + private PayRefundRespDTO doUnifiedRefundV2(PayRefundUnifiedReqDTO reqDTO) throws Throwable { + // 1. 构建 WxPayRefundRequest 请求 + WxPayRefundRequest request = new WxPayRefundRequest() + .setOutTradeNo(reqDTO.getOutTradeNo()) + .setOutRefundNo(reqDTO.getOutRefundNo()) + .setRefundFee(reqDTO.getRefundPrice()) + .setRefundDesc(reqDTO.getReason()) + .setTotalFee(reqDTO.getPayPrice()) + .setNotifyUrl(reqDTO.getNotifyUrl()); + // 2.1 执行请求 + WxPayRefundResult response = client.refundV2(request); + // 2.2 创建返回结果 + if (Objects.equals("SUCCESS", response.getResultCode())) { // V2 情况下,不直接返回退款成功,而是等待异步通知 + return PayRefundRespDTO.waitingOf(response.getRefundId(), + reqDTO.getOutRefundNo(), response); + } + return PayRefundRespDTO.failureOf(reqDTO.getOutRefundNo(), response); + } + + private PayRefundRespDTO doUnifiedRefundV3(PayRefundUnifiedReqDTO reqDTO) throws Throwable { + fixV3HttpClientConnectionPoolShutDown(); + // 1. 构建 WxPayRefundRequest 请求 + WxPayRefundV3Request request = new WxPayRefundV3Request() + .setOutTradeNo(reqDTO.getOutTradeNo()) + .setOutRefundNo(reqDTO.getOutRefundNo()) + .setAmount(new WxPayRefundV3Request.Amount().setRefund(reqDTO.getRefundPrice()) + .setTotal(reqDTO.getPayPrice()).setCurrency("CNY")) + .setReason(reqDTO.getReason()) + .setNotifyUrl(reqDTO.getNotifyUrl()); + // 2.1 执行请求 + WxPayRefundV3Result response = client.refundV3(request); + // 2.2 创建返回结果 + if (Objects.equals("SUCCESS", response.getStatus())) { + return PayRefundRespDTO.successOf(response.getRefundId(), parseDateV3(response.getSuccessTime()), + reqDTO.getOutRefundNo(), response); + } + if (Objects.equals("PROCESSING", response.getStatus())) { + return PayRefundRespDTO.waitingOf(response.getRefundId(), + reqDTO.getOutRefundNo(), response); + } + return PayRefundRespDTO.failureOf(reqDTO.getOutRefundNo(), response); + } + + @Override + public PayRefundRespDTO doParseRefundNotify(Map params, String body, Map headers) throws WxPayException { + switch (config.getApiVersion()) { + case API_VERSION_V2: + return doParseRefundNotifyV2(body); + case API_VERSION_V3: + return parseRefundNotifyV3(body, headers); + default: + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); + } + } + + private PayRefundRespDTO doParseRefundNotifyV2(String body) throws WxPayException { + // 1. 解析回调 + WxPayRefundNotifyResult response = client.parseRefundNotifyResult(body); + WxPayRefundNotifyResult.ReqInfo result = response.getReqInfo(); + // 2. 构建结果 + if (Objects.equals("SUCCESS", result.getRefundStatus())) { + return PayRefundRespDTO.successOf(result.getRefundId(), parseDateV2B(result.getSuccessTime()), + result.getOutRefundNo(), response); + } + return PayRefundRespDTO.failureOf(result.getOutRefundNo(), response); + } + + private PayRefundRespDTO parseRefundNotifyV3(String body, Map headers) throws WxPayException { + // 1. 解析回调 + SignatureHeader signatureHeader = getRequestHeader(headers); + WxPayRefundNotifyV3Result response = client.parseRefundNotifyV3Result(body, signatureHeader); + WxPayRefundNotifyV3Result.DecryptNotifyResult result = response.getResult(); + // 2. 构建结果 + if (Objects.equals("SUCCESS", result.getRefundStatus())) { + return PayRefundRespDTO.successOf(result.getRefundId(), parseDateV3(result.getSuccessTime()), + result.getOutRefundNo(), response); + } + return PayRefundRespDTO.failureOf(result.getOutRefundNo(), response); + } + + @Override + protected PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) throws WxPayException { + try { + switch (config.getApiVersion()) { + case API_VERSION_V2: + return doGetRefundV2(outTradeNo, outRefundNo); + case API_VERSION_V3: + return doGetRefundV3(outTradeNo, outRefundNo); + default: + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); + } + } catch (WxPayException e) { + if (ObjectUtils.equalsAny(e.getErrCode(), "REFUNDNOTEXIST", "RESOURCE_NOT_EXISTS")) { + String errorCode = getErrorCode(e); + String errorMessage = getErrorMessage(e); + return PayRefundRespDTO.failureOf(errorCode, errorMessage, + outRefundNo, e.getXmlString()); + } + throw e; + } + } + + private PayRefundRespDTO doGetRefundV2(String outTradeNo, String outRefundNo) throws WxPayException { + // 1. 构建 WxPayRefundRequest 请求 + WxPayRefundQueryRequest request = WxPayRefundQueryRequest.newBuilder() + .outTradeNo(outTradeNo) + .outRefundNo(outRefundNo) + .build(); + // 2.1 执行请求 + WxPayRefundQueryResult response = client.refundQuery(request); + // 2.2 创建返回结果 + if (!Objects.equals("SUCCESS", response.getResultCode())) { + return PayRefundRespDTO.waitingOf(null, + outRefundNo, response); + } + WxPayRefundQueryResult.RefundRecord refund = CollUtil.findOne(response.getRefundRecords(), + record -> record.getOutRefundNo().equals(outRefundNo)); + if (refund == null) { + return PayRefundRespDTO.failureOf(outRefundNo, response); + } + switch (refund.getRefundStatus()) { + case "SUCCESS": + return PayRefundRespDTO.successOf(refund.getRefundId(), parseDateV2B(refund.getRefundSuccessTime()), + outRefundNo, response); + case "PROCESSING": + return PayRefundRespDTO.waitingOf(refund.getRefundId(), + outRefundNo, response); + case "CHANGE": // 退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,资金回流到商户的现金帐号,需要商户人工干预,通过线下或者财付通转账的方式进行退款 + case "FAIL": + return PayRefundRespDTO.failureOf(outRefundNo, response); + default: + throw new IllegalArgumentException(String.format("未知的退款状态(%s)", refund.getRefundStatus())); + } + } + + private PayRefundRespDTO doGetRefundV3(String outTradeNo, String outRefundNo) throws WxPayException { + fixV3HttpClientConnectionPoolShutDown(); + // 1. 构建 WxPayRefundRequest 请求 + WxPayRefundQueryV3Request request = new WxPayRefundQueryV3Request(); + request.setOutRefundNo(outRefundNo); + // 2.1 执行请求 + WxPayRefundQueryV3Result response = client.refundQueryV3(request); + // 2.2 创建返回结果 + switch (response.getStatus()) { + case "SUCCESS": + return PayRefundRespDTO.successOf(response.getRefundId(), parseDateV3(response.getSuccessTime()), + outRefundNo, response); + case "PROCESSING": + return PayRefundRespDTO.waitingOf(response.getRefundId(), + outRefundNo, response); + case "ABNORMAL": // 退款异常 + case "CLOSED": + return PayRefundRespDTO.failureOf(outRefundNo, response); + default: + throw new IllegalArgumentException(String.format("未知的退款状态(%s)", response.getStatus())); + } + } + + @Override + protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) throws WxPayException { + fixV3HttpClientConnectionPoolShutDown(); + // 1. 构建 TransferBillsRequest 请求 + TransferBillsRequest request = TransferBillsRequest.newBuilder() + .appid(this.config.getAppId()) + .outBillNo(reqDTO.getOutTransferNo()) + .transferAmount(reqDTO.getPrice()) + .transferRemark(reqDTO.getSubject()) + .transferSceneId(reqDTO.getChannelExtras().get("sceneId")) + .openid(reqDTO.getUserAccount()) + .userName(reqDTO.getUserName()) + .transferSceneReportInfos(JsonUtils.parseArray(reqDTO.getChannelExtras().get("sceneReportInfos"), + TransferBillsRequest.TransferSceneReportInfo.class)) + .notifyUrl(reqDTO.getNotifyUrl()) + .build(); + // 特殊:微信转账,必须 0.3 元起,才允许传入姓名 + if (reqDTO.getPrice() < 30) { + request.setUserName(null); + } + + // 2.1 执行请求 + try { + TransferBillsResult response = client.getTransferService().transferBills(request); + + // 2.2 创建返回结果 + String state = response.getState(); + if (ObjectUtils.equalsAny(state, "ACCEPTED", "PROCESSING", "WAIT_USER_CONFIRM", "TRANSFERING")) { + return PayTransferRespDTO.processingOf(response.getTransferBillNo(), response.getOutBillNo(), response) + .setChannelPackageInfo(response.getPackageInfo()); // 一般情况下,只有 WAIT_USER_CONFIRM 会有! + } + if (Objects.equals("SUCCESS", state)) { + return PayTransferRespDTO.successOf(response.getTransferBillNo(), parseDateV3(response.getCreateTime()), + response.getOutBillNo(), response); + } + return PayTransferRespDTO.closedOf(state, response.getFailReason(), + response.getOutBillNo(), response); + } catch (WxPayException e) { + log.error("[doUnifiedTransfer][转账({}) 发起微信支付异常", reqDTO, e); + String errorCode = getErrorCode(e); + String errorMessage = getErrorMessage(e); + return PayTransferRespDTO.closedOf(errorCode, errorMessage, + reqDTO.getOutTransferNo(), e.getXmlString()); + } + } + + @Override + protected PayTransferRespDTO doGetTransfer(String outTradeNo) throws WxPayException { + fixV3HttpClientConnectionPoolShutDown(); + // 1. 执行请求 + TransferBillsGetResult response = client.getTransferService().getBillsByOutBillNo(outTradeNo); + + // 2. 创建返回结果 + String state = response.getState(); + if (ObjectUtils.equalsAny(state, "ACCEPTED", "PROCESSING", "WAIT_USER_CONFIRM", "TRANSFERING")) { + return PayTransferRespDTO.processingOf(response.getTransferBillNo(), response.getOutBillNo(), response); + } + if (Objects.equals("SUCCESS", state)) { + return PayTransferRespDTO.successOf(response.getTransferBillNo(), parseDateV3(response.getUpdateTime()), + response.getOutBillNo(), response); + } + return PayTransferRespDTO.closedOf(state, response.getFailReason(), + response.getOutBillNo(), response); + } + + @Override + public PayTransferRespDTO doParseTransferNotify(Map params, String body, Map headers) throws WxPayException { + switch (config.getApiVersion()) { + case API_VERSION_V3: + return parseTransferNotifyV3(body, headers); + case API_VERSION_V2: + throw new UnsupportedOperationException("V2 版本暂不支持,建议使用 V3 版本"); + default: + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); + } + } + + private PayTransferRespDTO parseTransferNotifyV3(String body, Map headers) throws WxPayException { + // 1. 解析回调 + SignatureHeader signatureHeader = getRequestHeader(headers); + TransferBillsNotifyResult response = client.getTransferService().parseTransferBillsNotifyResult(body, signatureHeader); + TransferBillsNotifyResult.DecryptNotifyResult result = response.getResult(); + + // 2. 创建返回结果 + String state = result.getState(); + if (ObjectUtils.equalsAny(state, "ACCEPTED", "PROCESSING", "WAIT_USER_CONFIRM", "TRANSFERING")) { + return PayTransferRespDTO.processingOf(result.getTransferBillNo(), result.getOutBillNo(), response); + } + if (Objects.equals("SUCCESS", state)) { + return PayTransferRespDTO.successOf(result.getTransferBillNo(), parseDateV3(result.getUpdateTime()), + result.getOutBillNo(), response); + } + return PayTransferRespDTO.closedOf(state, result.getFailReason(), + result.getOutBillNo(), response); + } + + // ========== 各种工具方法 ========== + + /** + * 组装请求头重的签名信息 + * + * @see 官方示例 + */ + private SignatureHeader getRequestHeader(Map headers) { + return SignatureHeader.builder() + .signature(headers.get("wechatpay-signature")) + .nonce(headers.get("wechatpay-nonce")) + .serial(headers.get("wechatpay-serial")) + .timeStamp(headers.get("wechatpay-timestamp")) + .build(); + } + + // TODO @哈客:可能是 wxjava 的 bug:https://github.com/binarywang/WxJava/issues/1557 + private void fixV3HttpClientConnectionPoolShutDown() { + client.getConfig().setApiV3HttpClient(null); + } + + static String formatDateV2(LocalDateTime time) { + return TemporalAccessorUtil.format(time.atZone(ZoneId.systemDefault()), PURE_DATETIME_PATTERN); + } + + static LocalDateTime parseDateV2(String time) { + return LocalDateTimeUtil.parse(time, PURE_DATETIME_PATTERN); + } + + static LocalDateTime parseDateV2B(String time) { + return LocalDateTimeUtil.parse(time, NORM_DATETIME_PATTERN); + } + + static String formatDateV3(LocalDateTime time) { + return TemporalAccessorUtil.format(time.atZone(ZoneId.systemDefault()), UTC_WITH_XXX_OFFSET_PATTERN); + } + + static LocalDateTime parseDateV3(String time) { + return LocalDateTimeUtil.parse(time, UTC_WITH_XXX_OFFSET_PATTERN); + } + + static String getErrorCode(WxPayException e) { + if (StrUtil.isNotEmpty(e.getErrCode())) { + return e.getErrCode(); + } + if (StrUtil.isNotEmpty(e.getCustomErrorMsg())) { + return "CUSTOM_ERROR"; + } + return e.getReturnCode(); + } + + static String getErrorMessage(WxPayException e) { + if (StrUtil.isNotEmpty(e.getErrCode())) { + return e.getErrCodeDes(); + } + if (StrUtil.isNotEmpty(e.getCustomErrorMsg())) { + return e.getCustomErrorMsg(); + } + return e.getReturnMsg(); + } + +} diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/service/serviceregist/ServiceRegistService.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/service/serviceregist/ServiceRegistService.java new file mode 100644 index 0000000..a7260de --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/service/serviceregist/ServiceRegistService.java @@ -0,0 +1,72 @@ +package cn.iocoder.hake.module.pay.service.serviceregist; + +import java.util.*; +import javax.validation.*; + +import cn.iocoder.hake.module.pay.controller.admin.serviceregist.vo.*; +import cn.iocoder.hake.module.pay.dal.dataobject.serviceregist.ServiceRegistDO; +import cn.iocoder.hake.framework.common.pojo.PageResult; + +/** + * 商户服务注册 Service 接口 + * + * @author hake + */ +public interface ServiceRegistService { + + /** + * 创建商户服务注册 + * + * @param createReqVO 创建信息 + * @return 编号 + */ + Long createServiceRegist(@Valid ServiceRegistSaveReqVO createReqVO); + + /** + * 更新商户服务注册 + * + * @param updateReqVO 更新信息 + */ + void updateServiceRegist(@Valid ServiceRegistSaveReqVO updateReqVO); + + /** + * 删除商户服务注册 + * + * @param id 编号 + */ + void deleteServiceRegist(Long id); + + /** + * 批量删除商户服务注册 + * + * @param ids 编号 + */ + void deleteServiceRegistListByIds(List ids); + + /** + * 获得商户服务注册 + * + * @param id 编号 + * @return 商户服务注册 + */ + ServiceRegistDO getServiceRegist(Long id); + + /** + * 获得商户服务注册分页 + * + * @param pageReqVO 分页查询 + * @return 商户服务注册分页 + */ + PageResult getServiceRegistPage(ServiceRegistPageReqVO pageReqVO); + + /** + * 获得商户服务注册信息 + * + * @param appId 应用编号 + * @param channelId 渠道编号 + * @param mchNo 商户编号 + * @return 商户服务注册信息 + */ + ServiceRegistDO getServiceRegist(String appId, String channelId, String mchNo); + +} \ No newline at end of file diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/service/serviceregist/ServiceRegistServiceImpl.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/service/serviceregist/ServiceRegistServiceImpl.java new file mode 100644 index 0000000..f10be8a --- /dev/null +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/service/serviceregist/ServiceRegistServiceImpl.java @@ -0,0 +1,113 @@ +package cn.iocoder.hake.module.pay.service.serviceregist; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.hake.framework.security.core.util.SecurityFrameworkUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +import org.springframework.validation.annotation.Validated; + +import java.time.LocalDateTime; +import java.util.*; + +import cn.iocoder.hake.module.pay.controller.admin.serviceregist.vo.*; +import cn.iocoder.hake.module.pay.dal.dataobject.serviceregist.ServiceRegistDO; +import cn.iocoder.hake.framework.common.pojo.PageResult; +import cn.iocoder.hake.framework.common.util.object.BeanUtils; + +import cn.iocoder.hake.module.pay.dal.mysql.serviceregist.ServiceRegistMapper; + +import static cn.iocoder.hake.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.hake.module.pay.enums.ErrorCodeConstants.*; + +/** + * 商户服务注册 Service 实现类 + * + * @author hake + */ +@Service +@Validated +public class ServiceRegistServiceImpl implements ServiceRegistService { + + @Resource + private ServiceRegistMapper serviceRegistMapper; + + + @Override + public Long createServiceRegist(ServiceRegistSaveReqVO createReqVO) { + // 插入 + ServiceRegistDO serviceRegist = BeanUtils.toBean(createReqVO, ServiceRegistDO.class); + serviceRegist.setCreator(SecurityFrameworkUtils.getLoginUserId().toString()); + serviceRegist.setUpdater(SecurityFrameworkUtils.getLoginUserId().toString()); + serviceRegist.setDeleted(false); + serviceRegistMapper.insert(serviceRegist); + // 返回 + return serviceRegist.getId(); + } + + @Override + public void updateServiceRegist(ServiceRegistSaveReqVO updateReqVO) { + // 校验存在 + validateServiceRegistExists(updateReqVO.getId()); + // 更新 + ServiceRegistDO updateObj = BeanUtils.toBean(updateReqVO, ServiceRegistDO.class); + updateObj.setUpdater(SecurityFrameworkUtils.getLoginUserId().toString()); + updateObj.setUpdateTime(LocalDateTime.now()); + serviceRegistMapper.updateById(updateObj); + } + + @Override + public void deleteServiceRegist(Long id) { + // 校验存在 + validateServiceRegistExists(id); + // 删除 + serviceRegistMapper.deleteById(id); + } + + @Override + public void deleteServiceRegistListByIds(List ids) { + // 校验存在 + validateServiceRegistExists(ids); + // 删除 + serviceRegistMapper.deleteByIds(ids); + } + + private void validateServiceRegistExists(List ids) { + List list = serviceRegistMapper.selectByIds(ids); + if (CollUtil.isEmpty(list) || list.size() != ids.size()) { + throw exception(SERVICE_REGIST_NOT_EXISTS); + } + } + + private void validateServiceRegistExists(Long id) { + if (serviceRegistMapper.selectById(id) == null) { + throw exception(SERVICE_REGIST_NOT_EXISTS); + } + } + + @Override + public ServiceRegistDO getServiceRegist(Long id) { + return serviceRegistMapper.selectById(id); + } + + @Override + public PageResult getServiceRegistPage(ServiceRegistPageReqVO pageReqVO) { + return serviceRegistMapper.selectPage(pageReqVO); + } + + + /** + * 获得商户服务注册信息 + * + * @param appId 应用编号 + * @param channelId 渠道编号 + * @param mchNo 商户编号 + * @return 商户服务注册信息 + */ + @Override + public ServiceRegistDO getServiceRegist(String appId, String channelId, String mchNo) { + return serviceRegistMapper.selectByCondition(appId, channelId, mchNo); + } + +} \ No newline at end of file diff --git a/sql/mysql/pay.sql b/sql/mysql/pay.sql index 58aaf09..d190ccd 100644 --- a/sql/mysql/pay.sql +++ b/sql/mysql/pay.sql @@ -479,18 +479,42 @@ BEGIN; INSERT INTO `pay_wallet_transaction` (`id`, `wallet_id`, `biz_type`, `biz_id`, `no`, `title`, `price`, `balance`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `tenant_id`) VALUES (1, 1, 1, '4', 'W202309301852101', '充值', 1000, 1100, NULL, '2023-09-30 18:52:10', NULL, '2023-09-30 18:52:10', b'0', 1), (2, 1, 1, '5', 'W202309301852251', '充值', 1000, 2100, NULL, '2023-09-30 18:52:26', NULL, '2023-09-30 18:52:26', b'0', 1), (3, 1, 3, '338', 'W202309302207411', '支付', -559920, 440079, '247', '2023-09-30 22:07:42', '247', '2023-09-30 22:07:42', b'0', 1), (4, 1, 3, '341', 'W202310021021111', '支付', -384945, 55134, '247', '2023-10-02 10:21:11', '247', '2023-10-02 10:21:11', b'0', 1), (5, 1, 3, '345', 'W202310052305281', '支付', -201, 54933, '247', '2023-10-05 23:05:28', '247', '2023-10-05 23:05:28', b'0', 1), (6, 1, 3, '349', 'W202310052322591', '支付', -201, 54732, '247', '2023-10-05 23:23:00', '247', '2023-10-05 23:23:00', b'0', 1), (7, 1, 3, '370', 'W202312122004591', '支付', -206, 54526, '247', '2023-12-12 20:04:59', '247', '2023-12-12 20:04:59', b'0', 1), (8, 1, 3, '371', 'W202312122012151', '支付', -700100, 53825900, '247', '2023-12-12 20:12:15', '247', '2023-12-12 20:12:15', b'0', 1), (9, 1, 3, '372', 'W202312122049431', '支付', -255, 53825645, '247', '2023-12-12 20:49:43', '247', '2023-12-12 20:49:43', b'0', 1), (10, 1, 3, '373', 'W202312122051121', '支付', -385145, 53440500, '247', '2023-12-12 20:51:12', '247', '2023-12-12 20:51:12', b'0', 1), (11, 1, 3, '375', 'W202312160001251', '支付', -206, 53440294, '247', '2023-12-16 00:01:26', '247', '2023-12-16 00:01:26', b'0', 1), (12, 1, 1, '10', 'W202312182308291', '充值', 11, 53440305, NULL, '2023-12-18 23:08:29', NULL, '2023-12-18 23:08:29', b'0', 1), (13, 1, 1, '11', 'W202312182309441', '充值', 120, 53440425, NULL, '2023-12-18 23:09:44', NULL, '2023-12-18 23:09:44', b'0', 1), (14, 1, 1, '12', 'W202312182311511', '充值', 11, 53440436, NULL, '2023-12-18 23:11:51', NULL, '2023-12-18 23:11:51', b'0', 1), (15, 18, 1, '15', 'W202407312339531', '充值', 120, 120, NULL, '2024-07-31 23:39:54', NULL, '2024-07-31 23:39:54', b'0', 1), (16, 18, 1, '16', 'W202407312343371', '充值', 120, 240, NULL, '2024-07-31 23:43:37', NULL, '2024-07-31 23:43:37', b'0', 1), (17, 18, 1, '17', 'W202407312345171', '充值', 120, 360, NULL, '2024-07-31 23:45:17', NULL, '2024-07-31 23:45:17', b'0', 1), (18, 18, 1, '18', 'W202408011247011', '充值', 120, 480, NULL, '2024-08-01 12:47:01', NULL, '2024-08-01 12:47:01', b'0', 1), (19, 18, 1, '19', 'W202408011250141', '充值', 120, 600, NULL, '2024-08-01 12:50:14', NULL, '2024-08-01 12:50:14', b'0', 1), (20, 18, 1, '21', 'W202408011256251', '充值', 12300, 12900, NULL, '2024-08-01 12:56:25', NULL, '2024-08-01 12:56:25', b'0', 1), (21, 18, 1, '22', 'W202408011257001', '充值', 12300, 25200, NULL, '2024-08-01 12:57:01', NULL, '2024-08-01 12:57:01', b'0', 1), (22, 18, 1, '23', 'W202408011257211', '充值', 120, 25320, NULL, '2024-08-01 12:57:21', NULL, '2024-08-01 12:57:21', b'0', 1), (23, 18, 1, '24', 'W202408011259431', '充值', 120, 25440, NULL, '2024-08-01 12:59:44', NULL, '2024-08-01 12:59:44', b'0', 1), (24, 18, 1, '26', 'W202408011302551', '充值', 32100, 57540, NULL, '2024-08-01 13:02:55', NULL, '2024-08-01 13:02:55', b'0', 1), (25, 18, 1, '27', 'W202408011305181', '充值', 100, 57640, NULL, '2024-08-01 13:05:18', NULL, '2024-08-01 13:05:18', b'0', 1), (26, 18, 1, '28', 'W202408011305541', '充值', 120, 57760, NULL, '2024-08-01 13:05:55', NULL, '2024-08-01 13:05:55', b'0', 1), (27, 18, 1, '29', 'W202408011306351', '充值', 22200, 79960, NULL, '2024-08-01 13:06:36', NULL, '2024-08-01 13:06:36', b'0', 1), (28, 18, 1, '30', 'W202408011307501', '充值', 3213100, 3293060, NULL, '2024-08-01 13:07:50', NULL, '2024-08-01 13:07:50', b'0', 1), (29, 1, 1, '33', 'W202409181912491', '充值', 120, 53440556, NULL, '2024-09-18 19:12:49', NULL, '2024-09-18 19:12:49', b'0', 1), (30, 1, 1, '34', 'W202409181923081', '充值', 120, 53440676, NULL, '2024-09-18 19:23:08', NULL, '2024-09-18 19:23:08', b'0', 1), (31, 1, 3, '477', 'W202409231344171', '支付', -7300, 53433376, '247', '2024-09-23 13:44:18', '247', '2024-09-23 13:44:18', b'0', 1), (32, 1, 1, '35', 'W202409240933571', '充值', 11, 53433387, NULL, '2024-09-24 09:33:58', NULL, '2024-09-24 09:33:58', b'0', 1), (33, 1, 1, '36', 'W202409240934351', '充值', 11, 53433398, NULL, '2024-09-24 09:34:36', NULL, '2024-09-24 09:34:36', b'0', 1), (34, 1, 3, '486', 'W202409300908431', '支付', -19840, 53413558, '247', '2024-09-30 09:08:44', '247', '2024-09-30 09:08:44', b'0', 1), (35, 1, 4, '98', 'W202409300909381', '支付退款', 19840, 53433398, '1', '2024-09-30 09:09:39', '1', '2024-09-30 09:09:39', b'0', 1), (36, 1, 6, '9', 'W202411251036261', '分佣提现', 10000, 53443398, '1', '2024-11-25 10:36:26', '1', '2024-11-25 10:36:26', b'0', 1), (37, 1, 6, '8', 'W202411251036401', '分佣提现', 4000, 53447398, '1', '2024-11-25 10:36:40', '1', '2024-11-25 10:36:40', b'0', 1), (38, 1, 6, '6', 'W202411251036561', '分佣提现', 80000, 53527398, '1', '2024-11-25 10:36:56', '1', '2024-11-25 10:36:56', b'0', 1), (39, 1, 6, '5', 'W202503161108241', '分佣提现', 40000, 53567398, '1', '2025-03-16 11:08:24', '1', '2025-03-16 11:08:24', b'0', 1), (40, 1, 6, '5', 'W202503161108491', '分佣提现', 40000, 53607398, '1', '2025-03-16 11:08:50', '1', '2025-03-16 11:08:50', b'0', 1), (41, 1, 3, '491', 'W202504261924171', '支付', -3500, 53603898, '247', '2025-04-26 19:24:18', '247', '2025-04-26 19:24:18', b'0', 1), (42, 1, 4, '99', 'W202504261928021', '支付退款', 3500, 53607398, '1', '2025-04-26 19:28:02', '1', '2025-04-26 19:28:02', b'0', 1), (43, 1, 3, '494', 'W202504280000491', '支付', -3500, 53603898, '247', '2025-04-28 00:00:49', '247', '2025-04-28 00:00:49', b'0', 1), (44, 1, 3, '497', 'W202504282245581', '支付', -3500, 53600398, '247', '2025-04-28 22:45:58', '247', '2025-04-28 22:45:58', b'0', 1), (45, 1, 6, 'T202505082321011', 'W202505082321011', '转账', 1, 53600399, '1', '2025-05-08 23:21:01', '1', '2025-05-08 23:21:01', b'0', 1), (46, 1, 6, 'T202505082321201', 'W202505082321201', '转账', 1, 53600400, '1', '2025-05-08 23:21:21', '1', '2025-05-08 23:21:21', b'0', 1), (47, 1, 3, '526', 'W202505082329051', '支付', -3500, 53596900, '247', '2025-05-08 23:29:06', '247', '2025-05-08 23:29:06', b'0', 1), (48, 1, 6, 'T202505092021201', 'W202505092021201', '转账', 1, 53596901, '1', '2025-05-09 20:21:20', '1', '2025-05-09 20:21:20', b'0', 1), (49, 1, 6, 'T202505092021551', 'W202505092021551', '转账', 1, 53596902, '1', '2025-05-09 20:21:55', '1', '2025-05-09 20:21:55', b'0', 1), (50, 1, 6, 'T202505092025561', 'W202505092025561', '转账', 1, 53596903, '1', '2025-05-09 20:25:56', '1', '2025-05-09 20:25:56', b'0', 1), (51, 1, 6, 'T202505092026271', 'W202505092026271', '转账', 1, 53596904, '1', '2025-05-09 20:26:28', '1', '2025-05-09 20:26:28', b'0', 1), (52, 1, 6, 'T202505092027501', 'W202505092027501', '转账', 1, 53596905, '1', '2025-05-09 20:27:50', '1', '2025-05-09 20:27:50', b'0', 1), (53, 1, 6, 'T202505092142231', 'W202505092142231', '转账', 1, 53596906, '1', '2025-05-09 21:42:23', '1', '2025-05-09 21:42:23', b'0', 1), (54, 1, 6, 'T202505101003511', 'W202505101003511', '转账', 100, 53597006, '1', '2025-05-10 10:03:51', '1', '2025-05-10 10:03:51', b'0', 1), (55, 1, 3, '527', 'W202505101352071', '支付', -3500, 53593506, '247', '2025-05-10 13:52:07', '247', '2025-05-10 13:52:07', b'0', 1), (56, 1, 4, '100', 'W202505101352311', '支付退款', 3500, 53597006, '1', '2025-05-10 13:52:31', '1', '2025-05-10 13:52:31', b'0', 1), (57, 1, 3, '528', 'W202505101353451', '支付', -3500, 53593506, '247', '2025-05-10 13:53:45', '247', '2025-05-10 13:53:45', b'0', 1), (58, 1, 4, '101', 'W202505101354181', '支付退款', 3500, 53597006, '1', '2025-05-10 13:54:19', '1', '2025-05-10 13:54:19', b'0', 1), (59, 1, 6, 'T202505101558111', 'W202505101558111', '转账', 1, 53597007, '1', '2025-05-10 15:58:11', '1', '2025-05-10 15:58:11', b'0', 1), (60, 1, 6, 'T202505101600231', 'W202505101600231', '转账', 1, 53597008, '1', '2025-05-10 16:00:23', '1', '2025-05-10 16:00:23', b'0', 1), (61, 1, 3, '540', 'W202505101609421', '支付', -3500, 53593508, '247', '2025-05-10 16:09:42', '247', '2025-05-10 16:09:42', b'0', 1), (62, 1, 4, '113', 'W202505101610201', '支付退款', 3500, 53597008, '1', '2025-05-10 16:10:20', '1', '2025-05-10 16:10:20', b'0', 1), (63, 1, 3, '541', 'W202505101616461', '支付', -3500, 53593508, '247', '2025-05-10 16:16:47', '247', '2025-05-10 16:16:47', b'0', 1), (64, 1, 4, '114', 'W202505101617011', '支付退款', 3500, 53597008, '1', '2025-05-10 16:17:02', '1', '2025-05-10 16:17:02', b'0', 1), (65, 1, 3, '545', 'W202505101639371', '支付', -3500, 53593508, '247', '2025-05-10 16:39:37', '247', '2025-05-10 16:39:37', b'0', 1), (66, 1, 4, '116', 'W202505101640241', '支付退款', 3500, 53597008, '1', '2025-05-10 16:40:24', '1', '2025-05-10 16:40:24', b'0', 1), (67, 1, 6, 'T202505111730161', 'W202505111730161', '转账', 1, 53597009, '1', '2025-05-11 17:30:17', '1', '2025-05-11 17:30:17', b'0', 1); COMMIT; -DROP TABLE IF EXISTS pay_mch_app; -CREATE TABLE `pay_mch_app` ( - `app_id` varchar(64) NOT NULL COMMENT '应用ID', - `app_name` varchar(64) NOT NULL DEFAULT '' COMMENT '应用名称', - `mch_no` VARCHAR(64) NOT NULL COMMENT '商户号', - `state` TINYINT(6) NOT NULL DEFAULT 1 COMMENT '应用状态: 0-停用, 1-正常', - `app_secret` VARCHAR(128) NOT NULL COMMENT '应用私钥', - `remark` varchar(128) DEFAULT NULL COMMENT '备注', - `created_uid` BIGINT(20) COMMENT '创建者用户ID', - `created_by` VARCHAR(64) COMMENT '创建者姓名', - `created_at` TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间', - `updated_at` TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间', - PRIMARY KEY (`app_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商户应用表'; + +DROP TABLE IF EXISTS mch_service_regist; +CREATE TABLE `mch_service_regist` ( + `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id', + `app_id` varchar(64) NOT NULL COMMENT '应用ID', + `app_name` varchar(64) NOT NULL DEFAULT '' COMMENT '应用名称', + `channel_id` varchar(64) NOT NULL DEFAULT '' COMMENT '渠道编号', + `mch_no` VARCHAR(64) NOT NULL COMMENT '商户号', + `mch_name` VARCHAR(64) NOT NULL COMMENT '商户名称', + `state` TINYINT(6) NOT NULL DEFAULT 1 COMMENT '应用状态: 0-停用, 1-正常', + `app_pub_key` TEXT NOT NULL COMMENT '应用公钥', + `app_secret` TEXT NOT NULL COMMENT '应用私钥', + `remark` varchar(128) DEFAULT NULL COMMENT '备注', + `creator` varchar(64) default '' null comment '创建者', + `create_time` datetime default CURRENT_TIMESTAMP not null comment '创建时间', + `updater` varchar(64) default '' null comment '更新者', + `update_time` datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + `deleted` bit default b'0' not null comment '是否删除', + `tenant_id` bigint default 0 not null comment '租户编号', + PRIMARY KEY (`id`), + UNIQUE (`app_id`,`channel_id`,`mch_no`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商户服务注册表'; + +DROP TABLE IF EXISTS huifu_mcc; +CREATE TABLE `huifu_mcc` ( + `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT 'id', + `major_category` varchar(64) NOT NULL COMMENT '大类名称', + `sub_category` varchar(64) NOT NULL COMMENT '小类名称', + `category` varchar(64) NOT NULL COMMENT '名称', + `code` VARCHAR(64) NOT NULL COMMENT '编码', + `creator` varchar(64) default '' null comment '创建者', + `create_time` datetime default CURRENT_TIMESTAMP not null comment '创建时间', + `updater` varchar(64) default '' null comment '更新者', + `update_time` datetime default CURRENT_TIMESTAMP not null on update CURRENT_TIMESTAMP comment '更新时间', + `deleted` bit default b'0' not null comment '是否删除', + PRIMARY KEY (`id`), + UNIQUE (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='汇付MCC表'; SET FOREIGN_KEY_CHECKS = 1; From b984f7f649fc56aea8acf5625168cdd32382cd9c Mon Sep 17 00:00:00 2001 From: duanyuqing <1697807853@qq.com> Date: Thu, 31 Jul 2025 13:57:49 +0800 Subject: [PATCH 3/3] =?UTF-8?q?Date:2025-07-31=20author:Duanyuqing=20comme?= =?UTF-8?q?nt:=E6=B1=87=E4=BB=98=E5=A4=A9=E4=B8=8B=E5=9F=BA=E6=9C=AC?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/config/HuifuClientConfig.java | 15 +- .../client/impl/huifu/HuifuPayClient.java | 571 +----------------- .../src/main/resources/application-dev.yaml | 8 + .../src/main/resources/application-local.yaml | 10 +- 4 files changed, 26 insertions(+), 578 deletions(-) diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/config/HuifuClientConfig.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/config/HuifuClientConfig.java index 7d37a81..027c316 100644 --- a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/config/HuifuClientConfig.java +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/config/HuifuClientConfig.java @@ -30,31 +30,30 @@ public class HuifuClientConfig implements PayClientConfig { */ private String prodMode; - //产品编号 - @Value("${huifu.procutId}") + @Value("${hake.huifu.procutId}") private String procutId; //系统编号 - @Value("${huifu.sysId}") + @Value("${hake.huifu.sysId}") private String sysId; //私钥 - @Value("${huifu.rsaPrivateKey}") + @Value("${hake.huifu.rsaPrivateKey}") private String rsaPrivateKey; //公钥 - @Value("${huifu.rsaPublicKey}") + @Value("${hake.huifu.rsaPublicKey}") private String rsaPublicKey; //自定义超时时间 - @Value("${huifu.customConnectTimeout}") + @Value("${hake.huifu.customConnectTimeout}") private String customSocketTimeout; - @Value("${huifu.customConnectTimeout}") + @Value("${hake.huifu.customConnectTimeout}") private String customConnectTimeout; - @Value("${huifu.customConnectionRequestTimeout}") + @Value("${hake.huifu.customConnectionRequestTimeout}") private String customConnectionRequestTimeout; diff --git a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/core/client/impl/huifu/HuifuPayClient.java b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/core/client/impl/huifu/HuifuPayClient.java index 2586a7b..5abfa8e 100644 --- a/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/core/client/impl/huifu/HuifuPayClient.java +++ b/hake-module-pay/hake-module-pay-server/src/main/java/cn/iocoder/hake/module/pay/framework/pay/core/client/impl/huifu/HuifuPayClient.java @@ -1,56 +1,19 @@ package cn.iocoder.hake.module.pay.framework.pay.core.client.impl.huifu; -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.codec.Base64; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.date.LocalDateTimeUtil; -import cn.hutool.core.date.TemporalAccessorUtil; -import cn.hutool.core.util.StrUtil; -import cn.iocoder.hake.framework.common.util.io.FileUtils; -import cn.iocoder.hake.framework.common.util.json.JsonUtils; -import cn.iocoder.hake.framework.common.util.object.ObjectUtils; -import cn.iocoder.hake.module.pay.enums.order.PayOrderStatusEnum; import cn.iocoder.hake.module.pay.framework.pay.config.HuifuClientConfig; -import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.order.PayOrderRespDTO; -import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; -import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.refund.PayRefundRespDTO; -import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; -import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.transfer.PayTransferRespDTO; -import cn.iocoder.hake.module.pay.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO; -import cn.iocoder.hake.module.pay.framework.pay.core.client.impl.AbstractPayClient; -import com.github.binarywang.wxpay.bean.notify.*; -import com.github.binarywang.wxpay.bean.request.*; -import com.github.binarywang.wxpay.bean.result.*; -import com.github.binarywang.wxpay.bean.transfer.TransferBillsGetResult; -import com.github.binarywang.wxpay.bean.transfer.TransferBillsNotifyResult; -import com.github.binarywang.wxpay.bean.transfer.TransferBillsRequest; -import com.github.binarywang.wxpay.bean.transfer.TransferBillsResult; -import com.github.binarywang.wxpay.config.WxPayConfig; -import com.github.binarywang.wxpay.exception.WxPayException; -import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; import lombok.extern.slf4j.Slf4j; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.Map; -import java.util.Objects; - -import static cn.hutool.core.date.DatePattern.*; -import static cn.iocoder.hake.module.pay.framework.pay.core.client.impl.weixin.WxPayClientConfig.API_VERSION_V2; -import static cn.iocoder.hake.module.pay.framework.pay.core.client.impl.weixin.WxPayClientConfig.API_VERSION_V3; - /** * 汇付天下支付抽象类 * * @author duanyuqing */ @Slf4j -public abstract class HuifuPayClient extends AbstractPayClient { +public abstract class HuifuPayClient { - protected TradePaymentMicropayRequest client; public HuifuPayClient(Long channelId, String channelCode, HuifuClientConfig config) { - super(channelId, channelCode, config); + } /** @@ -60,538 +23,8 @@ public abstract class HuifuPayClient extends AbstractPayClient params, String body, Map headers) throws WxPayException { - switch (config.getApiVersion()) { - case API_VERSION_V2: - return doParseOrderNotifyV2(body); - case API_VERSION_V3: - return doParseOrderNotifyV3(body, headers); - default: - throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); - } - } - - private PayOrderRespDTO doParseOrderNotifyV2(String body) throws WxPayException { - // 1. 解析回调 - WxPayOrderNotifyResult response = client.parseOrderNotifyResult(body); - // 2. 构建结果 - // V2 微信支付的回调,只有 SUCCESS 支付成功、CLOSED 支付失败两种情况,无需像支付宝一样解析的比较复杂 - Integer status = Objects.equals(response.getResultCode(), "SUCCESS") ? - PayOrderStatusEnum.SUCCESS.getStatus() : PayOrderStatusEnum.CLOSED.getStatus(); - return PayOrderRespDTO.of(status, response.getTransactionId(), response.getOpenid(), parseDateV2(response.getTimeEnd()), - response.getOutTradeNo(), body); - } - - private PayOrderRespDTO doParseOrderNotifyV3(String body, Map headers) throws WxPayException { - // 1. 解析回调 - SignatureHeader signatureHeader = getRequestHeader(headers); - WxPayNotifyV3Result response = client.parseOrderNotifyV3Result(body, signatureHeader); - WxPayNotifyV3Result.DecryptNotifyResult result = response.getResult(); - // 2. 构建结果 - Integer status = parseStatus(result.getTradeState()); - String openid = result.getPayer() != null ? result.getPayer().getOpenid() : null; - return PayOrderRespDTO.of(status, result.getTransactionId(), openid, parseDateV3(result.getSuccessTime()), - result.getOutTradeNo(), body); - } - - @Override - protected PayOrderRespDTO doGetOrder(String outTradeNo) throws Throwable { - try { - switch (config.getApiVersion()) { - case API_VERSION_V2: - return doGetOrderV2(outTradeNo); - case API_VERSION_V3: - return doGetOrderV3(outTradeNo); - default: - throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); - } - } catch (WxPayException e) { - if (ObjectUtils.equalsAny(e.getErrCode(), "ORDERNOTEXIST", "ORDER_NOT_EXIST")) { - String errorCode = getErrorCode(e); - String errorMessage = getErrorMessage(e); - return PayOrderRespDTO.closedOf(errorCode, errorMessage, - outTradeNo, e.getXmlString()); - } - throw e; - } - } - - private PayOrderRespDTO doGetOrderV2(String outTradeNo) throws WxPayException { - // 构建 WxPayUnifiedOrderRequest 对象 - WxPayOrderQueryRequest request = WxPayOrderQueryRequest.newBuilder() - .outTradeNo(outTradeNo).build(); - // 执行请求 - WxPayOrderQueryResult response = client.queryOrder(request); - - // 转换结果 - Integer status = parseStatus(response.getTradeState()); - return PayOrderRespDTO.of(status, response.getTransactionId(), response.getOpenid(), parseDateV2(response.getTimeEnd()), - outTradeNo, response); - } - - private PayOrderRespDTO doGetOrderV3(String outTradeNo) throws WxPayException { - fixV3HttpClientConnectionPoolShutDown(); - // 构建 WxPayUnifiedOrderRequest 对象 - WxPayOrderQueryV3Request request = new WxPayOrderQueryV3Request() - .setOutTradeNo(outTradeNo); - // 执行请求 - WxPayOrderQueryV3Result response = client.queryOrderV3(request); - - // 转换结果 - Integer status = parseStatus(response.getTradeState()); - String openid = response.getPayer() != null ? response.getPayer().getOpenid() : null; - return PayOrderRespDTO.of(status, response.getTransactionId(), openid, parseDateV3(response.getSuccessTime()), - outTradeNo, response); - } - - private static Integer parseStatus(String tradeState) { - switch (tradeState) { - case "NOTPAY": - case "USERPAYING": // 支付中,等待用户输入密码(条码支付独有) - return PayOrderStatusEnum.WAITING.getStatus(); - case "SUCCESS": - return PayOrderStatusEnum.SUCCESS.getStatus(); - case "REFUND": - return PayOrderStatusEnum.REFUND.getStatus(); - case "CLOSED": - case "REVOKED": // 已撤销(刷卡支付独有) - case "PAYERROR": // 支付失败(其它原因,如银行返回失败) - return PayOrderStatusEnum.CLOSED.getStatus(); - default: - throw new IllegalArgumentException(StrUtil.format("未知的支付状态({})", tradeState)); - } - } - - // ============ 退款相关 ========== - - @Override - protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable { - try { - switch (config.getApiVersion()) { - case API_VERSION_V2: - return doUnifiedRefundV2(reqDTO); - case API_VERSION_V3: - return doUnifiedRefundV3(reqDTO); - default: - throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); - } - } catch (WxPayException e) { - String errorCode = getErrorCode(e); - String errorMessage = getErrorMessage(e); - return PayRefundRespDTO.failureOf(errorCode, errorMessage, - reqDTO.getOutRefundNo(), e.getXmlString()); - } - } - - private PayRefundRespDTO doUnifiedRefundV2(PayRefundUnifiedReqDTO reqDTO) throws Throwable { - // 1. 构建 WxPayRefundRequest 请求 - WxPayRefundRequest request = new WxPayRefundRequest() - .setOutTradeNo(reqDTO.getOutTradeNo()) - .setOutRefundNo(reqDTO.getOutRefundNo()) - .setRefundFee(reqDTO.getRefundPrice()) - .setRefundDesc(reqDTO.getReason()) - .setTotalFee(reqDTO.getPayPrice()) - .setNotifyUrl(reqDTO.getNotifyUrl()); - // 2.1 执行请求 - WxPayRefundResult response = client.refundV2(request); - // 2.2 创建返回结果 - if (Objects.equals("SUCCESS", response.getResultCode())) { // V2 情况下,不直接返回退款成功,而是等待异步通知 - return PayRefundRespDTO.waitingOf(response.getRefundId(), - reqDTO.getOutRefundNo(), response); - } - return PayRefundRespDTO.failureOf(reqDTO.getOutRefundNo(), response); - } - - private PayRefundRespDTO doUnifiedRefundV3(PayRefundUnifiedReqDTO reqDTO) throws Throwable { - fixV3HttpClientConnectionPoolShutDown(); - // 1. 构建 WxPayRefundRequest 请求 - WxPayRefundV3Request request = new WxPayRefundV3Request() - .setOutTradeNo(reqDTO.getOutTradeNo()) - .setOutRefundNo(reqDTO.getOutRefundNo()) - .setAmount(new WxPayRefundV3Request.Amount().setRefund(reqDTO.getRefundPrice()) - .setTotal(reqDTO.getPayPrice()).setCurrency("CNY")) - .setReason(reqDTO.getReason()) - .setNotifyUrl(reqDTO.getNotifyUrl()); - // 2.1 执行请求 - WxPayRefundV3Result response = client.refundV3(request); - // 2.2 创建返回结果 - if (Objects.equals("SUCCESS", response.getStatus())) { - return PayRefundRespDTO.successOf(response.getRefundId(), parseDateV3(response.getSuccessTime()), - reqDTO.getOutRefundNo(), response); - } - if (Objects.equals("PROCESSING", response.getStatus())) { - return PayRefundRespDTO.waitingOf(response.getRefundId(), - reqDTO.getOutRefundNo(), response); - } - return PayRefundRespDTO.failureOf(reqDTO.getOutRefundNo(), response); - } - - @Override - public PayRefundRespDTO doParseRefundNotify(Map params, String body, Map headers) throws WxPayException { - switch (config.getApiVersion()) { - case API_VERSION_V2: - return doParseRefundNotifyV2(body); - case API_VERSION_V3: - return parseRefundNotifyV3(body, headers); - default: - throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); - } - } - - private PayRefundRespDTO doParseRefundNotifyV2(String body) throws WxPayException { - // 1. 解析回调 - WxPayRefundNotifyResult response = client.parseRefundNotifyResult(body); - WxPayRefundNotifyResult.ReqInfo result = response.getReqInfo(); - // 2. 构建结果 - if (Objects.equals("SUCCESS", result.getRefundStatus())) { - return PayRefundRespDTO.successOf(result.getRefundId(), parseDateV2B(result.getSuccessTime()), - result.getOutRefundNo(), response); - } - return PayRefundRespDTO.failureOf(result.getOutRefundNo(), response); - } - - private PayRefundRespDTO parseRefundNotifyV3(String body, Map headers) throws WxPayException { - // 1. 解析回调 - SignatureHeader signatureHeader = getRequestHeader(headers); - WxPayRefundNotifyV3Result response = client.parseRefundNotifyV3Result(body, signatureHeader); - WxPayRefundNotifyV3Result.DecryptNotifyResult result = response.getResult(); - // 2. 构建结果 - if (Objects.equals("SUCCESS", result.getRefundStatus())) { - return PayRefundRespDTO.successOf(result.getRefundId(), parseDateV3(result.getSuccessTime()), - result.getOutRefundNo(), response); - } - return PayRefundRespDTO.failureOf(result.getOutRefundNo(), response); - } - - @Override - protected PayRefundRespDTO doGetRefund(String outTradeNo, String outRefundNo) throws WxPayException { - try { - switch (config.getApiVersion()) { - case API_VERSION_V2: - return doGetRefundV2(outTradeNo, outRefundNo); - case API_VERSION_V3: - return doGetRefundV3(outTradeNo, outRefundNo); - default: - throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); - } - } catch (WxPayException e) { - if (ObjectUtils.equalsAny(e.getErrCode(), "REFUNDNOTEXIST", "RESOURCE_NOT_EXISTS")) { - String errorCode = getErrorCode(e); - String errorMessage = getErrorMessage(e); - return PayRefundRespDTO.failureOf(errorCode, errorMessage, - outRefundNo, e.getXmlString()); - } - throw e; - } - } - - private PayRefundRespDTO doGetRefundV2(String outTradeNo, String outRefundNo) throws WxPayException { - // 1. 构建 WxPayRefundRequest 请求 - WxPayRefundQueryRequest request = WxPayRefundQueryRequest.newBuilder() - .outTradeNo(outTradeNo) - .outRefundNo(outRefundNo) - .build(); - // 2.1 执行请求 - WxPayRefundQueryResult response = client.refundQuery(request); - // 2.2 创建返回结果 - if (!Objects.equals("SUCCESS", response.getResultCode())) { - return PayRefundRespDTO.waitingOf(null, - outRefundNo, response); - } - WxPayRefundQueryResult.RefundRecord refund = CollUtil.findOne(response.getRefundRecords(), - record -> record.getOutRefundNo().equals(outRefundNo)); - if (refund == null) { - return PayRefundRespDTO.failureOf(outRefundNo, response); - } - switch (refund.getRefundStatus()) { - case "SUCCESS": - return PayRefundRespDTO.successOf(refund.getRefundId(), parseDateV2B(refund.getRefundSuccessTime()), - outRefundNo, response); - case "PROCESSING": - return PayRefundRespDTO.waitingOf(refund.getRefundId(), - outRefundNo, response); - case "CHANGE": // 退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,资金回流到商户的现金帐号,需要商户人工干预,通过线下或者财付通转账的方式进行退款 - case "FAIL": - return PayRefundRespDTO.failureOf(outRefundNo, response); - default: - throw new IllegalArgumentException(String.format("未知的退款状态(%s)", refund.getRefundStatus())); - } - } - - private PayRefundRespDTO doGetRefundV3(String outTradeNo, String outRefundNo) throws WxPayException { - fixV3HttpClientConnectionPoolShutDown(); - // 1. 构建 WxPayRefundRequest 请求 - WxPayRefundQueryV3Request request = new WxPayRefundQueryV3Request(); - request.setOutRefundNo(outRefundNo); - // 2.1 执行请求 - WxPayRefundQueryV3Result response = client.refundQueryV3(request); - // 2.2 创建返回结果 - switch (response.getStatus()) { - case "SUCCESS": - return PayRefundRespDTO.successOf(response.getRefundId(), parseDateV3(response.getSuccessTime()), - outRefundNo, response); - case "PROCESSING": - return PayRefundRespDTO.waitingOf(response.getRefundId(), - outRefundNo, response); - case "ABNORMAL": // 退款异常 - case "CLOSED": - return PayRefundRespDTO.failureOf(outRefundNo, response); - default: - throw new IllegalArgumentException(String.format("未知的退款状态(%s)", response.getStatus())); - } - } - - @Override - protected PayTransferRespDTO doUnifiedTransfer(PayTransferUnifiedReqDTO reqDTO) throws WxPayException { - fixV3HttpClientConnectionPoolShutDown(); - // 1. 构建 TransferBillsRequest 请求 - TransferBillsRequest request = TransferBillsRequest.newBuilder() - .appid(this.config.getAppId()) - .outBillNo(reqDTO.getOutTransferNo()) - .transferAmount(reqDTO.getPrice()) - .transferRemark(reqDTO.getSubject()) - .transferSceneId(reqDTO.getChannelExtras().get("sceneId")) - .openid(reqDTO.getUserAccount()) - .userName(reqDTO.getUserName()) - .transferSceneReportInfos(JsonUtils.parseArray(reqDTO.getChannelExtras().get("sceneReportInfos"), - TransferBillsRequest.TransferSceneReportInfo.class)) - .notifyUrl(reqDTO.getNotifyUrl()) - .build(); - // 特殊:微信转账,必须 0.3 元起,才允许传入姓名 - if (reqDTO.getPrice() < 30) { - request.setUserName(null); - } - - // 2.1 执行请求 - try { - TransferBillsResult response = client.getTransferService().transferBills(request); - - // 2.2 创建返回结果 - String state = response.getState(); - if (ObjectUtils.equalsAny(state, "ACCEPTED", "PROCESSING", "WAIT_USER_CONFIRM", "TRANSFERING")) { - return PayTransferRespDTO.processingOf(response.getTransferBillNo(), response.getOutBillNo(), response) - .setChannelPackageInfo(response.getPackageInfo()); // 一般情况下,只有 WAIT_USER_CONFIRM 会有! - } - if (Objects.equals("SUCCESS", state)) { - return PayTransferRespDTO.successOf(response.getTransferBillNo(), parseDateV3(response.getCreateTime()), - response.getOutBillNo(), response); - } - return PayTransferRespDTO.closedOf(state, response.getFailReason(), - response.getOutBillNo(), response); - } catch (WxPayException e) { - log.error("[doUnifiedTransfer][转账({}) 发起微信支付异常", reqDTO, e); - String errorCode = getErrorCode(e); - String errorMessage = getErrorMessage(e); - return PayTransferRespDTO.closedOf(errorCode, errorMessage, - reqDTO.getOutTransferNo(), e.getXmlString()); - } - } - - @Override - protected PayTransferRespDTO doGetTransfer(String outTradeNo) throws WxPayException { - fixV3HttpClientConnectionPoolShutDown(); - // 1. 执行请求 - TransferBillsGetResult response = client.getTransferService().getBillsByOutBillNo(outTradeNo); - - // 2. 创建返回结果 - String state = response.getState(); - if (ObjectUtils.equalsAny(state, "ACCEPTED", "PROCESSING", "WAIT_USER_CONFIRM", "TRANSFERING")) { - return PayTransferRespDTO.processingOf(response.getTransferBillNo(), response.getOutBillNo(), response); - } - if (Objects.equals("SUCCESS", state)) { - return PayTransferRespDTO.successOf(response.getTransferBillNo(), parseDateV3(response.getUpdateTime()), - response.getOutBillNo(), response); - } - return PayTransferRespDTO.closedOf(state, response.getFailReason(), - response.getOutBillNo(), response); - } - - @Override - public PayTransferRespDTO doParseTransferNotify(Map params, String body, Map headers) throws WxPayException { - switch (config.getApiVersion()) { - case API_VERSION_V3: - return parseTransferNotifyV3(body, headers); - case API_VERSION_V2: - throw new UnsupportedOperationException("V2 版本暂不支持,建议使用 V3 版本"); - default: - throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); - } - } - - private PayTransferRespDTO parseTransferNotifyV3(String body, Map headers) throws WxPayException { - // 1. 解析回调 - SignatureHeader signatureHeader = getRequestHeader(headers); - TransferBillsNotifyResult response = client.getTransferService().parseTransferBillsNotifyResult(body, signatureHeader); - TransferBillsNotifyResult.DecryptNotifyResult result = response.getResult(); - - // 2. 创建返回结果 - String state = result.getState(); - if (ObjectUtils.equalsAny(state, "ACCEPTED", "PROCESSING", "WAIT_USER_CONFIRM", "TRANSFERING")) { - return PayTransferRespDTO.processingOf(result.getTransferBillNo(), result.getOutBillNo(), response); - } - if (Objects.equals("SUCCESS", state)) { - return PayTransferRespDTO.successOf(result.getTransferBillNo(), parseDateV3(result.getUpdateTime()), - result.getOutBillNo(), response); - } - return PayTransferRespDTO.closedOf(state, result.getFailReason(), - result.getOutBillNo(), response); - } - - // ========== 各种工具方法 ========== - - /** - * 组装请求头重的签名信息 - * - * @see 官方示例 - */ - private SignatureHeader getRequestHeader(Map headers) { - return SignatureHeader.builder() - .signature(headers.get("wechatpay-signature")) - .nonce(headers.get("wechatpay-nonce")) - .serial(headers.get("wechatpay-serial")) - .timeStamp(headers.get("wechatpay-timestamp")) - .build(); - } - - // TODO @哈客:可能是 wxjava 的 bug:https://github.com/binarywang/WxJava/issues/1557 - private void fixV3HttpClientConnectionPoolShutDown() { - client.getConfig().setApiV3HttpClient(null); - } - static String formatDateV2(LocalDateTime time) { - return TemporalAccessorUtil.format(time.atZone(ZoneId.systemDefault()), PURE_DATETIME_PATTERN); } - static LocalDateTime parseDateV2(String time) { - return LocalDateTimeUtil.parse(time, PURE_DATETIME_PATTERN); - } - - static LocalDateTime parseDateV2B(String time) { - return LocalDateTimeUtil.parse(time, NORM_DATETIME_PATTERN); - } - - static String formatDateV3(LocalDateTime time) { - return TemporalAccessorUtil.format(time.atZone(ZoneId.systemDefault()), UTC_WITH_XXX_OFFSET_PATTERN); - } - - static LocalDateTime parseDateV3(String time) { - return LocalDateTimeUtil.parse(time, UTC_WITH_XXX_OFFSET_PATTERN); - } - - static String getErrorCode(WxPayException e) { - if (StrUtil.isNotEmpty(e.getErrCode())) { - return e.getErrCode(); - } - if (StrUtil.isNotEmpty(e.getCustomErrorMsg())) { - return "CUSTOM_ERROR"; - } - return e.getReturnCode(); - } - - static String getErrorMessage(WxPayException e) { - if (StrUtil.isNotEmpty(e.getErrCode())) { - return e.getErrCodeDes(); - } - if (StrUtil.isNotEmpty(e.getCustomErrorMsg())) { - return e.getCustomErrorMsg(); - } - return e.getReturnMsg(); - } } diff --git a/hake-module-pay/hake-module-pay-server/src/main/resources/application-dev.yaml b/hake-module-pay/hake-module-pay-server/src/main/resources/application-dev.yaml index 4087431..09891fa 100644 --- a/hake-module-pay/hake-module-pay-server/src/main/resources/application-dev.yaml +++ b/hake-module-pay/hake-module-pay-server/src/main/resources/application-dev.yaml @@ -116,3 +116,11 @@ hake: refund-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址 transfer-notify-url: http://yunai.natapp1.cc/admin-api/pay/notify/transfer # 支付渠道的【转账】回调地址 demo: false # 关闭演示模式 + huifu: + procutId: PAYUN + sysId: 6666000162367855 + rsaPrivateKey: MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCOKQUkTWNZ1lug2yLa+6ESp+XDBN5roQMLQVZPbn7T5Jwo4yK3R8zNjSB8KSLaG23Dkr3xISf5HvFVOmoEtpQrCqzbDrU7hmR00ita/wQIRluh2RAT+RsUHDwCeXPOk3jkugKQtXvhQExxn61LIXAArB07MMkZgl5/HXcEQcLzukpSnQ55WIA1+HFPL20x8hHYEIILtI3zibFJtAoig0VeZPVUDTKbOEILkRriSJ7WQjMlsKw1w/TaFAXrCnQO7GlY8pVxkzW46WDt5xT9m26KNiXcQeS5Je215pgBnFidMAOQLxIlyDyh9/PTe2r0ygoGH52J5HyKHYenLlhv/DyBAgMBAAECggEBAIaxGuwQXsepr9syhU3SCATzC2DBZjO3tHifiTVtTcFZ4xNiUWwyHTvMMTEykJDyWAdrK4ghkAwbYzELTZP1oWE+lhRfVRt29AszblyjLqDgeMVaMj+aUCu3rKvzguQBGhQsoW2WZi8/iq5FSh3bKpGYgYGpcYA342yw8CkaXaoqN8jzH3ohEv9KX3cHIfCAeEg0zNH4+pXDhOjwXc/XIjQ5CoIduYey2JsHt/MyTR/5SrguMcr0VZLqYqJDy5Dd81kL46YlBACq5p1u7effgmVqb64MPGVaVU0FdUFv3CX4cLtEEEG63X1aijxPnKGyy5XEM+k/DFbw25xBBM1UJKECgYEAxCt21DWtS+1g6VVJA+qbpBMSzfA/xblvXyz5owCMmopte3WnzLPlkHdgTxlZSeRHursOPFd3v8hOmovFNw+OBS8Fhdy0b7tLwmb55CEOX7MsLJ5pqsUE+5IjGAVGJNHRlxTtDDXA8fILpeRJouAtAcrheyjmqWz8tsQ1okgWL8UCgYEAuYSZzcwKNHjBwOoMsxxmuh7hM+CXiO5TXnhuFkrVOR23147spKvUaV97z2SHEtbj13k70BTCVMCAyQOrMgL/ro0XHl2dK8zKPSuZvYC23r+AsE69edeJz2uYjDOxXfJJFNL4jqRDfNG/Cbk6VimkVzaeKdfnsf3MYQ5CFZ8eCY0CgYBpDsXy3FRU52oRTEVwPYLhGf3mIJZms+q7VADVlQO3+A6uIdKdxHJbLjN76R1yfzkS/f6fvlA5e3LtPZF+7Wunxwj0KcDQXcQy9qc5z6I9Cl3L/4KjnCQQ/rCguqJYMa5HdUOGWHtel7w5Octd2SUBYr/jD4KIlf+5edcnc+e96QKBgHZtO3GwSuNsIuNvhWPhQYKWq9ReDt4OpZGs9zmr06l+Wxlz14TXW+VYWsTtu3w/SXsHnTMbzWIk8RFhEiv+1hEraBKuV+LZ/FBIQQBD5nkTbqcd3L6m5QZP/TWi2hrKy/RLKPiFy78mdflTEPZn5sz1xMmZVgK9rXZXj8AVrysRAoGBAJJfMtoeNO8bj0TuvC/u+OFUsazjBziTrFRAlrVU6pUkZ+P8huKindNnQSzkH92JpdoPgPPzRsw8yFai3wgRPrExsSosELulEAZMZNnPEn7BxiTQjB7wcCSnRXAmW6g5wUjHhu1wAhGJpV1RSCVMgsfNQy6NOZizQahc6u4Qb77/ + rsaPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAik1dhiQNVn69cTq3WhhUxKKDwRQtdKbbAzRTTvkwcYH2J07iG0EmRZTqmZKTvNqGKizQbz9eNrMh7Awn5B+t8aTc+xe3amj7bngf0zk2jAwK36Hrokv5oOCAiyAWSEt9/M6gWUf0R+av5JS34XZmfDVyhcu2+3PdWBaqKlOx0HX9TphuDJDHqWP13+It5X2Iv1kkiaqcY6yjhBF8RlP1vD+Y77W4p+h9QHIAVCJGykjBDBf51pxHMrOuj1yFOpWCX4UlYQISPfdlgu+FARW38mjqV/J2QwITcseg1sb1aRvA2Bve+zdcQTAwNpUwOnqsfov+p7Vh0+VXUt1vyk0abQIDAQAB + customSocketTimeout: 20000 + customConnectTimeout: 20000 + customConnectionRequestTimeout: 20000 diff --git a/hake-module-pay/hake-module-pay-server/src/main/resources/application-local.yaml b/hake-module-pay/hake-module-pay-server/src/main/resources/application-local.yaml index d47ae82..8240f6d 100644 --- a/hake-module-pay/hake-module-pay-server/src/main/resources/application-local.yaml +++ b/hake-module-pay/hake-module-pay-server/src/main/resources/application-local.yaml @@ -138,4 +138,12 @@ hake: pay: order-notify-url: https://yutou.mynatapp.cc/admin-api/pay/notify/order # 支付渠道的【支付】回调地址 refund-notify-url: https://yutou.mynatapp.cc/admin-api/pay/notify/refund # 支付渠道的【退款】回调地址 - transfer-notify-url: https://yutou.mynatapp.cc/admin-api/pay/notify/transfer # 支付渠道的【转账】回调地址 \ No newline at end of file + transfer-notify-url: https://yutou.mynatapp.cc/admin-api/pay/notify/transfer # 支付渠道的【转账】回调地址 + huifu: + procutId: PAYUN + sysId: 6666000162367855 + rsaPrivateKey: MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCOKQUkTWNZ1lug2yLa+6ESp+XDBN5roQMLQVZPbn7T5Jwo4yK3R8zNjSB8KSLaG23Dkr3xISf5HvFVOmoEtpQrCqzbDrU7hmR00ita/wQIRluh2RAT+RsUHDwCeXPOk3jkugKQtXvhQExxn61LIXAArB07MMkZgl5/HXcEQcLzukpSnQ55WIA1+HFPL20x8hHYEIILtI3zibFJtAoig0VeZPVUDTKbOEILkRriSJ7WQjMlsKw1w/TaFAXrCnQO7GlY8pVxkzW46WDt5xT9m26KNiXcQeS5Je215pgBnFidMAOQLxIlyDyh9/PTe2r0ygoGH52J5HyKHYenLlhv/DyBAgMBAAECggEBAIaxGuwQXsepr9syhU3SCATzC2DBZjO3tHifiTVtTcFZ4xNiUWwyHTvMMTEykJDyWAdrK4ghkAwbYzELTZP1oWE+lhRfVRt29AszblyjLqDgeMVaMj+aUCu3rKvzguQBGhQsoW2WZi8/iq5FSh3bKpGYgYGpcYA342yw8CkaXaoqN8jzH3ohEv9KX3cHIfCAeEg0zNH4+pXDhOjwXc/XIjQ5CoIduYey2JsHt/MyTR/5SrguMcr0VZLqYqJDy5Dd81kL46YlBACq5p1u7effgmVqb64MPGVaVU0FdUFv3CX4cLtEEEG63X1aijxPnKGyy5XEM+k/DFbw25xBBM1UJKECgYEAxCt21DWtS+1g6VVJA+qbpBMSzfA/xblvXyz5owCMmopte3WnzLPlkHdgTxlZSeRHursOPFd3v8hOmovFNw+OBS8Fhdy0b7tLwmb55CEOX7MsLJ5pqsUE+5IjGAVGJNHRlxTtDDXA8fILpeRJouAtAcrheyjmqWz8tsQ1okgWL8UCgYEAuYSZzcwKNHjBwOoMsxxmuh7hM+CXiO5TXnhuFkrVOR23147spKvUaV97z2SHEtbj13k70BTCVMCAyQOrMgL/ro0XHl2dK8zKPSuZvYC23r+AsE69edeJz2uYjDOxXfJJFNL4jqRDfNG/Cbk6VimkVzaeKdfnsf3MYQ5CFZ8eCY0CgYBpDsXy3FRU52oRTEVwPYLhGf3mIJZms+q7VADVlQO3+A6uIdKdxHJbLjN76R1yfzkS/f6fvlA5e3LtPZF+7Wunxwj0KcDQXcQy9qc5z6I9Cl3L/4KjnCQQ/rCguqJYMa5HdUOGWHtel7w5Octd2SUBYr/jD4KIlf+5edcnc+e96QKBgHZtO3GwSuNsIuNvhWPhQYKWq9ReDt4OpZGs9zmr06l+Wxlz14TXW+VYWsTtu3w/SXsHnTMbzWIk8RFhEiv+1hEraBKuV+LZ/FBIQQBD5nkTbqcd3L6m5QZP/TWi2hrKy/RLKPiFy78mdflTEPZn5sz1xMmZVgK9rXZXj8AVrysRAoGBAJJfMtoeNO8bj0TuvC/u+OFUsazjBziTrFRAlrVU6pUkZ+P8huKindNnQSzkH92JpdoPgPPzRsw8yFai3wgRPrExsSosELulEAZMZNnPEn7BxiTQjB7wcCSnRXAmW6g5wUjHhu1wAhGJpV1RSCVMgsfNQy6NOZizQahc6u4Qb77/ + rsaPublicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAik1dhiQNVn69cTq3WhhUxKKDwRQtdKbbAzRTTvkwcYH2J07iG0EmRZTqmZKTvNqGKizQbz9eNrMh7Awn5B+t8aTc+xe3amj7bngf0zk2jAwK36Hrokv5oOCAiyAWSEt9/M6gWUf0R+av5JS34XZmfDVyhcu2+3PdWBaqKlOx0HX9TphuDJDHqWP13+It5X2Iv1kkiaqcY6yjhBF8RlP1vD+Y77W4p+h9QHIAVCJGykjBDBf51pxHMrOuj1yFOpWCX4UlYQISPfdlgu+FARW38mjqV/J2QwITcseg1sb1aRvA2Bve+zdcQTAwNpUwOnqsfov+p7Vh0+VXUt1vyk0abQIDAQAB + customSocketTimeout: 20000 + customConnectTimeout: 20000 + customConnectionRequestTimeout: 20000 \ No newline at end of file