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<SchArticle> queryClassListData() {
|
|
List<SchArticle> 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<Map<String, Object>> queryArticleOrgLst(String collegeCourseId, String subjectId) {
|
List<Object[]> handoutLst = null;
|
|
List<Object> args = new ArrayList<Object>();
|
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<Map<String, Object>> lstMap = new ArrayList<Map<String, Object>>(handoutLst.size());
|
Map<String, Object> map = null;
|
|
for (Object[] obj : handoutLst) {
|
map = new HashMap<String, Object>();
|
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<String> ids, List<Integer> 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, "修改成功");
|
}
|
|
/**
|
* 删除机构文章信息
|
*
|
* @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<String, Object> args = new HashMap<String, Object>();
|
// 删除需要回撤的机构讲义
|
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<String, Object>();
|
args.put("articleId", articleId);
|
args.put("orgIds", orgIds);
|
args.put("currOrgId", ClientUtils.getOrgId());
|
List<SchArticleReCourse> 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<String, Object>();
|
args.put("articleId", articleId);
|
args.put("classIds", classIds);
|
String hql = " from SchArticle where originArticleId = :articleId and deleteFlag is false and classId in (:classIds)";
|
List<SchArticle> 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<String> orgIds = this.findBySql(sql, CollectionUtils.newList(currOrgId));
|
|
String hql = " from SchArticleReCourse where articleId = :articleId and deleteFlag is false and orgId in (:orgIds)";
|
Map<String, Object> map = new HashMap<String, Object>();
|
map.put("articleId", articleId);
|
map.put("orgIds", orgIds.toArray());
|
List<SchArticleReCourse> 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<String, Object>();
|
map.put("orgIds", orgIds.toArray());
|
List<String> 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<String, Object>();
|
map.put("articleId", articleId);
|
map.put("classIds", clsIds.toArray());
|
List<SchArticle> 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<String, Object> argsMap = new HashMap<String, Object>();
|
Map<String, String> classMap = new HashMap<String, String>();
|
if (classIds.length > 0) {
|
String hql = " from ClsClass where classId in (:classIds) and deleteFlag is false";
|
argsMap = new HashMap<String, Object>();
|
argsMap.put("classIds", classIds);
|
List<ClsClass> classList = findByComplexHql(hql, argsMap, ClsClass.class);
|
|
// 放入map中 KEY:classId VALUE:orgId
|
|
for (ClsClass orgClass : classList) {
|
classMap.put(orgClass.getClassId(), orgClass.getOrgId());
|
}
|
}
|
|
// 一次性查出handoutId对应的handoutOrder
|
Map<String, Integer> orderMap = new HashMap<String, Integer>();
|
String hql = " from SchArticleReCourse where articleId in (:articleIds) and deleteFlag is false and orgId = :currOrgId";
|
argsMap = new HashMap<String, Object>();
|
argsMap.put("articleIds", articleIds);
|
argsMap.put("currOrgId", ClientUtils.getOrgId());
|
List<SchArticleReCourse> 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<String, Integer> orderMap) {
|
String hql = "select orgId from SchArticleReCourse where articleId = :articleId and deleteFlag is false and orgId in (:orgIds)";
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("articleId", articleId);
|
args.put("orgIds", orgIds);
|
List<String> strings = findByComplexHql(hql, args, String.class);
|
List<String> orgList = new ArrayList<String>();
|
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<String, Integer> orderMap) {
|
// 章节id
|
Map<String, SubjectChapter> origChapterMap = new HashMap<String, SubjectChapter>();
|
SchArticle article = read(SchArticle.class, articleId);
|
|
String hql = "select classId from SchArticle where deleteFlag is false and originArticleId = :articleId and classId in (:classIds)";
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("classIds", classIds);
|
args.put("articleId", articleId);
|
List<String> strings = findByComplexHql(hql, args, String.class);
|
List<String> classList = new ArrayList<String>();
|
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<String, Object>();
|
args.put("classIds", classList.toArray());
|
args.put("subjectId", article.getSubjectId());
|
List<SchClassSubject> lstClassSubject = findByComplexHql(hql, args, SchClassSubject.class);
|
Map<String, String> subjectMap = new HashMap<String, String>();
|
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<Object> args = new ArrayList<Object>();
|
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<Object[]> lstSchArticle = this.findByPageSql(sb.toString(), args, pager);
|
List<Map<String, Object>> lstResult = new ArrayList<Map<String, Object>>();
|
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<SchImg> imgs = cache.get(CACHE_MSG_IMGS + msgId, List.class);
|
//
|
// List<SchFile> files = cache.get(CACHE_MSG_FILES + msgId, List.class);
|
List<SchImg> imgs = null;
|
List<SchFile> files = null;
|
|
@SuppressWarnings("unused")
|
List<Comment> 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<Comment> updateComment(String articleId, boolean isUpdate) {
|
// List<Comment> comments = cache.get(CACHE_ARTICLE_COMMENTS + articleId,
|
// List.class);
|
List<Comment> 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;
|
}
|
}
|