2
0

feat: 计费规则

This commit is contained in:
caiyuchao
2025-01-07 10:51:00 +08:00
parent 9b902bfd84
commit 3b2ae3c597
7 changed files with 168 additions and 2 deletions

View File

@@ -0,0 +1,69 @@
package org.wfc.system.controller;
import cn.hutool.core.collection.CollUtil;
import org.springframework.beans.factory.annotation.Autowired;
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;
import org.wfc.common.core.web.controller.BaseController;
import org.wfc.common.core.web.domain.AjaxResult;
import org.wfc.common.core.web.page.TableDataInfo;
import org.wfc.system.domain.UBillRule;
import org.wfc.system.service.IUBillRuleService;
import java.util.List;
/**
* <p>
* 用户平台-计费规则表 前端控制器
* </p>
*
* @author sys
* @since 2025-01-07
*/
@RestController
@RequestMapping("/billRule")
public class UBillRuleController extends BaseController {
@Autowired
private IUBillRuleService uBillRuleService;
@GetMapping("/page")
public TableDataInfo page(UBillRule uBillRule) {
startPage();
List<UBillRule> list = uBillRuleService.list();
return getDataTable(list);
}
@GetMapping("/list")
public AjaxResult list(UBillRule uBillRule) {
List<UBillRule> list = uBillRuleService.list();
return success(list);
}
@GetMapping(value = "/{id}")
public AjaxResult getById(@PathVariable("id") Long id) {
return success(uBillRuleService.getById(id));
}
@PostMapping
public AjaxResult add(@RequestBody UBillRule uBillRule) {
return toAjax(uBillRuleService.save(uBillRule));
}
@PutMapping
public AjaxResult edit(@RequestBody UBillRule uBillRule) {
return toAjax(uBillRuleService.updateById(uBillRule));
}
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids) {
return toAjax(uBillRuleService.removeByIds(CollUtil.newArrayList(ids)));
}
}

View File

@@ -0,0 +1,38 @@
package org.wfc.system.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.math.BigDecimal;
import org.wfc.common.mybatis.domain.BaseData;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
/**
* <p>
* 用户平台-计费规则表
* </p>
*
* @author sys
* @since 2025-01-07
*/
@Getter
@Setter
@TableName("u_bill_rule")
@Schema(name = "UBillRule", description = "用户平台-计费规则表")
public class UBillRule extends BaseData {
private static final long serialVersionUID = 1L;
@Schema(description = "价格")
private BigDecimal price;
@Schema(description = "流量")
private Long traffic;
@Schema(description = "单位")
private Integer unit;
@Schema(description = "是否启用")
private Boolean enable;
}

View File

@@ -0,0 +1,18 @@
package org.wfc.system.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.wfc.system.domain.UBillRule;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* <p>
* 用户平台-计费规则表 Mapper 接口
* </p>
*
* @author sys
* @since 2025-01-07
*/
@DS("user")
public interface UBillRuleMapper extends BaseMapper<UBillRule> {
}

View File

@@ -0,0 +1,16 @@
package org.wfc.system.service;
import org.wfc.system.domain.UBillRule;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* <p>
* 用户平台-计费规则表 服务类
* </p>
*
* @author sys
* @since 2025-01-07
*/
public interface IUBillRuleService extends IService<UBillRule> {
}

View File

@@ -0,0 +1,20 @@
package org.wfc.system.service.impl;
import org.wfc.system.domain.UBillRule;
import org.wfc.system.mapper.UBillRuleMapper;
import org.wfc.system.service.IUBillRuleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
/**
* <p>
* 用户平台-计费规则表 服务实现类
* </p>
*
* @author sys
* @since 2025-01-07
*/
@Service
public class UBillRuleServiceImpl extends ServiceImpl<UBillRuleMapper, UBillRule> implements IUBillRuleService {
}

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="org.wfc.system.mapper.UBillRuleMapper">
</mapper>

View File

@@ -248,9 +248,9 @@ public class UAccountServiceImpl extends ServiceImpl<UAccountMapper, UAccount> i
BigDecimal balanceUsed = Optional.of(account.getBalanceUsed()).orElse(BigDecimal.ZERO);
BigDecimal balance = Optional.of(dashboardVo.getBalance()).orElse(BigDecimal.ZERO);
if (balance.compareTo(balanceUsed) >= 0) {
dashboardVo.setBalance(BigDecimal.ZERO);
} else {
dashboardVo.setBalance(balance.subtract(balanceUsed));
} else {
dashboardVo.setBalance(BigDecimal.ZERO);
}
}
return dashboardVo;