feat: initial iShare project code

This commit is contained in:
purovps
2026-02-16 23:20:59 +08:00
parent 8c83a6fd46
commit 6f270a972e
1910 changed files with 218015 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
FROM pig4cloud/java:8-jre
MAINTAINER wangiegie@gmail.com
ENV TZ=Asia/Shanghai
ENV JAVA_OPTS="-Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom"
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /as-pay-platform
WORKDIR /as-pay-platform
EXPOSE 5010
ADD ./target/as-pay-platform.jar ./
CMD sleep 180;java $JAVA_OPTS -jar as-pay-platform.jar

View File

@@ -0,0 +1,166 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-visual</artifactId>
<version>5.2.0</version>
</parent>
<artifactId>as-pay-platform</artifactId>
<packaging>jar</packaging>
<description>支付系统</description>
<properties>
<yungouos.version>2.0.4</yungouos.version>
</properties>
<dependencies>
<!--注册中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--配置中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!--mybatis-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
</dependency>
<!--PG-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!--DM8-->
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
</dependency>
<!-- druid 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<!--common-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-data</artifactId>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-sequence</artifactId>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-extra</artifactId>
</dependency>
<!--灰度支持-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-gray</artifactId>
</dependency>
<!-- sentinel-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-sentinel</artifactId>
</dependency>
<!--feign 接口-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>as-upms-api</artifactId>
</dependency>
<!--swagger-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-swagger</artifactId>
</dependency>
<!--安全模块-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-xss</artifactId>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-security</artifactId>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-log</artifactId>
</dependency>
<!-- 支付依赖-->
<dependency>
<groupId>com.github.javen205</groupId>
<artifactId>IJPay-WxPay</artifactId>
</dependency>
<dependency>
<groupId>com.github.javen205</groupId>
<artifactId>IJPay-AliPay</artifactId>
</dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-mp</artifactId>
</dependency>
<dependency>
<groupId>com.yungouos.pay</groupId>
<artifactId>yungouos-pay-sdk</artifactId>
<version>${yungouos.version}</version>
</dependency>
<!--web 模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--undertow容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay;
import com.pig4cloud.pigx.common.feign.annotation.EnablePigxFeignClients;
import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer;
import com.pig4cloud.pigx.common.swagger.annotation.EnableOpenApi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author lengleng
* @date 2019年05月27日17:25:38
* <p>
* 支付模块
*/
@EnableOpenApi("pay")
@EnablePigxFeignClients
@EnableDiscoveryClient
@EnablePigxResourceServer
@SpringBootApplication
public class AsPayPlatformApplication {
public static void main(String[] args) {
SpringApplication.run(AsPayPlatformApplication.class, args);
}
}

View File

@@ -0,0 +1,49 @@
package com.pig4cloud.pigx.pay.config;
import cn.hutool.core.date.DateUtil;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.common.sequence.builder.DbSeqBuilder;
import com.pig4cloud.pigx.common.sequence.properties.SequenceDbProperties;
import com.pig4cloud.pigx.common.sequence.sequence.Sequence;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
/**
* @author lengleng
* @date 2019-05-26
* <p>
* 设置发号器生成规则
*/
@Configuration
public class SequenceConfig {
/**
* 订单流水号发号器
* @param dataSource
* @param properties
* @return
*/
@Bean
public Sequence paySequence(DataSource dataSource, SequenceDbProperties properties) {
return DbSeqBuilder.create()
.bizName(() -> String.format("pay_%s_%s", TenantContextHolder.getTenantId(), DateUtil.today()))
.dataSource(dataSource).step(properties.getStep()).retryTimes(properties.getRetryTimes())
.tableName(properties.getTableName()).build();
}
/**
* 通道编号发号器
* @param dataSource
* @param properties
* @return
*/
@Bean
public Sequence channelSequence(DataSource dataSource, SequenceDbProperties properties) {
return DbSeqBuilder.create().bizName(() -> String.format("channel_%s", TenantContextHolder.getTenantId()))
.dataSource(dataSource).step(properties.getStep()).retryTimes(properties.getRetryTimes())
.tableName(properties.getTableName()).build();
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.service.PayChannelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 支付渠道表
*
* @author PIG
* @date 2023-02-27 17:49:03
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/channel")
@Tag(description = "channel", name = "支付渠道表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayChannelController {
private final PayChannelService payChannelService;
/**
* 分页查询
* @param page 分页对象
* @param payChannel 支付渠道表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('pay_channel_view')")
public R getpayChannelPage(Page page, PayChannel payChannel) {
LambdaQueryWrapper<PayChannel> wrapper = Wrappers.lambdaQuery();
wrapper.like(StrUtil.isNotBlank(payChannel.getChannelName()), PayChannel::getChannelName,
payChannel.getChannelName());
wrapper.eq(StrUtil.isNotBlank(payChannel.getState()), PayChannel::getState, payChannel.getState());
return R.ok(payChannelService.page(page, wrapper));
}
/**
* 通过id查询支付渠道表
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('pay_channel_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(payChannelService.getById(id));
}
/**
* 新增支付渠道表
* @param payChannel 支付渠道表
* @return R
*/
@Operation(summary = "新增支付渠道表", description = "新增支付渠道表")
@SysLog("新增支付渠道表")
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_channel_add')")
public R save(@RequestBody PayChannel payChannel) {
return R.ok(payChannelService.save(payChannel));
}
/**
* 修改支付渠道表
* @param payChannel 支付渠道表
* @return R
*/
@Operation(summary = "修改支付渠道表", description = "修改支付渠道表")
@SysLog("修改支付渠道表")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_channel_edit')")
public R updateById(@RequestBody PayChannel payChannel) {
return R.ok(payChannelService.updateById(payChannel));
}
/**
* 通过id删除支付渠道表
* @param ids id列表
* @return R
*/
@Operation(summary = "通过id删除支付渠道表", description = "通过id删除支付渠道表")
@SysLog("通过id删除支付渠道表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('pay_channel_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(payChannelService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param payChannel 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('pay_channel_export')")
public List<PayChannel> export(PayChannel payChannel) {
return payChannelService.list(Wrappers.query(payChannel));
}
}

View File

@@ -0,0 +1,242 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.http.ContentType;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.service.PayChannelService;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/goods")
@Tag(description = "goods", name = "商品订单表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayGoodsOrderController {
private final PayGoodsOrderService payGoodsOrderService;
private final PayChannelService channelService;
private final ObjectMapper objectMapper;
/**
* 商品订单
* @param goods 商品
* @param response
*
* AliPayApiConfigKit.setAppId WxPayApiConfigKit.setAppId shezhi
*
*/
@SneakyThrows
@Inner(false)
@GetMapping("/buy")
@Operation(summary = "购买商品", description = "购买商品")
public void buy(PayGoodsOrder goods, HttpServletRequest request, HttpServletResponse response) {
String ua = request.getHeader(HttpHeaders.USER_AGENT);
log.info("当前扫码方式 UA:{}", ua);
if (ua.contains(PayConstants.MICRO_MESSENGER)) {
PayChannel channel = channelService.getOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.WEIXIN_MP),
false);
if (channel == null) {
throw new IllegalArgumentException("公众号支付配置不存在");
}
String wxUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s"
+ "&redirect_uri=%s&response_type=code&scope=snsapi_base&state=%s";
String redirectUri = String.format("%s/admin/goods/wx?amount=%s&TENANT-ID=%s", channel.getNotifyUrl(),
goods.getAmount(), TenantContextHolder.getTenantId());
response.sendRedirect(
String.format(wxUrl, channel.getAppId(), URLUtil.encode(redirectUri), channel.getAppId()));
}
if (ua.contains(PayConstants.ALIPAY)) {
payGoodsOrderService.buy(goods, false);
}
}
@SneakyThrows
@Inner(false)
@GetMapping("/merge/buy")
@Operation(summary = "聚合支付购买商品", description = "聚合支付购买商品")
public void mergeBuy(PayGoodsOrder goods, HttpServletResponse response) {
Map<String, Object> result = payGoodsOrderService.buy(goods, true);
response.setContentType(ContentType.JSON.getValue());
response.getWriter().print(objectMapper.writeValueAsString(result));
}
/**
* oauth
* @param goods 商品信息
* @param code 回调code
* @param modelAndView
* @return
* @throws WxErrorException
*/
@Inner(false)
@SneakyThrows
@GetMapping("/wx")
@Operation(summary = "商品信息", description = "回调code")
public ModelAndView wx(PayGoodsOrder goods, String code, ModelAndView modelAndView) {
PayChannel channel = channelService.getOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.WEIXIN_MP), false);
if (channel == null) {
throw new IllegalArgumentException("公众号支付配置不存在");
}
JSONObject params = JSONUtil.parseObj(channel.getParam());
WxMpService wxMpService = new WxMpServiceImpl();
WxMpDefaultConfigImpl storage = new WxMpDefaultConfigImpl();
storage.setAppId(channel.getAppId());
storage.setSecret(params.getStr("secret"));
wxMpService.setWxMpConfigStorage(storage);
WxOAuth2AccessToken accessToken = wxMpService.getOAuth2Service().getAccessToken(code);
goods.setUserId(accessToken.getOpenId());
goods.setAmount(goods.getAmount());
modelAndView.setViewName("pay");
modelAndView.addAllObjects(payGoodsOrderService.buy(goods, false));
return modelAndView;
}
/**
* 分页查询
* @param page 分页对象
* @param payGoodsOrder 商品订单表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
public R getpayGoodsOrderPage(Page page, PayGoodsOrder payGoodsOrder) {
LambdaQueryWrapper<PayGoodsOrder> wrapper = Wrappers.lambdaQuery();
wrapper.eq(StrUtil.isNotBlank(payGoodsOrder.getStatus()), PayGoodsOrder::getStatus, payGoodsOrder.getStatus());
wrapper.like(Objects.nonNull(payGoodsOrder.getPayOrderId()), PayGoodsOrder::getPayOrderId,
payGoodsOrder.getPayOrderId());
return R.ok(payGoodsOrderService.page(page, wrapper));
}
/**
* 通过id查询商品订单表
* @param goodsOrderId id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{goodsOrderId}")
public R getById(@PathVariable("goodsOrderId") Long goodsOrderId) {
return R.ok(payGoodsOrderService.getById(goodsOrderId));
}
/**
* 新增商品订单表
* @param payGoodsOrder 商品订单表
* @return R
*/
@Operation(summary = "新增商品订单表", description = "新增商品订单表")
@SysLog("新增商品订单表")
@PostMapping
public R save(@RequestBody PayGoodsOrder payGoodsOrder) {
return R.ok(payGoodsOrderService.save(payGoodsOrder));
}
/**
* 修改商品订单表
* @param payGoodsOrder 商品订单表
* @return R
*/
@Operation(summary = "修改商品订单表", description = "修改商品订单表")
@SysLog("修改商品订单表")
@PutMapping
public R updateById(@RequestBody PayGoodsOrder payGoodsOrder) {
return R.ok(payGoodsOrderService.updateById(payGoodsOrder));
}
/**
* 通过id删除商品订单表
* @param ids goodsOrderId列表
* @return R
*/
@Operation(summary = "通过id删除商品订单表", description = "通过id删除商品订单表")
@SysLog("通过id删除商品订单表")
@DeleteMapping
public R removeById(@RequestBody Long[] ids) {
return R.ok(payGoodsOrderService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param payGoodsOrder 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
public List<PayGoodsOrder> export(PayGoodsOrder payGoodsOrder) {
return payGoodsOrderService.list(Wrappers.query(payGoodsOrder));
}
}

View File

@@ -0,0 +1,205 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ijpay.alipay.AliPayApi;
import com.ijpay.core.kit.HttpKit;
import com.ijpay.core.kit.WxPayKit;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.common.xss.core.XssCleanIgnore;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.handler.PayNotifyCallbakHandler;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/notify")
@Tag(description = "notify", name = "通知记录日志表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayNotifyRecordController {
private final PayNotifyRecordService payNotifyRecordService;
private final PayNotifyCallbakHandler alipayCallback;
private final PayNotifyCallbakHandler weChatCallback;
private final PayNotifyCallbakHandler mergePayCallback;
/**
* 分页查询
* @param page 分页对象
* @param payNotifyRecord 通知记录日志表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('pay_record_view')")
public R getpayNotifyRecordPage(Page page, PayNotifyRecord payNotifyRecord) {
LambdaQueryWrapper<PayNotifyRecord> wrapper = Wrappers.lambdaQuery();
wrapper.eq(StrUtil.isNotBlank(payNotifyRecord.getNotifyId()), PayNotifyRecord::getNotifyId,
payNotifyRecord.getNotifyId());
wrapper.eq(StrUtil.isNotBlank(payNotifyRecord.getOrderNo()), PayNotifyRecord::getOrderNo,
payNotifyRecord.getOrderNo());
return R.ok(payNotifyRecordService.page(page, wrapper));
}
/**
* 通过id查询通知记录日志表
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('pay_record_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(payNotifyRecordService.getById(id));
}
/**
* 新增通知记录日志表
* @param payNotifyRecord 通知记录日志表
* @return R
*/
@Operation(summary = "新增通知记录日志表", description = "新增通知记录日志表")
@SysLog("新增通知记录日志表")
@PostMapping
public R save(@RequestBody PayNotifyRecord payNotifyRecord) {
return R.ok(payNotifyRecordService.save(payNotifyRecord));
}
/**
* 修改通知记录日志表
* @param payNotifyRecord 通知记录日志表
* @return R
*/
@Operation(summary = "修改通知记录日志表", description = "修改通知记录日志表")
@SysLog("修改通知记录日志表")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_record_edit')")
public R updateById(@RequestBody PayNotifyRecord payNotifyRecord) {
return R.ok(payNotifyRecordService.updateById(payNotifyRecord));
}
/**
* 通过id删除通知记录日志表
* @param ids id列表
* @return R
*/
@Operation(summary = "通过id删除通知记录日志表", description = "通过id删除通知记录日志表")
@SysLog("通过id删除通知记录日志表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('pay_record_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(payNotifyRecordService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 支付宝渠道异步回调
* @param request 渠道请求
* @return
*/
@Inner(false)
@SneakyThrows
@XssCleanIgnore
@SysLog("支付宝渠道异步回调")
@PostMapping("/ali/callbak")
@Operation(summary = "支付宝渠道异步回调", description = "支付宝渠道异步回调")
public void aliCallbak(HttpServletRequest request, HttpServletResponse response) {
// 解析回调信息
Map<String, String> params = AliPayApi.toMap(request);
response.getWriter().print(alipayCallback.handle(params));
}
/**
* 微信渠道支付回调
* @param request
* @return
*/
@Inner(false)
@SneakyThrows
@XssCleanIgnore
@PostMapping("/wx/callbak")
@Operation(summary = "微信渠道支付回调", description = "微信渠道支付回调")
@SysLog("微信渠道支付回调")
public String wxCallbak(HttpServletRequest request) {
String xmlMsg = HttpKit.readData(request);
log.info("微信订单回调信息:{}", xmlMsg);
Map<String, String> params = WxPayKit.xmlToMap(xmlMsg);
return weChatCallback.handle(params);
}
/**
* 聚合渠道异步回调
* @param request 渠道请求
* @return
*/
@Inner(false)
@SneakyThrows
@XssCleanIgnore
@PostMapping("/merge/callbak")
@Operation(summary = "聚合渠道异步回调", description = "聚合渠道异步回调")
@SysLog("聚合渠道异步回调")
public void mergeCallbak(HttpServletRequest request, HttpServletResponse response) {
// 解析回调信息
Map<String, String> params = AliPayApi.toMap(request);
response.getWriter().print(mergePayCallback.handle(params));
}
/**
* 导出excel 表格
* @param payNotifyRecord 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('pay_record_export')")
public List<PayNotifyRecord> export(PayNotifyRecord payNotifyRecord) {
return payNotifyRecordService.list(Wrappers.query(payNotifyRecord));
}
}

View File

@@ -0,0 +1,137 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import com.pig4cloud.pigx.pay.service.PayRefundOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@RestController
@AllArgsConstructor
@RequestMapping("/refund")
@Tag(description = "refund", name = "退款订单表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayRefundOrderController {
private final PayRefundOrderService payRefundOrderService;
/**
* 分页查询
* @param page 分页对象
* @param payRefundOrder 退款订单表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('pay_refund_view')")
public R getpayRefundOrderPage(Page page, PayRefundOrder payRefundOrder) {
LambdaQueryWrapper<PayRefundOrder> wrapper = Wrappers.lambdaQuery();
wrapper.eq(payRefundOrder.getRefundOrderId() != null, PayRefundOrder::getRefundOrderId,
payRefundOrder.getRefundOrderId());
wrapper.eq(payRefundOrder.getPayOrderId() != null, PayRefundOrder::getPayOrderId,
payRefundOrder.getPayOrderId());
wrapper.eq(StrUtil.isNotBlank(payRefundOrder.getMchId()), PayRefundOrder::getMchId, payRefundOrder.getMchId());
return R.ok(payRefundOrderService.page(page, wrapper));
}
/**
* 通过id查询退款订单表
* @param refundOrderId id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{refundOrderId}")
@PreAuthorize("@pms.hasPermission('pay_refund_view')")
public R getById(@PathVariable("refundOrderId") Long refundOrderId) {
return R.ok(payRefundOrderService.getById(refundOrderId));
}
/**
* 新增退款订单表
* @param payRefundOrder 退款订单表
* @return R
*/
@Operation(summary = "新增退款订单表", description = "新增退款订单表")
@SysLog("新增退款订单表")
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_refund_add')")
public R save(@RequestBody PayRefundOrder payRefundOrder) {
return R.ok(payRefundOrderService.refund(payRefundOrder));
}
/**
* 修改退款订单表
* @param payRefundOrder 退款订单表
* @return R
*/
@Operation(summary = "修改退款订单表", description = "修改退款订单表")
@SysLog("修改退款订单表")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_refund_edit')")
public R updateById(@RequestBody PayRefundOrder payRefundOrder) {
return R.ok(payRefundOrderService.updateById(payRefundOrder));
}
/**
* 通过id删除退款订单表
* @param ids refundOrderId列表
* @return R
*/
@Operation(summary = "通过id删除退款订单表", description = "通过id删除退款订单表")
@SysLog("通过id删除退款订单表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('pay_refund_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(payRefundOrderService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param payRefundOrder 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('pay_refund_export')")
public List<PayRefundOrder> export(PayRefundOrder payRefundOrder) {
return payRefundOrderService.list(Wrappers.query(payRefundOrder));
}
}

View File

@@ -0,0 +1,134 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 支付订单表
*
* @author PIG
* @date 2023-02-28 14:18:17
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/trade")
@Tag(description = "trade", name = "支付订单表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PayTradeOrderController {
private final PayTradeOrderService payTradeOrderService;
/**
* 分页查询
* @param page 分页对象
* @param payTradeOrder 支付订单表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('pay_trade_view')")
public R getpayTradeOrderPage(Page page, PayTradeOrder payTradeOrder) {
LambdaQueryWrapper<PayTradeOrder> wrapper = Wrappers.lambdaQuery();
wrapper.like(payTradeOrder.getOrderId() != null, PayTradeOrder::getOrderId, payTradeOrder.getOrderId());
wrapper.eq(StrUtil.isNotBlank(payTradeOrder.getStatus()), PayTradeOrder::getStatus, payTradeOrder.getStatus());
return R.ok(payTradeOrderService.page(page, wrapper));
}
/**
* 通过id查询支付订单表
* @param orderId id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{orderId}")
@PreAuthorize("@pms.hasPermission('pay_trade_view')")
public R getById(@PathVariable("orderId") Long orderId) {
return R.ok(payTradeOrderService.getById(orderId));
}
/**
* 新增支付订单表
* @param payTradeOrder 支付订单表
* @return R
*/
@Operation(summary = "新增支付订单表", description = "新增支付订单表")
@SysLog("新增支付订单表")
@PostMapping
@PreAuthorize("@pms.hasPermission('pay_trade_add')")
public R save(@RequestBody PayTradeOrder payTradeOrder) {
return R.ok(payTradeOrderService.save(payTradeOrder));
}
/**
* 修改支付订单表
* @param payTradeOrder 支付订单表
* @return R
*/
@Operation(summary = "修改支付订单表", description = "修改支付订单表")
@SysLog("修改支付订单表")
@PutMapping
@PreAuthorize("@pms.hasPermission('pay_trade_edit')")
public R updateById(@RequestBody PayTradeOrder payTradeOrder) {
return R.ok(payTradeOrderService.updateById(payTradeOrder));
}
/**
* 通过id删除支付订单表
* @param ids orderId列表
* @return R
*/
@Operation(summary = "通过id删除支付订单表", description = "通过id删除支付订单表")
@SysLog("通过id删除支付订单表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('pay_trade_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(payTradeOrderService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param payTradeOrder 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('pay_trade_export')")
public List<PayTradeOrder> export(PayTradeOrder payTradeOrder) {
return payTradeOrderService.list(Wrappers.query(payTradeOrder));
}
}

View File

@@ -0,0 +1,136 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
@Data
@TableName("pay_channel")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "渠道")
public class PayChannel extends Model<PayChannel> {
private static final long serialVersionUID = 1L;
/**
* 渠道主键ID
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "渠道主键ID")
private Long id;
/**
* mchId
*/
@Schema(description = "mchId")
private String mchId;
/**
* 渠道ID
*/
@Schema(description = "渠道ID")
private String channelId;
/**
* 渠道名称,如:alipay,wechat
*/
@Schema(description = "渠道名称,如:alipay,wechat")
private String channelName;
/**
* 渠道商户ID | 12****123
*/
@Schema(description = "渠道商户ID | 12****123")
private String channelMchId;
/**
* 前端回调地址
*/
@Schema(description = "前端回调地址")
private String returnUrl;
/**
* 后端回调地址
*/
@Schema(description = "后端回调地址")
private String notifyUrl;
/**
* 渠道状态
*/
@Schema(description = "渠道状态")
private String state;
/**
* 配置参数,json字符串
*/
@Schema(description = "配置参数,json字符串")
private String param;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description = "更新时间")
private LocalDateTime updateTime;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
/**
* 应用ID
*/
@Schema(description = "应用ID")
private String appId;
}

