新增了草稿搜索
This commit is contained in:
parent
a899914fea
commit
8eb64d1c41
@ -0,0 +1,187 @@
|
|||||||
|
package com.example.caseData.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Dict;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.example.caseData.common.Response;
|
||||||
|
import com.example.caseData.dao.*;
|
||||||
|
import com.example.caseData.dto.T;
|
||||||
|
import com.example.caseData.dto.caseExchange.CaseExchangeDto;
|
||||||
|
import com.example.caseData.dto.caseExchangeDraft.CaseExchangeDraftDto;
|
||||||
|
import com.example.caseData.dto.caseExchangeLabel.CaseExchangeLabelDto;
|
||||||
|
import com.example.caseData.dto.caseExchangeVote.CaseExchangeVoteDto;
|
||||||
|
import com.example.caseData.dto.caseExchangeVoteOption.CaseExchangeVoteOptionDto;
|
||||||
|
import com.example.caseData.dto.userCommentCaseExchange.GetUserCaseExchangeCommentPageDto;
|
||||||
|
import com.example.caseData.dto.userCommentCaseExchange.UserCommentCaseExchangeDto;
|
||||||
|
import com.example.caseData.exception.BusinessException;
|
||||||
|
import com.example.caseData.model.*;
|
||||||
|
import com.example.caseData.request.caseExchangeDraftRequest.getCaseExchangeDraftSearchPage;
|
||||||
|
import com.example.caseData.request.caseExchangeRequest.*;
|
||||||
|
import com.example.caseData.service.CaseExchangeService;
|
||||||
|
import com.example.caseData.utils.IntToString;
|
||||||
|
import com.example.caseData.utils.Replace;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api")
|
||||||
|
public class CaseExchangeDraftController {
|
||||||
|
@Resource
|
||||||
|
private HttpServletRequest httpServletRequest;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CaseExchangeDao caseExchangeDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserDao userDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private BasicHospitalDao basicHospitalDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CaseExchangeService caseExchangeService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CaseExchangeDraftDao caseExchangeDraftDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CaseExchangeVoteDao caseExchangeVoteDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CaseExchangeLabelDao caseExchangeLabelDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CaseExchangeVoteOptionDao caseExchangeVoteOptionDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserVoteExchangeDao userVoteExchangeDao;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserCommentExchangeDao userCommentExchangeDao;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 临床病例库-病例交流-草稿-搜索
|
||||||
|
*/
|
||||||
|
@PostMapping("/exchange/draft/search")
|
||||||
|
public Response<Map<String, Object>> getCaseExchangeDraftSearchPage(
|
||||||
|
@Validated()
|
||||||
|
@RequestBody getCaseExchangeDraftSearchPage request
|
||||||
|
) {
|
||||||
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
||||||
|
if (userId == null) {
|
||||||
|
return Response.error("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
request.validateForPage();
|
||||||
|
|
||||||
|
Map<String, Object> resultMap = new HashMap<>();
|
||||||
|
|
||||||
|
Page<CaseExchangeDraftDto> page = new Page<>(request.getPage(), request.getPageSize());
|
||||||
|
|
||||||
|
|
||||||
|
IPage<CaseExchangeDraftDto> resultPage = caseExchangeDraftDao.getCaseExchangeDraftSearchPage(
|
||||||
|
page,
|
||||||
|
userId,
|
||||||
|
request.handleOrder()
|
||||||
|
);
|
||||||
|
|
||||||
|
for (CaseExchangeDraftDto dto : resultPage.getRecords()) {
|
||||||
|
// 处理标签
|
||||||
|
if (dto.getExchangeLabelJson() != null && !dto.getExchangeLabelJson().isEmpty()){
|
||||||
|
try {
|
||||||
|
JSONArray array = JSONUtil.parseArray(dto.getExchangeLabelJson());
|
||||||
|
List<CaseExchangeDraftDto.CaseExchangeLabelDto> caseExchangeLabelDto = JSONUtil.toList(array, CaseExchangeDraftDto.CaseExchangeLabelDto.class);
|
||||||
|
dto.setExchangeLabel(caseExchangeLabelDto);
|
||||||
|
dto.setExchangeLabelJson("");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理投票
|
||||||
|
if (dto.getExchangeVoteJson() != null && !dto.getExchangeVoteJson().isEmpty()){
|
||||||
|
try {
|
||||||
|
CaseExchangeDraftDto.ExchangeVoteDto caseExchangeVoteDto = JSONUtil.toBean(dto.getExchangeVoteJson(), CaseExchangeDraftDto.ExchangeVoteDto.class);
|
||||||
|
dto.setExchangeVote(caseExchangeVoteDto);
|
||||||
|
dto.setExchangeVoteJson("");
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Response.error(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resultMap.put("page", resultPage.getCurrent());
|
||||||
|
resultMap.put("pageSize", resultPage.getSize());
|
||||||
|
resultMap.put("total", resultPage.getTotal());
|
||||||
|
resultMap.put("data", resultPage.getRecords());
|
||||||
|
return Response.success(resultMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 病例交流-新增
|
||||||
|
*/
|
||||||
|
@PostMapping("/exchange/draft")
|
||||||
|
public Response<T> AddCaseExchange(
|
||||||
|
@Validated()
|
||||||
|
@RequestBody addCaseExchange request
|
||||||
|
) {
|
||||||
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
||||||
|
|
||||||
|
if (userId == null) {
|
||||||
|
return Response.error("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean res = caseExchangeService.AddCaseExchange(userId,request);
|
||||||
|
if (!res){
|
||||||
|
return Response.error("操作失败");
|
||||||
|
}
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
return Response.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 病例交流-评论-删除
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/exchange/draft/{draft_id}")
|
||||||
|
public Response<T> DeleteCaseExchangeComment(
|
||||||
|
@PathVariable("draft_id") String draftId
|
||||||
|
) {
|
||||||
|
|
||||||
|
String userId = (String) httpServletRequest.getAttribute("userId");
|
||||||
|
|
||||||
|
if (userId == null) {
|
||||||
|
return Response.error("操作失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
boolean res = caseExchangeService.DeleteCaseExchangeComment(draftId,userId);
|
||||||
|
if (!res){
|
||||||
|
return Response.error("操作失败");
|
||||||
|
}
|
||||||
|
} catch (BusinessException e) {
|
||||||
|
return Response.error(e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,29 @@
|
|||||||
|
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.caseExchange.CaseExchangeDto;
|
||||||
|
import com.example.caseData.dto.caseExchangeDraft.CaseExchangeDraftDto;
|
||||||
|
import com.example.caseData.model.CaseExchangeModel;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Update;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CaseExchangeDraftDao extends BaseMapper<CaseExchangeModel> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 临床病例库-草稿箱-搜索
|
||||||
|
* @param page 分页数据
|
||||||
|
* @param order 排序
|
||||||
|
*/
|
||||||
|
IPage<CaseExchangeDraftDto> getCaseExchangeDraftSearchPage(
|
||||||
|
Page<?> page,
|
||||||
|
@Param("userId") String userId,
|
||||||
|
@Param("order") Map<String, String> order
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -0,0 +1,136 @@
|
|||||||
|
package com.example.caseData.dto.caseExchangeDraft;
|
||||||
|
|
||||||
|
import com.example.caseData.dto.caseExchangeVoteOption.CaseExchangeVoteOptionDto;
|
||||||
|
import com.example.caseData.request.caseExchangeRequest.addCaseExchange;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import jakarta.validation.constraints.NotEmpty;
|
||||||
|
import jakarta.validation.constraints.Size;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CaseExchangeDraftDto {
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
@JsonProperty("draft_id")
|
||||||
|
private String draftId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
@JsonProperty("user_id")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
@JsonProperty("exchange_title")
|
||||||
|
private String exchangeTitle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容
|
||||||
|
*/
|
||||||
|
@JsonProperty("exchange_content")
|
||||||
|
private String exchangeContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总结
|
||||||
|
*/
|
||||||
|
@JsonProperty("exchange_summary")
|
||||||
|
private String exchangeSummary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签id(逗号分隔)
|
||||||
|
*/
|
||||||
|
@JsonProperty("exchange_label_json")
|
||||||
|
private String exchangeLabelJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签
|
||||||
|
*/
|
||||||
|
@JsonProperty("exchange_label")
|
||||||
|
private List<CaseExchangeLabelDto> exchangeLabel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 投票(json)
|
||||||
|
*/
|
||||||
|
@JsonProperty("exchange_vote_json")
|
||||||
|
private String exchangeVoteJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 投票
|
||||||
|
*/
|
||||||
|
@JsonProperty("exchange_vote")
|
||||||
|
private ExchangeVoteDto exchangeVote;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@JsonProperty("created_at")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
@JsonProperty("updated_at")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class CaseExchangeLabelDto {
|
||||||
|
/**
|
||||||
|
* app唯一标识
|
||||||
|
*/
|
||||||
|
@JsonProperty("app_iden")
|
||||||
|
private String appIden;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签名称
|
||||||
|
*/
|
||||||
|
@JsonProperty("label_name")
|
||||||
|
private String labelName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class ExchangeVoteDto {
|
||||||
|
/**
|
||||||
|
* 选项标题
|
||||||
|
*/
|
||||||
|
@JsonProperty("vote_title")
|
||||||
|
private String voteTitle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束投票时间
|
||||||
|
*/
|
||||||
|
@JsonProperty("end_time")
|
||||||
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选项
|
||||||
|
*/
|
||||||
|
@JsonProperty("option")
|
||||||
|
private List<OptionDto> option;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class OptionDto {
|
||||||
|
/**
|
||||||
|
* 选项
|
||||||
|
*/
|
||||||
|
@JsonProperty("option_value")
|
||||||
|
private String optionValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -41,7 +41,7 @@ public class CaseExchangeVoteDto {
|
|||||||
private LocalDateTime endTime;
|
private LocalDateTime endTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否开启中(0:否 1:是)
|
* 是否开启中(0:否 1:是)过期状态
|
||||||
*/
|
*/
|
||||||
@JsonProperty("is_enabled")
|
@JsonProperty("is_enabled")
|
||||||
private Integer isEnabled;
|
private Integer isEnabled;
|
||||||
|
|||||||
@ -0,0 +1,70 @@
|
|||||||
|
package com.example.caseData.model;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 病例库-病例交流-草稿实体类
|
||||||
|
*/
|
||||||
|
@Data // Lombok注解,用于自动生成getter/setter方法等
|
||||||
|
@TableName("`case_exchange_draft`") // 指定数据库表名
|
||||||
|
public class CaseExchangeDraftModel {
|
||||||
|
/**
|
||||||
|
* 主键id
|
||||||
|
*/
|
||||||
|
@TableId(type = IdType.ASSIGN_ID) // 使用MyBatis-Plus的ID生成策略
|
||||||
|
private Long draftId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
@TableField("user_id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
@TableField("exchange_title")
|
||||||
|
private String exchangeTitle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 内容
|
||||||
|
*/
|
||||||
|
@TableField("exchange_content")
|
||||||
|
private String exchangeContent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 总结
|
||||||
|
*/
|
||||||
|
@TableField("exchange_summary")
|
||||||
|
private String exchangeSummary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标签数据(json)
|
||||||
|
*/
|
||||||
|
@TableField("exchange_label_json")
|
||||||
|
private String exchangeLabelJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 投票(json格式存储)
|
||||||
|
*/
|
||||||
|
@TableField("exchange_vote_json")
|
||||||
|
private String exchangeVoteJson;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT)
|
||||||
|
@JsonProperty("created_at")
|
||||||
|
private LocalDateTime createdAt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改时间
|
||||||
|
*/
|
||||||
|
@TableField(fill = FieldFill.INSERT_UPDATE)
|
||||||
|
@JsonProperty("updated_at")
|
||||||
|
private LocalDateTime updatedAt;
|
||||||
|
}
|
||||||
@ -0,0 +1,66 @@
|
|||||||
|
package com.example.caseData.request.caseExchangeDraftRequest;
|
||||||
|
|
||||||
|
|
||||||
|
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 getCaseExchangeDraftSearchPage {
|
||||||
|
// ✅ 分页参数
|
||||||
|
@Min(value = 1,message = "页码最小为 1")
|
||||||
|
private Integer page = 1;
|
||||||
|
|
||||||
|
@JsonProperty("page_size")
|
||||||
|
@Min(value = 1, message = "每页个数最小为 1")
|
||||||
|
private Integer pageSize = 20;
|
||||||
|
|
||||||
|
// 排序字段
|
||||||
|
private OrderRequest order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序字段嵌套结构体
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public static class OrderRequest {
|
||||||
|
@JsonProperty("created_at")
|
||||||
|
private String createdAt; // 创建时间
|
||||||
|
|
||||||
|
public Map<String, String> toMap() {
|
||||||
|
Map<String, String> map = new HashMap<>();
|
||||||
|
if (StringUtils.hasText(createdAt)) {
|
||||||
|
map.put("a.created_at", createdAt);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认排序(如果用户未传递任何排序字段)
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/main/resources/mapper/CaseExchangeDraftMapper.xml
Normal file
21
src/main/resources/mapper/CaseExchangeDraftMapper.xml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?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.CaseExchangeDraftDao">
|
||||||
|
<select id="getCaseExchangeDraftSearchPage" resultType="com.example.caseData.dto.caseExchangeDraft.CaseExchangeDraftDto">
|
||||||
|
SELECT
|
||||||
|
a.*
|
||||||
|
FROM case_exchange_draft a
|
||||||
|
LEFT JOIN user c ON c.user_id = a.user_id
|
||||||
|
<where>
|
||||||
|
<if test="userId != null and userId != ''">
|
||||||
|
AND c.user_id = #{userId}
|
||||||
|
</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>
|
||||||
Loading…
x
Reference in New Issue
Block a user