feat:钱包规则代码生成

This commit is contained in:
dzc committed 2025-03-30 18:24:14 +08:00
1 parent bb80b19925
commit 00e53e3f4d
17 files changed
+323 -16

No files matched your search

+47
View File
@@ -173,6 +173,53 @@ CREATE TABLE wallet_type
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4 COMMENT ='钱包类型';
-- ----------------------------
-- Table structure for wallet_rule_join
-- ----------------------------
DROP TABLE IF EXISTS wallet_rule_join;
CREATE TABLE wallet_rule_join
(
id BIGINT(19) not null comment '主键',
source_wallet_type_id BIGINT(19) not null comment '源钱包类型id',
target_wallet_type_id BIGINT(19) not null comment '目标钱包类型id',
balance_multiple int DEFAULT 0 NOT NULL COMMENT '钱包转换百分比',
status VARCHAR(64) default '0' not null comment '是否启用',
create_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
create_time datetime DEFAULT NULL COMMENT '创建时间',
update_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
update_time datetime DEFAULT NULL COMMENT '修改时间',
del_flag char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标记',
tenant_id bigint DEFAULT NULL COMMENT '租户ID',
PRIMARY KEY (id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = '钱包规则配置';
-- ----------------------------
-- Table structure for wallet_rule_transaction
-- ----------------------------
DROP TABLE IF EXISTS wallet_rule_transaction;
CREATE TABLE wallet_rule_transaction
(
id BIGINT(19) not null comment '主键',
source_wallet_id BIGINT(19) not null comment '源钱包id',
target_wallet_id BIGINT(19) not null comment '目标钱包id',
source_wallet_balance int not null comment '源钱包余额',
target_wallet_balance int not null comment '目标钱包余额',
balance int DEFAULT 0 NOT NULL COMMENT '转换金额',
after_balance int DEFAULT 0 NOT NULL COMMENT '转换后的金额',
balance_multiple int DEFAULT 0 NOT NULL COMMENT '钱包转换百分比',
status VARCHAR(64) default '0' not null comment '是否启用',
create_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '创建人',
create_time datetime DEFAULT NULL COMMENT '创建时间',
update_by varchar(64) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '修改人',
update_time datetime DEFAULT NULL COMMENT '修改时间',
del_flag char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标记',
tenant_id bigint DEFAULT NULL COMMENT '租户ID',
PRIMARY KEY (id)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_general_ci COMMENT = '钱包转账记录';
-- ----------------------------
-- Table structure for wallet_active
@@ -1,4 +1,4 @@
package com.bsd.pjcloud.wallet.api.constant;
package com.bsd.pjcloud.wallet.api.constant.mch;
import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
@@ -11,7 +11,7 @@ import java.util.Arrays;
*/
@Getter
@AllArgsConstructor
public enum WalletRulePriceTypeEnum {
public enum WalletMchRulePriceTypeEnum {
STRIDE_LIMIT("10", "跨单位额外支付"),
EVERY_LIMIT("20", "每餐额外支付"),
;
@@ -19,7 +19,7 @@ public enum WalletRulePriceTypeEnum {
private final String code;
private final String desc;
public static WalletRulePriceTypeEnum valueOfByCode(String code) {
public static WalletMchRulePriceTypeEnum valueOfByCode(String code) {
if (ObjectUtil.isEmpty(code)) return null;
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(code, v.getCode())).findFirst().get();
}
@@ -0,0 +1,14 @@
package com.bsd.pjcloud.wallet.api.dto.rule;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleJoinEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WalletRuleJoinDto extends WalletRuleJoinEntity {
}
@@ -25,6 +25,7 @@ public class MchRulePriceConfigEntity extends Model<MchRulePriceConfigEntity> {
/**
* 规则类型
* @see
*/
@Schema(description = "规则类型")
private String rulePriceType;
@@ -0,0 +1,94 @@
package com.bsd.pjcloud.wallet.api.entity.rule;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.bsd.pjcloud.common.core.util.TenantTable;
import java.time.LocalDateTime;
/**
* 钱包规则配置
*/
@Data
@TenantTable
@TableName("wallet_rule_join")
@EqualsAndHashCode(callSuper = true)
@Schema(description = "钱包规则配置")
public class WalletRuleJoinEntity extends Model<WalletRuleJoinEntity> {
/**
* 主键
*/
@TableId(type = IdType.ASSIGN_ID)
@Schema(description="主键")
private Long id;
/**
* 源钱包类型id
*/
@Schema(description="源钱包类型id")
private Long sourceWalletTypeId;
/**
* 目标钱包类型id
*/
@Schema(description="目标钱包类型id")
private Long targetWalletTypeId;
/**
* 钱包转换百分比
*/
@Schema(description="钱包转换百分比")
private Integer balanceMultiple;
/**
* 是否启用
*/
@Schema(description="是否启用")
private String status;
/**
* 创建人
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建人")
private String createBy;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
@Schema(description="创建时间")
private LocalDateTime createTime;
/**
* 修改人
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="修改人")
private String updateBy;
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
@Schema(description="修改时间")
private LocalDateTime updateTime;
/**
* 删除标记
*/
@TableLogic
@TableField(fill = FieldFill.INSERT)
@Schema(description="删除标记")
private String delFlag;
/**
* 租户ID
*/
@Schema(description="租户ID")
private Long tenantId;
}
@@ -0,0 +1,15 @@
package com.bsd.pjcloud.wallet.api.vo.rule;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleJoinEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class WalletRuleJoinVo extends WalletRuleJoinEntity {
}
@@ -0,0 +1,82 @@
package com.bsd.pjcloud.wallet.controller.rule;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.core.util.R;
import com.bsd.pjcloud.common.log.annotation.SysLog;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleJoinEntity;
import com.bsd.pjcloud.wallet.service.WalletRuleJoinService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.bsd.pjcloud.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Objects;
/**
* 钱包规则配置
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/wallet-rule-join")
@Tag(description = "wallet-rule-join", name = "钱包规则配置管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class WalletRuleJoinController {
private final WalletRuleJoinService walletRuleJoinService;
@Operation(summary = "分页查询", description = "分页查询")
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('wallet_walletRuleJoin_view')")
public R getWalletRuleJoinPage(@ParameterObject Page page, @ParameterObject WalletRuleJoinEntity walletRuleJoin) {
LambdaQueryWrapper<WalletRuleJoinEntity> wrapper = Wrappers.lambdaQuery();
return R.ok(walletRuleJoinService.page(page, wrapper));
}
@Operation(summary = "通过id查询", description = "通过id查询")
@GetMapping("/{id}")
@PreAuthorize("@pms.hasPermission('wallet_walletRuleJoin_view')")
public R getById(@PathVariable("id") Long id) {
return R.ok(walletRuleJoinService.getById(id));
}
@Operation(summary = "新增钱包规则配置", description = "新增钱包规则配置")
@SysLog("新增钱包规则配置")
@PostMapping
@PreAuthorize("@pms.hasPermission('wallet_walletRuleJoin_add')")
public R save(@RequestBody WalletRuleJoinEntity walletRuleJoin) {
return R.ok(walletRuleJoinService.save(walletRuleJoin));
}
@Operation(summary = "修改钱包规则配置", description = "修改钱包规则配置")
@SysLog("修改钱包规则配置")
@PutMapping
@PreAuthorize("@pms.hasPermission('wallet_walletRuleJoin_edit')")
public R updateById(@RequestBody WalletRuleJoinEntity walletRuleJoin) {
return R.ok(walletRuleJoinService.updateById(walletRuleJoin));
}
@Operation(summary = "通过id删除钱包规则配置", description = "通过id删除钱包规则配置")
@SysLog("通过id删除钱包规则配置")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('wallet_walletRuleJoin_del')")
public R removeById(@RequestBody Long[] ids) {
return R.ok(walletRuleJoinService.removeBatchByIds(CollUtil.toList(ids)));
}
@ResponseExcel
@GetMapping("/export")
@PreAuthorize("@pms.hasPermission('wallet_walletRuleJoin_export')")
public List<WalletRuleJoinEntity> export(WalletRuleJoinEntity walletRuleJoin, Long[] ids) {
return walletRuleJoinService.list(Wrappers.lambdaQuery(walletRuleJoin).in(ArrayUtil.isNotEmpty(ids), WalletRuleJoinEntity::getId, ids));
}
}
@@ -1,14 +1,11 @@
package com.bsd.pjcloud.wallet.mapper.rule;
package com.bsd.pjcloud.wallet.mapper.mch;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.wallet.api.dto.mch.MchRuleJoinDto;
import com.bsd.pjcloud.wallet.api.entity.mch.MchManageEntity;
import com.bsd.pjcloud.wallet.api.entity.mch.MchRuleJoinDtoEntity;
import com.bsd.pjcloud.wallet.api.vo.mch.MchRuleJoinDtoVo;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
@@ -1,4 +1,4 @@
package com.bsd.pjcloud.wallet.mapper.rule;
package com.bsd.pjcloud.wallet.mapper.mch;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -8,7 +8,6 @@ import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.wallet.api.dto.mch.MchRulePriceConfigDto;
import com.bsd.pjcloud.wallet.api.entity.mch.MchRulePriceConfigEntity;
import com.bsd.pjcloud.wallet.api.vo.mch.MchRulePriceConfigVo;
import com.github.yulichang.query.MPJLambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
@@ -0,0 +1,11 @@
package com.bsd.pjcloud.wallet.mapper.rule;
import com.bsd.pjcloud.common.data.datascope.PjcloudBaseMapper;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleJoinEntity;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface WalletRuleJoinMapper extends PjcloudBaseMapper<WalletRuleJoinEntity> {
}
@@ -0,0 +1,8 @@
package com.bsd.pjcloud.wallet.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleJoinEntity;
public interface WalletRuleJoinService extends IService<WalletRuleJoinEntity> {
}
@@ -5,13 +5,16 @@ 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 com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.wallet.api.constant.mch.WalletMchRulePriceTypeEnum;
import com.bsd.pjcloud.wallet.api.dto.mch.MchRuleJoinDto;
import com.bsd.pjcloud.wallet.api.entity.mch.MchManageEntity;
import com.bsd.pjcloud.wallet.api.entity.mch.MchRuleJoinDtoEntity;
import com.bsd.pjcloud.wallet.api.entity.mch.MchRulePriceConfigEntity;
import com.bsd.pjcloud.wallet.api.vo.mch.MchRuleJoinDtoVo;
import com.bsd.pjcloud.wallet.mapper.rule.WalletRuleMchConfigMapper;
import com.bsd.pjcloud.wallet.mapper.mch.WalletRuleMchConfigMapper;
import com.bsd.pjcloud.wallet.service.MchManageService;
import com.bsd.pjcloud.wallet.service.MchRuleJoinControllerService;
import com.bsd.pjcloud.wallet.service.WalletRulePriceConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -27,14 +30,19 @@ import java.util.ArrayList;
public class MchRuleJoinControllerServiceImpl extends ServiceImpl<WalletRuleMchConfigMapper, MchRuleJoinDtoEntity> implements MchRuleJoinControllerService {
private final MchManageService mchManageService;
private final WalletRulePriceConfigService rulePriceConfigService;
@Override
public Long create(MchRuleJoinDtoEntity dto) {
if (existMchRuleJoin(dto)) {
throw new RuntimeException("绑定的规则类型不能重复");
}
if (areMchIdsDistinct(dto)) {
throw new RuntimeException("源商户与目标商户不能重复");
// 查询配置规则
MchRulePriceConfigEntity rulePriceConfig = rulePriceConfigService.getById(dto.getRulePriceConfigId());
if (ObjectUtil.notEqual(rulePriceConfig.getRulePriceType(), WalletMchRulePriceTypeEnum.EVERY_LIMIT.getCode())) {
if (areMchIdsDistinct(dto)) {
throw new RuntimeException("源商户与目标商户不能重复");
}
}
MchManageEntity targetMch = mchManageService.getById(dto.getTargetMchId());
if (ObjectUtil.isEmpty(targetMch)) {
@@ -87,7 +95,6 @@ public class MchRuleJoinControllerServiceImpl extends ServiceImpl<WalletRuleMchC
private boolean existMchRuleJoin(MchRuleJoinDtoEntity dto) {
Long count = baseMapper.selectCount(new LambdaQueryWrapper<MchRuleJoinDtoEntity>()
.eq(ObjectUtil.isNotEmpty(dto.getSourceMchId()), MchRuleJoinDtoEntity::getSourceMchId, dto.getSourceMchId())
.eq(ObjectUtil.isNotEmpty(dto.getTargetMchId()), MchRuleJoinDtoEntity::getTargetMchId, dto.getTargetMchId())
.eq(ObjectUtil.isNotEmpty(dto.getRulePriceConfigId()), MchRuleJoinDtoEntity::getRulePriceConfigId, dto.getRulePriceConfigId())
.ne(ObjectUtil.isNotEmpty(dto.getId()), MchRuleJoinDtoEntity::getId, dto.getId())
);
@@ -10,7 +10,7 @@ import com.bsd.pjcloud.common.data.datascope.DataScope;
import com.bsd.pjcloud.wallet.api.dto.mch.MchRulePriceConfigDto;
import com.bsd.pjcloud.wallet.api.entity.mch.MchRulePriceConfigEntity;
import com.bsd.pjcloud.wallet.api.vo.mch.MchRulePriceConfigVo;
import com.bsd.pjcloud.wallet.mapper.rule.WalletRulePriceConfigMapper;
import com.bsd.pjcloud.wallet.mapper.mch.WalletRulePriceConfigMapper;
import com.bsd.pjcloud.wallet.service.WalletRulePriceConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -0,0 +1,13 @@
package com.bsd.pjcloud.wallet.service.impl.rule;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleJoinEntity;
import com.bsd.pjcloud.wallet.mapper.rule.WalletRuleJoinMapper;
import com.bsd.pjcloud.wallet.service.WalletRuleJoinService;
import org.springframework.stereotype.Service;
/**
* 钱包规则配置
*/
@Service
public class WalletRuleJoinServiceImpl extends ServiceImpl<WalletRuleJoinMapper, WalletRuleJoinEntity> implements WalletRuleJoinService {
}
@@ -1,7 +1,7 @@
<?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.bsd.pjcloud.wallet.mapper.rule.WalletRuleMchConfigMapper">
<mapper namespace="com.bsd.pjcloud.wallet.mapper.mch.WalletRuleMchConfigMapper">
<resultMap id="walletRuleMchConfigMap" type="com.bsd.pjcloud.wallet.api.entity.mch.MchRuleJoinDtoEntity">
<result property="id" column="id"/>
<result property="sourceMchId" column="source_mch_id"/>
@@ -1,7 +1,7 @@
<?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.bsd.pjcloud.wallet.mapper.rule.WalletRulePriceConfigMapper">
<mapper namespace="com.bsd.pjcloud.wallet.mapper.mch.WalletRulePriceConfigMapper">
<resultMap id="walletRulePriceConfigMap" type="com.bsd.pjcloud.wallet.api.entity.mch.MchRulePriceConfigEntity">
<result property="id" column="id"/>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bsd.pjcloud.wallet.mapper.rule.WalletRuleJoinMapper">
<resultMap id="walletRuleJoinMap" type="com.bsd.pjcloud.wallet.api.entity.rule.WalletRuleJoinEntity">
<id property="id" column="id"/>
<result property="sourceWalletTypeId" column="source_wallet_type_id"/>
<result property="targetWalletTypeId" column="target_wallet_type_id"/>
<result property="balanceMultiple" column="balance_multiple"/>
<result property="status" column="status"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="delFlag" column="del_flag"/>
<result property="tenantId" column="tenant_id"/>
</resultMap>
</mapper>