Преглед на файлове

add payment config module

Mr.qian преди 1 седмица
родител
ревизия
cdba84edac

+ 35 - 18
cif-service/src/main/java/com/txz/cif/configurer/MybatisConfigurer.java

@@ -1,50 +1,67 @@
 package com.txz.cif.configurer;
 
-import java.util.Properties;
-
-import javax.sql.DataSource;
-
+import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
 import org.apache.ibatis.session.SqlSessionFactory;
-import org.mybatis.spring.SqlSessionFactoryBean;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
 import org.springframework.core.io.support.ResourcePatternResolver;
-
 import tk.mybatis.spring.mapper.MapperScannerConfigurer;
 
+import javax.sql.DataSource;
+import java.util.Properties;
+
 /**
  * Mybatis & Mapper & PageHelper 配置
  */
 @Configuration
 public class MybatisConfigurer {
-
+    
     @Bean
     public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
-        SqlSessionFactoryBean factory = new SqlSessionFactoryBean();
+        // 使用MyBatis-Plus的SqlSessionFactoryBean以支持两个框架
+        MybatisSqlSessionFactoryBean factory = new MybatisSqlSessionFactoryBean();
         factory.setDataSource(dataSource);
         factory.setTypeAliasesPackage(ProjectConstant.MODEL_PACKAGE);
-
-        //添加XML目录
+        
+        // 添加XML目录
         ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
         factory.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
         return factory.getObject();
     }
-
-    @Bean
-    public MapperScannerConfigurer mapperScannerConfigurer() {
+    
+    @Bean("tkMapperScannerConfigurer")
+    public MapperScannerConfigurer tkMapperScannerConfigurer() {
         MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
         mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean");
         mapperScannerConfigurer.setBasePackage(ProjectConstant.MAPPER_PACKAGE);
-
-        //配置通用Mapper,详情请查阅官方文档
+        
+        // 配置通用Mapper,详情请查阅官方文档
         Properties properties = new Properties();
         properties.setProperty("mappers", ProjectConstant.MAPPER_INTERFACE_REFERENCE);
-        properties.setProperty("notEmpty", "false");//insert、update是否判断字符串类型!='' 即 test="str != null"表达式内是否追加 and str != ''
+        properties.setProperty("notEmpty", "false");// insert、update是否判断字符串类型!='' 即 test="str != null"表达式内是否追加 and str != ''
         properties.setProperty("IDENTITY", "MYSQL");
         mapperScannerConfigurer.setProperties(properties);
-
+        
         return mapperScannerConfigurer;
     }
-
+    
+    /**
+     * MyBatis-Plus Mapper扫描配置
+     */
+    @Bean("mybatisPlusMapperScannerConfigurer")
+    public MapperScannerConfigurer mybatisPlusMapperScannerConfigurer() {
+        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
+        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactoryBean");
+        // 只扫描特定包下的MyBatis-Plus Mapper
+        mapperScannerConfigurer.setBasePackage("com.txz.cif.dao");
+        
+        Properties properties = new Properties();
+        properties.setProperty("notEmpty", "false");
+        properties.setProperty("IDENTITY", "MYSQL");
+        mapperScannerConfigurer.setProperties(properties);
+        
+        return mapperScannerConfigurer;
+    }
+    
 }

+ 13 - 0
cif-service/src/main/java/com/txz/cif/dao/PaymentPriceConfigMapper.java

@@ -0,0 +1,13 @@
+package com.txz.cif.dao;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.txz.cif.model.PaymentPriceConfig;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/8/28
+ */
+@Mapper
+public interface PaymentPriceConfigMapper extends BaseMapper<PaymentPriceConfig> {
+}

+ 34 - 185
cif-service/src/main/java/com/txz/cif/model/PaymentMethod.java

@@ -2,243 +2,92 @@ package com.txz.cif.model;
 
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
-import java.util.Date;
+import lombok.Data;
+
 import javax.persistence.*;
+import java.util.Date;
 
-@ApiModel(value="com.txz.cif.model.PaymentMethod")
+@ApiModel(value = "com.txz.cif.model.PaymentMethod")
 @Table(name = "c_payment_method")
