|
|
@ -1,19 +1,117 @@
|
|
|
|
package com.sztzjy.resource_center.controller.api;
|
|
|
|
package com.sztzjy.resource_center.controller.api;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.annotation.AnonymousAccess;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.entity.SysOneCatalog;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.entity.SysOneCatalogExample;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.entity.SysResource;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.entity.SysResourceAndCourse;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.entity.dto.SysResourceDto;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.mapper.SysCaseQuestionMapper;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.mapper.SysOneCatalogMapper;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.mapper.SysResourceAndCourseMapper;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.mapper.SysResourceMapper;
|
|
|
|
|
|
|
|
import com.sztzjy.resource_center.util.file.IFileUtil;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
@Api(tags = "资源方面API")
|
|
|
|
@Api(tags = "资源方面API")
|
|
|
|
@RequestMapping("api/tea/ResourceApi")
|
|
|
|
@RequestMapping("api/tea/ResourceApi")
|
|
|
|
public class ResourceApi {
|
|
|
|
public class ResourceApi {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private SysResourceMapper sysResourceMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private SysResourceAndCourseMapper sysResourceAndCourseMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private SysCaseQuestionMapper sysCaseQuestionMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
SysOneCatalogMapper oneCatalogMapper;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
|
|
private IFileUtil fileUtil;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private SysOneCatalog getSysOneCatalogs(String systemOwner) {
|
|
|
|
|
|
|
|
SysOneCatalogExample example = new SysOneCatalogExample();
|
|
|
|
|
|
|
|
example.createCriteria().andOneNameEqualTo(systemOwner);
|
|
|
|
|
|
|
|
List<SysOneCatalog> sysOneCatalogs = oneCatalogMapper.selectByExample(example);
|
|
|
|
|
|
|
|
return sysOneCatalogs.get(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 上传资源文件
|
|
|
|
* 上传资源文件
|
|
|
|
* 方法名:uploadResource
|
|
|
|
* 方法名:uploadResource
|
|
|
|
* 参数:MultipartFile schoolId courseId resourceType systemOwner
|
|
|
|
* 参数:MultipartFile schoolId twoId resourceType systemOwner
|
|
|
|
* return: boolean
|
|
|
|
* return: boolean
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
|
|
|
@ApiOperation("上传资源文件")
|
|
|
|
|
|
|
|
@PostMapping("uploadResource")
|
|
|
|
|
|
|
|
public Boolean uploadResource(@RequestParam MultipartFile file,
|
|
|
|
|
|
|
|
@RequestParam String schoolId,
|
|
|
|
|
|
|
|
@RequestParam String twoId,
|
|
|
|
|
|
|
|
@RequestParam String twoName,
|
|
|
|
|
|
|
|
@RequestParam String resourceType,
|
|
|
|
|
|
|
|
@RequestParam String systemOwner) {
|
|
|
|
|
|
|
|
if (file == null) {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//取到文件后缀名
|
|
|
|
|
|
|
|
String fileName = file.getName();
|
|
|
|
|
|
|
|
int lastIndex = fileName.lastIndexOf(".");
|
|
|
|
|
|
|
|
String extension = fileName.substring(lastIndex);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SysResource sysResource = new SysResource();
|
|
|
|
|
|
|
|
//判断文件type //todo 格式可能不够全
|
|
|
|
|
|
|
|
if (extension.equals(".pdf") || extension.equals(".ppt") || extension.equals(".pptx")
|
|
|
|
|
|
|
|
|| extension.equals(".xlsx") || extension.equals(".xls")
|
|
|
|
|
|
|
|
|| extension.equals(".doc") || extension.equals(".docx")) {
|
|
|
|
|
|
|
|
sysResource.setResourceType("课件");
|
|
|
|
|
|
|
|
} else if (extension.equals(".mp4") || extension.equals(".wmv") || extension.equals(".avi")) {
|
|
|
|
|
|
|
|
sysResource.setResourceType("视频");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String url = fileUtil.upload(file);
|
|
|
|
|
|
|
|
String uuid = IdUtil.randomUUID();
|
|
|
|
|
|
|
|
sysResource.setResourceId(uuid);
|
|
|
|
|
|
|
|
sysResource.setUrl(url);
|
|
|
|
|
|
|
|
sysResource.setSource(schoolId); //管理员或者 xx学校
|
|
|
|
|
|
|
|
sysResource.setResourceName(fileName);
|
|
|
|
|
|
|
|
sysResource.setStatus(1);
|
|
|
|
|
|
|
|
sysResource.setCreateTime(new Date()); //todo 测试修改资源之后 新增时间会不会变化,有变化就错了
|
|
|
|
|
|
|
|
sysResourceMapper.insert(sysResource);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//绑定资源的对应关系
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
SysResourceAndCourse sysResourceAndCourse = new SysResourceAndCourse();
|
|
|
|
|
|
|
|
SysOneCatalog sysOneCatalogs = getSysOneCatalogs(systemOwner);
|
|
|
|
|
|
|
|
String oneId = sysOneCatalogs.getOneId();
|
|
|
|
|
|
|
|
sysResourceAndCourse.setId(IdUtil.randomUUID());
|
|
|
|
|
|
|
|
sysResourceAndCourse.setOneId(oneId);
|
|
|
|
|
|
|
|
sysResourceAndCourse.setTwoId(twoId);
|
|
|
|
|
|
|
|
sysResourceAndCourse.setOneName(systemOwner);
|
|
|
|
|
|
|
|
sysResourceAndCourse.setTwoName(twoName);
|
|
|
|
|
|
|
|
sysResourceAndCourse.setResourceId(uuid); //资源ID
|
|
|
|
|
|
|
|
sysResourceAndCourseMapper.insert(sysResourceAndCourse);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 查看资源文件列表
|
|
|
|
* 查看资源文件列表
|
|
|
@ -21,6 +119,15 @@ public class ResourceApi {
|
|
|
|
* 参数:schoolId twoId oneId
|
|
|
|
* 参数:schoolId twoId oneId
|
|
|
|
* return: List<SysResource>
|
|
|
|
* return: List<SysResource>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
|
|
|
|
@ApiOperation("查看资源文件列表")
|
|
|
|
|
|
|
|
@PostMapping("selectResource")
|
|
|
|
|
|
|
|
public List<SysResourceDto> selectResource(@RequestParam String oneId, //这里传的是一级的名称
|
|
|
|
|
|
|
|
@RequestParam String twoId,
|
|
|
|
|
|
|
|
@RequestParam String schoolId) {
|
|
|
|
|
|
|
|
SysOneCatalog sysOneCatalogs = getSysOneCatalogs(oneId);
|
|
|
|
|
|
|
|
return sysResourceMapper.selectResource(sysOneCatalogs.getOneId(), twoId, null, schoolId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据章节查看资源文件列表
|
|
|
|
* 根据章节查看资源文件列表
|
|
|
@ -28,12 +135,13 @@ public class ResourceApi {
|
|
|
|
* 参数:threeId oneId
|
|
|
|
* 参数:threeId oneId
|
|
|
|
* return: List<SysResource>
|
|
|
|
* return: List<SysResource>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
@AnonymousAccess
|
|
|
|
/**
|
|
|
|
@ApiOperation("根据章节查看资源文件列表")
|
|
|
|
* 资源文件下载
|
|
|
|
@PostMapping("selectResourceByChapterId")
|
|
|
|
* 方法名:downloadResource
|
|
|
|
public List<SysResourceDto> selectResourceByChapterId(@RequestParam String oneId, //这里传的是一级的名称
|
|
|
|
* 参数:resourceDataName resourceId response
|
|
|
|
@RequestParam String threeId,
|
|
|
|
* return: void
|
|
|
|
@RequestParam String source) {
|
|
|
|
* method GET
|
|
|
|
SysOneCatalog sysOneCatalogs = getSysOneCatalogs(oneId);
|
|
|
|
*/
|
|
|
|
return sysResourceMapper.selectResource(sysOneCatalogs.getOneId(), null, threeId, source);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|