新增了标签
This commit is contained in:
parent
b05be13e5c
commit
872e6dc49c
@ -0,0 +1,47 @@
|
||||
package com.example.caseData.controller;
|
||||
|
||||
import com.example.caseData.common.Response;
|
||||
import com.example.caseData.dto.caseLabel.GetCaseLabelDto;
|
||||
import com.example.caseData.dto.user.UserDto;
|
||||
import com.example.caseData.extend.app.Hospital.GetHospitalByUuidResponse;
|
||||
import com.example.caseData.extend.app.Hospital.Hospital;
|
||||
import com.example.caseData.extend.app.label.GetLabelsResponse;
|
||||
import com.example.caseData.extend.app.label.Label;
|
||||
import com.example.caseData.request.UserRequest.UserRequest;
|
||||
import com.example.caseData.request.caseLabelRequest.getCaseLabel;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class CaseLabelController {
|
||||
@Resource
|
||||
private Label label;
|
||||
|
||||
/**
|
||||
* 获取疾病标签数据
|
||||
*/
|
||||
@GetMapping("/case/label")
|
||||
public Response<List<GetCaseLabelDto>> getCaseLabel(@Validated() @ModelAttribute getCaseLabel request) {
|
||||
GetLabelsResponse result = label.getLabels(request.getPId());
|
||||
List<GetLabelsResponse.GetLabelsData> datas = result.getData();
|
||||
|
||||
List<GetCaseLabelDto> labelDtoList = new ArrayList<>();
|
||||
for (GetLabelsResponse.GetLabelsData d : datas) {
|
||||
GetCaseLabelDto dto = new GetCaseLabelDto();
|
||||
dto.setAppIden(d.getId());
|
||||
dto.setLabelName(d.getName());
|
||||
labelDtoList.add(dto);
|
||||
}
|
||||
|
||||
return Response.success(labelDtoList);
|
||||
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.example.caseData.dto.caseLabel;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GetCaseLabelDto {
|
||||
/**
|
||||
* app唯一标识
|
||||
*/
|
||||
@JsonProperty("app_iden")
|
||||
private String appIden;
|
||||
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
@JsonProperty("label_name")
|
||||
private String labelName;
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package com.example.caseData.extend.app.label;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class GetLabelsResponse
|
||||
{
|
||||
/** 接口调用状态。200:正常;其它值:调用出错 */
|
||||
private int code;
|
||||
|
||||
/** 结果说明。如果接口调用出错,那么返回错误描述。成功则返回 ok */
|
||||
private String msg;
|
||||
|
||||
/** 接口返回的用户信息数据 */
|
||||
private List<GetLabelsData> data;
|
||||
|
||||
/** 接口是否调用成功 */
|
||||
private boolean success;
|
||||
|
||||
/** 错误信息或提示信息 */
|
||||
private String message;
|
||||
|
||||
|
||||
/**
|
||||
* 根据统一标签列表 - 详细数据
|
||||
*/
|
||||
@Data
|
||||
public static class GetLabelsData {
|
||||
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 子标签数量
|
||||
*/
|
||||
@JsonProperty("children_size")
|
||||
private String childrenSize;
|
||||
|
||||
/**
|
||||
* p_id
|
||||
*/
|
||||
@JsonProperty("p_id")
|
||||
private String pId;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,69 @@
|
||||
package com.example.caseData.extend.app.label;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.example.caseData.config.AppConfig;
|
||||
import com.example.caseData.exception.BusinessException;
|
||||
import com.example.caseData.extend.app.Base;
|
||||
import com.example.caseData.extend.app.Hospital.GetHospitalByUuidResponse;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class Label extends Base {
|
||||
@Resource
|
||||
private AppConfig appConfig;
|
||||
|
||||
// 根据医院唯一标识获取医院数据
|
||||
public GetLabelsResponse getLabels(String p_id) throws BusinessException {
|
||||
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
|
||||
// 处理参数
|
||||
Map<String, Object> requestData = new HashMap<>();
|
||||
requestData.put("p_id", p_id);
|
||||
requestData.put("platform", appConfig.getPlatform());
|
||||
requestData.put("timestamp", timestamp);
|
||||
|
||||
// 生成签名
|
||||
String sign = genSignature(requestData,appConfig.getSecretKey());
|
||||
|
||||
String url = appConfig.getApiUrl() + "/expert-api/getLabels";
|
||||
String jsonBody = JSONUtil.toJsonStr(requestData);
|
||||
log.info("获取app数据参数:{}",jsonBody);
|
||||
|
||||
try(HttpResponse response = HttpRequest.post(url)
|
||||
.header("Content-Type", "application/json")
|
||||
.header("sign", sign)
|
||||
.body(jsonBody)
|
||||
.execute()){
|
||||
|
||||
if (response.getStatus() != 200) {
|
||||
throw new BusinessException("失败");
|
||||
}
|
||||
|
||||
// 反序列化 JSON
|
||||
GetLabelsResponse result = JSONUtil.toBean(response.body(), GetLabelsResponse.class);
|
||||
log.info("获取app数据返回:{}",result);
|
||||
if (result.getCode() != 200){
|
||||
if (!Objects.equals(result.getMsg(), "")){
|
||||
throw new BusinessException(result.getMsg());
|
||||
}else{
|
||||
throw new BusinessException("失败");
|
||||
}
|
||||
}
|
||||
|
||||
if (result.getData() == null){
|
||||
throw new BusinessException("失败");
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
package com.example.caseData.request.caseLabelRequest;
|
||||
|
||||
import jakarta.validation.constraints.NotEmpty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class getCaseLabel {
|
||||
@NotEmpty(message = "参数错误")
|
||||
private String pId = "0";
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user