integrated_traffic/src/main/java/com/zcloud/controller/eduStudy/CurriculumController.java

291 lines
12 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.zcloud.controller.eduStudy;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zcloud.controller.base.BaseController;
import com.zcloud.entity.Page;
import com.zcloud.entity.PageData;
import com.zcloud.service.eduStudy.ChapterService;
import com.zcloud.service.eduStudy.CurriculumPrivateService;
import com.zcloud.service.eduStudy.CurriculumService;
import com.zcloud.service.eduStudy.VideoCoursewareService;
import com.zcloud.util.*;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 说明:课程管理
* 作者luoxiaobao
* 时间2021-07-03
* 官网www.zcloudchina.com
*/
@Controller
@RequestMapping("/curriculum")
public class CurriculumController extends BaseController {
@Autowired
private CurriculumService curriculumService;
@Autowired
private VideoCoursewareService videocoursewareService;
@Autowired
private ChapterService chapterService;
@Autowired
private CurriculumPrivateService curriculumPrivateService;
@Autowired
private Smb smb;
/**
* 列表
*
* @param page
* @throws Exception
*/
@RequestMapping(value = "/list")
// @RequiresPermissions("curriculum:list")
@ResponseBody
public Object list(Page page) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
String KEYWORDS = pd.getString("KEYWORDS"); //关键词检索条件
if (Tools.notEmpty(KEYWORDS)) pd.put("KEYWORDS", KEYWORDS.trim());
if (StringUtils.isNotBlank(pd.getString("STARTTIME"))) {
pd.put("STARTTIME", pd.getString("STARTTIME") + " 00:00:00");
}
if (StringUtils.isNotBlank(pd.getString("ENDTIME"))) {
pd.put("ENDTIME", pd.getString("ENDTIME") + " 23:59:59");
}
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
page.setPd(pd);
List<PageData> varList = curriculumService.list(page); //列出Curriculum列表
map.put("varList", varList);
map.put("page", page);
map.put("result", errInfo);
return map;
}
/**
* 新增
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/add")
@ResponseBody
@Transactional
public Object add(@RequestParam(value = "FFILE", required = false) MultipartFile FFILE) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
pd.put("CURRICULUM_ID", this.get32UUID()); //主键
pd.put("CREATOR", Jurisdiction.getUsername()); //添加人
pd.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间
pd.put("OPERATOR", Jurisdiction.getUsername()); //修改人
pd.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
pd.put("ISDELETE", "0"); //是否删除(0:有效 1删除)
pd.put("ISCOMPLETE", "1"); //是否完善 0 否 1是
pd.put("IS_CORP_CREATE", "1"); //是否完善 0 否 1是
pd.put("STATE", "1"); //状态 1-启用 2-禁用
pd.put("CURRICULUM_ID_REMOTE", ""); //同步课程id
if (null != FFILE && !FFILE.isEmpty()) {
String ffile = DateUtil.getDays();
//本地
// String filePath = PathUtil.getProjectpath() + Const.FILEPATHCURRICULUM + Jurisdiction.getCORPINFO_ID() + "/" + ffile; //文件上传路径
// String fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); //执行上传
//服务器
String fileName = this.get32UUID() + FFILE.getOriginalFilename().substring(FFILE.getOriginalFilename().lastIndexOf("."));
smb.sshSftp(FFILE, fileName, Const.FILEPATHCURRICULUM + ffile);
pd.put("COVERPATH", Const.FILEPATHCURRICULUM + ffile + "/" + fileName);
}
// 保存课程
PageData indFull = videocoursewareService.getIndFullByLast(pd);
pd.put("INDUSTRY_ALL_NAME", pd.getString("INDUSTRY_ALL_NAME"));
pd.put("INDUSTRY_ALL_TYPE", pd.getString("INDUSTRY_ALL_TYPE"));
pd.put("CLASSHOUR", "0");
pd.put("VIDEOTIME", "0");
if (pd.get("chapterList") != null && !pd.get("chapterList").equals("")) {
List<JSONObject> chapterList = (List<JSONObject>) JSON.parse(pd.get("chapterList").toString());
for (JSONObject json : chapterList) {
PageData chapter = new PageData();
chapter.put("CHAPTER_ID", this.get32UUID());
chapter.put("CURRICULUM_ID", pd.get("CURRICULUM_ID"));
chapter.put("NAME", json.get("NAME"));
chapter.put("SORT", json.get("SORT"));
chapter.put("CREATOR", Jurisdiction.getUsername()); //添加人
chapter.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间
chapter.put("OPERATOR", Jurisdiction.getUsername()); //修改人
chapter.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
chapter.put("ISDELETE", "0"); //是否删除(0:有效 1删除)
chapter.put("PARENT_ID", "0");
if (json.get("VIDEOCOURSEWARE_ID") != null && Tools.notEmpty(json.get("VIDEOCOURSEWARE_ID").toString())) {
chapter.put("VIDEOCOURSEWARE_ID", json.get("VIDEOCOURSEWARE_ID"));
PageData cv = videocoursewareService.findById(chapter);
chapter.put("COURSEWARENAME", cv.get("COURSEWARENAME"));
chapter.put("VIDEOFILES", cv.get("VIDEOFILES"));
chapter.put("CLASSHOUR", cv.get("CLASSHOUR"));
chapter.put("VIDEOTIME", cv.get("VIDEOTIME"));
}
// 保存章节
chapterService.save(chapter);
if (json.get("nodes") != null && Tools.notEmpty(json.get("nodes").toString())) {
List<JSONObject> nodes = (List<JSONObject>) JSON.parse(json.get("nodes").toString());
for (JSONObject children : nodes) {
PageData childrenChapter = new PageData();
childrenChapter.put("CHAPTER_ID", this.get32UUID());
childrenChapter.put("CURRICULUM_ID", pd.get("CURRICULUM_ID"));
childrenChapter.put("NAME", children.get("NAME"));
childrenChapter.put("SORT", children.get("SORT"));
childrenChapter.put("CREATOR", Jurisdiction.getUsername()); //添加人
childrenChapter.put("CREATTIME", DateUtil.date2Str(new Date())); //添加时间
childrenChapter.put("OPERATOR", Jurisdiction.getUsername()); //修改人
childrenChapter.put("OPERATTIME", DateUtil.date2Str(new Date())); //修改时间
childrenChapter.put("ISDELETE", "0"); //是否删除(0:有效 1删除)
childrenChapter.put("PARENT_ID", chapter.get("CHAPTER_ID"));
if (children.get("VIDEOCOURSEWARE_ID") != null && Tools.notEmpty(children.get("VIDEOCOURSEWARE_ID").toString())) {
childrenChapter.put("VIDEOCOURSEWARE_ID", children.get("VIDEOCOURSEWARE_ID"));
PageData scv = videocoursewareService.findById(childrenChapter);
childrenChapter.put("COURSEWARENAME", scv.get("COURSEWARENAME"));
childrenChapter.put("VIDEOFILES", scv.get("VIDEOFILES"));
childrenChapter.put("CLASSHOUR", scv.get("CLASSHOUR"));
childrenChapter.put("VIDEOTIME", scv.get("VIDEOTIME"));
}
chapterService.save(childrenChapter);
}
}
}
}
PageData curTime = chapterService.getTimeSum(pd);
pd.put("CLASSHOUR", curTime.get("CLASSHOUR"));
pd.put("VIDEOTIME", curTime.get("VIDEOTIME"));
curriculumService.save(pd);
// 添加到机构中
curriculumPrivateService.add(pd.getString("CURRICULUM_ID"));
map.put("pd", pd);
map.put("result", errInfo);
return map;
}
/**
* 去修改页面获取数据
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/goEdit")
@ResponseBody
public Object goEdit() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
pd.put("CORPINFO_ID", Jurisdiction.getCORPINFO_ID());
pd = curriculumService.findById(pd); //根据ID读取
pd.put("CURRICULUMID", pd.get("CURRICULUM_ID"));
pd.put("PARENT_ID", "0");
List<PageData> chapterList = chapterService.listAll(pd);
// 二级目录结构时,查询子级目录
if (pd != null && pd.get("CATALOGUELEVEL") != null
&& Tools.notEmpty(pd.get("CATALOGUELEVEL").toString())
&& "2".equals(pd.get("CATALOGUELEVEL").toString())
&& chapterList != null && chapterList.size() > 0) {
for (PageData chapter : chapterList) {
PageData firstChapter = new PageData();
firstChapter.put("CURRICULUM_ID", chapter.get("CURRICULUM_ID"));
firstChapter.put("PARENT_ID", chapter.get("CHAPTER_ID"));
List<PageData> nodesList = chapterService.listAll(firstChapter);
chapter.put("nodes", nodesList);
}
}
pd.put("RECORD_ID", pd.getString("CURRICULUM_ID"));
// List<PageData> coursewareAllList = coursewarerelationService.listAll(pd);//课件字典关系信息,全部的信息
// map.put("coursewareAllList", coursewareAllList);
map.put("pd", pd);
map.put("chapterList", chapterList);
map.put("result", errInfo);
return map;
}
/**
* 修改
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/edit")
@ResponseBody
public Object edit(@RequestParam(value = "FFILE", required = false) MultipartFile FFILE) throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
// 只能修改课程相关信息
if (null != FFILE && !FFILE.isEmpty()) {
String ffile = DateUtil.getDays();
//本地
// String filePath = PathUtil.getProjectpath() + Const.FILEPATHCURRICULUM + Jurisdiction.getCORPINFO_ID() + "/" + ffile; //文件上传路径
// String fileName = FileUpload.fileUp(file, filePath, this.get32UUID()); //执行上传
//服务器
String fileName = this.get32UUID() + FFILE.getOriginalFilename().substring(FFILE.getOriginalFilename().lastIndexOf("."));
smb.sshSftp(FFILE, fileName, Const.FILEPATHCURRICULUM + ffile);
pd.put("COVERPATH", Const.FILEPATHCURRICULUM + ffile + "/" + fileName);
}
curriculumService.edit(pd);
map.put("pd", pd);
map.put("result", errInfo);
return map;
}
/**
* 修改
*
* @param
* @throws Exception
*/
@RequestMapping(value = "/delById")
@ResponseBody
public Object delById() throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
String errInfo = "success";
PageData pd = new PageData();
pd = this.getPageData();
PageData curriculum = curriculumService.findById(pd); //根据ID读取
if (
curriculum.get("IS_CORP_CREATE") != null &&
Integer.valueOf(curriculum.get("IS_CORP_CREATE").toString()) == 1
) {
curriculumService.delById(pd);
}
map.put("result", errInfo);
return map;
}
}