派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
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
310
311
312
313
314
315
316
317
318
package com.qxueyou.scc.school.action;
 
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
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 com.qxueyou.scc.base.dao.CommonDAO;
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.base.util.QrCodeUtils;
import com.qxueyou.scc.config.AliOssConfig;
import com.qxueyou.scc.org.model.Organization;
import com.qxueyou.scc.org.service.IOrgTextService;
import com.qxueyou.scc.school.model.SchArticle;
import com.qxueyou.scc.school.service.IArticleService;
 
/**
 * 文章控制器
 * 
 * @author zhiyong
 * 
 */
@Controller
@RequestMapping(value = "/school/article")
@EnableConfigurationProperties(AliOssConfig.class)
public class ArticleController {
    
    @Autowired
    private IArticleService articleService;
    
    @Autowired
    AliOssConfig aliOssConfig;
    
    
    @Autowired
    private CommonDAO commonDAO;
    
    @SuppressWarnings("unused")
    @Autowired
    private IOrgTextService textService;
    
    //-------------------------------------------------------------app接口-------------------------------------------------------------------------------------------
    
    /**
     * 文章列表
     * 
     * @param pager
     * @return
     */
    @RequestMapping(value = "articleList", method = RequestMethod.GET) 
    public @ResponseBody Result articleList(Pager pager, String sortType, String sortField, String collegeCourseId, String subjectId) {
        return this.articleService.articleList(pager, sortType, sortField, collegeCourseId, subjectId);
    }
    
    /**
     * 更新观看进度
     * 
     * @param articleId
     * @return
     */
    @RequestMapping(value = "doSubmitSchedule", method = RequestMethod.POST) 
    public @ResponseBody Result doSubmitSchedule(String articleId, double compDegree) {
        return this.articleService.doSubmitSchedule(articleId, compDegree);
    }
    
    /**
     * 点赞
     * 
     * @param msgId
     * @return
     */
    @RequestMapping(value = "doLike", method = RequestMethod.POST) 
    public @ResponseBody Result doLike(String commentId) {
        return this.articleService.doLike(commentId);
    }
    
    /**
     * 新增评论
     * 
     * @param msgId
     * @return
     */
    @RequestMapping(value = "commentList", method = RequestMethod.GET) 
    public @ResponseBody Result commentList(String articleId) {
        return this.articleService.commentList(articleId);
    }
    
    /**
     * 新增评论
     * 
     * @param msgId
     * @return
     */
    @RequestMapping(value = "addComment", method = RequestMethod.POST) 
    public @ResponseBody Result addComment(String articleId, String content, String parentCommentId) {
        return this.articleService.addComment(articleId, content, parentCommentId);
    }
    
    /**
     * 删除评论
     * 
     * @param msgId
     * @param commentId
     * @return
     */
    @RequestMapping(value = "deleteComment", method = RequestMethod.POST) 
    public @ResponseBody Result deleteComment(String articleId, String commentId) {
        return this.articleService.deleteComment(articleId, commentId);
    }
    
    
    /**
     *  班级列表数据
     * URL :/school/article/list
     * 
     * type 1:机构 2:班级
     * @return
     */
    @RequestMapping(value = "/class/list", method = RequestMethod.GET)
    public @ResponseBody List<SchArticle> getClassListData() {
        
        return articleService.queryClassListData();
    }
    
    //-------------------------------------------------------------后台接口-------------------------------------------------------------------------------------------
    /**
     * 获取机构讲义列表数据
     * 
     * @return
     */
    @RequestMapping(value = "orgData", method = RequestMethod.GET)
    public @ResponseBody List<Map<String, Object>> queryArticleOrgLst(String collegeCourseId, String subjectId) {
 
        return articleService.queryArticleOrgLst(collegeCourseId, subjectId);
    }
    
    /**
     *  列表数据
     * URL :/school/article/list
     * 
     * @return
     */
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public @ResponseBody Result queryInfo(@RequestParam("articleId") String articleId) {
        
        return articleService.queryInfo(articleId);
    }
    
    /**
     *  班级列表数据
     * URL :/school/article/class/addOrUpdate
     * 
     * type 1:机构 2:班级
     * @return
     */
    @RequestMapping(value = "/class/addOrUpdate", method = RequestMethod.POST)
    public @ResponseBody Result updateArticle(SchArticle article) {
        
        return articleService.updateArticle(article);
    }
    
