feat(商品): 添加获取单个商品信息功能
新增获取单个商品信息的接口,包括在GoodsApplicationService、ShopGoodsService、ShopGoodsServiceImpl、ShopGoodsMapper中实现相关逻辑,并在ShopGoodsController中提供对外接口。 feat(支付日志): 添加支付操作日志记录功能 在支付回调、退款回调、提交订单、创建订单、退款等操作中添加支付操作日志记录功能,记录操作类型、状态、参数等信息,便于后续追踪和分析。
This commit is contained in:
parent
0426a879b8
commit
1945cb1787
|
@ -14,20 +14,13 @@ import io.swagger.v3.oas.annotations.Operation;
|
|||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.agileboot.common.core.base.BaseController;
|
||||
import com.agileboot.domain.shop.goods.command.AddGoodsCommand;
|
||||
import com.agileboot.domain.shop.goods.command.UpdateGoodsCommand;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -83,5 +76,16 @@ public class ShopGoodsController extends BaseController {
|
|||
goodsApplicationService.updateGoods(command);
|
||||
return ResponseDTO.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个商品信息
|
||||
*/
|
||||
@Operation(summary = "商品列表")
|
||||
// @PreAuthorize("@permission.has('shop:goods:list')")
|
||||
@GetMapping("/getGoodsInfo")
|
||||
public ResponseDTO<ShopGoodsDTO> getGoodsInfo(@RequestParam Long goodsId) {
|
||||
ShopGoodsDTO goodsInfo = goodsApplicationService.getGoodsInfo(goodsId);
|
||||
return ResponseDTO.ok(goodsInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.agileboot.api.controller;
|
|||
import cn.hutool.json.JSONUtil;
|
||||
import com.agileboot.common.constant.PayApiConstants;
|
||||
import com.agileboot.common.core.base.BaseController;
|
||||
import com.agileboot.common.exception.ApiException;
|
||||
import com.agileboot.common.exception.error.ErrorCode;
|
||||
import com.agileboot.domain.cabinet.operation.command.AddCabinetCellOperationCommand;
|
||||
import com.agileboot.domain.shop.order.dto.CreateOrderResult;
|
||||
import com.agileboot.domain.shop.order.dto.GetOrdersByOpenIdDTO;
|
||||
|
@ -10,7 +12,11 @@ import com.agileboot.domain.shop.order.model.OrderGoodsModelFactory;
|
|||
import com.agileboot.domain.shop.order.model.OrderModel;
|
||||
import com.agileboot.domain.shop.payment.PaymentApplicationService;
|
||||
import com.agileboot.domain.shop.payment.dto.RefundVO;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.PaymentOperationLogApplicationService;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.agileboot.common.core.dto.ResponseDTO;
|
||||
|
@ -33,6 +39,7 @@ public class OrderController extends BaseController {
|
|||
|
||||
private final OrderApplicationService orderApplicationService;
|
||||
private final PaymentApplicationService paymentApplicationService;
|
||||
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
|
||||
|
||||
/**
|
||||
* 提交订单接口
|
||||
|
@ -41,8 +48,20 @@ public class OrderController extends BaseController {
|
|||
*/
|
||||
@PostMapping("/submit")
|
||||
public ResponseDTO<CreateOrderResult> submitOrder(@Validated @RequestBody SubmitOrderCommand command) {
|
||||
CreateOrderResult result = orderApplicationService.createOrder(command);
|
||||
return ResponseDTO.ok(result);
|
||||
try {
|
||||
CreateOrderResult result = orderApplicationService.createOrder(command);
|
||||
return ResponseDTO.ok(result);
|
||||
} catch (Exception e) {
|
||||
log.error("submitOrder error: ", e);
|
||||
AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand();
|
||||
paymentOperationLogCommand.setParams(JSONUtil.toJsonStr(command));
|
||||
paymentOperationLogCommand.setOperationType("submitOrder");
|
||||
paymentOperationLogCommand.setStatus(2);
|
||||
paymentOperationLogCommand.setRemark(ExceptionUtils.getStackTrace(e));
|
||||
paymentOperationLogCommand.initBaseEntity();
|
||||
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
|
||||
return ResponseDTO.fail(new ApiException(ErrorCode.Internal.INTERNAL_ERROR, e));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,6 +28,8 @@ import java.nio.charset.StandardCharsets;
|
|||
import java.util.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.agileboot.domain.shop.paymentOperationLog.PaymentOperationLogApplicationService;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
|
||||
import com.agileboot.domain.system.menu.MenuApplicationService;
|
||||
import com.agileboot.domain.system.menu.dto.RouterDTO;
|
||||
import com.agileboot.domain.system.user.db.SysUserEntity;
|
||||
|
@ -63,6 +65,7 @@ public class PaymentController {
|
|||
private final SysUserQyUserApplicationService sysUserQyUserApplicationService;
|
||||
private final MenuApplicationService menuApplicationService;
|
||||
private final PaymentApplicationService paymentApplicationService;
|
||||
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
|
||||
|
||||
// 新增回调接口
|
||||
/**
|
||||
|
@ -78,6 +81,13 @@ public class PaymentController {
|
|||
@PostMapping("/callback")
|
||||
public String paymentCallback(HttpServletRequest request, @RequestBody String requestBody) {
|
||||
log.info("支付回调requestBody:{}", requestBody);
|
||||
// 记录支付操作日志
|
||||
AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand();
|
||||
paymentOperationLogCommand.setOperationType("payCallback");
|
||||
paymentOperationLogCommand.setStatus(1);
|
||||
paymentOperationLogCommand.setRemark(requestBody);
|
||||
paymentOperationLogCommand.initBaseEntity();
|
||||
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
|
||||
try {
|
||||
paymentApplicationService.paymentCallback(requestBody);
|
||||
return "success";
|
||||
|
@ -108,6 +118,13 @@ public class PaymentController {
|
|||
@PostMapping("/refund/callback")
|
||||
public String refundCallback(HttpServletRequest request, @RequestBody String requestBody) {
|
||||
log.info("退款回调requestBody:{}", requestBody);
|
||||
// 记录支付操作日志
|
||||
AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand();
|
||||
paymentOperationLogCommand.setOperationType("refundCallback");
|
||||
paymentOperationLogCommand.setStatus(1);
|
||||
paymentOperationLogCommand.setRemark(requestBody);
|
||||
paymentOperationLogCommand.initBaseEntity();
|
||||
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
|
||||
try {
|
||||
return paymentApplicationService.refundCallback(requestBody);
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.agileboot.domain.shop.approval;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.agileboot.common.constant.PayApiConstants;
|
||||
import com.agileboot.common.constant.WeixinConstants;
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
|
@ -32,6 +33,8 @@ import com.agileboot.domain.shop.order.model.OrderModel;
|
|||
import com.agileboot.domain.shop.order.model.OrderModelFactory;
|
||||
import com.agileboot.domain.shop.payment.PaymentApplicationService;
|
||||
import com.agileboot.domain.shop.payment.dto.RefundVO;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.PaymentOperationLogApplicationService;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
@ -45,6 +48,7 @@ import lombok.RequiredArgsConstructor;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
|
@ -66,6 +70,7 @@ public class ReturnApprovalApplicationService {
|
|||
private final QyUserService qyUserService;
|
||||
private final CabinetCellModelFactory cabinetCellModelFactory;
|
||||
private final QyUserService userService;
|
||||
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
|
||||
|
||||
/**
|
||||
* 获取退货审批列表
|
||||
|
@ -150,7 +155,22 @@ public class ReturnApprovalApplicationService {
|
|||
PayApiConstants.biz_id, PayApiConstants.appkey,
|
||||
orderModel.getBizOrderId(), orderModel.getUcid(),
|
||||
"退还", returnAmount.intValue());
|
||||
|
||||
AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand();
|
||||
paymentOperationLogCommand.setParams(JSONUtil.toJsonStr(command));
|
||||
paymentOperationLogCommand.setOperationType("refund");
|
||||
paymentOperationLogCommand.setStatus(1);
|
||||
paymentOperationLogCommand.setRemark(JSONUtil.toJsonStr(refundVO));
|
||||
paymentOperationLogCommand.initBaseEntity();
|
||||
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
|
||||
} catch (Exception e) {
|
||||
AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand();
|
||||
paymentOperationLogCommand.setParams(JSONUtil.toJsonStr(command));
|
||||
paymentOperationLogCommand.setOperationType("refund");
|
||||
paymentOperationLogCommand.setStatus(2);
|
||||
paymentOperationLogCommand.setRemark(ExceptionUtils.getStackTrace(e));
|
||||
paymentOperationLogCommand.initBaseEntity();
|
||||
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
|
||||
throw new RuntimeException("退款失败", e);
|
||||
}
|
||||
log.info("退款结果:{}", refundVO);
|
||||
|
|
|
@ -65,4 +65,8 @@ public class GoodsApplicationService {
|
|||
public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList() {
|
||||
return shopGoodsService.getGoodsWithCabinetList();
|
||||
}
|
||||
|
||||
public ShopGoodsDTO getGoodsInfo(Long goodsId) {
|
||||
return new ShopGoodsDTO(shopGoodsService.getGoodsInfo(goodsId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,4 +71,14 @@ public interface ShopGoodsMapper extends BaseMapper<ShopGoodsEntity> {
|
|||
"LEFT JOIN smart_cabinet sc ON cc.cabinet_id = sc.cabinet_id " +
|
||||
"WHERE g.deleted = 0 AND sc.deleted = 0 AND cc.deleted = 0 AND cc.goods_id IS NOT NULL ")
|
||||
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList();
|
||||
|
||||
@Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " +
|
||||
"g.stock, g.status, g.auto_approval, g.cover_img, SUM(cc.stock) AS total_stock, " +
|
||||
"GROUP_CONCAT(DISTINCT cc.cell_no) AS cell_no_str, " +
|
||||
"GROUP_CONCAT(DISTINCT sc.cabinet_name) AS cabinet_name " +
|
||||
"FROM shop_goods g " +
|
||||
"LEFT JOIN cabinet_cell cc ON g.goods_id = cc.goods_id AND cc.deleted = 0 " +
|
||||
"LEFT JOIN smart_cabinet sc ON cc.cabinet_id = sc.cabinet_id AND sc.deleted = 0 " +
|
||||
"WHERE g.goods_id = #{goodsId} ")
|
||||
SearchGoodsDO getGoodsInfo(@Param("goodsId") Long goodsId);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.agileboot.domain.shop.goods.db;
|
|||
import com.agileboot.common.core.page.AbstractPageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -19,4 +20,6 @@ public interface ShopGoodsService extends IService<ShopGoodsEntity> {
|
|||
List<ShopGoodsEntity> selectAll();
|
||||
|
||||
List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList();
|
||||
|
||||
SearchGoodsDO getGoodsInfo(Long goodsId);
|
||||
}
|
||||
|
|
|
@ -34,4 +34,9 @@ public class ShopGoodsServiceImpl extends ServiceImpl<ShopGoodsMapper, ShopGoods
|
|||
public List<SearchGoodsWithCabinetDO> getGoodsWithCabinetList() {
|
||||
return baseMapper.getGoodsWithCabinetList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SearchGoodsDO getGoodsInfo(Long goodsId) {
|
||||
return baseMapper.getGoodsInfo(goodsId);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ import com.agileboot.domain.shop.order.query.SearchShopOrderQuery;
|
|||
import com.agileboot.domain.shop.payment.PaymentApplicationService;
|
||||
import com.agileboot.domain.shop.payment.dto.WxJsApiPreCreateRequest;
|
||||
import com.agileboot.domain.shop.payment.dto.WxJsApiPreCreateResponse;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.PaymentOperationLogApplicationService;
|
||||
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
@ -48,6 +50,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.checkerframework.checker.units.qual.s;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -69,6 +72,7 @@ public class OrderApplicationService {
|
|||
private final QyUserService userService;
|
||||
private final QyUserModelFactory qyUserModelFactory;
|
||||
private final CabinetCellOperationModelFactory cabinetCellOperationModelFactory;
|
||||
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
|
||||
|
||||
public PageDTO<ShopOrderEntity> getOrderList(SearchShopOrderQuery<ShopOrderEntity> query) {
|
||||
Page<ShopOrderEntity> page = orderService.page(query.toPage(), query.toQueryWrapper());
|
||||
|
@ -164,6 +168,14 @@ public class OrderApplicationService {
|
|||
// 新增支付接口调用
|
||||
WxJsApiPreCreateRequest paymentRequest = buildPaymentRequest(orderModel);
|
||||
WxJsApiPreCreateResponse paymentResponse = paymentApplicationService.callJsApiPreCreate(paymentRequest);
|
||||
// 记录支付操作日志
|
||||
AddPaymentOperationLogCommand paymentOperationLogCommand = new AddPaymentOperationLogCommand();
|
||||
paymentOperationLogCommand.setParams(JSONUtil.toJsonStr(command));
|
||||
paymentOperationLogCommand.setOperationType("callJsApiPreCreate");
|
||||
paymentOperationLogCommand.setStatus(1);
|
||||
paymentOperationLogCommand.setRemark(JSONUtil.toJsonStr(paymentResponse));
|
||||
paymentOperationLogCommand.initBaseEntity();
|
||||
paymentOperationLogApplicationService.addPaymentOperationLog(paymentOperationLogCommand);
|
||||
|
||||
return new CreateOrderResult(orderModel.getOrderId(), orderModel.getTotalAmount(), paymentResponse, BigDecimal.valueOf(0));
|
||||
} else if (Objects.equals(command.getPaymentType(), "balance")) {
|
||||
|
|
|
@ -39,10 +39,17 @@ public class PaymentOperationLogEntity extends BaseEntity<PaymentOperationLogEnt
|
|||
@TableField("`status`")
|
||||
private Integer status;
|
||||
|
||||
@ApiModelProperty("操作类型")
|
||||
@TableField("operation_type")
|
||||
private String operationType;
|
||||
|
||||
@ApiModelProperty("操作备注")
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty("操作参数")
|
||||
@TableField("params")
|
||||
private String params;
|
||||
|
||||
@Override
|
||||
public Serializable pkVal() {
|
||||
|
|
|
@ -29,9 +29,15 @@ public class PaymentOperationLogDTO {
|
|||
@ExcelColumn(name = "操作状态")
|
||||
private String statusStr;
|
||||
|
||||
@ExcelColumn(name = "操作类型")
|
||||
private String operationType;
|
||||
|
||||
@ExcelColumn(name = "操作备注")
|
||||
private String remark;
|
||||
|
||||
@ExcelColumn(name = "操作参数")
|
||||
private String params;
|
||||
|
||||
@ExcelColumn(name = "操作人")
|
||||
private String operatorName;
|
||||
}
|
|
@ -12,4 +12,12 @@ CREATE TABLE `payment_operation_log` (
|
|||
`deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '删除标志(0存在 1删除)',
|
||||
PRIMARY KEY (`log_id`),
|
||||
KEY `idx_create_time` (`create_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='支付操作日志表';
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='支付操作日志表';
|
||||
|
||||
ALTER TABLE `payment_operation_log`
|
||||
ADD COLUMN `operation_type` VARCHAR(50) NULL DEFAULT '' COMMENT '操作类型'
|
||||
AFTER `status`;
|
||||
|
||||
ALTER TABLE `payment_operation_log`
|
||||
ADD COLUMN `params` TEXT DEFAULT NULL COMMENT '操作参数'
|
||||
AFTER `remark`;
|
Loading…
Reference in New Issue