View File

@@ -0,0 +1,112 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
@Data
@TableName("pay_goods_order")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "商品订单表")
public class PayGoodsOrder extends Model<PayGoodsOrder> {
private static final long serialVersionUID = 1L;
/**
* 商品订单ID
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "商品订单ID")
private Long goodsOrderId;
/**
* 商品ID
*/
@Schema(description = "商品ID")
private String goodsId;
/**
* 商品名称
*/
@Schema(description = "商品名称")
private String goodsName;
/**
* 金额,单位分
*/
@Schema(description = "金额,单位分")
private String amount;
/**
* 用户ID
*/
@Schema(description = "用户ID")
private String userId;
/**
* 订单状态,订单生成(0),支付成功(1),处理完成(2),处理失败(-1)
*/
@Schema(description = "订单状态,订单生成(0),支付成功(1),处理完成(2),处理失败(-1)")
private String status;
/**
* 支付订单号
*/
@Schema(description = "支付订单号")
private Long payOrderId;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
@Data
@TableName("pay_notify_record")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "异步通知记录")
public class PayNotifyRecord extends Model<PayNotifyRecord> {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "ID")
private Long id;
/**
* 响应ID
*/
@Schema(description = "响应ID")
private String notifyId;
/**
* 请求报文
*/
@Schema(description = "请求报文")
private String request;
/**
* 响应报文
*/
@Schema(description = "响应报文")
private String response;
/**
* 系统订单号
*/
@Schema(description = "系统订单号")
private String orderNo;
/**
* http状态
*/
@Schema(description = "http状态")
private String httpStatus;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}

View File

@@ -0,0 +1,226 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@Data
@TableName("pay_refund_order")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "退款订单表")
public class PayRefundOrder extends Model<PayRefundOrder> {
private static final long serialVersionUID = 1L;
/**
* 退款订单号
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "退款订单号")
private Long refundOrderId;
/**
* 支付订单号
*/
@Schema(description = "支付订单号")
private Long payOrderId;
/**
* 渠道支付单号
*/
@Schema(description = "渠道支付单号")
private String channelPayOrderNo;
/**
* 商户ID
*/
@Schema(description = "商户ID")
private String mchId;
/**
* 商户退款单号
*/
@Schema(description = "商户退款单号")
private String mchRefundNo;
/**
* 渠道ID
*/
@Schema(description = "渠道ID")
private String channelId;
/**
* 支付金额
*/
@Schema(description = "支付金额")
private String payAmount;
/**
* 退款金额,单位分
*/
@Schema(description = "退款金额,单位分")
private Long refundAmount;
/**
* 三位货币代码
*/
@Schema(description = "三位货币代码")
private String currency;
/**
* 退款状态:0-订单生成,1-退款中,2-退款成功,3-退款失败,4-业务处理完成
*/
@Schema(description = "退款状态:0-订单生成,1-退款中,2-退款成功,3-退款失败,4-业务处理完成")
private Integer status;
/**
* 退款结果:0-不确认结果,1-等待手动处理,2-确认成功,3-确认失败
*/
@Schema(description = "退款结果:0-不确认结果,1-等待手动处理,2-确认成功,3-确认失败")
private Integer result;
/**
* 客户端IP
*/
@Schema(description = "客户端IP")
private String clientIp;
/**
* 设备
*/
@Schema(description = "设备")
private String device;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
/**
* 渠道用户标识
*/
@Schema(description = "渠道用户标识")
private String channelUser;
/**
* 用户姓名
*/
@Schema(description = "用户姓名")
private String username;
/**
* 渠道商户ID
*/
@Schema(description = "渠道商户ID")
private String channelMchId;
/**
* 渠道订单号
*/
@Schema(description = "渠道订单号")
private String channelOrderNo;
/**
* 渠道错误码
*/
@Schema(description = "渠道错误码")
private String channelErrCode;
/**
* 渠道错误描述
*/
@Schema(description = "渠道错误描述")
private String channelErrMsg;
/**
* 特定渠道发起时额外参数
*/
@Schema(description = "特定渠道发起时额外参数")
private String extra;
/**
* 通知地址
*/
@Schema(description = "通知地址")
private String notifyUrl;
/**
* 扩展参数1
*/
@Schema(description = "扩展参数1")
private String param1;
/**
* 扩展参数2
*/
@Schema(description = "扩展参数2")
private String param2;
/**
* 订单失效时间
*/
@Schema(description = "订单失效时间")
private LocalDateTime expireTime;
/**
* 订单退款成功时间
*/
@Schema(description = "订单退款成功时间")
private LocalDateTime refundSuccTime;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}

View File

