5 Commits

Author SHA1 Message Date
f431d9eaf1 Merge pull request '发送验证码接口' (#1) from refactor/rename-literature-to-document into master
Reviewed-on: #1
2026-01-29 10:37:12 +08:00
dww
c1144fadcb 发送验证码接口 2026-01-29 10:32:16 +08:00
dww
ddcb8a1ad3 文献相关接口 2026-01-27 13:32:19 +08:00
dww
3963d64781 文献相关接口 2026-01-27 10:32:52 +08:00
dww
4fa0d501d4 课程中心相关接口 2026-01-27 08:52:20 +08:00
30 changed files with 598 additions and 237 deletions

View File

@@ -0,0 +1,7 @@
{
"permissions": {
"allow": [
"Bash(git mv:*)"
]
}
}

2
.gitignore vendored
View File

@@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 301 KiB

BIN
media/video/testVideo.mp4 Normal file

Binary file not shown.

View File

@@ -0,0 +1,29 @@
package com.bicloud.common.utils;
public class RedisConstants {
public static final String LOGIN_CODE_KEY = "login:code:";
public static final String GET_CODE_LOCK = "getCodeLock:phone:";
public static final String GET_CODE_BLACKLIST_PHONE = "getCodeBlacklist:phone:";
public static final String GET_CODE_BLACKLIST_IP_ADDR = "getCodeBlacklist:ipAddr:";
public static final String GET_CODE_BLACKLIST_MAC_ADDR = "getCodeBlacklist:macAddr:";
public static final Long GET_CODE_LOCK_TTL = 1L;
public static final Long REFRESH_BLACKLIST_TTL = 24L;
public static final Long LOGIN_CODE_TTL = 2L;
public static final String LOGIN_USER_KEY = "login:token:";
public static final Long LOGIN_USER_TTL = 36000L;
public static final Long CACHE_NULL_TTL = 2L;
public static final Long CACHE_SHOP_TTL = 30L;
public static final String CACHE_SHOP_KEY = "cache:shop:";
public static final String LOCK_SHOP_KEY = "lock:shop:";
public static final Long LOCK_SHOP_TTL = 10L;
public static final String SECKILL_STOCK_KEY = "seckill:stock:";
public static final String SECKILL_ORDER_KEY = "seckill:order";
public static final String BLOG_LIKED_KEY = "blog:liked:";
public static final String FEED_KEY = "feed:";
public static final String SHOP_GEO_KEY = "shop:geo:";
public static final String USER_SIGN_KEY = "sign:";
}

View File

@@ -0,0 +1,20 @@
package com.bicloud.common.utils;
public class RegexPatterns {
/**
* 手机号正则
*/
public static final String PHONE_REGEX = "^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\\d{8}$";
/**
* 邮箱正则
*/
public static final String EMAIL_REGEX = "^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
/**
* 密码正则。4~32位的字母、数字、下划线
*/
public static final String PASSWORD_REGEX = "^\\w{4,32}$";
/**
* 验证码正则, 6位数字或字母
*/
public static final String VERIFY_CODE_REGEX = "^[a-zA-Z\\d]{6}$";
}

View File

@@ -0,0 +1,39 @@
package com.bicloud.common.utils;
import com.github.xiaoymin.knife4j.core.util.StrUtil;
public class RegexUtils {
/**
* 是否是无效手机格式
* @param phone 要校验的手机号
* @return true:符合false不符合
*/
public static boolean isPhoneInvalid(String phone){
return mismatch(phone, RegexPatterns.PHONE_REGEX);
}
/**
* 是否是无效邮箱格式
* @param email 要校验的邮箱
* @return true:符合false不符合
*/
public static boolean isEmailInvalid(String email){
return mismatch(email, RegexPatterns.EMAIL_REGEX);
}
/**
* 是否是无效验证码格式
* @param code 要校验的验证码
* @return true:符合false不符合
*/
public static boolean isCodeInvalid(String code){
return mismatch(code, RegexPatterns.VERIFY_CODE_REGEX);
}
// 校验是否不符合正则格式
private static boolean mismatch(String str, String regex){
if (StrUtil.isBlank(str)) {
return true;
}
return !str.matches(regex);
}
}

View File

@@ -31,7 +31,7 @@ public class OpenApiConfig {
// 分组1文献管理接口
@Bean
public GroupedOpenApi literatureApi() {
public GroupedOpenApi documentApi() {
return GroupedOpenApi.builder()
.group("bicloud接口") // 分组名称
.packagesToScan("com.bicloud.controller") // 匹配的接口路径

View File

@@ -0,0 +1,64 @@
package com.bicloud.controller;
import com.bicloud.common.result.PageResult;
import com.bicloud.common.result.Result;
import com.bicloud.pojo.dto.DocumentCreateDto;
import com.bicloud.pojo.dto.DocumentPageQueryDto;
import com.bicloud.pojo.vo.DocumentTypeVo;
import com.bicloud.pojo.vo.DocumentListVo;
import com.bicloud.service.DocumentService;
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.*;
import java.util.List;
@CrossOrigin
@RestController
@RequestMapping("/document")
@Tag(name = "文献管理", description = "文献相关接口")
@Slf4j
public class DocumentController {
@Autowired
private DocumentService documentService;
// 新增文献数据
@PostMapping("/add")
@Operation(summary = "新增文献")
public Result<String> addDocument(@RequestBody DocumentCreateDto dto) {
documentService.addDocument(dto);
return Result.success("新增文献成功");
}
// 删除文献
@DeleteMapping("/delete/{id}") // 通过路径变量接收文献ID
@Operation(summary = "删除文献")
public Result<String> deleteDocument(@PathVariable Long id) { // @PathVariable绑定路径中的id参数
try {
documentService.deleteDocument(id);
return Result.success("删除文献成功");
} catch (Exception e) {
e.printStackTrace();
return Result.error("删除文献失败:" + e.getMessage());
}
}
//分页查询
@Operation(summary = "分页查询文献")
@GetMapping("/page")
public Result<PageResult<DocumentListVo>> page(DocumentPageQueryDto queryDTO) {
PageResult<DocumentListVo> result = documentService.pageQuery(queryDTO);
return Result.success(result);
}
// 文献分类下拉框document_type
@GetMapping("/types")
@Operation(summary = "获取文献分类下拉列表")
public Result<List<DocumentTypeVo>> types() {
return Result.success(documentService.listTypes());
}
}

View File

@@ -1,60 +0,0 @@
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);
}
}

View File

@@ -0,0 +1,33 @@
package com.bicloud.controller;
import com.bicloud.common.result.Result;
import com.bicloud.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@CrossOrigin
@RestController
@RequestMapping("/user")
@Tag(name = "用户管理")
@Slf4j
public class UserController {
@Autowired
private UserService userService;
/**
* 发送手机验证码
*/
@PostMapping("code")
@Operation(summary = "发送验证码")
public Result sendCode(@RequestParam("phone") String phone, HttpSession session, HttpServletRequest request) {
// 发送短信验证码并保存验证码
return userService.sendCode(phone, session, request);
}
}

View File

@@ -0,0 +1,26 @@
package com.bicloud.mapper;
import com.bicloud.pojo.dto.DocumentCreateDto;
import com.bicloud.pojo.dto.DocumentPageQueryDto;
import com.bicloud.pojo.vo.DocumentTypeVo;
import com.bicloud.pojo.vo.DocumentListVo;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface DocumentMapper {
// 新增:插入 biology_document_info
int insertDocument(DocumentCreateDto dto);
// 删除:软删除 removed=1
int softDeleteById(Long id);
// 分页查询返回列表VOPageHelper自动分页
Page<DocumentListVo> pageQuery(DocumentPageQueryDto queryDTO);
// 获取文献分类
List<DocumentTypeVo> listTypes();
}

View File

@@ -1,25 +0,0 @@
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);
}

