package cn.lihu.jh.module.ecg.controller.admin.external;
|
|
import cn.lihu.jh.framework.common.pojo.CommonResult;
|
import cn.lihu.jh.module.ecg.enums.ActionTypeEnum;
|
import cn.lihu.jh.module.ecg.service.appointment.AppointmentService;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import javax.annotation.security.PermitAll;
|
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotNull;
|
import java.util.Map;
|
import java.util.function.Consumer;
|
|
import static cn.lihu.jh.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.lihu.jh.framework.common.pojo.CommonResult.success;
|
import static cn.lihu.jh.module.ecg.enums.ErrorCodeConstants.APPOINTMENT_CREATE_FAIL;
|
|
@Tag(name = "供第三方调用接口")
|
@RestController
|
@RequestMapping("/ecg/external")
|
@Validated
|
@Slf4j
|
public class ExternalController {
|
|
@Resource
|
private AppointmentService appointmentService;
|
|
/**
|
* 通用接口
|
* <p>
|
* 支持以下action类型:
|
* - S0201ECG: 预约创建
|
* - S0202ECG: 预约更新
|
*
|
* @param dataMap 请求数据
|
* @param headers 请求头,必须包含action字段
|
* @return 处理结果
|
*/
|
@PermitAll
|
@Operation(summary = "通用接口")
|
@PostMapping("/generalInterface")
|
public CommonResult<Boolean> generalInterface(
|
@RequestBody @NotNull(message = "请求数据不能为空") Map<String, Object> dataMap,
|
@RequestHeader @NotEmpty(message = "请求头不能为空") Map<String, String> headers) {
|
log.info("[generalInterface][开始处理请求 action({}) dataMap({})]", headers.get("action"), dataMap);
|
|
String actionType = headers.get("action");
|
ActionTypeEnum action = ActionTypeEnum.getByType(actionType);
|
if (action == null) {
|
log.warn("[generalInterface][未知的action类型 action({})]", actionType);
|
throw exception(APPOINTMENT_CREATE_FAIL);
|
}
|
|
try {
|
// 使用策略模式处理不同的action
|
Map<ActionTypeEnum, Consumer<Map<String, Object>>> actionHandlers = Map.of(
|
ActionTypeEnum.S0201ECG, appointmentService::handleAppointmentCreate,
|
ActionTypeEnum.S0202ECG, appointmentService::handleAppointmentUpdate,
|
ActionTypeEnum.S040501HIS, appointmentService::handleAppointmentStateUpdate,
|
ActionTypeEnum.S050401, appointmentService::handleCheckAppointmentUpdate,
|
ActionTypeEnum.S050501, appointmentService::handleCheckAppointmentUpdate
|
);
|
|
Consumer<Map<String, Object>> handler = actionHandlers.get(action);
|
if (handler == null) {
|
throw exception(APPOINTMENT_CREATE_FAIL);
|
}
|
|
handler.accept(dataMap);
|
return success(true);
|
} catch (Exception e) {
|
throw exception(APPOINTMENT_CREATE_FAIL);
|
}
|
}
|
}
|