Compare commits
2 Commits
a5e68f197d
...
3963d64781
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3963d64781 | ||
|
|
4fa0d501d4 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -3,6 +3,8 @@ target/
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
!**/src/main/**/target/
|
||||
!**/src/test/**/target/
|
||||
/media/
|
||||
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
|
||||
BIN
media/img/test.jpg
Normal file
BIN
media/img/test.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 301 KiB |
BIN
media/video/testVideo.mp4
Normal file
BIN
media/video/testVideo.mp4
Normal file
Binary file not shown.
@@ -2,8 +2,10 @@ package com.bicloud.controller;
|
||||
|
||||
import com.bicloud.common.result.PageResult;
|
||||
import com.bicloud.common.result.Result;
|
||||
import com.bicloud.pojo.dto.LiteratureCreateDto;
|
||||
import com.bicloud.pojo.dto.LiteratureDto;
|
||||
import com.bicloud.pojo.dto.LiteraturePageQueryDto;
|
||||
import com.bicloud.pojo.vo.LiteratureListVo;
|
||||
import com.bicloud.service.LiteratureService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -24,16 +26,9 @@ public class LiteratureController {
|
||||
// 新增文献数据
|
||||
@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());
|
||||
}
|
||||
public Result<String> addLiterature(@RequestBody LiteratureCreateDto dto) {
|
||||
literatureService.addLiterature(dto);
|
||||
return Result.success("新增文献成功");
|
||||
}
|
||||
|
||||
// 删除文献
|
||||
@@ -50,11 +45,10 @@ public class LiteratureController {
|
||||
}
|
||||
|
||||
//分页查询
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "分页查询文献")
|
||||
public Result<PageResult<LiteratureDto>> page(LiteraturePageQueryDto queryDTO) {
|
||||
log.info("传入参数为:"+queryDTO);
|
||||
PageResult<LiteratureDto> result = literatureService.pageQuery(queryDTO);
|
||||
@GetMapping("/page")
|
||||
public Result<PageResult<LiteratureListVo>> page(LiteraturePageQueryDto queryDTO) {
|
||||
PageResult<LiteratureListVo> result = literatureService.pageQuery(queryDTO);
|
||||
return Result.success(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,20 @@
|
||||
package com.bicloud.mapper;
|
||||
|
||||
import com.bicloud.pojo.dto.LiteratureCreateDto;
|
||||
import com.bicloud.pojo.dto.LiteraturePageQueryDto;
|
||||
import com.bicloud.pojo.entity.LiteratureInfo;
|
||||
import com.bicloud.pojo.vo.LiteratureListVo;
|
||||
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);
|
||||
// 新增:插入 biology_document_info
|
||||
int insertDocument(LiteratureCreateDto dto);
|
||||
|
||||
// 删除:软删除 removed=1
|
||||
int softDeleteById(Long id);
|
||||
|
||||
// 根据文献ID删除数据
|
||||
@Delete("DELETE FROM literature_info WHERE id = #{id}")
|
||||
void deleteLiteratureById(Long id);
|
||||
|
||||
Page<LiteratureInfo> pageQuery(LiteraturePageQueryDto queryDTO);
|
||||
// 分页查询:返回列表VO(PageHelper自动分页)
|
||||
Page<LiteratureListVo> pageQuery(LiteraturePageQueryDto queryDTO);
|
||||
}
|
||||
|
||||
31
src/main/java/com/bicloud/pojo/dto/LiteratureCreateDto.java
Normal file
31
src/main/java/com/bicloud/pojo/dto/LiteratureCreateDto.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.bicloud.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 新增文献(写入 biology_document_info)的入参
|
||||
*/
|
||||
@Data
|
||||
public class LiteratureCreateDto {
|
||||
|
||||
private Integer docType; // 对应 biology_document_info.doc_type(类型ID)
|
||||
private String docLabel; // 对应 doc_label(目前是varchar,先按原样存)
|
||||
private String docTitle; // 标题
|
||||
private String docIcon; // 封面
|
||||
private String docDesp; // 简介/摘要
|
||||
private String docInfo; // 正文/富文本
|
||||
|
||||
private Integer docCollect; // 收藏/热度(可空)
|
||||
private Integer position; // 排序权重(可空)
|
||||
|
||||
private String author; // 作者
|
||||
private String publication; // 期刊
|
||||
private String impactFactor; // IF(新库是varchar)
|
||||
private LocalDateTime publishTime; // 发表时间
|
||||
private String techniques; // 样品来源/技术(你页面“样品来源”先映射这里)
|
||||
|
||||
private Integer status; // 状态(可空)
|
||||
private Integer ifContent; // 是否有内容(可空)
|
||||
}
|
||||
@@ -4,15 +4,23 @@ 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;
|
||||
}
|
||||
|
||||
private Integer year; // YEAR(publish_time)
|
||||
private String docTitle; // 文章标题(模糊)
|
||||
private String publication; // 期刊名称(模糊)
|
||||
private String techniques; // 样品来源(模糊)
|
||||
private Integer docType; // 文献分类(类型ID,下拉建议传这个)
|
||||
|
||||
private String keyword; // 关键字搜索(可选:对标题/期刊/作者/简介做模糊)
|
||||
|
||||
private BigDecimal impactFactorMin; // IF最小值
|
||||
private BigDecimal impactFactorMax; // IF最大值
|
||||
}
|
||||
|
||||
18
src/main/java/com/bicloud/pojo/vo/LiteratureListVo.java
Normal file
18
src/main/java/com/bicloud/pojo/vo/LiteratureListVo.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.bicloud.pojo.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 列表页返回对象
|
||||
*/
|
||||
@Data
|
||||
public class LiteratureListVo {
|
||||
|
||||
private Long id; // 隐藏id(用于操作)
|
||||
private Integer year; // 年份:由 YEAR(publish_time) 计算得到
|
||||
private String docTitle; // 文章标题
|
||||
private String publication; // 期刊
|
||||
private String impactFactor; // IF(varchar原样返回,避免精度/格式问题)
|
||||
private String techniques; // 样品来源(先用 techniques)
|
||||
private String typeName; // 文献分类名(来自 biology_document_type.name)
|
||||
}
|
||||
@@ -1,17 +1,18 @@
|
||||
package com.bicloud.service;
|
||||
|
||||
import com.bicloud.common.result.PageResult;
|
||||
import com.bicloud.pojo.dto.LiteratureDto;
|
||||
import com.bicloud.pojo.dto.LiteratureCreateDto;
|
||||
import com.bicloud.pojo.dto.LiteraturePageQueryDto;
|
||||
import com.bicloud.pojo.vo.LiteratureListVo;
|
||||
|
||||
public interface LiteratureService {
|
||||
// 新增文献
|
||||
void addLiterature(LiteratureDto literatureDTO);
|
||||
|
||||
// 删除文献
|
||||
// 新增文献(写入 biology_document_info)
|
||||
void addLiterature(LiteratureCreateDto dto);
|
||||
|
||||
// 删除文献(软删除:removed=1)
|
||||
void deleteLiterature(Long id);
|
||||
|
||||
// 文献分页查询
|
||||
PageResult<LiteratureDto> pageQuery(LiteraturePageQueryDto queryDTO);
|
||||
|
||||
}
|
||||
// 分页查询(返回列表VO)
|
||||
PageResult<LiteratureListVo> pageQuery(LiteraturePageQueryDto queryDTO);
|
||||
}
|
||||
|
||||
@@ -1,71 +1,48 @@
|
||||
package com.bicloud.service.impl;
|
||||
|
||||
import com.bicloud.common.result.PageResult;
|
||||
import com.bicloud.mapper.LiteratureMapper;
|
||||
import com.bicloud.pojo.dto.LiteratureCreateDto;
|
||||
import com.bicloud.pojo.dto.LiteraturePageQueryDto;
|
||||
import com.bicloud.pojo.vo.LiteratureListVo;
|
||||
import com.bicloud.service.LiteratureService;
|
||||
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);
|
||||
public void addLiterature(LiteratureCreateDto dto) {
|
||||
// 新库:直接写入 biology_document_info(SQL 在 XML)
|
||||
literatureMapper.insertDocument(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除文献
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void deleteLiterature(Long id) {
|
||||
literatureMapper.deleteLiteratureById(id);
|
||||
// 新库:软删除 removed=1
|
||||
literatureMapper.softDeleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文献分页查询
|
||||
* @param queryDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult<LiteratureDto> pageQuery(LiteraturePageQueryDto queryDTO) {
|
||||
public PageResult<LiteratureListVo> pageQuery(LiteraturePageQueryDto queryDTO) {
|
||||
|
||||
// 1) PageHelper 开始分页
|
||||
PageHelper.startPage(queryDTO.getPage(), queryDTO.getPageSize());
|
||||
// 1) 兜底默认值,避免空指针/非法分页参数
|
||||
int page = (queryDTO.getPage() == null || queryDTO.getPage() < 1) ? 1 : queryDTO.getPage();
|
||||
int pageSize = (queryDTO.getPageSize() == null || queryDTO.getPageSize() < 1) ? 10 : queryDTO.getPageSize();
|
||||
|
||||
// 2) 执行 mapper 查询(会被 PageHelper 自动加 limit)
|
||||
Page<LiteratureInfo> page = literatureMapper.pageQuery(queryDTO);
|
||||
// 2) PageHelper 开始分页
|
||||
PageHelper.startPage(page, pageSize);
|
||||
|
||||
// 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());
|
||||
// 3) 执行 mapper 查询(PageHelper 自动分页 + 自动 count)
|
||||
Page<LiteratureListVo> p = literatureMapper.pageQuery(queryDTO);
|
||||
|
||||
return new PageResult<>(total, records);
|
||||
// 4) 取 total + records
|
||||
return new PageResult<>(p.getTotal(), p.getResult());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,41 +3,93 @@
|
||||
"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>
|
||||
<!-- 新增文献:写入 biology_document_info -->
|
||||
<insert id="insertDocument" parameterType="com.bicloud.pojo.dto.LiteratureCreateDto" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO biology_document_info
|
||||
(doc_type, doc_label, doc_title, doc_icon, doc_desp, doc_info,
|
||||
doc_collect, position, author, publication, impact_factor,
|
||||
publish_time, techniques, addtime, updtime, status, if_content, removed)
|
||||
VALUES
|
||||
(#{docType}, #{docLabel}, #{docTitle}, #{docIcon}, #{docDesp}, #{docInfo},
|
||||
#{docCollect}, #{position}, #{author}, #{publication}, #{impactFactor},
|
||||
#{publishTime}, #{techniques}, NOW(), NOW(), #{status}, #{ifContent}, 0)
|
||||
</insert>
|
||||
|
||||
<if test="articleTitle != null and articleTitle != ''">
|
||||
and article_title like concat('%', #{articleTitle}, '%')
|
||||
</if>
|
||||
<!-- 软删除:removed=1 -->
|
||||
<update id="softDeleteById" parameterType="long">
|
||||
UPDATE biology_document_info
|
||||
SET removed = 1, updtime = NOW()
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<if test="journalName != null and journalName != ''">
|
||||
and journal_name like concat('%', #{journalName}, '%')
|
||||
</if>
|
||||
<!-- 分页查询:列表页7字段 + id
|
||||
说明:
|
||||
1) YEAR 取 publish_time
|
||||
2) 文献分类名来自 biology_document_type.name(join)
|
||||
3) IF范围:impact_factor 是varchar,先用 REGEXP 过滤“纯数字/小数”,再 CAST 比较
|
||||
-->
|
||||
<select id="pageQuery" resultType="com.bicloud.pojo.vo.LiteratureListVo">
|
||||
SELECT
|
||||
d.id,
|
||||
YEAR(d.publish_time) AS year,
|
||||
d.doc_title AS docTitle,
|
||||
d.publication AS publication,
|
||||
d.impact_factor AS impactFactor,
|
||||
d.techniques AS techniques,
|
||||
t.name AS typeName
|
||||
FROM biology_document_info d
|
||||
LEFT JOIN biology_document_type t
|
||||
ON t.id = d.doc_type
|
||||
WHERE d.removed = 0
|
||||
|
||||
<if test="literatureType != null and literatureType != ''">
|
||||
and literature_type like concat('%', #{literatureType}, '%')
|
||||
</if>
|
||||
<if test="year != null">
|
||||
AND d.publish_time IS NOT NULL
|
||||
AND YEAR(d.publish_time) = #{year}
|
||||
</if>
|
||||
|
||||
<if test="sampleSource != null and sampleSource != ''">
|
||||
and sample_source like concat('%', #{sampleSource}, '%')
|
||||
</if>
|
||||
<if test="docTitle != null and docTitle != ''">
|
||||
AND d.doc_title LIKE CONCAT('%', #{docTitle}, '%')
|
||||
</if>
|
||||
|
||||
<if test="publication != null and publication != ''">
|
||||
AND d.publication LIKE CONCAT('%', #{publication}, '%')
|
||||
</if>
|
||||
|
||||
<if test="impactFactorMin != null">
|
||||
and impact_factor >= #{impactFactorMin}
|
||||
</if>
|
||||
<if test="techniques != null and techniques != ''">
|
||||
AND d.techniques LIKE CONCAT('%', #{techniques}, '%')
|
||||
</if>
|
||||
|
||||
<if test="impactFactorMax != null">
|
||||
and impact_factor <= #{impactFactorMax}
|
||||
</if>
|
||||
</where>
|
||||
order by id desc
|
||||
<if test="docType != null">
|
||||
AND d.doc_type = #{docType}
|
||||
</if>
|
||||
|
||||
<!-- 关键字:可按需扩大范围(这里覆盖标题/期刊/作者/简介) -->
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (
|
||||
d.doc_title LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR d.publication LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR d.author LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR d.doc_desp LIKE CONCAT('%', #{keyword}, '%')
|
||||
)
|
||||
</if>
|
||||
|
||||
<!-- IF 下限:仅对可转换为数值的 IF 参与比较 -->
|
||||
<if test="impactFactorMin != null">
|
||||
AND d.impact_factor IS NOT NULL
|
||||
AND d.impact_factor != ''
|
||||
AND d.impact_factor REGEXP '^[0-9]+(\\\\.[0-9]+)?$'
|
||||
AND CAST(d.impact_factor AS DECIMAL(10, 3)) >= #{impactFactorMin}
|
||||
</if>
|
||||
|
||||
<!-- IF 上限 -->
|
||||
<if test="impactFactorMax != null">
|
||||
AND d.impact_factor IS NOT NULL
|
||||
AND d.impact_factor != ''
|
||||
AND d.impact_factor REGEXP '^[0-9]+(\\\\.[0-9]+)?$'
|
||||
AND CAST(d.impact_factor AS DECIMAL(10, 3)) <= #{impactFactorMax}
|
||||
</if>
|
||||
|
||||
ORDER BY d.id DESC
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user