feat(calculator): 食谱计算器历史记录功能(test-0415 反馈2-2)
后端: - GET /api/front/tool/calculator/history 倒序分页返回当前用户记录摘要 - ToolCalculatorService.getHistory(PageParamRequest) 实现 - 摘要含 id / createdAt / bmi / ckdStage / proteinIntake / energyIntake / isAdopted / hasDialysis 前端: - api/tool.js 新增 getCalculatorHistory(params) - pages/tool/calculator-history.vue 历史列表页(下拉刷新 + 触底加载) - 点击行跳转 calculator-result?id=xxx 复用结果页,自然支持「重新载入参数」 - pages.json 注册路由 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -102,6 +102,17 @@ public class ToolController {
|
||||
return CommonResult.success(toolCalculatorService.getResult(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取计算历史记录列表(test-0415 反馈2-2)
|
||||
* 当前登录用户最近的营养计算记录倒序分页。
|
||||
*/
|
||||
@ApiOperation(value = "获取计算历史记录", notes = "倒序分页返回当前用户的营养计算结果摘要")
|
||||
@GetMapping("/calculator/history")
|
||||
public CommonResult<CommonPage<Map<String, Object>>> getCalculatorHistory(
|
||||
@Validated PageParamRequest pageParamRequest) {
|
||||
return CommonResult.success(CommonPage.restPage(toolCalculatorService.getHistory(pageParamRequest)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 采纳营养计划
|
||||
* <p>
|
||||
|
||||
@@ -722,5 +722,36 @@ public class ToolCalculatorServiceImpl extends ServiceImpl<V2CalculatorResultDao
|
||||
if (value.compareTo(max) > 0) return "above";
|
||||
return "normal";
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户的计算历史记录(test-0415 反馈2-2)
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> getHistory(com.zbkj.common.request.PageParamRequest pageParamRequest) {
|
||||
Integer userId = tokenComponent.getUserId();
|
||||
if (userId == null) {
|
||||
throw new CrmebException("请先登录");
|
||||
}
|
||||
com.github.pagehelper.PageHelper.startPage(pageParamRequest.getPage(), pageParamRequest.getLimit());
|
||||
LambdaQueryWrapper<V2CalculatorResult> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(V2CalculatorResult::getUserId, userId.longValue())
|
||||
.orderByDesc(V2CalculatorResult::getCreatedAt);
|
||||
List<V2CalculatorResult> list = calculatorResultDao.selectList(lqw);
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (V2CalculatorResult e : list) {
|
||||
Map<String, Object> m = new HashMap<>();
|
||||
m.put("id", e.getResultId());
|
||||
m.put("createdAt", e.getCreatedAt());
|
||||
m.put("bmi", e.getBmi());
|
||||
m.put("bmiStatus", e.getBmiStatus());
|
||||
m.put("ckdStage", e.getCkdStage());
|
||||
m.put("proteinIntake", e.getProteinIntake());
|
||||
m.put("energyIntake", e.getEnergyIntake());
|
||||
m.put("isAdopted", e.getIsAdopted());
|
||||
m.put("hasDialysis", e.getHasDialysis());
|
||||
result.add(m);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.zbkj.service.service.tool;
|
||||
|
||||
import com.zbkj.common.request.NutritionCalculateRequest;
|
||||
import com.zbkj.common.request.PageParamRequest;
|
||||
import com.zbkj.common.response.NutritionAdoptResponse;
|
||||
import com.zbkj.common.response.NutritionCalculateResponse;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 食谱计算器服务接口
|
||||
* +----------------------------------------------------------------------
|
||||
@@ -55,5 +59,11 @@ public interface ToolCalculatorService {
|
||||
* @return 采纳结果,包含计划ID、日期范围、积分奖励
|
||||
*/
|
||||
NutritionAdoptResponse adopt(Long resultId);
|
||||
|
||||
/**
|
||||
* 获取当前登录用户的计算历史记录(test-0415 反馈2-2)
|
||||
* 仅返回摘要:id、createdAt、bmi、ckdStage、proteinIntake、energyIntake、isAdopted
|
||||
*/
|
||||
List<Map<String, Object>> getHistory(PageParamRequest pageParamRequest);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user