heheng
2025-12-03 430477c7e0777531f22fc18dc8906ea75cdc21d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package com.gkhy.exam.system.service.impl;
 
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gkhy.exam.common.api.CommonPage;
import com.gkhy.exam.common.api.CommonResult;
import com.gkhy.exam.common.domain.entity.SysUser;
import com.gkhy.exam.common.utils.PageUtils;
import com.gkhy.exam.common.utils.SecurityUtils;
import com.gkhy.exam.system.domain.CourseEffectiven;
import com.gkhy.exam.system.mapper.CourseEffectivenMapper;
import com.gkhy.exam.system.mapper.SysUserMapper;
import com.gkhy.exam.system.service.CourseEffectivenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
 
 
@Service
public class CourseEffectivenServiceImpl extends ServiceImpl<CourseEffectivenMapper, CourseEffectiven> implements CourseEffectivenService {
 
    @Autowired
    private CourseEffectivenMapper courseEffectivenMapper;
 
    @Autowired
    private SysUserMapper sysUserMapper;
 
    @Override
    public CommonPage selectCourseEffectivenList(CourseEffectiven courseEffectiven) {
        if (!SecurityUtils.adminUser() && courseEffectiven.getCompanyId() == null){
            throw new RuntimeException("非管理员操作,企业查询不可为空");
        }
        PageUtils.startPage();
        List<CourseEffectiven> courseEffectivens = courseEffectivenMapper.selectEffectivenList(courseEffectiven);
        Set<Integer> allUserIds = courseEffectivens.stream()
                .map(CourseEffectiven::getStaffs)
                .filter(Objects::nonNull)
                .flatMap(staffs -> Arrays.stream(staffs.split(",")))
                .map(String::trim)
                .filter(s -> !s.isEmpty())
                .map(Integer::valueOf)
                .collect(Collectors.toSet());
 
        if (!allUserIds.isEmpty()) {
            // 批量查询用户信息
            Map<Long, String> userMap  = sysUserMapper.selectBatchIds(new ArrayList<>(allUserIds)).stream()
                    .collect(Collectors.toMap(SysUser::getId, SysUser::getName));
 
            // 设置用户姓名
            courseEffectivens.forEach(item -> {
                if (item.getStaffs() != null) {
                    String staffNames = Arrays.stream(item.getStaffs().split(","))
                            .map(String::trim)
                            .filter(s -> !s.isEmpty())
                            .map(Long::valueOf)
                            .map(userMap::get)
                            .filter(Objects::nonNull)
                            .collect(Collectors.joining(","));
                    item.setStaffsNames(staffNames);
                }
            });
        }
        return CommonPage.restPage(courseEffectivens);
    }
 
    @Override
    public CommonResult insertCourseEffectiven(CourseEffectiven courseEffectiven) {
        courseEffectiven.setCreateBy(SecurityUtils.getUsername());
        courseEffectiven.setCreateTime(LocalDateTime.now());
        int insert = courseEffectivenMapper.insert(courseEffectiven);
        if (insert>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
 
    @Override
    public CommonResult updateCourseEffectiven(CourseEffectiven courseEffectiven) {
        courseEffectiven.setUpdateBy(SecurityUtils.getUsername());
        courseEffectiven.setUpdateTime(LocalDateTime.now());
        int update = courseEffectivenMapper.updateById(courseEffectiven);
        if (update>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
 
    @Override
    public CommonResult deletedCourseEffectiven(Integer effectivenId) {
        CourseEffectiven courseEffectiven = new CourseEffectiven();
        courseEffectiven.setId(effectivenId);
        courseEffectiven.setUpdateBy(SecurityUtils.getUsername());
        courseEffectiven.setUpdateTime(LocalDateTime.now());
        courseEffectiven.setDelFlag(2);
        int update = courseEffectivenMapper.updateById(courseEffectiven);
        if (update>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }
}