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 getClassListData() { return articleService.queryClassListData(); } //-------------------------------------------------------------后台接口------------------------------------------------------------------------------------------- /** * 获取机构讲义列表数据 * * @return */ @RequestMapping(value = "orgData", method = RequestMethod.GET) public @ResponseBody List> 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 ids, @RequestParam("index[]") List index){ return articleService.doitemOrder(ids, index); } /** * 获取机构指定的机构和班级 * * @return */ @RequestMapping(value = "articleOrgIds", method = RequestMethod.GET) public @ResponseBody Result findAlreadyOrg(String articleId) { Map map = new HashMap(); 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 lstOrg = commonDAO.find(hql, CollectionUtils.newList(articleId), Organization.class); // StringBuffer sbName = new StringBuffer(); StringBuffer sbId = new StringBuffer(); List classIds = new ArrayList(); // 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 args = new HashMap(); args.put("classIds", classIds.toArray()); args.put("articleId", articleId); List 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); } }