|
|
@@ -0,0 +1,64 @@
|
|
|
+package work.baiyun.chronicdiseaseapp.controller;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+import work.baiyun.chronicdiseaseapp.common.R;
|
|
|
+import work.baiyun.chronicdiseaseapp.model.vo.AddPhysicalDataRequest;
|
|
|
+import work.baiyun.chronicdiseaseapp.model.vo.PhysicalDataResponse;
|
|
|
+import work.baiyun.chronicdiseaseapp.model.vo.BaseQueryRequest;
|
|
|
+import work.baiyun.chronicdiseaseapp.service.PhysicalDataService;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/physical")
|
|
|
+public class PhysicalDataController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PhysicalDataService physicalDataService;
|
|
|
+
|
|
|
+ @PostMapping(path = "/add", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public R<?> addPhysicalData(@RequestBody AddPhysicalDataRequest req) {
|
|
|
+ try {
|
|
|
+ physicalDataService.addPhysicalData(req);
|
|
|
+ return R.success(200, "ok");
|
|
|
+ } catch (Exception e) {
|
|
|
+ return R.fail(500, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(path = "/list", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public R<?> listPhysicalData(@RequestBody BaseQueryRequest req) {
|
|
|
+ try {
|
|
|
+ Page<PhysicalDataResponse> page = physicalDataService.listPhysicalData(req);
|
|
|
+ return R.success(200, "ok", page);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return R.fail(500, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping(path = "/bmi", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
+ public R<?> calculateBmi(@RequestBody Map<String, Object> body) {
|
|
|
+ try {
|
|
|
+ if (body == null) return R.fail(400, "Missing body");
|
|
|
+ Object h = body.get("height");
|
|
|
+ Object w = body.get("weight");
|
|
|
+ if (h == null || w == null) return R.fail(400, "Missing height or weight");
|
|
|
+ BigDecimal height = new BigDecimal(h.toString());
|
|
|
+ BigDecimal weight = new BigDecimal(w.toString());
|
|
|
+ BigDecimal bmi = physicalDataService.calculateBMI(height, weight);
|
|
|
+ Map<String, Object> out = new HashMap<>();
|
|
|
+ out.put("bmi", bmi);
|
|
|
+ return R.success(200, "ok", out);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return R.fail(500, e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|