diff --git a/src/main/java/com/sztzjy/resource_center/controller/api/ResourceApi.java b/src/main/java/com/sztzjy/resource_center/controller/api/ResourceApi.java index 9b05ae0..e06a4cb 100644 --- a/src/main/java/com/sztzjy/resource_center/controller/api/ResourceApi.java +++ b/src/main/java/com/sztzjy/resource_center/controller/api/ResourceApi.java @@ -11,13 +11,17 @@ import com.sztzjy.resource_center.mapper.SysResourceMapper; import com.sztzjy.resource_center.util.file.IFileUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; 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.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.util.Arrays; import java.util.Date; import java.util.List; @@ -28,17 +32,16 @@ import java.util.stream.Collectors; @Api(tags = "资源方面API") @RequestMapping("api/tea/ResourceApi") public class ResourceApi { - @Autowired private SysResourceMapper sysResourceMapper; + @Value("${file.path}") + private String filePath; @Autowired - private SysResourceAndCourseMapper sysResourceAndCourseMapper; + private IFileUtil fileUtil; @Autowired - private SysCaseQuestionMapper sysCaseQuestionMapper; + private SysResourceAndCourseMapper sysResourceAndCourseMapper; @Autowired SysOneCatalogMapper oneCatalogMapper; - @Autowired - private IFileUtil fileUtil; private SysOneCatalog getSysOneCatalogs(String systemOwner) { @@ -190,6 +193,93 @@ public class ResourceApi { } + //下载资源文件 + @GetMapping("downloadResource") + @ApiOperation("下载资源文件") + @AnonymousAccess + public void downloadResource(@ApiParam("资源ID") @RequestParam String resourceId, HttpServletResponse response) { + SysResource sysResource = sysResourceMapper.selectByPrimaryKey(resourceId); + if ("课件".equals(sysResource.getResourceType())) { + fileUtil.download(response, sysResource.getResourceName(), sysResource.getUrl()); + } + if (sysResource.getCount() == null) { + sysResource.setCount(1); + } else { + sysResource.setCount(sysResource.getCount() + 1); + } + sysResourceMapper.updateByPrimaryKey(sysResource); + } + + + + + @GetMapping("/getResource") + @ApiOperation("预览/获取视频或课件") + @AnonymousAccess + public ResponseEntity streamVideo(@ApiParam("资源ID") @RequestParam String id) { + + SysResource sysResource = sysResourceMapper.selectByPrimaryKey(id); + String url = sysResource.getUrl(); + String videoPath = filePath + url; + File videoFile = new File(videoPath); + if ("视频".equals(sysResource.getResourceType())) { + if (videoFile.exists()) { +// Path path = Paths.get(videoPath); + FileSystemResource fileSystemResource = new FileSystemResource(videoFile); + + //设置count + if (sysResource.getCount() == null) { + sysResource.setCount(1); + } else { + sysResource.setCount(sysResource.getCount() + 1); + } + sysResourceMapper.updateByPrimaryKey(sysResource); + + + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("video/mp4")) + .body(fileSystemResource); + } else { + return ResponseEntity.notFound().build(); + } + } else if ("课件".equals(sysResource.getResourceType())) { + if (videoFile.exists()) { + FileSystemResource fileSystemResource = new FileSystemResource(videoFile); + + //设置count + if (sysResource.getCount() == null) { + sysResource.setCount(1); + } else { + sysResource.setCount(sysResource.getCount() + 1); + } + sysResourceMapper.updateByPrimaryKey(sysResource); + + + if (url.endsWith("pptx")) { + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.presentationml.presentation")) + .body(fileSystemResource); + } else if (url.endsWith("ppt")) { + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("application/vnd.ms-powerpoint")) + .body(fileSystemResource); + } else { + return ResponseEntity.ok() + .contentType(MediaType.parseMediaType("application/pdf")) + .body(fileSystemResource); + } + } else { + return ResponseEntity.notFound().build(); + } + } + + return ResponseEntity.notFound().build(); + } + + + + + /** * 获取最受欢迎的资源名称 * 方法名:getMostPopularName diff --git a/src/main/java/com/sztzjy/resource_center/entity/SysResource.java b/src/main/java/com/sztzjy/resource_center/entity/SysResource.java index a55b0e9..b30dc64 100644 --- a/src/main/java/com/sztzjy/resource_center/entity/SysResource.java +++ b/src/main/java/com/sztzjy/resource_center/entity/SysResource.java @@ -43,6 +43,9 @@ public class SysResource { private String threeName; + @ApiModelProperty("使用次数") + private Integer count; + @ApiModelProperty("启用状态 1已启用 0未启用") private Integer status; @@ -145,6 +148,14 @@ public class SysResource { this.threeName = threeName == null ? null : threeName.trim(); } + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } + public Integer getStatus() { return status; } diff --git a/src/main/java/com/sztzjy/resource_center/entity/SysResourceExample.java b/src/main/java/com/sztzjy/resource_center/entity/SysResourceExample.java index 27c29e3..bc0466c 100644 --- a/src/main/java/com/sztzjy/resource_center/entity/SysResourceExample.java +++ b/src/main/java/com/sztzjy/resource_center/entity/SysResourceExample.java @@ -945,6 +945,66 @@ public class SysResourceExample { return (Criteria) this; } + public Criteria andCountIsNull() { + addCriterion("count is null"); + return (Criteria) this; + } + + public Criteria andCountIsNotNull() { + addCriterion("count is not null"); + return (Criteria) this; + } + + public Criteria andCountEqualTo(Integer value) { + addCriterion("count =", value, "count"); + return (Criteria) this; + } + + public Criteria andCountNotEqualTo(Integer value) { + addCriterion("count <>", value, "count"); + return (Criteria) this; + } + + public Criteria andCountGreaterThan(Integer value) { + addCriterion("count >", value, "count"); + return (Criteria) this; + } + + public Criteria andCountGreaterThanOrEqualTo(Integer value) { + addCriterion("count >=", value, "count"); + return (Criteria) this; + } + + public Criteria andCountLessThan(Integer value) { + addCriterion("count <", value, "count"); + return (Criteria) this; + } + + public Criteria andCountLessThanOrEqualTo(Integer value) { + addCriterion("count <=", value, "count"); + return (Criteria) this; + } + + public Criteria andCountIn(List values) { + addCriterion("count in", values, "count"); + return (Criteria) this; + } + + public Criteria andCountNotIn(List values) { + addCriterion("count not in", values, "count"); + return (Criteria) this; + } + + public Criteria andCountBetween(Integer value1, Integer value2) { + addCriterion("count between", value1, value2, "count"); + return (Criteria) this; + } + + public Criteria andCountNotBetween(Integer value1, Integer value2) { + addCriterion("count not between", value1, value2, "count"); + return (Criteria) this; + } + public Criteria andStatusIsNull() { addCriterion("status is null"); return (Criteria) this; diff --git a/src/main/java/com/sztzjy/resource_center/mapper/SysResourceMapper.java b/src/main/java/com/sztzjy/resource_center/mapper/SysResourceMapper.java index 89b9c9d..47afd95 100644 --- a/src/main/java/com/sztzjy/resource_center/mapper/SysResourceMapper.java +++ b/src/main/java/com/sztzjy/resource_center/mapper/SysResourceMapper.java @@ -2,14 +2,12 @@ package com.sztzjy.resource_center.mapper; import com.sztzjy.resource_center.entity.SysResource; import com.sztzjy.resource_center.entity.SysResourceExample; - import java.util.List; import java.util.Map; import com.sztzjy.resource_center.entity.dto.SysResourceDto; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; - @Mapper public interface SysResourceMapper { long countByExample(SysResourceExample example); @@ -45,5 +43,5 @@ public interface SysResourceMapper { @Param("threeId") String threeId, @Param("resourceName") String resourceName); - Map getCountByType(@Param("list") List ids,@Param("schoolId") String schoolId); + Map getCountByType(@Param("list") List ids, @Param("schoolId") String schoolId); } \ No newline at end of file diff --git a/src/main/resources/generatorConfig.xml b/src/main/resources/generatorConfig.xml index 1968f9a..5bd6340 100644 --- a/src/main/resources/generatorConfig.xml +++ b/src/main/resources/generatorConfig.xml @@ -23,7 +23,7 @@ - + @@ -35,7 +35,7 @@ - @@ -46,14 +46,14 @@ - + -
-
+ + diff --git a/src/main/resources/mapper/SysResourceMapper.xml b/src/main/resources/mapper/SysResourceMapper.xml index d832a0c..62da8df 100644 --- a/src/main/resources/mapper/SysResourceMapper.xml +++ b/src/main/resources/mapper/SysResourceMapper.xml @@ -1,436 +1,447 @@ - - - - - - - - - - - - - - - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + - - - - - - - - - - - and ${criterion.condition} - - - and ${criterion.condition} #{criterion.value} - - - and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} - - - and ${criterion.condition} - - #{listItem} - - - - - - - - - - - resource_id - , resource_name, url, picture_url, resource_type, source, one_tag, one_name, - two_tag, two_name, three_tag, three_name, status, create_time - - - - - delete - from sys_resource - where resource_id = #{resourceId,jdbcType=VARCHAR} - - - delete from sys_resource - - + - - - insert into sys_resource (resource_id, resource_name, url, - picture_url, resource_type, source, - one_tag, one_name, two_tag, - two_name, three_tag, three_name, - status, create_time) - values (#{resourceId,jdbcType=VARCHAR}, #{resourceName,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, - #{pictureUrl,jdbcType=VARCHAR}, #{resourceType,jdbcType=VARCHAR}, #{source,jdbcType=VARCHAR}, - #{oneTag,jdbcType=VARCHAR}, #{oneName,jdbcType=VARCHAR}, #{twoTag,jdbcType=VARCHAR}, - #{twoName,jdbcType=VARCHAR}, #{threeTag,jdbcType=VARCHAR}, #{threeName,jdbcType=VARCHAR}, - #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}) - - - insert into sys_resource - - - resource_id, - - - resource_name, - - - url, - - - picture_url, - - - resource_type, - - - source, - - - one_tag, - - - one_name, - - - two_tag, - - - two_name, - - - three_tag, - - - three_name, - - - status, - - - create_time, - - - - - #{resourceId,jdbcType=VARCHAR}, - - - #{resourceName,jdbcType=VARCHAR}, - - - #{url,jdbcType=VARCHAR}, - - - #{pictureUrl,jdbcType=VARCHAR}, - - - #{resourceType,jdbcType=VARCHAR}, - - - #{source,jdbcType=VARCHAR}, - - - #{oneTag,jdbcType=VARCHAR}, - - - #{oneName,jdbcType=VARCHAR}, - - - #{twoTag,jdbcType=VARCHAR}, - - - #{twoName,jdbcType=VARCHAR}, - - - #{threeTag,jdbcType=VARCHAR}, - - - #{threeName,jdbcType=VARCHAR}, - - - #{status,jdbcType=INTEGER}, - - - #{createTime,jdbcType=TIMESTAMP}, - - - - - - update sys_resource - - - resource_id = #{record.resourceId,jdbcType=VARCHAR}, - - - resource_name = #{record.resourceName,jdbcType=VARCHAR}, - - - url = #{record.url,jdbcType=VARCHAR}, - - - picture_url = #{record.pictureUrl,jdbcType=VARCHAR}, - - - resource_type = #{record.resourceType,jdbcType=VARCHAR}, - - - source = #{record.source,jdbcType=VARCHAR}, - - - one_tag = #{record.oneTag,jdbcType=VARCHAR}, - - - one_name = #{record.oneName,jdbcType=VARCHAR}, - - - two_tag = #{record.twoTag,jdbcType=VARCHAR}, - - - two_name = #{record.twoName,jdbcType=VARCHAR}, - - - three_tag = #{record.threeTag,jdbcType=VARCHAR}, - - - three_name = #{record.threeName,jdbcType=VARCHAR}, - - - status = #{record.status,jdbcType=INTEGER}, - - - create_time = #{record.createTime,jdbcType=TIMESTAMP}, - - - - + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + - - - update sys_resource - set resource_id = #{record.resourceId,jdbcType=VARCHAR}, + + + + + resource_id, resource_name, url, picture_url, resource_type, source, one_tag, one_name, + two_tag, two_name, three_tag, three_name, count, status, create_time + + + + + delete from sys_resource + where resource_id = #{resourceId,jdbcType=VARCHAR} + + + delete from sys_resource + + + + + + insert into sys_resource (resource_id, resource_name, url, + picture_url, resource_type, source, + one_tag, one_name, two_tag, + two_name, three_tag, three_name, + count, status, create_time + ) + values (#{resourceId,jdbcType=VARCHAR}, #{resourceName,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, + #{pictureUrl,jdbcType=VARCHAR}, #{resourceType,jdbcType=VARCHAR}, #{source,jdbcType=VARCHAR}, + #{oneTag,jdbcType=VARCHAR}, #{oneName,jdbcType=VARCHAR}, #{twoTag,jdbcType=VARCHAR}, + #{twoName,jdbcType=VARCHAR}, #{threeTag,jdbcType=VARCHAR}, #{threeName,jdbcType=VARCHAR}, + #{count,jdbcType=INTEGER}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP} + ) + + + insert into sys_resource + + + resource_id, + + + resource_name, + + + url, + + + picture_url, + + + resource_type, + + + source, + + + one_tag, + + + one_name, + + + two_tag, + + + two_name, + + + three_tag, + + + three_name, + + + count, + + + status, + + + create_time, + + + + + #{resourceId,jdbcType=VARCHAR}, + + + #{resourceName,jdbcType=VARCHAR}, + + + #{url,jdbcType=VARCHAR}, + + + #{pictureUrl,jdbcType=VARCHAR}, + + + #{resourceType,jdbcType=VARCHAR}, + + + #{source,jdbcType=VARCHAR}, + + + #{oneTag,jdbcType=VARCHAR}, + + + #{oneName,jdbcType=VARCHAR}, + + + #{twoTag,jdbcType=VARCHAR}, + + + #{twoName,jdbcType=VARCHAR}, + + + #{threeTag,jdbcType=VARCHAR}, + + + #{threeName,jdbcType=VARCHAR}, + + + #{count,jdbcType=INTEGER}, + + + #{status,jdbcType=INTEGER}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + + + + update sys_resource + + + resource_id = #{record.resourceId,jdbcType=VARCHAR}, + + resource_name = #{record.resourceName,jdbcType=VARCHAR}, + + url = #{record.url,jdbcType=VARCHAR}, + + picture_url = #{record.pictureUrl,jdbcType=VARCHAR}, + + resource_type = #{record.resourceType,jdbcType=VARCHAR}, + + source = #{record.source,jdbcType=VARCHAR}, + + one_tag = #{record.oneTag,jdbcType=VARCHAR}, + + one_name = #{record.oneName,jdbcType=VARCHAR}, + + two_tag = #{record.twoTag,jdbcType=VARCHAR}, + + two_name = #{record.twoName,jdbcType=VARCHAR}, + + three_tag = #{record.threeTag,jdbcType=VARCHAR}, + + three_name = #{record.threeName,jdbcType=VARCHAR}, + + + count = #{record.count,jdbcType=INTEGER}, + + status = #{record.status,jdbcType=INTEGER}, - create_time = #{record.createTime,jdbcType=TIMESTAMP} - - - - - - update sys_resource - - - resource_name = #{resourceName,jdbcType=VARCHAR}, - - - url = #{url,jdbcType=VARCHAR}, - - - picture_url = #{pictureUrl,jdbcType=VARCHAR}, - - - resource_type = #{resourceType,jdbcType=VARCHAR}, - - - source = #{source,jdbcType=VARCHAR}, - - - one_tag = #{oneTag,jdbcType=VARCHAR}, - - - one_name = #{oneName,jdbcType=VARCHAR}, - - - two_tag = #{twoTag,jdbcType=VARCHAR}, - - - two_name = #{twoName,jdbcType=VARCHAR}, - - - three_tag = #{threeTag,jdbcType=VARCHAR}, - - - three_name = #{threeName,jdbcType=VARCHAR}, - - - status = #{status,jdbcType=INTEGER}, - - - create_time = #{createTime,jdbcType=TIMESTAMP}, - - - where resource_id = #{resourceId,jdbcType=VARCHAR} - - - update sys_resource - set resource_name = #{resourceName,jdbcType=VARCHAR}, - url = #{url,jdbcType=VARCHAR}, - picture_url = #{pictureUrl,jdbcType=VARCHAR}, - resource_type = #{resourceType,jdbcType=VARCHAR}, - source = #{source,jdbcType=VARCHAR}, - one_tag = #{oneTag,jdbcType=VARCHAR}, - one_name = #{oneName,jdbcType=VARCHAR}, - two_tag = #{twoTag,jdbcType=VARCHAR}, - two_name = #{twoName,jdbcType=VARCHAR}, - three_tag = #{threeTag,jdbcType=VARCHAR}, - three_name = #{threeName,jdbcType=VARCHAR}, - status = #{status,jdbcType=INTEGER}, - create_time = #{createTime,jdbcType=TIMESTAMP} - where resource_id = #{resourceId,jdbcType=VARCHAR} - - - - - - - - - - - - - - - - - - + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + + + + + + + update sys_resource + set resource_id = #{record.resourceId,jdbcType=VARCHAR}, + resource_name = #{record.resourceName,jdbcType=VARCHAR}, + url = #{record.url,jdbcType=VARCHAR}, + picture_url = #{record.pictureUrl,jdbcType=VARCHAR}, + resource_type = #{record.resourceType,jdbcType=VARCHAR}, + source = #{record.source,jdbcType=VARCHAR}, + one_tag = #{record.oneTag,jdbcType=VARCHAR}, + one_name = #{record.oneName,jdbcType=VARCHAR}, + two_tag = #{record.twoTag,jdbcType=VARCHAR}, + two_name = #{record.twoName,jdbcType=VARCHAR}, + three_tag = #{record.threeTag,jdbcType=VARCHAR}, + three_name = #{record.threeName,jdbcType=VARCHAR}, + count = #{record.count,jdbcType=INTEGER}, + status = #{record.status,jdbcType=INTEGER}, + create_time = #{record.createTime,jdbcType=TIMESTAMP} + + + + + + update sys_resource + + + resource_name = #{resourceName,jdbcType=VARCHAR}, + + + url = #{url,jdbcType=VARCHAR}, + + + picture_url = #{pictureUrl,jdbcType=VARCHAR}, + + + resource_type = #{resourceType,jdbcType=VARCHAR}, + + + source = #{source,jdbcType=VARCHAR}, + + + one_tag = #{oneTag,jdbcType=VARCHAR}, + + + one_name = #{oneName,jdbcType=VARCHAR}, + + + two_tag = #{twoTag,jdbcType=VARCHAR}, + + + two_name = #{twoName,jdbcType=VARCHAR}, + + + three_tag = #{threeTag,jdbcType=VARCHAR}, + + + three_name = #{threeName,jdbcType=VARCHAR}, + + + count = #{count,jdbcType=INTEGER}, + + + status = #{status,jdbcType=INTEGER}, + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + where resource_id = #{resourceId,jdbcType=VARCHAR} + + + update sys_resource + set resource_name = #{resourceName,jdbcType=VARCHAR}, + url = #{url,jdbcType=VARCHAR}, + picture_url = #{pictureUrl,jdbcType=VARCHAR}, + resource_type = #{resourceType,jdbcType=VARCHAR}, + source = #{source,jdbcType=VARCHAR}, + one_tag = #{oneTag,jdbcType=VARCHAR}, + one_name = #{oneName,jdbcType=VARCHAR}, + two_tag = #{twoTag,jdbcType=VARCHAR}, + two_name = #{twoName,jdbcType=VARCHAR}, + three_tag = #{threeTag,jdbcType=VARCHAR}, + three_name = #{threeName,jdbcType=VARCHAR}, + count = #{count,jdbcType=INTEGER}, + status = #{status,jdbcType=INTEGER}, + create_time = #{createTime,jdbcType=TIMESTAMP} + where resource_id = #{resourceId,jdbcType=VARCHAR} + - - + + + + + + + + + + + + + + + + - - + + - + + + + \ No newline at end of file