CourseDictServiceImpl.java
4.16 KB
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
104
105
106
107
108
109
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.course.QueryCoursesDTO;
import com.subsidy.mapper.CourseDictMapper;
import com.subsidy.mapper.RoleAdministerMappingMapper;
import com.subsidy.model.CourseDictDO;
import com.subsidy.model.RoleAdministerMappingDO;
import com.subsidy.service.CourseDictService;
import com.subsidy.util.ConstantUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
/**
* <p>
* 服务实现类
* </p>
*
* @author DengMin
* @since 2021-10-11
*/
@Service
public class CourseDictServiceImpl extends ServiceImpl<CourseDictMapper, CourseDictDO> implements CourseDictService {
@Autowired
private RoleAdministerMappingMapper roleAdministerMappingMapper;
public String addCourse(CourseDictDO courseDictDO) {
int count;
if (null != courseDictDO.getCompanyId()) {
count = this.baseMapper.selectCount(new QueryWrapper<CourseDictDO>()
.lambda()
.eq(CourseDictDO::getCourseName, courseDictDO.getCourseName())
.isNull(CourseDictDO::getCompanyId));
} else {
count = this.baseMapper.selectCount(new QueryWrapper<CourseDictDO>()
.lambda()
.eq(CourseDictDO::getCourseName, courseDictDO.getCourseName())
.eq(CourseDictDO::getCompanyId, courseDictDO.getCompanyId()));
}
if (count > 0) {
throw new HttpException(20001);
}
this.baseMapper.insert(courseDictDO);
return ConstantUtils.ADD_SUCCESS;
}
public String deleteCourse(CourseDictDO courseDictDO) {
this.baseMapper.deleteById(courseDictDO.getId());
return ConstantUtils.DELETE_SUCCESS;
}
public IPage queryCourses(QueryCoursesDTO queryCoursesDTO) {
Page pager = new Page(queryCoursesDTO.getPageNum(), queryCoursesDTO.getPageSize());
//判断当前用户是运营者还是企业者
Integer count = roleAdministerMappingMapper.selectCount(new QueryWrapper<RoleAdministerMappingDO>()
.lambda()
.eq(RoleAdministerMappingDO::getAdministerId,queryCoursesDTO.getAdministerId())
.eq(RoleAdministerMappingDO::getRoleId,1));
if (count > 0){
//后台管理员
queryCoursesDTO.setCompanyId(null);
}
return this.baseMapper.queryCourses(pager, queryCoursesDTO.getCourseName(), queryCoursesDTO.getCategoryId(), queryCoursesDTO.getCourseType(), queryCoursesDTO.getCourseSource(), queryCoursesDTO.getCompanyId());
}
public String updateCourses(CourseDictDO courseDictDO) {
int count;
if (null != courseDictDO.getCompanyId()) {
count = this.baseMapper.selectCount(new QueryWrapper<CourseDictDO>()
.lambda()
.eq(CourseDictDO::getCourseName, courseDictDO.getCourseName())
.ne(CourseDictDO::getId, courseDictDO.getCompanyId()));
} else {
count = this.baseMapper.selectCount(new QueryWrapper<CourseDictDO>()
.lambda()
.eq(CourseDictDO::getCourseName, courseDictDO.getCourseName())
.isNull(CourseDictDO::getCompanyId));
}
if (count > 0) {
throw new HttpException(20001);
}
this.baseMapper.updateById(courseDictDO);
return ConstantUtils.DELETE_SUCCESS;
}
public IPage queryCompanyCourse(QueryCoursesDTO queryCoursesDTO) {
Page pager = new Page(queryCoursesDTO.getPageNum(), queryCoursesDTO.getPageSize());
return this.baseMapper.queryCompanyCourse(pager, queryCoursesDTO.getCourseName(), queryCoursesDTO.getCategoryId(), queryCoursesDTO.getCourseType(), queryCoursesDTO.getCourseSource(), queryCoursesDTO.getCompanyId());
}
}