+@Data
 public class PaymentMethod {
     @Id
     @GeneratedValue(strategy = GenerationType.IDENTITY)
-    @ApiModelProperty(value="id")
+    @ApiModelProperty(value = "id")
     private Long id;
-
+    
     /**
      * 支付方式编码
      */
     @Column(name = "method_code")
-    @ApiModelProperty(value="methodCode支付方式编码")
+    @ApiModelProperty(value = "methodCode支付方式编码")
     private String methodCode;
-
+    
     /**
      * 支付方式名称
      */
     @Column(name = "method_name")
-    @ApiModelProperty(value="methodName支付方式名称")
+    @ApiModelProperty(value = "methodName支付方式名称")
     private String methodName;
-
-
-
+    
+    
     /**
      * 1开启 0关闭
      */
-    @ApiModelProperty(value="status1开启 0关闭")
+    @ApiModelProperty(value = "status1开启 0关闭")
     private Byte status;
-
+    
     /**
      * 创建人
      */
     @Column(name = "create_user")
-    @ApiModelProperty(value="createUser创建人")
+    @ApiModelProperty(value = "createUser创建人")
     private String createUser;
-
+    
     /**
      * 更新人
      */
     @Column(name = "update_user")
-    @ApiModelProperty(value="updateUser更新人")
+    @ApiModelProperty(value = "updateUser更新人")
     private String updateUser;
-
+    
     /**
      * 更新时间
      */
     @Column(name = "update_time")
-    @ApiModelProperty(value="updateTime更新时间")
+    @ApiModelProperty(value = "updateTime更新时间")
     private Date updateTime;
-
+    
     /**
      * 创建时间
      */
     @Column(name = "create_time")
-    @ApiModelProperty(value="createTime创建时间")
+    @ApiModelProperty(value = "createTime创建时间")
     private Date createTime;
-
+    
     /**
      * 删除标识 1是0否
      */
     @Column(name = "is_valid")
-    @ApiModelProperty(value="isValid删除标识 1是0否")
+    @ApiModelProperty(value = "isValid删除标识 1是0否")
     private Byte isValid;
-
+    
     /**
      * 版本号
      */
-    @ApiModelProperty(value="version版本号")
+    @ApiModelProperty(value = "version版本号")
     private Integer version;
-
-    /**
-     * @return id
-     */
-    public Long getId() {
-        return id;
-    }
-
-    /**
-     * @param id
-     */
-    public void setId(Long id) {
-        this.id = id;
-    }
-
-    /**
-     * 获取支付方式编码
-     *
-     * @return method_code - 支付方式编码
-     */
-    public String getMethodCode() {
-        return methodCode;
-    }
-
-    /**
-     * 设置支付方式编码
-     *
-     * @param methodCode 支付方式编码
-     */
-    public void setMethodCode(String methodCode) {
-        this.methodCode = methodCode;
-    }
-
-    /**
-     * 获取支付方式名称
-     *
-     * @return method_name - 支付方式名称
-     */
-    public String getMethodName() {
-        return methodName;
-    }
-
-    /**
-     * 设置支付方式名称
-     *
-     * @param methodName 支付方式名称
-     */
-    public void setMethodName(String methodName) {
-        this.methodName = methodName;
-    }
-
+    
     /**
-     * 获取创建人
-     *
-     * @return create_user - 创建人
+     * 充值最低限额
      */
-    public String getCreateUser() {
-        return createUser;
-    }
-
+    @Column(name = "mini_price")
+    private Integer miniPrice;
+    
     /**
-     * 设置创建人
-     *
-     * @param createUser 创建人
+     * 充值最高限额
      */
-    public void setCreateUser(String createUser) {
-        this.createUser = createUser;
-    }
-
-    /**
-     * 获取更新人
-     *
-     * @return update_user - 更新人
-     */
-    public String getUpdateUser() {
-        return updateUser;
-    }
-
-    /**
-     * 设置更新人
-     *
-     * @param updateUser 更新人
-     */
-    public void setUpdateUser(String updateUser) {
-        this.updateUser = updateUser;
-    }
-
-    /**
-     * 获取更新时间
-     *
-     * @return update_time - 更新时间
-     */
-    public Date getUpdateTime() {
-        return updateTime;
-    }
-
-    /**
-     * 设置更新时间
-     *
-     * @param updateTime 更新时间
-     */
-    public void setUpdateTime(Date updateTime) {
-        this.updateTime = updateTime;
-    }
-
-    /**
-     * 获取创建时间
-     *
-     * @return create_time - 创建时间
-     */
-    public Date getCreateTime() {
-        return createTime;
-    }
-
-    /**
-     * 设置创建时间
-     *
-     * @param createTime 创建时间
-     */
-    public void setCreateTime(Date createTime) {
-        this.createTime = createTime;
-    }
-
-    /**
-     * 获取删除标识 1是0否
-     *
-     * @return is_valid - 删除标识 1是0否
-     */
-    public Byte getIsValid() {
-        return isValid;
-    }
-
-    /**
-     * 设置删除标识 1是0否
-     *
-     * @param isValid 删除标识 1是0否
-     */
-    public void setIsValid(Byte isValid) {
-        this.isValid = isValid;
-    }
-
-    /**
-     * 获取版本号
-     *
-     * @return version - 版本号
-     */
-    public Integer getVersion() {
-        return version;
-    }
-
-    /**
-     * 设置版本号
-     *
-     * @param version 版本号
-     */
-    public void setVersion(Integer version) {
-        this.version = version;
-    }
-
-    public void setStatus(Byte status) {
-        this.status = status;
-    }
-
-    public Byte getStatus() {
-        return status;
-    }
+    @Column(name = "max_price")
+    private Integer maxPrice;
+    
 }

