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); } }