@@ -0,0 +1,196 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
@Data
@TableName("pay_trade_order")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "支付订单表")
public class PayTradeOrder extends Model<PayTradeOrder> {
private static final long serialVersionUID = 1L;
/**
* 支付订单号
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "支付订单号")
private Long orderId;
/**
* 渠道ID
*/
@Schema(description = "渠道ID")
private String channelId;
/**
* 支付金额
*/
@Schema(description = "支付金额")
private String amount;
/**
* 三位货币代码
*/
@Schema(description = "三位货币代码")
private String currency;
/**
* 支付状态,0-订单生成,1-支付中(目前未使用),2-支付成功,3-业务处理完成
*/
@Schema(description = "支付状态,0-订单生成,1-支付中(目前未使用),2-支付成功,3-业务处理完成")
private String status;
/**
* 客户端IP
*/
@Schema(description = "客户端IP")
private String clientIp;
/**
* 设备
*/
@Schema(description = "设备")
private String device;
/**
* 商品标题
*/
@Schema(description = "商品标题")
private String subject;
/**
* 商品描述信息
*/
@Schema(description = "商品描述信息")
private String body;
/**
* 特定渠道发起时额外参数
*/
@Schema(description = "特定渠道发起时额外参数")
private String extra;
/**
* 渠道商户ID
*/
@Schema(description = "渠道商户ID")
private String channelMchId;
/**
* 渠道订单号
*/
@Schema(description = "渠道订单号")
private String channelOrderNo;
/**
* 渠道支付错误码
*/
@Schema(description = "渠道支付错误码")
private String errCode;
/**
* 渠道支付错误描述
*/
@Schema(description = "渠道支付错误描述")
private String errMsg;
/**
* 扩展参数1
*/
@Schema(description = "扩展参数1")
private String param1;
/**
* 扩展参数2
*/
@Schema(description = "扩展参数2")
private String param2;
/**
* 通知地址
*/
@Schema(description = "通知地址")
private String notifyUrl;
/**
* 通知次数
*/
@Schema(description = "通知次数")
private Integer notifyCount;
/**
* 最后一次通知时间
*/
@Schema(description = "最后一次通知时间")
private Long lastNotifyTime;
/**
* 订单失效时间
*/
@Schema(description = "订单失效时间")
private Long expireTime;
/**
* 订单支付成功时间
*/
@Schema(description = "订单支付成功时间")
private LocalDateTime paySuccTime;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 更新时间
*/
@Schema(description = "更新时间")
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updateTime;
/**
* delFlag
*/
@TableLogic
@Schema(description = "delFlag")
private String delFlag;
/**
* 租户ID
*/
@Schema(description = "租户ID")
private Long tenantId;
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler;
/**
* @author lengleng
* @date 2019-06-14
* <p>
* 消息去重
*/
public interface MessageDuplicateCheckerHandler {
/**
* 判断回调消息是否重复.
* @param messageId messageId需要根据上面讲的方式构造
* @return 如果是重复消息返回false否则返回true
*/
boolean isDuplicate(String messageId);
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler;
import java.util.Map;
/**
* @author lengleng
* @date 2019-06-27
* <p>
* 支付回调处理器
*/
public interface PayNotifyCallbakHandler {
/**
* 初始化执行
* @param params
*/
void before(Map<String, String> params);
/**
* 去重处理
* @param params 回调报文
* @return
*/
Boolean duplicateChecker(Map<String, String> params);
/**
* 验签逻辑
* @param params 回调报文
* @return
*/
Boolean verifyNotify(Map<String, String> params);
/**
* 解析报文
* @param params
* @return
*/
String parse(Map<String, String> params);
/**
* 调用入口
* @param params
* @return
*/
String handle(Map<String, String> params);
/**
* 保存回调记录
* @param result 处理结果
* @param params 回调报文
*/
void saveNotifyRecord(Map<String, String> params, String result);
}

View File

@@ -0,0 +1,58 @@
package com.pig4cloud.pigx.pay.handler;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
/**
* @author lengleng
* @date 2019-05-31
* <p>
* 支付业务
*/
public interface PayOrderHandler {
/**
* 准备支付参数
*/
default PayChannel preparePayParams() {
return null;
}
/**
* 创建商品订单
* @param goodsOrder 金额
* @return
*/
void createGoodsOrder(PayGoodsOrder goodsOrder);
/**
* 创建交易订单
* @param goodsOrder 商品订单
* @return
*/
PayTradeOrder createTradeOrder(PayGoodsOrder goodsOrder);
/**
* 调起渠道支付
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
* @return obj
*/
Object pay(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder);
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
void updateOrder(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder);
/**
* 调用入口
* @param goodsOrde 商品订单
* @return
*/
Object handle(PayGoodsOrder goodsOrde);
}

View File

@@ -0,0 +1,51 @@
package com.pig4cloud.pigx.pay.handler;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
/**
* @author lengleng
* @date 2023-03-01
* <p>
* 退款业务
*/
public interface PayOrderRefundHandler {
/**
* 准备支付参数
*/
default PayChannel preparePayParams() {
return null;
}
/**
* 创建商品退款订单
* @param tradeOrder 交易订单
* @return
*/
PayRefundOrder createPayRefundOrder(PayRefundOrder refundOrder, PayTradeOrder tradeOrder);
/**
* 调起渠道退款
* @param refundOrder 商品退款订单
* @param tradeOrder 交易订单
* @return obj
*/
Object refund(PayRefundOrder refundOrder, PayTradeOrder tradeOrder);
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
void updateOrder(Object obj, PayRefundOrder refundOrder, PayTradeOrder tradeOrder);
/**
* 调用入口
* @param goodsOrde 商品订单
* @return
*/
Object handle(PayRefundOrder refundOrder);
}

View File

@@ -0,0 +1,82 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.handler.PayNotifyCallbakHandler;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import lombok.extern.slf4j.Slf4j;
import java.util.Map;
/**
* @author lengleng
* @date 2019-06-27
*/
@Slf4j
public abstract class AbstractPayNotifyCallbakHandler implements PayNotifyCallbakHandler {
/**
* 调用入口
* @param params
* @return
*/
@Override
public String handle(Map<String, String> params) {
// 初始化租户
before(params);
// 去重处理
if (duplicateChecker(params)) {
return null;
}
// 验签处理
if (!verifyNotify(params)) {
return null;
}
String result = parse(params);
// 保存处理结果
saveNotifyRecord(params, result);
return result;
}
/**
* 保存记录
* @param params
* @param result
* @param record
* @param notifyId
* @param recordService
*/
void saveRecord(Map<String, String> params, String result, PayNotifyRecord record, String notifyId,
PayNotifyRecordService recordService) {
record.setNotifyId(notifyId);
String orderNo = params.get(PayConstants.OUT_TRADE_NO);
record.setOrderNo(orderNo);
record.setRequest(MapUtil.join(params, StrUtil.DASHED, StrUtil.DASHED));
record.setResponse(result);
recordService.save(record);
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import com.pig4cloud.pigx.common.sequence.sequence.Sequence;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.PayOrderHandler;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.utils.ChannelPayApiConfigKit;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @author lengleng
* @date 2019-05-31
*/
public abstract class AbstractPayOrderHandler implements PayOrderHandler {
@Autowired
private PayGoodsOrderMapper goodsOrderMapper;
@Autowired
private Sequence paySequence;
/**
* 创建商品订单
* @param goodsOrder 商品订单
* @return
*/
@Override
public void createGoodsOrder(PayGoodsOrder goodsOrder) {
goodsOrder.setPayOrderId(Long.parseLong(paySequence.nextNo()));
goodsOrder.setStatus(OrderStatusEnum.INIT.getStatus());
goodsOrderMapper.insert(goodsOrder);
}
/**
* 调用入口
* @return
*/
@Override
public Object handle(PayGoodsOrder payGoodsOrder) {
PayChannel payChannel = preparePayParams();
ChannelPayApiConfigKit.put(payChannel);
createGoodsOrder(payGoodsOrder);
PayTradeOrder tradeOrder = createTradeOrder(payGoodsOrder);
Object result = pay(payGoodsOrder, tradeOrder);
updateOrder(payGoodsOrder, tradeOrder);
// 情况ttl
ChannelPayApiConfigKit.remove();
return result;
}
}

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.MessageDuplicateCheckerHandler;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import com.pig4cloud.pigx.pay.utils.TradeStatusEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Map;
/**
* @author lengleng
* @date 2019-06-27
* <p>
* 支付宝回调处理
*/
@Slf4j
@AllArgsConstructor
@Service("alipayCallback")
public class AlipayPayNotifyCallbackHandler extends AbstractPayNotifyCallbakHandler {
private final MessageDuplicateCheckerHandler duplicateCheckerHandler;
private final PayTradeOrderService tradeOrderService;
private final PayGoodsOrderService goodsOrderService;
private final PayNotifyRecordService recordService;
/**
* 维护租户信息
* @param params
*/
@Override
public void before(Map<String, String> params) {
Long tenant = MapUtil.getLong(params, "passback_params");
TenantContextHolder.setTenantId(tenant);
}
/**
* 去重处理
* @param params 回调报文
* @return
*/
@Override
public Boolean duplicateChecker(Map<String, String> params) {
// 判断是否是为支付中
if (StrUtil.equals(TradeStatusEnum.WAIT_BUYER_PAY.getDescription(), params.get(PayConstants.TRADE_STATUS))) {
log.info("支付宝订单待支付 {} 不做处理", params);
return true;
}
// 判断10秒内是否已经回调处理
if (duplicateCheckerHandler.isDuplicate(params.get(PayConstants.OUT_TRADE_NO))) {
log.info("支付宝订单重复回调 {} 不做处理", params);
this.saveNotifyRecord(params, "重复回调");
return true;
}
return false;
}
/**
* 验签逻辑
* @param params 回调报文
* @return
*/
@Override
public Boolean verifyNotify(Map<String, String> params) {
return true;
}
/**
* 解析报文
* @param params 回调报文
* @return
*/
@Override
public String parse(Map<String, String> params) {
String tradeStatus = EnumUtil.fromString(TradeStatusEnum.class, params.get(PayConstants.TRADE_STATUS))
.getStatus();
String orderNo = params.get(PayConstants.OUT_TRADE_NO);
PayGoodsOrder goodsOrder = goodsOrderService
.getOne(Wrappers.<PayGoodsOrder>lambdaQuery().eq(PayGoodsOrder::getPayOrderId, orderNo));
goodsOrder.setStatus(tradeStatus);
goodsOrderService.updateById(goodsOrder);
PayTradeOrder tradeOrder = tradeOrderService
.getOne(Wrappers.<PayTradeOrder>lambdaQuery().eq(PayTradeOrder::getOrderId, orderNo));
tradeOrder.setPaySuccTime(LocalDateTime.now());
tradeOrder.setChannelOrderNo(params.get("trade_no"));
tradeOrder.setStatus(TradeStatusEnum.TRADE_SUCCESS.getStatus());
tradeOrderService.updateById(tradeOrder);
return "success";
}
/**
* 保存回调记录
* @param result 处理结果
* @param params 回调报文
*/
@Override
public void saveNotifyRecord(Map<String, String> params, String result) {
PayNotifyRecord record = new PayNotifyRecord();
String notifyId = params.get("notify_id");
saveRecord(params, result, record, notifyId, recordService);
}
}

View File

@@ -0,0 +1,142 @@
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alipay.api.domain.AlipayTradeRefundModel;
import com.alipay.api.response.AlipayTradeRefundResponse;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ijpay.alipay.AliPayApi;
import com.ijpay.alipay.AliPayApiConfig;
import com.ijpay.alipay.AliPayApiConfigKit;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.PayOrderRefundHandler;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.mapper.PayRefundOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import com.pig4cloud.pigx.pay.utils.TradeStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
/**
* yungous 退款时限
*
* @author lengleng
* @date 2023/3/1
*/
@Service("ALIPAY_REFUND")
@RequiredArgsConstructor
public class AlipayPayOrderRefundHandler implements PayOrderRefundHandler {
private final PayRefundOrderMapper refundOrderMapper;
private final PayChannelMapper channelMapper;
private final PayTradeOrderMapper tradeOrderMapper;
private final HttpServletRequest request;
@Override
public PayChannel preparePayParams() {
PayChannel channel = channelMapper.selectOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.ALIPAY_WAP.name()));
if (channel == null) {
throw new IllegalArgumentException("支付宝网页支付渠道配置为空");
}
JSONObject params = JSONUtil.parseObj(channel.getParam());
AliPayApiConfig aliPayApiConfig = AliPayApiConfig.builder().setAppId(channel.getAppId())
.setPrivateKey(params.getStr("privateKey")).setCharset(CharsetUtil.UTF_8)
.setAliPayPublicKey(params.getStr("publicKey")).setServiceUrl(params.getStr("serviceUrl"))
.setSignType("RSA2").build();
AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig);
return channel;
}
/**
* 创建商品退款订单
* @param refundOrder 退款订单
* @param tradeOrder 交易订单
* @return
*/
@Override
public PayRefundOrder createPayRefundOrder(PayRefundOrder refundOrder, PayTradeOrder tradeOrder) {
refundOrder.setPayOrderId(tradeOrder.getOrderId());
refundOrder.setChannelOrderNo(tradeOrder.getChannelOrderNo());
refundOrder.setChannelId(PayChannelNameEnum.ALIPAY_WAP.getName());
refundOrder.setChannelMchId(AliPayApiConfigKit.getAliPayApiConfig().getAppId());
refundOrder.setClientIp(ServletUtil.getClientIP(request));
refundOrder.setPayAmount(tradeOrder.getAmount());
refundOrderMapper.insert(refundOrder);
return refundOrder;
}
/**
* 调起渠道退款
* @param refundOrder 商品退款订单
* @param tradeOrder 交易订单
* @return obj
*/
@Override
@SneakyThrows
public Object refund(PayRefundOrder refundOrder, PayTradeOrder tradeOrder) {
AlipayTradeRefundModel refundModel = new AlipayTradeRefundModel();
refundModel.setOutTradeNo(tradeOrder.getOrderId().toString());
refundModel.setTradeNo(tradeOrder.getChannelOrderNo());
refundModel.setRefundAmount(NumberUtil.div(refundOrder.getRefundAmount().toString(), "100", 2).toString());
refundModel.setRefundReason(refundOrder.getRemark());
return AliPayApi.tradeRefundToResponse(refundModel);
}
/**
* 更新订单信息
* @param refundOrder 退款订单
* @param tradeOrder 交易订单
*/
@Override
public void updateOrder(Object obj, PayRefundOrder refundOrder, PayTradeOrder tradeOrder) {
AlipayTradeRefundResponse refundResponse = (AlipayTradeRefundResponse) obj;
refundOrder.setMchRefundNo(refundResponse.getTradeNo());
// 更新退款单状态成功
refundOrder.setStatus(Integer.parseInt(TradeStatusEnum.TRADE_SUCCESS.getStatus()));
refundOrder.setRefundSuccTime(LocalDateTime.now());
refundOrderMapper.updateById(refundOrder);
// 更新原订单为退款成功状态
tradeOrder.setPaySuccTime(LocalDateTime.now());
tradeOrder.setStatus(OrderStatusEnum.REFUND_SUCCESS.getStatus());
tradeOrderMapper.updateById(tradeOrder);
}
/**
* 调用入口
* @param refundOrder 退款订单
* @return
*/
@Override
public Object handle(PayRefundOrder refundOrder) {
// 准备支付宝相关参数
preparePayParams();
// 根据订单ID查询交易订单
PayTradeOrder payTradeOrder = tradeOrderMapper.selectOne(
Wrappers.<PayTradeOrder>lambdaQuery().eq(PayTradeOrder::getOrderId, refundOrder.getPayOrderId()));
// 创建退款单
createPayRefundOrder(refundOrder, payTradeOrder);
// 拉起支付宝退款
Object refund = refund(refundOrder, payTradeOrder);
// 更新库表状态
updateOrder(refund, refundOrder, payTradeOrder);
return null;
}
}

View File

@@ -0,0 +1,161 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alipay.api.AlipayApiException;
import com.alipay.api.domain.AlipayTradeWapPayModel;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ijpay.alipay.AliPayApi;
import com.ijpay.alipay.AliPayApiConfig;
import com.ijpay.alipay.AliPayApiConfigKit;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.utils.ChannelPayApiConfigKit;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author lengleng
* @date 2019-05-31
* <p>
* 支付宝手机支付
*/
@Slf4j
@Service("ALIPAY_WAP")
@AllArgsConstructor
public class AlipayWapPayOrderHandler extends AbstractPayOrderHandler {
private final PayTradeOrderMapper tradeOrderMapper;
private final PayGoodsOrderMapper goodsOrderMapper;
private final PayChannelMapper channelMapper;
private final HttpServletRequest request;
private final HttpServletResponse response;
/**
* 准备支付参数
*/
@Override
public PayChannel preparePayParams() {
PayChannel channel = channelMapper.selectOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.ALIPAY_WAP.name()));
if (channel == null) {
throw new IllegalArgumentException("支付宝网页支付渠道配置为空");
}
JSONObject params = JSONUtil.parseObj(channel.getParam());
AliPayApiConfig aliPayApiConfig = AliPayApiConfig.builder().setAppId(channel.getAppId())
.setPrivateKey(params.getStr("privateKey")).setCharset(CharsetUtil.UTF_8)
.setAliPayPublicKey(params.getStr("publicKey")).setServiceUrl(params.getStr("serviceUrl"))
.setSignType("RSA2").build();
AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig);
return channel;
}
/**
* 创建交易订单
* @param goodsOrder
* @return
*/
@Override
public PayTradeOrder createTradeOrder(PayGoodsOrder goodsOrder) {
PayTradeOrder tradeOrder = new PayTradeOrder();
tradeOrder.setOrderId(goodsOrder.getPayOrderId());
tradeOrder.setAmount(goodsOrder.getAmount());
tradeOrder.setChannelId(PayChannelNameEnum.ALIPAY_WAP.getName());
tradeOrder.setChannelMchId(AliPayApiConfigKit.getAliPayApiConfig().getAppId());
tradeOrder.setClientIp(ServletUtil.getClientIP(request));
tradeOrder.setCurrency("cny");
tradeOrder.setExpireTime(30L);
tradeOrder.setStatus(OrderStatusEnum.INIT.getStatus());
tradeOrder.setBody(goodsOrder.getGoodsName());
tradeOrderMapper.insert(tradeOrder);
return tradeOrder;
}
/**
* 调起渠道支付
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public PayTradeOrder pay(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
model.setBody(tradeOrder.getBody());
model.setSubject(tradeOrder.getBody());
model.setOutTradeNo(String.valueOf(tradeOrder.getOrderId()));
model.setTimeoutExpress("30m");
// 分转成元 并且保留两位
model.setTotalAmount(NumberUtil.div(tradeOrder.getAmount(), "100", 2).toString());
model.setProductCode(goodsOrder.getGoodsId());
model.setPassbackParams(String.valueOf(TenantContextHolder.getTenantId()));
try {
log.info("拉起支付宝wap 支付参数 {}", model);
AliPayApi.wapPay(response, model, ChannelPayApiConfigKit.get().getReturnUrl(),
ChannelPayApiConfigKit.get().getNotifyUrl() + "/admin/notify/ali/callbak");
}
catch (AlipayApiException e) {
log.error("支付宝手机支付失败", e);
tradeOrder.setErrMsg(e.getErrMsg());
tradeOrder.setErrCode(e.getErrCode());
tradeOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
goodsOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
}
catch (IOException e) {
log.error("支付宝手机支付失败", e);
tradeOrder.setErrMsg(e.getMessage());
tradeOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
goodsOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
}
return tradeOrder;
}
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public void updateOrder(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
tradeOrderMapper.updateById(tradeOrder);
goodsOrderMapper.updateById(goodsOrder);
}
}

View File

@@ -0,0 +1,49 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import com.pig4cloud.pigx.pay.handler.MessageDuplicateCheckerHandler;
import lombok.AllArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.time.Duration;
/**
* @author lengleng
* @date 2019-06-14
* <p>
* 消息去重
*/
@Service
@AllArgsConstructor
public class MessageRedisDuplicateCheckerHandler implements MessageDuplicateCheckerHandler {
private final RedisTemplate redisTemplate;
/**
* 判断回调消息是否重复.
* @param messageId messageId需要根据上面讲的方式构造
* @return 如果是重复消息true否则返回false
*/
@Override
public boolean isDuplicate(String messageId) {
return !redisTemplate.opsForValue().setIfAbsent(messageId, messageId, Duration.ofSeconds(10L));
}
}

