|
@@ -14,10 +14,13 @@ import com.xhkjedu.sstudy.vo.paper.AnalyzeSearchVo;
|
14
|
14
|
import com.xhkjedu.sstudy.vo.resource.GuideAnalyzeVo;
|
15
|
15
|
import com.xhkjedu.sstudy.vo.resource.GuideVo;
|
16
|
16
|
import com.xhkjedu.utils.N_Utils;
|
|
17
|
+import com.xhkjedu.vo.ResultVo;
|
|
18
|
+import lombok.extern.slf4j.Slf4j;
|
17
|
19
|
import org.apache.commons.lang3.StringUtils;
|
18
|
20
|
import org.springframework.beans.factory.annotation.Autowired;
|
19
|
21
|
import org.springframework.stereotype.Service;
|
20
|
22
|
import org.springframework.transaction.annotation.Transactional;
|
|
23
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
21
|
24
|
|
22
|
25
|
import javax.annotation.Resource;
|
23
|
26
|
import java.util.*;
|
|
@@ -30,6 +33,7 @@ import java.util.stream.Collectors;
|
30
|
33
|
* Date 2021/10/20 10:37
|
31
|
34
|
**/
|
32
|
35
|
@Service
|
|
36
|
+@Slf4j
|
33
|
37
|
public class GuideService {
|
34
|
38
|
@Resource
|
35
|
39
|
private GuideMapper guideMapper;
|
|
@@ -90,76 +94,93 @@ public class GuideService {
|
90
|
94
|
}
|
91
|
95
|
|
92
|
96
|
//保存学生预习
|
93
|
|
- @Transactional
|
94
|
|
- public Integer save(TGuide guide){
|
95
|
|
- Integer timestamp = N_Utils.getSecondTimestamp();
|
96
|
|
- guide.setCreatetime(timestamp);
|
97
|
|
- guideMapper.insertUseGeneratedKeys(guide);
|
98
|
|
- Integer guideid = guide.getId();//预习id
|
99
|
|
- guide.setGuideid(guideid);
|
100
|
|
-
|
101
|
|
- //保存资源
|
102
|
|
- List<TResource> resources = guide.getResources();
|
103
|
|
- for(TResource r : resources) {
|
104
|
|
- r.setCreateid(guide.getCreateid());
|
105
|
|
- r.setCreatetime(guide.getCreatetime());
|
106
|
|
- r.setLevel(3);
|
107
|
|
- r.setResourcestate(1);
|
108
|
|
- r.setResourcetype(10);
|
109
|
|
- r.setBelong(4);
|
110
|
|
- r.setSchoolid(guide.getSchoolid());
|
111
|
|
- r.setSubjectid(guide.getSubjectid());
|
112
|
|
-
|
113
|
|
- String resourceid = StudyUtil.getId();//资源id
|
114
|
|
- r.setResourceid(resourceid);
|
115
|
|
- Integer resourceclass = r.getResourceclass();
|
116
|
|
- if (resourceclass == 3 || resourceclass == 4 || resourceclass == 6) {
|
117
|
|
- r.setConverted(1);
|
118
|
|
- } else if (resourceclass == 5 && (r.getSuffix().equals("flv") || r.getMp4code().equals("h264"))) {
|
119
|
|
- r.setConverted(1);
|
|
97
|
+ @Transactional(rollbackFor = Exception.class)
|
|
98
|
+ public ResultVo save(TGuide guide){
|
|
99
|
+
|
|
100
|
+ try {
|
|
101
|
+ Integer timestamp = N_Utils.getSecondTimestamp();
|
|
102
|
+ guide.setCreatetime(timestamp);
|
|
103
|
+ guideMapper.insertUseGeneratedKeys(guide);
|
|
104
|
+ Integer guideid = guide.getId();//预习id
|
|
105
|
+ guide.setGuideid(guideid);
|
|
106
|
+
|
|
107
|
+ //保存资源
|
|
108
|
+ List<TResource> resources = guide.getResources();
|
|
109
|
+ for(TResource r : resources) {
|
|
110
|
+ r.setCreateid(guide.getCreateid());
|
|
111
|
+ r.setCreatetime(guide.getCreatetime());
|
|
112
|
+ r.setLevel(3);
|
|
113
|
+ r.setResourcestate(1);
|
|
114
|
+ r.setResourcetype(10);
|
|
115
|
+ r.setBelong(4);
|
|
116
|
+ r.setSchoolid(guide.getSchoolid());
|
|
117
|
+ r.setSubjectid(guide.getSubjectid());
|
|
118
|
+
|
|
119
|
+ String resourceid = StudyUtil.getId();//资源id
|
|
120
|
+ r.setResourceid(resourceid);
|
|
121
|
+ Integer resourceclass = r.getResourceclass();
|
|
122
|
+ if (resourceclass == 3 || resourceclass == 4 || resourceclass == 6) {
|
|
123
|
+ r.setConverted(1);
|
|
124
|
+ } else if (resourceclass == 5 && (r.getSuffix().equals("flv") || r.getMp4code().equals("h264"))) {
|
|
125
|
+ r.setConverted(1);
|
|
126
|
+ }
|
|
127
|
+ //保存资源信息
|
|
128
|
+ resourceMapper.insertSelective(r);
|
|
129
|
+ //保存预习资源关联关系
|
|
130
|
+ TGuideResource gr = new TGuideResource();
|
|
131
|
+ gr.setGuideid(guideid);
|
|
132
|
+ gr.setResourceid(resourceid);
|
|
133
|
+ gr.setCreateid(guide.getCreateid());
|
|
134
|
+ gr.setCreatetime(guide.getCreatetime());
|
|
135
|
+ guideResourceMapper.insertUseGeneratedKeys(gr);
|
|
136
|
+
|
|
137
|
+ convertUtil.convertResource(r);//资源转换(word或ppt转为pdf,视频非h264编码转码,压缩包解压)
|
120
|
138
|
}
|
121
|
|
- //保存资源信息
|
122
|
|
- resourceMapper.insertSelective(r);
|
123
|
|
- //保存预习资源关联关系
|
124
|
|
- TGuideResource gr = new TGuideResource();
|
125
|
|
- gr.setGuideid(guideid);
|
126
|
|
- gr.setResourceid(resourceid);
|
127
|
|
- gr.setCreateid(guide.getCreateid());
|
128
|
|
- gr.setCreatetime(guide.getCreatetime());
|
129
|
|
- guideResourceMapper.insertUseGeneratedKeys(gr);
|
130
|
|
-
|
131
|
|
- convertUtil.convertResource(r);//资源转换(word或ppt转为pdf,视频非h264编码转码,压缩包解压)
|
|
139
|
+
|
|
140
|
+ //保存预习学生关联信息
|
|
141
|
+ batchSaveGuideStudent(guide);
|
|
142
|
+ return new ResultVo(0,"保存成功");
|
|
143
|
+ }catch (Exception e){
|
|
144
|
+ log.error("保存预习失败:" + e.getMessage());
|
|
145
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
146
|
+ return new ResultVo(1,"保存失败");
|
132
|
147
|
}
|
133
|
148
|
|
134
|
|
- //保存预习学生关联信息
|
135
|
|
- batchSaveGuideStudent(guide);
|
136
|
|
- return guideid;
|
137
|
149
|
}
|
138
|
150
|
|
139
|
151
|
//个人空间分享到学生预习
|
140
|
|
- @Transactional
|
141
|
|
- public void shareGuide(TGuide guide) {
|
142
|
|
- String resourceid = guide.getResourceid();
|
143
|
|
- Integer timestamp = N_Utils.getSecondTimestamp();
|
144
|
|
- guide.setCreatetime(timestamp);
|
145
|
|
- guideMapper.insertUseGeneratedKeys(guide);
|
146
|
|
- Integer guideid = guide.getId();//预习id
|
147
|
|
-
|
148
|
|
- //保存预习资源
|
149
|
|
- TGuideResource guideResource = new TGuideResource();
|
150
|
|
- guideResource.setGuideid(guideid);
|
151
|
|
- guideResource.setResourceid(resourceid);
|
152
|
|
- guideResource.setCreateid(guide.getCreateid());
|
153
|
|
- guideResource.setCreatetime(timestamp);
|
154
|
|
- guideResourceMapper.insert(guideResource);
|
155
|
|
- guide.setGuideid(guideid);
|
156
|
|
-
|
157
|
|
- //保存预习学生关联信息
|
158
|
|
- batchSaveGuideStudent(guide);
|
|
152
|
+ @Transactional(rollbackFor = Exception.class)
|
|
153
|
+ public ResultVo shareGuide(TGuide guide){
|
|
154
|
+
|
|
155
|
+ try {
|
|
156
|
+ String resourceid = guide.getResourceid();
|
|
157
|
+ Integer timestamp = N_Utils.getSecondTimestamp();
|
|
158
|
+ guide.setCreatetime(timestamp);
|
|
159
|
+ guideMapper.insertUseGeneratedKeys(guide);
|
|
160
|
+ Integer guideid = guide.getId();//预习id
|
|
161
|
+
|
|
162
|
+ //保存预习资源
|
|
163
|
+ TGuideResource guideResource = new TGuideResource();
|
|
164
|
+ guideResource.setGuideid(guideid);
|
|
165
|
+ guideResource.setResourceid(resourceid);
|
|
166
|
+ guideResource.setCreateid(guide.getCreateid());
|
|
167
|
+ guideResource.setCreatetime(timestamp);
|
|
168
|
+ guideResourceMapper.insert(guideResource);
|
|
169
|
+ guide.setGuideid(guideid);
|
|
170
|
+
|
|
171
|
+ //保存预习学生关联信息
|
|
172
|
+ batchSaveGuideStudent(guide);
|
|
173
|
+ return new ResultVo(0,"分享成功");
|
|
174
|
+ }catch (Exception e){
|
|
175
|
+ log.error("分享预习失败:" + e.getMessage());
|
|
176
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
177
|
+ return new ResultVo(1,"分享失败");
|
|
178
|
+ }
|
|
179
|
+
|
159
|
180
|
}
|
160
|
181
|
|
161
|
182
|
//批量维护预习班级和学生信息
|
162
|
|
- private void batchSaveGuideStudent(TGuide guide) {
|
|
183
|
+ private void batchSaveGuideStudent(TGuide guide) throws Exception {
|
163
|
184
|
List<TGuideGroup> guideGroups = guide.getGuideGroups().stream().distinct().collect(Collectors.toList());
|
164
|
185
|
List<TGuideGroup> savegroup = new ArrayList<>();
|
165
|
186
|
List<TGuideGroupStudent> savestus = new ArrayList<>();
|
|
@@ -172,23 +193,29 @@ public class GuideService {
|
172
|
193
|
g.setCreatetime(guide.getCreatetime());
|
173
|
194
|
savegroup.add(g);
|
174
|
195
|
|
175
|
|
- //页面选择的学生预习学生集合
|
176
|
|
- String groupids = StringUtils.join(gg.getGroups(),",");
|
177
|
|
-
|
178
|
|
- //获取选中班级分组下所有学生
|
179
|
|
- List<Integer> stus = classMapper.listStudentidsByGroupids(groupids);
|
180
|
|
- for (Integer studentid : stus) {
|
181
|
|
- TGuideGroupStudent ggs = new TGuideGroupStudent();
|
182
|
|
- ggs.setGuideid(guide.getGuideid());
|
183
|
|
- ggs.setClassid(classid);
|
184
|
|
- ggs.setStudentid(studentid);
|
185
|
|
- ggs.setCosttime(0);
|
186
|
|
- ggs.setCreatetime(N_Utils.getSecondTimestamp());
|
187
|
|
- savestus.add(ggs);
|
|
196
|
+ if(gg.getGroups() != null && gg.getGroups().size() > 0){
|
|
197
|
+ //页面选择的学生预习学生集合
|
|
198
|
+ String groupids = StringUtils.join(gg.getGroups(),",");
|
|
199
|
+
|
|
200
|
+ //获取选中班级分组下所有学生
|
|
201
|
+ List<Integer> stus = classMapper.listStudentidsByGroupids(groupids);
|
|
202
|
+ for (Integer studentid : stus) {
|
|
203
|
+ TGuideGroupStudent ggs = new TGuideGroupStudent();
|
|
204
|
+ ggs.setGuideid(guide.getGuideid());
|
|
205
|
+ ggs.setClassid(classid);
|
|
206
|
+ ggs.setStudentid(studentid);
|
|
207
|
+ ggs.setCosttime(0);
|
|
208
|
+ ggs.setCreatetime(N_Utils.getSecondTimestamp());
|
|
209
|
+ savestus.add(ggs);
|
188
|
210
|
|
|
211
|
+ }
|
189
|
212
|
}
|
190
|
213
|
}
|
191
|
214
|
|
|
215
|
+ if(savestus == null || savestus.size() == 0){
|
|
216
|
+ throw new Exception("未选择学生");
|
|
217
|
+ }
|
|
218
|
+
|
192
|
219
|
//保存预习班级、预习学生信息
|
193
|
220
|
guideGroupMapper.insertList(savegroup);
|
194
|
221
|
guideGroupStudentMapper.insertList(savestus);
|