|
@@ -0,0 +1,218 @@
|
|
1
|
+package com.xhkjedu.slive.service.liveplay;
|
|
2
|
+
|
|
3
|
+import com.xhkjedu.slive.mapper.gradeclass.ClassTeacherMapper;
|
|
4
|
+import com.xhkjedu.slive.mapper.gradeclass.SchoolMapper;
|
|
5
|
+import com.xhkjedu.slive.mapper.liveplay.CourseClassMapper;
|
|
6
|
+import com.xhkjedu.slive.mapper.liveplay.CourseMapper;
|
|
7
|
+import com.xhkjedu.slive.mapper.liveplay.CsMapper;
|
|
8
|
+import com.xhkjedu.slive.mapper.system.UserMapper;
|
|
9
|
+import com.xhkjedu.slive.model.gradeclass.TClass;
|
|
10
|
+import com.xhkjedu.slive.model.gradeclass.TClassTeacher;
|
|
11
|
+import com.xhkjedu.slive.model.liveplay.LCourse;
|
|
12
|
+import com.xhkjedu.slive.model.liveplay.LCourseClass;
|
|
13
|
+import com.xhkjedu.slive.model.notice.TNotice;
|
|
14
|
+import com.xhkjedu.slive.service.gradeclass.ClassService;
|
|
15
|
+import com.xhkjedu.slive.service.notice.NoticeService;
|
|
16
|
+import com.xhkjedu.slive.vo.gradeclass.ClassVo;
|
|
17
|
+import com.xhkjedu.slive.vo.liveplay.CourseParams;
|
|
18
|
+import com.xhkjedu.slive.vo.liveplay.CourseVo;
|
|
19
|
+import com.xhkjedu.utils.N_Utils;
|
|
20
|
+import com.xhkjedu.vo.ResultVo;
|
|
21
|
+import lombok.extern.slf4j.Slf4j;
|
|
22
|
+import org.springframework.beans.BeansException;
|
|
23
|
+import org.springframework.stereotype.Service;
|
|
24
|
+import org.springframework.transaction.annotation.Transactional;
|
|
25
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
26
|
+
|
|
27
|
+import javax.annotation.Resource;
|
|
28
|
+import java.util.ArrayList;
|
|
29
|
+import java.util.List;
|
|
30
|
+import java.util.Map;
|
|
31
|
+
|
|
32
|
+/**
|
|
33
|
+ * @author ywx
|
|
34
|
+ * @classname CourseService
|
|
35
|
+ * @description
|
|
36
|
+ * @date 2021/1/15 12:33
|
|
37
|
+ **/
|
|
38
|
+@Service
|
|
39
|
+@Slf4j
|
|
40
|
+public class CsService {
|
|
41
|
+ @Resource
|
|
42
|
+ private CourseMapper courseMapper;
|
|
43
|
+ @Resource
|
|
44
|
+ private ClassService classService;
|
|
45
|
+ @Resource
|
|
46
|
+ private ClassTeacherMapper classTeacherMapper;
|
|
47
|
+ @Resource
|
|
48
|
+ private NoticeService noticeService;
|
|
49
|
+ @Resource
|
|
50
|
+ private SchoolMapper schoolMapper;
|
|
51
|
+ @Resource
|
|
52
|
+ private UserMapper userMapper;
|
|
53
|
+ @Resource
|
|
54
|
+ private CourseClassMapper courseClassMapper;
|
|
55
|
+ @Resource
|
|
56
|
+ private CsMapper csMapper;
|
|
57
|
+
|
|
58
|
+ //添加
|
|
59
|
+ @Transactional(rollbackFor = Exception.class)
|
|
60
|
+ public ResultVo save(LCourse model) {
|
|
61
|
+ try {
|
|
62
|
+ List<Map> users = new ArrayList<>();
|
|
63
|
+ if (model.getCoursetype() == 1) {
|
|
64
|
+ if (N_Utils.isListEmpty(model.getClassids())) {
|
|
65
|
+ return new ResultVo(1, "班级id集合不能为空");
|
|
66
|
+ }
|
|
67
|
+ users = courseMapper.listUid(model.getClassids());//获取课程学生id集合
|
|
68
|
+ if (N_Utils.isListEmpty(users)) {
|
|
69
|
+ return new ResultVo(1, "直播班级学生为空");
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ model.setStunum(0);
|
|
73
|
+ model.setCoursestate(0);
|
|
74
|
+ model.setCreatetime(N_Utils.getSecondTimestamp());
|
|
75
|
+ String coursename = model.getCoursename();
|
|
76
|
+ Integer createid = model.getCreateid();
|
|
77
|
+ Integer schoolid = model.getSchoolid();
|
|
78
|
+ Integer teacherid = model.getTeacherid();
|
|
79
|
+ //班级信息
|
|
80
|
+ TClass c = new TClass();
|
|
81
|
+ c.setClassname(coursename + "班");
|
|
82
|
+ c.setCreateid(createid);
|
|
83
|
+ c.setSchoolid(schoolid);
|
|
84
|
+ Integer year = schoolMapper.getYearById(schoolid);
|
|
85
|
+ c.setSchoolyear(year);
|
|
86
|
+ c.setYear(year);
|
|
87
|
+ c.setClassorder(999);
|
|
88
|
+ c.setGradeid(model.getGradeid());
|
|
89
|
+
|
|
90
|
+ if (model.getCoursetype() == 1) {
|
|
91
|
+ c.setClasstype(99);//已直播班级
|
|
92
|
+ } else {
|
|
93
|
+ c.setClasstype(3);//直播班(学生选班)
|
|
94
|
+ }
|
|
95
|
+
|
|
96
|
+ Integer classid = classService.save(c);
|
|
97
|
+ if (!N_Utils.isEmptyInteger(teacherid)) {
|
|
98
|
+ //班级教师
|
|
99
|
+ TClassTeacher teacher = new TClassTeacher();
|
|
100
|
+ teacher.setClassid(classid);
|
|
101
|
+ teacher.setTeacherid(teacherid);
|
|
102
|
+ teacher.setCreateid(createid);
|
|
103
|
+ teacher.setCreatetime(N_Utils.getSecondTimestamp());
|
|
104
|
+ teacher.setSchoolid(schoolid);
|
|
105
|
+
|
|
106
|
+ classTeacherMapper.insertSelective(teacher);
|
|
107
|
+ }
|
|
108
|
+ //课程信息
|
|
109
|
+ model.setClassid(classid);
|
|
110
|
+ model.setDeleted(1);
|
|
111
|
+ model.setCourseclass(0);
|
|
112
|
+ model.setCourseschool(1);
|
|
113
|
+ courseMapper.insertUseGeneratedKeys(model);
|
|
114
|
+ List<ClassVo> classes = new ArrayList<>();
|
|
115
|
+ if (model.getCoursetype() == 1) {
|
|
116
|
+ Integer courseid = model.getId();
|
|
117
|
+ List<Integer> studentids = new ArrayList<>();
|
|
118
|
+ users.forEach(userVo -> {
|
|
119
|
+ studentids.add((Integer) userVo.get("userid"));
|
|
120
|
+ });
|
|
121
|
+
|
|
122
|
+ classService.batchSaveStu(createid, schoolid, classid, studentids);//批量添加报名学生
|
|
123
|
+ courseMapper.updateStuNum(courseid);//更新已报学生数量
|
|
124
|
+
|
|
125
|
+ //保存直播关联班级
|
|
126
|
+ List<LCourseClass> cclist = new ArrayList<>();
|
|
127
|
+ for(Integer cid : model.getClassids()){
|
|
128
|
+ LCourseClass cc = new LCourseClass();
|
|
129
|
+ cc.setCourseid(courseid);
|
|
130
|
+ cc.setClassid(cid);
|
|
131
|
+ cc.setCreateid(model.getCreateid());
|
|
132
|
+ cc.setCreatetime(N_Utils.getSecondTimestamp());
|
|
133
|
+ cclist.add(cc);
|
|
134
|
+ //通知班级
|
|
135
|
+ ClassVo classVo = new ClassVo();
|
|
136
|
+ classVo.setClassid(cid);
|
|
137
|
+ classes.add(classVo);
|
|
138
|
+ }
|
|
139
|
+ courseClassMapper.insertList(cclist);//保存原班级和直播的关联关系
|
|
140
|
+ }
|
|
141
|
+
|
|
142
|
+ //通知信息
|
|
143
|
+ StringBuffer sbcomm = new StringBuffer(); //通知消息体
|
|
144
|
+ sbcomm.append("同学你好:本次直播课程为《").append(model.getCoursename()).append("》,共有").append(model.getCoursenum());
|
|
145
|
+ sbcomm.append("节课程,每节").append(model.getDuration()).append("分钟");
|
|
146
|
+ sbcomm.append("\n开课日期:").append(model.getBegindate()).append(",");
|
|
147
|
+ sbcomm.append("上课时间:").append(model.getBegintime());
|
|
148
|
+ if (!N_Utils.isEmptyInteger(teacherid)) {
|
|
149
|
+ String teachername = userMapper.getUserNameById(model.getTeacherid());
|
|
150
|
+ sbcomm.append(",主讲教师为").append(teachername).append("。");
|
|
151
|
+ }
|
|
152
|
+ if(N_Utils.isNotEmpty(model.getComm())){
|
|
153
|
+ sbcomm.append("\n主要内容为:").append(model.getComm());
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ if(model.getCoursetype()==0){
|
|
157
|
+ String strtime = N_Utils.getStrtimeTimestamp(model.getStarttime(),"yyyy-MM-dd HH:mm");
|
|
158
|
+ String littime = N_Utils.getStrtimeTimestamp(model.getLimitstamp(),"yyyy-MM-dd HH:mm");
|
|
159
|
+ sbcomm.append("\n报名日期:").append(strtime).append("至").append(littime).append(" ");
|
|
160
|
+ sbcomm.append("\n请同学在规定时间内进行报名。");
|
|
161
|
+ }
|
|
162
|
+
|
|
163
|
+ TNotice n = new TNotice();
|
|
164
|
+ StringBuilder sb = new StringBuilder();
|
|
165
|
+ sb.append(coursename);
|
|
166
|
+ sb.append("(开课时间:");
|
|
167
|
+ sb.append(model.getBegindate()).append(" ").append(model.getBegintime());
|
|
168
|
+ sb.append(")");
|
|
169
|
+ n.setNoticetitle(sb.toString());
|
|
170
|
+ n.setNoticecontent(sbcomm.toString());
|
|
171
|
+ n.setNoticetxt(sbcomm.toString());
|
|
172
|
+ n.setNoticetype(1);
|
|
173
|
+
|
|
174
|
+ if(model.getCoursetype()==0){
|
|
175
|
+ //如果是学生选课,选择的有年级,则通知关联年级下所有班级
|
|
176
|
+ List<Integer> classids = classService.listClassidsByGradeid(model.getGradeid(),model.getSchoolid());
|
|
177
|
+ if(classids!=null && classids.size()>0){
|
|
178
|
+ for(Integer cid : classids){
|
|
179
|
+ ClassVo classVo = new ClassVo();
|
|
180
|
+ classVo.setClassid(cid);
|
|
181
|
+ classes.add(classVo);
|
|
182
|
+ }
|
|
183
|
+ }
|
|
184
|
+ }
|
|
185
|
+
|
|
186
|
+ n.setClasses(classes);
|
|
187
|
+ n.setCreateid(createid);
|
|
188
|
+ n.setCreatetime(model.getCreatetime());
|
|
189
|
+ n.setSchoolid(schoolid);
|
|
190
|
+ noticeService.save(n);
|
|
191
|
+ return new ResultVo(0, "保存成功", model.getId());
|
|
192
|
+ } catch (BeansException e) {
|
|
193
|
+ log.error("添加课程失败", e.getMessage());
|
|
194
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
195
|
+ return new ResultVo(1, "保存失败");
|
|
196
|
+ }
|
|
197
|
+ }
|
|
198
|
+
|
|
199
|
+ //获取列表
|
|
200
|
+ public List<CourseVo> listAll(LCourse course) {
|
|
201
|
+ return csMapper.listAll(course);
|
|
202
|
+ }
|
|
203
|
+
|
|
204
|
+ //课程班级
|
|
205
|
+ public List<Map> listClass(Integer courseid) {
|
|
206
|
+ return csMapper.listClass(courseid);
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ //我的月份下日期课节数量
|
|
210
|
+ public List<Map> listMySectionDate(CourseParams params) {
|
|
211
|
+ return csMapper.listMySectionDate(params);
|
|
212
|
+ }
|
|
213
|
+
|
|
214
|
+ //我的课程列表
|
|
215
|
+ public List<Map> listMySection(CourseParams params) {
|
|
216
|
+ return csMapper.listMySection(params);
|
|
217
|
+ }
|
|
218
|
+}
|