|
|
@@ -937,8 +937,9 @@ public class UserInfoController {
|
|
|
cDietInfo = new CDietInfo();
|
|
|
cDietInfo.setUserId(userId);
|
|
|
cDietInfo.setPreCalorie(calorie);
|
|
|
- cDietInfo.setCreateTime(new Date());
|
|
|
- cDietInfo.setUpdateTime(new Date());
|
|
|
+ cDietInfo.setDayCalorieIndex(0);
|
|
|
+ cDietInfo.setCreateTime(DateUtil.date());
|
|
|
+ cDietInfo.setUpdateTime(DateUtil.date());
|
|
|
}else{
|
|
|
cDietInfo.setPreCalorie(calorie);
|
|
|
// cDietInfo.setUpdateTime(new Date());
|
|
|
@@ -974,4 +975,95 @@ public class UserInfoController {
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("get_diet_info")
|
|
|
+ public ResultVO getDietInfo(@RequestParam(value = "userId") String userId) {
|
|
|
+ try {
|
|
|
+ CDietInfo cDietInfo = cDietInfoService.findByUserId(userId);
|
|
|
+ return ResultVOUtil.success(cDietInfo != null?CopyUtil.copy(cDietInfo,CDietInfoSimpleVo.class):null);
|
|
|
+ } catch (UserException e) {
|
|
|
+ return ResultVOUtil.error(e.getCode(), e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("upload_day_calorie_index")
|
|
|
+ @Transactional
|
|
|
+ public ResultVO uploadDietCalorie(@RequestParam(value = "dayCalorieIndex") Integer dayCalorieIndex, @RequestParam(value = "userId") String userId) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ CDietInfo cDietInfo = cDietInfoService.findByUserId(userId);
|
|
|
+ if(cDietInfo == null){
|
|
|
+ cDietInfo = new CDietInfo();
|
|
|
+ cDietInfo.setUserId(userId);
|
|
|
+ cDietInfo.setPreCalorie(0d);
|
|
|
+ cDietInfo.setDayCalorieIndex(dayCalorieIndex);
|
|
|
+ cDietInfo.setCreateTime(DateUtil.date());
|
|
|
+ cDietInfo.setUpdateTime(DateUtil.date());
|
|
|
+ }else{
|
|
|
+ cDietInfo.setDayCalorieIndex(dayCalorieIndex);
|
|
|
+ }
|
|
|
+ //保存数据库,获取保存后的字段
|
|
|
+ CDietInfoVo cDietInfoVo = new CDietInfoVo();
|
|
|
+ BeanUtils.copyProperties(cDietInfo, cDietInfoVo);
|
|
|
+ cDietInfoVo = cDietInfoService.saveReturnVo(cDietInfoVo);
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("dayCalorieIndex", cDietInfoVo.getPreCalorie());
|
|
|
+ return ResultVOUtil.success(map);
|
|
|
+ } catch (UserException e) {
|
|
|
+ return ResultVOUtil.error(e.getCode(), e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("upload_day_calorie_and_index")
|
|
|
+ @Transactional
|
|
|
+ public ResultVO uploadDietCalorieAndIndex(
|
|
|
+ @RequestParam(value = "calorie") Double calorie,
|
|
|
+ @RequestParam(value = "dayCalorieIndex") Integer dayCalorieIndex, @RequestParam(value = "userId") String userId) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ CDietInfo cDietInfo = cDietInfoService.findByUserId(userId);
|
|
|
+ if (cDietInfo == null) {
|
|
|
+ cDietInfo = new CDietInfo();
|
|
|
+ cDietInfo.setUserId(userId);
|
|
|
+ cDietInfo.setPreCalorie(calorie);
|
|
|
+ cDietInfo.setDayCalorieIndex(dayCalorieIndex);
|
|
|
+ cDietInfo.setCreateTime(DateUtil.date());
|
|
|
+ cDietInfo.setUpdateTime(DateUtil.date());
|
|
|
+ } else {
|
|
|
+ cDietInfo.setPreCalorie(calorie);
|
|
|
+ cDietInfo.setDayCalorieIndex(dayCalorieIndex);
|
|
|
+ }
|
|
|
+ //保存数据库,获取保存后的字段
|
|
|
+ CDietInfoVo cDietInfoVo = new CDietInfoVo();
|
|
|
+ BeanUtils.copyProperties(cDietInfo, cDietInfoVo);
|
|
|
+ cDietInfoVo = cDietInfoService.saveReturnVo(cDietInfoVo);
|
|
|
+ return ResultVOUtil.success(CopyUtil.copy(cDietInfoVo, CDietInfoSimpleVo.class));
|
|
|
+ } catch (UserException e) {
|
|
|
+ return ResultVOUtil.error(e.getCode(), e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("modify_user_info_weight")
|
|
|
+ @Transactional
|
|
|
+ public ResultVO modifyUserWeightInfo(@RequestParam(value = "weight") Double weight, @RequestParam(value = "userId") String userId) {
|
|
|
+ //把体重同步到user_info 里面
|
|
|
+ UserInfo userInfo = null;
|
|
|
+ try {
|
|
|
+ userInfo = userInfoService.findUserInfoById(userId, false);
|
|
|
+ if (userInfo != null) {
|
|
|
+ userInfo.setWeight(weight);
|
|
|
+ userInfoService.addUserInfo(userInfo);
|
|
|
+ }
|
|
|
+ } catch (UserException e) {
|
|
|
+ return ResultVOUtil.error(e.getCode(), e.getMessage());
|
|
|
+ }
|
|
|
+ Map map = new HashMap();
|
|
|
+ map.put("currentWeight", userInfo == null?0:userInfo.getWeight());
|
|
|
+ return ResultVOUtil.success(map);
|
|
|
+ }
|
|
|
}
|