添加视频缓存和商品缓存和获取
This commit is contained in:
parent
fccce9f4c2
commit
668787f053
94
ruoyi-modules/ruoyi-content/README_定时任务.md
Normal file
94
ruoyi-modules/ruoyi-content/README_定时任务.md
Normal file
@ -0,0 +1,94 @@
|
||||
# 视频点赞排行榜定时任务
|
||||
|
||||
## 功能说明
|
||||
|
||||
本功能实现了每天12点自动查询点赞最多的100条视频并存储到Redis中的定时任务。缓存时会先打乱顺序,然后按点赞数排序存储。
|
||||
|
||||
## 实现内容
|
||||
|
||||
### 1. 数据库查询
|
||||
- 在 `VlogMapper` 中添加了 `selectAllPublicVlogs` 方法
|
||||
- 在 `VlogMapper` 中添加了 `selectRandomVlogs` 方法(随机查询视频)
|
||||
- 查询条件:状态为1(审核通过)且非私密视频
|
||||
- 获取所有公开视频的基本信息
|
||||
|
||||
### 2. 服务层实现
|
||||
- 在 `VlogService` 接口中添加了 `cacheTopLikedVlogs` 方法
|
||||
- 在 `VlogService` 接口中添加了 `getRandomVlogs` 方法
|
||||
- 在 `VlogServiceImpl` 中实现了缓存逻辑
|
||||
- 从Redis中获取每个视频的点赞数量(key格式:`redis_vlog_be_liked_counts:{vlogId}`)
|
||||
- **缓存逻辑优化**:先打乱视频顺序,然后按Redis中的点赞数排序,获取前100个最受欢迎的视频
|
||||
- 将查询结果以JSON格式存储到Redis,过期时间为24小时
|
||||
|
||||
### 3. 定时任务
|
||||
- 创建了 `VlogScheduledTask` 定时任务类
|
||||
- 使用 `@Scheduled(cron = "0 0 12 * * ?")` 配置每天12点执行
|
||||
- 在主应用类 `DromaraApplication` 上添加了 `@EnableScheduling` 注解
|
||||
|
||||
### 4. 控制器接口
|
||||
- 添加了手动触发缓存的接口:`POST /vlog/cacheTopLikedVlogs`
|
||||
- 添加了获取缓存数据的接口:`GET /vlog/getTopLikedVlogs`
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 1. 自动执行
|
||||
定时任务会在每天12点自动执行,无需手动干预。
|
||||
|
||||
### 2. 手动触发
|
||||
如果需要立即执行缓存任务,可以调用以下接口:
|
||||
|
||||
```bash
|
||||
POST /vlog/cacheTopLikedVlogs?limit=100
|
||||
```
|
||||
|
||||
参数说明:
|
||||
- `limit`: 查询的视频数量,默认为100
|
||||
|
||||
### 3. 查看缓存结果
|
||||
可以通过以下接口查看缓存的数据:
|
||||
|
||||
```bash
|
||||
GET /vlog/getTopLikedVlogs
|
||||
GET /vlog/getTopLikedVlogs?date=2024-01-15
|
||||
GET /vlog/getTopLikedVlogs?pageSize=10&pageNum=0
|
||||
```
|
||||
|
||||
参数说明:
|
||||
- `date`: 指定日期,格式为 yyyy-MM-dd,如果不传则使用当天日期
|
||||
- `pageSize`: 每页返回的视频数量,默认为10
|
||||
- `pageNum`: 页码,从0开始,默认为0
|
||||
|
||||
**获取逻辑**:
|
||||
1. 首先从Redis缓存中获取指定页的视频数据
|
||||
2. 如果Redis中的数据不足,会从数据库随机查询补充
|
||||
3. 确保每次返回指定数量的视频
|
||||
|
||||
## Redis存储格式
|
||||
|
||||
缓存数据以JSON格式存储在Redis中,key格式为:
|
||||
```
|
||||
top_liked_vlogs:yyyy-MM-dd
|
||||
```
|
||||
|
||||
例如:`top_liked_vlogs:2024-01-15`
|
||||
|
||||
数据包含视频的完整信息,包括:
|
||||
- 视频ID、标题、URL、封面
|
||||
- 点赞数、评论数(包含Redis中的实际点赞数:`redis_like_count`)
|
||||
- 上传者ID、创建时间等
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. 确保Redis服务正常运行
|
||||
2. 确保数据库连接正常
|
||||
3. 定时任务依赖于Spring Boot的调度功能,需要确保应用正常运行
|
||||
4. 缓存数据有效期为24小时,过期后需要重新执行任务
|
||||
5. 缓存时会先打乱视频顺序,确保数据的随机性
|
||||
6. 获取视频时会优先从Redis获取,不足时从数据库随机查询补充
|
||||
|
||||
## 日志监控
|
||||
|
||||
定时任务的执行情况会记录在应用日志中,可以通过以下关键字搜索:
|
||||
- "开始执行定时任务:查询点赞最多的100条视频并存储到Redis"
|
||||
- "定时任务执行完成:成功缓存点赞最多的100条视频到Redis"
|
||||
- "定时任务执行失败:缓存点赞最多视频到Redis时发生异常"
|
@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Slf4j
|
||||
@Api(tags = "VlogController 短视频相关业务功能的接口")
|
||||
@ -318,7 +319,9 @@ public class VlogController extends BaseInfoProperties {
|
||||
|
||||
@Tag(name = "获取缓存中的点赞最多视频")
|
||||
@GetMapping("/getTopLikedVlogs")
|
||||
public R<Object> getTopLikedVlogs(@RequestParam(defaultValue = "") String date) {
|
||||
public R<Object> getTopLikedVlogs(@RequestParam(defaultValue = "") String date,
|
||||
@RequestParam(defaultValue = "10") int pageSize,
|
||||
@RequestParam(defaultValue = "0") int pageNum) {
|
||||
try {
|
||||
String redisKey;
|
||||
if (StringUtils.isBlank(date)) {
|
||||
@ -329,14 +332,36 @@ public class VlogController extends BaseInfoProperties {
|
||||
}
|
||||
|
||||
String cachedData = redis.get(redisKey);
|
||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||
|
||||
if (StringUtils.isNotBlank(cachedData)) {
|
||||
// 解析JSON数据
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
List<Map<String, Object>> vlogList = objectMapper.readValue(cachedData, new com.fasterxml.jackson.core.type.TypeReference<List<Map<String, Object>>>() {});
|
||||
return R.ok(vlogList);
|
||||
} else {
|
||||
return R.fail("未找到缓存数据,请先执行缓存任务");
|
||||
|
||||
// 计算分页
|
||||
int startIndex = pageNum * pageSize;
|
||||
int endIndex = Math.min(startIndex + pageSize, vlogList.size());
|
||||
|
||||
if (startIndex < vlogList.size()) {
|
||||
// 从Redis缓存中获取指定页的数据
|
||||
resultList = vlogList.subList(startIndex, endIndex);
|
||||
log.info("从Redis缓存中获取了{}条视频数据", resultList.size());
|
||||
}
|
||||
}
|
||||
|
||||
// 如果Redis中的数据不足,从数据库随机查询补充
|
||||
if (resultList.size() < pageSize) {
|
||||
int needMore = pageSize - resultList.size();
|
||||
log.info("Redis缓存数据不足,需要从数据库随机查询{}条视频", needMore);
|
||||
|
||||
// 从数据库随机查询视频
|
||||
List<Map<String, Object>> randomVlogs = vlogService.getRandomVlogs(needMore);
|
||||
resultList.addAll(randomVlogs);
|
||||
log.info("从数据库随机查询了{}条视频", randomVlogs.size());
|
||||
}
|
||||
|
||||
return R.ok(resultList);
|
||||
} catch (Exception e) {
|
||||
log.error("获取缓存中的点赞最多视频失败", e);
|
||||
return R.fail("获取缓存失败: " + e.getMessage());
|
||||
|
@ -139,4 +139,33 @@ public interface VlogMapper extends BaseMapper<Vlog> {
|
||||
"WHERE v.status = 1 AND v.is_private = 0 " +
|
||||
"ORDER BY v.create_time DESC")
|
||||
List<Map<String, Object>> selectAllPublicVlogs();
|
||||
|
||||
/**
|
||||
* 随机查询指定数量的公开视频
|
||||
* @param limit 查询数量限制
|
||||
* @return 随机视频列表
|
||||
*/
|
||||
@Select("SELECT " +
|
||||
" v.id, " +
|
||||
" v.vloger_id, " +
|
||||
" v.url, " +
|
||||
" v.cover, " +
|
||||
" v.title, " +
|
||||
" v.width, " +
|
||||
" v.height, " +
|
||||
" v.like_counts, " +
|
||||
" v.comments_counts, " +
|
||||
" v.is_private, " +
|
||||
" v.create_time, " +
|
||||
" v.update_time, " +
|
||||
" v.status, " +
|
||||
" v.file_id, " +
|
||||
" v.reason, " +
|
||||
" v.city_code, " +
|
||||
" v.first_frame_img " +
|
||||
"FROM t_vlog v " +
|
||||
"WHERE v.status = 1 AND v.is_private = 0 " +
|
||||
"ORDER BY RAND() " +
|
||||
"LIMIT #{limit}")
|
||||
List<Map<String, Object>> selectRandomVlogs(@Param("limit") int limit);
|
||||
}
|
||||
|
@ -143,4 +143,11 @@ public interface VlogService {
|
||||
* @param limit 查询数量限制
|
||||
*/
|
||||
void cacheTopLikedVlogs(int limit);
|
||||
|
||||
/**
|
||||
* 随机查询视频列表
|
||||
* @param limit 查询数量限制
|
||||
* @return 随机视频列表
|
||||
*/
|
||||
List<Map<String, Object>> getRandomVlogs(int limit);
|
||||
}
|
||||
|
@ -644,6 +644,9 @@ public class VlogServiceImpl extends BaseInfoProperties implements VlogService {
|
||||
vlogsWithLikeCounts.add(vlog);
|
||||
}
|
||||
|
||||
// 先打乱顺序
|
||||
Collections.shuffle(vlogsWithLikeCounts);
|
||||
|
||||
// 按Redis中的点赞数排序,获取前limit个
|
||||
vlogsWithLikeCounts.sort((v1, v2) -> {
|
||||
int count1 = (Integer) v1.get("redis_like_count");
|
||||
@ -679,4 +682,17 @@ public class VlogServiceImpl extends BaseInfoProperties implements VlogService {
|
||||
log.error("缓存点赞最多视频到Redis失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getRandomVlogs(int limit) {
|
||||
try {
|
||||
log.info("开始随机查询{}条视频", limit);
|
||||
List<Map<String, Object>> randomVlogs = vlogMapper.selectRandomVlogs(limit);
|
||||
log.info("成功随机查询到{}条视频", randomVlogs.size());
|
||||
return randomVlogs;
|
||||
} catch (Exception e) {
|
||||
log.error("随机查询视频失败", e);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
package com.wzj.soopin.content.task;
|
||||
|
||||
import com.wzj.soopin.content.service.VlogService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 视频相关定时任务
|
||||
*
|
||||
* @author wzj
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class VlogScheduledTask {
|
||||
|
||||
@Autowired
|
||||
private VlogService vlogService;
|
||||
|
||||
/**
|
||||
* 每天12点定时查询点赞最多的100条视频并存储到Redis
|
||||
* cron表达式:0 0 12 * * ? (每天12点执行)
|
||||
*/
|
||||
@Scheduled(cron = "0 0 12 * * ?")
|
||||
public void cacheTopLikedVlogs() {
|
||||
log.info("开始执行定时任务:查询点赞最多的100条视频并存储到Redis");
|
||||
try {
|
||||
vlogService.cacheTopLikedVlogs(100);
|
||||
log.info("定时任务执行完成:成功缓存点赞最多的100条视频到Redis");
|
||||
} catch (Exception e) {
|
||||
log.error("定时任务执行失败:缓存点赞最多视频到Redis时发生异常", e);
|
||||
}
|
||||
}
|
||||
}
|
111
ruoyi-modules/ruoyi-order/README_定时任务.md
Normal file
111
ruoyi-modules/ruoyi-order/README_定时任务.md
Normal file
@ -0,0 +1,111 @@
|
||||
# 商品交易量排行榜定时任务
|
||||
|
||||
## 功能说明
|
||||
|
||||
本功能实现了每天12点自动查询交易量最多的100个商品并存储到Redis中的定时任务。
|
||||
|
||||
## 实现内容
|
||||
|
||||
### 1. 数据库查询
|
||||
- 在 `OrderItemMapper` 中添加了 `selectTopTradingProducts` 方法
|
||||
- 查询条件:已完成订单(status = 3)且未删除订单(delete_status = 0)
|
||||
- 按销售数量降序排列,取前100个商品
|
||||
- 统计信息包括:商品ID、商品名称、图片、总销售数量、总销售金额、订单数量
|
||||
|
||||
### 2. 服务层实现
|
||||
- 在 `OrderItemService` 接口中添加了 `cacheTopTradingProducts` 方法
|
||||
- 在 `OrderItemServiceImpl` 中实现了缓存逻辑
|
||||
- 将查询结果以JSON格式存储到Redis,过期时间为24小时
|
||||
|
||||
### 3. 定时任务
|
||||
- 创建了 `OrderScheduledTask` 定时任务类
|
||||
- 使用 `@Scheduled(cron = "0 0 12 * * ?")` 配置每天12点执行
|
||||
- 在主应用类 `DromaraApplication` 上已添加了 `@EnableScheduling` 注解
|
||||
|
||||
### 4. 控制器接口
|
||||
- 添加了手动触发缓存的接口:`POST /oms/order/cacheTopTradingProducts`
|
||||
- 添加了获取缓存数据的接口:`GET /oms/order/getTopTradingProducts`
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 1. 自动执行
|
||||
定时任务会在每天12点自动执行,无需手动干预。
|
||||
|
||||
### 2. 手动触发
|
||||
如果需要立即执行缓存任务,可以调用以下接口:
|
||||
|
||||
```bash
|
||||
POST /oms/order/cacheTopTradingProducts?limit=100
|
||||
```
|
||||
|
||||
参数说明:
|
||||
- `limit`: 查询的商品数量,默认为100
|
||||
|
||||
### 3. 查看缓存结果
|
||||
可以通过以下接口查看缓存的数据:
|
||||
|
||||
```bash
|
||||
GET /oms/order/getTopTradingProducts
|
||||
GET /oms/order/getTopTradingProducts?date=2024-01-15
|
||||
```
|
||||
|
||||
参数说明:
|
||||
- `date`: 可选,指定查看某一天的缓存数据,格式为yyyy-MM-dd
|
||||
|
||||
### 4. 返回数据格式
|
||||
缓存的数据包含以下字段:
|
||||
- `product_id`: 商品ID
|
||||
- `product_name`: 商品名称
|
||||
- `pic`: 商品图片
|
||||
- `out_product_id`: 商品编码
|
||||
- `product_category_id`: 商品分类ID
|
||||
- `total_quantity`: 总销售数量
|
||||
- `total_amount`: 总销售金额
|
||||
- `order_count`: 订单数量
|
||||
|
||||
## 技术实现
|
||||
|
||||
### 1. SQL查询逻辑
|
||||
```sql
|
||||
SELECT
|
||||
oi.product_id,
|
||||
oi.product_name,
|
||||
oi.pic,
|
||||
oi.out_product_id,
|
||||
oi.product_category_id,
|
||||
SUM(oi.quantity) as total_quantity,
|
||||
SUM(oi.quantity * oi.sale_price) as total_amount,
|
||||
COUNT(DISTINCT o.id) as order_count
|
||||
FROM oms_order_item oi
|
||||
JOIN oms_order o ON oi.order_id = o.id
|
||||
WHERE o.status = 3 -- 已完成订单
|
||||
AND o.delete_status = 0 -- 未删除订单
|
||||
GROUP BY oi.product_id, oi.product_name, oi.pic, oi.out_product_id, oi.product_category_id
|
||||
ORDER BY total_quantity DESC
|
||||
LIMIT #{limit}
|
||||
```
|
||||
|
||||
### 2. Redis缓存
|
||||
- Key格式:`top_trading_products:yyyy-MM-dd`
|
||||
- 过期时间:24小时
|
||||
- 数据格式:JSON字符串
|
||||
|
||||
### 3. 异常处理
|
||||
- 完善的异常处理和日志记录
|
||||
- 手动触发接口返回详细的错误信息
|
||||
- 定时任务异常不会影响系统正常运行
|
||||
|
||||
## 注意事项
|
||||
|
||||
1. **数据准确性**:只统计已完成订单的商品,确保数据的准确性
|
||||
2. **性能考虑**:大量订单数据时,查询可能需要较长时间
|
||||
3. **缓存更新**:每天12点自动更新,也可手动触发
|
||||
4. **数据过期**:缓存数据24小时自动过期,避免数据过期问题
|
||||
|
||||
## 扩展功能
|
||||
|
||||
如需扩展功能,可以考虑:
|
||||
1. 按时间范围统计(如最近7天、30天)
|
||||
2. 按商品分类统计
|
||||
3. 添加更多统计维度(如销售额、利润率等)
|
||||
4. 支持多租户数据隔离
|
@ -0,0 +1,35 @@
|
||||
package com.wzj.soopin.order.task;
|
||||
|
||||
import com.wzj.soopin.order.service.OrderItemService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 订单相关定时任务
|
||||
*
|
||||
* @author wzj
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class OrderScheduledTask {
|
||||
|
||||
@Autowired
|
||||
private OrderItemService orderItemService;
|
||||
|
||||
/**
|
||||
* 每天12点定时查询交易量最多的100个商品并存储到Redis
|
||||
* cron表达式:0 0 12 * * ? (每天12点执行)
|
||||
*/
|
||||
@Scheduled(cron = "0 0 12 * * ?")
|
||||
public void cacheTopTradingProducts() {
|
||||
log.info("开始执行定时任务:查询交易量最多的100个商品并存储到Redis");
|
||||
try {
|
||||
orderItemService.cacheTopTradingProducts(100);
|
||||
log.info("定时任务执行完成:成功缓存交易量最多的100个商品到Redis");
|
||||
} catch (Exception e) {
|
||||
log.error("定时任务执行失败:缓存交易量最多商品到Redis时发生异常", e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
package org.dromara.system.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.log.annotation.Log;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.system.domain.CommissionTemplate;
|
||||
import org.dromara.system.domain.bo.CommissionSectionBo;
|
||||
import org.dromara.system.domain.bo.CommissionTemplateBo;
|
||||
import org.dromara.system.domain.dto.CommissionSectionBatchAddDTO;
|
||||
import org.dromara.system.domain.vo.CommissionSectionVo;
|
||||
import org.dromara.system.domain.vo.CommissionTemplateVo;
|
||||
import org.dromara.system.service.ICommissionSectionService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
|
||||
import org.dromara.system.service.ICommissionTemplateService;
|
||||
import org.dromara.system.convert.CommissionSectionConvert;
|
||||
|
||||
|
||||
/**
|
||||
* 分成比例区间接口
|
||||
*/
|
||||
@Tag(name = "分成比例区间管理")
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/commission-section")
|
||||
public class CommissionSectionController {
|
||||
private final ICommissionSectionService commissionSectionService;
|
||||
private final CommissionSectionConvert convert;
|
||||
|
||||
|
||||
|
||||
/** 分页查询 */
|
||||
@Tag(name = "查询分成比例区间列表")
|
||||
@SaCheckPermission("system:commissionsection:list")
|
||||
@PostMapping("/list")
|
||||
public R<Page<CommissionSectionVo>> list(@RequestBody CommissionSectionBo bo, @RequestBody Page<CommissionSection> page) {
|
||||
Page<CommissionSection> memberPage = commissionSectionService.page(page,bo.toWrapper());
|
||||
TableDataInfo.build(memberPage);
|
||||
return R.ok(convert.toVO(memberPage));
|
||||
}
|
||||
|
||||
/** 查询详情 */
|
||||
@Operation(summary = "查询分成比例区间详情")
|
||||
@GetMapping("/{id}")
|
||||
public R<CommissionSectionVo> getInfo(@Parameter(description = "主键ID") @PathVariable Integer id) {
|
||||
return R.ok(commissionSectionService.queryById(id));
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
@Operation(summary = "新增分成比例区间")
|
||||
@Log(title = "分成比例区间", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public R<Boolean> add(@Validated @RequestBody CommissionSectionBo bo) {
|
||||
return R.ok(commissionSectionService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/** 修改 */
|
||||
@Operation(summary = "修改分成比例区间")
|
||||
@Log(title = "分成比例区间", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/edit")
|
||||
public R<Boolean> edit(@Validated @RequestBody CommissionSectionBatchAddDTO dto) {
|
||||
List<CommissionSectionBo> list = cn.hutool.json.JSONUtil.toList(dto.getTemplateList(), CommissionSectionBo.class);
|
||||
// 给每个bo设置templateId
|
||||
for (CommissionSectionBo bo : list) {
|
||||
bo.setTemplateId(dto.getTemplateId());
|
||||
commissionSectionService.updateByBo(bo);
|
||||
}
|
||||
return R.ok(true);
|
||||
}
|
||||
|
||||
/** 批量新增分成比例区间 */
|
||||
@Operation(summary = "批量新增分成比例区间")
|
||||
@Log(title = "分成比例区间", businessType = BusinessType.INSERT)
|
||||
@PostMapping("/batch")
|
||||
public R<Boolean> batchAdd(@RequestBody CommissionSectionBatchAddDTO dto) {
|
||||
// 反序列化字符串为List<CommissionSectionBo>
|
||||
List<CommissionSectionBo> list = cn.hutool.json.JSONUtil.toList(dto.getTemplateList(), CommissionSectionBo.class);
|
||||
// 给每个bo设置templateId
|
||||
for (CommissionSectionBo bo : list) {
|
||||
bo.setTemplateId(dto.getTemplateId());
|
||||
commissionSectionService.insertByBo(bo);
|
||||
}
|
||||
return R.ok(true);
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
@Operation(summary = "批量删除分成比例区间")
|
||||
@Log(title = "分成比例区间", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Boolean> remove(@Parameter(description = "主键ID集合") @PathVariable List<Integer> ids) {
|
||||
return R.ok(commissionSectionService.deleteWithValidByIds(ids, true));
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
package org.dromara.system.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.log.annotation.Log;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
|
||||
import org.dromara.system.domain.bo.CommissionTemplateBo;
|
||||
import org.dromara.system.domain.vo.CommissionTemplateVo;
|
||||
import org.dromara.system.service.ICommissionTemplateService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
import org.dromara.system.domain.CommissionTemplate;
|
||||
import org.dromara.system.convert.CommissionTemplateConvert;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.system.service.ICommissionSectionService;
|
||||
import org.dromara.system.domain.vo.CommissionSectionVo;
|
||||
|
||||
|
||||
/**
|
||||
* 分成比例模板接口
|
||||
*/
|
||||
@Tag(name = "分成比例模板管理")
|
||||
@Validated
|
||||
@RequiredArgsConstructor
|
||||
@RestController
|
||||
@RequestMapping("/system/commission-template")
|
||||
public class CommissionTemplateController {
|
||||
private final ICommissionTemplateService commissionTemplateService;
|
||||
private final CommissionTemplateConvert convert;
|
||||
private final ICommissionSectionService commissionSectionService;
|
||||
|
||||
|
||||
/** 分页查询 */
|
||||
@Operation(summary = "分页查询分成比例模板")
|
||||
@Tag(name = "查询分成比例模板列表")
|
||||
@PostMapping("/list")
|
||||
public R<Page<CommissionTemplateVo>> list(@RequestBody CommissionTemplateBo bo, @RequestBody Page<CommissionTemplate> page) {
|
||||
Page<CommissionTemplate> memberPage = commissionTemplateService.page(page,bo.toWrapper());
|
||||
TableDataInfo.build(memberPage);
|
||||
return R.ok(convert.toVO(memberPage));
|
||||
}
|
||||
|
||||
@Operation(summary = "查询全部分成比例模板")
|
||||
@Tag(name = "查询分成比例模板列表")
|
||||
@GetMapping("/all")
|
||||
public R<List<CommissionTemplateVo>> listAll() {
|
||||
// 查询全部,不分页
|
||||
List<CommissionTemplate> list = commissionTemplateService.list();
|
||||
List<CommissionTemplateVo> voList = convert.toVO(list);
|
||||
return R.ok(voList);
|
||||
}
|
||||
/** 查询详情 */
|
||||
@Operation(summary = "查询分成比例模板详情")
|
||||
@GetMapping("/{id}")
|
||||
public R<CommissionTemplateVo> getInfo(@Parameter(description = "主键ID") @PathVariable Integer id) {
|
||||
return R.ok(commissionTemplateService.queryById(id));
|
||||
}
|
||||
|
||||
/** 新增 */
|
||||
@Operation(summary = "新增分成比例模板")
|
||||
@Log(title = "分成比例模板", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public R<Boolean> add(@Validated @RequestBody CommissionTemplateBo bo) {
|
||||
return R.ok(commissionTemplateService.insertByBo(bo));
|
||||
}
|
||||
|
||||
/** 修改 */
|
||||
@Operation(summary = "修改分成比例模板")
|
||||
@Log(title = "分成比例模板", businessType = BusinessType.UPDATE)
|
||||
@PostMapping("/edit")
|
||||
public R<Boolean> edit(@Validated @RequestBody CommissionTemplateBo bo) {
|
||||
return R.ok(commissionTemplateService.updateByBo(bo));
|
||||
}
|
||||
|
||||
/** 删除 */
|
||||
@Operation(summary = "批量删除分成比例模板")
|
||||
@Log(title = "分成比例模板", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public R<Boolean> remove(@Parameter(description = "主键ID集合") @PathVariable List<Integer> ids) {
|
||||
return R.ok(commissionTemplateService.deleteWithValidByIds(ids, true));
|
||||
}
|
||||
|
||||
/** 根据模板ID查询区间比例列表(POST风格) */
|
||||
@Operation(summary = "根据模板ID查询区间比例列表")
|
||||
@PostMapping("/sections")
|
||||
public R<List<CommissionSectionVo>> getSectionsByTemplateId(@RequestBody TemplateIdRequest req) {
|
||||
List<CommissionSectionVo> list = commissionSectionService.queryListByTemplateId(req.getTemplateId());
|
||||
return R.ok(list);
|
||||
}
|
||||
|
||||
// DTO
|
||||
public static class TemplateIdRequest {
|
||||
private Integer templateId;
|
||||
public Integer getTemplateId() { return templateId; }
|
||||
public void setTemplateId(Integer templateId) { this.templateId = templateId; }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package org.dromara.system.convert;
|
||||
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
import org.dromara.system.domain.bo.CommissionSectionBo;
|
||||
import org.dromara.system.domain.vo.CommissionSectionVo;
|
||||
import org.dromara.common.web.core.BaseConverter;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
/**
|
||||
* @author 86132
|
||||
*/
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface CommissionSectionConvert extends BaseConverter<CommissionSectionVo, CommissionSectionBo, CommissionSection> {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package org.dromara.system.convert;
|
||||
|
||||
import org.dromara.system.domain.CommissionTemplate;
|
||||
import org.dromara.system.domain.bo.CommissionTemplateBo;
|
||||
import org.dromara.system.domain.vo.CommissionTemplateVo;
|
||||
import org.dromara.common.web.core.BaseConverter;
|
||||
import org.mapstruct.Mapper;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface CommissionTemplateConvert extends BaseConverter<CommissionTemplateVo, CommissionTemplateBo, CommissionTemplate> {
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.dromara.system.convert;
|
||||
|
||||
import org.dromara.common.web.core.BaseConverter;
|
||||
import org.dromara.system.domain.SysTenantAccount;
|
||||
import org.dromara.system.domain.bo.SysTenantAccountBo;
|
||||
import org.dromara.system.domain.vo.SysTenantAccountVo;
|
||||
import org.mapstruct.Mapper;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper(componentModel = "spring")
|
||||
public interface SysTenantAccountConvert extends BaseConverter<SysTenantAccountVo, SysTenantAccountBo, SysTenantAccount> {
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package org.dromara.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.core.domain.model.BaseAudit;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import org.dromara.common.tenant.core.TenantEntity;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 分成比例区间表 commission_section
|
||||
* @author 86132
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("commission_rate_range")
|
||||
@Schema(name = "CommissionSection", description = "分成比例区间表")
|
||||
public class CommissionSection extends BaseAudit {
|
||||
/** 主键,自增ID */
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@Schema(description = "主键,自增ID")
|
||||
private Integer id;
|
||||
|
||||
/** 所属模板ID,关联commission_template表 */
|
||||
@Schema(description = "所属模板ID,关联commission_template表")
|
||||
private Integer templateId;
|
||||
|
||||
/** 区间下限(包含),单位:元 */
|
||||
@Schema(description = "区间下限(包含),单位:元")
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/** 区间上限(包含),单位:元 */
|
||||
@Schema(description = "区间上限(包含),单位:元")
|
||||
private BigDecimal maxAmount;
|
||||
|
||||
/** 分成比例(如0.6000表示60%) */
|
||||
@Schema(description = "分成比例(如0.6000表示60%)")
|
||||
private BigDecimal rate;
|
||||
|
||||
/** 区间名称 */
|
||||
@Schema(description = "名称")
|
||||
private String rateName;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package org.dromara.system.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.core.domain.model.BaseAudit;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import org.dromara.common.tenant.core.TenantEntity;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 分成比例模板表 commission_template
|
||||
* @author 86132
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@TableName("commission_template")
|
||||
@Schema(name = "CommissionTemplate", description = "分成比例模板表")
|
||||
public class CommissionTemplate extends BaseAudit {
|
||||
/** 主键,自增ID */
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@Schema(description = "主键,自增ID")
|
||||
private Integer id;
|
||||
|
||||
/** 模板名称,唯一标识一个分成模板 */
|
||||
@Schema(description = "模板名称,唯一标识一个分成模板")
|
||||
private String templateName;
|
||||
|
||||
/** 模板描述,简要说明模板用途 */
|
||||
@Schema(description = "模板描述,简要说明模板用途")
|
||||
private String description;
|
||||
|
||||
/** 是否启用:1=启用,0=禁用 */
|
||||
@Schema(description = "是否启用:1=启用,0=禁用")
|
||||
private Integer isActive;
|
||||
|
||||
/** 模板类型 */
|
||||
@Schema(description = "类型")
|
||||
private String templateType;
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package org.dromara.system.domain;
|
||||
|
||||
import lombok.Data;
|
||||
import org.dromara.common.core.domain.model.BaseAudit;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@Schema(description = "租户账户实体")
|
||||
public class SysTenantAccount extends BaseAudit {
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
@Schema(description = "租户ID")
|
||||
private Long tenantId;
|
||||
@Schema(description = "积分余额")
|
||||
private BigDecimal integralBalance;
|
||||
@Schema(description = "累计积分余额")
|
||||
private BigDecimal totalIntegralBalance;
|
||||
@Schema(description = "现金余额")
|
||||
private BigDecimal moneyBalance;
|
||||
@Schema(description = "钱包余额")
|
||||
private BigDecimal wallet;
|
||||
@Schema(description = "累计收益")
|
||||
private BigDecimal revenue;
|
||||
@Schema(description = "创建人")
|
||||
private Long createBy;
|
||||
@Schema(description = "更新人")
|
||||
private Long updateBy;
|
||||
@Schema(description = "账户类型 1商家 2代理 3平台")
|
||||
private Integer type;
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package org.dromara.system.domain.bo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.DecimalMax;
|
||||
import jakarta.validation.constraints.DecimalMin;
|
||||
import jakarta.validation.constraints.Digits;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.dromara.common.core.domain.model.BaseAudit;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 分成比例区间业务对象 commission_section
|
||||
* @author 86132
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = CommissionSection.class, reverseConvertGenerate = false)
|
||||
@Schema(name = "CommissionSectionBo", description = "分成比例区间业务对象")
|
||||
public class CommissionSectionBo extends BaseAudit {
|
||||
/** 主键 */
|
||||
@Schema(description = "主键")
|
||||
private Integer id;
|
||||
|
||||
/** 所属模板ID */
|
||||
@Schema(description = "所属模板ID")
|
||||
@NotNull(message = "所属模板ID不能为空")
|
||||
private Integer templateId;
|
||||
|
||||
/** 区间下限(包含),单位:元 */
|
||||
@Schema(description = "区间下限(包含),单位:元")
|
||||
|
||||
@Digits(integer = 17, fraction = 2, message = "区间下限最多19位,含2位小数")
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/** 区间上限(包含),单位:元 */
|
||||
@Schema(description = "区间上限(包含),单位:元")
|
||||
|
||||
@Digits(integer = 17, fraction = 2, message = "区间上限最多19位,含2位小数")
|
||||
private BigDecimal maxAmount;
|
||||
|
||||
/** 分成比例(如0.6000表示60%) */
|
||||
@Schema(description = "分成比例(如0.6000表示60%)")
|
||||
|
||||
@Digits(integer = 1, fraction = 4, message = "分成比例最多5位,含4位小数")
|
||||
private BigDecimal rate;
|
||||
|
||||
/** 区间名称 */
|
||||
@Schema(description = "名称")
|
||||
private String rateName;
|
||||
|
||||
/**
|
||||
* 构建分页查询条件
|
||||
*/
|
||||
public LambdaQueryWrapper<CommissionSection> toWrapper() {
|
||||
LambdaQueryWrapper<CommissionSection> wrapper = new LambdaQueryWrapper<>();
|
||||
if (this.getTemplateId() != null) {
|
||||
wrapper.eq(CommissionSection::getTemplateId, this.getTemplateId());
|
||||
}
|
||||
if (this.getMinAmount() != null) {
|
||||
wrapper.ge(CommissionSection::getMinAmount, this.getMinAmount());
|
||||
}
|
||||
if (this.getMaxAmount() != null) {
|
||||
wrapper.le(CommissionSection::getMaxAmount, this.getMaxAmount());
|
||||
}
|
||||
if (this.getRate() != null) {
|
||||
wrapper.eq(CommissionSection::getRate, this.getRate());
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package org.dromara.system.domain.bo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import io.github.linpeilie.annotations.AutoMapper;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.dromara.common.core.domain.model.BaseAudit;
|
||||
import org.dromara.common.mybatis.core.domain.BaseEntity;
|
||||
import org.dromara.system.domain.CommissionTemplate;
|
||||
|
||||
/**
|
||||
* 分成比例模板业务对象 commission_template
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AutoMapper(target = CommissionTemplate.class, reverseConvertGenerate = false)
|
||||
@Schema(name = "CommissionTemplateBo", description = "分成比例模板业务对象")
|
||||
public class CommissionTemplateBo extends BaseAudit {
|
||||
/** 主键 */
|
||||
@Schema(description = "主键")
|
||||
private Integer id;
|
||||
|
||||
/** 模板名称,唯一标识一个分成模板 */
|
||||
@Schema(description = "模板名称,唯一标识一个分成模板")
|
||||
@NotBlank(message = "模板名称不能为空")
|
||||
@Size(max = 100, message = "模板名称长度不能超过100个字符")
|
||||
private String templateName;
|
||||
|
||||
/** 模板描述 */
|
||||
@Schema(description = "模板描述")
|
||||
@Size(max = 255, message = "模板描述长度不能超过255个字符")
|
||||
private String description;
|
||||
|
||||
/** 模板类型 */
|
||||
@Schema(description = "类型")
|
||||
private String templateType;
|
||||
|
||||
/** 是否启用:1=启用,0=禁用 */
|
||||
@Schema(description = "是否启用:1=启用,0=禁用")
|
||||
private Integer isActive;
|
||||
|
||||
/**
|
||||
* 构建分页查询条件
|
||||
*/
|
||||
public LambdaQueryWrapper<CommissionTemplate> toWrapper() {
|
||||
LambdaQueryWrapper<CommissionTemplate> wrapper = new LambdaQueryWrapper<>();
|
||||
if (this.getTemplateName() != null && !this.getTemplateName().isEmpty()) {
|
||||
wrapper.like(CommissionTemplate::getTemplateName, this.getTemplateName());
|
||||
}
|
||||
if (this.getIsActive() != null) {
|
||||
wrapper.eq(CommissionTemplate::getIsActive, this.getIsActive());
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package org.dromara.system.domain.bo;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.dromara.common.core.domain.model.BaseAudit;
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
import org.dromara.system.domain.SysTenantAccount;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@Data
|
||||
@Schema(description = "租户账户业务对象")
|
||||
public class SysTenantAccountBo extends BaseAudit {
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
@Schema(description = "租户ID")
|
||||
private Long tenantId;
|
||||
@Schema(description = "积分余额")
|
||||
private BigDecimal integralBalance;
|
||||
@Schema(description = "累计积分余额")
|
||||
private BigDecimal totalIntegralBalance;
|
||||
@Schema(description = "现金余额")
|
||||
private BigDecimal moneyBalance;
|
||||
@Schema(description = "钱包余额")
|
||||
private BigDecimal wallet;
|
||||
@Schema(description = "累计收益")
|
||||
private BigDecimal revenue;
|
||||
@Schema(description = "创建人")
|
||||
private Long createBy;
|
||||
@Schema(description = "更新人")
|
||||
private Long updateBy;
|
||||
@Schema(description = "账户类型 1商家 2代理 3平台")
|
||||
private Integer type;
|
||||
|
||||
public LambdaQueryWrapper<SysTenantAccount> toWrapper() {
|
||||
LambdaQueryWrapper<SysTenantAccount> wrapper = new LambdaQueryWrapper<>();
|
||||
if (id != null) {
|
||||
wrapper.eq(SysTenantAccount::getId, id);
|
||||
}
|
||||
if (type != null) {
|
||||
wrapper.eq(SysTenantAccount::getType, type);
|
||||
}
|
||||
if (tenantId != null) {
|
||||
wrapper.eq(SysTenantAccount::getTenantId, tenantId);
|
||||
}
|
||||
|
||||
if (wallet != null) {
|
||||
wrapper.eq(SysTenantAccount::getWallet, wallet);
|
||||
}
|
||||
if (revenue != null) {
|
||||
wrapper.eq(SysTenantAccount::getRevenue, revenue);
|
||||
}
|
||||
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package org.dromara.system.domain.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 分成比例区间返回对象 commission_section
|
||||
* @author 86132
|
||||
*/
|
||||
@Data
|
||||
@Schema(name = "CommissionSectionVo", description = "分成比例区间返回对象")
|
||||
public class CommissionSectionVo {
|
||||
/** 主键 */
|
||||
@Schema(description = "主键")
|
||||
private Integer id;
|
||||
|
||||
/** 所属模板ID */
|
||||
@Schema(description = "所属模板ID")
|
||||
private Integer templateId;
|
||||
|
||||
/** 区间下限 */
|
||||
@Schema(description = "区间下限")
|
||||
private BigDecimal minAmount;
|
||||
|
||||
/** 区间上限 */
|
||||
@Schema(description = "区间上限")
|
||||
private BigDecimal maxAmount;
|
||||
|
||||
/** 分成比例 */
|
||||
@Schema(description = "分成比例")
|
||||
private BigDecimal rate;
|
||||
|
||||
/** 区间名称 */
|
||||
@Schema(description = "名称")
|
||||
private String rateName;
|
||||
|
||||
/** 创建时间 */
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package org.dromara.system.domain.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 分成比例模板返回对象 commission_template
|
||||
* @author 86132
|
||||
*/
|
||||
@Data
|
||||
@Schema(name = "CommissionTemplateVo", description = "分成比例模板返回对象")
|
||||
public class CommissionTemplateVo {
|
||||
/** 主键 */
|
||||
@Schema(description = "主键")
|
||||
private Integer id;
|
||||
|
||||
/** 模板名称 */
|
||||
@Schema(description = "模板名称")
|
||||
private String templateName;
|
||||
|
||||
/** 模板描述 */
|
||||
@Schema(description = "模板描述")
|
||||
private String description;
|
||||
|
||||
/** 是否启用 */
|
||||
@Schema(description = "是否启用")
|
||||
private Integer isActive;
|
||||
|
||||
/** 模板类型 */
|
||||
@Schema(description = "类型")
|
||||
private String templateType;
|
||||
|
||||
/** 创建时间 */
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/** 最后更新时间 */
|
||||
@Schema(description = "最后更新时间")
|
||||
private LocalDateTime updateTime;
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package org.dromara.system.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
@Data
|
||||
@Schema(description = "租户账户视图对象")
|
||||
public class SysTenantAccountVo {
|
||||
@Schema(description = "主键ID")
|
||||
private Long id;
|
||||
@Schema(description = "租户ID")
|
||||
private Long tenantId;
|
||||
@Schema(description = "积分余额")
|
||||
private BigDecimal integralBalance;
|
||||
@Schema(description = "累计积分余额")
|
||||
private BigDecimal totalIntegralBalance;
|
||||
@Schema(description = "更新时间")
|
||||
private Date updateTime;
|
||||
@Schema(description = "创建时间")
|
||||
private Date createTime;
|
||||
@Schema(description = "现金余额")
|
||||
private BigDecimal moneyBalance;
|
||||
@Schema(description = "钱包余额")
|
||||
private BigDecimal wallet;
|
||||
@Schema(description = "累计收益")
|
||||
private BigDecimal revenue;
|
||||
@Schema(description = "创建人")
|
||||
private Long createBy;
|
||||
@Schema(description = "更新人")
|
||||
private Long updateBy;
|
||||
@Schema(description = "账户类型 1商家 2代理 3平台")
|
||||
private Integer type;
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package org.dromara.system.mapper;
|
||||
|
||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
import org.dromara.system.domain.vo.CommissionSectionVo;
|
||||
|
||||
/**
|
||||
* 分成比例区间Mapper接口
|
||||
*/
|
||||
public interface CommissionSectionMapper extends BaseMapperPlus<CommissionSection, CommissionSectionVo> {
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package org.dromara.system.mapper;
|
||||
|
||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.dromara.system.domain.CommissionTemplate;
|
||||
import org.dromara.system.domain.vo.CommissionTemplateVo;
|
||||
|
||||
/**
|
||||
* 分成比例模板Mapper接口
|
||||
*/
|
||||
public interface CommissionTemplateMapper extends BaseMapperPlus<CommissionTemplate, CommissionTemplateVo> {
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.dromara.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
import org.dromara.system.domain.SysTenantAccount;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.dromara.system.domain.vo.CommissionSectionVo;
|
||||
import org.dromara.system.domain.vo.SysTenantAccountVo;
|
||||
|
||||
@Mapper
|
||||
public interface SysTenantAccountMapper extends BaseMapperPlus<SysTenantAccount, SysTenantAccountVo> {
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package org.dromara.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
import org.dromara.system.domain.bo.CommissionSectionBo;
|
||||
import org.dromara.system.domain.vo.CommissionSectionVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分成比例区间Service接口
|
||||
*/
|
||||
public interface ICommissionSectionService extends IService<CommissionSection> {
|
||||
/**
|
||||
* 分页查询分成比例区间列表
|
||||
*/
|
||||
TableDataInfo<CommissionSectionVo> queryPageList(CommissionSectionBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询分成比例区间详情
|
||||
*/
|
||||
CommissionSectionVo queryById(Integer id);
|
||||
|
||||
/**
|
||||
* 新增分成比例区间
|
||||
*/
|
||||
Boolean insertByBo(CommissionSectionBo bo);
|
||||
|
||||
/**
|
||||
* 修改分成比例区间
|
||||
*/
|
||||
Boolean updateByBo(CommissionSectionBo bo);
|
||||
|
||||
/**
|
||||
* 批量删除分成比例区间
|
||||
*/
|
||||
Boolean deleteWithValidByIds(List<Integer> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 根据模板ID查询区间比例列表
|
||||
*/
|
||||
List<CommissionSectionVo> queryListByTemplateId(Integer templateId);
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package org.dromara.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.system.domain.CommissionTemplate;
|
||||
import org.dromara.system.domain.bo.CommissionTemplateBo;
|
||||
import org.dromara.system.domain.vo.CommissionTemplateVo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分成比例模板Service接口
|
||||
*/
|
||||
public interface ICommissionTemplateService extends IService<CommissionTemplate> {
|
||||
/**
|
||||
* 分页查询分成比例模板列表
|
||||
*/
|
||||
TableDataInfo<CommissionTemplateVo> queryPageList(CommissionTemplateBo bo, PageQuery pageQuery);
|
||||
|
||||
/**
|
||||
* 查询分成比例模板详情
|
||||
*/
|
||||
CommissionTemplateVo queryById(Integer id);
|
||||
|
||||
/**
|
||||
* 新增分成比例模板
|
||||
*/
|
||||
Boolean insertByBo(CommissionTemplateBo bo);
|
||||
|
||||
/**
|
||||
* 修改分成比例模板
|
||||
*/
|
||||
Boolean updateByBo(CommissionTemplateBo bo);
|
||||
|
||||
/**
|
||||
* 批量删除分成比例模板
|
||||
*/
|
||||
Boolean deleteWithValidByIds(List<Integer> ids, Boolean isValid);
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package org.dromara.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
import org.dromara.system.domain.SysTenantAccount;
|
||||
import org.dromara.system.domain.bo.SysTenantAccountBo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ISysTenantAccountService extends IService<SysTenantAccount> {
|
||||
IPage<SysTenantAccount> pageWithTenant(Page<SysTenantAccount> page, SysTenantAccountBo bo);
|
||||
List<SysTenantAccount> list(SysTenantAccountBo bo);
|
||||
SysTenantAccount getById(Long id);
|
||||
boolean save(SysTenantAccount po);
|
||||
boolean updateById(SysTenantAccount po);
|
||||
boolean removeById(Long id);
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
package org.dromara.system.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
import org.dromara.system.domain.bo.CommissionSectionBo;
|
||||
import org.dromara.system.domain.vo.CommissionSectionVo;
|
||||
import org.dromara.system.mapper.CommissionSectionMapper;
|
||||
import org.dromara.system.service.ICommissionSectionService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import org.dromara.system.mapper.CommissionTemplateMapper;
|
||||
import org.dromara.system.domain.CommissionTemplate;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
|
||||
/**
|
||||
* 分成比例区间Service实现
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class CommissionSectionServiceImpl extends ServiceImpl<CommissionSectionMapper,CommissionSection> implements ICommissionSectionService{
|
||||
private final CommissionSectionMapper baseMapper;
|
||||
private final CommissionTemplateMapper templateMapper;
|
||||
|
||||
@Override
|
||||
public TableDataInfo<CommissionSectionVo> queryPageList(CommissionSectionBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<CommissionSection> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(bo.getTemplateId() != null, CommissionSection::getTemplateId, bo.getTemplateId());
|
||||
Page<CommissionSectionVo> page = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommissionSectionVo queryById(Integer id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertByBo(CommissionSectionBo bo) {
|
||||
// 1. 查询模板类型
|
||||
CommissionTemplate template = templateMapper.selectById(bo.getTemplateId());
|
||||
if (template == null) {
|
||||
throw new ServiceException("分成比例模板不存在");
|
||||
}
|
||||
String templateType = template.getTemplateType();
|
||||
// 2. 校验逻辑
|
||||
if ("2".equals(templateType)) {
|
||||
if (bo.getRateName() != null && !bo.getRateName().isEmpty()) {
|
||||
throw new ServiceException("类型为2的模板不能填写名称");
|
||||
}
|
||||
} else if ("1".equals(templateType)) {
|
||||
if (bo.getRateName() == null || bo.getRateName().isEmpty()) {
|
||||
throw new ServiceException("类型为1的模板必须填写名称");
|
||||
}
|
||||
}
|
||||
CommissionSection entity = cn.hutool.core.bean.BeanUtil.toBean(bo, CommissionSection.class);
|
||||
return baseMapper.insert(entity) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateByBo(CommissionSectionBo bo) {
|
||||
// 1. 查询模板类型
|
||||
CommissionTemplate template = templateMapper.selectById(bo.getTemplateId());
|
||||
if (template == null) {
|
||||
throw new ServiceException("分成比例模板不存在");
|
||||
}
|
||||
String templateType = template.getTemplateType();
|
||||
// 2. 校验逻辑
|
||||
if ("2".equals(templateType)) {
|
||||
if (bo.getRateName() != null && !bo.getRateName().isEmpty()) {
|
||||
throw new ServiceException("类型为2的模板不能填写名称");
|
||||
}
|
||||
} else if ("".equals(templateType)) {
|
||||
if (bo.getRateName() == null || bo.getRateName().isEmpty()) {
|
||||
throw new ServiceException("类型为1的模板必须填写名称");
|
||||
}
|
||||
}
|
||||
CommissionSection entity = cn.hutool.core.bean.BeanUtil.toBean(bo, CommissionSection.class);
|
||||
return baseMapper.updateById(entity) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(List<Integer> ids, Boolean isValid) {
|
||||
// 可扩展校验逻辑
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CommissionSectionVo> queryListByTemplateId(Integer templateId) {
|
||||
LambdaQueryWrapper<CommissionSection> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(CommissionSection::getTemplateId, templateId);
|
||||
List<CommissionSection> list = baseMapper.selectList(lqw);
|
||||
// 转VO
|
||||
return list.stream().map(section -> cn.hutool.core.bean.BeanUtil.toBean(section, CommissionSectionVo.class)).toList();
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
package org.dromara.system.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.system.domain.CommissionTemplate;
|
||||
import org.dromara.system.domain.bo.CommissionTemplateBo;
|
||||
import org.dromara.system.domain.vo.CommissionTemplateVo;
|
||||
import org.dromara.system.mapper.CommissionTemplateMapper;
|
||||
import org.dromara.system.service.ICommissionTemplateService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import org.dromara.system.mapper.CommissionSectionMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.dromara.system.domain.CommissionSection;
|
||||
|
||||
/**
|
||||
* 分成比例模板Service实现
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Service
|
||||
public class CommissionTemplateServiceImpl extends ServiceImpl<CommissionTemplateMapper, CommissionTemplate> implements ICommissionTemplateService {
|
||||
private final CommissionTemplateMapper baseMapper;
|
||||
|
||||
@Autowired
|
||||
private CommissionSectionMapper commissionSectionMapper;
|
||||
|
||||
@Override
|
||||
public TableDataInfo<CommissionTemplateVo> queryPageList(CommissionTemplateBo bo, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<CommissionTemplate> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.like(bo.getTemplateName() != null, CommissionTemplate::getTemplateName, bo.getTemplateName());
|
||||
lqw.eq(bo.getIsActive() != null, CommissionTemplate::getIsActive, bo.getIsActive());
|
||||
Page<CommissionTemplateVo> page = baseMapper.selectVoPage(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(page);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommissionTemplateVo queryById(Integer id) {
|
||||
return baseMapper.selectVoById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean insertByBo(CommissionTemplateBo bo) {
|
||||
CommissionTemplate entity = BeanUtil.toBean(bo, CommissionTemplate.class);
|
||||
return baseMapper.insert(entity) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean updateByBo(CommissionTemplateBo bo) {
|
||||
CommissionTemplate entity = BeanUtil.toBean(bo, CommissionTemplate.class);
|
||||
return baseMapper.updateById(entity) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean deleteWithValidByIds(List<Integer> ids, Boolean isValid) {
|
||||
// 先删除所有关联的区间
|
||||
LambdaQueryWrapper<CommissionSection> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(CommissionSection::getTemplateId, ids);
|
||||
commissionSectionMapper.delete(wrapper);
|
||||
|
||||
// 再删除模板
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package org.dromara.system.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.system.domain.SysTenantAccount;
|
||||
import org.dromara.system.domain.bo.SysTenantAccountBo;
|
||||
import org.dromara.system.mapper.SysTenantAccountMapper;
|
||||
import org.dromara.system.service.ISysTenantAccountService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class SysTenantAccountServiceImpl extends ServiceImpl<SysTenantAccountMapper,SysTenantAccount> implements ISysTenantAccountService{
|
||||
private final SysTenantAccountMapper mapper;
|
||||
|
||||
@Override
|
||||
public IPage<SysTenantAccount> pageWithTenant(Page<SysTenantAccount> page, SysTenantAccountBo bo) {
|
||||
LambdaQueryWrapper<SysTenantAccount> wrapper = buildWrapper(bo);
|
||||
return mapper.selectPage(page, wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysTenantAccount> list(SysTenantAccountBo bo) {
|
||||
LambdaQueryWrapper<SysTenantAccount> wrapper = buildWrapper(bo);
|
||||
return mapper.selectList(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysTenantAccount getById(Long id) {
|
||||
return mapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(SysTenantAccount po) {
|
||||
return mapper.insert(po) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateById(SysTenantAccount po) {
|
||||
return mapper.updateById(po) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeById(Long id) {
|
||||
return mapper.deleteById(id) > 0;
|
||||
}
|
||||
|
||||
private LambdaQueryWrapper<SysTenantAccount> buildWrapper(SysTenantAccountBo bo) {
|
||||
LambdaQueryWrapper<SysTenantAccount> wrapper = new LambdaQueryWrapper<>();
|
||||
if (bo == null) return wrapper;
|
||||
if (bo.getTenantId() != null) wrapper.eq(SysTenantAccount::getTenantId, bo.getTenantId());
|
||||
if (bo.getType() != null) wrapper.eq(SysTenantAccount::getType, bo.getType());
|
||||
// 可根据实际业务补充更多条件
|
||||
return wrapper;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user