Compare commits

..

2 Commits

Author SHA1 Message Date
dww
3963d64781 文献相关接口 2026-01-27 10:32:52 +08:00
dww
4fa0d501d4 课程中心相关接口 2026-01-27 08:52:20 +08:00
11 changed files with 195 additions and 117 deletions

2
.gitignore vendored
View File

@@ -3,6 +3,8 @@ target/
.mvn/wrapper/maven-wrapper.jar .mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/ !**/src/main/**/target/
!**/src/test/**/target/ !**/src/test/**/target/
/media/
### STS ### ### STS ###
.apt_generated .apt_generated

BIN
media/img/test.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 KiB

BIN
media/video/testVideo.mp4 Normal file

Binary file not shown.

View File

@@ -2,8 +2,10 @@ package com.bicloud.controller;
import com.bicloud.common.result.PageResult; import com.bicloud.common.result.PageResult;
import com.bicloud.common.result.Result; import com.bicloud.common.result.Result;
import com.bicloud.pojo.dto.LiteratureCreateDto;
import com.bicloud.pojo.dto.LiteratureDto; import com.bicloud.pojo.dto.LiteratureDto;
import com.bicloud.pojo.dto.LiteraturePageQueryDto; import com.bicloud.pojo.dto.LiteraturePageQueryDto;
import com.bicloud.pojo.vo.LiteratureListVo;
import com.bicloud.service.LiteratureService; import com.bicloud.service.LiteratureService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@@ -24,16 +26,9 @@ public class LiteratureController {
// 新增文献数据 // 新增文献数据
@PostMapping("/add") @PostMapping("/add")
@Operation(summary = "新增文献") @Operation(summary = "新增文献")
public Result<String> addLiterature(@RequestBody LiteratureDto literatureDTO) { public Result<String> addLiterature(@RequestBody LiteratureCreateDto dto) {
try { literatureService.addLiterature(dto);
literatureService.addLiterature(literatureDTO); return Result.success("新增文献成功");
// 成功返回200码
return Result.success("新增文献成功");
} catch (Exception e) {
e.printStackTrace();
// 失败返回500码、自定义失败提示
return Result.error("新增文献失败:" + e.getMessage());
}
} }
// 删除文献 // 删除文献
@@ -50,11 +45,10 @@ public class LiteratureController {
} }
//分页查询 //分页查询
@GetMapping("/page")
@Operation(summary = "分页查询文献") @Operation(summary = "分页查询文献")
public Result<PageResult<LiteratureDto>> page(LiteraturePageQueryDto queryDTO) { @GetMapping("/page")
log.info("传入参数为:"+queryDTO); public Result<PageResult<LiteratureListVo>> page(LiteraturePageQueryDto queryDTO) {
PageResult<LiteratureDto> result = literatureService.pageQuery(queryDTO); PageResult<LiteratureListVo> result = literatureService.pageQuery(queryDTO);
return Result.success(result); return Result.success(result);
} }
} }

View File

@@ -1,25 +1,20 @@
package com.bicloud.mapper; package com.bicloud.mapper;
import com.bicloud.pojo.dto.LiteratureCreateDto;
import com.bicloud.pojo.dto.LiteraturePageQueryDto; import com.bicloud.pojo.dto.LiteraturePageQueryDto;
import com.bicloud.pojo.entity.LiteratureInfo; import com.bicloud.pojo.vo.LiteratureListVo;
import com.github.pagehelper.Page; 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.Mapper;
@Mapper @Mapper
public interface LiteratureMapper { public interface LiteratureMapper {
// 插入文献数据 // 新增:插入 biology_document_info
@Insert("INSERT INTO literature_info(year, article_title, journal_name, impact_factor, sample_source, literature_type,literature_url) " + int insertDocument(LiteratureCreateDto dto);
"VALUES(#{year}, #{articleTitle}, #{journalName}, #{impactFactor}, #{sampleSource}, #{literatureType},#{literatureUrl})")
int insertLiterature(LiteratureInfo literatureInfo);
// 删除:软删除 removed=1
int softDeleteById(Long id);
// 根据文献ID删除数据 // 分页查询返回列表VOPageHelper自动分页
@Delete("DELETE FROM literature_info WHERE id = #{id}") Page<LiteratureListVo> pageQuery(LiteraturePageQueryDto queryDTO);
void deleteLiteratureById(Long id);
Page<LiteratureInfo> pageQuery(LiteraturePageQueryDto queryDTO);
} }

View 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; // 是否有内容(可空)
}

View File

@@ -4,15 +4,23 @@ import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
/**
* 列表页筛选 + 分页参数
*/
@Data @Data
public class LiteraturePageQueryDto { public class LiteraturePageQueryDto {
private Integer page; private Integer page;
private Integer pageSize; private Integer pageSize;
private String articleTitle;
private Integer year; private Integer year; // YEAR(publish_time)
private String journalName; private String docTitle; // 文章标题(模糊)
private String literatureType; private String publication; // 期刊名称(模糊)
private String sampleSource; private String techniques; // 样品来源(模糊)
private BigDecimal impactFactorMin; private Integer docType; // 文献分类类型ID下拉建议传这个
private BigDecimal impactFactorMax;
private String keyword; // 关键字搜索(可选:对标题/期刊/作者/简介做模糊)
private BigDecimal impactFactorMin; // IF最小值
private BigDecimal impactFactorMax; // IF最大值
} }

View 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; // IFvarchar原样返回避免精度/格式问题)
private String techniques; // 样品来源(先用 techniques
private String typeName; // 文献分类名(来自 biology_document_type.name
}

View File

