打造高校健康管理系统的Java、Spring Boot与Vue框架实践
最编程
2024-08-05 22:47:48
...
@GetMapping("/getCurrentCheckInfo/{userId}")
ResponseEntity<CheckInfo> getCurrentCheckInfo(@PathVariable("userId") Integer userId) {
return checkInfoService.getCurrentCheckInfo(userId);
}
@GetMapping("/getBim")
ResponseEntity judgeIsHealth(Double height, Double weight) {
String suggestion;
if (height == null || weight == null) {
throw new MyException(ExceptionEnums.NO_WEIGHT_HEIGHT);
}
Double result = weight / ((height / 100) * (height / 100));
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(2);
nf.setRoundingMode(RoundingMode.UP);
result = Double.valueOf(nf.format(result));
if (result < 19) {
suggestion = "体重偏低";
} else if (result < 25) {
suggestion = "健康体重";
} else if (result < 30) {
suggestion = "超重";
} else if (result < 39) {
suggestion = "严重超重";
} else {
suggestion = "极度超重";
}
return ResponseEntity.ok(new HealthDTO().setBim(result).setSuggestion(suggestion));
}
@GetMapping("/getDataAnalysis/{userId}")
ResponseEntity getDataAnalysis(@PathVariable("userId") Integer userId) {
List<CheckInfo> analysis = checkInfoService.getDataAnalysis(userId);
if (analysis == null) {
throw new MyException(ExceptionEnums.NO_CHECK_INFO);
} else {
List<String> label = new ArrayList<>();
List<Double> height = new ArrayList<>();
List<Double> weight = new ArrayList<>();
analysis.forEach(v -> {
label.add(v.getCheckYear());
height.add(v.getHeight());
weight.add(v.getWeight());
});
return ResponseEntity.ok(new AnalysisData().setLabel(label).setHeight(height).setWeight(weight));
}
}
@ApiOperation(value = "基础接口: 分页返回数据")
@PostMapping(value = "page")
public ResponseEntity<Page<CheckInfo>> page(@RequestBody Condition condition) {
//log.info();
return ResponseEntity.ok(checkInfoService.selectPage(condition));
}
/**
* 判断体检表是否存在
*
* @param userId 用户id
* @param checkYear 检查年份
* @return 是否存在
*/
@GetMapping("/judgeCheckIsExist")
ResponseEntity judgeCheckIsExist(Integer userId, String checkYear) {
boolean aBoolean = checkInfoService.CheckIsExist(userId, checkYear);
return ResponseEntity.ok(aBoolean);
}
@ApiOperation(value = "基础接口: 新增操作")
@PostMapping(value = "add")
@RequiresPermissions("checkInfo:add")
public ResponseEntity<CheckInfo> save(@RequestBody CheckInfo checkInfo) {
checkInfo.setCreateDatetime(new Date());
checkInfo.setUpdateDatetime(new Date());
LambdaQueryWrapper<CheckInfo> checkInfoLambdaQueryWrapper = new LambdaQueryWrapper<>();
checkInfoLambdaQueryWrapper.eq(CheckInfo::getCheckYear, checkInfo.getCheckYear());
checkInfoLambdaQueryWrapper.eq(CheckInfo::getStuNo, checkInfo.getStuNo());
CheckInfo check = checkInfoService.getOne(checkInfoLambdaQueryWrapper);
if (null == check && checkInfo.getCheckYear() != null) {
boolean save = checkInfoService.save(checkInfo);
if (save) {
return ResponseEntity.ok(checkInfo);
}
}
throw new MyException(ExceptionEnums.ADD_ERROR);
}
@ApiOperation(value = "基础接口: 返回指定ID的数据")
@GetMapping(value = "get/{id}")
public ResponseEntity<CheckInfo> get(@PathVariable("id") Integer id) {
CheckInfo checkInfo = checkInfoService.getById(id);
if (checkInfo != null) {
return ResponseEntity.ok(checkInfo);
}
throw new MyException(ExceptionEnums.GET_ITEM);
}