View File

@@ -0,0 +1,147 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.extra.servlet.ServletUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ijpay.core.enums.SignType;
import com.ijpay.core.enums.TradeType;
import com.ijpay.core.kit.WxPayKit;
import com.ijpay.wxpay.WxPayApi;
import com.ijpay.wxpay.WxPayApiConfig;
import com.ijpay.wxpay.WxPayApiConfigKit;
import com.ijpay.wxpay.model.UnifiedOrderModel;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.utils.ChannelPayApiConfigKit;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
/**
* @author lengleng
* @date 2019-05-31
* <p>
* 微信公众号支付
*/
@Slf4j
@Service("WEIXIN_MP")
@RequiredArgsConstructor
public class WeChatMpPayOrderHandler extends AbstractPayOrderHandler {
private final PayTradeOrderMapper tradeOrderMapper;
private final PayGoodsOrderMapper goodsOrderMapper;
private final PayChannelMapper channelMapper;
private final HttpServletRequest request;
/**
* 准备支付参数
* @return PayChannel
*/
@Override
public PayChannel preparePayParams() {
PayChannel channel = channelMapper.selectOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.WEIXIN_MP.name()));
if (channel == null) {
throw new IllegalArgumentException("微信公众号支付渠道配置为空");
}
JSONObject params = JSONUtil.parseObj(channel.getParam());
WxPayApiConfig wx = WxPayApiConfig.builder().appId(channel.getAppId()).mchId(channel.getChannelMchId())
.partnerKey(params.getStr("partnerKey")).build();
WxPayApiConfigKit.setThreadLocalWxPayApiConfig(wx);
return channel;
}
/**
* 创建交易订单
* @param goodsOrder
* @return
*/
@Override
public PayTradeOrder createTradeOrder(PayGoodsOrder goodsOrder) {
PayTradeOrder tradeOrder = new PayTradeOrder();
tradeOrder.setOrderId(goodsOrder.getPayOrderId());
tradeOrder.setAmount(goodsOrder.getAmount());
tradeOrder.setChannelId(PayChannelNameEnum.WEIXIN_MP.getName());
tradeOrder.setChannelMchId(WxPayApiConfigKit.getWxPayApiConfig().getMchId());
tradeOrder.setClientIp(ServletUtil.getClientIP(request));
tradeOrder.setCurrency("CNY");
tradeOrder.setStatus(OrderStatusEnum.INIT.getStatus());
tradeOrder.setBody(goodsOrder.getGoodsName());
tradeOrderMapper.insert(tradeOrder);
return tradeOrder;
}
/**
* 调起渠道支付
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public Object pay(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
String ip = ServletUtil.getClientIP(request);
WxPayApiConfig wxPayApiConfig = WxPayApiConfigKit.getWxPayApiConfig();
// 预订单参数
Map<String, String> params = UnifiedOrderModel.builder().appid(wxPayApiConfig.getAppId())
.mch_id(wxPayApiConfig.getMchId()).nonce_str(WxPayKit.generateStr()).body(goodsOrder.getGoodsName())
.attach(TenantContextHolder.getTenantId().toString())
.out_trade_no(String.valueOf(tradeOrder.getOrderId())).total_fee(goodsOrder.getAmount())
.spbill_create_ip(ip)
.notify_url(ChannelPayApiConfigKit.get().getNotifyUrl() + "/admin/notify/wx/callbak")
.trade_type(TradeType.JSAPI.getTradeType()).openid(goodsOrder.getUserId()).build()
.createSign(wxPayApiConfig.getPartnerKey(), SignType.HMACSHA256);
String xmlResult = WxPayApi.pushOrder(false, params);
log.info("微信统一下单返回 {}", xmlResult);
Map<String, String> resultMap = WxPayKit.xmlToMap(xmlResult);
String prepayId = resultMap.get("prepay_id");
return WxPayKit.prepayIdCreateSign(prepayId, wxPayApiConfig.getAppId(), wxPayApiConfig.getPartnerKey(),
SignType.HMACSHA256);
}
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public void updateOrder(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
tradeOrderMapper.updateById(tradeOrder);
goodsOrderMapper.updateById(goodsOrder);
}
}

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.EnumUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ijpay.core.kit.WxPayKit;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.MessageDuplicateCheckerHandler;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import com.pig4cloud.pigx.pay.utils.TradeStatusEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
/**
* @author lengleng
* @date 2019-06-27
* <p>
* 微信回调处理
*/
@Slf4j
@AllArgsConstructor
@Service("weChatCallback")
public class WeChatPayNotifyCallbackHandler extends AbstractPayNotifyCallbakHandler {
private final MessageDuplicateCheckerHandler duplicateCheckerHandler;
private final PayTradeOrderService tradeOrderService;
private final PayGoodsOrderService goodsOrderService;
private final PayNotifyRecordService recordService;
/**
* 维护租户信息
* @param params
*/
@Override
public void before(Map<String, String> params) {
Long tenant = MapUtil.getLong(params, "attach");
TenantContextHolder.setTenantId(tenant);
}
/**
* 去重处理
* @param params 回调报文
* @return
*/
@Override
public Boolean duplicateChecker(Map<String, String> params) {
// 判断10秒内是否已经回调处理
if (duplicateCheckerHandler.isDuplicate(params.get(PayConstants.OUT_TRADE_NO))) {
log.info("微信订单重复回调 {} 不做处理", params);
this.saveNotifyRecord(params, "重复回调");
return true;
}
return false;
}
/**
* 验签逻辑
* @param params 回调报文
* @return
*/
@Override
public Boolean verifyNotify(Map<String, String> params) {
return true;
}
/**
* 解析报文
* @param params
* @return
*/
@Override
public String parse(Map<String, String> params) {
String tradeStatus = EnumUtil.fromString(TradeStatusEnum.class, params.get(PayConstants.RESULT_CODE))
.getStatus();
String orderNo = params.get(PayConstants.OUT_TRADE_NO);
PayGoodsOrder goodsOrder = goodsOrderService
.getOne(Wrappers.<PayGoodsOrder>lambdaQuery().eq(PayGoodsOrder::getPayOrderId, orderNo));
goodsOrder.setStatus(tradeStatus);
goodsOrderService.updateById(goodsOrder);
PayTradeOrder tradeOrder = tradeOrderService
.getOne(Wrappers.<PayTradeOrder>lambdaQuery().eq(PayTradeOrder::getOrderId, orderNo));
tradeOrder.setPaySuccTime(LocalDateTime.now());
tradeOrder.setStatus(tradeStatus);
tradeOrder.setChannelOrderNo(params.get("transaction_id"));
tradeOrder.setErrMsg(params.get("err_code_des"));
tradeOrder.setErrCode(params.get("err_code"));
tradeOrderService.updateById(tradeOrder);
Map<String, String> xml = new HashMap<>(4);
xml.put("return_code", "SUCCESS");
xml.put("return_msg", "OK");
return WxPayKit.toXml(xml);
}
/**
* 保存回调记录
* @param result 处理结果
* @param params 回调报文
*/
@Override
public void saveNotifyRecord(Map<String, String> params, String result) {
PayNotifyRecord record = new PayNotifyRecord();
String notifyId = params.get("transaction_id");
saveRecord(params, result, record, notifyId, recordService);
}
}

View File

@@ -0,0 +1,126 @@
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.handler.MessageDuplicateCheckerHandler;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayConstants;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Map;
/**
* @author lengleng
* @date 2021/1/4
* <p>
* 聚合支付回调处理
*/
@Slf4j
@AllArgsConstructor
@Service("mergePayCallback")
public class YungouosMergePayNotifyCallbakHandler extends AbstractPayNotifyCallbakHandler {
private final MessageDuplicateCheckerHandler duplicateCheckerHandler;
private final PayNotifyRecordService recordService;
private final PayTradeOrderService tradeOrderService;
private final PayGoodsOrderService goodsOrderService;
/**
* 初始化执行
* @param params
*/
@Override
public void before(Map<String, String> params) {
Long tenant = MapUtil.getLong(params, "attach");
TenantContextHolder.setTenantId(tenant);
}
/**
* 去重处理
* @param params 回调报文
* @return
*/
@Override
public Boolean duplicateChecker(Map<String, String> params) {
// 判断10秒内是否已经回调处理
if (duplicateCheckerHandler.isDuplicate(params.get(PayConstants.MERGE_OUT_TRADE_NO))) {
log.info("聚合支付订单重复回调 {} 不做处理", params);
this.saveNotifyRecord(params, "重复回调");
return true;
}
return false;
}
/**
* 验签逻辑
* @param params 回调报文
* @return
*/
@Override
public Boolean verifyNotify(Map<String, String> params) {
return Boolean.TRUE;
}
/**
* 解析报文
* @param params
* @return
*/
@Override
public String parse(Map<String, String> params) {
String mergeCode = params.get(PayConstants.MERGE_CODE);
String orderNo = params.get(PayConstants.MERGE_OUT_TRADE_NO);
PayGoodsOrder goodsOrder = goodsOrderService
.getOne(Wrappers.<PayGoodsOrder>lambdaQuery().eq(PayGoodsOrder::getPayOrderId, orderNo));
PayTradeOrder tradeOrder = tradeOrderService
.getOne(Wrappers.<PayTradeOrder>lambdaQuery().eq(PayTradeOrder::getOrderId, orderNo));
if (OrderStatusEnum.SUCCESS.getStatus().equals(mergeCode)) {
goodsOrder.setStatus(OrderStatusEnum.SUCCESS.getStatus());
tradeOrder.setStatus(OrderStatusEnum.SUCCESS.getStatus());
}
else {
goodsOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
tradeOrder.setStatus(OrderStatusEnum.FAIL.getStatus());
}
goodsOrderService.updateById(goodsOrder);
tradeOrder.setPaySuccTime(LocalDateTime.now());
tradeOrder.setChannelOrderNo(params.get("orderNo"));
// 修改实际的支付渠道
String payChannel = params.get(PayConstants.MERGE_OUT_TRADE_NO);
tradeOrder.setChannelId(payChannel);
tradeOrderService.updateById(tradeOrder);
return "SUCCESS";
}
/**
* 保存回调记录
* @param params 回调报文
* @param result 处理结果
*/
@Override
public void saveNotifyRecord(Map<String, String> params, String result) {
PayNotifyRecord record = new PayNotifyRecord();
String notifyId = RandomUtil.randomNumbers(12);
MapUtil.renameKey(params, PayConstants.MERGE_OUT_TRADE_NO, PayConstants.OUT_TRADE_NO);
saveRecord(params, result, record, notifyId, recordService);
}
}

View File

