led
This commit is contained in:
@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Optional;
|
||||
|
||||
@Tag(name = "LED-排班接口")
|
||||
@RestController
|
||||
@@ -25,13 +26,61 @@ public class LedApiController extends BaseController {
|
||||
|
||||
@Operation(summary = "查询一周内停替诊医生排班信息(10017)")
|
||||
@PostMapping("/stop-replace")
|
||||
public ApiResult<JSONObject> searchStopAndReplace(@RequestBody BmeStopReplaceParam param) {
|
||||
return success(ledScheduleService.searchStopAndReplace(param));
|
||||
public ApiResult<Object> searchStopAndReplace(@RequestBody BmeStopReplaceParam param) {
|
||||
return success(extractScheduleData(ledScheduleService.searchStopAndReplace(param)));
|
||||
}
|
||||
|
||||
@Operation(summary = "查询医生排班信息当日剩余号源(10018)")
|
||||
@PostMapping("/number-sources")
|
||||
public ApiResult<JSONObject> searchNumberSources(@RequestBody BmeNumberSourcesParam param) {
|
||||
return success(ledScheduleService.searchNumberSources(param));
|
||||
public ApiResult<Object> searchNumberSources(@RequestBody BmeNumberSourcesParam param) {
|
||||
return success(extractScheduleData(ledScheduleService.searchNumberSources(param)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将中台层层嵌套的响应简化为单层:tid、resultCode/resultMsg、data(主要数据)。
|
||||
*/
|
||||
private JSONObject flattenScheduleResponse(JSONObject raw) {
|
||||
JSONObject current = Optional.ofNullable(raw).orElseGet(JSONObject::new);
|
||||
String tid = current.getString("tid");
|
||||
|
||||
// 下钻 data 层级
|
||||
while (current.getJSONObject("data") != null) {
|
||||
current = current.getJSONObject("data");
|
||||
if (current.containsKey("tid")) {
|
||||
tid = current.getString("tid");
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("tid", tid);
|
||||
result.put("resultCode", firstNonEmpty(current.getString("resultCode"), current.getString("code")));
|
||||
result.put("resultMsg", firstNonEmpty(current.getString("resultMsg"), current.getString("msg")));
|
||||
|
||||
// 主体数据:优先 dataList.data,其次 data
|
||||
if (current.containsKey("dataList") && current.getJSONObject("dataList") != null) {
|
||||
result.put("data", current.getJSONObject("dataList").get("data"));
|
||||
} else if (current.containsKey("data")) {
|
||||
result.put("data", current.get("data"));
|
||||
} else {
|
||||
result.put("data", current);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接返回核心数据字段(即扁平化后的 result.data)。
|
||||
*/
|
||||
private Object extractScheduleData(JSONObject raw) {
|
||||
JSONObject flattened = flattenScheduleResponse(raw);
|
||||
return flattened.get("data");
|
||||
}
|
||||
|
||||
private String firstNonEmpty(String... values) {
|
||||
for (String v : values) {
|
||||
if (v != null && !v.isEmpty()) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user