View File

@@ -0,0 +1,31 @@
package com.bicloud.pojo.dto;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 新增文献(写入 biology_document_info的入参
*/
@Data
public class DocumentCreateDto {
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,7 +4,7 @@ import lombok.Data;
import java.math.BigDecimal;
@Data
public class LiteratureDto {
public class DocumentDto {
// 字段名要和前端提交的参数名一致
private Long id;
private Integer year;

View File

@@ -0,0 +1,26 @@
package com.bicloud.pojo.dto;
import lombok.Data;
import java.math.BigDecimal;
/**
* 列表页筛选 + 分页参数
*/
@Data
public class DocumentPageQueryDto {
private Integer page;
private Integer pageSize;
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最大值
}

View File

@@ -1,18 +0,0 @@
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;
}

View File

@@ -4,7 +4,7 @@ import lombok.Data;
import java.math.BigDecimal;
@Data // Lombok注解自动生成get/set/toString等方法
public class LiteratureInfo {
public class DocumentInfo {
private Long id;
private Integer year;
private String articleTitle; // 对应表中article_title

View File

@@ -0,0 +1,19 @@
package com.bicloud.pojo.vo;
import lombok.Data;
/**
* 列表页返回对象
*/
@Data
public class DocumentListVo {
private Long id; // 隐藏id
private Integer year; // 年份
private String docTitle; // 文章标题
private String publication; // 期刊
private String impactFactor; // IFvarchar原样返回避免精度/格式问题)
private String techniques; // 样品来源(先用 techniques
private String typeName; // 文献分类名
private String docUrl; //链接
}

View File

@@ -0,0 +1,12 @@
package com.bicloud.pojo.vo;
import lombok.Data;
/**
* 文献分类document_type下拉项
*/
@Data
public class DocumentTypeVo {
private Integer id;
private String name;
}

View File

@@ -0,0 +1,24 @@
package com.bicloud.service;
import com.bicloud.common.result.PageResult;
import com.bicloud.pojo.dto.DocumentCreateDto;
import com.bicloud.pojo.dto.DocumentPageQueryDto;
import com.bicloud.pojo.vo.DocumentTypeVo;
import com.bicloud.pojo.vo.DocumentListVo;
import java.util.List;
public interface DocumentService {
// 新增文献(写入 biology_document_info
void addDocument(DocumentCreateDto dto);
// 删除文献软删除removed=1
void deleteDocument(Long id);
// 分页查询返回列表VO
PageResult<DocumentListVo> pageQuery(DocumentPageQueryDto queryDTO);
// 获取文献分类下拉列表
List<DocumentTypeVo> listTypes();
}

View File

@@ -1,17 +0,0 @@
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);
}

View File

@@ -0,0 +1,9 @@
package com.bicloud.service;
import com.bicloud.common.result.Result;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
public interface UserService {
Result sendCode(String phone, HttpSession session, HttpServletRequest request);
}

View File

@@ -0,0 +1,57 @@
package com.bicloud.service.impl;
import com.bicloud.common.result.PageResult;
import com.bicloud.mapper.DocumentMapper;
import com.bicloud.pojo.dto.DocumentCreateDto;
import com.bicloud.pojo.dto.DocumentPageQueryDto;
import com.bicloud.pojo.vo.DocumentTypeVo;
import com.bicloud.pojo.vo.DocumentListVo;
import com.bicloud.service.DocumentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class DocumentServiceImpl implements DocumentService {
@Autowired
private DocumentMapper documentMapper;
@Override
public void addDocument(DocumentCreateDto dto) {
// 新库:直接写入 biology_document_infoSQL 在 XML
documentMapper.insertDocument(dto);
}
@Override
public void deleteDocument(Long id) {
// 新库:软删除 removed=1
documentMapper.softDeleteById(id);
}
@Override
public PageResult<DocumentListVo> pageQuery(DocumentPageQueryDto queryDTO) {
// 1) 兜底默认值,避免空指针/非法分页参数
int page = (queryDTO.getPage() == null || queryDTO.getPage() < 1) ? 1 : queryDTO.getPage();
int pageSize = (queryDTO.getPageSize() == null || queryDTO.getPageSize() < 1) ? 10 : queryDTO.getPageSize();
// 2) PageHelper 开始分页
PageHelper.startPage(page, pageSize);
// 3) 执行 mapper 查询PageHelper 自动分页 + 自动 count
Page<DocumentListVo> p = documentMapper.pageQuery(queryDTO);
// 4) 取 total + records
return new PageResult<>(p.getTotal(), p.getResult());
}
@Override
public List<DocumentTypeVo> listTypes() {
return documentMapper.listTypes();
}
}

View File

@@ -1,71 +0,0 @@
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);
}
}