    /**
     *  机构列表数据
     * URL :/school/article/org/addOrUpdate
     * 
     * type 1:机构 2:班级
     * @return
     */
    @RequestMapping(value = "/org/addOrUpdate", method = RequestMethod.POST)
    public @ResponseBody Result updateOrgArticle(SchArticle article, String collegeCourseId) {
        
        return articleService.updateOrgArticle(article, collegeCourseId);
    }
    
    /**
     *  删除班级数据
     * URL :/school/article/delete
     * 
     * type  班级
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public @ResponseBody Result deleteArticle(@RequestParam("articleIds") String articleIds) {
        
        return articleService.deleteArticle(articleIds);
    }
    
    
    /**
     * 习题排序
     * 
     * @param key
     * @return
     */
    @RequestMapping(value = "/order", method=RequestMethod.POST)
    public @ResponseBody Result itemOrder(@RequestParam("ids[]") List<String> ids,  @RequestParam("index[]") List<Integer> index){
        
        return articleService.doitemOrder(ids, index);
    }
    
    /**
     * 获取机构指定的机构和班级
     * 
     * @return
     */
    @RequestMapping(value = "articleOrgIds", method = RequestMethod.GET)
    public @ResponseBody Result findAlreadyOrg(String articleId) {
        Map<String, Object> map = new HashMap<String, Object>();
        String hql = " select r from SchArticleReCourse c,Organization r" 
                   + " where c.orgId = r.organizationId" 
                   + " and c.deleteFlag is false" 
                   + " and r.deleteFlag is false" 
                   + " and c.articleId = ?";
        List<Organization> lstOrg = commonDAO.find(hql, CollectionUtils.newList(articleId), Organization.class);
        // StringBuffer sbName = new StringBuffer();
        StringBuffer sbId = new StringBuffer();
        List<String> classIds = new ArrayList<String>();
        // String orgNames = "";
        String orgIds = "";
        for (Organization org : lstOrg) {
            // sbName.append(org.getName() + ",");
            sbId.append(org.getOrganizationId()).append(',');
        }
        if (classIds.isEmpty()) {
            map.put("classIds", "");
        } else {
            hql = "select distinct classId from SchArticle where classId in (:classIds) and deleteFlag is false and originArticleId = :articleId";
            Map<String, Object> args = new HashMap<String, Object>();
 
            args.put("classIds", classIds.toArray());
 
            args.put("articleId", articleId);
            List<String> objs = commonDAO.findByComplexHql(hql, args, String.class);
            map.put("classIds", StringUtils.join(objs.toArray(), ","));
        }
        /*
         * if (sbName.length() > 0) { orgNames = sbName.deleteCharAt(sbName.length() - 1).toString(); }
         */
        if (sbId.length() > 0) {
            orgIds = sbId.deleteCharAt(sbId.length() - 1).toString();
        }
        // map.put("orgNames", orgNames);
        map.put("orgIds", orgIds);
 
        Result result = new Result(true);
        result.setData(map);
        return result;
    }
    
    /**
     * 删除讲义信息
     * 
     * @return
     */
    @RequestMapping(value = "deleteOrg", method = RequestMethod.POST)
    @ResponseBody
    public Result deleteOrg(String articleIds, Integer delAll, String orgIds[], String classIds[]) {
 
        // 保存到服务器
        Result result = articleService.deleteOrgArticleIds(articleIds.split(","), delAll, orgIds, classIds);
 
        // 删除微商项目所有缓存
//        new CacheUtils().deleteWBProjectCacheData();
        
        // 返回结果
        return result;
    }
    
    /**
     * 指定讲义数据到某个机构
     * 
     * @return
     */
    @RequestMapping(value = "orgArticle", method = RequestMethod.GET)
    public @ResponseBody Result orgHandout(String articleId[], String orgId[], String classIds[], String collegeCourseId) {
        
        // 删除微商项目所有缓存
//        new CacheUtils().deleteWBProjectCacheData();
                
        return articleService.insertAppointArticle(articleId, orgId, classIds, collegeCourseId);
    }
    
    /**
     * 预览
     * 
     * @param articleId
     * @param request
     * @param response
     * @throws IOException
     */
    @RequestMapping(value = "/preview/qrcode/{articleId}", method = RequestMethod.GET)
    public void qrcodeWeChat(@PathVariable String articleId, HttpServletRequest request, HttpServletResponse response)
            throws IOException {
 
        SchArticle article = commonDAO.read(SchArticle.class, articleId);
        
        QrCodeUtils.createQRCodeImgAndSend(aliOssConfig.getDomain()+article.getUrl(), 
                response.getOutputStream(), true);
    }
    
    
}