feat: 团队订单与管理端订单代码重构、合并

This commit is contained in:
yys 2026-04-23 17:16:57 +08:00
parent e1733e3f47
commit 24f518acd1
8 changed files with 264 additions and 55 deletions

View File

@ -16,6 +16,16 @@
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="团队" prop="deptId">
<treeselect
v-model="queryParams.deptId"
:options="deptOptions"
:normalizer="deptNormalizer"
placeholder="全部"
clearable
style="width: 220px"
/>
</el-form-item>
<el-form-item label="操作类型" prop="type">
<el-select
v-model="queryParams.type"
@ -62,6 +72,7 @@
<el-table-column label="主键ID" align="center" prop="id" width="80"/>
<el-table-column label="用户ID" align="center" prop="uuid" width="100" show-overflow-tooltip />
<el-table-column label="用户昵称" align="center" prop="nickname" width="150" show-overflow-tooltip />
<el-table-column label="团队名称" align="center" prop="deptName" width="120" show-overflow-tooltip />
<el-table-column label="关联订单号" align="center" prop="orderNo" width="180" show-overflow-tooltip />
<el-table-column label="操作类型" align="center" width="100" prop="type" :formatter="formatType" />
<el-table-column
@ -140,9 +151,13 @@ import {
addRecord,
updateRecord
} from "@/api/ai/balanceChangeRecord";
import { listDept } from "@/api/ai/dept";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
name: "Record",
components: { Treeselect },
data() {
return {
//
@ -182,13 +197,15 @@ export default {
title: "",
//
open: false,
deptOptions: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
type: null,
uuid: null,
userId: null
userId: null,
deptId: null
},
//
form: {},
@ -201,9 +218,25 @@ export default {
};
},
created() {
this.loadDeptTree();
this.getList();
},
methods: {
loadDeptTree() {
listDept().then(res => {
this.deptOptions = this.handleTree(res.data, "deptId");
});
},
deptNormalizer(node) {
if (node.children && !node.children.length) {
delete node.children;
}
return {
id: node.deptId,
label: node.deptName,
children: node.children
};
},
/** 西式千分位en-US积分为整数 */
formatPointsWestern(value) {
if (value === null || value === undefined || value === "") {

View File

@ -1,11 +1,36 @@
<template>
<div class="app-container">
<el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true">
<el-form-item label="用户ID" prop="userId">
<el-input v-model="queryParams.userId" clearable @keyup.enter.native="handleQuery" />
<el-form
:model="queryParams"
ref="queryForm"
size="small"
:inline="true"
v-show="showSearch"
label-width="68px"
>
<el-form-item label="用户ID" prop="uuid">
<el-input
v-model="queryParams.uuid"
placeholder="请输入用户ID"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="类型" prop="type">
<el-input v-model="queryParams.type" clearable placeholder="类型码" @keyup.enter.native="handleQuery" />
<el-form-item label="操作类型" prop="type">
<el-select
v-model="queryParams.type"
placeholder="请选择操作类型"
filterable
clearable
style="width: 200px; margin-bottom: 16px;"
>
<el-option
v-for="(label, value) in typeMap"
:key="value"
:label="label"
:value="Number(value)"
/>
</el-select>
</el-form-item>
<el-form-item label="创建时间">
<el-date-picker
@ -21,52 +46,144 @@
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['subteam:userBalance:export']"
>导出</el-button>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
</el-form-item>
</el-form>
<el-row class="mb8"><right-toolbar :show-search.sync="showSearch" @queryTable="getList" /></el-row>
<el-table v-loading="loading" :data="list">
<el-table-column label="ID" prop="id" width="80" />
<el-table-column label="用户ID" prop="userId" width="90" />
<el-table-column label="账号" prop="nickname" min-width="100" />
<el-table-column label="类型" prop="type" width="80" />
<el-table-column label="变更" prop="changeAmount" width="100" />
<el-table-column label="余额" prop="resultAmount" width="100" />
<el-table-column label="时间" width="160"><template slot-scope="s">{{ parseTime(s.row.createTime) }}</template></el-table-column>
<el-table v-loading="loading" :data="recordList">
<el-table-column label="主键ID" align="center" prop="id" width="80" />
<el-table-column label="用户ID" align="center" prop="uuid" width="100" show-overflow-tooltip />
<el-table-column label="用户昵称" align="center" prop="nickname" width="150" show-overflow-tooltip />
<el-table-column label="关联订单号" align="center" prop="orderNo" width="180" show-overflow-tooltip />
<el-table-column label="操作类型" align="center" width="100" prop="type" :formatter="formatType" />
<el-table-column
label="变更积分"
align="center"
prop="changeAmount"
:formatter="formatChangeAmount"
width="120"
/>
<el-table-column
label="变更后积分"
align="center"
prop="resultAmount"
:formatter="formatResultAmount"
width="120"
/>
<el-table-column label="操作时间" align="center" prop="createTime" width="150" />
<el-table-column label="备注" align="center" prop="remark" />
</el-table>
<pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</div>
</template>
<script>
import { listSubteamUserBalance } from '@/api/subteam'
import { listSubteamUserBalance, subteamUserBalanceExportUrl } from "@/api/subteam";
export default {
name: 'SubteamUserBalance',
name: "SubteamUserBalance",
data() {
return {
dateRange: [],
typeMap: {
9: "快捷生视频",
11: "系统操作",
12: "团队下发",
13: "团队收回"
},
loading: true,
showSearch: true,
dateRange: [],
list: [],
total: 0,
queryParams: { pageNum: 1, pageSize: 10, userId: undefined, type: undefined }
recordList: [],
queryParams: {
pageNum: 1,
pageSize: 10,
type: null,
uuid: null
}
};
},
created() {
this.getList();
},
created() { this.getList() },
methods: {
getList() {
this.loading = true
listSubteamUserBalance(this.addDateRange(this.queryParams, this.dateRange, 'CreateTime')).then(res => {
this.list = res.rows
this.total = res.total
this.loading = false
})
formatPointsWestern(value) {
if (value === null || value === undefined || value === "") {
return "";
}
const n = Number(value);
if (Number.isNaN(n)) {
return String(value);
}
return n.toLocaleString("en-US", { maximumFractionDigits: 0 });
},
formatChangeAmount(row) {
const value = row.changeAmount;
if (value === null || value === undefined || value === "") {
return "";
}
const n = Number(value);
if (Number.isNaN(n)) {
return String(value);
}
const formatted = Math.abs(n).toLocaleString("en-US", {
maximumFractionDigits: 0
});
if (n > 0) {
return `+${formatted}`;
}
if (n < 0) {
return `-${formatted}`;
}
return "0";
},
formatResultAmount(row) {
return this.formatPointsWestern(row.resultAmount);
},
formatType(row) {
return this.typeMap[row.type] || "未知";
},
getList() {
this.loading = true;
listSubteamUserBalance(
this.addDateRange(this.queryParams, this.dateRange)
).then(response => {
this.recordList = response.rows;
this.total = response.total;
this.loading = false;
});
},
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
handleQuery() { this.queryParams.pageNum = 1; this.getList() },
resetQuery() {
this.dateRange = []
this.resetForm('queryForm')
this.handleQuery()
}
this.dateRange = [];
this.resetForm("queryForm");
this.handleQuery();
},
handleExport() {
this.download(
subteamUserBalanceExportUrl,
this.addDateRange({ ...this.queryParams }, this.dateRange),
`user_balance_${new Date().getTime()}.xlsx`
);
}
}
};
</script>

View File

@ -1,17 +1,24 @@
package com.ruoyi.web.controller.subteam;
import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.ai.domain.AiBalanceChangeRecord;
import com.ruoyi.ai.domain.vo.AiBalanceChangeRecordListVo;
import com.ruoyi.ai.service.IAiBalanceChangeRecordService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.subteam.ISubteamDataQueryService;
import com.ruoyi.system.service.subteam.ISubteamScopeService;
@ -31,15 +38,54 @@ public class SubteamUserBalanceController extends BaseController {
@PreAuthorize("@ss.hasPermi('subteam:userBalance:list')")
@GetMapping("/list")
public TableDataInfo list(AiBalanceChangeRecord query) {
clearCrossTeamQueryFields(query);
startPage();
List<AiBalanceChangeRecord> list = subteamDataQueryService.selectUserBalanceRecords(query);
return getDataTable(list);
List<AiBalanceChangeRecordListVo> rows = list.stream()
.map(AiBalanceChangeRecordListVo::from)
.peek(v -> v.setDeptName(null))
.collect(Collectors.toList());
TableDataInfo rsp = getDataTable(list);
rsp.setRows(rows);
return rsp;
}
/**
* 与本团队 /ai/balance-change-record 导出同结构不导出团队名称本端仅看本团队
* 复用 {@link ISubteamDataQueryService#selectUserBalanceRecords} {@link com.ruoyi.ai.mapper.AiBalanceChangeRecordMapper}
*/
@PreAuthorize("@ss.hasPermi('subteam:userBalance:export')")
@Log(title = "用户积分变动", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, AiBalanceChangeRecord query) {
clearCrossTeamQueryFields(query);
List<AiBalanceChangeRecord> list = subteamDataQueryService.selectUserBalanceRecords(query);
List<AiBalanceChangeRecordListVo> rows = list.stream()
.map(AiBalanceChangeRecordListVo::from)
.collect(Collectors.toList());
ExcelUtil<AiBalanceChangeRecordListVo> util = new ExcelUtil<>(AiBalanceChangeRecordListVo.class);
util.hideColumn("deptName");
util.exportExcel(response, rows, "用户积分变动");
}
@PreAuthorize("@ss.hasPermi('subteam:userBalance:query')")
@GetMapping("/{id}")
public AjaxResult getInfo(@PathVariable Long id) {
subteamScopeService.assertAiBalanceRecordVisible(id, subteamScopeService.currentTeamDeptId());
return success(aiBalanceChangeRecordService.selectAiBalanceChangeRecordById(id));
AiBalanceChangeRecord record = aiBalanceChangeRecordService.selectAiBalanceChangeRecordById(id);
AiBalanceChangeRecordListVo vo = AiBalanceChangeRecordListVo.from(record);
if (vo != null) {
vo.setDeptName(null);
}
return success(vo);
}
/** 忽略入参中的团队条件,仅数据范围以当前团队为准 */
private void clearCrossTeamQueryFields(AiBalanceChangeRecord query) {
if (query == null) {
return;
}
query.setDeptId(null);
query.setDeptName(null);
}
}

View File

@ -69,4 +69,16 @@ public class AiBalanceChangeRecord extends BaseEntity {
@TableField(exist = false)
private String nickname;
/**
* 用户归属团队ai_user.dept_id用于筛选
*/
@TableField(exist = false)
private Long deptId;
/**
* 团队名称关联 sys_dept.dept_name
*/
@TableField(exist = false)
private String deptName;
}

View File

@ -27,23 +27,26 @@ public class AiBalanceChangeRecordListVo implements Serializable {
@Excel(name = "用户昵称", sort = 3)
private String nickname;
@Excel(name = "关联订单号", sort = 4)
@Excel(name = "团队名称", sort = 4)
private String deptName;
@Excel(name = "关联订单号", sort = 5)
private String orderNo;
@Excel(name = "操作类型", sort = 5, readConverterExp = "0=充值,1=返佣,2=充值赠送,3=体验金赠送,4=体验金回收,5=一键换衣,6=图生图2,7=一键换脸,8=快捷生图,9=快捷生视频,10=退款,11=系统操作,12=团队下发,13=团队收回")
@Excel(name = "操作类型", sort = 6, readConverterExp = "0=充值,1=返佣,2=充值赠送,3=体验金赠送,4=体验金回收,5=一键换衣,6=图生图2,7=一键换脸,8=快捷生图,9=快捷生视频,10=退款,11=系统操作,12=团队下发,13=团队收回")
private Integer type;
@Excel(name = "变更积分", sort = 6, handler = BalanceChangeAmountExcelHandler.class)
@Excel(name = "变更积分", sort = 7, handler = BalanceChangeAmountExcelHandler.class)
private BigDecimal changeAmount;
@Excel(name = "变更后积分", sort = 7)
@Excel(name = "变更后积分", sort = 8)
private BigDecimal resultAmount;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "操作时间", sort = 8, width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
@Excel(name = "操作时间", sort = 9, width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
private Date createTime;
@Excel(name = "备注", sort = 9)
@Excel(name = "备注", sort = 10)
private String remark;
public static AiBalanceChangeRecordListVo from(AiBalanceChangeRecord e) {
@ -54,6 +57,7 @@ public class AiBalanceChangeRecordListVo implements Serializable {
v.setId(e.getId());
v.setUuid(e.getUuid());
v.setNickname(e.getNickname());
v.setDeptName(e.getDeptName());
v.setOrderNo(e.getOrderNo());
v.setType(e.getType());
v.setChangeAmount(e.getChangeAmount());

View File

@ -73,9 +73,8 @@ public class DeptUserScoreTransferTxService {
}
String orderNum = buildOrderNum();
String remark = buildRemark(request.getRemark(), "用户积分回收至团队");
aiUserService.addUserBalance(orderNum, user.getId(), amount.negate(), BalanceChangerConstants.DEPT_SCORE_RECLAIM, remark);
aiUserService.addUserBalance(orderNum, user.getId(), amount.negate(), BalanceChangerConstants.DEPT_SCORE_RECLAIM, request.getRemark());
int rows = deptService.addDeptBalance(deptId, amount);
if (rows == 0) {
@ -83,7 +82,7 @@ public class DeptUserScoreTransferTxService {
}
BigDecimal deptBalAfter = getDeptBalance(deptId);
insertGroupRecord(orderNum, deptId, GroupBalanceChangeType.RECLAIM.getCode(), amount, deptBalAfter, remark);
insertGroupRecord(orderNum, deptId, GroupBalanceChangeType.RECLAIM.getCode(), amount, deptBalAfter, request.getRemark());
}
private AiUser requireUserWithDept(Long id) {
@ -108,13 +107,6 @@ public class DeptUserScoreTransferTxService {
return BigDecimal.valueOf(amount);
}
private String buildRemark(String input, String defaultPrefix) {
if (StringUtils.isNotEmpty(input)) {
return input;
}
return defaultPrefix;
}
private BigDecimal getDeptBalance(Long deptId) {
SysDept dept = deptService.selectDeptById(deptId);
if (dept == null) {

View File

@ -19,20 +19,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="resultAmount" column="result_amount" />
<result property="nickname" column="nickname" />
<result property="uuid" column="uuid" />
<result property="deptName" column="dept_name" />
</resultMap>
<sql id="selectAiBalanceChangeRecordVo">
select r.id, r.del_flag, r.create_by, r.create_time, r.update_by, r.update_time, r.remark, r.order_no, r.user_id, r.type, r.change_amount, r.result_amount, u.nickname, u.user_id uuid from ai_balance_change_record r
select r.id, r.del_flag, r.create_by, r.create_time, r.update_by, r.update_time, r.remark, r.order_no, r.user_id, r.type, r.change_amount, r.result_amount, u.nickname, u.user_id uuid, d.dept_name from ai_balance_change_record r
left join ai_user u on u.id = r.user_id
left join sys_dept d on d.dept_id = u.dept_id and d.del_flag = '0'
</sql>
<select id="selectAiBalanceChangeRecordList" parameterType="AiBalanceChangeRecord" resultMap="AiBalanceChangeRecordResult">
<include refid="selectAiBalanceChangeRecordVo"/>
<where>
<if test="nickname != null and nickname != '' "> and u.nickname like concat('%', #{nickname}, '%') </if>
<if test="deptId != null "> and u.dept_id = #{deptId}</if>
<if test="userId != null "> and r.user_id = #{userId}</if>
<if test="uuid != null "> and u.user_id = #{uuid}</if>
<if test="type != null "> and type = #{type}</if>
<if test="type != null "> and r.type = #{type}</if>
<if test="changeAmount != null "> and change_amount = #{changeAmount}</if>
<if test="resultAmount != null "> and result_amount = #{resultAmount}</if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->

View File

@ -90,6 +90,8 @@ values('用户余额变动', @subteamRoot, '5', 'user-balance', 'subteam/userBal
SELECT @m4 := LAST_INSERT_ID();
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('余额变动查询', @m4, '1', '#', '', 1, 0, 'F', '0', '0', 'subteam:userBalance:query', '#', 'admin', sysdate(), '', null, '');
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
values('用户余额变动导出', @m4, '2', '#', '', 1, 0, 'F', '0', '0', 'subteam:userBalance:export', '#', 'admin', sysdate(), '', null, '与 subteam:userBalance:list 同页');
-- 团队消耗统计
insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, is_cache, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)