View File

@@ -0,0 +1,72 @@
package com.bicloud.service.impl;
import com.bicloud.common.result.Result;
import com.bicloud.common.utils.RegexUtils;
import com.bicloud.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
import java.util.concurrent.TimeUnit;
import static com.bicloud.common.utils.RedisConstants.*;
@Service
@Slf4j
public class UserServiceImpl implements UserService {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Override
public Result sendCode(String phone, HttpSession session, HttpServletRequest request) {
// 1.校验手机号
if (RegexUtils.isPhoneInvalid(phone)) {
// 2.如果不符合,返回错误信息
return Result.error("手机号格式错误!");
}
// 3. 获取客户端IP地址
String clientIpAddr = request.getRemoteAddr();
// 4.如果存在锁,直接返回失败
String phoneGetCodeLock = stringRedisTemplate.opsForValue().get(GET_CODE_LOCK + phone);
if (phoneGetCodeLock != null) {
return Result.error("获取验证码过快,请稍后重试!");
}
// 5.检查两个黑名单中的次数
String blacklistPhoneCount = stringRedisTemplate.opsForValue().get(GET_CODE_BLACKLIST_PHONE + phone);
int getCodePhoneCount = (blacklistPhoneCount != null) ? Integer.parseInt(blacklistPhoneCount) : 0;
if (getCodePhoneCount >= 400) {
return Result.error("获取验证码次数过多,您的手机号已被限制!");
}
String blacklistIpAddrCount = stringRedisTemplate.opsForValue().get(GET_CODE_BLACKLIST_IP_ADDR + clientIpAddr);
int getCodeIpAddrCount = (blacklistIpAddrCount != null) ? Integer.parseInt(blacklistIpAddrCount) : 0;
if (getCodeIpAddrCount >= 300) {
return Result.error("获取验证码次数过多您的IP已被限制");
}
// 6.更新锁和黑名单
stringRedisTemplate.opsForValue().set(GET_CODE_BLACKLIST_PHONE + phone, String.valueOf(getCodePhoneCount + 1), REFRESH_BLACKLIST_TTL, TimeUnit.HOURS);
stringRedisTemplate.opsForValue().set(GET_CODE_BLACKLIST_IP_ADDR + clientIpAddr, String.valueOf(getCodeIpAddrCount + 1), REFRESH_BLACKLIST_TTL, TimeUnit.HOURS);
stringRedisTemplate.opsForValue().set(GET_CODE_LOCK + phone, "1", GET_CODE_LOCK_TTL, TimeUnit.MINUTES);
// 7.校验通过,生成验证码
// String code = RandomUtil.randomNumbers(6);
String code = "123123"; //为了方便测试,改成固定值
// 8.保存验证码到 redis并上锁
stringRedisTemplate.opsForValue().set(LOGIN_CODE_KEY + phone, code, LOGIN_CODE_TTL, TimeUnit.MINUTES);
// 9.发送验证码
log.debug("发送短信验证码成功,验证码:{}", code);
// 10.返回ok
return Result.success("发送短信验证码成功,验证码:"+code);
}
}