@@ -1,17 +1,18 @@
package com.bicloud.service; package com.bicloud.service;
import com.bicloud.common.result.PageResult; 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.dto.LiteraturePageQueryDto;
import com.bicloud.pojo.vo.LiteratureListVo;
public interface LiteratureService { public interface LiteratureService {
// 新增文献
void addLiterature(LiteratureDto literatureDTO);
// 删除文献 // 新增文献(写入 biology_document_info
void addLiterature(LiteratureCreateDto dto);
// 删除文献软删除removed=1
void deleteLiterature(Long id); void deleteLiterature(Long id);
// 文献分页查询 // 分页查询返回列表VO
PageResult<LiteratureDto> pageQuery(LiteraturePageQueryDto queryDTO); PageResult<LiteratureListVo> pageQuery(LiteraturePageQueryDto queryDTO);
} }

View File

@@ -1,71 +1,48 @@
package com.bicloud.service.impl; 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.Page;
import com.github.pagehelper.PageHelper; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service @Service
public class LiteratureServiceImpl implements LiteratureService { public class LiteratureServiceImpl implements LiteratureService {
@Autowired @Autowired
private LiteratureMapper literatureMapper; private LiteratureMapper literatureMapper;
/**
* 新增文献
* @param literatureDTO
*/
@Override @Override
public void addLiterature(LiteratureDto literatureDTO) { public void addLiterature(LiteratureCreateDto dto) {
// 把DTO转成Entity // 新库:直接写入 biology_document_infoSQL 在 XML
LiteratureInfo literatureInfo = new LiteratureInfo(); literatureMapper.insertDocument(dto);
BeanUtils.copyProperties(literatureDTO, literatureInfo); // 自动拷贝同名属性
// 调用Mapper插入数据库
literatureMapper.insertLiterature(literatureInfo);
} }
/**
* 删除文献
* @param id
*/
@Override @Override
public void deleteLiterature(Long id) { public void deleteLiterature(Long id) {
literatureMapper.deleteLiteratureById(id); // 新库:软删除 removed=1
literatureMapper.softDeleteById(id);
} }
/**
* 文献分页查询
* @param queryDTO
* @return
*/
@Override @Override
public PageResult<LiteratureDto> pageQuery(LiteraturePageQueryDto queryDTO) { public PageResult<LiteratureListVo> pageQuery(LiteraturePageQueryDto queryDTO) {
// 1) PageHelper 开始分页 // 1) 兜底默认值,避免空指针/非法分页参数
PageHelper.startPage(queryDTO.getPage(), queryDTO.getPageSize()); 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 // 2) PageHelper 开始分页
Page<LiteratureInfo> page = literatureMapper.pageQuery(queryDTO); PageHelper.startPage(page, pageSize);
// 3) 取 total + records // 3) 执行 mapper 查询PageHelper 自动分页 + 自动 count
long total = page.getTotal(); Page<LiteratureListVo> p = literatureMapper.pageQuery(queryDTO);
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); // 4) 取 total + records
return new PageResult<>(p.getTotal(), p.getResult());
} }
} }

View File

@@ -3,41 +3,93 @@
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bicloud.mapper.LiteratureMapper"> <mapper namespace="com.bicloud.mapper.LiteratureMapper">
<select id="pageQuery" resultType="com.bicloud.pojo.entity.LiteratureInfo"> <!-- 新增文献:写入 biology_document_info -->
select * <insert id="insertDocument" parameterType="com.bicloud.pojo.dto.LiteratureCreateDto" useGeneratedKeys="true" keyProperty="id">
from literature_info INSERT INTO biology_document_info
<where> (doc_type, doc_label, doc_title, doc_icon, doc_desp, doc_info,
<if test="year != null"> doc_collect, position, author, publication, impact_factor,
and year = #{year} publish_time, techniques, addtime, updtime, status, if_content, removed)
</if> 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 != ''"> <!-- 软删除removed=1 -->
and article_title like concat('%', #{articleTitle}, '%') <update id="softDeleteById" parameterType="long">
</if> UPDATE biology_document_info
SET removed = 1, updtime = NOW()
WHERE id = #{id}
</update>
<if test="journalName != null and journalName != ''"> <!-- 分页查询列表页7字段 + id
and journal_name like concat('%', #{journalName}, '%') 说明:
</if> 1) YEAR 取 publish_time
2) 文献分类名来自 biology_document_type.namejoin
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 != ''"> <if test="year != null">
and literature_type like concat('%', #{literatureType}, '%') AND d.publish_time IS NOT NULL
</if> AND YEAR(d.publish_time) = #{year}
</if>
<if test="sampleSource != null and sampleSource != ''"> <if test="docTitle != null and docTitle != ''">
and sample_source like concat('%', #{sampleSource}, '%') AND d.doc_title LIKE CONCAT('%', #{docTitle}, '%')
</if> </if>
<if test="publication != null and publication != ''">
AND d.publication LIKE CONCAT('%', #{publication}, '%')
</if>
<if test="impactFactorMin != null"> <if test="techniques != null and techniques != ''">
and impact_factor &gt;= #{impactFactorMin} AND d.techniques LIKE CONCAT('%', #{techniques}, '%')
</if> </if>
<if test="impactFactorMax != null"> <if test="docType != null">
and impact_factor &lt;= #{impactFactorMax} AND d.doc_type = #{docType}
</if> </if>
</where>
order by id desc <!-- 关键字:可按需扩大范围(这里覆盖标题/期刊/作者/简介) -->
<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)) &gt;= #{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)) &lt;= #{impactFactorMax}
</if>
ORDER BY d.id DESC
</select> </select>
</mapper> </mapper>