@@ -0,0 +1,107 @@
package com.pig4cloud.pigx.pay.handler.impl;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.utils.ChannelPayApiConfigKit;
import com.pig4cloud.pigx.pay.utils.OrderStatusEnum;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import com.yungouos.pay.merge.MergePay;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
/**
* @author lengleng
* @date 2021/1/4
* <p>
* https://open.pay.yungouos.com/#/api/api/pay/merge/nativePay 服务商聚合支付模式
*/
@Slf4j
@Service("MERGE_PAY")
@RequiredArgsConstructor
public class YungouosMergePayOrderHandler extends AbstractPayOrderHandler {
private final PayTradeOrderMapper tradeOrderMapper;
private final PayGoodsOrderMapper goodsOrderMapper;
private final PayChannelMapper channelMapper;
private final HttpServletRequest request;
/**
* 准备支付参数
* @return
*/
@Override
public PayChannel preparePayParams() {
PayChannel channel = channelMapper.selectOne(
Wrappers.<PayChannel>lambdaQuery().eq(PayChannel::getChannelId, PayChannelNameEnum.MERGE_PAY.name()));
if (channel == null) {
throw new IllegalArgumentException("聚合支付渠道配置为空");
}
return channel;
}
/**
* 创建交易订单
* @param goodsOrder 商品订单
* @return
*/
@Override
public PayTradeOrder createTradeOrder(PayGoodsOrder goodsOrder) {
PayTradeOrder tradeOrder = new PayTradeOrder();
tradeOrder.setOrderId(goodsOrder.getPayOrderId());
tradeOrder.setAmount(goodsOrder.getAmount());
tradeOrder.setChannelId(PayChannelNameEnum.MERGE_PAY.getName());
tradeOrder.setChannelMchId(ChannelPayApiConfigKit.get().getChannelMchId());
tradeOrder.setClientIp(ServletUtil.getClientIP(request));
tradeOrder.setCurrency("CNY");
tradeOrder.setStatus(OrderStatusEnum.INIT.getStatus());
tradeOrder.setBody(goodsOrder.getGoodsName());
tradeOrderMapper.insert(tradeOrder);
return tradeOrder;
}
/**
* 调起渠道支付
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
* @return obj
*/
@Override
public Object pay(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
PayChannel channel = ChannelPayApiConfigKit.get();
String money = NumberUtil.div(tradeOrder.getAmount(), "100", 2).toString();
return MergePay.nativePay(String.valueOf(tradeOrder.getOrderId()), money, channel.getChannelMchId(),
tradeOrder.getBody(), "1", TenantContextHolder.getTenantId().toString(),
ChannelPayApiConfigKit.get().getNotifyUrl() + "/admin/notify/merge/callbak",
ChannelPayApiConfigKit.get().getReturnUrl(), "", "", "", channel.getParam());
}
/**
* 更新订单信息
* @param goodsOrder 商品订单
* @param tradeOrder 交易订单
*/
@Override
public void updateOrder(PayGoodsOrder goodsOrder, PayTradeOrder tradeOrder) {
tradeOrderMapper.updateById(tradeOrder);
goodsOrderMapper.updateById(goodsOrder);
}
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import org.apache.ibatis.annotations.Mapper;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
@Mapper
public interface PayChannelMapper extends PigxBaseMapper<PayChannel> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import org.apache.ibatis.annotations.Mapper;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
@Mapper
public interface PayGoodsOrderMapper extends PigxBaseMapper<PayGoodsOrder> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import org.apache.ibatis.annotations.Mapper;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
@Mapper
public interface PayNotifyRecordMapper extends PigxBaseMapper<PayNotifyRecord> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import org.apache.ibatis.annotations.Mapper;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@Mapper
public interface PayRefundOrderMapper extends PigxBaseMapper<PayRefundOrder> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.mapper;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import org.apache.ibatis.annotations.Mapper;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
@Mapper
public interface PayTradeOrderMapper extends PigxBaseMapper<PayTradeOrder> {
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayChannel;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
public interface PayChannelService extends IService<PayChannel> {
/**
* 新增支付渠道
* @param payChannel 支付渠道
* @return
*/
Boolean saveChannel(PayChannel payChannel);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import java.util.Map;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
public interface PayGoodsOrderService extends IService<PayGoodsOrder> {
/**
* 购买商品
* @param goodsOrder goods
* @param isMerge 是否是服务商
* @return
*/
Map<String, Object> buy(PayGoodsOrder goodsOrder, boolean isMerge);
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
public interface PayNotifyRecordService extends IService<PayNotifyRecord> {
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
public interface PayRefundOrderService extends IService<PayRefundOrder> {
/**
* 退款操作
* @param refundOrder refundOrder
* @return true/false
*/
Boolean refund(PayRefundOrder refundOrder);
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
public interface PayTradeOrderService extends IService<PayTradeOrder> {
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import com.pig4cloud.pigx.pay.mapper.PayChannelMapper;
import com.pig4cloud.pigx.pay.service.PayChannelService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
* 渠道
*
* @author lengleng
* @date 2019-05-28 23:57:58
*/
@Service
@AllArgsConstructor
public class PayChannelServiceImpl extends ServiceImpl<PayChannelMapper, PayChannel> implements PayChannelService {
/**
* 新增支付渠道
* @param payChannel 支付渠道
* @return
*/
@Override
public Boolean saveChannel(PayChannel payChannel) {
return save(payChannel);
}
}

View File

@@ -0,0 +1,76 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayGoodsOrder;
import com.pig4cloud.pigx.pay.handler.PayOrderHandler;
import com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper;
import com.pig4cloud.pigx.pay.service.PayGoodsOrderService;
import com.pig4cloud.pigx.pay.utils.PayChannelNameEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;
/**
* 商品
*
* @author lengleng
* @date 2019-05-28 23:58:27
*/
@Slf4j
@Service
@AllArgsConstructor
public class PayGoodsOrderServiceImpl extends ServiceImpl<PayGoodsOrderMapper, PayGoodsOrder>
implements PayGoodsOrderService {
private final Map<String, PayOrderHandler> orderHandlerMap;
private final HttpServletRequest request;
/**
* 下单购买
* @param goodsOrder
* @param isMerge
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Map<String, Object> buy(PayGoodsOrder goodsOrder, boolean isMerge) {
// 是否聚合支付
String ua = isMerge ? "MERGE_PAY" : request.getHeader(HttpHeaders.USER_AGENT);
Enum channel = PayChannelNameEnum.getChannel(ua);
PayOrderHandler orderHandler = orderHandlerMap.get(channel.name());
goodsOrder.setGoodsName("测试产品");
goodsOrder.setGoodsId("10001");
Object params = orderHandler.handle(goodsOrder);
Map<String, Object> result = new HashMap<>(4);
result.put("channel", channel.name());
result.put("goods", goodsOrder);
result.put("params", params);
return result;
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayNotifyRecord;
import com.pig4cloud.pigx.pay.mapper.PayNotifyRecordMapper;
import com.pig4cloud.pigx.pay.service.PayNotifyRecordService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
/**
* 异步通知记录
*
* @author lengleng
* @date 2019-05-28 23:57:23
*/
@Slf4j
@Service
@AllArgsConstructor
public class PayNotifyRecordServiceImpl extends ServiceImpl<PayNotifyRecordMapper, PayNotifyRecord>
implements PayNotifyRecordService {
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayRefundOrder;
import com.pig4cloud.pigx.pay.handler.PayOrderRefundHandler;
import com.pig4cloud.pigx.pay.mapper.PayRefundOrderMapper;
import com.pig4cloud.pigx.pay.service.PayRefundOrderService;
import com.pig4cloud.pigx.pay.utils.RefundNameEnum;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.util.Map;
/**
* 退款
*
* @author lengleng
* @date 2019-05-28 23:58:11
*/
@Service
@RequiredArgsConstructor
public class PayRefundOrderServiceImpl extends ServiceImpl<PayRefundOrderMapper, PayRefundOrder>
implements PayRefundOrderService {
private final Map<String, PayOrderRefundHandler> refundHandlerMap;
/**
* 退款操作
* @param refundOrder refundOrder
* @return true/false
*/
@Override
public Boolean refund(PayRefundOrder refundOrder) {
String channelId = refundOrder.getChannelId();
// 判断用哪个通道
if (StrUtil.containsAnyIgnoreCase(channelId, "ali")) {
refundHandlerMap.get(RefundNameEnum.ALIPAY.getName()).handle(refundOrder);
}
else {
throw new UnsupportedOperationException();
}
return null;
}
}

View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.pay.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper;
import com.pig4cloud.pigx.pay.service.PayTradeOrderService;
import org.springframework.stereotype.Service;
/**
* 支付
*
* @author lengleng
* @date 2019-05-28 23:58:18
*/
@Service
public class PayTradeOrderServiceImpl extends ServiceImpl<PayTradeOrderMapper, PayTradeOrder>
implements PayTradeOrderService {
}

View File

@@ -0,0 +1,29 @@
package com.pig4cloud.pigx.pay.utils;
import com.pig4cloud.pigx.pay.entity.PayChannel;
import lombok.experimental.UtilityClass;
/**
* @author lengleng
* @date 2021/2/2
*
* 聚合支付配置管理
*/
@UtilityClass
public class ChannelPayApiConfigKit {
private static final ThreadLocal<PayChannel> TL = new ThreadLocal();
public PayChannel get() {
return TL.get();
}
public void put(PayChannel channel) {
TL.set(channel);
}
public void remove() {
TL.remove();
}
}

View File

@@ -0,0 +1,51 @@
package com.pig4cloud.pigx.pay.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author lengleng
* @date 2019-05-30
* <p>
* 订单状态
*/
@Getter
@AllArgsConstructor
public enum OrderStatusEnum {
/**
* 订单初始 下单
*/
INIT("0", "下单"),
/**
* 订单支付成功
*/
SUCCESS("1", "成功"),
/**
* 订单支付完成
*/
COMPLETE("2", "完成"),
/**
* 退款成功
*/
REFUND_SUCCESS("5", "退款成功"),
/**
* 订单支付失败
*/
FAIL("-1", "失败");
/**
* 状态
*/
private String status;
/**
* 描述
*/
private String description;
}

View File

@@ -0,0 +1,63 @@
package com.pig4cloud.pigx.pay.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author lengleng
* @date 2019-05-30
* <p>
* 支付渠道名称
*/
@AllArgsConstructor
public enum PayChannelNameEnum {
/**
* 支付宝wap支付
*/
ALIPAY_WAP("ALIPAY_WAP", "支付宝手机支付"),
/**
* 微信H5支付
*/
WEIXIN_WAP("WEIXIN_WAP", "微信H5支付"),
/**
* 微信公众号支付
*/
WEIXIN_MP("WEIXIN_MP", "微信公众号支付"),
/**
* 聚合支付
*/
MERGE_PAY("MERGE_PAY", "yungouos 一码付");
/**
* 名称
*/
@Getter
private String name;
/**
* 描述
*/
private String description;
/**
* 通过ua 判断所属渠道
* @param ua 浏览器类型
* @return
*/
public static Enum getChannel(String ua) {
if (ua.contains(PayConstants.ALIPAY)) {
return PayChannelNameEnum.ALIPAY_WAP;
}
else if (ua.contains(PayConstants.MICRO_MESSENGER)) {
return PayChannelNameEnum.WEIXIN_MP;
}
else {
return PayChannelNameEnum.MERGE_PAY;
}
}
}

View File

@@ -0,0 +1,51 @@
package com.pig4cloud.pigx.pay.utils;
/**
* @author lengleng
* @date 2019-06-14
* <p>
* 支付相关的常量
*/
public interface PayConstants {
/**
* 支付宝商户交易编号
*/
String OUT_TRADE_NO = "out_trade_no";
/**
* 支付宝浏览器标志
*/
String ALIPAY = "Alipay";
/**
* 微信浏览器标志
*/
String MICRO_MESSENGER = "MicroMessenger";
/**
* 返回码
*/
String RESULT_CODE = "result_code";
/**
* 支付状态(支付宝)
*/
String TRADE_STATUS = "trade_status";
/**
* 聚合支付返回 Code
*/
String MERGE_CODE = "code";
/**
* 聚合支付订单号
*/
String MERGE_OUT_TRADE_NO = "outTradeNo";
/**
* 支付渠道
*/
String PAY_CHANNEL = "payChannel";
}

View File

@@ -0,0 +1,13 @@
package com.pig4cloud.pigx.pay.utils;
/**
* @author lengleng
* @date 2023/3/1
*
* 支付异常错误
*/
public interface PayErrorCodes {
String UNSUPPORTED_OPERATION = "unsupported_operation";
}

View File

@@ -0,0 +1,36 @@
package com.pig4cloud.pigx.pay.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author lengleng
* @date 2019-05-30
* <p>
* 支付渠道名称
*/
@AllArgsConstructor
public enum RefundNameEnum {
/**
* 支付宝wap支付
*/
ALIPAY("ALIPAY_REFUND", "支付宝退款"),
/**
* 微信H5支付
*/
WEIXIN("WEIXIN_REFUND", "微信退款");
/**
* 名称
*/
@Getter
private String name;
/**
* 描述
*/
private String description;
}

View File

@@ -0,0 +1,54 @@
package com.pig4cloud.pigx.pay.utils;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author lengleng
* @date 2019-06-14
*/
@Getter
@AllArgsConstructor
public enum TradeStatusEnum {
/**
* 交易完成
*/
WAIT_BUYER_PAY("WAIT_BUYER_PAY", OrderStatusEnum.INIT.getStatus()),
/**
* TRADE_CLOSED
*/
TRADE_CLOSED("TRADE_CLOSED", OrderStatusEnum.FAIL.getStatus()),
/**
* TRADE_SUCCESS
*/
TRADE_SUCCESS("TRADE_SUCCESS", OrderStatusEnum.SUCCESS.getStatus()),
/**
* 交易关闭
*/
TRADE_FINISHED("TRADE_FINISHED", OrderStatusEnum.COMPLETE.getStatus()),
/**
* 微信支付成功
*/
SUCCESS("SUCCESS", OrderStatusEnum.SUCCESS.getStatus()),
/**
* 微信支付失败
*/
FAIL("FAIL", OrderStatusEnum.FAIL.getStatus());
/**
* 描述
*/
private String description;
/**
* 描述
*/
private String status;
}

View File

@@ -0,0 +1,18 @@
server:
port: 5010
spring:
application:
name: @artifactId@
cloud:
nacos:
username: @nacos.username@
password: @nacos.password@
discovery:
server-addr: ${NACOS_HOST:pigx-register}:${NACOS_PORT:8848}
config:
server-addr: ${spring.cloud.nacos.discovery.server-addr}
config:
import:
- optional:nacos:application-@profiles.active@.yml
- optional:nacos:${spring.application.name}-@profiles.active@.yml

View File

@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
小技巧: 在根pom里面设置统一存放路径统一管理方便维护
<properties>
<log-path>/Users/lengleng</log-path>
</properties>
1. 其他模块加日志输出直接copy本文件放在resources 目录即可
2. 注意修改 <property name="${log-path}/log.path" value=""/> 的value模块
-->
<configuration debug="false" scan="false">
<property name="log.path" value="logs/${project.artifactId}"/>
<!-- 彩色日志格式 -->
<property name="CONSOLE_LOG_PATTERN"
value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
<conversionRule conversionWord="wex"
converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
<conversionRule conversionWord="wEx"
converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<!-- Log file debug output -->
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
</encoder>
</appender>
<!-- Log file error output -->
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log.path}/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<maxFileSize>50MB</maxFileSize>
<maxHistory>30</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</appender>
<logger name="org.activiti.engine.impl.db" level="DEBUG">
<appender-ref ref="debug"/>
</logger>
<!--nacos 心跳 INFO 屏蔽-->
<logger name="com.alibaba.nacos" level="OFF">
<appender-ref ref="error"/>
</logger>
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
<root level="INFO">
<appender-ref ref="console"/>
<appender-ref ref="error"/>
</root>
</configuration>

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayChannelMapper">
<resultMap id="payChannelMap" type="com.pig4cloud.pigx.pay.entity.PayChannel">
<id property="id" column="id"/>
<result property="appId" column="app_id"/>
<result property="channelName" column="channel_name"/>
<result property="channelMchId" column="channel_mch_id"/>
<result property="channelId" column="channel_id"/>
<result property="state" column="state"/>
<result property="param" column="param"/>
<result property="remark" column="remark"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayGoodsOrderMapper">
<resultMap id="payGoodsOrderMap" type="com.pig4cloud.pigx.pay.entity.PayGoodsOrder">
<id property="goodsOrderId" column="goods_order_id"/>
<result property="goodsId" column="goods_id"/>
<result property="goodsName" column="goods_name"/>
<result property="amount" column="amount"/>
<result property="userId" column="user_id"/>
<result property="status" column="status"/>
<result property="payOrderId" column="pay_order_id"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayNotifyRecordMapper">
<resultMap id="payNotifyRecordMap" type="com.pig4cloud.pigx.pay.entity.PayNotifyRecord">
<id property="id" column="id"/>
<result property="notifyId" column="notify_id"/>
<result property="request" column="request"/>
<result property="response" column="response"/>
<result property="orderNo" column="order_no"/>
<result property="httpStatus" column="http_status"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayRefundOrderMapper">
<resultMap id="payRefundOrderMap" type="com.pig4cloud.pigx.pay.entity.PayRefundOrder">
<id property="refundOrderId" column="refund_]order_id"/>
<result property="payOrderId" column="pay_order_id"/>
<result property="channelPayOrderNo" column="channel_pay_order_no"/>
<result property="mchId" column="mch_id"/>
<result property="mchRefundNo" column="mch_refund_no"/>
<result property="channelId" column="channel_id"/>
<result property="payAmount" column="pay_amount"/>
<result property="refundAmount" column="refund_amount"/>
<result property="currency" column="currency"/>
<result property="status" column="status"/>
<result property="result" column="result"/>
<result property="clientIp" column="client_ip"/>
<result property="device" column="device"/>
<result property="remark" column="remark"/>
<result property="channelUser" column="channel_user"/>
<result property="username" column="username"/>
<result property="channelMchId" column="channel_mch_id"/>
<result property="channelOrderNo" column="channel_order_no"/>
<result property="channelErrCode" column="channel_err_code"/>
<result property="channelErrMsg" column="channel_err_msg"/>
<result property="extra" column="extra"/>
<result property="notifyurl" column="notifyUrl"/>
<result property="param1" column="param1"/>
<result property="param2" column="param2"/>
<result property="expireTime" column="expire_time"/>
<result property="refundSuccTime" column="refund_succ_time"/>
<result property="delFlag" column="del_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.pig4cloud.pigx.pay.mapper.PayTradeOrderMapper">
<resultMap id="payTradeOrderMap" type="com.pig4cloud.pigx.pay.entity.PayTradeOrder">
<id property="orderId" column="order_id"/>
<result property="channelId" column="channel_id"/>
<result property="amount" column="amount"/>
<result property="currency" column="currency"/>
<result property="status" column="status"/>
<result property="clientIp" column="client_ip"/>
<result property="device" column="device"/>
<result property="subject" column="subject"/>
<result property="body" column="body"/>
<result property="extra" column="extra"/>
<result property="channelMchId" column="channel_mch_id"/>
<result property="channelOrderNo" column="channel_order_no"/>
<result property="errCode" column="err_code"/>
<result property="errMsg" column="err_msg"/>
<result property="param1" column="param1"/>
<result property="param2" column="param2"/>
<result property="notifyUrl" column="notify_url"/>
<result property="notifyCount" column="notify_count"/>
<result property="lastNotifyTime" column="last_notify_time"/>
<result property="expireTime" column="expire_time"/>
<result property="paySuccTime" column="pay_succ_time"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>

View File

@@ -0,0 +1,58 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<meta charset="UTF-8">
<title>Pigx Pro 支付模块</title>
</head>
<script src="//cdn.jsdelivr.net/jquery/1.12.1/jquery.min.js"></script>
<body>
<#if channel == 'WEIXIN_WAP'>
<a href="javascript:void(0)" onclick="pay()">确认购买</a>
</#if>
</body>
</html>
<#if channel == 'WEIXIN_MP'>
<script>
function onBridgeReady() {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
"appId": "${params.appId}", //公众号名称,由商户传入
"timeStamp": "${params.timeStamp}", //时间戳自1970年以来的秒数
"nonceStr": "${params.nonceStr}", //随机串
"package": "${params.package}",
"signType": "${params.signType}", //微信签名方式:
"paySign": "${params.paySign}" //微信签名,paySign 采用统一的微信支付 Sign 签名生成方法,注意这里 appId 也要参与签名appId 与 config 中传入的 appId 一致即最后参与签名的参数有appId, timeStamp, nonceStr, package, signType。
},
function (res) {
if (res.err_msg == "get_brand_wcpay_request:ok") { // 使用以上方式判断前端返回,微信团队郑重提示res.err_msg将在用户支付成功后返回 ok但并不保证它绝对可靠。
alert('支付成功!');
} else {
alert('支付失败:' + res.err_msg);
}
WeixinJSBridge.call('closeWindow');
}
);
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
} else {
onBridgeReady();
}
</script>
</#if>
<#if channel == 'WEIXIN_WAP'>
<script>
function pay() {
window.location.href = "${params}"
}
</script>
</#if>

View File

@@ -0,0 +1,18 @@
FROM pig4cloud/java:8-jre
MAINTAINER wangiegie@gmail.com
ENV TZ=Asia/Shanghai
ENV JAVA_OPTS="-Xms128m -Xmx256m -Djava.security.egd=file:/dev/./urandom"
RUN ln -sf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN mkdir -p /pigx-codegen
WORKDIR /pigx-codegen
EXPOSE 5003
ADD ./target/pigx-codegen.jar ./
CMD sleep 120;java $JAVA_OPTS -jar pigx-codegen.jar

View File

@@ -0,0 +1,183 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-visual</artifactId>
<version>5.2.0</version>
</parent>
<artifactId>pigx-codegen</artifactId>
<packaging>jar</packaging>
<description>代码生成模块</description>
<properties>
<magic.version>2.0.2</magic.version>
<screw.version>0.0.1</screw.version>
<db2.version>11.5.0.0</db2.version>
<configuration.version>1.10</configuration.version>
</properties>
<dependencies>
<!--注册中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--配置中心客户端-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!--数据操作-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-data</artifactId>
</dependency>
<!--动态数据源 数据操作-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-datasource</artifactId>
</dependency>
<!--mybatis-->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
</dependency>
<!-- postgresql 驱动 -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!-- oracle 驱动 -->
<dependency>
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
</dependency>
<!-- sqlserver 驱动 -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<!-- db2 驱动-->
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>${db2.version}</version>
</dependency>
<!-- 瀚高 -->
<dependency>
<groupId>com.highgo</groupId>
<artifactId>HgdbJdbc</artifactId>
</dependency>
<!--DM-->
<dependency>
<groupId>com.dameng</groupId>
<artifactId>DmJdbcDriver18</artifactId>
</dependency>
<!-- druid 连接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
</dependency>
<!--common-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-core</artifactId>
</dependency>
<dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
<version>${configuration.version}</version>
</dependency>
<!--swagger-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-swagger</artifactId>
</dependency>
<!--安全模块-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-xss</artifactId>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
</dependency>
<!--sentinel-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-sentinel</artifactId>
</dependency>
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-log</artifactId>
</dependency>
<!--灰度支持-->
<dependency>
<groupId>com.pig4cloud</groupId>
<artifactId>pigx-common-gray</artifactId>
</dependency>
<!--代码生成模板引擎-->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>${velocity.version}</version>
</dependency>
<dependency>
<groupId>org.apache.velocity.tools</groupId>
<artifactId>velocity-tools-generic</artifactId>
<version>${velocity.tool.version}</version>
</dependency>
<!--生成文档-->
<dependency>
<groupId>io.springboot.plugin</groupId>
<artifactId>screw-spring-boot-starter</artifactId>
<version>${screw.version}</version>
</dependency>
<!--web 模块-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--undertow容器-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen;
import com.pig4cloud.pigx.common.datasource.annotation.EnableDynamicDataSource;
import com.pig4cloud.pigx.common.feign.annotation.EnablePigxFeignClients;
import com.pig4cloud.pigx.common.security.annotation.EnablePigxResourceServer;
import com.pig4cloud.pigx.common.swagger.annotation.EnableOpenApi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
/**
* @author lengleng
* @date 2018/07/29 代码生成模块
*/
@EnableDynamicDataSource
@EnableOpenApi("gen")
@EnablePigxFeignClients
@EnableDiscoveryClient
@EnablePigxResourceServer
@SpringBootApplication
public class PigxCodeGenApplication {
public static void main(String[] args) {
SpringApplication.run(PigxCodeGenApplication.class, args);
}
}

View File

@@ -0,0 +1,145 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.ContentType;
import cn.smallbun.screw.boot.config.Screw;
import cn.smallbun.screw.boot.properties.ScrewProperties;
import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.codegen.entity.GenDatasourceConf;
import com.pig4cloud.pigx.codegen.service.GenDatasourceConfService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
import com.pig4cloud.pigx.common.security.annotation.Inner;
import com.pig4cloud.pigx.common.xss.core.XssCleanIgnore;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
/**
* 数据源管理
*
* @author lengleng
* @date 2019-03-31 16:00:20
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/dsconf")
public class GenDsConfController {
private final GenDatasourceConfService datasourceConfService;
private final Screw screw;
/**
* 分页查询
* @param page 分页对象
* @param datasourceConf 数据源表
* @return
*/
@GetMapping("/page")
public R getSysDatasourceConfPage(Page page, GenDatasourceConf datasourceConf) {
return R.ok(datasourceConfService.page(page,
Wrappers.<GenDatasourceConf>lambdaQuery().like(StrUtil.isNotBlank(datasourceConf.getDsName()),
GenDatasourceConf::getDsName, datasourceConf.getDsName())));
}
/**
* 查询全部数据源
* @return
*/
@GetMapping("/list")
@Inner(value = false)
public R list() {
return R.ok(datasourceConfService.list());
}
/**
* 通过id查询数据源表
* @param id id
* @return R
*/
@GetMapping("/{id}")
public R getById(@PathVariable("id") Long id) {
return R.ok(datasourceConfService.getById(id));
}
/**
* 新增数据源表
* @param datasourceConf 数据源表
* @return R
*/
@PostMapping
@XssCleanIgnore
public R save(@RequestBody GenDatasourceConf datasourceConf) {
return R.ok(datasourceConfService.saveDsByEnc(datasourceConf));
}
/**
* 修改数据源表
* @param conf 数据源表
* @return R
*/
@PutMapping
@XssCleanIgnore
public R updateById(@RequestBody GenDatasourceConf conf) {
return R.ok(datasourceConfService.updateDsByEnc(conf));
}
/**
* 通过id删除数据源表
* @param ids id
* @return R
*/
@DeleteMapping
public R removeById(@RequestBody Long[] ids) {
return R.ok(datasourceConfService.removeByDsId(ids));
}
/**
* 查询数据源对应的文档
* @param dsName 数据源名称
*/
@SneakyThrows
@GetMapping("/doc")
public void generatorDoc(String dsName, HttpServletResponse response) {
// 设置指定的数据源
DynamicRoutingDataSource dynamicRoutingDataSource = SpringContextHolder.getBean(DynamicRoutingDataSource.class);
DynamicDataSourceContextHolder.push(dsName);
DataSource dataSource = dynamicRoutingDataSource.determineDataSource();
// 设置指定的目标表
ScrewProperties screwProperties = SpringContextHolder.getBean(ScrewProperties.class);
// 生成
byte[] data = screw.documentGeneration(dataSource, screwProperties).toByteArray();
response.reset();
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
response.setContentType(ContentType.OCTET_STREAM.getValue());
IoUtil.write(response.getOutputStream(), Boolean.TRUE, data);
}
}

View File

@@ -0,0 +1,136 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.codegen.entity.GenFieldType;
import com.pig4cloud.pigx.codegen.service.GenFieldTypeService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 列属性
*
* @author pigx code generator
* @date 2023-02-06 20:16:01
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/fieldtype")
@Tag(description = "fieldtype", name = "列属性管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class GenFieldTypeController {
private final GenFieldTypeService fieldTypeService;
/**
* 分页查询
* @param page 分页对象
* @param fieldType 列属性
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
public R getFieldTypePage(Page page, GenFieldType fieldType) {
return R.ok(fieldTypeService.page(page,
Wrappers.<GenFieldType>lambdaQuery().like(StrUtil.isNotBlank(fieldType.getColumnType()),
GenFieldType::getColumnType, fieldType.getColumnType())));
}
@Operation(summary = "查询列表", description = "查询列表")
@GetMapping("/list")
public R list(GenFieldType fieldType) {
return R.ok(fieldTypeService.list(Wrappers.query(fieldType)));
}
/**
* 通过id查询列属性
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/details/{id}")
public R getById(@PathVariable("id") Long id) {
return R.ok(fieldTypeService.getById(id));
}
@GetMapping("/details")
public R getDetails(GenFieldType query) {
return R.ok(fieldTypeService.getOne(Wrappers.query(query), false));
}
/**
* 新增列属性
* @param fieldType 列属性
* @return R
*/
@Operation(summary = "新增列属性", description = "新增列属性")
@SysLog("新增列属性")
@PostMapping
public R save(@RequestBody GenFieldType fieldType) {
return R.ok(fieldTypeService.save(fieldType));
}
/**
* 修改列属性
* @param fieldType 列属性
* @return R
*/
@Operation(summary = "修改列属性", description = "修改列属性")
@SysLog("修改列属性")
@PutMapping
public R updateById(@RequestBody GenFieldType fieldType) {
return R.ok(fieldTypeService.updateById(fieldType));
}
/**
* 通过id删除列属性
* @param ids id
* @return R
*/
@Operation(summary = "通过id删除列属性", description = "通过id删除列属性")
@SysLog("通过id删除列属性")
@DeleteMapping
public R removeById(@RequestBody Long[] ids) {
return R.ok(fieldTypeService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param fieldType 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
public List<GenFieldType> export(GenFieldType fieldType) {
return fieldTypeService.list(Wrappers.query(fieldType));
}
}

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
import com.pig4cloud.pigx.codegen.service.GenFormConfService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
/**
* 表单管理
*
* @author lengleng
* @date 2019-08-12 15:55:35
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/form")
@Tag(description = "form", name = "表单管理")
public class GenFormConfController {
private final GenFormConfService genRecordService;
/**
* 分页查询
* @param page 分页对象
* @param formConf 生成记录
* @return
*/
@Operation(description = "分页查询", summary = "分页查询")
@GetMapping("/page")
public R getGenFormConfPage(Page page, GenFormConf formConf) {
return R.ok(genRecordService.page(page, Wrappers.query(formConf)));
}
/**
* 通过id查询生成记录
* @param id id
* @return R
*/
@Operation(description = "通过id查询", summary = "通过id查询")
@GetMapping("/{id}")
public R getById(@PathVariable("id") Long id) {
return R.ok(genRecordService.getById(id));
}
/**
* 新增生成记录
* @param formConf 生成记录
* @return R
*/
@Operation(description = "新增生成记录", summary = "新增生成记录")
@PostMapping
public R save(@RequestBody GenFormConf formConf) {
genRecordService.save(formConf);
return R.ok(formConf);
}
/**
* 修改生成记录
* @param formConf 生成记录
* @return R
*/
@Operation(description = "修改生成记录", summary = "修改生成记录")
@SysLog("修改生成记录")
@PutMapping
public R updateById(@RequestBody GenFormConf formConf) {
return R.ok(genRecordService.updateById(formConf));
}
/**
* 通过id删除生成记录
* @param id id
* @return R
*/
@Operation(description = "通过id删除生成记录", summary = "通过id删除生成记录")
@SysLog("通过id删除生成记录")
@DeleteMapping("/{id}")
public R removeById(@PathVariable Long id) {
return R.ok(genRecordService.removeById(id));
}
}

View File

@@ -0,0 +1,146 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.codegen.entity.GenGroupEntity;
import com.pig4cloud.pigx.codegen.service.GenGroupService;
import com.pig4cloud.pigx.codegen.util.vo.GroupVo;
import com.pig4cloud.pigx.codegen.util.vo.TemplateGroupDTO;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 模板分组
*
* @author PIG
* @date 2023-02-21 20:01:53
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/group")
@Tag(description = "group", name = "模板分组管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class GenGroupController {
private final GenGroupService genGroupService;
/**
* 分页查询
* @param page 分页对象
* @param genGroup 模板分组
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('codegen_group_view')")
public R getgenGroupPage(Page page, GenGroupEntity genGroup) {
LambdaQueryWrapper<GenGroupEntity> wrapper = Wrappers.<GenGroupEntity>lambdaQuery()
.like(genGroup.getId() != null, GenGroupEntity::getId, genGroup.getId())
.like(StrUtil.isNotEmpty(genGroup.getGroupName()), GenGroupEntity::getGroupName,
genGroup.getGroupName());
return R.ok(genGroupService.page(page, wrapper));
}
/**
* 通过id查询模板分组
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('codegen_group_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(genGroupService.getGroupVoById(id));
}
/**
* 新增模板分组
* @param genTemplateGroup 模板分组
* @return R
*/
@Operation(summary = "新增模板分组", description = "新增模板分组")
@SysLog("新增模板分组")
@PostMapping
@PreAuthorize("@pms.hasPermission('codegen_group_add')")
public R save(@RequestBody TemplateGroupDTO genTemplateGroup) {
genGroupService.saveGenGroup(genTemplateGroup);
return R.ok();
}
/**
* 修改模板分组
* @param groupVo 模板分组
* @return R
*/
@Operation(summary = "修改模板分组", description = "修改模板分组")
@SysLog("修改模板分组")
@PutMapping
@PreAuthorize("@pms.hasPermission('codegen_group_edit')")
public R updateById(@RequestBody GroupVo groupVo) {
genGroupService.updateGroupAndTemplateById(groupVo);
return R.ok();
}
/**
* 通过id删除模板分组
* @param ids id列表
* @return R
*/
@Operation(summary = "通过id删除模板分组", description = "通过id删除模板分组")
@SysLog("通过id删除模板分组")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('codegen_group_del')")
public R removeById(@RequestBody Long[] ids) {
genGroupService.delGroupAndTemplate(ids);
return R.ok();
}
/**
* 导出excel 表格
* @param genGroup 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('codegen_group_export')")
public List<GenGroupEntity> export(GenGroupEntity genGroup) {
return genGroupService.list(Wrappers.query(genGroup));
}
@GetMapping("/list")
@Operation(summary = "查询列表", description = "查询列表")
public R list() {
List<GenGroupEntity> list = genGroupService.list();
return R.ok(list);
}
}

View File

@@ -0,0 +1,175 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.codegen.entity.GenTable;
import com.pig4cloud.pigx.codegen.entity.GenTableColumnEntity;
import com.pig4cloud.pigx.codegen.service.GenTableColumnService;
import com.pig4cloud.pigx.codegen.service.GenTableService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 列属性
*
* @author pigx code generator
* @date 2023-02-06 20:34:55
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/table")
@Tag(description = "table", name = "列属性管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class GenTableController {
private final GenTableColumnService tableColumnService;
private final GenTableService tableService;
/**
* 分页查询
* @param page 分页对象
* @param table 列属性
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
public R getTablePage(Page page, GenTable table) {
return R.ok(tableService.list(page, table));
}
/**
* 通过id查询列属性
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
public R getById(@PathVariable("id") Long id) {
return R.ok(tableService.getById(id));
}
/**
* 新增列属性
* @param table 列属性
* @return R
*/
@Operation(summary = "新增列属性", description = "新增列属性")
@SysLog("新增列属性")
@PostMapping
public R save(@RequestBody GenTable table) {
return R.ok(tableService.save(table));
}
/**
* 修改列属性
* @param table 列属性
* @return R
*/
@Operation(summary = "修改列属性", description = "修改列属性")
@SysLog("修改列属性")
@PutMapping
public R updateById(@RequestBody GenTable table) {
return R.ok(tableService.updateById(table));
}
/**
* 通过id删除列属性
* @param id id
* @return R
*/
@Operation(summary = "通过id删除列属性", description = "通过id删除列属性")
@SysLog("通过id删除列属性")
@DeleteMapping("/{id}")
public R removeById(@PathVariable Long id) {
return R.ok(tableService.removeById(id));
}
/**
* 导出excel 表格
* @param table 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
public List<GenTable> export(GenTable table) {
return tableService.list(Wrappers.query(table));
}
@GetMapping("/list/{dsName}")
public R listTable(@PathVariable("dsName") String dsName) {
return R.ok(tableService.queryDsAllTable(dsName));
}
@GetMapping("/column/{dsName}/{tableName}")
public R column(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
return R.ok(tableService.queryColumn(dsName, tableName));
}
/**
* 获取表信息
* @param dsName 数据源
* @param tableName 表名称
*/
@GetMapping("/{dsName}/{tableName}")
public R<GenTable> info(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
return R.ok(tableService.queryOrBuildTable(dsName, tableName));
}
/**
* 同步表信息
* @param dsName 数据源
* @param tableName 表名称
*/
@GetMapping("/sync/{dsName}/{tableName}")
public R<GenTable> sync(@PathVariable("dsName") String dsName, @PathVariable String tableName) {
// 表配置删除
tableService.remove(
Wrappers.<GenTable>lambdaQuery().eq(GenTable::getDsName, dsName).eq(GenTable::getTableName, tableName));
// 字段配置删除
tableColumnService.remove(Wrappers.<GenTableColumnEntity>lambdaQuery()
.eq(GenTableColumnEntity::getDsName, dsName).eq(GenTableColumnEntity::getTableName, tableName));
return R.ok(tableService.queryOrBuildTable(dsName, tableName));
}
/**
* 修改表字段数据
* @param dsName 数据源
* @param tableName 表名称
* @param tableFieldList 字段列表
*/
@PutMapping("/field/{dsName}/{tableName}")
public R<String> updateTableField(@PathVariable("dsName") String dsName, @PathVariable String tableName,
@RequestBody List<GenTableColumnEntity> tableFieldList) {
tableColumnService.updateTableField(dsName, tableName, tableFieldList);
return R.ok();
}
}

View File

@@ -0,0 +1,149 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.codegen.entity.GenTemplateEntity;
import com.pig4cloud.pigx.codegen.service.GenTemplateService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import com.pig4cloud.pigx.common.xss.core.XssCleanIgnore;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 模板
*
* @author PIG
* @date 2023-02-21 17:15:44
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/template")
@Tag(description = "template", name = "模板管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class GenTemplateController {
private final GenTemplateService genTemplateService;
/**
* 分页查询
* @param page 分页对象
* @param genTemplate 模板
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('codegen_template_view')")
public R getgenTemplatePage(Page page, GenTemplateEntity genTemplate) {
LambdaQueryWrapper<GenTemplateEntity> wrapper = Wrappers.<GenTemplateEntity>lambdaQuery()
.like(genTemplate.getId() != null, GenTemplateEntity::getId, genTemplate.getId())
.like(StrUtil.isNotEmpty(genTemplate.getTemplateName()), GenTemplateEntity::getTemplateName,
genTemplate.getTemplateName());
return R.ok(genTemplateService.page(page, wrapper));
}
/**
* 查询全部模板
* @return
*/
@Operation(summary = "查询全部", description = "查询全部")
@GetMapping("/list")
@PreAuthorize("@pms.hasPermission('codegen_template_view')")
public R list() {
return R.ok(genTemplateService.list(Wrappers.emptyWrapper()));
}
/**
* 通过id查询模板
* @param id id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('codegen_template_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(genTemplateService.getById(id));
}
/**
* 新增模板
* @param genTemplate 模板
* @return R
*/
@XssCleanIgnore
@Operation(summary = "新增模板", description = "新增模板")
@SysLog("新增模板")
@PostMapping
@PreAuthorize("@pms.hasPermission('codegen_template_add')")
public R save(@RequestBody GenTemplateEntity genTemplate) {
return R.ok(genTemplateService.save(genTemplate));
}
/**
* 修改模板
* @param genTemplate 模板
* @return R
*/
@XssCleanIgnore
@Operation(summary = "修改模板", description = "修改模板")
@SysLog("修改模板")
@PutMapping
@PreAuthorize("@pms.hasPermission('codegen_template_edit')")
public R updateById(@RequestBody GenTemplateEntity genTemplate) {
return R.ok(genTemplateService.updateById(genTemplate));
}
/**
* 通过id删除模板
* @param ids id列表
* @return R
*/
@Operation(summary = "通过id删除模板", description = "通过id删除模板")
@SysLog("通过id删除模板")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('codegen_template_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(genTemplateService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param genTemplate 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('codegen_template_export')")
public List<GenTemplateEntity> export(GenTemplateEntity genTemplate) {
return genTemplateService.list(Wrappers.query(genTemplate));
}
}

View File

@@ -0,0 +1,131 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.codegen.entity.GenTemplateGroupEntity;
import com.pig4cloud.pigx.codegen.service.GenTemplateGroupService;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.excel.annotation.ResponseExcel;
import com.pig4cloud.pigx.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* 模板分组关联表
*
* @author PIG
* @date 2023-02-22 09:25:15
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/templateGroup")
@Tag(description = "templateGroup", name = "模板分组关联表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class GenTemplateGroupController {
private final GenTemplateGroupService genTemplateGroupService;
/**
* 分页查询
* @param page 分页对象
* @param genTemplateGroup 模板分组关联表
* @return
*/
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('codegen_templateGroup_view')")
public R getgenTemplateGroupPage(Page page, GenTemplateGroupEntity genTemplateGroup) {
LambdaQueryWrapper<GenTemplateGroupEntity> wrapper = Wrappers.lambdaQuery();
return R.ok(genTemplateGroupService.page(page, wrapper));
}
/**
* 通过id查询模板分组关联表
* @param groupId id
* @return R
*/
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{groupId}")
@PreAuthorize("@pms.hasPermission('codegen_templateGroup_view')")
public R getById(@PathVariable("groupId") Long groupId) {
return R.ok(genTemplateGroupService.getById(groupId));
}
/**
* 新增模板分组关联表
* @param genTemplateGroup 模板分组关联表
* @return R
*/
@Operation(summary = "新增模板分组关联表", description = "新增模板分组关联表")
@SysLog("新增模板分组关联表")
@PostMapping
@PreAuthorize("@pms.hasPermission('codegen_templateGroup_add')")
public R save(@RequestBody GenTemplateGroupEntity genTemplateGroup) {
return R.ok(genTemplateGroupService.save(genTemplateGroup));
}
/**
* 修改模板分组关联表
* @param genTemplateGroup 模板分组关联表
* @return R
*/
@Operation(summary = "修改模板分组关联表", description = "修改模板分组关联表")
@SysLog("修改模板分组关联表")
@PutMapping
@PreAuthorize("@pms.hasPermission('codegen_templateGroup_edit')")
public R updateById(@RequestBody GenTemplateGroupEntity genTemplateGroup) {
return R.ok(genTemplateGroupService.updateById(genTemplateGroup));
}
/**
* 通过id删除模板分组关联表
* @param ids groupId列表
* @return R
*/
@Operation(summary = "通过id删除模板分组关联表", description = "通过id删除模板分组关联表")
@SysLog("通过id删除模板分组关联表")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('codegen_templateGroup_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(genTemplateGroupService.removeBatchByIds(CollUtil.toList(ids)));
}
/**
* 导出excel 表格
* @param genTemplateGroup 查询条件
* @return excel 文件流
*/
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('codegen_templateGroup_export')")
public List<GenTemplateGroupEntity> export(GenTemplateGroupEntity genTemplateGroup) {
return genTemplateGroupService.list(Wrappers.query(genTemplateGroup));
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.controller;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import com.pig4cloud.pigx.codegen.service.GeneratorService;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipOutputStream;
/**
* 代码生成器
*
* @author lengleng
* @date 2018-07-30
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/generator")
public class GeneratorController {
private final GeneratorService generatorService;
/**
* ZIP 下载生成代码
* @param tableIds 数据表ID
* @param response 流输出对象
*/
@SneakyThrows
@GetMapping("/download")
public void download(String tableIds, HttpServletResponse response) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
// 生成代码
for (String tableId : tableIds.split(StrUtil.COMMA)) {
generatorService.downloadCode(Long.parseLong(tableId), zip);
}
IoUtil.close(zip);
// zip压缩包数据
byte[] data = outputStream.toByteArray();
response.reset();
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment; filename=%s.zip", tableIds));
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
response.setContentType("application/octet-stream; charset=UTF-8");
IoUtil.write(response.getOutputStream(), false, data);
}
/**
* 目标目录生成代码
*/
@ResponseBody
@GetMapping("/code")
public R<String> code(String tableIds) throws Exception {
// 生成代码
for (String tableId : tableIds.split(StrUtil.COMMA)) {
generatorService.generatorCode(Long.valueOf(tableId));
}
return R.ok();
}
/**
* 预览代码
* @param tableId 表ID
* @return
*/
@SneakyThrows
@GetMapping("/preview")
public List<Map<String, String>> preview(Long tableId) {
return generatorService.preview(tableId);
}
/**
* 获取表单设计器初始化数据
* @param dsName 数据源名称
* @param tableName 表名称
* @return json string
*/
@SneakyThrows
@GetMapping("/vform")
public String vform(String dsName, String tableName) {
return generatorService.vform(dsName, tableName);
}
/**
* 获取表单设计器初始化数据
* @param formId 表单ID
* @return json string
*/
@SneakyThrows
@GetMapping("/vform/sfc")
public void vformSfc(Long formId, HttpServletResponse response) {
String result = generatorService.vformSfc(formId);
byte[] data = result.getBytes(StandardCharsets.UTF_8);
response.reset();
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=form.vue");
response.addHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(data.length));
response.setContentType("application/octet-stream; charset=UTF-8");
IoUtil.write(response.getOutputStream(), false, data);
}
}

View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import lombok.Data;
/**
* @author lengleng
* @date 2018/07/29 列属性: https://blog.csdn.net/lkforce/article/details/79557482
*/
@Data
public class ColumnEntity {
/**
* 列表
*/
private String columnName;
/**
* 数据类型
*/
private String dataType;
/**
* JAVA 数据类型
*/
private String javaType;
/**
* 备注
*/
private String comments;
/**
* 驼峰属性
*/
private String caseAttrName;
/**
* 普通属性
*/
private String lowerAttrName;
/**
* 属性类型
*/
private String attrType;
/**
* 其他信息
*/
private String extra;
/**
* 字段类型
*/
private String columnType;
/**
* 是否可以为空
*/
private Boolean nullable;
/**
* 是否隐藏
*/
private Boolean hidden;
}

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import lombok.Data;
/**
* @author lengleng
* @date 2018/8/2 生成配置
*/
@Data
public class GenConfig {
/**
* 数据源name
*/
private String dsName;
/**
* 包名
*/
private String packageName;
/**
* 作者
*/
private String author;
/**
* 模块名称
*/
private String moduleName;
/**
* 表前缀
*/
private String tablePrefix;
/**
* 表名称
*/
private String tableName;
/**
* 表备注
*/
private String comments;
/**
* 代码风格 0 - avue 1 - element 2 - uview
*/
private String style;
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 数据源表
*
* @author lengleng
* @date 2019-03-31 16:00:20
*/
@Data
@TableName("gen_datasource_conf")
@EqualsAndHashCode(callSuper = true)
public class GenDatasourceConf extends Model<GenDatasourceConf> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 名称
*/
private String name;
/**
* 数据库类型
*/
private String dsType;
/**
* 配置类型 0 主机形式 | 1 url形式
*/
private Integer confType;
/**
* 主机地址
*/
private String host;
/**
* 端口
*/
private Integer port;
/**
* jdbc-url
*/
private String url;
/**
* 实例
*/
private String instance;
/**
* 数据库名称
*/
private String dsName;
/**
* 用户名
*/
private String username;
/**
* 密码
*/
private String password;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 修改时间
*/
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 0-正常1-删除
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
private String delFlag;
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 列属性
*
* @author pigx code generator
* @date 2023-02-06 20:16:01
*/
@Data
@TableName("gen_field_type")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "列属性")
public class GenFieldType extends Model<GenFieldType> {
private static final long serialVersionUID = 1L;
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "id")
private Long id;
/**
* 字段类型
*/
@Schema(description = "字段类型")
private String columnType;
/**
* 属性类型
*/
@Schema(description = "属性类型")
private String attrType;
/**
* 属性包名
*/
@Schema(description = "属性包名")
private String packageName;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建人")
private String createBy;
/**
* 修改人
*/
@TableField(fill = FieldFill.UPDATE)
@Schema(description = "修改人")
private String updateBy;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 修改时间
*/
@Schema(description = "修改时间")
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 删除标识0-正常,1-删除)
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description = "删除标记,1:已删除,0:正常")
private String delFlag;
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 生成记录
*
* @author lengleng
* @date 2019-08-12 15:55:35
*/
@Data
@TableName("gen_form_conf")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "生成记录")
public class GenFormConf extends Model<GenFormConf> {
private static final long serialVersionUID = 1L;
/**
* ID
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "ID")
private Long id;
/**
* 数据源名称
*/
@Schema(description = "数据源名称")
private String dsName;
/**
* 表名称
*/
@Schema(description = "表名称")
private String tableName;
/**
* 表单信息
*/
@Schema(description = "表单信息")
private String formInfo;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 修改时间
*/
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 0-正常1-删除
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
private String delFlag;
/**
* 所属租户
*/
@Schema(description = "所属租户", hidden = true)
private Long tenantId;
}

View File

@@ -0,0 +1,98 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 模板分组
*
* @author PIG
* @date 2023-02-21 20:01:53
*/
@Data
@TableName("gen_group")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "模板分组")
public class GenGroupEntity extends Model<GenGroupEntity> {
private static final long serialVersionUID = 1L;
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "id")
private Long id;
/**
* 分组名称
*/
@Schema(description = "分组名称")
private String groupName;
/**
* 分组描述
*/
@Schema(description = "分组描述")
@TableField(fill = FieldFill.INSERT)
private String groupDesc;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建人")
private String createBy;
/**
* 修改人
*/
@TableField(fill = FieldFill.UPDATE)
@Schema(description = "修改人")
private String updateBy;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 修改时间
*/
@Schema(description = "修改时间")
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 删除标识0-正常,1-删除)
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description = "删除标记,1:已删除,0:正常")
private String delFlag;
}

