feat(支付操作日志): 新增支付操作日志模块

新增支付操作日志模块,包括实体类、Mapper、Service、DTO、查询条件、命令类、控制器等。支持支付操作日志的增删改查功能,并提供了根据订单ID查询最新日志的功能。
This commit is contained in:
dzq 2025-04-25 09:58:13 +08:00
parent cb7cb21754
commit 0426a879b8
15 changed files with 468 additions and 1 deletions

View File

@ -0,0 +1,68 @@
package com.agileboot.admin.controller.shop;
import com.agileboot.admin.customize.aop.accessLog.AccessLog;
import com.agileboot.common.core.base.BaseController;
import com.agileboot.common.core.dto.ResponseDTO;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.common.enums.common.BusinessTypeEnum;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.shop.paymentOperationLog.PaymentOperationLogApplicationService;
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
import com.agileboot.domain.shop.paymentOperationLog.command.UpdatePaymentOperationLogCommand;
import com.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogEntity;
import com.agileboot.domain.shop.paymentOperationLog.dto.PaymentOperationLogDTO;
import com.agileboot.domain.shop.paymentOperationLog.query.SearchPaymentOperationLogQuery;
import io.swagger.v3.oas.annotations.Operation;
import java.util.List;
import javax.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
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;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/shop/paymentOperationLogs")
@RequiredArgsConstructor
@Validated
public class PaymentOperationLogController extends BaseController {
private final PaymentOperationLogApplicationService paymentOperationLogApplicationService;
@Operation(summary = "支付操作日志列表")
@GetMapping
public ResponseDTO<PageDTO<PaymentOperationLogDTO>> list(SearchPaymentOperationLogQuery<PaymentOperationLogEntity> query) {
PageDTO<PaymentOperationLogDTO> page = paymentOperationLogApplicationService.getPaymentOperationLogList(query);
return ResponseDTO.ok(page);
}
@Operation(summary = "新增支付操作日志")
@AccessLog(title = "支付操作日志管理", businessType = BusinessTypeEnum.ADD)
@PostMapping
public ResponseDTO<Void> add(@Validated @RequestBody AddPaymentOperationLogCommand command) {
paymentOperationLogApplicationService.addPaymentOperationLog(command);
return ResponseDTO.ok();
}
@Operation(summary = "修改支付操作日志")
@AccessLog(title = "支付操作日志管理", businessType = BusinessTypeEnum.MODIFY)
@PutMapping("/{logId}")
public ResponseDTO<Void> edit(@PathVariable Long logId, @Validated @RequestBody UpdatePaymentOperationLogCommand command) {
command.setLogId(logId);
paymentOperationLogApplicationService.updatePaymentOperationLog(command);
return ResponseDTO.ok();
}
@Operation(summary = "删除支付操作日志")
@AccessLog(title = "支付操作日志管理", businessType = BusinessTypeEnum.DELETE)
@DeleteMapping("/{ids}")
public ResponseDTO<Void> remove(@PathVariable @NotNull List<Long> ids) {
paymentOperationLogApplicationService.deletePaymentOperationLog(new BulkOperationCommand<>(ids));
return ResponseDTO.ok();
}
}

View File

@ -0,0 +1,57 @@
package com.agileboot.domain.shop.paymentOperationLog;
import com.agileboot.common.core.page.PageDTO;
import com.agileboot.domain.common.command.BulkOperationCommand;
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
import com.agileboot.domain.shop.paymentOperationLog.command.UpdatePaymentOperationLogCommand;
import com.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogEntity;
import com.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogService;
import com.agileboot.domain.shop.paymentOperationLog.dto.PaymentOperationLogDTO;
import com.agileboot.domain.shop.paymentOperationLog.model.PaymentOperationLogModel;
import com.agileboot.domain.shop.paymentOperationLog.model.PaymentOperationLogModelFactory;
import com.agileboot.domain.shop.paymentOperationLog.query.SearchPaymentOperationLogQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@Slf4j
@Service
@RequiredArgsConstructor
public class PaymentOperationLogApplicationService {
private final PaymentOperationLogService paymentOperationLogService;
private final PaymentOperationLogModelFactory paymentOperationLogModelFactory;
public PageDTO<PaymentOperationLogDTO> getPaymentOperationLogList(SearchPaymentOperationLogQuery<PaymentOperationLogEntity> query) {
Page<PaymentOperationLogEntity> page = paymentOperationLogService.getPaymentLogList(query);
List<PaymentOperationLogDTO> dtoList = page.getRecords().stream()
.map(PaymentOperationLogDTO::new)
.collect(Collectors.toList());
return new PageDTO<>(dtoList, page.getTotal());
}
public void addPaymentOperationLog(AddPaymentOperationLogCommand command) {
PaymentOperationLogModel model = paymentOperationLogModelFactory.create();
model.loadAddCommand(command);
model.insert();
}
public void updatePaymentOperationLog(UpdatePaymentOperationLogCommand command) {
PaymentOperationLogModel model = paymentOperationLogModelFactory.loadById(command.getLogId());
model.loadUpdateCommand(command);
model.updateById();
}
public void deletePaymentOperationLog(BulkOperationCommand<Long> command) {
for (Long logId : command.getIds()) {
PaymentOperationLogModel model = paymentOperationLogModelFactory.loadById(logId);
model.deleteById();
}
}
public PaymentOperationLogEntity selectLatestByOrderId(Long orderId) {
return paymentOperationLogService.selectLatestByOrderId(orderId);
}
}

