package com.qxueyou.scc.controller; import com.fasterxml.jackson.databind.ObjectMapper; import com.qxueyou.scc.base.model.Result; import com.qxueyou.scc.base.util.ClientUtils; import com.qxueyou.scc.base.util.CollectionUtils; import com.qxueyou.scc.base.util.QBeanUtils; import com.qxueyou.scc.teach.res.model.Res; import com.qxueyou.scc.teach.res.model.ResDatas; import com.qxueyou.scc.teach.res.model.ResDir; import com.qxueyou.scc.teach.res.service.IResService; import io.swagger.annotations.Api; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.io.IOException; import java.util.List; import java.util.Map; /** * ×ÊÔ´¹ÜÀí¿ØÖÆÆ÷ * * @author chenjunliang */ @Api(tags = "×ÊÔ´¹ÜÀí½Ó¿Ú") @RestController @RequestMapping(value = "/teach/res") public class ResController { @Autowired IResService resService; /** * ×ÊÔ´¿â²ã¼¶¹ÜÀíTree */ @GetMapping(value = "categoryLevel") public Result categoryLevel(String parentId) { List dirs = resService.doGetMyLibChildDirs(parentId); return new Result(true, "success", QBeanUtils.listBean2ListMap(dirs, CollectionUtils.newStringMap("name", "name", "dirId", "id"))); } /** * ×ÊÔ´¿â¸ù½Úµã * * @param type ×ÊÔ´¿âÀàÐÍ * user,¸öÈË×ÊÔ´¿â * class,°à¼¶×ÊÔ´¿â * @param ownerId ×ÊÔ´¿âËùÊôÖ÷Ìåid,¸öÈË×ÊÔ´¿â´«userId,°à¼¶×ÊÔ´¿â´«classId */ @GetMapping(value = "rootDir") public Result getRoot(String type, String ownerId) { if ("user".equals(type) && StringUtils.isEmpty(ownerId)) { ownerId = ClientUtils.getUserId(); // System.out.println(ownerId); } ResDir root = resService.doGetRootDir(type, ownerId); // System.out.println(root); return new Result(true, "success", CollectionUtils.newList( QBeanUtils.bean2Map(root, CollectionUtils.newStringMap("name", "name", "dirId", "id")))); } /** * ×ÊÔ´¹ÜÀí»ñÈ¡ ×ÊÔ´Áбí * * @param dirId Ŀ¼id * @param keyword ËÑË÷¹Ø¼ü×Ö * @param limit ÿҳÏÔʾ¼¸Ìõ * @param pageNum Ò³Âë * @param type ÀàÐÍ(0,ÊÓÆµ¡£1,ÒôƵ¡£2,Îĵµ¡£3,Á·Ï°¡£) * @return ×ÊÔ´ÁбíÊý¾Ý */ @GetMapping(value = "lstRes") public Result lstRes(String dirId, String keyword, Integer limit, Integer pageNum, String type) { List resLst = resService.listRes(dirId, keyword, limit, pageNum, type); List> lst = QBeanUtils.listBean2ListMap(resLst, CollectionUtils.newStringMap("resId", "id", "name", "name", "type", "type", "coverPageUrl", "imgPath", "updateTime", "updateTime", "remark", "size", "status", "status")); return new Result(true, "success", CollectionUtils.newObjectMap("resLst", lst, "resCount", resService.listResCount(dirId, keyword, type))); } /** * ×ÊÔ´¹ÜÀíɾ³ý ×ÊÔ´ * * @param id ×ÊÔ´id,Ó¢ÎĶººÅÇø·Ö,¿É´«¶à¸ö */ @GetMapping(value = "deleteFile") public Result deleteRes(String fileId) { return resService.delete(fileId.split(",")); } /** * ×ÊÔ´¹ÜÀí ¸´ÖÆ×ÊÔ´ * * @param resId ×ÊÔ´id * @param dirId Ŀ¼id * @param type ÀàÐÍ */ @GetMapping(value = "copyRes") public Result copyRes(String resId, String dirId, String type) { return resService.doCopy(resId, dirId, null); } /** * ×ÊÔ´¹ÜÀí ×ÊÔ´µÄÒÆ¶¯ * * @param resId ÒªÒÆ¶¯µÄ×ÊÔ´ * @param type Ŀ¼ÀàÐÍ * @param dirId Ŀ¼id */ @GetMapping(value = "moveRes") public Result moveRes(String resId, String type, String dirId) { return resService.doMove(resId, dirId, null); } /** * ×ÊÔ´¹ÜÀíÐÂÔöor±à¼­Ä¿Â¼ * * @param dirId Ŀ¼id * @param name Ŀ¼Ãû * @param type (addÐÂÔö and editÐÞ¸Ä) * @param childFlag ÊÇ·ñ²Ù×÷ϼ¶ */ @GetMapping(value = "addOrUpdateDir") public Result addOrUpdateDir(String type, String name, String dirId, boolean childFlag) { ResDir dir = resService.readDir(dirId); String parentDirId = childFlag ? dirId : dir.getParentDirId(); if ("add".equals(type)) { return resService.addDir(parentDirId, name); } else { return resService.updateDir(dirId, name); } } /** * ×ÊÔ´¹ÜÀí ɾ³ýĿ¼ * * @param dirId Ŀ¼id */ @GetMapping(value = "deleteDir") public Result deleteDir(String dirId) { return resService.deleteDir(dirId.split(",")); } /** * Ìí¼Ó/¸üÐÂ(ÊÓÆµ£¬½²Ò壬ÒôƵ) * * @param dirId ×ÊÔ´¼Ðid * @param name Ãû³Æ * @param coverUrl ·âÃæUrl * @param remark:

* ÊÓÆµ°¡°¡°¡ *

* ½éÉÜ * @param fileId ×ÊÔ´id * @param id ×ÊÔ´id * @param type * @return ״̬˵Ã÷(0, ÊÓÆµ ¡£ 1, ÒôƵ ¡£ 2, Îĵµ ¡£ 3, Á·Ï° ¡£) */ @PostMapping(value = "addOrUpdateRes") public Result addOrUpdateRes(String dirId, String id, String remark, String name, String coverUrl, String type, String fileId) { if (StringUtils.isEmpty(id)) { return resService.add(dirId, fileId, name, remark, type, coverUrl); } else { return resService.update(id, name, remark, coverUrl); } } /** * ÅúÁ¿Ìí¼Ó×ÊÔ´ * * @param dirId ½Úµãid * @param fileId Îļþid * @param fileName ÎļþÃû³Æ * @param fileType ×ÊÔ´ÀàÐÍ */ @PostMapping(value = "addOfBatch") public Result addOfBatch(String dirId, String type, @RequestParam(value = "datas") String datas) { // ת»»jsonµ½¶ÔÏó ObjectMapper mapper = new ObjectMapper(); try { ResDatas resDatas = mapper.readValue(datas, ResDatas.class); return resService.addBatchRes(dirId, type, resDatas.getItems()); } catch (IOException e) { e.printStackTrace(); } return new Result(false); } /** * ±à¼­ »ñÈ¡ÄÚÈÝ * * @param id ×ÊÔ´id */ @GetMapping(value = "getResDetail") public Result getResDetail(String id) { Res res = resService.read(id); Result pathResult = resService.readAccessPath(id, null); return new Result(true, "success", CollectionUtils.newObjectMap("type", res.getType(), "name", res.getName(), "coverUrl", res.getCoverPageUrl(), "remark", res.getRemark(), "fullPath", pathResult.getDataT("path"))); } }