Browse Source

共享资料库相关接口

Signed-off-by: guoWenHao <2532478980@qq.com>
guoWenHao 9 months ago
parent
commit
948fd01e51

+ 1 - 1
teacher-common/src/main/java/com/example/properties/AliOssProperties.java

@@ -5,7 +5,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.stereotype.Component;
 import org.springframework.stereotype.Component;
 
 
 @Component
 @Component
-@ConfigurationProperties(prefix = "sky.alioss")
+@ConfigurationProperties(prefix = "teacher.alioss")
 @Data
 @Data
 public class AliOssProperties {
 public class AliOssProperties {
 
 

+ 2 - 0
teacher-pojo/src/main/java/com/example/dto/PageQueryDTO.java

@@ -18,4 +18,6 @@ public class PageQueryDTO implements Serializable {
 
 
     private Long teacherId;
     private Long teacherId;
 
 
+    private String uploaderName;
+
 }
 }

+ 21 - 0
teacher-pojo/src/main/java/com/example/dto/ResourceDTO.java

@@ -0,0 +1,21 @@
+package com.example.dto;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.time.LocalDate;
+
+@Data
+public class ResourceDTO implements Serializable {
+
+    private String name;
+
+    private String uploaderName;
+
+    private String image;;
+
+    private String file;
+
+    private Integer status;
+}

+ 32 - 0
teacher-pojo/src/main/java/com/example/entity/Resource.java

@@ -0,0 +1,32 @@
+package com.example.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class Resource implements Serializable {
+
+    private Long id;
+
+    private String name;
+
+    private String uploaderName;
+
+    private Long uploader;
+
+    private String image;;
+
+    private String file;
+
+    private Integer status;
+
+    private LocalDateTime createTime;
+}

+ 32 - 0
teacher-pojo/src/main/java/com/example/vo/ResourceVO.java

@@ -0,0 +1,32 @@
+package com.example.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.time.LocalDateTime;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Builder
+public class ResourceVO implements Serializable {
+
+    private Long id;
+
+    private String name;
+
+    private String uploaderName;
+
+    private Long uploader;
+
+    private String image;;
+
+    private String file;
+
+    private Integer status;
+
+    private LocalDateTime createTime;
+}

+ 1 - 0
teacher-serve/src/main/java/com/example/config/WebMvcConfiguration.java

@@ -41,6 +41,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
         registry.addInterceptor(jwtTokenAdminInterceptor)
         registry.addInterceptor(jwtTokenAdminInterceptor)
                 .addPathPatterns("/teacher/**")
                 .addPathPatterns("/teacher/**")
                 .addPathPatterns("/user/password")
                 .addPathPatterns("/user/password")
+                .addPathPatterns("/resources/**")
                 .excludePathPatterns("/open/**")
                 .excludePathPatterns("/open/**")
                 .excludePathPatterns("/user/download");
                 .excludePathPatterns("/user/download");
 
 

+ 65 - 0
teacher-serve/src/main/java/com/example/controller/user/ResourceController.java

@@ -0,0 +1,65 @@
+package com.example.controller.user;
+
+import com.example.dto.PageQueryDTO;
+import com.example.dto.ResourceDTO;
+import com.example.entity.Resource;
+import com.example.result.PageResult;
+import com.example.result.Result;
+import com.example.service.ResourceService;
+import com.example.vo.ResourceVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.annotations.Delete;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@Slf4j
+@Api(tags = "共享资源库相关接口")
+@RequestMapping("/resources")
+public class ResourceController {
+
+    @Autowired
+    private ResourceService resourceService;
+
+    @PostMapping
+    @ApiOperation(value = "共享资料库上传")
+    public Result upload(@RequestBody ResourceDTO resourceDTO) {
+        log.info("共享资料库上传:{}", resourceDTO);
+        resourceService.upload(resourceDTO);
+        return Result.success();
+    }
+
+    @PutMapping("/{id}")
+    @ApiOperation(value = "更新指定资料库")
+    public Result update(@RequestBody ResourceDTO resourceDTO, @PathVariable Long id) {
+        log.info("更新指定共享资料库:{}", resourceDTO);
+        resourceService.update(resourceDTO, id);
+        return Result.success();
+    }
+
+    @DeleteMapping("/{id}")
+    @ApiOperation(value = "删除指定资料")
+    public Result delete(@PathVariable Long id) {
+        log.info("删除指定资料:{}", id);
+        resourceService.delete(id);
+        return Result.success();
+    }
+
+    @GetMapping("/{id}")
+    @ApiOperation(value = "查询指定资料")
+    public Result<ResourceVO> getById(@PathVariable Long id) {
+        log.info("查询指定资料:{}", id);
+        ResourceVO resourceVO = resourceService.getById(id);
+        return Result.success(resourceVO);
+    }
+
+    @GetMapping("/page")
+    public Result<PageResult> getAll(PageQueryDTO pageQueryDTO){
+        log.info("资料库分页展示,参数:{},{}",pageQueryDTO.getPage(),pageQueryDTO.getPageSize());
+
+        PageResult pageResult=resourceService.getAll(pageQueryDTO);
+        return Result.success(pageResult);
+    }
+}

+ 43 - 0
teacher-serve/src/main/java/com/example/mapper/ResourceMapper.java

@@ -0,0 +1,43 @@
+package com.example.mapper;
+
+import com.example.dto.PageQueryDTO;
+import com.example.entity.Resource;
+import com.github.pagehelper.Page;
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+
+@Mapper
+public interface ResourceMapper {
+    /**
+     * 资料库上传
+     * @param resource
+     */
+    @Insert("insert into teacherteam_system.resources(uploader, name, create_time, image, file, uploader_name,status)" +
+            " VALUES (#{uploader},#{name},#{createTime},#{image},#{file},#{uploaderName},#{status})")
+    void upload(Resource resource);
+
+    /**
+     * 指定资料修改
+     * @param resource
+     */
+    void update(Resource resource);
+
+    /**
+     * 指定资料删除
+     * @param id
+     */
+    @Delete("delete from teacherteam_system.resources where id = #{id}")
+    void delete(Long id);
+
+    /**
+     * 查询指定资料
+     * @param id
+     * @return
+     */
+    @Select("select * from teacherteam_system.resources where id = #{id}")
+    Resource getById(Long id);
+
+    Page<Resource> getAll(PageQueryDTO pageQueryDTO);
+}

+ 36 - 0
teacher-serve/src/main/java/com/example/service/ResourceService.java

@@ -0,0 +1,36 @@
+package com.example.service;
+
+import com.example.dto.PageQueryDTO;
+import com.example.dto.ResourceDTO;
+import com.example.result.PageResult;
+import com.example.vo.ResourceVO;
+
+public interface ResourceService {
+    /**
+     * 资料库上传
+     * @param resourceDTO
+     */
+    void upload(ResourceDTO resourceDTO);
+
+    /**
+     * 指定资料修改
+     * @param resourceDTO
+     * @param id
+     */
+    void update(ResourceDTO resourceDTO,Long id);
+
+    /**
+     * 指定资料删除
+     * @param id
+     */
+    void delete(Long id);
+
+    /**
+     * 查询指定资料
+     * @param id
+     * @return
+     */
+    ResourceVO getById(Long id);
+
+    PageResult getAll(PageQueryDTO pageQueryDTO);
+}

+ 82 - 0
teacher-serve/src/main/java/com/example/service/impl/ResourceServiceImpl.java

@@ -0,0 +1,82 @@
+package com.example.service.impl;
+
+import com.example.context.BaseContext;
+import com.example.dto.PageQueryDTO;
+import com.example.dto.ResourceDTO;
+import com.example.entity.Resource;
+import com.example.mapper.ResourceMapper;
+import com.example.result.PageResult;
+import com.example.service.ResourceService;
+import com.example.vo.ResourceVO;
+import com.github.pagehelper.Page;
+import com.github.pagehelper.PageHelper;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+@Service
+public class ResourceServiceImpl implements ResourceService {
+
+    @Autowired
+    private ResourceMapper resourceMapper;
+
+    /**
+     * 资料库上传
+     * @param resourceDTO
+     */
+    @Override
+    public void upload(ResourceDTO resourceDTO) {
+        Resource resource = new Resource();
+        BeanUtils.copyProperties(resourceDTO,resource);
+        resource.setUploader(BaseContext.getCurrentId());
+        resource.setCreateTime(LocalDateTime.now());
+        resourceMapper.upload(resource);
+    }
+
+    /**
+     * 指定资料修改
+     * @param resourceDTO
+     * @param id
+     */
+    @Override
+    public void update(ResourceDTO resourceDTO,Long id) {
+        Resource resource = new Resource();
+        BeanUtils.copyProperties(resourceDTO,resource);
+        resource.setId(id);
+        resourceMapper.update(resource);
+    }
+
+    /**
+     * 指定资料删除
+     * @param id
+     */
+    @Override
+    public void delete(Long id) {
+        resourceMapper.delete(id);
+    }
+
+    /**
+     * 查询指定资料
+     * @param id
+     * @return
+     */
+    @Override
+    public ResourceVO getById(Long id) {
+        Resource resource = resourceMapper.getById(id);
+        ResourceVO resourceVO=new ResourceVO();
+        BeanUtils.copyProperties(resource,resourceVO);
+        return resourceVO;
+    }
+
+    @Override
+    public PageResult getAll(PageQueryDTO pageQueryDTO) {
+        PageHelper.startPage(pageQueryDTO.getPage(),pageQueryDTO.getPageSize());
+        Page<Resource> page=resourceMapper.getAll(pageQueryDTO);
+        Long total=page.getTotal();
+        List<Resource> result=page.getResult();
+        return new PageResult(total,result);
+    }
+}

+ 1 - 1
teacher-serve/src/main/resources/application-dev.yml

@@ -3,7 +3,7 @@ teacher:
     driver-class-name: com.mysql.cj.jdbc.Driver
     driver-class-name: com.mysql.cj.jdbc.Driver
     host: localhost
     host: localhost
     port: 3306
     port: 3306
-    database: sky_take_out
+    database: teacherteam_system
     username: root
     username: root
     password: 123456
     password: 123456
   alioss:
   alioss:

+ 1 - 1
teacher-serve/src/main/resources/mapper/AwardsMapper.xml

@@ -14,7 +14,7 @@
                 date =#{date},
                 date =#{date},
             </if>
             </if>
             <if test="image != null">
             <if test="image != null">
-                image =#{image}
+                image =#{image},
             </if>
             </if>
         </set>
         </set>
         where id = #{id}
         where id = #{id}

+ 38 - 0
teacher-serve/src/main/resources/mapper/ResourceMapper.xml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+<mapper namespace="com.example.mapper.ResourceMapper">
+
+    <update id="update">
+        update teacherteam_system.resources
+        <set>
+            <if test="name != null">
+                name=#{name},
+            </if>
+            <if test="image != null">
+                image=#{image},
+            </if>
+            <if test="file != null">
+                file=#{file},
+            </if>
+            <if test="uploaderName != null">
+                uploader_name=#{uploaderName},
+            </if>
+            <if test="status != null">
+                status=#{status}
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+    <select id="getAll" resultType="com.example.entity.Resource">
+        select * from teacherteam_system.resources
+        <where>
+            <if test="name != null and name != ''">
+                name like concat('%',#{name},'%')
+            </if>
+        <if test="uploaderName != null and uploaderName != ''">
+            and uploader_name like concat('%',#{uploaderName},'%')
+        </if>
+        </where>
+    </select>
+</mapper>