View File

@@ -16,6 +16,18 @@ spring:
connection-timeout: 30000
maximum-pool-size: 10
minimum-idle: 5
data:
redis:
host: 127.0.0.1
port: 6379
password: 123456
database: 2
lettuce:
pool:
max-active: 10
max-idle: 10
min-idle: 1
time-between-eviction-runs: 10s
mybatis:
mapper-locations: classpath*:mapper/*.xml

View File

@@ -0,0 +1,108 @@
<?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.DocumentMapper">
<!-- 新增文献:写入 biology_document_info -->
<insert id="insertDocument" parameterType="com.bicloud.pojo.dto.DocumentCreateDto" 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>
<!-- 软删除removed=1 -->
<update id="softDeleteById" parameterType="long">
UPDATE biology_document_info
SET removed = 1, updtime = NOW()
WHERE id = #{id}
</update>
<!-- 分页查询列表页7字段 + id
说明:
1) YEAR 取 publish_time
2) 文献分类名来自 biology_document_type.namejoin
3) IF范围impact_factor 是varchar先用 REGEXP 过滤“纯数字/小数”,再 CAST 比较
-->
<select id="pageQuery" resultType="com.bicloud.pojo.vo.DocumentListVo">
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,
d.doc_url AS docUrl
FROM biology_document_info d
LEFT JOIN biology_document_type t
ON t.id = d.doc_type
WHERE d.removed = 0
<if test="year != null">
AND d.publish_time IS NOT NULL
AND YEAR(d.publish_time) = #{year}
</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="techniques != null and techniques != ''">
AND d.techniques LIKE CONCAT('%', #{techniques}, '%')
</if>
<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)) &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>
<!-- 文献分类document_type下拉列表 -->
<select id="listTypes" resultType="com.bicloud.pojo.vo.DocumentTypeVo">
SELECT
id,
name
FROM biology_document_type
WHERE removed = '0'
ORDER BY position ASC, id ASC
</select>
</mapper>

View File

@@ -1,43 +0,0 @@
<?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 &gt;= #{impactFactorMin}
</if>
<if test="impactFactorMax != null">
and impact_factor &lt;= #{impactFactorMax}
</if>
</where>
order by id desc
</select>
</mapper>

View File

@@ -1,13 +1,18 @@
package com.bicloud;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
@SpringBootTest
class BicloudApplicationTests {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Test
void contextLoads() {
}
}