新增了标签搜索

This commit is contained in:
wucongxing8150 2025-06-13 13:16:54 +08:00
parent 637dea8d2f
commit 4ebdb2c862
11 changed files with 504 additions and 4 deletions

View File

@ -657,4 +657,28 @@ public class CaseExchangeController {
resultMap.put("data", resultPage.getRecords());
return Response.success(resultMap);
}
/**
* 病例交流-投票
*/
@PostMapping("/exchange/vote/{exchange_id}")
public Response<T> AddCaseExchangeVote(
@Validated()
@PathVariable("exchange_id") String exchangeId,
@ModelAttribute addCaseExchangeVote r
) {
String userId = (String) httpServletRequest.getAttribute("userId");
if (userId == null) {
return Response.error("操作失败");
}
boolean res = caseExchangeService.AddCaseExchangeVote(exchangeId,userId,r.getOptionId());
if (!res){
return Response.error("操作失败");
}
return Response.success();
}
}

View File

@ -13,11 +13,9 @@ import com.example.caseData.dto.caseClinicalVideo.CaseClinicalVideoDto;
import com.example.caseData.dto.caseClinicalVideoAuthor.CaseClinicalVideoAuthorDto;
import com.example.caseData.dto.statsCaseClinicalDoctor.StatsCaseClinicalDoctorDto;
import com.example.caseData.dto.statsCaseClinicalHospital.StatsCaseClinicalHospitalDto;
import com.example.caseData.dto.statsCaseClinicalLabel.StatsCaseClinicalLabelDto;
import com.example.caseData.model.*;
import com.example.caseData.request.clinicalRequest.getClinicalArticleSearchPage;
import com.example.caseData.request.clinicalRequest.getClinicalDoctorSearchPage;
import com.example.caseData.request.clinicalRequest.getClinicalHospitalSearchPage;
import com.example.caseData.request.clinicalRequest.getClinicalVideoSearchPage;
import com.example.caseData.request.clinicalRequest.*;
import com.example.caseData.service.CaseClinicalArticleService;
import com.example.caseData.service.CaseClinicalVideoService;
import com.example.caseData.utils.Replace;
@ -69,6 +67,9 @@ public class ClinicalController extends BaseController {
@Resource
private CaseClinicalVideoService caseClinicalVideoService;
@Resource
private StatsCaseClinicalLabelDao statsCaseClinicalLabelDao;
/**
@ -289,6 +290,31 @@ public class ClinicalController extends BaseController {
return Response.success(resultMap);
}
/**
* 临床病例库-疾病标签-搜索
*/
@PostMapping("/clinical/label/search")
public Response<Map<String, Object>> getClinicalLabelSearchPage(
@Validated()
@RequestBody getClinicalLabelSearchPage request
) {
request.validateForPage();
Page<StatsCaseClinicalHospitalDto> page = new Page<>(request.getPage(), request.getPageSize());
IPage<StatsCaseClinicalLabelDto> resultPage = statsCaseClinicalLabelDao.getStatsCaseClinicalLabelSearchPage(
page,
request.getLabelName(),
request.handleOrder()
);
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("page", resultPage.getCurrent());
resultMap.put("pageSize", resultPage.getSize());
resultMap.put("total", resultPage.getTotal());
resultMap.put("data", resultPage.getRecords());
return Response.success(resultMap);
}
}

View File

@ -0,0 +1,48 @@
package com.example.caseData.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.caseData.dto.statsCaseClinicalHospital.StatsCaseClinicalHospitalDto;
import com.example.caseData.dto.statsCaseClinicalLabel.StatsCaseClinicalLabelDto;
import com.example.caseData.model.StatsCaseExchangeUserModel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import java.util.Map;
@Mapper
public interface StatsCaseClinicalLabelDao extends BaseMapper<StatsCaseExchangeUserModel> {
/**
* 医院病例库推荐-搜索
* @param page 分页数据
* @param labelName 疾病标签名称
* @param order 排序
*/
IPage<StatsCaseClinicalLabelDto> getStatsCaseClinicalLabelSearchPage(
Page<?> page,
@Param("labelName") String labelName,
@Param("order") Map<String, String> order
);
/**
* Inc 自增
* @param field 字段名称
* @param numeral 增加的数值
* @return 更新的行数
*/
@Update("UPDATE stats_case_exchange_label SET ${field} = ${field} + #{numeral} WHERE label_iden = #{labelIden}")
int inc(@Param("labelIden") Long labelIden, @Param("field") String field, @Param("numeral") int numeral);
/**
* Dec 自减
*
* @param field 字段名称
* @param numeral 减少的数值
* @return 更新的行数
*/
@Update("UPDATE stats_case_exchange_label SET ${field} = ${field} - #{numeral} WHERE label_iden = #{labelIdenuserId}")
int dec(@Param("labelIden") Long labelIden, @Param("field") String field, @Param("numeral") int numeral);
}