+ 61 - 0
cif-service/src/main/java/com/txz/cif/model/PaymentPriceConfig.java

@@ -0,0 +1,61 @@
+package com.txz.cif.model;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Date;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/8/28
+ */
+@Data
+@TableName("c_payment_price_config")
+@EqualsAndHashCode(callSuper = true)
+public class PaymentPriceConfig extends Model<PaymentPriceConfig> {
+    
+    /**
+     * null
+     */
+    @TableId(type = IdType.AUTO)
+    private Long id;
+    
+    /**
+     * 有效标识 1是0否
+     */
+    private Integer isValid;
+    
+    /**
+     * 渠道id
+     */
+    private Long paymentId;
+    
+    /**
+     * 金额
+     */
+    private Integer priceVal;
+    
+    /**
+     * 创建人
+     */
+    private String createUser;
+    
+    /**
+     * 更新人
+     */
+    private String updateUser;
+    
+    /**
+     * 更新时间
+     */
+    private Date updateTime;
+    
+    /**
+     * 创建时间
+     */
+    private Date createTime;
+}

+ 12 - 0
cif-service/src/main/java/com/txz/cif/service/PaymentPriceConfigService.java

@@ -0,0 +1,12 @@
+package com.txz.cif.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.txz.cif.model.PaymentPriceConfig;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/8/28
+ */
+
+public interface PaymentPriceConfigService extends IService<PaymentPriceConfig> {
+}

+ 17 - 0
cif-service/src/main/java/com/txz/cif/service/impl/PaymentPriceConfigServiceImpl.java

@@ -0,0 +1,17 @@
+package com.txz.cif.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.txz.cif.dao.PaymentPriceConfigMapper;
+import com.txz.cif.model.PaymentPriceConfig;
+import com.txz.cif.service.PaymentPriceConfigService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/8/28
+ */
+@Slf4j
+@Service
+public class PaymentPriceConfigServiceImpl extends ServiceImpl<PaymentPriceConfigMapper, PaymentPriceConfig> implements PaymentPriceConfigService {
+}

+ 152 - 0
cif-service/src/main/java/com/txz/cif/web/mng/PaymentPriceConfigController.java

