diff --git a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaResourceCenterController.java b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaResourceCenterController.java index a9ada94..decda79 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaResourceCenterController.java +++ b/src/main/java/com/sztzjy/financial_bigdata/controller/tea/TeaResourceCenterController.java @@ -1,7 +1,7 @@ package com.sztzjy.financial_bigdata.controller.tea; import com.sztzjy.financial_bigdata.annotation.AnonymousAccess; -import com.sztzjy.financial_bigdata.entity.*; +import com.sztzjy.financial_bigdata.entity.TeaResourceCenter; import com.sztzjy.financial_bigdata.entity.resource_entity.SysResource; import com.sztzjy.financial_bigdata.resourceCenterAPI.ResourceCenterApi; import com.sztzjy.financial_bigdata.service.tea.ITeaResourceCenterService; @@ -10,11 +10,17 @@ import com.sztzjy.financial_bigdata.util.file.IFileUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + import java.io.IOException; +import java.util.ArrayList; import java.util.List; //资源中心 @@ -35,7 +41,7 @@ public class TeaResourceCenterController { @GetMapping("selectResource") @ApiOperation("**查看资源文件列表,图片资源使用默认图片") public ResultEntity> selectResource(@ApiParam("学校id") @RequestParam String schoolId, - @ApiParam("课程Id") @RequestParam String courseId, @RequestParam String systemOwner) { + @ApiParam("课程Id") @RequestParam String courseId, @RequestParam String systemOwner) { List resourceList = null; try { resourceList = ResourceCenterApi.selectResource(schoolId, courseId, systemOwner); @@ -49,9 +55,15 @@ public class TeaResourceCenterController { @AnonymousAccess @GetMapping("selectResourceByChapterId") @ApiOperation("**根据章节查看资源文件列表,图片资源使用默认图片") - public ResultEntity> selectResourceByChapterId(@ApiParam("章节Id") @RequestParam String chapterId, @RequestParam String systemOwner) { + public ResultEntity> selectResourceByChapterId(@ApiParam("章节Id") @RequestParam(required = false) String chapterId, + @RequestParam String systemOwner) { try { - List resourceList = ResourceCenterApi.selectResourceByChapterId(chapterId, systemOwner); + List resourceList = new ArrayList<>(); + if (StringUtils.isBlank(chapterId)) { + resourceList = ResourceCenterApi.selectResourceByChapterId(systemOwner); + } else { + resourceList = ResourceCenterApi.selectResourceByChapterId(chapterId, systemOwner); + } return new ResultEntity(HttpStatus.OK, "根据章节查看资源文件列表,展示成功", resourceList); } catch (IOException e) { return new ResultEntity<>(HttpStatus.BAD_REQUEST, "资源中心接口异常"); diff --git a/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/ResourceCenterApi.java b/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/ResourceCenterApi.java index a1f3da0..2cb8886 100644 --- a/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/ResourceCenterApi.java +++ b/src/main/java/com/sztzjy/financial_bigdata/resourceCenterAPI/ResourceCenterApi.java @@ -79,6 +79,20 @@ public class ResourceCenterApi { } + public static List selectResourceByChapterId(String systemOwner) throws IOException { + String requestBody = "oneId=" + systemOwner; + JSONObject object = HttpUtils.sendPost( + selectResourceByChapterId, + requestBody); + Gson gson = new GsonBuilder() + .registerTypeAdapter(Date.class, new DateTypeAdapter()) + .create(); + Type listType = new TypeToken>() { + }.getType(); + List resourceList = gson.fromJson(object.get("respString").toString(), listType); + return resourceList; + } + /** * local:资源文件下载 * rsapi:资源文件下载