新增:微信支付及回调
This commit is contained in:
@@ -53,7 +53,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
"/api/wx-login/loginByMpWxPhone",
|
||||
"/api/wxWorkQrConnect",
|
||||
"/api/sys/user-plan-log/wx-pay/**",
|
||||
"/api/wx-official/**"
|
||||
"/api/wx-official/**",
|
||||
"/lvQ4EoivKJ.txt"
|
||||
)
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
|
||||
@@ -73,10 +73,10 @@ public class SocketIOConfig implements InitializingBean {
|
||||
config.setKeyStorePassword("123456"); // 设置证书密码
|
||||
|
||||
// 启动socket服务
|
||||
SocketIOServer server = new SocketIOServer(config);
|
||||
server.addListeners(socketIOHandler);
|
||||
server.start();
|
||||
ClientCache.setSocketIOServer(server);
|
||||
logger.debug("Netty SocketIO启动:{}:{}",host,port);
|
||||
// SocketIOServer server = new SocketIOServer(config);
|
||||
// server.addListeners(socketIOHandler);
|
||||
// server.start();
|
||||
// ClientCache.setSocketIOServer(server);
|
||||
// logger.debug("Netty SocketIO启动:{}:{}",host,port);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Company;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.CompanyService;
|
||||
import com.gxwebsoft.common.system.service.OrderInfoService;
|
||||
import com.gxwebsoft.common.system.service.OrderService;
|
||||
import com.gxwebsoft.common.system.entity.Order;
|
||||
import com.gxwebsoft.common.system.param.OrderParam;
|
||||
@@ -36,6 +38,8 @@ public class OrderController extends BaseController {
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:list')")
|
||||
@OperationLog
|
||||
@@ -71,19 +75,32 @@ public class OrderController extends BaseController {
|
||||
public ApiResult<?> save(@RequestBody Order order) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
long timeMillis = System.currentTimeMillis();
|
||||
long orderNo = IdUtil.getSnowflakeNextId();
|
||||
if (loginUser != null) {
|
||||
order.setUserId(loginUser.getUserId());
|
||||
order.setOpenid(loginUser.getOpenid());
|
||||
}
|
||||
order.setOrderNo(Long.toString(orderNo));
|
||||
order.setRealName(loginUser.getRealName());
|
||||
order.setStartTime(timeMillis / 1000);
|
||||
order.setAddTime(timeMillis / 1000);
|
||||
order.setPhone(loginUser.getPhone());
|
||||
order.setVersion(10);
|
||||
if (orderService.save(order)) {
|
||||
System.out.println("order = " + order);
|
||||
// 延长到期时间
|
||||
final Company company = companyService.getByTenantIdRel(order.getTenantId());
|
||||
company.setStatus(1);
|
||||
// company.setExpirationTime(new Date());
|
||||
companyService.updateById(company);
|
||||
return success("添加成功");
|
||||
order.getOrderInfoList().forEach(d -> {
|
||||
d.setOid(order.getOrderId());
|
||||
d.setTimeFlag(timeMillis);
|
||||
d.setVersion(10);
|
||||
d.setOrderTime(timeMillis / 1000);
|
||||
});
|
||||
orderInfoService.saveBatch(order.getOrderInfoList());
|
||||
// 创建微信订单
|
||||
if (order.getPayType().equals(1)) {
|
||||
return success("下单成功",orderService.createWxOrder(order));
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
return fail("下单失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:order:update')")
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.OrderInfoService;
|
||||
import com.gxwebsoft.common.system.entity.OrderInfo;
|
||||
import com.gxwebsoft.common.system.param.OrderInfoParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-10 18:02:54
|
||||
*/
|
||||
@Api(tags = "管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/order-info")
|
||||
public class OrderInfoController extends BaseController {
|
||||
@Resource
|
||||
private OrderInfoService orderInfoService;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<OrderInfo>> page(OrderInfoParam param) {
|
||||
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(orderInfoService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(orderInfoService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部")
|
||||
@GetMapping()
|
||||
public ApiResult<List<OrderInfo>> list(OrderInfoParam param) {
|
||||
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("create_time desc");
|
||||
return success(orderInfoService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(orderInfoService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<OrderInfo> get(@PathVariable("id") Integer id) {
|
||||
return success(orderInfoService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(orderInfoService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody OrderInfo orderInfo) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
}
|
||||
if (orderInfoService.save(orderInfo)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody OrderInfo orderInfo) {
|
||||
if (orderInfoService.updateById(orderInfo)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (orderInfoService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<OrderInfo> list) {
|
||||
if (orderInfoService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<OrderInfo> batchParam) {
|
||||
if (batchParam.update(orderInfoService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:orderInfo:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (orderInfoService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Merchant;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.service.PaymentService;
|
||||
import com.gxwebsoft.common.system.entity.Payment;
|
||||
import com.gxwebsoft.common.system.param.PaymentParam;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.annotation.OperationLog;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付方式控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-11 12:39:11
|
||||
*/
|
||||
@Api(tags = "支付方式管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/system/payment")
|
||||
public class PaymentController extends BaseController {
|
||||
@Resource
|
||||
private PaymentService paymentService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("分页查询支付方式")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<Payment>> page(PaymentParam param) {
|
||||
PageParam<Payment, PaymentParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc, create_time asc");
|
||||
return success(paymentService.page(page, page.getWrapper()));
|
||||
// 使用关联查询
|
||||
// return success(paymentService.pageRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("查询全部支付方式")
|
||||
@GetMapping()
|
||||
public ApiResult<List<Payment>> list(PaymentParam param) {
|
||||
PageParam<Payment, PaymentParam> page = new PageParam<>(param);
|
||||
page.setDefaultOrder("sort_number asc, create_time asc");
|
||||
return success(paymentService.list(page.getOrderWrapper()));
|
||||
// 使用关联查询
|
||||
//return success(paymentService.listRel(param));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:list')")
|
||||
@OperationLog
|
||||
@ApiOperation("根据id查询支付方式")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<Payment> get(@PathVariable("id") Integer id) {
|
||||
return success(paymentService.getById(id));
|
||||
// 使用关联查询
|
||||
//return success(paymentService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("添加支付方式")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody Payment payment) {
|
||||
if (paymentService.count(new LambdaQueryWrapper<Payment>().eq(Payment::getCode,payment.getCode())) > 0) {
|
||||
return fail(payment.getName() + "已存在");
|
||||
}
|
||||
if (paymentService.save(payment)) {
|
||||
String key = "Payment:" + payment.getCode() + ":" + getTenantId();
|
||||
redisUtil.set(key,payment);
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("修改支付方式")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody Payment payment) {
|
||||
if (paymentService.updateById(payment)) {
|
||||
String key = "Payment:" + payment.getCode() + ":" + getTenantId();
|
||||
redisUtil.set(key,payment);
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("删除支付方式")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
final Payment payment = paymentService.getById(id);
|
||||
System.out.println("payment = " + payment);
|
||||
String key = "Payment:" + payment.getCode() + ":" + getTenantId();
|
||||
redisUtil.delete(key);
|
||||
if (paymentService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:save')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量添加支付方式")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<Payment> list) {
|
||||
if (paymentService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:update')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量修改支付方式")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<Payment> batchParam) {
|
||||
if (batchParam.update(paymentService, "id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('sys:payment:remove')")
|
||||
@OperationLog
|
||||
@ApiOperation("批量删除支付方式")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (paymentService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Api(tags = "域名所有权验证")
|
||||
@RestController
|
||||
@RequestMapping("/lvQ4EoivKJ.txt")
|
||||
public class VerifyTxt {
|
||||
|
||||
@ApiOperation("域名所有权验证")
|
||||
@GetMapping()
|
||||
public String verify(){
|
||||
return "cbfbfe827744f1ebfaf03bfe2a0def6a";
|
||||
}
|
||||
}
|
||||
@@ -268,7 +268,12 @@ public class WxLoginController extends BaseController {
|
||||
final String response = HttpUtil.get(apiUrl,map);
|
||||
System.out.println("response = " + response);
|
||||
final JSONObject jsonObject = JSONObject.parseObject(response);
|
||||
return fail("更新失败",null);
|
||||
final String openid = jsonObject.getString("openid");
|
||||
jsonObject.getString("session_key");
|
||||
jsonObject.getString("unionid");
|
||||
System.out.println("openid = " + openid);
|
||||
System.out.println("loginUser = " + loginUser);
|
||||
return success("获取成功",jsonObject);
|
||||
}
|
||||
|
||||
@ApiOperation("获取微信小程序码")
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
package com.gxwebsoft.common.system.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
||||
import com.alipay.api.response.AlipayTradeAppPayResponse;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.utils.AlipayConfigUtil;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.Order;
|
||||
import com.gxwebsoft.common.system.entity.Setting;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.common.system.mapper.SettingMapper;
|
||||
import com.gxwebsoft.common.system.param.SettingParam;
|
||||
import com.gxwebsoft.common.system.service.OrderInfoService;
|
||||
import com.gxwebsoft.common.system.service.OrderService;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import com.gxwebsoft.common.system.service.UserService;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationConfig;
|
||||
import com.wechat.pay.java.core.notification.NotificationParser;
|
||||
import com.wechat.pay.java.core.notification.RSANotificationConfig;
|
||||
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.gxwebsoft.common.core.constants.OrderConstants.PAY_STATUS_NO_PAY;
|
||||
import static com.gxwebsoft.common.core.constants.OrderConstants.PAY_STATUS_SUCCESS;
|
||||
|
||||
/**
|
||||
* 会员特权购买记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2023-06-20 18:07:50
|
||||
*/
|
||||
@Api(tags = "会员特权购买记录表管理")
|
||||
@RestController
|
||||
@RequestMapping("/api/love/user-plan-log")
|
||||
public class WxPayNotifyController extends BaseController {
|
||||
@Resource
|
||||
private OrderService orderService;
|
||||
@Resource
|
||||
private ConfigProperties config;
|
||||
@Resource
|
||||
private SettingMapper settingMapper;
|
||||
|
||||
@ApiModelProperty("异步通知")
|
||||
@PostMapping("/wx-pay/notify/{tenantId}")
|
||||
public String wxNotify(@RequestHeader Map<String, String> header, @RequestBody String body, @PathVariable("tenantId") Integer tenantId) {
|
||||
System.out.println("异步通知*************** = ");
|
||||
System.out.println("request header = " + header);
|
||||
System.out.println("request body = " + body);
|
||||
System.out.println("tenantId = " + tenantId);
|
||||
|
||||
// 获取支付配置信息用于解密
|
||||
final SettingParam param = new SettingParam();
|
||||
param.setSettingKey("payment");
|
||||
param.setTenantId(tenantId);
|
||||
final String uploadPath = config.getUploadPath(); // 服务器本地路径
|
||||
final Setting payment = settingMapper.getBySettingKeyIgnore(param);
|
||||
final JSONObject jsonObject = JSONObject.parseObject(payment.getContent());
|
||||
final String apiV3key = jsonObject.getString("wechatApiKey");
|
||||
final String apiclientCert = uploadPath.concat("file").concat(jsonObject.getString("apiclientCert"));
|
||||
|
||||
// System.out.println("apiV3key ====== " + apiV3key);
|
||||
// System.out.println("payment ===== " + payment);
|
||||
|
||||
com.wechat.pay.java.core.notification.RequestParam requestParam = new com.wechat.pay.java.core.notification.RequestParam.Builder()
|
||||
.serialNumber(header.get("wechatpay-serial"))
|
||||
.nonce(header.get("wechatpay-nonce"))
|
||||
.signature(header.get("wechatpay-signature"))
|
||||
.timestamp(header.get("wechatpay-timestamp"))
|
||||
.body(body)
|
||||
.build();
|
||||
|
||||
// 如果已经初始化了 RSAAutoCertificateConfig,可直接使用
|
||||
// 没有的话,则构造一个
|
||||
NotificationConfig config = new RSANotificationConfig.Builder()
|
||||
.apiV3Key(apiV3key)
|
||||
.certificatesFromPath(apiclientCert)
|
||||
.build();
|
||||
|
||||
// 初始化 NotificationParser
|
||||
NotificationParser parser = new NotificationParser(config);
|
||||
|
||||
// 以支付通知回调为例,验签、解密并转换成 Transaction
|
||||
try {
|
||||
Transaction transaction = parser.parse(requestParam, Transaction.class);
|
||||
final String outTradeNo = transaction.getOutTradeNo();
|
||||
final String transactionId = transaction.getTransactionId();
|
||||
final Integer total = transaction.getAmount().getTotal();
|
||||
final String tradeStateDesc = transaction.getTradeStateDesc();
|
||||
// final Transaction.TradeStateEnum tradeState = transaction.getTradeState();
|
||||
// final Transaction.TradeTypeEnum tradeType = transaction.getTradeType();
|
||||
// System.out.println("transaction = " + transaction);
|
||||
// System.out.println("tradeStateDesc = " + tradeStateDesc);
|
||||
// System.out.println("tradeType = " + tradeType);
|
||||
// System.out.println("tradeState = " + tradeState);
|
||||
// System.out.println("outTradeNo = " + outTradeNo);
|
||||
// System.out.println("amount = " + total);
|
||||
|
||||
if (StrUtil.equals("支付成功", tradeStateDesc)) {
|
||||
// 1. 查询要处理的订单
|
||||
Order order = orderService.getByOutTradeNo(outTradeNo);
|
||||
// 2. 已支付则跳过
|
||||
if (order.getPayStatus().equals(PAY_STATUS_SUCCESS)) {
|
||||
return "SUCCESS";
|
||||
}
|
||||
// 2. 未支付则处理更新订单状态
|
||||
if (order.getPayStatus().equals(PAY_STATUS_NO_PAY)) {
|
||||
// 5. TODO 处理订单状态
|
||||
order.setPayStatus(PAY_STATUS_SUCCESS);
|
||||
order.setPayTime(DateUtil.date());
|
||||
order.setTransactionId(transactionId);
|
||||
// 实际付款金额:Integer除以100后转BigDecimal
|
||||
DecimalFormat df = new DecimalFormat("0.00");
|
||||
final String format = df.format(total / 100);
|
||||
order.setPayPrice(new BigDecimal(format));
|
||||
orderService.updateByOutTradeNo(order);
|
||||
return "SUCCESS";
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
System.out.println($e.getMessage());
|
||||
}
|
||||
|
||||
return "fail";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -72,9 +72,18 @@ public class Merchant implements Serializable {
|
||||
@ApiModelProperty(value = "资质图片")
|
||||
private String files;
|
||||
|
||||
@ApiModelProperty(value = "营业时间")
|
||||
private String businessTime;
|
||||
|
||||
@ApiModelProperty(value = "商户简介")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty(value = "是否自营")
|
||||
private Integer ownStore;
|
||||
|
||||
@ApiModelProperty(value = "每小时价格")
|
||||
private BigDecimal price;
|
||||
|
||||
@ApiModelProperty(value = "是否推荐")
|
||||
private Integer recommend;
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
@@ -66,9 +67,15 @@ public class Order implements Serializable {
|
||||
@ApiModelProperty(value = "联系电话")
|
||||
private String phone;
|
||||
|
||||
@ApiModelProperty(value = "订单总额")
|
||||
private BigDecimal totalPrice;
|
||||
|
||||
@ApiModelProperty(value = "付款时间")
|
||||
private Date payTime;
|
||||
|
||||
@ApiModelProperty(value = "1微信支付,2积分,3支付宝,4现金,5POS机,6VIP月卡,7VIP年卡,8VIP次卡,9IC月卡,10IC年卡,11IC次卡,12免费,13VIP充值卡,14IC充值卡,15积分支付,16VIP季卡,17IC季卡")
|
||||
private Integer payType;
|
||||
|
||||
@ApiModelProperty(value = "支付流水号")
|
||||
private String transactionId;
|
||||
|
||||
@@ -130,6 +137,19 @@ public class Order implements Serializable {
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
@ApiModelProperty(value = "用于微信支付")
|
||||
@TableField(exist = false)
|
||||
private String openid;
|
||||
|
||||
@ApiModelProperty(value = "预约详情开始时间数组")
|
||||
private Long startTime;
|
||||
|
||||
@ApiModelProperty(value = "下单时间")
|
||||
private Long addTime;
|
||||
|
||||
@ApiModelProperty(value = "系统版本")
|
||||
private Integer version;
|
||||
|
||||
@ApiModelProperty(value = "租户名称")
|
||||
@TableField(exist = false)
|
||||
private String tenantName;
|
||||
@@ -138,4 +158,8 @@ public class Order implements Serializable {
|
||||
@TableField(exist = false)
|
||||
private Integer companyId;
|
||||
|
||||
@ApiModelProperty(value = "订单详情")
|
||||
@TableField(exist = false)
|
||||
private List<OrderInfo> orderInfoList;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
package com.gxwebsoft.common.system.entity;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import java.io.Serializable;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-10 18:02:54
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "OrderInfo对象", description = "")
|
||||
@TableName("sys_order_info")
|
||||
public class OrderInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "关联订单表id")
|
||||
private Integer oid;
|
||||
|
||||
@ApiModelProperty(value = "关联场馆id")
|
||||
private Integer sid;
|
||||
|
||||
@ApiModelProperty(value = "关联场地id")
|
||||
private Integer fid;
|
||||
|
||||
@ApiModelProperty(value = "场馆")
|
||||
private String siteName;
|
||||
|
||||
@ApiModelProperty(value = "场地")
|
||||
private String fieldName;
|
||||
|
||||
@ApiModelProperty(value = "预约时间段")
|
||||
private String dateTime;
|
||||
|
||||
@ApiModelProperty(value = "单价")
|
||||
private BigDecimal price;
|
||||
|
||||
@ApiModelProperty(value = "儿童价")
|
||||
private BigDecimal childrenPrice;
|
||||
|
||||
@ApiModelProperty(value = "成人人数")
|
||||
private Integer adultNum;
|
||||
|
||||
@ApiModelProperty(value = "儿童人数")
|
||||
private Integer childrenNum;
|
||||
|
||||
@ApiModelProperty(value = "1已付款,2未付款,3无需付款或占用状态")
|
||||
private Integer payStatus;
|
||||
|
||||
@ApiModelProperty(value = "是否免费:1免费、2收费")
|
||||
private Integer isFree;
|
||||
|
||||
@ApiModelProperty(value = "是否支持儿童票:1支持,2不支持")
|
||||
private Integer isChildren;
|
||||
|
||||
@ApiModelProperty(value = "预订类型:1全场,2半场")
|
||||
private Integer type;
|
||||
|
||||
@ApiModelProperty(value = "组合数据:日期+时间段+场馆id+场地id")
|
||||
private String mergeData;
|
||||
|
||||
@ApiModelProperty(value = "开场时间")
|
||||
private Integer startTime;
|
||||
|
||||
@ApiModelProperty(value = "下单时间")
|
||||
private Long orderTime;
|
||||
|
||||
@ApiModelProperty(value = "毫秒时间戳")
|
||||
private Long timeFlag;
|
||||
|
||||
@ApiModelProperty(value = "系统版本")
|
||||
private Integer version;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.gxwebsoft.common.system.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 支付方式
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-11 12:39:11
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value = "Payment对象", description = "支付方式")
|
||||
@TableName("sys_payment")
|
||||
public class Payment implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "ID")
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "支付方式")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "标识")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty(value = "支付图标")
|
||||
private String image;
|
||||
|
||||
@ApiModelProperty(value = "微信商户号类型 1普通商户2子商户")
|
||||
private Integer wechatType;
|
||||
|
||||
@ApiModelProperty(value = "应用ID")
|
||||
private String appId;
|
||||
|
||||
@ApiModelProperty(value = "商户号")
|
||||
private String mchId;
|
||||
|
||||
@ApiModelProperty(value = "设置APIv3密钥")
|
||||
private String apiKey;
|
||||
|
||||
@ApiModelProperty(value = "证书文件 (CERT)")
|
||||
private String apiclientCert;
|
||||
|
||||
@ApiModelProperty(value = "证书文件 (KEY)")
|
||||
private String apiclientKey;
|
||||
|
||||
@ApiModelProperty(value = "商户证书序列号")
|
||||
private String merchantSerialNumber;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String comments;
|
||||
|
||||
@ApiModelProperty(value = "文章排序(数字越小越靠前)")
|
||||
private Integer sortNumber;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0未启用, 1启用")
|
||||
private Boolean status;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@TableLogic
|
||||
private Integer deleted;
|
||||
|
||||
@ApiModelProperty(value = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
@ApiModelProperty(value = "注册时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "修改时间")
|
||||
private Date updateTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.gxwebsoft.common.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gxwebsoft.common.system.entity.OrderInfo;
|
||||
import com.gxwebsoft.common.system.param.OrderInfoParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Mapper
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-10 18:02:54
|
||||
*/
|
||||
public interface OrderInfoMapper extends BaseMapper<OrderInfo> {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param param 查询参数
|
||||
* @return List<OrderInfo>
|
||||
*/
|
||||
List<OrderInfo> selectPageRel(@Param("page") IPage<OrderInfo> page,
|
||||
@Param("param") OrderInfoParam param);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<User>
|
||||
*/
|
||||
List<OrderInfo> selectListRel(@Param("param") OrderInfoParam param);
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.gxwebsoft.common.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gxwebsoft.common.system.entity.Order;
|
||||
@@ -34,4 +35,10 @@ public interface OrderMapper extends BaseMapper<Order> {
|
||||
*/
|
||||
List<Order> selectListRel(@Param("param") OrderParam param);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
List<Order> getByOutTradeNo(OrderParam param);
|
||||
|
||||
@InterceptorIgnore(tenantLine = "true")
|
||||
void updateByOutTradeNo(@Param("param") Order outTradeNo);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.gxwebsoft.common.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.gxwebsoft.common.system.entity.Payment;
|
||||
import com.gxwebsoft.common.system.param.PaymentParam;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付方式Mapper
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-11 12:39:11
|
||||
*/
|
||||
public interface PaymentMapper extends BaseMapper<Payment> {
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param param 查询参数
|
||||
* @return List<Payment>
|
||||
*/
|
||||
List<Payment> selectPageRel(@Param("page") IPage<Payment> page,
|
||||
@Param("param") PaymentParam param);
|
||||
|
||||
/**
|
||||
* 查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<User>
|
||||
*/
|
||||
List<Payment> selectListRel(@Param("param") PaymentParam param);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?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.gxwebsoft.common.system.mapper.OrderInfoMapper">
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*
|
||||
FROM sys_order_info a
|
||||
<where>
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.id}
|
||||
</if>
|
||||
<if test="param.oid != null">
|
||||
AND a.oid = #{param.oid}
|
||||
</if>
|
||||
<if test="param.sid != null">
|
||||
AND a.sid = #{param.sid}
|
||||
</if>
|
||||
<if test="param.fid != null">
|
||||
AND a.fid = #{param.fid}
|
||||
</if>
|
||||
<if test="param.siteName != null">
|
||||
AND a.site_name LIKE CONCAT('%', #{param.siteName}, '%')
|
||||
</if>
|
||||
<if test="param.fieldName != null">
|
||||
AND a.field_name LIKE CONCAT('%', #{param.fieldName}, '%')
|
||||
</if>
|
||||
<if test="param.dateTime != null">
|
||||
AND a.date_time LIKE CONCAT('%', #{param.dateTime}, '%')
|
||||
</if>
|
||||
<if test="param.price != null">
|
||||
AND a.price = #{param.price}
|
||||
</if>
|
||||
<if test="param.childrenPrice != null">
|
||||
AND a.children_price = #{param.childrenPrice}
|
||||
</if>
|
||||
<if test="param.adultNum != null">
|
||||
AND a.adult_num = #{param.adultNum}
|
||||
</if>
|
||||
<if test="param.childrenNum != null">
|
||||
AND a.children_num = #{param.childrenNum}
|
||||
</if>
|
||||
<if test="param.payStatus != null">
|
||||
AND a.pay_status = #{param.payStatus}
|
||||
</if>
|
||||
<if test="param.isFree != null">
|
||||
AND a.is_free = #{param.isFree}
|
||||
</if>
|
||||
<if test="param.isChildren != null">
|
||||
AND a.is_children = #{param.isChildren}
|
||||
</if>
|
||||
<if test="param.type != null">
|
||||
AND a.type = #{param.type}
|
||||
</if>
|
||||
<if test="param.mergeData != null">
|
||||
AND a.merge_data LIKE CONCAT('%', #{param.mergeData}, '%')
|
||||
</if>
|
||||
<if test="param.startTime != null">
|
||||
AND a.start_time = #{param.startTime}
|
||||
</if>
|
||||
<if test="param.orderTime != null">
|
||||
AND a.order_time = #{param.orderTime}
|
||||
</if>
|
||||
<if test="param.timeFlag != null">
|
||||
AND a.time_flag LIKE CONCAT('%', #{param.timeFlag}, '%')
|
||||
</if>
|
||||
<if test="param.deleted != null">
|
||||
AND a.deleted = #{param.deleted}
|
||||
</if>
|
||||
<if test="param.deleted == null">
|
||||
AND a.deleted = 0
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.OrderInfo">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 查询全部 -->
|
||||
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.OrderInfo">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -123,4 +123,14 @@
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 按OutTradeNo查询 -->
|
||||
<select id="getByOutTradeNo" resultType="com.gxwebsoft.common.system.entity.Order">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 更新订单状态 -->
|
||||
<select id="updateByOutTradeNo" resultType="com.gxwebsoft.common.system.entity.Order">
|
||||
UPDATE sys_order SET pay_status = #{param.payStatus},pay_time = #{param.payTime},pay_price = #{param.payPrice},transaction_id = #{param.transactionId} WHERE order_no = #{param.orderNo}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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.gxwebsoft.common.system.mapper.PaymentMapper">
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*
|
||||
FROM sys_payment a
|
||||
<where>
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.id}
|
||||
</if>
|
||||
<if test="param.name != null">
|
||||
AND a.name LIKE CONCAT('%', #{param.name}, '%')
|
||||
</if>
|
||||
<if test="param.code != null">
|
||||
AND a.code = #{param.code}
|
||||
</if>
|
||||
<if test="param.wechatType != null">
|
||||
AND a.wechat_type = #{param.wechatType}
|
||||
</if>
|
||||
<if test="param.appId != null">
|
||||
AND a.app_id LIKE CONCAT('%', #{param.appId}, '%')
|
||||
</if>
|
||||
<if test="param.mchId != null">
|
||||
AND a.mch_id LIKE CONCAT('%', #{param.mchId}, '%')
|
||||
</if>
|
||||
<if test="param.apiKey != null">
|
||||
AND a.api_key LIKE CONCAT('%', #{param.apiKey}, '%')
|
||||
</if>
|
||||
<if test="param.apiclientCert != null">
|
||||
AND a.apiclient_cert LIKE CONCAT('%', #{param.apiclientCert}, '%')
|
||||
</if>
|
||||
<if test="param.apiclientKey != null">
|
||||
AND a.apiclient_key LIKE CONCAT('%', #{param.apiclientKey}, '%')
|
||||
</if>
|
||||
<if test="param.merchantSerialNumber != null">
|
||||
AND a.merchant_serial_number LIKE CONCAT('%', #{param.merchantSerialNumber}, '%')
|
||||
</if>
|
||||
<if test="param.comments != null">
|
||||
AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
|
||||
</if>
|
||||
<if test="param.sortNumber != null">
|
||||
AND a.sort_number = #{param.sortNumber}
|
||||
</if>
|
||||
<if test="param.status != null">
|
||||
AND a.status = #{param.status}
|
||||
</if>
|
||||
<if test="param.deleted != null">
|
||||
AND a.deleted = #{param.deleted}
|
||||
</if>
|
||||
<if test="param.deleted == null">
|
||||
AND a.deleted = 0
|
||||
</if>
|
||||
<if test="param.createTimeStart != null">
|
||||
AND a.create_time >= #{param.createTimeStart}
|
||||
</if>
|
||||
<if test="param.createTimeEnd != null">
|
||||
AND a.create_time <= #{param.createTimeEnd}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.Payment">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
<!-- 查询全部 -->
|
||||
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.Payment">
|
||||
<include refid="selectSql"></include>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.gxwebsoft.common.system.param;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.gxwebsoft.common.core.annotation.QueryField;
|
||||
import com.gxwebsoft.common.core.annotation.QueryType;
|
||||
import com.gxwebsoft.common.core.web.BaseParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 查询参数
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-10 18:02:54
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModel(value = "OrderInfoParam对象", description = "查询参数")
|
||||
public class OrderInfoParam extends BaseParam {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "关联订单表id")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer oid;
|
||||
|
||||
@ApiModelProperty(value = "关联场馆id")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer sid;
|
||||
|
||||
@ApiModelProperty(value = "关联场地id")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer fid;
|
||||
|
||||
@ApiModelProperty(value = "场馆")
|
||||
private String siteName;
|
||||
|
||||
@ApiModelProperty(value = "场地")
|
||||
private String fieldName;
|
||||
|
||||
@ApiModelProperty(value = "预约时间段")
|
||||
private String dateTime;
|
||||
|
||||
@ApiModelProperty(value = "单价")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal price;
|
||||
|
||||
@ApiModelProperty(value = "儿童价")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private BigDecimal childrenPrice;
|
||||
|
||||
@ApiModelProperty(value = "成人人数")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean adultNum;
|
||||
|
||||
@ApiModelProperty(value = "儿童人数")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean childrenNum;
|
||||
|
||||
@ApiModelProperty(value = "1已付款,2未付款,3无需付款或占用状态")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean payStatus;
|
||||
|
||||
@ApiModelProperty(value = "是否免费:1免费、2收费")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean isFree;
|
||||
|
||||
@ApiModelProperty(value = "是否支持儿童票:1支持,2不支持")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean isChildren;
|
||||
|
||||
@ApiModelProperty(value = "预订类型:1全场,2半场")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean type;
|
||||
|
||||
@ApiModelProperty(value = "组合数据:日期+时间段+场馆id+场地id")
|
||||
private String mergeData;
|
||||
|
||||
@ApiModelProperty(value = "开场时间")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer startTime;
|
||||
|
||||
@ApiModelProperty(value = "下单时间")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer orderTime;
|
||||
|
||||
@ApiModelProperty(value = "毫秒时间戳")
|
||||
private Long timeFlag;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer deleted;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.gxwebsoft.common.system.param;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.gxwebsoft.common.core.annotation.QueryField;
|
||||
import com.gxwebsoft.common.core.annotation.QueryType;
|
||||
import com.gxwebsoft.common.core.web.BaseParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 支付方式查询参数
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-11 12:39:11
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ApiModel(value = "PaymentParam对象", description = "支付方式查询参数")
|
||||
public class PaymentParam extends BaseParam {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty(value = "ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "支付方式")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty(value = "标识")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer code;
|
||||
|
||||
@ApiModelProperty(value = "微信商户号类型 1普通商户2子商户")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer wechatType;
|
||||
|
||||
@ApiModelProperty(value = "应用ID")
|
||||
private String appId;
|
||||
|
||||
@ApiModelProperty(value = "商户号")
|
||||
private String mchId;
|
||||
|
||||
@ApiModelProperty(value = "设置APIv3密钥")
|
||||
private String apiKey;
|
||||
|
||||
@ApiModelProperty(value = "证书文件 (CERT)")
|
||||
private String apiclientCert;
|
||||
|
||||
@ApiModelProperty(value = "证书文件 (KEY)")
|
||||
private String apiclientKey;
|
||||
|
||||
@ApiModelProperty(value = "商户证书序列号")
|
||||
private String merchantSerialNumber;
|
||||
|
||||
@ApiModelProperty(value = "备注")
|
||||
private String comments;
|
||||
|
||||
@ApiModelProperty(value = "文章排序(数字越小越靠前)")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer sortNumber;
|
||||
|
||||
@ApiModelProperty(value = "状态, 0启用, 1禁用")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Boolean status;
|
||||
|
||||
@ApiModelProperty(value = "是否删除, 0否, 1是")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Integer deleted;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.gxwebsoft.common.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.OrderInfo;
|
||||
import com.gxwebsoft.common.system.param.OrderInfoParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Service
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-10 18:02:54
|
||||
*/
|
||||
public interface OrderInfoService extends IService<OrderInfo> {
|
||||
|
||||
/**
|
||||
* 分页关联查询
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return PageResult<OrderInfo>
|
||||
*/
|
||||
PageResult<OrderInfo> pageRel(OrderInfoParam param);
|
||||
|
||||
/**
|
||||
* 关联查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<OrderInfo>
|
||||
*/
|
||||
List<OrderInfo> listRel(OrderInfoParam param);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param id
|
||||
* @return OrderInfo
|
||||
*/
|
||||
OrderInfo getByIdRel(Integer id);
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Order;
|
||||
import com.gxwebsoft.common.system.param.OrderParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -39,4 +40,9 @@ public interface OrderService extends IService<Order> {
|
||||
*/
|
||||
Order getByIdRel(Integer orderId);
|
||||
|
||||
HashMap<String, String> createWxOrder(Order order);
|
||||
|
||||
Order getByOutTradeNo(String outTradeNo);
|
||||
|
||||
void updateByOutTradeNo(Order order);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.gxwebsoft.common.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.Payment;
|
||||
import com.gxwebsoft.common.system.param.PaymentParam;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付方式Service
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-11 12:39:11
|
||||
*/
|
||||
public interface PaymentService extends IService<Payment> {
|
||||
|
||||
/**
|
||||
* 分页关联查询
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return PageResult<Payment>
|
||||
*/
|
||||
PageResult<Payment> pageRel(PaymentParam param);
|
||||
|
||||
/**
|
||||
* 关联查询全部
|
||||
*
|
||||
* @param param 查询参数
|
||||
* @return List<Payment>
|
||||
*/
|
||||
List<Payment> listRel(PaymentParam param);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param id ID
|
||||
* @return Payment
|
||||
*/
|
||||
Payment getByIdRel(Integer id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.gxwebsoft.common.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gxwebsoft.common.system.mapper.OrderInfoMapper;
|
||||
import com.gxwebsoft.common.system.service.OrderInfoService;
|
||||
import com.gxwebsoft.common.system.entity.OrderInfo;
|
||||
import com.gxwebsoft.common.system.param.OrderInfoParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Service实现
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-10 18:02:54
|
||||
*/
|
||||
@Service
|
||||
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {
|
||||
|
||||
@Override
|
||||
public PageResult<OrderInfo> pageRel(OrderInfoParam param) {
|
||||
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>(param);
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
List<OrderInfo> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OrderInfo> listRel(OrderInfoParam param) {
|
||||
List<OrderInfo> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>();
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OrderInfo getByIdRel(Integer id) {
|
||||
OrderInfoParam param = new OrderInfoParam();
|
||||
param.setId(id);
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,31 @@
|
||||
package com.gxwebsoft.common.system.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gxwebsoft.common.core.config.ConfigProperties;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.system.entity.OrderInfo;
|
||||
import com.gxwebsoft.common.system.entity.Payment;
|
||||
import com.gxwebsoft.common.system.mapper.OrderMapper;
|
||||
import com.gxwebsoft.common.system.service.OrderService;
|
||||
import com.gxwebsoft.common.system.entity.Order;
|
||||
import com.gxwebsoft.common.system.param.OrderParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.service.PaymentService;
|
||||
import com.gxwebsoft.common.system.service.SettingService;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAConfig;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -19,7 +36,14 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
|
||||
|
||||
@Resource
|
||||
private ConfigProperties config;
|
||||
@Resource
|
||||
private SettingService settingService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private PaymentService paymentService;
|
||||
@Override
|
||||
public PageResult<Order> pageRel(OrderParam param) {
|
||||
PageParam<Order, OrderParam> page = new PageParam<>(param);
|
||||
@@ -44,4 +68,95 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建微信支付
|
||||
*
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public HashMap<String, String> createWxOrder(Order order) {
|
||||
final String uploadPath = config.getUploadPath(); // 服务器本地路径
|
||||
final HashMap<String, String> orderInfo = new HashMap<>();
|
||||
// 微信小程序(微信支付)
|
||||
String key = "Payment:wxPay:".concat(order.getTenantId().toString());
|
||||
final Payment payment = redisUtil.get(key, Payment.class);
|
||||
System.out.println("payment1 = " + payment);
|
||||
|
||||
final JSONObject mpWx = settingService.getBySettingKey("mp-weixin");
|
||||
// final JSONObject payment = settingService.getBySettingKey("payment");
|
||||
|
||||
|
||||
// 计算金额
|
||||
BigDecimal decimal = order.getTotalPrice();
|
||||
final BigDecimal multiply = decimal.multiply(new BigDecimal(100));
|
||||
// 将 BigDecimal 转换为 Integer
|
||||
Integer money = multiply.intValue();
|
||||
|
||||
final String appId = mpWx.getString("appId");
|
||||
final String mchId = payment.getMchId();
|
||||
final String openid = order.getOpenid(); // openid
|
||||
final String notifyUrl = config.getServerUrl() + "/love/user-plan-log/wx-pay/notify/" + order.getTenantId(); // 异步通知地址
|
||||
final String privateKey = uploadPath.concat("file").concat(payment.getApiclientKey()); // 秘钥证书
|
||||
final String apiclientCert = uploadPath.concat("file").concat(payment.getApiclientCert());
|
||||
final String merchantSerialNumber = payment.getMerchantSerialNumber(); // 证书序列号
|
||||
final String apiV3key = payment.getApiKey();
|
||||
|
||||
System.out.println("privateKey = " + privateKey);
|
||||
System.out.println("apiclientCert = " + apiclientCert);
|
||||
System.out.println("merchantSerialNumber = " + merchantSerialNumber);
|
||||
System.out.println("apiV3key = " + apiV3key);
|
||||
System.out.println("mchId = " + mchId);
|
||||
System.out.println("appId = " + appId);
|
||||
|
||||
Config config =
|
||||
new RSAConfig.Builder()
|
||||
.merchantId(mchId)
|
||||
.privateKeyFromPath(privateKey)
|
||||
.merchantSerialNumber(merchantSerialNumber)
|
||||
.wechatPayCertificatesFromPath(apiclientCert)
|
||||
.build();
|
||||
|
||||
// 构建service
|
||||
JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
|
||||
// 跟之前下单示例一样,填充预下单参数
|
||||
PrepayRequest request = new PrepayRequest();
|
||||
Amount amount = new Amount();
|
||||
amount.setTotal(money);
|
||||
amount.setCurrency("CNY");
|
||||
request.setAmount(amount);
|
||||
request.setAppid(appId);
|
||||
request.setMchid(mchId);
|
||||
OrderInfo desc = order.getOrderInfoList().get(0);
|
||||
|
||||
request.setDescription(desc.getSiteName().concat(desc.getFieldName()).concat(desc.getDateTime()));
|
||||
request.setNotifyUrl(notifyUrl);
|
||||
request.setOutTradeNo(order.getOrderNo());
|
||||
request.setAttach(order.getTenantId().toString());
|
||||
final Payer payer = new Payer();
|
||||
payer.setOpenid(openid);
|
||||
request.setPayer(payer);
|
||||
System.out.println("request2 = " + request);
|
||||
PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
|
||||
System.out.println("response = " + response);
|
||||
orderInfo.put("provider", "wxpay");
|
||||
orderInfo.put("timeStamp", response.getTimeStamp());
|
||||
orderInfo.put("nonceStr", response.getNonceStr());
|
||||
orderInfo.put("package", response.getPackageVal());
|
||||
orderInfo.put("signType", "RSA");
|
||||
orderInfo.put("paySign", response.getPaySign());
|
||||
return orderInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order getByOutTradeNo(String outTradeNo) {
|
||||
OrderParam param = new OrderParam();
|
||||
param.setOrderNo(outTradeNo);
|
||||
return param.getOne(baseMapper.getByOutTradeNo(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateByOutTradeNo(Order order) {
|
||||
baseMapper.updateByOutTradeNo(order);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.gxwebsoft.common.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gxwebsoft.common.system.mapper.PaymentMapper;
|
||||
import com.gxwebsoft.common.system.service.PaymentService;
|
||||
import com.gxwebsoft.common.system.entity.Payment;
|
||||
import com.gxwebsoft.common.system.param.PaymentParam;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 支付方式Service实现
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-05-11 12:39:11
|
||||
*/
|
||||
@Service
|
||||
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements PaymentService {
|
||||
|
||||
@Override
|
||||
public PageResult<Payment> pageRel(PaymentParam param) {
|
||||
PageParam<Payment, PaymentParam> page = new PageParam<>(param);
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
List<Payment> list = baseMapper.selectPageRel(page, param);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Payment> listRel(PaymentParam param) {
|
||||
List<Payment> list = baseMapper.selectListRel(param);
|
||||
// 排序
|
||||
PageParam<Payment, PaymentParam> page = new PageParam<>();
|
||||
//page.setDefaultOrder("create_time desc");
|
||||
return page.sortRecords(list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Payment getByIdRel(Integer id) {
|
||||
PaymentParam param = new PaymentParam();
|
||||
param.setId(id);
|
||||
return param.getOne(baseMapper.selectListRel(param));
|
||||
}
|
||||
|
||||
}
|
||||
227
src/test/java/com/gxwebsoft/generator/Sys2Generator.java
Normal file
227
src/test/java/com/gxwebsoft/generator/Sys2Generator.java
Normal file
@@ -0,0 +1,227 @@
|
||||
package com.gxwebsoft.generator;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringPool;
|
||||
import com.baomidou.mybatisplus.generator.AutoGenerator;
|
||||
import com.baomidou.mybatisplus.generator.InjectionConfig;
|
||||
import com.baomidou.mybatisplus.generator.config.*;
|
||||
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
|
||||
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
|
||||
import com.gxwebsoft.generator.engine.BeetlTemplateEnginePlus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 代码生成工具
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2021-09-05 00:31:14
|
||||
*/
|
||||
public class Sys2Generator {
|
||||
// 输出位置
|
||||
private static final String OUTPUT_LOCATION = System.getProperty("user.dir");
|
||||
//private static final String OUTPUT_LOCATION = "D:/codegen"; // 不想生成到项目中可以写磁盘路径
|
||||
// 输出目录
|
||||
private static final String OUTPUT_DIR = "/src/main/java";
|
||||
// Vue文件输出位置
|
||||
private static final String OUTPUT_LOCATION_VUE = "/Users/gxwebsoft/VUE/com.gxwebsoft.core-web";
|
||||
// Vue文件输出目录
|
||||
private static final String OUTPUT_DIR_VUE = "/src";
|
||||
// 作者名称
|
||||
private static final String AUTHOR = "科技小王子";
|
||||
// 是否在xml中添加二级缓存配置
|
||||
private static final boolean ENABLE_CACHE = false;
|
||||
// 数据库连接配置
|
||||
private static final String DB_URL = "jdbc:mysql://47.119.165.234:3308/gxwebsoft_core?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8";
|
||||
private static final String DB_DRIVER = "com.mysql.cj.jdbc.Driver";
|
||||
private static final String DB_USERNAME = "gxwebsoft_core";
|
||||
private static final String DB_PASSWORD = "jdj7HYEdYHnYEFBy";
|
||||
// 包名
|
||||
private static final String PACKAGE_NAME = "com.gxwebsoft";
|
||||
// 模块名
|
||||
private static final String MODULE_NAME = "common.system";
|
||||
// 需要生成的表
|
||||
private static final String[] TABLE_NAMES = new String[]{
|
||||
"sys_payment"
|
||||
};
|
||||
// 需要去除的表前缀
|
||||
private static final String[] TABLE_PREFIX = new String[]{
|
||||
"sys_",
|
||||
"tb_"
|
||||
};
|
||||
// 不需要作为查询参数的字段
|
||||
private static final String[] PARAM_EXCLUDE_FIELDS = new String[]{
|
||||
"tenant_id",
|
||||
"create_time",
|
||||
"update_time"
|
||||
};
|
||||
// 查询参数使用String的类型
|
||||
private static final String[] PARAM_TO_STRING_TYPE = new String[]{
|
||||
"Date",
|
||||
"LocalDate",
|
||||
"LocalTime",
|
||||
"LocalDateTime"
|
||||
};
|
||||
// 查询参数使用EQ的类型
|
||||
private static final String[] PARAM_EQ_TYPE = new String[]{
|
||||
"Integer",
|
||||
"Boolean",
|
||||
"BigDecimal"
|
||||
};
|
||||
// 是否添加权限注解
|
||||
private static final boolean AUTH_ANNOTATION = true;
|
||||
// 是否添加日志注解
|
||||
private static final boolean LOG_ANNOTATION = true;
|
||||
// controller的mapping前缀
|
||||
private static final String CONTROLLER_MAPPING_PREFIX = "/api";
|
||||
// 模板所在位置
|
||||
private static final String TEMPLATES_DIR = "/src/test/java/com/gxwebsoft/generator/templates";
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 代码生成器
|
||||
AutoGenerator mpg = new AutoGenerator();
|
||||
|
||||
// 全局配置
|
||||
GlobalConfig gc = new GlobalConfig();
|
||||
gc.setOutputDir(OUTPUT_LOCATION + OUTPUT_DIR);
|
||||
gc.setAuthor(AUTHOR);
|
||||
gc.setOpen(false);
|
||||
gc.setFileOverride(true);
|
||||
gc.setEnableCache(ENABLE_CACHE);
|
||||
gc.setSwagger2(true);
|
||||
gc.setIdType(IdType.AUTO);
|
||||
gc.setServiceName("%sService");
|
||||
mpg.setGlobalConfig(gc);
|
||||
|
||||
// 数据源配置
|
||||
DataSourceConfig dsc = new DataSourceConfig();
|
||||
dsc.setUrl(DB_URL);
|
||||
// dsc.setSchemaName("public");
|
||||
dsc.setDriverName(DB_DRIVER);
|
||||
dsc.setUsername(DB_USERNAME);
|
||||
dsc.setPassword(DB_PASSWORD);
|
||||
mpg.setDataSource(dsc);
|
||||
|
||||
// 包配置
|
||||
PackageConfig pc = new PackageConfig();
|
||||
pc.setModuleName(MODULE_NAME);
|
||||
pc.setParent(PACKAGE_NAME);
|
||||
mpg.setPackageInfo(pc);
|
||||
|
||||
// 策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setColumnNaming(NamingStrategy.underline_to_camel);
|
||||
strategy.setInclude(TABLE_NAMES);
|
||||
strategy.setTablePrefix(TABLE_PREFIX);
|
||||
strategy.setSuperControllerClass(PACKAGE_NAME + ".common.core.web.BaseController");
|
||||
strategy.setEntityLombokModel(true);
|
||||
strategy.setRestControllerStyle(true);
|
||||
strategy.setControllerMappingHyphenStyle(true);
|
||||
strategy.setLogicDeleteFieldName("deleted");
|
||||
mpg.setStrategy(strategy);
|
||||
|
||||
// 模板配置
|
||||
TemplateConfig templateConfig = new TemplateConfig();
|
||||
templateConfig.setController(TEMPLATES_DIR + "/controller.java");
|
||||
templateConfig.setEntity(TEMPLATES_DIR + "/entity.java");
|
||||
templateConfig.setMapper(TEMPLATES_DIR + "/mapper.java");
|
||||
templateConfig.setXml(TEMPLATES_DIR + "/mapper.xml");
|
||||
templateConfig.setService(TEMPLATES_DIR + "/service.java");
|
||||
templateConfig.setServiceImpl(TEMPLATES_DIR + "/serviceImpl.java");
|
||||
mpg.setTemplate(templateConfig);
|
||||
mpg.setTemplateEngine(new BeetlTemplateEnginePlus());
|
||||
|
||||
// 自定义模板配置
|
||||
InjectionConfig cfg = new InjectionConfig() {
|
||||
@Override
|
||||
public void initMap() {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("packageName", PACKAGE_NAME);
|
||||
map.put("paramExcludeFields", PARAM_EXCLUDE_FIELDS);
|
||||
map.put("paramToStringType", PARAM_TO_STRING_TYPE);
|
||||
map.put("paramEqType", PARAM_EQ_TYPE);
|
||||
map.put("authAnnotation", AUTH_ANNOTATION);
|
||||
map.put("logAnnotation", LOG_ANNOTATION);
|
||||
map.put("controllerMappingPrefix", CONTROLLER_MAPPING_PREFIX);
|
||||
this.setMap(map);
|
||||
}
|
||||
};
|
||||
String templatePath = TEMPLATES_DIR + "/param.java.btl";
|
||||
List<FileOutConfig> focList = new ArrayList<>();
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION + OUTPUT_DIR + "/"
|
||||
+ PACKAGE_NAME.replace(".", "/")
|
||||
+ "/" + pc.getModuleName() + "/param/"
|
||||
+ tableInfo.getEntityName() + "Param" + StringPool.DOT_JAVA;
|
||||
}
|
||||
});
|
||||
/**
|
||||
* 以下是生成VUE项目代码
|
||||
* 生成文件的路径 /api/shop/goods/index.ts
|
||||
*/
|
||||
templatePath = TEMPLATES_DIR + "/index.ts.btl";
|
||||
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.ts";
|
||||
}
|
||||
});
|
||||
// 生成TS文件 (/api/shop/goods/model/index.ts)
|
||||
templatePath = TEMPLATES_DIR + "/model.ts.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/api/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/model/" + "index.ts";
|
||||
}
|
||||
});
|
||||
// 生成Vue文件(/views/shop/goods/index.vue)
|
||||
templatePath = TEMPLATES_DIR + "/index.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/" + "index.vue";
|
||||
}
|
||||
});
|
||||
|
||||
// 生成components文件(/views/shop/goods/components/edit.vue)
|
||||
templatePath = TEMPLATES_DIR + "/components.edit.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/components/" + tableInfo.getEntityPath() + "Edit.vue";
|
||||
}
|
||||
});
|
||||
|
||||
// 生成components文件(/views/shop/goods/components/search.vue)
|
||||
templatePath = TEMPLATES_DIR + "/components.search.vue.btl";
|
||||
focList.add(new FileOutConfig(templatePath) {
|
||||
@Override
|
||||
public String outputFile(TableInfo tableInfo) {
|
||||
return OUTPUT_LOCATION_VUE + OUTPUT_DIR_VUE
|
||||
+ "/views/" + pc.getModuleName() + "/"
|
||||
+ tableInfo.getEntityPath() + "/components/" + "search.vue";
|
||||
}
|
||||
});
|
||||
|
||||
cfg.setFileOutConfigList(focList);
|
||||
mpg.setCfg(cfg);
|
||||
|
||||
mpg.execute();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -69,8 +69,10 @@ public class SysGenerator {
|
||||
// "sys_website_field",
|
||||
// "sys_white_domain"
|
||||
// "sys_order",
|
||||
// "sys_order_info",
|
||||
// "sys_user_collection",
|
||||
"sys_user"
|
||||
// "sys_user",
|
||||
"sys_payment"
|
||||
};
|
||||
// 需要去除的表前缀
|
||||
private static final String[] TABLE_PREFIX = new String[]{
|
||||
|
||||
@@ -0,0 +1,221 @@
|
||||
<!-- 编辑弹窗 -->
|
||||
<template>
|
||||
<ele-modal
|
||||
:width="800"
|
||||
:visible="visible"
|
||||
:maskClosable="false"
|
||||
:maxable="maxable"
|
||||
:title="isUpdate ? '编辑${table.comment!}' : '添加${table.comment!}'"
|
||||
:body-style="{ paddingBottom: '28px' }"
|
||||
@update:visible="updateVisible"
|
||||
@ok="save"
|
||||
>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
:label-col="styleResponsive ? { md: 4, sm: 5, xs: 24 } : { flex: '90px' }"
|
||||
:wrapper-col="
|
||||
styleResponsive ? { md: 19, sm: 19, xs: 24 } : { flex: '1' }
|
||||
"
|
||||
>
|
||||
<% for(field in table.fields) { %>
|
||||
<% if(field.propertyName == 'comments'){ %>
|
||||
<a-form-item label="${field.comment!}" name="${field.propertyName}">
|
||||
<a-textarea
|
||||
:rows="4"
|
||||
:maxlength="200"
|
||||
placeholder="请输入描述"
|
||||
v-model:value="form.${field.propertyName}"
|
||||
/>
|
||||
</a-form-item>
|
||||
<% } %>
|
||||
<% else if(field.propertyName == 'sortNumber'){ %>
|
||||
<a-form-item label="${field.comment!}" name="${field.propertyName}">
|
||||
<a-input-number
|
||||
:min="0"
|
||||
:max="9999"
|
||||
class="ele-fluid"
|
||||
placeholder="请输入排序号"
|
||||
v-model:value="form.${field.propertyName}"
|
||||
/>
|
||||
</a-form-item>
|
||||
<% } %>
|
||||
<% else if(field.propertyName == 'status'){ %>
|
||||
<a-form-item label="${field.comment!}" name="${field.propertyName}">
|
||||
<a-radio-group v-model:value="form.status">
|
||||
<a-radio :value="0">显示</a-radio>
|
||||
<a-radio :value="1">隐藏</a-radio>
|
||||
</a-radio-group>
|
||||
</a-form-item>
|
||||
<% } %>
|
||||
<% else if(field.propertyName == 'image'){ %>
|
||||
<a-form-item
|
||||
label="${field.comment!}"
|
||||
name="${field.propertyName}">
|
||||
<SelectFile
|
||||
:placeholder="`请选择图片`"
|
||||
:limit="1"
|
||||
:data="images"
|
||||
@done="chooseImage"
|
||||
@del="onDeleteItem"
|
||||
/>
|
||||
</a-form-item>
|
||||
<% } %>
|
||||
<% else if(field.keyFlag){ %>
|
||||
<% } %>
|
||||
<% else if(field.propertyName == 'tenantId'){ %>
|
||||
<% } %>
|
||||
<% else if(field.propertyName == 'createTime'){ %>
|
||||
<% } %>
|
||||
<% else { %>
|
||||
<a-form-item label="${field.comment!}" name="${field.propertyName}">
|
||||
<a-input
|
||||
allow-clear
|
||||
placeholder="请输入${field.comment!}"
|
||||
v-model:value="form.${field.propertyName}"
|
||||
/>
|
||||
</a-form-item>
|
||||
<% } %>
|
||||
<% } %>
|
||||
</a-form>
|
||||
</ele-modal>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, watch } from 'vue';
|
||||
import { Form, message } from 'ant-design-vue';
|
||||
import { assignObject, uuid } from 'ele-admin-pro';
|
||||
import { add${entity}, update${entity} } from '@/api/${package.ModuleName}/${table.entityPath}';
|
||||
import { ${entity} } from '@/api/${package.ModuleName}/${table.entityPath}/model';
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
|
||||
import { FormInstance } from 'ant-design-vue/es/form';
|
||||
import { FileRecord } from '@/api/system/file/model';
|
||||
|
||||
// 是否是修改
|
||||
const isUpdate = ref(false);
|
||||
const useForm = Form.useForm;
|
||||
// 是否开启响应式布局
|
||||
const themeStore = useThemeStore();
|
||||
const { styleResponsive } = storeToRefs(themeStore);
|
||||
|
||||
const props = defineProps<{
|
||||
// 弹窗是否打开
|
||||
visible: boolean;
|
||||
// 修改回显的数据
|
||||
data?: ${entity} | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'done'): void;
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
}>();
|
||||
|
||||
// 提交状态
|
||||
const loading = ref(false);
|
||||
// 是否显示最大化切换按钮
|
||||
const maxable = ref(true);
|
||||
// 表格选中数据
|
||||
const formRef = ref<FormInstance | null>(null);
|
||||
const images = ref<ItemType[]>([]);
|
||||
|
||||
// 用户信息
|
||||
const form = reactive<${entity}>({
|
||||
<% for(field in table.fields) { %>
|
||||
${field.propertyName}: undefined,
|
||||
<% } %>
|
||||
${table.entityPath}Id: undefined,
|
||||
${table.entityPath}Name: '',
|
||||
status: 0,
|
||||
comments: '',
|
||||
sortNumber: 100
|
||||
});
|
||||
|
||||
/* 更新visible */
|
||||
const updateVisible = (value: boolean) => {
|
||||
emit('update:visible', value);
|
||||
};
|
||||
|
||||
// 表单验证规则
|
||||
const rules = reactive({
|
||||
${table.entityPath}Name: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '请填写${table.comment!}名称',
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const chooseImage = (data: FileRecord) => {
|
||||
images.value.push({
|
||||
uid: data.id,
|
||||
url: data.path,
|
||||
status: 'done'
|
||||
});
|
||||
form.image = data.path;
|
||||
};
|
||||
|
||||
const onDeleteItem = (index: number) => {
|
||||
images.value.splice(index, 1);
|
||||
form.image = '';
|
||||
};
|
||||
|
||||
const { resetFields } = useForm(form, rules);
|
||||
|
||||
/* 保存编辑 */
|
||||
const save = () => {
|
||||
if (!formRef.value) {
|
||||
return;
|
||||
}
|
||||
formRef.value
|
||||
.validate()
|
||||
.then(() => {
|
||||
loading.value = true;
|
||||
const formData = {
|
||||
...form
|
||||
};
|
||||
const saveOrUpdate = isUpdate.value ? update${entity} : add${entity};
|
||||
saveOrUpdate(formData)
|
||||
.then((msg) => {
|
||||
loading.value = false;
|
||||
message.success(msg);
|
||||
updateVisible(false);
|
||||
emit('done');
|
||||
})
|
||||
.catch((e) => {
|
||||
loading.value = false;
|
||||
message.error(e.message);
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
images.value = [];
|
||||
if (props.data) {
|
||||
assignObject(form, props.data);
|
||||
if(props.data.image){
|
||||
images.value.push({
|
||||
uid: uuid(),
|
||||
url: props.data.image,
|
||||
status: 'done'
|
||||
})
|
||||
}
|
||||
isUpdate.value = true;
|
||||
} else {
|
||||
isUpdate.value = false;
|
||||
}
|
||||
} else {
|
||||
resetFields();
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
</script>
|
||||
@@ -0,0 +1,42 @@
|
||||
<!-- 搜索表单 -->
|
||||
<template>
|
||||
<a-space :size="10" style="flex-wrap: wrap">
|
||||
<a-button type="primary" class="ele-btn-icon" @click="add">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
<span>添加</span>
|
||||
</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { PlusOutlined } from '@ant-design/icons-vue';
|
||||
import type { GradeParam } from '@/api/user/grade/model';
|
||||
import { watch } from 'vue';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
// 选中的角色
|
||||
selection?: [];
|
||||
}>(),
|
||||
{}
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'search', where?: GradeParam): void;
|
||||
(e: 'add'): void;
|
||||
(e: 'remove'): void;
|
||||
(e: 'batchMove'): void;
|
||||
}>();
|
||||
|
||||
// 新增
|
||||
const add = () => {
|
||||
emit('add');
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.selection,
|
||||
() => {}
|
||||
);
|
||||
</script>
|
||||
106
src/test/java/com/gxwebsoft/generator/templates/index.ts.btl
Normal file
106
src/test/java/com/gxwebsoft/generator/templates/index.ts.btl
Normal file
@@ -0,0 +1,106 @@
|
||||
import request from '@/utils/request';
|
||||
import type { ApiResult, PageResult } from '@/api';
|
||||
import type { ${entity}, ${entity}Param } from './model';
|
||||
import { MODULES_API_URL } from '@/config/setting';
|
||||
|
||||
/**
|
||||
* 分页查询${table.comment!}
|
||||
*/
|
||||
export async function page${entity}(params: ${entity}Param) {
|
||||
const res = await request.get<ApiResult<PageResult<${entity}>>>(
|
||||
MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/page',
|
||||
{
|
||||
params
|
||||
}
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
return res.data.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询${table.comment!}列表
|
||||
*/
|
||||
export async function list${entity}(params?: ${entity}Param) {
|
||||
const res = await request.get<ApiResult<${entity}[]>>(
|
||||
MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}',
|
||||
{
|
||||
params
|
||||
}
|
||||
);
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
return res.data.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加${table.comment!}
|
||||
*/
|
||||
export async function add${entity}(data: ${entity}) {
|
||||
const res = await request.post<ApiResult<unknown>>(
|
||||
MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}',
|
||||
data
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
return res.data.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改${table.comment!}
|
||||
*/
|
||||
export async function update${entity}(data: ${entity}) {
|
||||
const res = await request.put<ApiResult<unknown>>(
|
||||
MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}',
|
||||
data
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
return res.data.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除${table.comment!}
|
||||
*/
|
||||
export async function remove${entity}(id?: number) {
|
||||
const res = await request.delete<ApiResult<unknown>>(
|
||||
MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/' + id
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
return res.data.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除${table.comment!}
|
||||
*/
|
||||
export async function removeBatch${entity}(data: (number | undefined)[]) {
|
||||
const res = await request.delete<ApiResult<unknown>>(
|
||||
MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/batch',
|
||||
{
|
||||
data
|
||||
}
|
||||
);
|
||||
if (res.data.code === 0) {
|
||||
return res.data.message;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询${table.comment!}
|
||||
*/
|
||||
export async function get${entity}(id: number) {
|
||||
const res = await request.get<ApiResult<${entity}>>(
|
||||
MODULES_API_URL + '/${package.ModuleName}/${controllerMappingHyphen}/' + id
|
||||
);
|
||||
if (res.data.code === 0 && res.data.data) {
|
||||
return res.data.data;
|
||||
}
|
||||
return Promise.reject(new Error(res.data.message));
|
||||
}
|
||||
217
src/test/java/com/gxwebsoft/generator/templates/index.vue.btl
Normal file
217
src/test/java/com/gxwebsoft/generator/templates/index.vue.btl
Normal file
@@ -0,0 +1,217 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="ele-body">
|
||||
<a-card :bordered="false" :body-style="{ padding: '16px' }">
|
||||
<ele-pro-table
|
||||
ref="tableRef"
|
||||
row-key="${table.entityPath}Id"
|
||||
:columns="columns"
|
||||
:datasource="datasource"
|
||||
:customRow="customRow"
|
||||
tool-class="ele-toolbar-form"
|
||||
class="sys-org-table"
|
||||
>
|
||||
<template #toolbar>
|
||||
<search
|
||||
@search="reload"
|
||||
:selection="selection"
|
||||
@add="openEdit"
|
||||
@remove="removeBatch"
|
||||
@batchMove="openMove"
|
||||
/>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'image'">
|
||||
<a-image :src="record.image" :width="50" />
|
||||
</template>
|
||||
<template v-if="column.key === 'status'">
|
||||
<a-tag v-if="record.status === 0" color="green">显示</a-tag>
|
||||
<a-tag v-if="record.status === 1" color="red">隐藏</a-tag>
|
||||
</template>
|
||||
<template v-if="column.key === 'action'">
|
||||
<a-space>
|
||||
<a @click="openEdit(record)">修改</a>
|
||||
<a-divider type="vertical" />
|
||||
<a-popconfirm
|
||||
title="确定要删除此记录吗?"
|
||||
@confirm="remove(record)"
|
||||
>
|
||||
<a class="ele-text-danger">删除</a>
|
||||
</a-popconfirm>
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</ele-pro-table>
|
||||
</a-card>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<${entity}Edit v-model:visible="showEdit" :data="current" @done="reload" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { createVNode, ref } from 'vue';
|
||||
import { message, Modal } from 'ant-design-vue';
|
||||
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
|
||||
import type { EleProTable } from 'ele-admin-pro';
|
||||
import { toDateString } from 'ele-admin-pro';
|
||||
import type {
|
||||
DatasourceFunction,
|
||||
ColumnItem
|
||||
} from 'ele-admin-pro/es/ele-pro-table/types';
|
||||
import Search from './components/search.vue';
|
||||
import ${entity}Edit from './components/${table.entityPath}Edit.vue';
|
||||
import { page${entity}, remove${entity}, removeBatch${entity} } from '@/api/${package.ModuleName}/${table.entityPath}';
|
||||
import type { ${entity}, ${entity}Param } from '@/api/${package.ModuleName}/${table.entityPath}/model';
|
||||
|
||||
// 表格实例
|
||||
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||
|
||||
// 表格选中数据
|
||||
const selection = ref<${entity}[]>([]);
|
||||
// 当前编辑数据
|
||||
const current = ref<${entity} | null>(null);
|
||||
// 是否显示编辑弹窗
|
||||
const showEdit = ref(false);
|
||||
// 是否显示批量移动弹窗
|
||||
const showMove = ref(false);
|
||||
// 加载状态
|
||||
const loading = ref(true);
|
||||
|
||||
// 表格数据源
|
||||
const datasource: DatasourceFunction = ({
|
||||
page,
|
||||
limit,
|
||||
where,
|
||||
orders,
|
||||
filters
|
||||
}) => {
|
||||
if (filters) {
|
||||
where.status = filters.status;
|
||||
}
|
||||
return page${entity}({
|
||||
...where,
|
||||
...orders,
|
||||
page,
|
||||
limit
|
||||
});
|
||||
};
|
||||
|
||||
// 表格列配置
|
||||
const columns = ref<ColumnItem[]>([
|
||||
<% for(field in table.fields) { %>
|
||||
<% if(field.propertyName != 'tenantId'){ %>
|
||||
{
|
||||
title: '${field.comment}',
|
||||
dataIndex: '${field.propertyName}',
|
||||
key: '${field.propertyName}',
|
||||
align: 'center',
|
||||
<% if(field.keyFlag){ %>
|
||||
width: 90,
|
||||
<% } %>
|
||||
<% if(field.propertyName == 'createTime'){ %>
|
||||
sorter: true,
|
||||
ellipsis: true,
|
||||
customRender: ({ text }) => toDateString(text, 'yyyy-MM-dd')
|
||||
<% } %>
|
||||
},
|
||||
<% } %>
|
||||
<% } %>
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 180,
|
||||
fixed: 'right',
|
||||
align: 'center',
|
||||
hideInSetting: true
|
||||
}
|
||||
]);
|
||||
|
||||
/* 搜索 */
|
||||
const reload = (where?: ${entity}Param) => {
|
||||
selection.value = [];
|
||||
tableRef?.value?.reload({ where: where });
|
||||
};
|
||||
|
||||
/* 打开编辑弹窗 */
|
||||
const openEdit = (row?: ${entity}) => {
|
||||
current.value = row ?? null;
|
||||
showEdit.value = true;
|
||||
};
|
||||
|
||||
/* 打开批量移动弹窗 */
|
||||
const openMove = () => {
|
||||
showMove.value = true;
|
||||
};
|
||||
|
||||
/* 删除单个 */
|
||||
const remove = (row: ${entity}) => {
|
||||
const hide = message.loading('请求中..', 0);
|
||||
remove${entity}(row.${table.entityPath}Id)
|
||||
.then((msg) => {
|
||||
hide();
|
||||
message.success(msg);
|
||||
reload();
|
||||
})
|
||||
.catch((e) => {
|
||||
hide();
|
||||
message.error(e.message);
|
||||
});
|
||||
};
|
||||
|
||||
/* 批量删除 */
|
||||
const removeBatch = () => {
|
||||
if (!selection.value.length) {
|
||||
message.error('请至少选择一条数据');
|
||||
return;
|
||||
}
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
content: '确定要删除选中的记录吗?',
|
||||
icon: createVNode(ExclamationCircleOutlined),
|
||||
maskClosable: true,
|
||||
onOk: () => {
|
||||
const hide = message.loading('请求中..', 0);
|
||||
removeBatch${entity}(selection.value.map((d) => d.${table.entityPath}Id))
|
||||
.then((msg) => {
|
||||
hide();
|
||||
message.success(msg);
|
||||
reload();
|
||||
})
|
||||
.catch((e) => {
|
||||
hide();
|
||||
message.error(e.message);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/* 查询 */
|
||||
const query = () => {
|
||||
loading.value = true;
|
||||
};
|
||||
|
||||
/* 自定义行属性 */
|
||||
const customRow = (record: ${entity}) => {
|
||||
return {
|
||||
// 行点击事件
|
||||
onClick: () => {
|
||||
// console.log(record);
|
||||
},
|
||||
// 行双击事件
|
||||
onDblclick: () => {
|
||||
openEdit(record);
|
||||
}
|
||||
};
|
||||
};
|
||||
query();
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: '${entity}'
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped></style>
|
||||
43
src/test/java/com/gxwebsoft/generator/templates/model.ts.btl
Normal file
43
src/test/java/com/gxwebsoft/generator/templates/model.ts.btl
Normal file
@@ -0,0 +1,43 @@
|
||||
import type { PageParam } from '@/api';
|
||||
|
||||
/**
|
||||
* ${table.comment!}
|
||||
*/
|
||||
export interface ${entity} {
|
||||
<% /** -----------BEGIN 字段循环遍历----------- **/ %>
|
||||
<% for(field in table.fields) { %>
|
||||
<%
|
||||
var keyPropertyName;
|
||||
if(field.keyFlag) {
|
||||
keyPropertyName = field.propertyName;
|
||||
}
|
||||
%>
|
||||
<% /* 主键 */ %>
|
||||
<% if(field.keyFlag) { %>
|
||||
<% /* 普通字段 */ %>
|
||||
<% } else if(isNotEmpty(field.fill)) { %>
|
||||
<% if(field.convert){ %>
|
||||
@TableField(value = "${field.annotationColumnName}", fill = FieldFill.${field.fill})
|
||||
<% }else{ %>
|
||||
@TableField(fill = FieldFill.${field.fill})
|
||||
<% } %>
|
||||
<% } else if(field.convert) { %>
|
||||
@TableField("${field.annotationColumnName}")
|
||||
<% } %>
|
||||
// ${field.comment}
|
||||
${field.propertyName}?: <% if(field.propertyType == 'Integer') { %>number<% }else{ %>string<% } %>;
|
||||
<% } %>
|
||||
<% /** -----------END 字段循环遍历----------- **/ %>
|
||||
}
|
||||
|
||||
/**
|
||||
* ${table.comment!}搜索条件
|
||||
*/
|
||||
export interface ${entity}Param extends PageParam {
|
||||
<% for(field in table.fields) { %>
|
||||
<% if(field.keyFlag) { %>
|
||||
${field.propertyName}?: number;
|
||||
<% } %>
|
||||
<% } %>
|
||||
keywords?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user