@@ -0,0 +1,152 @@
+package com.txz.cif.web.mng;
+
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.txz.cif.core.Result;
+import com.txz.cif.model.PaymentMethod;
+import com.txz.cif.model.PaymentPriceConfig;
+import com.txz.cif.service.PaymentMethodService;
+import com.txz.cif.service.PaymentPriceConfigService;
+import com.txz.cif.web.ro.PaymentPriceConfigRO;
+import com.txz.cif.web.vo.PaymentPriceVO;
+import lombok.RequiredArgsConstructor;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * [后台]充值金额配置
+ *
+ * @author: MTD®️
+ * @date: 2025/8/28
+ */
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("paymentPriceConfig")
+public class PaymentPriceConfigController {
+    
+    private final PaymentPriceConfigService paymentPriceConfigService;
+    
+    private final PaymentMethodService paymentMethodService;
+    
+    /**
+     * 列表
+     */
+    @GetMapping("list/{paymentId:^\\d+$}")
+    public Result<PaymentPriceVO> list(@PathVariable("paymentId") Long paymentId) {
+        PaymentMethod paymentMethod = paymentMethodService.findById(paymentId);
+        return Result.success(PaymentPriceVO.builder()
+                .list(paymentPriceConfigService.list(
+                        Wrappers.<PaymentPriceConfig>lambdaQuery()
+                                .eq(PaymentPriceConfig::getPaymentId, paymentId)
+                                .eq(PaymentPriceConfig::getIsValid, 1)
+                                .orderByAsc(PaymentPriceConfig::getPriceVal)
+                ))
+                .miniPrice(paymentMethod.getMiniPrice())
+                .maxPrice(paymentMethod.getMaxPrice())
+                .build()
+        );
+    }
+    
+    /**
+     * 新增
+     */
+    @PostMapping("add/{paymentId:^\\d+$}")
+    public Result add(@PathVariable("paymentId") Long paymentId, @RequestBody @Validated({PaymentPriceConfigRO.Add.class}) PaymentPriceConfigRO ro) {
+        if (paymentPriceConfigService.count(
+                Wrappers.<PaymentPriceConfig>lambdaQuery()
+                        .eq(PaymentPriceConfig::getPaymentId, paymentId)
+                        .eq(PaymentPriceConfig::getIsValid, 1)) >= 9L
+        ) {
+            return Result.fail("最多添加9个");
+        }
+        PaymentPriceConfig exist = paymentPriceConfigService.getOne(Wrappers.<PaymentPriceConfig>lambdaQuery()
+                .eq(PaymentPriceConfig::getPriceVal, ro.getPriceVal())
+                .eq(PaymentPriceConfig::getPaymentId, paymentId)
+                .eq(PaymentPriceConfig::getIsValid, 1)
+        );
+        if (ObjectUtil.isNotEmpty(exist)) {
+            return Result.fail("该金额已存在");
+        }
+        PaymentPriceConfig addInfo = new PaymentPriceConfig();
+        addInfo.setPaymentId(paymentId);
+        addInfo.setPriceVal(ro.getPriceVal());
+        addInfo.setIsValid(1);
+        paymentPriceConfigService.save(addInfo);
+        return Result.success();
+    }
+    
+    /**
+     * 修改
+     */
+    @PatchMapping("edit/{id:^\\d+$}")
+    public Result edit(@PathVariable("id") Long id, @RequestBody @Validated({PaymentPriceConfigRO.Edit.class}) PaymentPriceConfigRO ro) {
+        PaymentPriceConfig exist = paymentPriceConfigService.getOne(Wrappers.<PaymentPriceConfig>lambdaQuery()
+                .eq(PaymentPriceConfig::getPriceVal, ro.getPriceVal())
+                .ne(PaymentPriceConfig::getId, id)
+                .eq(PaymentPriceConfig::getIsValid, 1)
+        );
+        if (ObjectUtil.isNotEmpty(exist)) {
+            return Result.fail("该金额已存在");
+        }
+        paymentPriceConfigService.update(Wrappers.<PaymentPriceConfig>lambdaUpdate()
+                .eq(PaymentPriceConfig::getId, id)
+                .set(PaymentPriceConfig::getPriceVal, ro.getPriceVal())
+        
+        );
+        return Result.success();
+    }
+    
+    /**
+     * 删除
+     */
+    @DeleteMapping("del/{id:^\\d+$}")
+    public Result del(@PathVariable("id") Long id) {
+        paymentPriceConfigService.update(Wrappers.<PaymentPriceConfig>lambdaUpdate()
+                .eq(PaymentPriceConfig::getId, id)
+                .set(PaymentPriceConfig::getIsValid, 0)
+        
+        );
+        return Result.success();
+    }
+    
+    /**
+     * 修改区间
+     */
+    @PatchMapping("editInterval/{paymentId:^\\d+$}")
+    public Result editInterval(@PathVariable("paymentId") Long paymentId, @RequestBody @Validated({PaymentPriceConfigRO.EditInterval.class}) PaymentPriceConfigRO ro) {
+        // PaymentPriceConfig mini = paymentPriceConfigService.getOne(Wrappers.<PaymentPriceConfig>lambdaQuery()
+        //         .eq(PaymentPriceConfig::getPaymentId, paymentId)
+        //         .lt(PaymentPriceConfig::getPriceVal, ro.getMiniPrice())
+        //         .eq(PaymentPriceConfig::getIsValid, 1)
+        //         .last("limit 1")
+        // );
+        // if (ObjectUtil.isNotEmpty(mini)) {
+        //     return Result.fail("最小金额不能小于已配置金额");
+        // }
+        //
+        // PaymentPriceConfig max = paymentPriceConfigService.getOne(Wrappers.<PaymentPriceConfig>lambdaQuery()
+        //         .eq(PaymentPriceConfig::getPaymentId, paymentId)
+        //         .gt(PaymentPriceConfig::getPriceVal, ro.getMaxPrice())
+        //         .eq(PaymentPriceConfig::getIsValid, 1)
+        //         .last("limit 1")
+        // );
+        // if (ObjectUtil.isNotEmpty(max)) {
+        //     return Result.fail("最大金额不能大于已配置金额");
+        // }
+        
+        if (ro.getMiniPrice() > ro.getMaxPrice()) {
+            return Result.fail("最小金额不能大于最大金额");
+        }
+        
+        PaymentMethod updateMethod = new PaymentMethod();
+        updateMethod.setId(paymentId);
+        updateMethod.setMiniPrice(ro.getMiniPrice());
+        updateMethod.setMaxPrice(ro.getMaxPrice());
+        
+        paymentMethodService.update(updateMethod);
+        
+        return Result.success();
+    }
+    
+}

