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();
|
}
|
}
|