派生自 projectDept/qhighschool

Administrator
2022-11-21 8d0e57a64fe6c31559ffcf38859fb1f5084e1e23
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
package com.qxueyou.scc.controller;
 
import java.util.List;
import java.util.Map;
 
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import com.qxueyou.scc.admin.teacher.service.ITeacherService;
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.util.ClientUtils;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.QBeanUtils;
import com.qxueyou.scc.teach.res.service.IFileService;
import com.qxueyou.scc.teach.subject.model.Subject;
import com.qxueyou.scc.teach.subject.service.ISubjectService;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
 
/**
 * ¿Î³Ì¹ÜÀí¿ØÖÆÆ÷
 * 
 * @author chenjunliang
 *
 */
@Api(tags = "¿Î³Ì¹ÜÀí-½Ìʦ¶Ë")
@RestController
@RequestMapping(value = "/teach/subject")
public class SubjectController {
 
    @Autowired
    ISubjectService subjectService;
 
    @Autowired
    IFileService fileService;
    
    @Autowired
    private ITeacherService teacherService;
    
    /**-------------------------------------------------------------------app½Ó¿Ú------------------------------------------------------------------------------------------**/
    
    /**
     * ¿Î³Ì¹ÜÀíÁбí
     * 
     * @param keyword
     *            Ë÷Ëѹؼü×Ö
     * @param limit
     *            ÏÔʾ¼¸Ìõ
     * @param pageNum
     *            µ±Ç°Ò³Âë
     * @param status
     *            ×´Ì¬
     */
    @ApiOperation(value = "»ñÈ¡ÁбíÊý¾Ý-½Ìʦ¶Ë", notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "status", value = "״̬", required = false, paramType="query", dataType = "String"),
        @ApiImplicitParam(name = "type", value = "ÀàÐÍ(1:°à¼¶¿Î³Ì,3:¹«¿ª¿Î³Ì)", required = false, paramType="query", dataType = "Integer")
    })
    @GetMapping(value = "/app/teacherSubjectList")
    public Result list(Pager pager, @RequestParam(defaultValue="")String keyword, String status, Integer type) {
        if(type == null) {
            return new Result(false, "²ÎÊý´íÎó");
        }
        return subjectService.teacherSubjectList(pager, keyword, status, type);
    }
    
    /**-------------------------------------------------------------------ºó¶Ë½Ó¿Ú------------------------------------------------------------------------------------------**/
 
    /**
     * ¿Î³Ì¹ÜÀíÁбí
     * 
     * @param keyword
     *            Ë÷Ëѹؼü×Ö
     * @param limit
     *            ÏÔʾ¼¸Ìõ
     * @param pageNum
     *            µ±Ç°Ò³Âë
     * @param status
     *            ×´Ì¬
     */
    @GetMapping(value = "/list")
    public Result list(String keyword,String status,Integer type, Integer limit, Integer pageNum) {
 
        String teacherId = ClientUtils.isAdmin() ? null : ClientUtils.getUserId();
 
        List<Subject> lst = subjectService.list(keyword, teacherId, status, type, limit, pageNum);
 
        int count = subjectService.listCount(keyword, teacherId, status,type);
 
        return new Result(true, "success", CollectionUtils.newObjectMap("subjectLst",
                QBeanUtils.listBean2ListMap(lst,
                        CollectionUtils.newStringMap("name", "subjectName", "subjectId", "subjectId","type","type", "status",
                                "status", "updateTime", "updateTime", "lectureCount", "lectureCount")),
 
                "subjectCount", count));
    }
 
    /**
     * ¿Î³Ì¹ÜÀíÁбí
     * 
     * @param keyword
     *            Ë÷Ëѹؼü×Ö
     * @param limit
     *            ÏÔʾ¼¸Ìõ
     * @param pageNum
     *            µ±Ç°Ò³Âë
     * @param status
     *            ×´Ì¬
     */
    @GetMapping(value = "/listAllSimple")
    public Result listAllSimple() {
 
        List<Subject> lst = subjectService.list("", null, "1", null,1000, 1);
 
        return new Result(true, "success", QBeanUtils.listBean2ListMap(lst,
                CollectionUtils.newStringMap("name", "subjectName", "subjectId", "subjectId")));
    }
 
    /**
     * ¿Î³Ì·¢²¼
     * a
     * @param ¿Î³Ìids
     */
    @GetMapping(value = "/release")
    public Result release(String subjectIds) {
 
        return subjectService.doRelease(subjectIds.split(","));
 
    }
 
    /**
     * ¿Î³ÌϼÜ
     * 
     * @param subjectIds
     *            ¿Î³Ìids
     */
    @GetMapping(value = "/soldOut")
    public Result soldOut(String subjectIds) {
        return subjectService.doCancel(subjectIds.split(","));
    }
 
    /**
     * ¿Î³Ìɾ³ý
     * 
     * @param subjectIds
     *            ¿Î³Ìids
     */
    @GetMapping(value = "/delete")
    public Result delete(String subjectIds) {
        return subjectService.delete(subjectIds.split(","));
    }
 
    /**
     * ¸´ÖƿγÌ
     * 
     * @param subjectId
     *            ¿Î³Ìid
     * @param subjectName
     *            ¿Î³ÌÃû³Æ
     * @param imgPath
     *            Í¼Æ¬url
     * @param content
     *            ¿Î³Ì½éÉÜ
     */
    @PostMapping(value = "/copy")
    public Result copy(String subjectId, String subjectName, String imgPath, String content,int type) {
        return add(subjectName, imgPath, content,type);
    }
 
    /**
     * ÐÂÔö¿Î³Ì
     * 
     * @param subjectName
     *            ¿Î³ÌÃû³Æ
     * @param imgPath
     *            Í¼Æ¬url
     * @param content
     *            ¿Î³Ì½éÉÜ
     * @return
     */
    @PostMapping(value = "/add")
    public Result add(String subjectName, String imgPath, String content,int type) {
        String contentFileId = null;
        
        if(StringUtils.isNotEmpty(content)){
            Result fileResult = fileService.doUpload(IOUtils.toInputStream(content), subjectName + ".data");
            contentFileId = fileResult.getDataT("fileId");
        }
        
        String coverPageFileId = null;
        
        if (StringUtils.isNotBlank(imgPath)) {
            coverPageFileId = fileService.readIdByPath(imgPath);
        }
        
        return subjectService.add(subjectName, coverPageFileId,contentFileId,type);
    }
 
    /**
     * ÐÂÔöÁ·Ï°
     * 
     * @param name
     *            ÌâÄ¿Ãû³Æ
     * @param type
     *            Ìâ¿âÀàÐÍ
     * @param difficulty
     *            ÄѶÈϵÊý
     * @param repeatFlag
     *            ÊÇ·ñÖØ¸´
     * @return
     */
    @PostMapping(value = "addExercise")
    public Result addOrgExercise(String name, Integer type, Integer difficulty, Boolean repeatFlag) {
        return new Result(true, "success");
    }
 
    /**
     * ¸üпγÌ
     * 
     * @param subjectId
     *            ¿Î³Ìid
     * @param subjectName
     *            ¿Î³ÌÃû³Æ
     * @param imgPath
     *            Í¼Æ¬url
     * @param content
     *            ¿Î³Ì½éÉÜ
     */
    @PostMapping(value = "/update")
    public Result update(String subjectId, String subjectName, String imgPath, String content,int type) {
        String contentFileId = null;
        
        if(StringUtils.isNotEmpty(content)){
            Result fileResult = fileService.doUpload(IOUtils.toInputStream(content), subjectName + ".data");
            contentFileId = fileResult.getDataT("fileId");
        }
        
        String coverPageFileId = null;
        if (StringUtils.isNotBlank(imgPath)) {
            coverPageFileId = fileService.readIdByPath(imgPath);
        }
 
        return subjectService.update(subjectId, subjectName, coverPageFileId, contentFileId,type);
    }
 
    /**
     * ¸üпγ̻ñÈ¡¿Î³ÌÄÚÈÝ
     * 
     * @param subjectId
     *            ¿Î³Ìid
     */
    @ApiOperation(value = "»ñÈ¡¿Î³ÌÏêÇé-½Ìʦ¶Ë", notes = "")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "subjectId", value = "¿Î³Ìid", required = false, paramType="query", dataType = "String")
    })
    @GetMapping(value = "getSubjectDetail")
    public Result getSubjectDetail(String subjectId) {
 
        Map<String, Object> result = QBeanUtils.bean2Map(subjectService.read(subjectId), CollectionUtils
                .newStringMap("name", "subjectName",
                        "subjectId", "subjectId",
                        "type","type", 
                        "coverPageUrl", "imgPath",
                        "teacherId","teacherId",
                        "teacherName","teacherName",
                        "schoolYear","schoolYear",
                        "createTime","createTime",
                        "creator","creator",
                        "term","term"));
        
        result.put("reSubjects",this.subjectService.querySubjectReClassInfos(subjectId));
        result.put("content", subjectService.readSubjectContent(subjectId));
        result.put("lectureCount", subjectService.getLectureCount(subjectId));
        return new Result(true, "success", result);
    }
    
    
    /**
     * »ñÈ¡¿ÉÓÿγÌÏÂÀ­Áбí½Ó¿Ú
     * 
     * @param examId
     * @return
     */
    @RequestMapping(value = "/selectlist", method = RequestMethod.GET)
    public @ResponseBody List<Map<String,Object>> subjectList(Integer subjectType) {
        //ÅжÏÊÇ·ñÊǽÌʦ
        String teacherId = ClientUtils.isAdmin() ? null : teacherService.getTeacherIdByUserId(ClientUtils.getUserId());
        
        if(subjectType==null){
            subjectType= Subject.TYPE_ORG_SUBJECT;
        }
        
        return this.subjectService.queryAvailableSubjectIdAndName(teacherId,subjectType);
    }
    
 
}