View File

@@ -0,0 +1,193 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
import java.util.List;
/**
* 列属性
*
* @author pigx code generator
* @date 2023-02-06 20:34:55
*/
@Data
@TableName("gen_table")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "列属性")
public class GenTable extends Model<GenTable> {
private static final long serialVersionUID = 1L;
/**
* id
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "id")
private Long id;
/**
* 数据源名称
*/
@Schema(description = "数据源名称")
private String dsName;
/**
* 数据源类型
*/
@Schema(description = "数据源类型")
private String dbType;
/**
* 表名
*/
@Schema(description = "表名")
private String tableName;
/**
* 类名
*/
@Schema(description = "类名")
private String className;
/**
* 说明
*/
@Schema(description = "说明")
private String tableComment;
/**
* 作者
*/
@Schema(description = "作者")
private String author;
/**
* 邮箱
*/
@Schema(description = "邮箱")
private String email;
/**
* 项目包名
*/
@Schema(description = "项目包名")
private String packageName;
/**
* 项目版本号
*/
@Schema(description = "项目版本号")
private String version;
/**
* 生成方式 0zip压缩包 1自定义目录
*/
@Schema(description = "生成方式 0zip压缩包 1自定义目录")
private String generatorType;
/**
* 后端生成路径
*/
@Schema(description = "后端生成路径")
private String backendPath;
/**
* 前端生成路径
*/
@Schema(description = "前端生成路径")
private String frontendPath;
/**
* 模块名
*/
@Schema(description = "模块名")
private String moduleName;
/**
* 功能名
*/
@Schema(description = "功能名")
private String functionName;
/**
* 表单布局 1一列 2两列
*/
@Schema(description = "表单布局 1一列 2两列")
private Integer formLayout;
/**
* 基类ID
*/
@Schema(description = "基类ID")
private Long baseclassId;
/**
* 创建时间
*/
@Schema(description = "创建时间")
private LocalDateTime createTime;
/**
* 代码生成风格
*/
private Long style;
/**
* 子表名称
*/
private String childTableName;
/**
* 主表关联键
*/
private String mainField;
/**
* 子表关联键
*/
private String childField;
/**
* 字段列表
*/
@TableField(exist = false)
private List<GenTableColumnEntity> fieldList;
/**
* 子表字段列表
*/
@TableField(exist = false)
private List<GenTableColumnEntity> childFieldList;
/**
* 代码风格(模版分组信息)
*/
@TableField(exist = false)
private List<GenGroupEntity> groupList;
}