View File

@ -0,0 +1,128 @@
package com.example.caseData.dto.statsCaseClinicalLabel;
import cn.hutool.core.bean.BeanUtil;
import com.example.caseData.dto.caseClinicalDoctor.CaseClinicalDoctorDto;
import com.example.caseData.model.StatsCaseClinicalDoctorModel;
import com.example.caseData.model.StatsCaseClinicalLabelModel;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Data
public class StatsCaseClinicalLabelDto {
/**
* 主键id
*/
@JsonProperty("stats_id")
private String statsId;
@JsonProperty("label_iden")
private String labelIden;
@JsonProperty("label_name")
private String labelName;
/**
* 数量-文章
*/
@JsonProperty("article_num")
private Integer articleNum = 0;
/**
* 总阅读量-文章
*/
@JsonProperty("article_read_num")
private Integer articleReadNum = 0;
/**
* 总收藏量-文章
*/
@JsonProperty("article_collect_num")
private Integer articleCollectNum = 0;
/**
* 最后一篇文章发表时间
*/
@JsonProperty("last_push_date")
private LocalDateTime lastPushDate;
/**
* 数量-视频
*/
@JsonProperty("video_num")
private Integer videoNum = 0;
/**
* 总阅读量-视频
*/
@JsonProperty("video_read_num")
private Integer videoReadNum = 0;
/**
* 总收藏量-视频
*/
@JsonProperty("video_collect_num")
private Integer videoCollectNum = 0;
/**
* 创建时间
*/
@JsonProperty("created_at")
private LocalDateTime createdAt;
/**
* 修改时间
*/
@JsonProperty("updated_at")
private LocalDateTime updatedAt;
/**
* 基础数据-医生
*/
@JsonProperty("case_clinical_doctor")
private CaseClinicalDoctorDto caseClinicalDoctor;
/**
* 列表
*/
public static List<StatsCaseClinicalLabelDto> GetListDto(List<StatsCaseClinicalLabelModel> models) {
if (models == null || models.isEmpty()) {
return Collections.emptyList();
}
return models.stream()
.map(model -> {
StatsCaseClinicalLabelDto dto = BeanUtil.copyProperties(model, StatsCaseClinicalLabelDto.class);
// 示例手动处理字段类型不一致
if (model.getStatsId() != null) {
dto.setStatsId(String.valueOf(model.getStatsId())); // Long -> String
}
return dto;
})
.collect(Collectors.toList());
}
/**
* 详情
*/
public static StatsCaseClinicalLabelDto GetDto(StatsCaseClinicalLabelModel model) {
if (model == null) {
return null;
}
StatsCaseClinicalLabelDto dto = BeanUtil.copyProperties(model, StatsCaseClinicalLabelDto.class);
// 示例手动处理字段类型不一致
if (model.getStatsId() != null) {
dto.setStatsId(String.valueOf(model.getStatsId())); // Long -> String
}
return dto;
}
}

View File

@ -0,0 +1,98 @@
package com.example.caseData.model;
import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 统计表-病例库-临床-疾病标签实体类
*/
@Data // Lombok 注解自动生成 getter/setter
@TableName("`stats_case_clinical_label`") // 指定数据库表名
public class StatsCaseClinicalLabelModel {
/**
* 主键id
*/
@TableId(type = IdType.ASSIGN_ID) // 使用雪花算法生成 ID适用于分布式系统
private Long statsId;
/**
* 疾病标签唯一标识
*/
@TableField("label_iden")
private String labelIden;
/**
* 疾病标签名称
*/
@TableField("label_name")
private String labelName;
/**
* 数量-文章
*/
@TableField("article_num")
private Integer articleNum;
/**
* 总阅读量-文章
*/
@TableField("article_read_num")
private Integer articleReadNum;
/**
* 总收藏量-文章
*/
@TableField("article_collect_num")
private Integer articleCollectNum;
/**
* 总评论量-文章
*/
@TableField("article_comment_num")
private Integer articleCommentNum;
/**
* 最后一篇文章发表时间
*/
@TableField("last_push_date")
private LocalDateTime lastPushDate;
/**
* 数量-视频
*/
@TableField("video_num")
private Integer videoNum;
/**
* 总阅读量-视频
*/
@TableField("video_read_num")
private Integer videoReadNum;
/**
* 总收藏量-视频
*/
@TableField("video_collect_num")
private Integer videoCollectNum;
/**
* 总评论量-视频
*/
@TableField("video_comment_num")
private Integer videoCommentNum;
/**
* 创建时间
*/
@TableField(fill = FieldFill.INSERT)
private LocalDateTime createdAt;
/**
* 修改时间
*/
@TableField(fill = FieldFill.INSERT_UPDATE)
private LocalDateTime updatedAt;
}

View File

@ -0,0 +1,12 @@
package com.example.caseData.request.caseExchangeRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
@Data
public class addCaseExchangeVote {
// 父级 次级评论此字段必须存在
@JsonProperty("option_id")
private String optionId;
}