+ 51 - 0
cif-service/src/main/java/com/txz/cif/web/mng/appcontroller/AppPaymentPriceConfigController.java

@@ -0,0 +1,51 @@
+package com.txz.cif.web.mng.appcontroller;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.txz.cif.core.Result;
+import com.txz.cif.model.PaymentMethod;
+import com.txz.cif.model.PaymentPriceConfig;
+import com.txz.cif.service.PaymentMethodService;
+import com.txz.cif.service.PaymentPriceConfigService;
+import com.txz.cif.web.vo.PaymentPriceVO;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * app端充值金额配置
+ *
+ * @author: MTD®️
+ * @date: 2025/8/28
+ */
+@RestController
+@RequiredArgsConstructor
+@RequestMapping("app/paymentPriceConfig")
+public class AppPaymentPriceConfigController {
+    
+    private final PaymentPriceConfigService paymentPriceConfigService;
+    
+    private final PaymentMethodService paymentMethodService;
+    
+    
+    /**
+     * 获取配置
+     */
+    @GetMapping("priceInfo/{paymentId:^\\d+$}")
+    public Result<PaymentPriceVO> list(@PathVariable("paymentId") Long paymentId) {
+        PaymentMethod paymentMethod = paymentMethodService.findById(paymentId);
+        return Result.success(PaymentPriceVO.builder()
+                .list(paymentPriceConfigService.list(
+                        Wrappers.<PaymentPriceConfig>lambdaQuery()
+                                .eq(PaymentPriceConfig::getPaymentId, paymentId)
+                                .eq(PaymentPriceConfig::getIsValid, 1)
+                                .orderByAsc(PaymentPriceConfig::getPriceVal)
+                ))
+                .miniPrice(paymentMethod.getMiniPrice())
+                .maxPrice(paymentMethod.getMaxPrice())
+                .build()
+        );
+    }
+    
+}

+ 37 - 0
cif-service/src/main/java/com/txz/cif/web/ro/PaymentPriceConfigRO.java

@@ -0,0 +1,37 @@
+package com.txz.cif.web.ro;
+
+import lombok.Data;
+
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/8/28
+ */
+@Data
+public class PaymentPriceConfigRO {
+    
+    @NotNull(message = "金额不能为空", groups = {Add.class, Edit.class})
+    @Min(value = 1, message = "金额不能为空不能小于1", groups = {Add.class, Edit.class})
+    // @Max(value = Integer.MAX_VALUE, message = "金额不能为空不能大于")
+    private Integer priceVal;
+    
+    @NotNull(message = "金额不能为空", groups = {EditInterval.class})
+    @Min(value = 1, message = "金额不能为空不能小于1", groups = {EditInterval.class})
+    private Integer miniPrice;
+    
+    @NotNull(message = "金额不能为空", groups = {EditInterval.class})
+    @Min(value = 1, message = "金额不能为空不能小于1", groups = {EditInterval.class})
+    private Integer maxPrice;
+    
+    public interface Add {
+    }
+    
+    public interface Edit {
+    }
+    
+    public interface EditInterval {
+    }
+    
+}

+ 32 - 0
cif-service/src/main/java/com/txz/cif/web/vo/PaymentPriceVO.java

@@ -0,0 +1,32 @@
+package com.txz.cif.web.vo;
+
+import com.txz.cif.model.PaymentPriceConfig;
+import lombok.Builder;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author: MTD®️
+ * @date: 2025/8/28
+ */
+@Data
+@Builder
+public class PaymentPriceVO {
+    
+    /**
+     * 配置列表
+     */
+    private List<PaymentPriceConfig> list;
+    
+    /**
+     * 充值最低限额
+     */
+    private Integer miniPrice;
+    
+    /**
+     * 充值最高限额
+     */
+    private Integer maxPrice;
+    
+}