CourseDictServiceImpl.java
5.75 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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.subsidy.common.exception.HttpException;
import com.subsidy.dto.course.QueryCoursesDTO;
import com.subsidy.mapper.AdministerMapper;
import com.subsidy.mapper.CompanyDictMapper;
import com.subsidy.mapper.RoleAdministerMappingMapper;
import com.subsidy.model.AdministerDO;
import com.subsidy.model.CompanyDictDO;
import com.subsidy.model.CourseDictDO;
import com.subsidy.mapper.CourseDictMapper;
import com.subsidy.model.RoleAdministerMappingDO;
import com.subsidy.service.CompanyDictService;
import com.subsidy.service.CourseDictService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* <p>
* 服务实现类
* </p>
*
* @author DengMin
* @since 2021-10-11
*/
@Service
public class CourseDictServiceImpl extends ServiceImpl<CourseDictMapper, CourseDictDO> implements CourseDictService {
@Autowired
private RoleAdministerMappingMapper roleAdministerMappingMapper;
@Autowired
private AdministerMapper administerMapper;
@Autowired
private CompanyDictMapper companyDictMapper;
public String addCourse(CourseDictDO courseDictDO) {
int count = 0;
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 = 0;
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());
////判断角色
//List<RoleAdministerMappingDO> roleAdministerMappingDOS = roleAdministerMappingMapper.selectList(new QueryWrapper<RoleAdministerMappingDO>()
//.lambda()
//.eq(RoleAdministerMappingDO::getAdministerId,roleAdministerMappingMapper));
//
//Boolean flag = false;
//for (RoleAdministerMappingDO roleAdministerMappingDO : roleAdministerMappingDOS){
//
// if (roleAdministerMappingDO.getRoleId() ==3){
// flag= false;
// }else if(roleAdministerMappingDO.getRoleId()==2) {
// flag = true;
// }
//}
//List<Long> longs = new ArrayList<>();
//if (flag){
// //运营者账号 该企业下的所有课程 管理员
// //获取该企业下所有老师的课程
// AdministerDO administerDO = administerMapper.selectById(queryCoursesDTO.getAdministerId());
//
// List<AdministerDO> administerDOS = administerMapper.selectList(new QueryWrapper<AdministerDO>()
// .lambda()
// .eq(AdministerDO::getCompanyId,administerDO.getCompanyId()));
// for (AdministerDO administerDO1 : administerDOS){
// longs.add(administerDO1.getId());
// }
return this.baseMapper.queryCompanyCourse(pager, queryCoursesDTO.getCourseName(), queryCoursesDTO.getCategoryId(), queryCoursesDTO.getCourseType(), queryCoursesDTO.getCourseSource(), queryCoursesDTO.getCompanyId());
//}
}
}