package com.qxueyou.scc.courseware.service.impl;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.stereotype.Service;
|
|
import com.qxueyou.scc.admin.classes.model.ClsClass;
|
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.base.util.UUIDUtils;
|
import com.qxueyou.scc.base.util.WordProcessUtils;
|
import com.qxueyou.scc.exercise.model.ExerciseGroup;
|
import com.qxueyou.scc.media.model.MediaVideo;
|
import com.qxueyou.scc.media.service.IMediaVideoService;
|
import com.qxueyou.scc.org.dao.OrgDAO;
|
import com.qxueyou.scc.org.model.OrgCategoryLevel;
|
import com.qxueyou.scc.org.model.OrgCollegeCourse;
|
import com.qxueyou.scc.org.model.OrgCourseCategory;
|
import com.qxueyou.scc.org.model.Organization;
|
import com.qxueyou.scc.courseware.service.ICourceCategoryService;
|
import com.qxueyou.scc.school.model.SchHandout;
|
import com.qxueyou.scc.school.service.IHandoutService;
|
import com.qxueyou.scc.sys.model.SysCondition;
|
|
@Service(value = "courceCategoryAppService")
|
public class CourceCategoryAppService extends CommonAppService implements ICourceCategoryService {
|
|
private OrgDAO orgDAO;
|
|
/**
|
* IHandoutService·þÎñ
|
*/
|
@Autowired
|
IHandoutService handoutService;
|
|
@Autowired
|
private IMediaVideoService mediaVideoService;
|
|
public OrgDAO getOrgDAO() {
|
return orgDAO;
|
}
|
|
/**
|
* ÒÀÀµ×¢Èë
|
*
|
* @param commonDAO
|
*/
|
@Autowired(required = false)
|
public void setOrgDAO(@Qualifier("orgDAO")
|
OrgDAO orgDAO) {
|
this.orgDAO = orgDAO;
|
}
|
|
@Override
|
public List<OrgCollegeCourse> queryOrgCourseList(String hql, List<Object> args) {
|
return orgDAO.queryOrgCourseList(hql, args);
|
}
|
|
@Override
|
public List<OrgCourseCategory> queryOrgCourseCategoryList(String hql,
|
List<Object> args) {
|
return orgDAO.queryOrgCourseCategoryList(hql, args);
|
}
|
|
@Override
|
public List<OrgCollegeCourse> queryOrgCourseListNew(String hql, List<Object> args) {
|
return orgDAO.queryOrgCourseListNew(hql, args);
|
}
|
|
/**
|
* ×é×° È«²¿¿Î³Ì ËùÓвéѯÌõ¼þ
|
*
|
* @return
|
* @version 2.0
|
*/
|
public Map<String,Object> generateAllCourseCondition(){
|
|
Map<String,Object> result = new HashMap<String,Object>(3);
|
|
// 1.¿Î³Ì·ÖÀà
|
String firstHql = "select c from OrgCourseCategory c where c.deleteFlag is false and c.categoryLevel = ? order by c.code asc ";
|
List<OrgCourseCategory> lstFirstCategory = this.find(firstHql,
|
CollectionUtils.newList(OrgCourseCategory.CATEGORY_LEVEL_FIRST) , OrgCourseCategory.class);
|
|
String secondHql = "select c from OrgCourseCategory c where c.deleteFlag is false and c.categoryLevel = ? and type <> ? order by c.code asc ";
|
List<OrgCourseCategory> lstSecondCategory = this.find(secondHql,
|
CollectionUtils.newList(OrgCourseCategory.CATEGORY_LEVEL_SECOND,Organization.ORG_TYPE_DEGREE_EDUCATION) , OrgCourseCategory.class);
|
|
|
// 1.1 µÚ¶þ²ã
|
Map<String,List<OrgCourseCategory>> secondMap = new HashMap<String,List<OrgCourseCategory>>(lstFirstCategory.size());
|
for(OrgCourseCategory second : lstSecondCategory ){
|
if(StringUtils.isNotBlank(second.getParentCategoryId()) && null == secondMap.get(second.getParentCategoryId())){
|
secondMap.put(second.getParentCategoryId(), CollectionUtils.newList(OrgCourseCategory.class, second));
|
}else if(StringUtils.isNotBlank(second.getParentCategoryId())){
|
secondMap.get(second.getParentCategoryId()).add(second);
|
}
|
}
|
|
// ×é×°µÄÊý¾Ý¸ñʽ
|
Map<String,Object> sMap;
|
List<Map<String,Object>> lstS ;
|
|
Map<String,Object> fMap;
|
List<Map<String,Object>> lstF = new ArrayList<Map<String,Object>>();
|
|
int fIndex = 0;
|
int sIndex = 0;
|
|
// Ñ»·
|
for(OrgCourseCategory first : lstFirstCategory){
|
|
fIndex = fIndex + 1 ;
|
sIndex = 0;
|
fMap = new HashMap<String,Object>();
|
lstS = new ArrayList<Map<String,Object>>();
|
|
fMap.put("index", fIndex );
|
fMap.put("categoryId", first.getCategoryId());
|
fMap.put("categoryName", first.getCategoryName());
|
fMap.put("code", first.getCode());
|
fMap.put("parentId", null);
|
|
// µÚ¶þ²ã
|
if(null != secondMap.get(first.getCategoryId()) ){
|
for(OrgCourseCategory second : secondMap.get(first.getCategoryId())){
|
|
sIndex = sIndex + 1 ;
|
sMap = new HashMap<String,Object>();
|
|
sMap.put("index", sIndex );
|
sMap.put("categoryId", second.getCategoryId());
|
sMap.put("categoryName", second.getCategoryName());
|
sMap.put("code", second.getCode());
|
sMap.put("parentId", second.getParentCategoryId());
|
lstS.add(sMap);
|
}
|
}
|
|
fMap.put("children", lstS);
|
|
lstF.add(fMap);
|
}
|
|
result.put("course", lstF);
|
|
// 2.ÅÅÐò
|
List<Map<String,Object>> lstSort = new ArrayList<Map<String,Object>>(5);
|
Map<String,Object> sort;
|
|
String sortHql = "from SysCondition s where s.deleteFlag is false and s.module = ? order by s.order asc ";
|
List<SysCondition> lstSorts = this.find(sortHql, CollectionUtils.newList(SysCondition.MODULE_COURSE_MARKET_SORT), SysCondition.class);
|
|
for(SysCondition s : lstSorts ){
|
sort = new HashMap<String,Object>(3);
|
sort.put("index", s.getOrder());
|
sort.put("code", s.getCode());
|
sort.put("name", s.getName());
|
lstSort.add(sort);
|
}
|
result.put("sort", lstSort);
|
|
// 3.µØÇø
|
List<Map<String,Object>> lstCity = new ArrayList<Map<String,Object>>(6);
|
Map<String,Object> city;
|
|
String cityHql = "from SysCondition s where s.deleteFlag is false and s.module = ? order by s.order asc ";
|
List<SysCondition> lstCitys = this.find(cityHql, CollectionUtils.newList(SysCondition.MODULE_COURSE_MARKET_CITY), SysCondition.class);
|
|
for(SysCondition s : lstCitys ){
|
city = new HashMap<String,Object>(3);
|
city.put("index", s.getOrder());
|
city.put("code", s.getCode());
|
city.put("name", s.getName());
|
lstCity.add(city);
|
}
|
result.put("city", lstCity);
|
|
|
return result ;
|
}
|
|
public Result insertLevelCategory(String id,String name,String code,String type){
|
Organization org = read(Organization.class, ClientUtils.getOrgId());
|
Result result = new Result(true);
|
//±£´æ
|
if("save".equals(type)){
|
OrgCategoryLevel ocl = read(OrgCategoryLevel.class, id);
|
ocl.setCategoryName(name);
|
ocl.setCode(code);
|
save(ocl);
|
result.setData(ocl);
|
return result;
|
}
|
//Ôö¼Óͬ¼¶
|
if("add".equals(type)){
|
OrgCategoryLevel ocl0 = read(OrgCategoryLevel.class, id);
|
OrgCategoryLevel ocl = new OrgCategoryLevel();
|
ocl.setCategoryName(name);
|
ocl.setCode(code);
|
ocl.setDeleteFlag(false);
|
ocl.setFullName(name);
|
ocl.setImgPath(null);
|
ocl.setLevel(ocl0.getLevel());
|
ocl.setParentId(ocl0.getParentId());
|
OrgCategoryLevel parent = read(OrgCategoryLevel.class, ocl0.getParentId());
|
ocl.setOrgId(ClientUtils.getOrgId());
|
ocl.setTopOrgId(org.getTopOrganizationId());
|
TraceUtils.setCreateTrace(ocl);
|
|
result.setData(insertOcl(ocl,parent,name));
|
return result;
|
}
|
|
//Ôö¼Óϼ¶
|
if("addNext".equals(type)){
|
OrgCategoryLevel parent = read(OrgCategoryLevel.class, id);
|
OrgCategoryLevel ocl = new OrgCategoryLevel();
|
ocl.setCategoryName(name);
|
ocl.setCode(code);
|
ocl.setDeleteFlag(false);
|
ocl.setFullName(name);
|
ocl.setImgPath(null);
|
ocl.setParentId(id);
|
|
ocl.setOrgId(ClientUtils.getOrgId());
|
ocl.setTopOrgId(org.getTopOrganizationId());
|
TraceUtils.setCreateTrace(ocl);
|
|
result.setData(insertOcl(ocl,parent,name));
|
return result;
|
}
|
|
return new Result(false,"²ÎÊý´íÎó");
|
|
|
}
|
|
private OrgCategoryLevel insertOcl(OrgCategoryLevel ocl,OrgCategoryLevel parent,String name){
|
int loop = 0;
|
String levelCode = "";
|
String origLevelCode = "";
|
OrgCategoryLevel origCateLevel ;
|
//BeanUtils.copyProperties(ocl, origCateLevel);
|
if(parent==null){
|
// Êײ㣺ֱ½ÓÉú³É
|
levelCode = UUIDUtils.generateUUID();
|
origLevelCode = levelCode;
|
}else{
|
// ϲ㣺¸ù¾ÝparentÉú³É
|
levelCode = parent.getLevelCode()+"00";
|
}
|
do {
|
|
try {
|
|
origCateLevel = new OrgCategoryLevel();
|
BeanUtils.copyProperties(ocl , origCateLevel);
|
if(parent==null){ // Êײ㣺ֱ½ÓÉú³É
|
origCateLevel.setLevel(BigDecimal.ONE.shortValue());
|
origCateLevel.setLevelCode(levelCode+"_00");
|
}else{ // ϲ㣺¸ù¾ÝparentÉú³É
|
origCateLevel.setLevel(new BigDecimal(parent.getLevel()).add(BigDecimal.ONE).shortValue());
|
origCateLevel.setLevelCode(levelCode);
|
}
|
save(origCateLevel);
|
flush();
|
|
return origCateLevel ;
|
// break;
|
|
} catch (Exception e) {
|
|
clearCache();
|
|
loop++;
|
if(parent==null){
|
// Êײ㣺ֱ½ÓÉú³É
|
levelCode = origLevelCode.concat(String.valueOf(loop));
|
}else{
|
// ϲ㣺¸ù¾ÝparentÉú³É
|
String h = String.valueOf(loop);
|
if(loop<10){
|
h = "0"+loop;
|
}
|
levelCode = parent.getLevelCode().concat(h);
|
}
|
|
}
|
|
} while (loop < 1000);
|
|
return null ;
|
}
|
|
@SuppressWarnings("unused")
|
private String generateLevelCode(String name) {
|
|
// תƴÒô
|
//ʹÓÃ΢Èí×Ô´øÖÐÎÄÊäÈë·¨ÓÃÊó±ê·Ò³£¬Ñ¡ÔñµÚÒ»Ò³Ö®ºóµÄÊý¾Ýʱ£¬»áÉú³É(li'zhi.dr)ÕâÖÖÕ˺Å
|
String[] arrUnidecode = WordProcessUtils.toPinyin(name," ").replaceAll("'", "").split(" ");
|
|
String orgCode = "";
|
if(null != arrUnidecode){
|
for(String str : arrUnidecode){
|
orgCode = orgCode.concat(str.substring(0,1));
|
}
|
}
|
|
|
return orgCode;
|
}
|
|
public Result doDeleteCate(String id){
|
boolean flag = false;
|
String hql = " from OrgCategoryLevel where deleteFlag is false and (categoryLevelId = ? or parentId = ?)";
|
List<OrgCategoryLevel> lstCate = find(hql, CollectionUtils.newList(id,id), OrgCategoryLevel.class);
|
for (OrgCategoryLevel orgCategoryLevel : lstCate) {
|
hql = " from OrgCollegeCourse where deleteFlag is false and courseCategoryId = ?";
|
List<OrgCollegeCourse> course = find(hql, CollectionUtils.newList(orgCategoryLevel.getCategoryLevelId()), OrgCollegeCourse.class);
|
for (OrgCollegeCourse orgCollegeCourse : course) {
|
hql = " from ClsClass where collegeCourseId = ? and deleteFlag is false";
|
List<ClsClass> classes = find(hql, CollectionUtils.newList(orgCollegeCourse.getCollegeCourseId()), ClsClass.class);
|
if(!classes.isEmpty()){
|
flag = true;
|
break;
|
}
|
|
}
|
if(flag){
|
break;
|
}
|
|
}
|
if(flag){
|
return new Result(false,"¸Ã·ÖÀàϵĿÆÄ¿Ï´æÔڰ༶,ÇëÏÈɾ³ý°à¼¶");
|
}
|
for (OrgCategoryLevel orgCategoryLevel : lstCate) {
|
hql = " from OrgCollegeCourse where deleteFlag is false and courseCategoryId = ?";
|
List<OrgCollegeCourse> course = find(hql, CollectionUtils.newList(orgCategoryLevel.getCategoryLevelId()), OrgCollegeCourse.class);
|
for (OrgCollegeCourse orgCollegeCourse : course) {
|
doDeleteCourse(orgCollegeCourse.getCollegeCourseId());
|
}
|
orgCategoryLevel.setDeleteFlag(true);
|
TraceUtils.setUpdateTrace(orgCategoryLevel);
|
save(orgCategoryLevel);
|
|
}
|
return new Result(true);
|
}
|
|
public Result doDeleteCourse(String id){
|
String hql = " from ClsClass where deleteFlag is false and collegeCourseId = ?";
|
ClsClass cls = findUnique(hql, CollectionUtils.newList(id), ClsClass.class);
|
if(cls!=null){
|
return new Result(false,"¸Ã¿ÆÄ¿Ï´æÔڰ༶,ÇëÏÈɾ³ý°à¼¶");
|
}
|
//ɾ³ýËùÓÐÊÓÆµ
|
doDeleteVideo(id);
|
//ɾ³ýËùÓÐÁ·Ï°
|
doDeleteExe(id);
|
//ɾ³ýËùÓн²Òå
|
doDeleteHandout(id);
|
|
hql = " from OrgCollegeCourse where deleteFlag is false and collegeCourseId = ?";
|
OrgCollegeCourse course = findUnique(hql, CollectionUtils.newList(id), OrgCollegeCourse.class);
|
course.setDeleteFlag(true);
|
TraceUtils.setUpdateTrace(course);
|
return save(course);
|
}
|
|
private void doDeleteVideo(String id){
|
String hql = " from MediaVideo where (videoId in "
|
+ " (select videoId from MediaVideoReCourse where collegeCourseId = ? and deleteFlag is false)"
|
+ " or originVideoId in (select videoId from MediaVideoReCourse where collegeCourseId = ? and deleteFlag is false))"
|
+ " and deleteFlag is false";
|
List<MediaVideo> lstVideo = find(hql, CollectionUtils.newList(id,id), MediaVideo.class);
|
for (MediaVideo mv : lstVideo) {
|
mv.setDeleteFlag(true);
|
TraceUtils.setUpdateTrace(mv);
|
this.mediaVideoService.saveVideo(mv);
|
}
|
}
|
private void doDeleteExe(String id){
|
String hql = " from ExerciseGroup where (groupId in (select groupId from ExerciseReCourse where collegeCourseId = ? and deleteFlag is false)"
|
+ " or originExerciseId in (select groupId from ExerciseReCourse where collegeCourseId = ? and deleteFlag is false))"
|
+ " and deleteFlag is false";
|
List<ExerciseGroup> groups = find(hql,CollectionUtils.newList(id,id),ExerciseGroup.class);
|
for (ExerciseGroup g : groups){
|
g.setDeleteFlag(true);
|
TraceUtils.setUpdateTrace(g);
|
save(g);
|
}
|
}
|
|
private void doDeleteHandout(String id){
|
String hql = " from SchHandout where (handoutId in "
|
+ "(select handoutId from SchHandoutReCourse where collegeCourseId = ? and deleteFlag is false"
|
+ ") or originHandoutId in (select handoutId from SchHandoutReCourse where collegeCourseId = ? and deleteFlag is false ))"
|
+ "and deleteFlag is false";
|
List<SchHandout> handouts = find(hql,CollectionUtils.newList(id,id),SchHandout.class);
|
for(SchHandout handout : handouts){
|
handout.setDeleteFlag(true);
|
TraceUtils.setUpdateTrace(handout);
|
this.handoutService.saveHandout(handout);
|
}
|
}
|
|
/**
|
* ÐÂÔö¿ÆÄ¿
|
* @param id
|
* @param name
|
* @param code
|
* @param type
|
* @return
|
*/
|
@Override
|
public Result addCategory(Organization org, String id, String name, String code, String type) {
|
Result result = new Result(true);
|
//±£´æ
|
if("save".equals(type)){
|
OrgCategoryLevel ocl = this.read(OrgCategoryLevel.class, id);
|
ocl.setCategoryName(name);
|
ocl.setCode(code);
|
this.save(ocl);
|
result.setData(ocl);
|
return result;
|
}
|
//Ôö¼Óͬ¼¶
|
if("add".equals(type)){
|
OrgCategoryLevel ocl0 = this.read(OrgCategoryLevel.class, id);
|
OrgCategoryLevel ocl = new OrgCategoryLevel();
|
ocl.setCategoryName(name);
|
ocl.setCode(code);
|
ocl.setDeleteFlag(false);
|
ocl.setFullName(name);
|
ocl.setImgPath(null);
|
ocl.setLevel(ocl0.getLevel());
|
ocl.setParentId(ocl0.getParentId());
|
OrgCategoryLevel parent = this.read(OrgCategoryLevel.class, ocl0.getParentId());
|
TraceUtils.setCreateTrace(ocl);
|
|
result.setData(insertOcl(ocl,parent,name));//²åÈëocl
|
return result;
|
}
|
|
//Ôö¼Óϼ¶
|
if("addNext".equals(type)){
|
OrgCategoryLevel parent = this.read(OrgCategoryLevel.class, id);
|
OrgCategoryLevel ocl = new OrgCategoryLevel();
|
ocl.setCategoryName(name);
|
ocl.setCode(code);
|
ocl.setDeleteFlag(false);
|
ocl.setFullName(name);
|
ocl.setImgPath(null);
|
ocl.setParentId(id);
|
TraceUtils.setCreateTrace(ocl);
|
|
result.setData(insertOcl(ocl,parent,name));
|
return result;
|
}
|
|
return new Result(false);
|
}
|
|
}
|