parent
0442325910
commit
f63029e4d1
18 changed files with 983 additions and 790 deletions
@ -0,0 +1,78 @@ |
|||||||
|
package com.teaching.backend.controller.resource; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author:youhang |
||||||
|
* @Date:2024-06-09-9:55 |
||||||
|
* @Description: |
||||||
|
*/ |
||||||
|
|
||||||
|
|
||||||
|
import com.teaching.backend.common.BaseResponse; |
||||||
|
import com.teaching.backend.model.entity.resource.Resources; |
||||||
|
import com.teaching.backend.service.resource.ResourceGraphService; |
||||||
|
import com.teaching.backend.service.resource.ResourceService; |
||||||
|
import io.swagger.annotations.Api; |
||||||
|
import io.swagger.annotations.ApiModel; |
||||||
|
import io.swagger.annotations.ApiOperation; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.core.io.InputStreamResource; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.*; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
|
||||||
|
@RestController |
||||||
|
@RequestMapping("/api/resource/graph") |
||||||
|
@Api(tags= "资源与图管理") |
||||||
|
public class ResourceGraphController { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ResourceGraphService resourceGraphService; |
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/addRelationship/BetweenKnowAndResources") |
||||||
|
@ApiOperation(value = "添加知识点资源关系") |
||||||
|
public BaseResponse<String> addResourcesByIdAndResourcesIds(@RequestParam Long id,@RequestParam List<Long> resourcesIds){ |
||||||
|
return resourceGraphService.addResourcesByIdAndResourcesIds(id,resourcesIds); |
||||||
|
} |
||||||
|
|
||||||
|
@GetMapping("/deleteRelationship/BetweenKnowAndResources") |
||||||
|
@ApiOperation(value = "删除知识点资源关系") |
||||||
|
public BaseResponse<String> deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam List<Long> resourcesIds){ |
||||||
|
return resourceGraphService.deleteResourcesAndKnowById(id,resourcesIds); |
||||||
|
} |
||||||
|
|
||||||
|
//查询课程下资源
|
||||||
|
@GetMapping("/queryByCourseId") |
||||||
|
@ApiOperation(value = "查询课程下资源") |
||||||
|
BaseResponse<Set<Resources>> queryResourcesByCourseId(@RequestParam String courseId){ |
||||||
|
return resourceGraphService.queryResourcesByCourseId(courseId); |
||||||
|
} |
||||||
|
|
||||||
|
//查询章节下资源
|
||||||
|
@GetMapping("/queryByChapterId") |
||||||
|
@ApiOperation(value = "查询章节下资源") |
||||||
|
BaseResponse<Set<Resources>> queryResourcesByChapterId(@RequestParam Long chapterId){ |
||||||
|
return resourceGraphService.queryResourcesByChapterId(chapterId); |
||||||
|
} |
||||||
|
|
||||||
|
//查询二级节点下资源
|
||||||
|
@ApiOperation(value = "查询二级节点下资源") |
||||||
|
@GetMapping("/queryBesidesKnow") |
||||||
|
BaseResponse<Set<Resources>> queryBesidesKnowToResources(@RequestParam Long knowId){ |
||||||
|
return resourceGraphService.queryBesidesKnowToResources(knowId); |
||||||
|
} |
||||||
|
|
||||||
|
//查询知识点下资源
|
||||||
|
@GetMapping("/queryResourcesByKnowId") |
||||||
|
@ApiOperation(value = "查询知识点下资源") |
||||||
|
BaseResponse<Set<Resources>> queryResourcesByKnowId(@RequestParam Long knowId){ |
||||||
|
return resourceGraphService.queryResourcesByKnowId(knowId); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
package com.teaching.backend.mapper.Knowtemp; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
||||||
|
import com.teaching.backend.model.entity.know.KnowStr; |
||||||
|
import com.teaching.backend.model.entity.knowtmp.Knowtmp; |
||||||
|
import io.lettuce.core.dynamic.annotation.Param; |
||||||
|
import org.apache.ibatis.annotations.Mapper; |
||||||
|
import org.apache.ibatis.annotations.Select; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* |
||||||
|
*/ |
||||||
|
@Mapper |
||||||
|
public interface KnowstrMapper extends BaseMapper<KnowStr> { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,30 @@ |
|||||||
|
package com.teaching.backend.model.entity.know; |
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableId; |
||||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import javax.xml.soap.Text; |
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author:youhang |
||||||
|
* @Date:2024-08-23-17:29 |
||||||
|
* @Description: |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@TableName("know_str") |
||||||
|
public class KnowStr implements Serializable { |
||||||
|
private static final long serialVersionUID = 1L; |
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.AUTO) |
||||||
|
private Long id; |
||||||
|
private String courseId; |
||||||
|
|
||||||
|
private String coursestr; |
||||||
|
private String chapterstr; |
||||||
|
private String knowstr; |
||||||
|
private String edgestr; |
||||||
|
|
||||||
|
} |
@ -0,0 +1,29 @@ |
|||||||
|
package com.teaching.backend.model.entity.know; |
||||||
|
|
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import lombok.Data; |
||||||
|
import lombok.NoArgsConstructor; |
||||||
|
import org.checkerframework.checker.units.qual.A; |
||||||
|
import org.springframework.data.neo4j.core.schema.GeneratedValue; |
||||||
|
import org.springframework.data.neo4j.core.schema.Id; |
||||||
|
import org.springframework.data.neo4j.core.schema.Node; |
||||||
|
import org.springframework.data.neo4j.core.schema.Property; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author:youhang |
||||||
|
* @Date:2024-07-21-16:32 |
||||||
|
* @Description: |
||||||
|
*/ |
||||||
|
@Data |
||||||
|
@AllArgsConstructor |
||||||
|
@NoArgsConstructor |
||||||
|
public class LinksVO { |
||||||
|
|
||||||
|
private Long source; |
||||||
|
|
||||||
|
private Long target; |
||||||
|
|
||||||
|
private String label; |
||||||
|
|
||||||
|
|
||||||
|
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,151 @@ |
|||||||
|
package com.teaching.backend.service.impl.resource; |
||||||
|
|
||||||
|
|
||||||
|
import com.teaching.backend.common.BaseResponse; |
||||||
|
import com.teaching.backend.common.ErrorCode; |
||||||
|
import com.teaching.backend.common.ResultUtils; |
||||||
|
import com.teaching.backend.mapper.know.KnowRepository; |
||||||
|
import com.teaching.backend.mapper.resource.ResourcesRepository; |
||||||
|
import com.teaching.backend.model.dto.resource.ResourceUploadDto; |
||||||
|
import com.teaching.backend.model.entity.know.KnowChapter; |
||||||
|
import com.teaching.backend.model.entity.know.KnowCourse; |
||||||
|
import com.teaching.backend.model.entity.resource.Resources; |
||||||
|
import com.teaching.backend.service.resource.ResourceGraphService; |
||||||
|
import com.teaching.backend.service.resource.ResourceService; |
||||||
|
import com.teaching.backend.utils.MinioUtils; |
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
import org.springframework.beans.factory.annotation.Autowired; |
||||||
|
import org.springframework.beans.factory.annotation.Value; |
||||||
|
import org.springframework.core.io.InputStreamResource; |
||||||
|
import org.springframework.data.neo4j.core.Neo4jClient; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.stereotype.Service; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import javax.annotation.Resource; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @Author:youhang |
||||||
|
* @Date:2024-07-26-13:58 |
||||||
|
* @Description: |
||||||
|
*/ |
||||||
|
@Service |
||||||
|
public class ResourceGraphServiceImpl implements ResourceGraphService { |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private ResourcesRepository resourcesRepository; |
||||||
|
|
||||||
|
@Autowired |
||||||
|
private KnowRepository knowRepository; |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override |
||||||
|
public BaseResponse<String> addResourcesByIdAndResourcesIds(Long id, List<Long> resourcesIds) { |
||||||
|
// 查询知识点是否存在 ,资源是否存在
|
||||||
|
int f = knowRepository.queryNode(id); |
||||||
|
if(f <= 0){ |
||||||
|
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在"); |
||||||
|
} |
||||||
|
Set<Resources>resourcesSet = resourcesRepository.queryResourcesByIds(resourcesIds); |
||||||
|
|
||||||
|
if(resourcesSet.size() < resourcesIds.size()){ |
||||||
|
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在"); |
||||||
|
} |
||||||
|
|
||||||
|
//查询关系是否存在
|
||||||
|
for (int i = 0; i < resourcesIds.size(); i++) { |
||||||
|
int count = resourcesRepository.queryExisitRel(id,resourcesIds.get(i)); |
||||||
|
if(count <= 0){ |
||||||
|
//添加关系 addResourcesAndKnowById
|
||||||
|
f = resourcesRepository.addResourcesAndKnowById(id,resourcesIds.get(i)); |
||||||
|
if(f<= 0){ |
||||||
|
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"创建关系失败"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return ResultUtils.success("添加关系成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public BaseResponse<String> deleteResourcesAndKnowById(Long id, List<Long> resourcesIds) { |
||||||
|
// 查询知识点是否存在 ,资源是否存在
|
||||||
|
int f = knowRepository.queryNode(id); |
||||||
|
if(f <= 0){ |
||||||
|
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"知识点不存在"); |
||||||
|
} |
||||||
|
Set<Resources>resourcesSet = resourcesRepository.queryResourcesByIds(resourcesIds); |
||||||
|
|
||||||
|
if(resourcesSet.size() < resourcesIds.size()){ |
||||||
|
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"资源不存在"); |
||||||
|
} |
||||||
|
|
||||||
|
//查询关系是否存在
|
||||||
|
for (int i = 0; i < resourcesIds.size(); i++) { |
||||||
|
int count = resourcesRepository.queryExisitRel(id,resourcesIds.get(i)); |
||||||
|
if(count <= 0){ |
||||||
|
//添加关系 addResourcesAndKnowById
|
||||||
|
f = resourcesRepository.deleteResourcesAndKnowById(id,resourcesIds.get(i)); |
||||||
|
if(f<= 0){ |
||||||
|
return ResultUtils.error(ErrorCode.PARAMS_ERROR,"删除关系失败"); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return ResultUtils.success("删除关系成功"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
//查询课程下资源
|
||||||
|
public BaseResponse<Set<Resources>> queryResourcesByCourseId(String courseId){ |
||||||
|
// 判空,查询
|
||||||
|
KnowCourse knowCourse = knowRepository.queryCourse(courseId); |
||||||
|
if(knowCourse == null){ |
||||||
|
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"课程不存在"); |
||||||
|
} |
||||||
|
Set<Resources> resourcesSet = resourcesRepository.queryResourcesByCourseId(courseId); |
||||||
|
return ResultUtils.success(resourcesSet); |
||||||
|
} |
||||||
|
@Override |
||||||
|
//查询章节下资源
|
||||||
|
public BaseResponse<Set<Resources>> queryResourcesByChapterId(Long chapterId){ |
||||||
|
// 判空,查询
|
||||||
|
KnowChapter knowChapter = knowRepository.queryChapter(chapterId); |
||||||
|
if(knowChapter == null){ |
||||||
|
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"章节不存在"); |
||||||
|
} |
||||||
|
Set<Resources>resourcesSet ; |
||||||
|
resourcesSet = resourcesRepository.queryResourcesByChapterId(chapterId); |
||||||
|
return ResultUtils.success(resourcesSet); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
//查询二级节点下资源
|
||||||
|
public BaseResponse<Set<Resources>> queryBesidesKnowToResources(Long knowId){ |
||||||
|
// 判空,查询
|
||||||
|
int i = knowRepository.queryNode(knowId); |
||||||
|
if(i <= 0){ |
||||||
|
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"知识点不存在"); |
||||||
|
} |
||||||
|
Set<Resources> resourcesSet = resourcesRepository.queryBesidesKnowToResources(knowId); |
||||||
|
return ResultUtils.success(resourcesSet); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public BaseResponse<Set<Resources>> queryResourcesByKnowId(Long knowId) { |
||||||
|
// 判空,查询
|
||||||
|
int i = knowRepository.queryNode(knowId); |
||||||
|
if(i <= 0){ |
||||||
|
return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR,"知识点不存在"); |
||||||
|
} |
||||||
|
Set<Resources> resourcesSet = resourcesRepository.queryResourcesByKnowId(knowId); |
||||||
|
return ResultUtils.success(resourcesSet); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
package com.teaching.backend.service.resource; |
||||||
|
|
||||||
|
|
||||||
|
import com.teaching.backend.common.BaseResponse; |
||||||
|
import com.teaching.backend.model.entity.resource.Resources; |
||||||
|
import org.springframework.core.io.InputStreamResource; |
||||||
|
import org.springframework.http.ResponseEntity; |
||||||
|
import org.springframework.web.bind.annotation.RequestParam; |
||||||
|
import org.springframework.web.multipart.MultipartFile; |
||||||
|
|
||||||
|
import java.util.List; |
||||||
|
import java.util.Set; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Author:youhang |
||||||
|
* @Date:2024-07-26-13:55 |
||||||
|
* @Description: |
||||||
|
*/ |
||||||
|
|
||||||
|
public interface ResourceGraphService { |
||||||
|
|
||||||
|
public BaseResponse<String> deleteResourcesAndKnowById(@RequestParam Long id, @RequestParam List<Long> resourcesIds); |
||||||
|
|
||||||
|
BaseResponse<String> addResourcesByIdAndResourcesIds(Long id, List<Long> resourcesIds); |
||||||
|
|
||||||
|
|
||||||
|
//查询课程下资源
|
||||||
|
BaseResponse<Set<Resources>> queryResourcesByCourseId(String courseId); |
||||||
|
|
||||||
|
//查询章节下资源
|
||||||
|
BaseResponse<Set<Resources>> queryResourcesByChapterId(Long chapterId); |
||||||
|
|
||||||
|
//查询二级节点下资源
|
||||||
|
BaseResponse<Set<Resources>> queryBesidesKnowToResources(Long knowId); |
||||||
|
|
||||||
|
BaseResponse<Set<Resources>> queryResourcesByKnowId(Long knowId); |
||||||
|
|
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue