文献管理功能
This commit is contained in:
15
src/main/java/com/bicloud/common/result/PageResult.java
Normal file
15
src/main/java/com/bicloud/common/result/PageResult.java
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package com.bicloud.common.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class PageResult<T> {
|
||||||
|
private long total;
|
||||||
|
private List<T> records;
|
||||||
|
|
||||||
|
public PageResult(long total, List<T> records) {
|
||||||
|
this.total = total;
|
||||||
|
this.records = records;
|
||||||
|
}
|
||||||
|
}
|
||||||
30
src/main/java/com/bicloud/common/result/Result.java
Normal file
30
src/main/java/com/bicloud/common/result/Result.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
package com.bicloud.common.result;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.io.Serializable; // 1. 导入Serializable包
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Result<T> implements Serializable {
|
||||||
|
// 注意:添加序列化版本号
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Integer code; // 200成功,500失败
|
||||||
|
private String msg;
|
||||||
|
private T data;
|
||||||
|
|
||||||
|
// 原有方法完全保留
|
||||||
|
public static <T> Result<T> success(T data) {
|
||||||
|
Result<T> result = new Result<>();
|
||||||
|
result.setCode(200);
|
||||||
|
result.setMsg("操作成功");
|
||||||
|
result.setData(data);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Result<T> error(String msg) {
|
||||||
|
Result<T> result = new Result<>();
|
||||||
|
result.setCode(500);
|
||||||
|
result.setMsg(msg);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
40
src/main/java/com/bicloud/config/OpenApiConfig.java
Normal file
40
src/main/java/com/bicloud/config/OpenApiConfig.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package com.bicloud.config;
|
||||||
|
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.info.Info;
|
||||||
|
import io.swagger.v3.oas.models.info.License;
|
||||||
|
import org.springdoc.core.models.GroupedOpenApi;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Knife4j + OpenAPI 3 文档主信息配置(无 externalDocs)
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class OpenApiConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public OpenAPI myOpenAPI() {
|
||||||
|
return new OpenAPI()
|
||||||
|
.info(new Info()
|
||||||
|
|
||||||
|
.title("接口文档")
|
||||||
|
.description("OpenAPI 3接口文档")
|
||||||
|
.version("v1.0.0")
|
||||||
|
.license(new License()
|
||||||
|
.name("Apache 2.0")
|
||||||
|
.url("https://www.apache.org/licenses/LICENSE-2.0")
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分组1:文献管理接口
|
||||||
|
@Bean
|
||||||
|
public GroupedOpenApi literatureApi() {
|
||||||
|
return GroupedOpenApi.builder()
|
||||||
|
.group("文献管理接口") // 分组名称
|
||||||
|
.packagesToScan("com.bicloud.controller") // 匹配的接口路径
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
18
src/main/java/com/bicloud/config/StaticResourceConfig.java
Normal file
18
src/main/java/com/bicloud/config/StaticResourceConfig.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package com.bicloud.config;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class StaticResourceConfig implements WebMvcConfigurer {
|
||||||
|
@Override
|
||||||
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||||
|
// 使用 "file:./" 前缀代表项目根路径(无论项目怎么移动,开发部署都不影响)
|
||||||
|
registry.addResourceHandler("/img/**")
|
||||||
|
.addResourceLocations("file:./media/img/");
|
||||||
|
registry.addResourceHandler("/video/**")
|
||||||
|
.addResourceLocations("file:./media/video/");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package com.bicloud.controller;
|
||||||
|
|
||||||
|
import com.bicloud.common.result.PageResult;
|
||||||
|
import com.bicloud.common.result.Result;
|
||||||
|
import com.bicloud.pojo.dto.LiteratureDto;
|
||||||
|
import com.bicloud.pojo.dto.LiteraturePageQueryDto;
|
||||||
|
import com.bicloud.service.LiteratureService;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@CrossOrigin
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/literature")
|
||||||
|
@Tag(name = "文献管理", description = "文献相关接口")
|
||||||
|
@Slf4j
|
||||||
|
public class LiteratureController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LiteratureService literatureService;
|
||||||
|
|
||||||
|
// 新增文献数据
|
||||||
|
@PostMapping("/add")
|
||||||
|
@Operation(summary = "新增文献")
|
||||||
|
public Result<String> addLiterature(@RequestBody LiteratureDto literatureDTO) {
|
||||||
|
try {
|
||||||
|
literatureService.addLiterature(literatureDTO);
|
||||||
|
// 成功:返回200码
|
||||||
|
return Result.success("新增文献成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
// 失败:返回500码、自定义失败提示
|
||||||
|
return Result.error("新增文献失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除文献
|
||||||
|
@DeleteMapping("/delete/{id}") // 通过路径变量接收文献ID
|
||||||
|
@Operation(summary = "删除文献")
|
||||||
|
public Result<String> deleteLiterature(@PathVariable Long id) { // @PathVariable绑定路径中的id参数
|
||||||
|
try {
|
||||||
|
literatureService.deleteLiterature(id);
|
||||||
|
return Result.success("删除文献成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return Result.error("删除文献失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//分页查询
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "分页查询文献")
|
||||||
|
public Result<PageResult<LiteratureDto>> page(LiteraturePageQueryDto queryDTO) {
|
||||||
|
log.info("传入参数为:"+queryDTO);
|
||||||
|
PageResult<LiteratureDto> result = literatureService.pageQuery(queryDTO);
|
||||||
|
return Result.success(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/main/java/com/bicloud/mapper/LiteratureMapper.java
Normal file
25
src/main/java/com/bicloud/mapper/LiteratureMapper.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package com.bicloud.mapper;
|
||||||
|
|
||||||
|
import com.bicloud.pojo.dto.LiteraturePageQueryDto;
|
||||||
|
import com.bicloud.pojo.entity.LiteratureInfo;
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import org.apache.ibatis.annotations.Delete;
|
||||||
|
import org.apache.ibatis.annotations.Insert;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface LiteratureMapper {
|
||||||
|
|
||||||
|
// 插入文献数据
|
||||||
|
@Insert("INSERT INTO literature_info(year, article_title, journal_name, impact_factor, sample_source, literature_type,literature_url) " +
|
||||||
|
"VALUES(#{year}, #{articleTitle}, #{journalName}, #{impactFactor}, #{sampleSource}, #{literatureType},#{literatureUrl})")
|
||||||
|
int insertLiterature(LiteratureInfo literatureInfo);
|
||||||
|
|
||||||
|
|
||||||
|
// 根据文献ID删除数据
|
||||||
|
@Delete("DELETE FROM literature_info WHERE id = #{id}")
|
||||||
|
void deleteLiteratureById(Long id);
|
||||||
|
|
||||||
|
Page<LiteratureInfo> pageQuery(LiteraturePageQueryDto queryDTO);
|
||||||
|
}
|
||||||
18
src/main/java/com/bicloud/pojo/dto/LiteratureDto.java
Normal file
18
src/main/java/com/bicloud/pojo/dto/LiteratureDto.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package com.bicloud.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LiteratureDto {
|
||||||
|
// 字段名要和前端提交的参数名一致
|
||||||
|
private Long id;
|
||||||
|
private Integer year;
|
||||||
|
private String articleTitle;
|
||||||
|
private String journalName;
|
||||||
|
private BigDecimal impactFactor;
|
||||||
|
private String sampleSource;
|
||||||
|
private String literatureType;
|
||||||
|
private String literatureUrl;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.bicloud.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class LiteraturePageQueryDto {
|
||||||
|
private Integer page;
|
||||||
|
private Integer pageSize;
|
||||||
|
private String articleTitle;
|
||||||
|
private Integer year;
|
||||||
|
private String journalName;
|
||||||
|
private String literatureType;
|
||||||
|
private String sampleSource;
|
||||||
|
private BigDecimal impactFactorMin;
|
||||||
|
private BigDecimal impactFactorMax;
|
||||||
|
}
|
||||||
16
src/main/java/com/bicloud/pojo/entity/LiteratureInfo.java
Normal file
16
src/main/java/com/bicloud/pojo/entity/LiteratureInfo.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package com.bicloud.pojo.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
@Data // Lombok注解,自动生成get/set/toString等方法
|
||||||
|
public class LiteratureInfo {
|
||||||
|
private Long id;
|
||||||
|
private Integer year;
|
||||||
|
private String articleTitle; // 对应表中article_title
|
||||||
|
private String journalName; // 对应journal_name
|
||||||
|
private BigDecimal impactFactor; // 对应impact_factor
|
||||||
|
private String sampleSource; // 对应sample_source
|
||||||
|
private String literatureType; // 对应literature_type
|
||||||
|
private String literatureUrl; // 对应literature_url
|
||||||
|
}
|
||||||
17
src/main/java/com/bicloud/service/LiteratureService.java
Normal file
17
src/main/java/com/bicloud/service/LiteratureService.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.bicloud.service;
|
||||||
|
|
||||||
|
import com.bicloud.common.result.PageResult;
|
||||||
|
import com.bicloud.pojo.dto.LiteratureDto;
|
||||||
|
import com.bicloud.pojo.dto.LiteraturePageQueryDto;
|
||||||
|
|
||||||
|
public interface LiteratureService {
|
||||||
|
// 新增文献
|
||||||
|
void addLiterature(LiteratureDto literatureDTO);
|
||||||
|
|
||||||
|
// 删除文献
|
||||||
|
void deleteLiterature(Long id);
|
||||||
|
|
||||||
|
// 文献分页查询
|
||||||
|
PageResult<LiteratureDto> pageQuery(LiteraturePageQueryDto queryDTO);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.bicloud.service.impl;
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.bicloud.common.result.PageResult;
|
||||||
|
import com.bicloud.pojo.dto.LiteratureDto;
|
||||||
|
import com.bicloud.pojo.dto.LiteraturePageQueryDto;
|
||||||
|
import com.bicloud.pojo.entity.LiteratureInfo;
|
||||||
|
import com.bicloud.mapper.LiteratureMapper;
|
||||||
|
import com.bicloud.service.LiteratureService;
|
||||||
|
import org.springframework.beans.BeanUtils; // Spring工具类,用于对象属性拷贝
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class LiteratureServiceImpl implements LiteratureService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LiteratureMapper literatureMapper;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增文献
|
||||||
|
* @param literatureDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void addLiterature(LiteratureDto literatureDTO) {
|
||||||
|
// 把DTO转成Entity
|
||||||
|
LiteratureInfo literatureInfo = new LiteratureInfo();
|
||||||
|
BeanUtils.copyProperties(literatureDTO, literatureInfo); // 自动拷贝同名属性
|
||||||
|
|
||||||
|
// 调用Mapper插入数据库
|
||||||
|
literatureMapper.insertLiterature(literatureInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除文献
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteLiterature(Long id) {
|
||||||
|
literatureMapper.deleteLiteratureById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文献分页查询
|
||||||
|
* @param queryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult<LiteratureDto> pageQuery(LiteraturePageQueryDto queryDTO) {
|
||||||
|
|
||||||
|
// 1) PageHelper 开始分页
|
||||||
|
PageHelper.startPage(queryDTO.getPage(), queryDTO.getPageSize());
|
||||||
|
|
||||||
|
// 2) 执行 mapper 查询(会被 PageHelper 自动加 limit)
|
||||||
|
Page<LiteratureInfo> page = literatureMapper.pageQuery(queryDTO);
|
||||||
|
|
||||||
|
// 3) 取 total + records
|
||||||
|
long total = page.getTotal();
|
||||||
|
List<LiteratureDto> records = page.getResult().stream().map(info -> {
|
||||||
|
LiteratureDto dto = new LiteratureDto();
|
||||||
|
BeanUtils.copyProperties(info, dto);
|
||||||
|
return dto;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
return new PageResult<>(total, records);
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/main/resources/application.yml
Normal file
39
src/main/resources/application.yml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
server:
|
||||||
|
port: 8080
|
||||||
|
servlet:
|
||||||
|
context-path: /
|
||||||
|
|
||||||
|
spring:
|
||||||
|
datasource:
|
||||||
|
url: jdbc:mysql://192.168.1.102:3308/genome1_db?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||||
|
username: app_user
|
||||||
|
password: "NewSecurePassword123"
|
||||||
|
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
|
hikari:
|
||||||
|
connection-timeout: 30000
|
||||||
|
maximum-pool-size: 10
|
||||||
|
minimum-idle: 5
|
||||||
|
|
||||||
|
mybatis:
|
||||||
|
mapper-locations: classpath*:mapper/*.xml
|
||||||
|
type-aliases-package: com.genepioneer.pojo.entity
|
||||||
|
configuration:
|
||||||
|
map-underscore-to-camel-case: true
|
||||||
|
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||||
|
|
||||||
|
springdoc:
|
||||||
|
default-flat-param-object: true
|
||||||
|
api-docs:
|
||||||
|
enabled: true
|
||||||
|
swagger-ui:
|
||||||
|
enabled: true
|
||||||
|
path: /swagger-ui.html
|
||||||
|
|
||||||
|
knife4j:
|
||||||
|
enable: true
|
||||||
|
setting:
|
||||||
|
language: zh-CN
|
||||||
|
|
||||||
|
logging:
|
||||||
|
level:
|
||||||
|
com.genepioneer.mapper: debug
|
||||||
43
src/main/resources/mapper/LiteratureMapper.xml
Normal file
43
src/main/resources/mapper/LiteratureMapper.xml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?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.bicloud.mapper.LiteratureMapper">
|
||||||
|
|
||||||
|
<select id="pageQuery" resultType="com.bicloud.pojo.entity.LiteratureInfo">
|
||||||
|
select *
|
||||||
|
from literature_info
|
||||||
|
<where>
|
||||||
|
<if test="year != null">
|
||||||
|
and year = #{year}
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="articleTitle != null and articleTitle != ''">
|
||||||
|
and article_title like concat('%', #{articleTitle}, '%')
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="journalName != null and journalName != ''">
|
||||||
|
and journal_name like concat('%', #{journalName}, '%')
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="literatureType != null and literatureType != ''">
|
||||||
|
and literature_type like concat('%', #{literatureType}, '%')
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="sampleSource != null and sampleSource != ''">
|
||||||
|
and sample_source like concat('%', #{sampleSource}, '%')
|
||||||
|
</if>
|
||||||
|
|
||||||
|
|
||||||
|
<if test="impactFactorMin != null">
|
||||||
|
and impact_factor >= #{impactFactorMin}
|
||||||
|
</if>
|
||||||
|
|
||||||
|
<if test="impactFactorMax != null">
|
||||||
|
and impact_factor <= #{impactFactorMax}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by id desc
|
||||||
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user