|
@@ -0,0 +1,181 @@
|
|
|
|
|
+package work.baiyun.chronicdiseaseapp.controller;
|
|
|
|
|
+
|
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.http.MediaType;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.model.po.CriticalValue;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.model.vo.CreateOrUpdateCriticalValueRequest;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.model.vo.CriticalValueResponse;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.model.vo.DeleteRequest;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.model.vo.EnumVO;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.model.vo.CriticalValuesFormRequest;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.model.vo.CriticalValuesFormResponse;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.service.CriticalValueService;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.enums.ValueType;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.common.R;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.enums.ErrorCode;
|
|
|
|
|
+import work.baiyun.chronicdiseaseapp.exception.CustomException;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.media.Content;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
+
|
|
|
|
|
+import org.slf4j.Logger;
|
|
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/critical-values")
|
|
|
|
|
+@Tag(name = "危急值管理", description = "危急值配置管理接口")
|
|
|
|
|
+public class CriticalValueController {
|
|
|
|
|
+
|
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(CriticalValueController.class);
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private CriticalValueService criticalValueService;
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "获取危急值列表", description = "按类型查询危急值配置,valueType 可选")
|
|
|
|
|
+ @ApiResponses(value = {
|
|
|
|
|
+ @ApiResponse(responseCode = "200", description = "成功",
|
|
|
|
|
+ content = @Content(mediaType = "application/json",
|
|
|
|
|
+ schema = @Schema(implementation = work.baiyun.chronicdiseaseapp.model.vo.CriticalValueResponse.class))),
|
|
|
|
|
+ @ApiResponse(responseCode = "500", description = "服务器内部错误",
|
|
|
|
|
+ content = @Content(mediaType = "application/json",
|
|
|
|
|
+ schema = @Schema(implementation = Void.class)))
|
|
|
|
|
+ })
|
|
|
|
|
+ @GetMapping(path = "", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public R<?> list(@RequestParam(required = false) String valueType) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<CriticalValue> list = criticalValueService.list(valueType);
|
|
|
|
|
+ List<CriticalValueResponse> resp = list.stream().map(e -> {
|
|
|
|
|
+ CriticalValueResponse r = new CriticalValueResponse();
|
|
|
|
|
+ BeanUtils.copyProperties(e, r);
|
|
|
|
|
+ r.setId(e.getId() == null ? null : e.getId().toString());
|
|
|
|
|
+ r.setValueType(e.getValueType() == null ? null : e.getValueType().getCode());
|
|
|
|
|
+ return r;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ return R.success(200, "ok", resp);
|
|
|
|
|
+ } catch (CustomException e) {
|
|
|
|
|
+ logger.error("list critical values failed", e);
|
|
|
|
|
+ return R.fail(e.getCode(), e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("list critical values failed", e);
|
|
|
|
|
+ return R.fail(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "获取危急值详情", description = "根据ID获取单条危急值配置")
|
|
|
|
|
+ @GetMapping(path = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public R<?> get(@PathVariable Long id) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ CriticalValue entity = criticalValueService.getById(id);
|
|
|
|
|
+ if (entity == null) return R.success(200, "ok", null);
|
|
|
|
|
+ CriticalValueResponse r = new CriticalValueResponse();
|
|
|
|
|
+ BeanUtils.copyProperties(entity, r);
|
|
|
|
|
+ r.setId(entity.getId() == null ? null : entity.getId().toString());
|
|
|
|
|
+ r.setValueType(entity.getValueType() == null ? null : entity.getValueType().getCode());
|
|
|
|
|
+ return R.success(200, "ok", r);
|
|
|
|
|
+ } catch (CustomException e) {
|
|
|
|
|
+ logger.error("get critical value failed", e);
|
|
|
|
|
+ return R.fail(e.getCode(), e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("get critical value failed", e);
|
|
|
|
|
+ return R.fail(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "新增或更新危急值", description = "统一写接口:无 id 为新增,含 id 为更新")
|
|
|
|
|
+ @PostMapping(path = "", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public R<?> saveOrUpdate(@RequestBody CreateOrUpdateCriticalValueRequest req) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ criticalValueService.saveOrUpdate(req);
|
|
|
|
|
+ return R.success(200, "ok");
|
|
|
|
|
+ } catch (CustomException e) {
|
|
|
|
|
+ logger.error("saveOrUpdate critical value failed", e);
|
|
|
|
|
+ return R.fail(e.getCode(), e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("saveOrUpdate critical value failed", e);
|
|
|
|
|
+ return R.fail(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "删除危急值", description = "支持批量删除")
|
|
|
|
|
+ @PostMapping(path = "/delete", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public R<?> delete(@RequestBody DeleteRequest req) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ criticalValueService.deleteByIds(req.getIds());
|
|
|
|
|
+ return R.success(200, "ok");
|
|
|
|
|
+ } catch (CustomException e) {
|
|
|
|
|
+ logger.error("delete critical value failed", e);
|
|
|
|
|
+ return R.fail(e.getCode(), e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("delete critical value failed", e);
|
|
|
|
|
+ return R.fail(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "获取危急值类型枚举", description = "返回 value+label 列表供前端下拉使用")
|
|
|
|
|
+ @GetMapping(path = "/types", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public R<?> types() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ List<EnumVO> list = Arrays.stream(ValueType.values())
|
|
|
|
|
+ .map(v -> new EnumVO(v.getCode(), v.getDescription()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ return R.success(200, "ok", list);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("types critical values failed", e);
|
|
|
|
|
+ return R.fail(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "获取整表危急值配置", description = "返回前端所需的整表结构(physical/bmi/bloodPressure/bloodGlucose/heartRate)")
|
|
|
|
|
+ @GetMapping(path = "/form", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public R<?> getForm() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ CriticalValuesFormResponse resp = criticalValueService.loadForm();
|
|
|
|
|
+ return R.success(200, "ok", resp);
|
|
|
|
|
+ } catch (CustomException e) {
|
|
|
|
|
+ logger.error("get form failed", e);
|
|
|
|
|
+ return R.fail(e.getCode(), e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("get form failed", e);
|
|
|
|
|
+ return R.fail(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "保存整表危急值配置", description = "接收前端整表对象并拆分写入多条配置")
|
|
|
|
|
+ @PostMapping(path = "/form", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public R<?> saveForm(@RequestBody CriticalValuesFormRequest req) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ criticalValueService.saveForm(req);
|
|
|
|
|
+ return R.success(200, "ok");
|
|
|
|
|
+ } catch (CustomException e) {
|
|
|
|
|
+ logger.error("save form failed", e);
|
|
|
|
|
+ return R.fail(e.getCode(), e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("save form failed", e);
|
|
|
|
|
+ return R.fail(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "重置整表危急值配置", description = "删除或清空已配置的危急值条目")
|
|
|
|
|
+ @DeleteMapping(path = "/form", produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
|
|
+ public R<?> resetForm() {
|
|
|
|
|
+ try {
|
|
|
|
|
+ criticalValueService.resetForm();
|
|
|
|
|
+ return R.success(200, "ok");
|
|
|
|
|
+ } catch (CustomException e) {
|
|
|
|
|
+ logger.error("reset form failed", e);
|
|
|
|
|
+ return R.fail(e.getCode(), e.getMessage());
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ logger.error("reset form failed", e);
|
|
|
|
|
+ return R.fail(ErrorCode.SYSTEM_ERROR.getCode(), ErrorCode.SYSTEM_ERROR.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|