View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* @author lengleng
* @date 2023-02-06
*
* 记录表字段的配置信息
*/
@Data
@TableName("gen_table_column")
@EqualsAndHashCode(callSuper = true)
public class GenTableColumnEntity extends Model<GenDatasourceConf> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
private Long id;
/**
* 数据源名
*/
private String dsName;
/**
* 表名称
*/
private String tableName;
/**
* 字段名称
*/
private String fieldName;
/**
* 排序
*/
private Integer sort;
/**
* 字段类型
*/
private String fieldType;
/**
* 字段说明
*/
private String fieldComment;
/**
* 属性名
*/
private String attrName;
/**
* 属性类型
*/
private String attrType;
/**
* 属性包名
*/
private String packageName;
/**
* 自动填充
*/
private String autoFill;
/**
* 主键 0否 1
*/
private String primaryPk;
/**
* 基类字段 0否 1
*/
private String baseField;
/**
* 表单项 0否 1
*/
private String formItem;
/**
* 表单必填 0否 1
*/
private String formRequired;
/**
* 表单类型
*/
private String formType;
/**
* 表单效验
*/
private String formValidator;
/**
* 列表项 0否 1
*/
private String gridItem;
/**
* 列表排序 0否 1
*/
private String gridSort;
/**
* 查询项 0否 1
*/
private String queryItem;
/**
* 查询方式
*/
private String queryType;
/**
* 查询表单类型
*/
private String queryFormType;
/**
* 字段字典类型
*/
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String fieldDict;
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.time.LocalDateTime;
/**
* 模板
*
* @author PIG
* @date 2023-02-21 17:15:44
*/
@Data
@TableName("gen_template")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "模板")
public class GenTemplateEntity extends Model<GenTemplateEntity> {
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description = "主键")
private Long id;
/**
* 模板名称
*/
@Schema(description = "模板名称")
private String templateName;
/**
* 模板路径
*/
@Schema(description = "模板路径")
private String generatorPath;
/**
* 模板描述
*/
@Schema(description = "模板描述")
private String templateDesc;
/**
* 模板代码
*/
@Schema(description = "模板代码")
private String templateCode;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description = "创建人")
private String createBy;
/**
* 修改人
*/
@TableField(fill = FieldFill.UPDATE)
@Schema(description = "修改人")
private String updateBy;
/**
* 创建时间
*/
@Schema(description = "创建时间")
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createTime;
/**
* 修改时间
*/
@Schema(description = "修改时间")
@TableField(fill = FieldFill.UPDATE)
private LocalDateTime updateTime;
/**
* 删除标识0-正常,1-删除)
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description = "删除标记,1:已删除,0:正常")
private String delFlag;
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* 模板分组关联表
*
* @author PIG
* @date 2023-02-22 09:25:15
*/
@Data
@TableName("gen_template_group")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@Schema(description = "模板分组关联表")
public class GenTemplateGroupEntity extends Model<GenTemplateGroupEntity> {
private static final long serialVersionUID = 1L;
/**
* 分组id
*/
@Schema(description = "分组id")
private Long groupId;
/**
* 模板id
*/
@Schema(description = "模板id")
private Long templateId;
}

