feat: 设计师大厅添加二级部门筛选功能
This commit is contained in:
parent
16726b06c4
commit
1080a49eaa
@ -25,8 +25,10 @@ public class DesignerController {
|
||||
|
||||
@Operation(summary = "获取所有设计师统计信息")
|
||||
@GetMapping("/stats")
|
||||
public Result<List<DesignerStatsVO>> getAllDesignerStats() {
|
||||
return Result.success(designerService.getAllDesignerStats());
|
||||
public Result<List<DesignerStatsVO>> getAllDesignerStats(
|
||||
@Parameter(description = "部门ID,不传则查询所有接单部门") @RequestParam(required = false) Long deptId
|
||||
) {
|
||||
return Result.success(designerService.getAllDesignerStats(deptId));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取单个设计师统计信息")
|
||||
|
||||
@ -35,29 +35,63 @@ public class DesignerService {
|
||||
* 获取所有设计师的统计信息
|
||||
*/
|
||||
public List<DesignerStatsVO> getAllDesignerStats() {
|
||||
// 仅获取接单部门(designer/receiving)的用户
|
||||
List<Long> receivingDeptIds = departmentMapper.selectList(
|
||||
new LambdaQueryWrapper<Department>()
|
||||
.eq(Department::getDeptType, "receiving")
|
||||
.eq(Department::getStatus, 1)
|
||||
).stream()
|
||||
.map(Department::getId)
|
||||
.collect(Collectors.toList());
|
||||
return getAllDesignerStats(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有设计师的统计信息(支持部门筛选)
|
||||
*/
|
||||
public List<DesignerStatsVO> getAllDesignerStats(Long deptId) {
|
||||
List<Long> targetDeptIds;
|
||||
|
||||
if (deptId != null) {
|
||||
// 如果指定了部门,获取该部门及其所有子部门
|
||||
targetDeptIds = getDeptAndChildIds(deptId);
|
||||
log.debug("筛选部门: deptId={}, targetDeptIds={}", deptId, targetDeptIds);
|
||||
} else {
|
||||
// 仅获取接单部门(designer/receiving)的用户
|
||||
targetDeptIds = departmentMapper.selectList(
|
||||
new LambdaQueryWrapper<Department>()
|
||||
.eq(Department::getDeptType, "receiving")
|
||||
.eq(Department::getStatus, 1)
|
||||
).stream()
|
||||
.map(Department::getId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
if (receivingDeptIds.isEmpty()) {
|
||||
if (targetDeptIds.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
List<User> designers = userMapper.selectList(
|
||||
new LambdaQueryWrapper<User>()
|
||||
.eq(User::getStatus, 1)
|
||||
.in(User::getDeptId, receivingDeptIds)
|
||||
.in(User::getDeptId, targetDeptIds)
|
||||
);
|
||||
|
||||
return designers.stream()
|
||||
.map(this::buildDesignerStats)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归获取部门及其所有子部门ID
|
||||
*/
|
||||
private List<Long> getDeptAndChildIds(Long deptId) {
|
||||
List<Long> deptIds = new ArrayList<>();
|
||||
deptIds.add(deptId);
|
||||
|
||||
List<Department> children = departmentMapper.selectList(
|
||||
new LambdaQueryWrapper<Department>()
|
||||
.eq(Department::getParentId, deptId)
|
||||
.eq(Department::getStatus, 1)
|
||||
);
|
||||
|
||||
for (Department child : children) {
|
||||
deptIds.addAll(getDeptAndChildIds(child.getId()));
|
||||
}
|
||||
return deptIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取单个设计师的统计信息
|
||||
|
||||
@ -26,8 +26,10 @@ export interface DesignerStats {
|
||||
/**
|
||||
* 获取所有设计师统计信息
|
||||
*/
|
||||
export const getAllDesignerStats = () => {
|
||||
return request.get<any>('/designers/stats')
|
||||
export const getAllDesignerStats = (deptId?: number) => {
|
||||
const params: any = {}
|
||||
if (deptId) params.deptId = deptId
|
||||
return request.get<any>('/designers/stats', { params })
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -111,7 +111,27 @@
|
||||
|
||||
<!-- 设计师列表 -->
|
||||
<div class="designers-section">
|
||||
<h2 class="section-title">设计师列表</h2>
|
||||
<div class="section-header">
|
||||
<h2 class="section-title">设计师列表</h2>
|
||||
<div class="filter-area">
|
||||
<a-select
|
||||
v-model:value="selectedDeptId"
|
||||
placeholder="选择部门"
|
||||
style="width: 180px"
|
||||
allowClear
|
||||
@change="handleDeptChange"
|
||||
>
|
||||
<a-select-option :value="undefined">全部部门</a-select-option>
|
||||
<a-select-option
|
||||
v-for="dept in receivingDepts"
|
||||
:key="dept.id"
|
||||
:value="dept.id"
|
||||
>
|
||||
{{ dept.deptName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-card">
|
||||
<div v-if="loading" class="loading-container">
|
||||
<a-spin size="large" />
|
||||
@ -284,9 +304,18 @@ import { message } from 'ant-design-vue'
|
||||
import DefaultLayout from '@/layouts/DefaultLayout.vue'
|
||||
import Icon from '@/components/Icon.vue'
|
||||
import * as designerApi from '@/api/designer'
|
||||
import * as departmentApi from '@/api/department'
|
||||
import type { DesignerStats } from '@/api/designer'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
// 部门类型定义
|
||||
interface Department {
|
||||
id: number
|
||||
deptName: string
|
||||
deptType: string
|
||||
parentId: number | null
|
||||
}
|
||||
|
||||
// 状态
|
||||
const loading = ref(false)
|
||||
const designersList = ref<DesignerStats[]>([])
|
||||
@ -294,6 +323,8 @@ const leaderboardData = ref<DesignerStats[]>([])
|
||||
const activeLeaderboard = ref('score')
|
||||
const selectedMonth = ref('') // 选中的月份
|
||||
const leaderboardExpanded = ref(false) // 排行榜默认折叠
|
||||
const selectedDeptId = ref<number | undefined>(undefined) // 选中的部门ID
|
||||
const receivingDepts = ref<Department[]>([]) // 接单部门列表(二级部门)
|
||||
|
||||
// 排行榜Tab配置
|
||||
const leaderboardTabs = [
|
||||
@ -384,7 +415,7 @@ const getLeaderboardLabel = () => {
|
||||
const loadDesigners = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const response = await designerApi.getAllDesignerStats()
|
||||
const response = await designerApi.getAllDesignerStats(selectedDeptId.value)
|
||||
if (response.code === 200) {
|
||||
designersList.value = response.data || []
|
||||
}
|
||||
@ -396,6 +427,26 @@ const loadDesigners = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// 加载接单部门列表(二级部门)
|
||||
const loadReceivingDepts = async () => {
|
||||
try {
|
||||
const response = await departmentApi.getDepartments()
|
||||
if (response.code === 200 && response.data) {
|
||||
// 只获取接单类型的二级部门(parent_id 不为空且 dept_type 为 receiving)
|
||||
receivingDepts.value = response.data.filter((dept: Department) =>
|
||||
dept.deptType === 'receiving' && dept.parentId !== null
|
||||
)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载部门列表失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
// 部门筛选变更
|
||||
const handleDeptChange = () => {
|
||||
loadDesigners()
|
||||
}
|
||||
|
||||
// 加载排行榜数据
|
||||
const loadLeaderboard = async (type: string, month?: string) => {
|
||||
try {
|
||||
@ -443,6 +494,7 @@ const loadDesignerTasks = async (designer: DesignerStats) => {
|
||||
onMounted(() => {
|
||||
// 设置默认选中当前月份
|
||||
selectedMonth.value = dayjs().format('YYYY-MM')
|
||||
loadReceivingDepts() // 加载部门列表
|
||||
loadDesigners()
|
||||
loadLeaderboard('score')
|
||||
})
|
||||
@ -699,6 +751,23 @@ onMounted(() => {
|
||||
// 设计师列表
|
||||
.designers-section {
|
||||
margin-top: $space-xxxl;
|
||||
|
||||
.section-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: $space-lg;
|
||||
|
||||
.section-title {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.filter-area {
|
||||
display: flex;
|
||||
gap: $space-md;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.section-title {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user