From 80dc4425282015aebe72c844eed5be1fe2a606bd Mon Sep 17 00:00:00 2001
From: lihongbiao <964708803@qq.com>
Date: Mon, 20 Jan 2025 12:13:08 +0800
Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../api/pa/controller/PaOrderController.java | 125 ++++++++++++++++++
.../com/pixelai/api/pa/dao/PaOrderMapper.java | 16 +++
.../com/pixelai/api/pa/entity/PaOrder.java | 69 ++++++++++
.../api/pa/service/PaOrderService.java | 41 ++++++
.../pa/service/impl/PaOrderServiceImpl.java | 63 +++++++++
src/main/resources/mapper/PaOrderMapper.xml | 20 +++
6 files changed, 334 insertions(+)
create mode 100644 src/main/java/com/pixelai/api/pa/controller/PaOrderController.java
create mode 100644 src/main/java/com/pixelai/api/pa/dao/PaOrderMapper.java
create mode 100644 src/main/java/com/pixelai/api/pa/entity/PaOrder.java
create mode 100644 src/main/java/com/pixelai/api/pa/service/PaOrderService.java
create mode 100644 src/main/java/com/pixelai/api/pa/service/impl/PaOrderServiceImpl.java
create mode 100644 src/main/resources/mapper/PaOrderMapper.xml
diff --git a/src/main/java/com/pixelai/api/pa/controller/PaOrderController.java b/src/main/java/com/pixelai/api/pa/controller/PaOrderController.java
new file mode 100644
index 0000000..05443ba
--- /dev/null
+++ b/src/main/java/com/pixelai/api/pa/controller/PaOrderController.java
@@ -0,0 +1,125 @@
+package com.pixelai.api.pa.controller;
+
+import com.aliyun.core.utils.StringUtils;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.base.annotation.SysLog;
+import com.base.helper.BaseController;
+import com.base.helper.Result;
+import com.pixelai.api.domain.apy.OrderPayAppService;
+import com.pixelai.api.pa.entity.PaOrder;
+import com.pixelai.api.pa.service.PaOrderService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.annotation.*;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.Valid;
+import java.util.Collections;
+import java.util.Map;
+import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+/**
+ *
+ * 前端控制器
+ *
+ *
+ * @author gjj
+ * @since 2025-01-19
+ */
+@Api(tags = "pa订单管理")
+@RestController
+@RequestMapping("/paOrder")
+public class PaOrderController extends BaseController {
+
+ private static final Logger LOG = LoggerFactory.getLogger(PaOrderController.class);
+ @Autowired
+ private PaOrderService entityService;
+ @Autowired
+ private OrderPayAppService payAppService;
+
+ @SysLog(action = "findByPage", value = "分页查询订单")
+ @ApiOperation(value = "分页查询订单", notes = "分页查询订单")
+ @RequestMapping(method = RequestMethod.GET)
+ @ApiImplicitParams({@ApiImplicitParam(name = "size", value = "分页大小", paramType = "query"),
+ @ApiImplicitParam(name = "current", value = "当前页面:从1开始", paramType = "query")})
+ public Result> findByPage(final PaOrder example, final Page page) {
+ IPage records = entityService.page(example,page);
+ return new Result(true, records);
+ }
+
+ @SysLog(action = "one", value = "查询单个订单")
+ @ApiOperation(value = "查询单个订单")
+ @RequestMapping(value = "{id}", method = {RequestMethod.GET})
+ @ApiImplicitParam(name = "id", value = "订单ID", required = true, paramType = "path")
+ public Result one(@PathVariable final Integer id) {
+ try {
+ PaOrder entity = entityService.getById(id);
+ return new Result(true, entity);
+ } catch (Exception e) {
+ LOG.error("查询单个订单失败", e);
+ return new Result(false, new PaOrder());
+ }
+ }
+
+ @SysLog(action = "add", value = "添加订单")
+ @ApiOperation(value = "添加订单")
+ @RequestMapping(method = {RequestMethod.POST})
+ public Result add(@Valid @RequestBody final PaOrder entity, final BindingResult result) {
+ try {
+ if (result.hasErrors()) {
+ Map map = this.getErrors(result);
+ String errorMsg = map.entrySet().iterator().next().getValue();
+ return new Result(false, "保存订单失败", errorMsg, map);
+ } else {
+ entityService.save(entity);
+ return new Result(true, "成功保存订单", null);
+ }
+ } catch (Exception e) {
+ LOG.error("添加订单失败", e);
+ return new Result(false, "保存订单失败", e.getMessage());
+ }
+ }
+
+
+ @ApiOperation(value = "全部订单")
+ @RequestMapping(value = "all", method = RequestMethod.GET)
+ public Result> all(PaOrder example) {
+ List entitys = entityService.list(example);
+ if (null != entitys) {
+ return new Result<>(true, entitys);
+ }
+ return new Result<>(true, Collections.emptyList());
+ }
+
+ @ApiOperation(value = "h5支付")
+ @RequestMapping(value = "h5Pay", method = RequestMethod.GET)
+ public Result h5Pay(PaOrder order,HttpServletRequest request) {
+ // 调用业务逻辑获取支付 URL
+ String h5Url = payAppService.h5Pay(order,request);
+ // 如果没有获取到支付链接,返回失败的结果
+ if (StringUtils.isBlank(h5Url)) {
+ return new Result<>(false, "支付失败");
+ }
+
+ // 返回成功的结果
+ return new Result<>(true, h5Url);
+ }
+
+ @ApiOperation(value = "h5回调")
+ @RequestMapping(value = "payNotify", method = RequestMethod.GET)
+ public void payNotify(HttpServletRequest request) {
+ try {
+ payAppService.payNotify(request);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+}
+
diff --git a/src/main/java/com/pixelai/api/pa/dao/PaOrderMapper.java b/src/main/java/com/pixelai/api/pa/dao/PaOrderMapper.java
new file mode 100644
index 0000000..2db78cf
--- /dev/null
+++ b/src/main/java/com/pixelai/api/pa/dao/PaOrderMapper.java
@@ -0,0 +1,16 @@
+package com.pixelai.api.pa.dao;
+
+import com.pixelai.api.pa.entity.PaOrder;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ *
+ * Mapper 接口
+ *
+ *
+ * @author gjj
+ * @since 2025-01-19
+ */
+public interface PaOrderMapper extends BaseMapper {
+
+}
diff --git a/src/main/java/com/pixelai/api/pa/entity/PaOrder.java b/src/main/java/com/pixelai/api/pa/entity/PaOrder.java
new file mode 100644
index 0000000..558d55f
--- /dev/null
+++ b/src/main/java/com/pixelai/api/pa/entity/PaOrder.java
@@ -0,0 +1,69 @@
+package com.pixelai.api.pa.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+
+import java.math.BigDecimal;
+import java.time.LocalDateTime;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+import java.util.Date;
+
+import com.pixelai.api.pa.entity.enums.PayState;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ *
+ *
+ *
+ *
+ * @author gjj
+ * @since 2025-01-19
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value="PaOrder", description="")
+public class PaOrder implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @TableId(value = "id", type = IdType.AUTO)
+ private Integer id;
+
+ @ApiModelProperty(value = "用户 ID")
+ private Integer memberId;
+
+ @ApiModelProperty(value = "订单号")
+ private String orderNum;
+
+ @ApiModelProperty(value = "支付人账号")
+ private String memberAccount;
+
+ @ApiModelProperty(value = "商家账号")
+ private String merchantAccount;
+
+ @ApiModelProperty(value = "支付金额")
+ private BigDecimal amount;
+
+ @ApiModelProperty(value = "创建时间")
+ private Date createTime;
+
+ @ApiModelProperty(value = "支付用途")
+ private String orderType;
+
+ @ApiModelProperty(value = "支付状态")
+ private PayState payStatus;
+
+ @ApiModelProperty(value = "支付结果")
+ private String result;
+
+ @ApiModelProperty(value = "状态(有效:t 无效:f)")
+ private String state;
+
+ @ApiModelProperty(value = "1-5, 2-10, 3-20, 4-30, 5-50, 6-100")
+ private String buyType;
+}
diff --git a/src/main/java/com/pixelai/api/pa/service/PaOrderService.java b/src/main/java/com/pixelai/api/pa/service/PaOrderService.java
new file mode 100644
index 0000000..07b4dda
--- /dev/null
+++ b/src/main/java/com/pixelai/api/pa/service/PaOrderService.java
@@ -0,0 +1,41 @@
+package com.pixelai.api.pa.service;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.pixelai.api.pa.entity.PaOrder;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
+/**
+ *
+ * 服务类
+ *
+ *
+ * @author gjj
+ * @since 2025-01-19
+ */
+public interface PaOrderService extends IService {
+
+ /**
+ * 条件查询
+ * @param example
+ * @return
+ */
+ List list(PaOrder example);
+
+ /**
+ * 分页查询
+ * @param example
+ * @param page
+ * @return
+ */
+ IPage page(PaOrder example, IPage page);
+
+ /**
+ * 订单号查询订单
+ * @param outTradeNo
+ * @return
+ */
+ PaOrder getOrderByTradeNo(String outTradeNo);
+}
diff --git a/src/main/java/com/pixelai/api/pa/service/impl/PaOrderServiceImpl.java b/src/main/java/com/pixelai/api/pa/service/impl/PaOrderServiceImpl.java
new file mode 100644
index 0000000..76f99ac
--- /dev/null
+++ b/src/main/java/com/pixelai/api/pa/service/impl/PaOrderServiceImpl.java
@@ -0,0 +1,63 @@
+package com.pixelai.api.pa.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.pixelai.api.pa.dao.PaOrderMapper;
+import com.pixelai.api.pa.entity.PaOrder;
+import com.pixelai.api.pa.service.PaOrderService;
+import com.pixelai.config.WeChatConfig;
+import com.pixelai.utils.WeChatUtil;
+import com.wechat.pay.java.core.exception.MalformedMessageException;
+import com.wechat.pay.java.service.payments.h5.H5Service;
+import com.wechat.pay.java.service.payments.h5.model.*;
+import eu.bitwalker.useragentutils.UserAgent;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import java.util.List;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ *
+ * 服务实现类
+ *
+ *
+ * @author gjj
+ * @since 2025-01-19
+ */
+@Service
+public class PaOrderServiceImpl extends ServiceImpl implements PaOrderService {
+
+
+ @Override
+ public List list(PaOrder example) {
+ return this.list(buildWrapper(example));
+ }
+
+ @Override
+ public IPage page(PaOrder example, IPage page) {
+ return this.page(page,buildWrapper(example));
+ }
+
+ @Override
+ public PaOrder getOrderByTradeNo(String outTradeNo) {
+ QueryWrapper queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("out_trade_no", outTradeNo);
+ queryWrapper.eq("state", "t");
+ return this.getOne(queryWrapper);
+ }
+
+
+ /**
+ * 构建查询
+ *
+ * @param example
+ * @return
+ */
+ private QueryWrapper buildWrapper(PaOrder example) {
+ QueryWrapper wrapper = new QueryWrapper<>();
+ return wrapper;
+ }
+
+}
diff --git a/src/main/resources/mapper/PaOrderMapper.xml b/src/main/resources/mapper/PaOrderMapper.xml
new file mode 100644
index 0000000..4c902df
--- /dev/null
+++ b/src/main/resources/mapper/PaOrderMapper.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+