View File

@@ -0,0 +1,66 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.entity;
import lombok.Data;
import java.util.List;
/**
* @author lengleng
* @date 2018/07/29 表属性: https://blog.csdn.net/lkforce/article/details/79557482
*/
@Data
public class TableEntity {
/**
* 名称
*/
private String tableName;
/**
* 备注
*/
private String comments;
/**
* 主键
*/
private ColumnEntity pk;
/**
* 列名
*/
private List<ColumnEntity> columns;
/**
* 驼峰类型
*/
private String caseClassName;
/**
* 普通类型
*/
private String lowerClassName;
/**
* 数据库类型 (用于根据数据库个性化)
*/
private String dbType;
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.pig4cloud.pigx.codegen.entity.GenDatasourceConf;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 数据源表
*
* @author lengleng
* @date 2019-03-31 16:00:20
*/
@Mapper
public interface GenDatasourceConfMapper extends PigxBaseMapper<GenDatasourceConf> {
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.LinkedHashMap;
import java.util.List;
/**
* 动态查询
*
* @author lengleng
* @date 2022-07-09
*/
@Mapper
public interface GenDynamicMapper {
@InterceptorIgnore(tenantLine = "true")
List<LinkedHashMap<String, Object>> dynamicQuerySql(@Param("value") String sq);
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.pig4cloud.pigx.codegen.entity.GenFieldType;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Set;
/**
* 列属性
*
* @author pigx code generator
* @date 2023-02-06 20:16:01
*/
@Mapper
public interface GenFieldTypeMapper extends PigxBaseMapper<GenFieldType> {
/**
* 根据tableId获取包列表
* @param dsName 数据源名称
* @param tableName 表名称
* @return 返回包列表
*/
Set<String> getPackageByTableId(@Param("dsName") String dsName, @Param("tableName") String tableName);
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 生成记录
*
* @author lengleng
* @date 2019-08-12 15:55:35
*/
@Mapper
public interface GenFormConfMapper extends PigxBaseMapper<GenFormConf> {
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.pig4cloud.pigx.codegen.entity.GenGroupEntity;
import com.pig4cloud.pigx.codegen.util.vo.GroupVo;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/**
* 模板分组
*
* @author PIG
* @date 2023-02-21 20:01:53
*/
@Mapper
public interface GenGroupMapper extends PigxBaseMapper<GenGroupEntity> {
GroupVo getGroupVoById(@Param("id") Long id);
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.pig4cloud.pigx.codegen.entity.GenTableColumnEntity;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 列属性
*
* @author pigx code generator
* @date 2023-02-06 20:16:01
*/
@Mapper
public interface GenTableColumnMapper extends PigxBaseMapper<GenTableColumnEntity> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.pig4cloud.pigx.codegen.entity.GenTable;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 列属性
*
* @author pigx code generator
* @date 2023-02-06 20:34:55
*/
@Mapper
public interface GenTableMapper extends PigxBaseMapper<GenTable> {
}

View File

@@ -0,0 +1,33 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pigx.codegen.entity.GenTemplateGroupEntity;
import org.apache.ibatis.annotations.Mapper;
/**
* 模板分组关联表
*
* @author PIG
* @date 2023-02-22 09:25:15
*/
@Mapper
public interface GenTemplateGroupMapper extends BaseMapper<GenTemplateGroupEntity> {
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.pig4cloud.pigx.codegen.entity.GenTemplateEntity;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* 模板
*
* @author PIG
* @date 2023-02-21 17:15:44
*/
@Mapper
public interface GenTemplateMapper extends PigxBaseMapper<GenTemplateEntity> {
/**
* 根据groupId查询 模板
* @param groupId
* @return
*/
List<GenTemplateEntity> listTemplateById(Long groupId);
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 支持 db2 代码生成器
*
* @author lengleng
* @date 2020-12-11
*/
@Mapper
public interface GeneratorDB2Mapper extends GeneratorMapper {
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 支持 达梦 代码生成器
*
* @author lengleng
* @date 2022-03-24
*/
@Mapper
public interface GeneratorDmMapper extends GeneratorMapper {
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 支持 瀚高数据库 代码生成器
*
* @author lengleng
* @date 2023-04-26
*/
@Mapper
public interface GeneratorHighGoMapper extends GeneratorMapper {
}

View File

@@ -0,0 +1,97 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.codegen.entity.ColumnEntity;
import com.pig4cloud.pigx.common.data.datascope.PigxBaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* 代码生成器
*
* @author lengleng
* @date 2018-07-30
*/
public interface GeneratorMapper extends PigxBaseMapper<ColumnEntity> {
/**
* 查询全部的表
* @return
*/
@InterceptorIgnore(tenantLine = "true")
List<Map<String, Object>> queryTable();
/**
* 分页查询表格
* @param page 分页信息
* @param tableName 表名称
* @return
*/
@InterceptorIgnore(tenantLine = "true")
IPage<Map<String, Object>> queryTable(Page page, @Param("tableName") String tableName);
/**
* 查询表信息
* @param tableName 表名称
* @param dsName 数据源名称
* @return
*/
@DS("#last")
@InterceptorIgnore(tenantLine = "true")
Map<String, String> queryTable(@Param("tableName") String tableName, String dsName);
/**
* 分页查询表分页信息
* @param page
* @param tableName
* @param dsName
* @return
*/
@DS("#last")
@InterceptorIgnore(tenantLine = "true")
IPage<ColumnEntity> selectTableColumn(Page page, @Param("tableName") String tableName,
@Param("dsName") String dsName);
/**
* 查询表全部列信息
* @param tableName
* @param dsName
* @return
*/
@DS("#last")
@InterceptorIgnore(tenantLine = "true")
List<ColumnEntity> selectTableColumn(@Param("tableName") String tableName, @Param("dsName") String dsName);
/**
* 查询表全部列信息
* @param tableName 表名称
* @param dsName 数据源名称
* @return
*/
@DS("#last")
@InterceptorIgnore(tenantLine = "true")//fix pigX功能bug 少传参数
List<Map<String, String>> selectMapTableColumn(@Param("tableName") String tableName, @Param("dsName")String dsName);
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 支持 SQL SERVER 代码生成器
*
* @author lengleng
* @date 2020-12-11
*/
@Mapper
public interface GeneratorMssqlMapper extends GeneratorMapper {
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 支持 mysql 代码生成器
*
* @author lengleng
* @date 2020-12-11
*/
@Mapper
public interface GeneratorMysqlMapper extends GeneratorMapper {
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 支持 Oracle 代码生成器
*
* @author lengleng
* @date 2020-12-11
*/
@Mapper
public interface GeneratorOracleMapper extends GeneratorMapper {
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.mapper;
import org.apache.ibatis.annotations.Mapper;
/**
* 支持 PostgreSQL 代码生成器
*
* @author lengleng
* @date 2020-12-11
*/
@Mapper
public interface GeneratorPgMapper extends GeneratorMapper {
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.codegen.entity.GenDatasourceConf;
/**
* 数据源表
*
* @author lengleng
* @date 2019-03-31 16:00:20
*/
public interface GenDatasourceConfService extends IService<GenDatasourceConf> {
/**
* 保存数据源并且加密
* @param genDatasourceConf
* @return
*/
Boolean saveDsByEnc(GenDatasourceConf genDatasourceConf);
/**
* 更新数据源
* @param genDatasourceConf
* @return
*/
Boolean updateDsByEnc(GenDatasourceConf genDatasourceConf);
/**
* 更新动态数据的数据源列表
* @param datasourceConf
* @return
*/
void addDynamicDataSource(GenDatasourceConf datasourceConf);
/**
* 校验数据源配置是否有效
* @param datasourceConf 数据源信息
* @return 有效/无效
*/
Boolean checkDataSource(GenDatasourceConf datasourceConf);
/**
* 通过数据源名称删除
* @param dsIds 数据源ID
* @return
*/
Boolean removeByDsId(Long[] dsIds);
}

View File

@@ -0,0 +1,41 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.codegen.entity.GenFieldType;
import java.util.Set;
/**
* 列属性
*
* @author pigx code generator
* @date 2023-02-06 20:16:01
*/
public interface GenFieldTypeService extends IService<GenFieldType> {
/**
* 根据tableId获取包列表
* @param dsName 数据源名称
* @param tableName 表名称
* @return 返回包列表
*/
Set<String> getPackageByTableId(String dsName, String tableName);
}

View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2018-2025, lengleng All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: lengleng (wangiegie@gmail.com)
*/
package com.pig4cloud.pigx.codegen.service;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import com.pig4cloud.pigx.codegen.entity.GenFormConf;
import java.util.List;
import java.util.Map;
/**
* 表单管理
*
* @author lengleng
* @date 2019-08-12 15:55:35
*/
public interface GenFormConfService extends IService<GenFormConf> {
/**
* 解析 form json
* @param formInfo json
* @return 字段
*/
Map<String, List<JSONObject>> parse(String formInfo);
}

Some files were not shown because too many files have changed in this diff Show More