View File

@ -0,0 +1,11 @@
package com.agileboot.domain.shop.paymentOperationLog.command;
import com.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class AddPaymentOperationLogCommand extends PaymentOperationLogEntity {
}

View File

@ -0,0 +1,16 @@
package com.agileboot.domain.shop.paymentOperationLog.command;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.PositiveOrZero;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class UpdatePaymentOperationLogCommand extends AddPaymentOperationLogCommand {
@NotNull
@PositiveOrZero
private Long logId;
}

View File

@ -0,0 +1,52 @@
package com.agileboot.domain.shop.paymentOperationLog.db;
import com.agileboot.common.core.base.BaseEntity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 支付操作日志表
* </p>
*
* @author valarchie
* @since 2025-04-25
*/
@Getter
@Setter
@TableName("payment_operation_log")
@ApiModel(value = "PaymentOperationLogEntity对象", description = "支付操作日志表")
public class PaymentOperationLogEntity extends BaseEntity<PaymentOperationLogEntity> {
private static final long serialVersionUID = 1L;
@ApiModelProperty("日志ID")
@TableId(value = "log_id", type = IdType.AUTO)
private Long logId;
@ApiModelProperty("订单ID关联shop_order.order_id")
@TableField("order_id")
private Long orderId;
@ApiModelProperty("操作状态1成功 2失败")
@TableField("`status`")
private Integer status;
@ApiModelProperty("操作备注")
@TableField("remark")
private String remark;
@Override
public Serializable pkVal() {
return this.logId;
}
}

View File

@ -0,0 +1,40 @@
package com.agileboot.domain.shop.paymentOperationLog.db;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
/**
* <p>
* 支付操作日志表 Mapper 接口
* </p>
*
* @author valarchie
* @since 2025-04-25
*/
public interface PaymentOperationLogMapper extends BaseMapper<PaymentOperationLogEntity> {
@Select("SELECT * " +
"FROM payment_operation_log " +
"${ew.customSqlSegment}")
Page<PaymentOperationLogEntity> getPaymentLogList(
Page<PaymentOperationLogEntity> page,
@Param(Constants.WRAPPER) Wrapper<PaymentOperationLogEntity> queryWrapper
);
@Select("SELECT * FROM payment_operation_log WHERE order_id = #{orderId} ORDER BY create_time DESC LIMIT 1")
PaymentOperationLogEntity selectLatestByOrderId(Long orderId);
@Select("SELECT * FROM payment_operation_log WHERE status = #{status} ORDER BY create_time DESC")
List<PaymentOperationLogEntity> selectByStatus(Integer status);
@Select("SELECT * FROM payment_operation_log WHERE order_id = #{orderId} AND status = #{status}")
PaymentOperationLogEntity selectByOrderAndStatus(
@Param("orderId") Long orderId,
@Param("status") Integer status
);
}

View File

@ -0,0 +1,26 @@
package com.agileboot.domain.shop.paymentOperationLog.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;
/**
* <p>
* 支付操作日志表 服务类
* </p>
*
* @author valarchie
* @since 2025-04-25
*/
public interface PaymentOperationLogService extends IService<PaymentOperationLogEntity> {
Page<PaymentOperationLogEntity> getPaymentLogList(AbstractPageQuery<PaymentOperationLogEntity> query);
List<PaymentOperationLogEntity> selectAll();
PaymentOperationLogEntity selectLatestByOrderId(Long orderId);
PaymentOperationLogEntity selectByOrderAndStatus(Long orderId, Integer status);
}

View File

@ -0,0 +1,40 @@
package com.agileboot.domain.shop.paymentOperationLog.db;
import com.agileboot.common.core.page.AbstractPageQuery;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* <p>
* 支付操作日志表 服务实现类
* </p>
*
* @author valarchie
* @since 2025-04-25
*/
@Service
public class PaymentOperationLogServiceImpl extends ServiceImpl<PaymentOperationLogMapper, PaymentOperationLogEntity> implements PaymentOperationLogService {
@Override
public Page<PaymentOperationLogEntity> getPaymentLogList(AbstractPageQuery<PaymentOperationLogEntity> query) {
return this.page(query.toPage(), query.toQueryWrapper());
}
@Override
public List<PaymentOperationLogEntity> selectAll() {
return this.list();
}
@Override
public PaymentOperationLogEntity selectLatestByOrderId(Long orderId) {
return baseMapper.selectLatestByOrderId(orderId);
}
@Override
public PaymentOperationLogEntity selectByOrderAndStatus(Long orderId, Integer status) {
return baseMapper.selectByOrderAndStatus(orderId, status);
}
}

View File

