package com.qxueyou.scc.school.service.impl; import java.math.BigInteger; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.qxueyou.scc.admin.classes.model.ClsClass; import com.qxueyou.scc.base.model.Pager; import com.qxueyou.scc.base.model.Result; import com.qxueyou.scc.base.model.UserInfoWrapper; //import com.qxueyou.scc.base.service.ICacheService; import com.qxueyou.scc.base.service.impl.CommonAppService; //import com.qxueyou.scc.base.util.CacheUtils; import com.qxueyou.scc.base.util.ClientUtils; import com.qxueyou.scc.base.util.CollectionUtils; import com.qxueyou.scc.base.util.TraceUtils; import com.qxueyou.scc.operation.comment.mode.Comment; import com.qxueyou.scc.operation.comment.mode.CommentPraise; //import com.qxueyou.scc.sys.service.IOssService; import com.qxueyou.scc.org.model.OrgText; import com.qxueyou.scc.org.service.IOrgTextService; import com.qxueyou.scc.school.model.SchArticle; import com.qxueyou.scc.school.model.SchArticleReCourse; import com.qxueyou.scc.school.model.SchArticleStatistic; import com.qxueyou.scc.school.model.SchClassCircleMsg; import com.qxueyou.scc.school.model.SchClassSubject; import com.qxueyou.scc.school.model.SchCourseware; import com.qxueyou.scc.school.model.SchFile; import com.qxueyou.scc.school.model.SchImg; import com.qxueyou.scc.school.service.IArticleService; import com.qxueyou.scc.school.service.ICourseWareService; import com.qxueyou.scc.teach.subject.model.SubjectChapter; /** * ÎÄÕÂʵÏÖÀà * * @author zhiyong * */ @Service public class ArticleService extends CommonAppService implements IArticleService { // @Autowired // ICacheService cache; // // @Autowired // IOssService ossService; @Autowired IOrgTextService orgTextService; @Autowired private ICourseWareService courseWareService; // »º´æ @SuppressWarnings("unused") private static final String CACHE_MSG_IMGS = "CACHE_MSG_IMGS_"; @SuppressWarnings("unused") private static final String CACHE_MSG_FILES = "CACHE_MSG_FILES_"; @SuppressWarnings("unused") private static final String CACHE_ARTICLE_COMMENTS = "CACHE_ARTICLE_COMMENTS"; @SuppressWarnings("unused") private static final int ONE_DAY = 60 * 60 * 24; /** * ²éѯÁбíÊý¾Ý * * @param type * @return */ @Override public List queryClassListData() { List resultLst = this.find( "from SchArticle where deleteFlag is false and classId=? order by orderNum ", CollectionUtils.newList(ClientUtils.getClassId()), SchArticle.class); return resultLst; } /** * ÐÂÔö»ò¸üÐÂÁбíÊý¾Ý * * @param articleId * @param name * @return */ @SuppressWarnings("unused") @Override public Result updateArticle(SchArticle article) { String articleId = article.getArticleId(); if (StringUtils.isBlank(articleId)) {// ÐÂÔö article.setArticleId(null); article.setClassId(ClientUtils.getClassId()); article.setOrgId(ClientUtils.getOrgId()); article.setDeleteFlag(false); TraceUtils.setCreateTrace(article); // ÐòºÅ String hql = "select MAX(c.orderNum) from SchArticle c where c.deleteFlag is false and c.classId= ? "; Integer iMax = this.findUnique(hql, CollectionUtils.newList(ClientUtils.getClassId()), Integer.class); if (iMax == null || iMax == 0) { iMax = 1; } else { iMax = iMax + 1; } article.setOrderNum(iMax); this.saveArticle(article); article.setOriginArticleId(article.getArticleId()); this.saveArticle(article); articleId = article.getArticleId(); } else {// ¸üРSchArticle articleNew = this.read(SchArticle.class, articleId); // Ô­ÉÏ´«µÄÎļþurl String originUrl = articleNew.getUrl(); articleNew.setCoverPageUrl(article.getCoverPageUrl()); // articleNew.setSubjectId(article.getSubjectId()); // articleNew.setSubjectName(article.getSubjectName()); articleNew.setName(article.getName()); articleNew.setUrl(article.getUrl()); TraceUtils.setUpdateTrace(articleNew); this.saveArticle(articleNew); // // ɾ³ýÔ­ÉÏ´«µÄÎļþ // if(StringUtils.isNotBlank(originUrl)){ // ossService.deleteOSSFile(originUrl.substring(1)); // } } // ±£´æOrgText ¡ª¡ª ÎÄÕÂÄÚÈÝ orgTextService.doSaveOrgText(articleId, OrgText.TABLE_NAME_ARTICLE, article.getContent()); // ɾ³ý¸Ã°à¼¶ËùÓлº´æ // new CacheUtils().deleteWBProjectCacheData(); return new Result(true, "²Ù×÷³É¹¦", articleId); } /** * ÐÂÔö»ò¸üÐÂÁбíÊý¾Ý »ú¹¹ * * @return */ @SuppressWarnings("unused") @Override public Result updateOrgArticle(SchArticle article, String collegeCourseId) { String articleId = article.getArticleId(); // jgw Ö±½Ó½«ÎÄÕÂÐÞ¸ÄΪÒÑ·¢²¼ article.setStatus(SchArticle.STATUS_PUBLISHED); if (StringUtils.isBlank(articleId)) {// ÐÂÔö article.setArticleId(null); article.setOrgId(ClientUtils.getOrgId()); article.setDeleteFlag(false); TraceUtils.setCreateTrace(article); this.saveArticle(article); article.setOriginArticleId(article.getArticleId()); this.saveArticle(article); articleId = article.getArticleId(); // ±£´æÎÄÕ¿γ̹ØÁª¹ØÏµ saveSchArticleReCourse(collegeCourseId, article.getArticleId()); } else {// ¸üРSchArticle articleNew = this.read(SchArticle.class, articleId); // Ô­ÉÏ´«µÄÎļþurl String originUrl = articleNew.getUrl(); articleNew.setCoverPageUrl(article.getCoverPageUrl()); // articleNew.setSubjectId(article.getSubjectId()); // articleNew.setSubjectName(article.getSubjectName()); articleNew.setName(article.getName()); articleNew.setUrl(article.getUrl()); TraceUtils.setUpdateTrace(articleNew); this.saveArticle(articleNew); // // ɾ³ýÔ­ÉÏ´«µÄÎļþ // if(StringUtils.isNotBlank(originUrl)){ // ossService.deleteOSSFile(originUrl.substring(1)); // } } // ±£´æOrgText ¡ª¡ª ÎÄÕÂÄÚÈÝ orgTextService.doSaveOrgText(articleId, OrgText.TABLE_NAME_ARTICLE, article.getContent()); // ɾ³ý¸Ã°à¼¶ËùÓлº´æ // new CacheUtils().deleteWBProjectCacheData(); return new Result(true, "²Ù×÷³É¹¦", articleId); } /** * ±£´æÎÄÕ¿γ̹ØÁª¹ØÏµ * * @param collegeCourseId * @param articleId */ private void saveSchArticleReCourse(String collegeCourseId, String articleId) { SchArticleReCourse course = new SchArticleReCourse(); course.setCollegeCourseId(collegeCourseId); course.setDeleteFlag(false); course.setArticleId(articleId); course.setOrgId(ClientUtils.getOrgId()); TraceUtils.setCreateTrace(course); // ÐòºÅ String hql = "select MAX(c.orderNum) from SchArticleReCourse c where c.deleteFlag is false and c.collegeCourseId = ? and orgId = ? "; Integer iMax = this.findUnique(hql, CollectionUtils.newList(collegeCourseId, ClientUtils.getOrgId()), Integer.class); if (iMax == null || iMax == 0) { iMax = 1; } else { iMax = iMax + 1; } course.setOrderNum(iMax); save(course); } /** * ɾ³ýÎÄÕ * * @param articleIds * @return */ @Override public Result deleteArticle(String articleIds) { if (StringUtils.isBlank(articleIds)) { return new Result(false, "Ìá½»Êý¾ÝÒì³£"); } String[] aIds = articleIds.split(","); this.bulkUpdateInLoop("update SchArticle set deleteFlag=1 where articleId=?", aIds); this.bulkUpdateInLoop("update SchCourseware set deleteFlag=1 where id=?", aIds); // ɾ³ý΢ÉÌÏîÄ¿ËùÓлº´æ // new CacheUtils().deleteWBProjectCacheData(); return new Result(true, "²Ù×÷¹¦ÄÜ"); } /** * * ²éѯ»ù±¾ÐÅÏ¢ * * @param articleId * @return */ @Override public Result queryInfo(String articleId) { SchArticle article = this.read(SchArticle.class, articleId); String content = this.findUnique( "select content from OrgText where key=? and tableName=? and deleteFlag is false", CollectionUtils.newList(articleId, OrgText.TABLE_NAME_ARTICLE), String.class); if (StringUtils.isBlank(content)) { content = ""; } article.setCommentCount(this.findCount("from Comment where deleteFlag is false and commentObjectId = ?", CollectionUtils.newList(articleId))); article.setContent(content); return new Result(true, "²éѯ³É¹¦", article); } /** * ²éѯ¿ÆÄ¿ÎÄÕÂlist * * @param collegeCourseId * @return */ @Override public List> queryArticleOrgLst(String collegeCourseId, String subjectId) { List handoutLst = null; List args = new ArrayList(); String hql = ""; // ÆäËû if (("-" + collegeCourseId).equals(subjectId)) { hql = "select v.articleId,v.name,'','','',0,'' from SchArticle v,SchArticleReCourse r where v.collegeCourseId = ? and r.deleteFlag is false and r.articleId = v.articleId and v.deleteFlag is false and r.orgId = ? " + "and not EXISTS (select 1 from SchSubject t where t.deleteFlag is false and t.subjectId = v.subjectId)"; args.add(collegeCourseId); args.add(ClientUtils.getOrgId()); } else { hql = "select h.articleId,h.name,o.courseCategoryName,o.name,h.subjectName,s.orderNum,h.subjectId " + " from SchArticleReCourse s , SchArticle h,OrgCollegeCourse o" + " where s.deleteFlag is false and h.deleteFlag is false " + " and o.collegeCourseId = s.collegeCourseId" + " and s.orgId = ?" + " and s.articleId = h.articleId "; args.add(ClientUtils.getOrgId()); if (StringUtils.isNotBlank(subjectId)) { hql = hql.concat(" and h.subjectId = ?"); args.add(subjectId); } hql = hql.concat(" and s.collegeCourseId = ? ORDER BY s.orderNum ASC"); args.add(collegeCourseId); } handoutLst = findwithRawResult(hql, args); List> lstMap = new ArrayList>(handoutLst.size()); Map map = null; for (Object[] obj : handoutLst) { map = new HashMap(); map.put("articleId", obj[0]); map.put("name", obj[1]); map.put("courseCategoryName", obj[2]); map.put("courseName", obj[3]); map.put("subjectName", obj[4]); map.put("orderNum", obj[5]); map.put("subjectId", obj[6]); lstMap.add(map); } return lstMap; } /** * ÅÅÐò */ @Override public Result doitemOrder(List ids, List index) { // Ñ­»·ÐÞ¸Äorder for (int i = 0; i < ids.size(); i++) { String id = ids.get(i); if (UserInfoWrapper.ROLE_TEACHER.equals(ClientUtils.getCurrentRole()) || UserInfoWrapper.ROLE_CHARGER.equals(ClientUtils.getCurrentRole())) { this.bulkUpdate("update SchArticle set orderNum = " + index.get(i) + " where articleId = ?", new Object[] { id }); } else { this.bulkUpdate("update SchArticleReCourse set orderNum = " + index.get(i) + " where articleId = ?", new Object[] { id }); } this.bulkUpdate("update SchCourseware set orderNum = " + index.get(i) + " where id = ?", new Object[] { id }); } // ɾ³ý΢ÉÌÏîÄ¿ËùÓлº´æ // new CacheUtils().deleteWBProjectCacheData(); return new Result(true, "Ð޸ijɹ¦"); } /** * ɾ³ý»ú¹¹ÎÄÕÂÐÅÏ¢ * * @param articleIds * @param delAll * @param orgIds * @param classIds */ @Override public Result deleteOrgArticleIds(String[] articleIds, Integer delAll, String[] orgIds, String[] classIds) { for (String articleId : articleIds) { if ((orgIds != null && orgIds.length != 0) || (classIds != null && classIds.length != 0)) { // ɾ³ýÐèÒª»Ø³·µÄ½²Òå deleteAppoint(articleId, orgIds, classIds); } else { // ɾ³ý½²Òå String hql = " from SchArticleReCourse where articleId = ? and deleteFlag is false and orgId = ?"; SchArticleReCourse shr = findUnique(hql, CollectionUtils.newList(articleId, ClientUtils.getOrgId()), SchArticleReCourse.class); if (shr != null) { TraceUtils.setUpdateTrace(shr); shr.setDeleteFlag(true); save(shr); this.courseWareService.deleteOrgCourseware(shr.getArticleId(), shr.getOrgId()); } /* * SchArticle article = this.read(SchArticle.class, articleId); if(article != * null){ TraceUtils.setUpdateTrace(article); article.setDeleteFlag(true); * this.saveArticle(article); } */ // Óû§Ñ¡Ôñͬʱɾ³ýϼ¶½²Òå if (delAll == 1) { deleteSub(articleId, ClientUtils.getOrgId()); } } } return new Result(true, "ɾ³ý³É¹¦"); } private Result deleteAppoint(String articleId, String orgIds[], String classIds[]) { Map args = new HashMap(); // ɾ³ýÐèÒª»Ø³·µÄ»ú¹¹½²Òå if (orgIds.length != 0) { String hql = " from SchArticleReCourse where articleId = :articleId and deleteFlag is false and orgId in (:orgIds) and orgId != :currOrgId"; args = new HashMap(); args.put("articleId", articleId); args.put("orgIds", orgIds); args.put("currOrgId", ClientUtils.getOrgId()); List courses = findByComplexHql(hql, args, SchArticleReCourse.class); for (SchArticleReCourse course : courses) { TraceUtils.setUpdateTrace(course); course.setDeleteFlag(true); save(course); this.courseWareService.deleteOrgCourseware(course.getArticleId(), course.getOrgId()); } } // ɾ³ýÐèÒª»Ø³·µÄ°àÖ÷Èν²Òå if (classIds.length != 0) { args = new HashMap(); args.put("articleId", articleId); args.put("classIds", classIds); String hql = " from SchArticle where originArticleId = :articleId and deleteFlag is false and classId in (:classIds)"; List articles = findByComplexHql(hql, args, SchArticle.class); for (SchArticle article : articles) { TraceUtils.setUpdateTrace(article); article.setDeleteFlag(true); this.saveArticle(article); } } return new Result(true); } @SuppressWarnings("unchecked") private void deleteSub(String articleId, String currOrgId) { // »ú¹¹²ã¼¶ÊÓÆµÊÇûÓÐÖØÐÂnew £¬²éѯ³ö»ú¹¹Ï¼¶IDÔÙɾ¹ØÁª±í String sql = " select oa.organization_id from organization as oa,organization ob " + " where " + " ob.ORGANIZATION_ID = ? " + " and " + " oa.org_code like CONCAT(ob.org_code,'%' ) " + " and oa.delete_flag is false and ob.delete_flag is false " + " order by oa.level,oa.org_code asc "; List orgIds = this.findBySql(sql, CollectionUtils.newList(currOrgId)); String hql = " from SchArticleReCourse where articleId = :articleId and deleteFlag is false and orgId in (:orgIds)"; Map map = new HashMap(); map.put("articleId", articleId); map.put("orgIds", orgIds.toArray()); List artCourses = findByComplexHql(hql, map, SchArticleReCourse.class); for (SchArticleReCourse artCourse : artCourses) { artCourse.setDeleteFlag(true); TraceUtils.setUpdateTrace(artCourse); save(artCourse); } // °àÖ÷ÈβãÃæÊÓÆµÖ¸¶¨¹ýºó¶¼ÊÇnew ³öÀ´µÄ£¬Í¨¹ýoriginVideoId ¿ÉÒÔ²é³öËùÓÐÖ¸¶¨¹ýÈ¥µÄÊÓÆµ hql = "select classId from ClsClass where orgId in (:orgIds) and deleteFlag is false"; map = new HashMap(); map.put("orgIds", orgIds.toArray()); List clsIds = findByComplexHql(hql, map, String.class); if (!clsIds.isEmpty()) { hql = " from SchArticle where originArticleId = :articleId and deleteFlag is false and articleId!=originArticleId and classId in (:classIds)"; map = new HashMap(); map.put("articleId", articleId); map.put("classIds", clsIds.toArray()); List lstArticle = findByComplexHql(hql, map, SchArticle.class); for (SchArticle article : lstArticle) { article.setDeleteFlag(true); TraceUtils.setUpdateTrace(article); this.saveArticle(article); } } } /** * Ï·¢»ú¹¹Îļþ * * @param articleId * @param orgId * @param classIds * @param collegeCourseId * @return */ @Override public Result insertAppointArticle(String[] articleIds, String[] orgIds, String[] classIds, String collegeCourseId) { if (null == articleIds || articleIds.length == 0) { return new Result(false, "²ÎÊý´íÎó"); } // Ò»´ÎÐÔ²éѯclassId¶ÔÓ¦µÄorgId Map argsMap = new HashMap(); Map classMap = new HashMap(); if (classIds.length > 0) { String hql = " from ClsClass where classId in (:classIds) and deleteFlag is false"; argsMap = new HashMap(); argsMap.put("classIds", classIds); List classList = findByComplexHql(hql, argsMap, ClsClass.class); // ·ÅÈëmapÖÐ KEY:classId VALUE:orgId for (ClsClass orgClass : classList) { classMap.put(orgClass.getClassId(), orgClass.getOrgId()); } } // Ò»´ÎÐÔ²é³öhandoutId¶ÔÓ¦µÄhandoutOrder Map orderMap = new HashMap(); String hql = " from SchArticleReCourse where articleId in (:articleIds) and deleteFlag is false and orgId = :currOrgId"; argsMap = new HashMap(); argsMap.put("articleIds", articleIds); argsMap.put("currOrgId", ClientUtils.getOrgId()); List articleCourse = findByComplexHql(hql, argsMap, SchArticleReCourse.class); for (SchArticleReCourse schArticleReCourse : articleCourse) { orderMap.put(schArticleReCourse.getArticleId(), schArticleReCourse.getOrderNum()); } for (String articleId : articleIds) { if (orgIds.length > 0) { // Ö¸¶¨¸ø»ú¹¹ insertAppointOrg(orgIds, articleId, collegeCourseId, orderMap); } if (classIds.length > 0) { // Ö¸¶¨¸ø°à¼¶ insertAppointClass(classIds, articleId, collegeCourseId, orderMap); } } return new Result(true); } /** * Ö¸¶¨¸ø»ú¹¹ * * @param orgIds * @param handoutId * @param collegeCourseId */ private void insertAppointOrg(String orgIds[], String articleId, String collegeCourseId, Map orderMap) { String hql = "select orgId from SchArticleReCourse where articleId = :articleId and deleteFlag is false and orgId in (:orgIds)"; Map args = new HashMap(); args.put("articleId", articleId); args.put("orgIds", orgIds); List strings = findByComplexHql(hql, args, String.class); List orgList = new ArrayList(); for (String orgId : orgIds) { orgList.add(orgId); } // ÌÞ³ýµô²»·ûºÏÌõ¼þµÄorgId orgList.removeAll(strings); if (orgList.isEmpty()) { return; } for (String orgId : orgList) { SchArticleReCourse shrc = new SchArticleReCourse(); shrc.setCollegeCourseId(collegeCourseId); shrc.setDeleteFlag(false); shrc.setArticleId(articleId); shrc.setOrderNum(orderMap.get(articleId)); shrc.setOrgId(orgId); TraceUtils.setCreateTrace(shrc); save(shrc); this.courseWareService.insertOrgCourseware(articleId, ClientUtils.getOrgId(), orgId, collegeCourseId); } } /** * Ö¸¶¨¸ø°à¼¶ * * @param classIds * @param handoutId * @param classMap */ private void insertAppointClass(String classIds[], String articleId, String collegeCourseId, Map orderMap) { // Õ½Úid Map origChapterMap = new HashMap(); SchArticle article = read(SchArticle.class, articleId); String hql = "select classId from SchArticle where deleteFlag is false and originArticleId = :articleId and classId in (:classIds)"; Map args = new HashMap(); args.put("classIds", classIds); args.put("articleId", articleId); List strings = findByComplexHql(hql, args, String.class); List classList = new ArrayList(); for (String classId : classIds) { classList.add(classId); } classList.removeAll(strings); if (classList.isEmpty()) { return; } // Ò»´ÎÐÔ²éѯ°à¼¶ID¶ÔÓ¦µÄclassSubjectId hql = " from SchClassSubject where classId in(:classIds) and origSubjectId = :subjectId and deleteFlag is false"; args = new HashMap(); args.put("classIds", classList.toArray()); args.put("subjectId", article.getSubjectId()); List lstClassSubject = findByComplexHql(hql, args, SchClassSubject.class); Map subjectMap = new HashMap(); for (SchClassSubject schClassSubject : lstClassSubject) { subjectMap.put(schClassSubject.getClassId(), schClassSubject.getClassSubjectId()); } OrgText oldOrgText = orgTextService.getOrgText(articleId, OrgText.TABLE_NAME_ARTICLE); SchArticle sh; for (String classId : classList) { sh = new SchArticle(); sh.setDeleteFlag(false); sh.setName(article.getName()); sh.setClassId(classId); sh.setOrgId(article.getOrgId()); sh.setOriginArticleId(articleId); sh.setSubjectId(subjectMap.get(classId)); sh.setSubjectName(article.getSubjectName()); sh.setCoverPageUrl(article.getCoverPageUrl()); sh.setCollegeCourseId(collegeCourseId); sh.setUrl(article.getUrl()); sh.setOrderNum(1000); if (null != origChapterMap.get(classId)) { sh.setChapterId(origChapterMap.get(classId).getChapterId()); } else { sh.setChapterId(null); } TraceUtils.setCreateTrace(sh); this.saveArticle(sh); // ²åÈëOrgText orgTextService.doInsertOrgText(sh.getArticleId(), OrgText.TABLE_NAME_ARTICLE, oldOrgText == null ? "" : oldOrgText.getContent()); } } /** * »ñÈ¡ÅóÓÑȦ * * @param pager * @return */ @SuppressWarnings("unchecked") public Result articleList(Pager pager, String sortType, String sortField, String collegeCourseId, String subjectId) { List args = new ArrayList(); StringBuffer sb = new StringBuffer(512); sb.append(" SELECT "); sb.append(" aa.ARTICLE_ID, "); sb.append(" aa.NAME, "); sb.append(" aa.COLLEGE_COURSE_ID, "); sb.append(" aa.SUBJECT_ID, "); sb.append(" aa.COVER_PAGE_URL, "); sb.append(" aa.VIEW_COUNT, "); sb.append(" aa.ORDER_NUM, "); sb.append(" aa.CREATE_TIME, "); sb.append(" ss.COMP_DEGREE "); sb.append(" FROM "); sb.append(" ( "); sb.append(" SELECT * FROM sch_article a "); sb.append(" WHERE "); sb.append(" a.CLASS_ID = ? "); sb.append(" AND a.DELETE_FLAG IS FALSE "); sb.append(" ) aa "); sb.append(" LEFT JOIN ( "); sb.append(" SELECT * FROM "); sb.append(" sch_article_statistic s "); sb.append(" WHERE "); sb.append(" s.delete_flag IS FALSE "); sb.append(" AND s.user_id = ? "); sb.append(" ) ss ON ss.article_ID = aa.ARTICLE_ID "); args.add(ClientUtils.getClassId()); args.add(ClientUtils.getUserId()); if (StringUtils.isNotBlank(collegeCourseId)) { sb.append(" and college_CourseId = ?"); args.add(collegeCourseId); } if (StringUtils.isNotBlank(subjectId)) { sb.append(" and SUBJECT_ID = ?"); args.add(subjectId); } if (StringUtils.isNotBlank(sortType) && StringUtils.isNotBlank(sortField)) { sb.append(" order by " + sortField + " " + sortType); } else { sb.append(" order by order_Num "); } List lstSchArticle = this.findByPageSql(sb.toString(), args, pager); List> lstResult = new ArrayList>(); if (lstSchArticle != null && !lstSchArticle.isEmpty()) { for (Object[] obj : lstSchArticle) { lstResult.add(CollectionUtils.newObjectMap("articleId", obj[0], "name", obj[1], "coverPageUrl", obj[3], "viewCount", obj[4], "compDegree", obj[7], "createTime", obj[6])); } } return new Result(true, "", lstResult); } /** * »ñÈ¡ÏûÏ¢µÄÆÀÂÛͼƬºÍÎļþ * * @param objSchClassCircleMsg * @return */ public SchClassCircleMsg packageMsg(SchClassCircleMsg objSchClassCircleMsg) { String msgId = objSchClassCircleMsg.getMsgId(); // List imgs = cache.get(CACHE_MSG_IMGS + msgId, List.class); // // List files = cache.get(CACHE_MSG_FILES + msgId, List.class); List imgs = null; List files = null; @SuppressWarnings("unused") List comments = this.updateComment(msgId, false); if (imgs == null || imgs.isEmpty()) { imgs = this.find("from SchImg where deleteFlag is false and objectId = ? order by createTime asc", CollectionUtils.newList(msgId), SchImg.class); // cache.set(CACHE_MSG_IMGS + msgId, ONE_DAY, imgs); } if (files == null || files.isEmpty()) { files = this.find("from SchFile where deleteFlag is false and objectId = ? order by createTime asc", CollectionUtils.newList(msgId), SchFile.class); // cache.set(CACHE_MSG_FILES + msgId, ONE_DAY, files); } objSchClassCircleMsg.setImgs(imgs); objSchClassCircleMsg.setFiles(files); //objSchClassCircleMsg.setComments(comments); return objSchClassCircleMsg; } /** * µãÔÞ * * @param commentId * @return */ public Result doLike(String commentId) { CommentPraise praiseObj = new CommentPraise(); praiseObj.setCommentId(commentId); praiseObj.setPraise(true); praiseObj.setCommentterId(ClientUtils.getUserId()); praiseObj.setCommentter(ClientUtils.getUserName()); praiseObj.setPraiseTime(new Date(System.currentTimeMillis())); praiseObj.setDeleteFlag(false); TraceUtils.setCreateTrace(praiseObj); this.save(praiseObj); this.bulkUpdate("update Comment set commentPraiseCount = commentPraiseCount +1 where commentId = ?", new Object[] { commentId }); return new Result(true); } /** * ÆÀÂÛ * * @param msgId * @param content * @param parentCommentId * @return */ public Result addComment(String articleId, String content, String parentCommentId) { // ÆÀÂÛ±í Comment comment = new Comment(); comment.setCommentterId(ClientUtils.getUserId()); comment.setCommentter(ClientUtils.getUserName()); comment.setCommentterHeadimg(ClientUtils.getUserImg()); comment.setContent(content); comment.setCommentCount(BigInteger.ZERO); comment.setCommentPraiseCount(BigInteger.ZERO); comment.setCommentObjectId(articleId); comment.setCommentTime(new Date(System.currentTimeMillis())); comment.setCommentParentId(parentCommentId); comment.setClassId(ClientUtils.getClassId()); TraceUtils.setCreateTrace(comment); if (StringUtils.isNotEmpty(parentCommentId)) { Comment parentComment = this.read(Comment.class, parentCommentId); comment.setCommentedName(parentComment.getCommentter()); comment.setCommentedId(parentComment.getCommentterId()); } this.save(comment); this.bulkUpdate("update SchArticle set commentCount = commentCount +1 where articleId = ?", new Object[] { articleId }); this.updateComment(articleId, true); return new Result(true, "", comment); } /** * ɾ³ýÆÀÂÛ * * @param msgId * @param commentId * @return */ public Result deleteComment(String articleId, String commentId) { this.bulkUpdate("update Comment set deleteFlag = 1 where commentId = ? ", new Object[] { commentId }); this.bulkUpdate("update SchArticle set commentCount = commentCount -1 where articleId = ?", new Object[] { articleId }); this.updateComment(articleId, true); return new Result(true); } /** * »º´æ»ñÈ¡ÆÀÂÛ * * @param articleId * @param isUpdate * @return */ private List updateComment(String articleId, boolean isUpdate) { // List comments = cache.get(CACHE_ARTICLE_COMMENTS + articleId, // List.class); List comments = null; if (comments == null || comments.isEmpty() || isUpdate) { comments = this.find( "from Comment where deleteFlag is false and commentObjectId = ? order by createTime asc", CollectionUtils.newList(articleId), Comment.class); // cache.set(CACHE_ARTICLE_COMMENTS + articleId, ONE_DAY, comments); } return comments; } /** * ÆÀÂÛÁбí * * @param articleId * @return */ public Result commentList(String articleId) { return new Result(true, "", this.updateComment(articleId, false)); } /** * ¹Û¿´½ø¶È * * @param articleId * @param compDegree * @return */ public Result doSubmitSchedule(String articleId, double compDegree) { SchArticleStatistic objSchArticleStatistic = this.findUnique( "from SchArticleStatistic where deleteFlag is false and userId = ? and articleId = ?", CollectionUtils.newList(ClientUtils.getUserId(), articleId), SchArticleStatistic.class); if (objSchArticleStatistic == null) { objSchArticleStatistic = new SchArticleStatistic(); objSchArticleStatistic.setClassId(ClientUtils.getClassId()); objSchArticleStatistic.setDeleteFlag(false); objSchArticleStatistic.setArticleId(articleId); objSchArticleStatistic.setCompDegree(compDegree); objSchArticleStatistic.setOrgId(ClientUtils.getOrgId()); objSchArticleStatistic.setUserId(ClientUtils.getUserId()); TraceUtils.setCreateTrace(objSchArticleStatistic); this.save(objSchArticleStatistic); } else { this.bulkUpdate( "update SchArticleStatistic set compDegree = ? where deleteFlag is false and userId = ? and articleId = ?", new Object[] { compDegree, ClientUtils.getUserId(), articleId }); } return new Result(true); } /** * ±£´æÎÄÕÂ½Ó¿Ú * * @param article * @return */ public Result saveArticle(SchArticle article) { Result result = new Result(false); result = this.save(article); String parentChapterId = null; if (StringUtils.isNotEmpty(article.getChapterId())) { SubjectChapter chapter = this.read(SubjectChapter.class, article.getChapterId()); parentChapterId = chapter == null ? null : chapter.getParentChapterId(); } boolean isClass = StringUtils.isNotEmpty(ClientUtils.getClassId()) || StringUtils.isNotEmpty(article.getClassId()); SchCourseware courseware = null; if (isClass) { courseware = this.findUnique("from SchCourseware where id = ? and classId = ? and deleteFlag is false", CollectionUtils.newList(article.getArticleId(), article.getClassId()), SchCourseware.class); } else { courseware = this.findUnique( "from SchCourseware where id = ? and orgId = ? and classId is null and deleteFlag is false", CollectionUtils.newList(article.getArticleId(), ClientUtils.getOrgId()), SchCourseware.class); this.bulkUpdate("update SchCourseware set name = ? where id = ?", new Object[] { article.getName(), article.getArticleId() }); } // ͬ²½¿Î¼þ±í if (courseware == null) { courseware = new SchCourseware(); courseware.setChapterId(article.getChapterId()); courseware.setId(article.getArticleId()); courseware.setCollegeCourseId(article.getCollegeCourseId()); courseware.setcType(-1); courseware.setType(SchCourseware.COURSEWARE_TYPE_ARTICLE); courseware.setName(article.getName()); courseware.setDeleteFlag(article.getDeleteFlag()); courseware.setOrderNum(1000); courseware.setSubjectId(article.getSubjectId()); courseware.setStatus(article.getStatus()); courseware.setOrgId(ClientUtils.getOrgId()); courseware.setClassId(article.getClassId()); courseware.setParentChapterId(parentChapterId); TraceUtils.setCreateTrace(courseware); } else { courseware.setChapterId(article.getChapterId()); // courseware.setCollegeCourseId(article.getCollegeCourseId()); courseware.setcType(-1); courseware.setName(article.getName()); courseware.setDeleteFlag(article.getDeleteFlag()); courseware.setOrderNum(article.getOrderNum() == null ? 1000 : article.getOrderNum()); courseware.setSubjectId(article.getSubjectId()); courseware.setStatus(article.getStatus()); courseware.setParentChapterId(parentChapterId); TraceUtils.setUpdateTrace(courseware); } this.save(courseware); return result; } }