package com.qxueyou.scc.courseware.service.impl;
|
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.springframework.stereotype.Service;
|
|
import com.qxueyou.scc.base.model.Result;
|
import com.qxueyou.scc.base.service.impl.CommonAppService;
|
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.courseware.service.ICourseService;
|
import com.qxueyou.scc.org.model.OrgCategoryLevel;
|
import com.qxueyou.scc.org.model.OrgCollegeCourse;
|
import com.qxueyou.scc.teach.subject.model.Subject;
|
import com.qxueyou.scc.teach.subject.model.SubjectChapter;
|
|
/**
|
* 项目服务类
|
*
|
* @author 岩龙
|
* @createtime 2017-10-31
|
*/
|
@Service
|
public class CourseService extends CommonAppService implements ICourseService {
|
|
public List<Map<String, Object>> queryCategoryList() {
|
String hql = "select categoryLevelId as id ,categoryName as name ,parentId as parentId,'category' as iconSkin,'true' as isParent , 'category' as type "
|
+ "from OrgCategoryLevel " + "where parentId is null and deleteFlag is false";
|
|
List<Map<String, Object>> result = findListWithMapByHql(hql, null);
|
// List<OrgCategoryLevel> result = find(hql,
|
// CollectionUtils.newList(categoryId), OrgCategoryLevel.class);
|
|
return result;
|
|
}
|
|
public Result insertCourseCategory(String parentId, String categoryName) {
|
OrgCategoryLevel vo = new OrgCategoryLevel();
|
|
TraceUtils.setCreateTrace(vo);
|
vo.setDeleteFlag(false);
|
|
vo.setParentId(parentId);
|
vo.setCategoryName(categoryName);
|
vo.setOrgId(ClientUtils.getOrgId());
|
vo.setTopOrgId(ClientUtils.getTopOrgId());
|
|
save(vo);
|
|
return new Result(true);
|
}
|
|
@Override
|
public Result updateCourseCategory(String categoryId, String categoryName) {
|
OrgCategoryLevel categoryLevel = read(OrgCategoryLevel.class, categoryId);
|
|
TraceUtils.setCreateTrace(categoryLevel);
|
categoryLevel.setCategoryName(categoryName);
|
|
save(categoryLevel);
|
|
return new Result(true);
|
}
|
|
@Override
|
public Result deleteCategory(String categoryId) {
|
this.bulkUpdate("update OrgCategoryLevel set deleteFlag is true where categoryLevelId=?",
|
new Object[] { categoryId });
|
|
return new Result(true, "Operation Success");
|
}
|
|
@Override
|
public List<Map<String, Object>> queryCourse(String categoryId) {
|
String hql = "select collegeCourseId as id , name as name ,courseCategoryId as parentId ,'course' as iconSkin,'true' as isParent,'course' as type "
|
+ " from OrgCollegeCourse" + " where courseCategoryId =:categoryId and deleteFlag is false";
|
|
return findListWithMapByHql(hql, CollectionUtils.newObjectMap("categoryId", categoryId));
|
}
|
|
@Override
|
public Result insertCourse(String categoryId, String courseName) {
|
OrgCollegeCourse course = new OrgCollegeCourse();
|
TraceUtils.setCreateTrace(course);
|
course.setDeleteFlag(false);
|
|
course.setCourseCategoryId(categoryId);
|
course.setName(courseName);
|
course.setOrganizationId(ClientUtils.getOrgId());
|
course.setTopOrgId(ClientUtils.getTopOrgId());
|
course.setPrice(BigDecimal.ONE);
|
|
save(course);
|
|
return new Result(true);
|
}
|
|
@Override
|
public Result updateCourse(String courseId, String courseName) {
|
OrgCollegeCourse course = read(OrgCollegeCourse.class, courseId);
|
|
TraceUtils.setUpdateTrace(course);
|
course.setName(courseName);
|
|
save(course);
|
|
return new Result(true, "Operation Success");
|
}
|
|
@Override
|
public Result deleteCourse(String courseId) {
|
|
this.bulkUpdate("update OrgCollegeCourse set deleteFlag is true where collegeCourseId=?",
|
new Object[] { courseId });
|
|
return new Result(true, "Operation Success");
|
}
|
|
@Override
|
public List<Map<String, Object>> querySubject(String courseId) {
|
String hql = "select subjectId as id ,name as name ,collegeCourseId as parentId ,'subject' as iconSkin,'true' as isParent,'subject' as type"
|
+ " from SchSubject " + "where collegeCourseId=:courseId and deleteFlag is false";
|
|
return findListWithMapByHql(hql, CollectionUtils.newObjectMap("courseId", courseId));
|
}
|
|
@Override
|
public Result insertSubject(String courseId, String subjectName) {
|
Subject subject = new Subject();
|
|
TraceUtils.setCreateTrace(subject);
|
subject.setDeleteFlag(false);
|
|
subject.setName(subjectName);
|
|
save(subject);
|
|
return new Result(true, "Operation Success");
|
}
|
|
@Override
|
public Result updateSubject(String subjectId, String subjectName) {
|
Subject subject = read(Subject.class, subjectName);
|
|
TraceUtils.setUpdateTrace(subject);
|
subject.setName(subjectName);
|
|
save(subject);
|
|
return new Result(true);
|
}
|
|
@Override
|
public Result deleteSubject(String subjectId) {
|
|
this.bulkUpdate("update SchSubject set deleteFlag is true where subjectId=?", new Object[] { subjectId });
|
|
return new Result(true, "Operation Success");
|
}
|
|
@Override
|
public List<Map<String, Object>> queryChapter(String subjectId) {
|
String hql = "select chapterId as id ,name as name,parentChapterId as parentId,'chapter' as iconSkin,'true' as isParent,'chapter' as type "
|
+ " from SchChapter "
|
+ "where subjectId =:subjectId and parentChapterId is null and deleteFlag is false ";
|
|
// List<SchChapter> result = find(hql,
|
// CollectionUtils.newList(subjectId), SchChapter.class);
|
|
return findListWithMapByHql(hql, CollectionUtils.newObjectMap("subjectId", subjectId));
|
}
|
|
@Override
|
public List<Map<String, Object>> querychildChapter(String id) {
|
String hql = "select chapterId as id ,name as name,parentChapterId as parentId,'section' as iconSkin,'false' as isParent,'section' as type "
|
+ " from SchChapter " + "where parentChapterId =:parentChapterId and deleteFlag is false ";
|
|
return findListWithMapByHql(hql, CollectionUtils.newObjectMap("parentChapterId", id));
|
}
|
|
@Override
|
public Result insertChapter(String subjectId, String chapterId, String chapterName, String courseId) {
|
SubjectChapter chapter = new SubjectChapter();
|
|
TraceUtils.setCreateTrace(chapter);
|
chapter.setDeleteFlag(false);
|
|
chapter.setSubjectId(subjectId);
|
chapter.setParentChapterId(chapterId);
|
chapter.setName(chapterName);
|
|
save(chapter);
|
|
return new Result(true);
|
}
|
|
@Override
|
public Result updateChapter(String chapterId, String chapterName) {
|
SubjectChapter schChapter = read(SubjectChapter.class, chapterId);
|
|
TraceUtils.setUpdateTrace(schChapter);
|
schChapter.setName(chapterName);
|
|
save(schChapter);
|
|
return new Result(true);
|
}
|
|
@Override
|
public Result deleteChapter(String chapterId) {
|
this.bulkUpdate("update SchChapter set deleteFlag is true where chapterId=?", new Object[] { chapterId });
|
|
return new Result(true, "操作成功!");
|
}
|
|
// 显示有过班级的项目名称
|
@Override
|
public List<Map<String, Object>> queryCourseName() {
|
String hql = "select collegeCourseId as id , name as name from OrgCollegeCourse where deleteFlag is false order by createTime asc";
|
|
return findListWithMapByHql(hql, null);
|
}
|
|
// PC端首页显示有过班级的项目名称
|
@Override
|
public List<Map<String, Object>> findclassNameByCourse(String mode) {
|
String hql = "select distinct c.collegeCourseId as id , c.name as name from OrgCollegeCourse c ,ClsClass o where o.deleteFlag is false and c.deleteFlag is false and o.collegeCourseId =c.collegeCourseId ";
|
|
Map<String,Object> map =new HashMap<String, Object>();
|
if (mode.equals("0")) {
|
hql = hql.concat(" and o.mode = 0 and o.approveStatus = 4 and o.signupEndTime>:nowDate ");
|
map.put("nowDate", new Date());
|
}
|
if (mode.equals("1")) {
|
hql = hql.concat(" and o.mode = 1 and o.approveStatus = 4 ");
|
}
|
List<Map<String, Object>> lstCourse = findListWithMapByHql(hql, map);
|
return lstCourse;
|
}
|
|
/**
|
* 删除科目下的项目
|
*
|
* @param categoryId
|
* @return
|
*/
|
public Result deleteCourseByParentId(String categoryId) {
|
String hql = "from OrgCollegeCourse where courseCategoryId=? and deleteFlag =false ";
|
|
List<OrgCollegeCourse> list = find(hql, CollectionUtils.newList(categoryId), OrgCollegeCourse.class);
|
|
for (OrgCollegeCourse orgCollegeCourse : list) {
|
TraceUtils.setUpdateTrace(orgCollegeCourse);
|
orgCollegeCourse.setDeleteFlag(true);
|
save(orgCollegeCourse);
|
}
|
return new Result(true);
|
}
|
|
/**
|
* 删除项目下的课程
|
*
|
* @param courseId
|
* @return
|
*/
|
public Result deleteSubjectByParentId(String courseId) {
|
String hql = "from SchSubject where collegeCourseId= ? and deleteFlag = false";
|
|
List<Subject> list = find(hql, CollectionUtils.newList(courseId), Subject.class);
|
|
for (Subject schSubject : list) {
|
TraceUtils.setUpdateTrace(schSubject);
|
schSubject.setDeleteFlag(true);
|
save(schSubject);
|
}
|
return new Result(true);
|
}
|
|
/**
|
* 删除节
|
*
|
* @param chapterId
|
* @return
|
*/
|
public Result deleteChapterByParentId(String chapterId) {
|
String hql = "from SchChapter where parentChapterId=? and deleteFlag = false ";
|
|
List<SubjectChapter> list = find(hql, CollectionUtils.newList(chapterId), SubjectChapter.class);
|
|
for (SubjectChapter schChapter : list) {
|
TraceUtils.setUpdateTrace(schChapter);
|
schChapter.setDeleteFlag(true);
|
save(schChapter);
|
}
|
|
return new Result(true);
|
|
}
|
|
/**
|
* 删除树节点
|
*/
|
public Result deleteNode(String id, String type) {
|
if (type.equals("category")) {
|
return this.deleteCategory(id);
|
|
} else if (type.equals("course")) {
|
return this.deleteCourse(id);
|
|
} else if (type.equals("subject")) {
|
return this.deleteSubject(id);
|
|
} else if (type.equals("chapter") || type.equals("section")) {
|
return this.deleteChapter(id);
|
} else {
|
return new Result(false, "Parameter error");
|
}
|
}
|
|
}
|