@ -0,0 +1,37 @@
package com.agileboot.domain.shop.paymentOperationLog.dto;
import cn.hutool.core.bean.BeanUtil;
import com.agileboot.common.annotation.ExcelColumn;
import com.agileboot.common.annotation.ExcelSheet;
import com.agileboot.domain.common.cache.CacheCenter;
import com.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogEntity;
import com.agileboot.domain.system.user.db.SysUserEntity;
import lombok.Data;
@ExcelSheet(name = "支付操作日志列表")
@Data
public class PaymentOperationLogDTO {
public PaymentOperationLogDTO(PaymentOperationLogEntity entity) {
if (entity != null) {
BeanUtil.copyProperties(entity, this);
this.statusStr = entity.getStatus() == 1 ? "成功" : "失败";
}
}
@ExcelColumn(name = "日志ID")
private Long logId;
@ExcelColumn(name = "订单ID")
private Long orderId;
@ExcelColumn(name = "操作状态")
private String statusStr;
@ExcelColumn(name = "操作备注")
private String remark;
@ExcelColumn(name = "操作人")
private String operatorName;
}

View File

@ -0,0 +1,39 @@
package com.agileboot.domain.shop.paymentOperationLog.model;
import cn.hutool.core.bean.BeanUtil;
import com.agileboot.domain.shop.paymentOperationLog.command.AddPaymentOperationLogCommand;
import com.agileboot.domain.shop.paymentOperationLog.command.UpdatePaymentOperationLogCommand;
import com.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogEntity;
import com.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogService;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class PaymentOperationLogModel extends PaymentOperationLogEntity {
private PaymentOperationLogService paymentOperationLogService;
public PaymentOperationLogModel(PaymentOperationLogEntity entity, PaymentOperationLogService paymentOperationLogService) {
this(paymentOperationLogService);
if (entity != null) {
BeanUtil.copyProperties(entity, this);
}
}
public PaymentOperationLogModel(PaymentOperationLogService paymentOperationLogService) {
this.paymentOperationLogService = paymentOperationLogService;
}
public void loadAddCommand(AddPaymentOperationLogCommand command) {
if (command != null) {
BeanUtil.copyProperties(command, this, "logId");
}
}
public void loadUpdateCommand(UpdatePaymentOperationLogCommand command) {
if (command != null) {
loadAddCommand(command);
}
}
}

View File

@ -0,0 +1,27 @@
package com.agileboot.domain.shop.paymentOperationLog.model;
import com.agileboot.common.exception.ApiException;
import com.agileboot.common.exception.error.ErrorCode;
import com.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogEntity;
import com.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
public class PaymentOperationLogModelFactory {
private final PaymentOperationLogService paymentOperationLogService;
public PaymentOperationLogModel loadById(Long logId) {
PaymentOperationLogEntity entity = paymentOperationLogService.getById(logId);
if (entity == null) {
throw new ApiException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, logId, "支付操作日志");
}
return new PaymentOperationLogModel(entity, paymentOperationLogService);
}
public PaymentOperationLogModel create() {
return new PaymentOperationLogModel(paymentOperationLogService);
}
}

View File

@ -0,0 +1,34 @@
package com.agileboot.domain.shop.paymentOperationLog.query;
import cn.hutool.core.util.StrUtil;
import com.agileboot.common.core.page.AbstractPageQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import java.util.Date;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class SearchPaymentOperationLogQuery<T> extends AbstractPageQuery<T> {
private Long orderId;
private Integer status;
private String remark;
private Date startTime;
private Date endTime;
@Override
public QueryWrapper<T> addQueryCondition() {
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
queryWrapper
.eq(orderId != null, "order_id", orderId)
.eq(status != null, "`status`", status)
.like(StrUtil.isNotEmpty(remark), "remark", remark)
.between(startTime != null && endTime != null, "create_time", startTime, endTime);
this.timeRangeColumn = "create_time";
return queryWrapper;
}
}

View File

@ -0,0 +1,5 @@
<?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.agileboot.domain.shop.paymentOperationLog.db.PaymentOperationLogMapper">
</mapper>

View File

@ -61,7 +61,7 @@ public class CodeGenerator {
//生成的类 放在orm子模块下的/target/generated-code目录底下
.module("/agileboot-orm/target/generated-code")
.parentPackage("com.agileboot")
.tableName("cabinet_cell_operation")
.tableName("payment_operation_log")
// 决定是否继承基类
.isExtendsFromBaseEntity(true)
.build();

View File

@ -0,0 +1,15 @@
DROP TABLE IF EXISTS `payment_operation_log`;
CREATE TABLE `payment_operation_log` (
`log_id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '日志ID',
`order_id` BIGINT NULL COMMENT '订单ID关联shop_order.order_id',
`status` TINYINT NOT NULL DEFAULT 1 COMMENT '操作状态1成功 2失败',
`creator_id` BIGINT NOT NULL DEFAULT 0 COMMENT '创建者ID',
`create_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`updater_id` BIGINT NOT NULL DEFAULT 0 COMMENT '更新者ID',
`update_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`remark` TEXT DEFAULT NULL COMMENT '操作备注',
`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='支付操作日志表';