View File

@ -33,6 +33,10 @@ public class getClinicalArticleSearchPage {
@JsonProperty("doctor_id")
private String doctorId;
// 疾病标签唯一标识
@JsonProperty("label_iden")
private String labelIden;
// 是否需要数量(0: 1:)
@JsonProperty("is_need_num")
private Integer isNeedNum = 0;

View File

@ -0,0 +1,84 @@
package com.example.caseData.request.clinicalRequest;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.Min;
import lombok.Data;
import org.springframework.util.StringUtils;
import java.util.HashMap;
import java.util.Map;
@Data
public class getClinicalLabelSearchPage {
// 分页参数
@Min(value = 1, message = "页码最小为 1")
private Integer page = 1;
@JsonProperty("page_size")
@Min(value = 1, message = "每页个数最小为 1")
private Integer pageSize = 20;
// 疾病标签名称
@JsonProperty("label_name")
private String labelName;
// 排序字段
private OrderRequest order;
/**
* 排序字段嵌套结构体
*/
@Data
public static class OrderRequest {
@JsonProperty("updated_at")
private String updatedAt; // 更新时间排序
@JsonProperty("label_name")
private String labelName; // 医院名称
@JsonProperty("article_num")
private String articleNum; // 数量-文章
public Map<String, String> toMap() {
Map<String, String> map = new HashMap<>();
if (StringUtils.hasText(updatedAt)) {
map.put("a.updated_at", updatedAt);
}
if (StringUtils.hasText(labelName)) {
map.put("b.label_name", labelName);
}
if (StringUtils.hasText(articleNum)) {
map.put("a.article_num", articleNum);
}
// 默认排序如果用户未传递任何排序字段
if (map.isEmpty()) {
map.put("a.updated_at", "desc");
}
return map;
}
}
/**
* 获取排序字段若无用户输入则使用默认排序
*/
public Map<String, String> handleOrder() {
return order != null ? order.toMap() : new OrderRequest().toMap();
}
// 校验分页参数
public void validateForPage() {
// 如果 page 为空设为默认值 1
if (page == null) {
page = 1;
}
if (pageSize == null) {
pageSize = 20;
}
}
}

View File

@ -33,6 +33,10 @@ public class getClinicalVideoSearchPage {
@JsonProperty("doctor_id")
private String doctorId;
// 疾病标签唯一标识
@JsonProperty("label_iden")
private String labelIden;
// 是否需要数量(0: 1:)
@JsonProperty("is_need_num")
private Integer isNeedNum = 0;

View File

@ -495,4 +495,45 @@ public class CaseExchangeService {
return true;
}
/**
* 新增投票-病例交流
* @param exchangeId 病例交流id
* @param userId 用户id
* @return bool
*/
@Transactional
public boolean AddCaseExchangeVote(String exchangeId,String userId,String optionId){
// 获取病例交流数据
CaseExchangeModel article = caseExchangeDao.selectById(exchangeId);
if (article == null) {
return false;
}
// 检测用户是否已收藏过
UserCollectExchangeModel userCollectExchange = getUserCollectExchangeStatus(exchangeId,userId);
if (userCollectExchange != null) {
return true;
}
// 新增收藏
UserCollectExchangeModel userCollectExchangeData = new UserCollectExchangeModel();
userCollectExchangeData.setUserId(Long.valueOf(userId));
userCollectExchangeData.setExchangeId(Long.valueOf(exchangeId));
int res = userCollectExchangeDao.insert(userCollectExchangeData);
if (res <= 0){
return false;
}
// 增加病例交流收藏数
caseExchangeDao.inc(Long.valueOf(exchangeId),"collect_num",1);
// 增加病例交流总收藏数
statsCaseExchangeDao.inc(1L,"exchange_collect_num",1);
// 增加用户交流收藏数
statsCaseExchangeUserDao.inc(Long.valueOf(userId),"exchange_collect_num",1);
return true;
}
}

View File

@ -0,0 +1,31 @@
<?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.caseData.dao.StatsCaseClinicalLabelDao">
<select id="getStatsCaseClinicalLabelSearchPage"
resultType="com.example.caseData.dto.statsCaseClinicalLabel.StatsCaseClinicalLabelDto">
SELECT
a.stats_id,
a.label_iden,
a.label_name,
a.article_num,
a.article_read_num,
a.article_collect_num,
a.last_push_date,
a.video_num,
a.video_read_num,
a.video_collect_num,
a.created_at
FROM stats_case_clinical_label a
<where>
<if test="labelName != null and labelName != ''">
a.label_name LIKE CONCAT('%', #{labelName}, '%')
</if>
</where>
<if test="order != null and !order.isEmpty()">
ORDER BY
<foreach item="entry" index="key" collection="order" separator=",">
${key} ${entry}
</foreach>
</if>
</select>
</mapper>