|
|
@@ -2,7 +2,9 @@ package com.etotem.cfc.controller.admin;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.entity.DimensionDailyLimit;
|
|
|
import com.etotem.cfc.entity.EnergySourceConfig;
|
|
|
+import com.etotem.cfc.mapper.DimensionDailyLimitMapper;
|
|
|
import com.etotem.cfc.mapper.EnergySourceConfigMapper;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
@@ -23,6 +25,9 @@ public class AdminEnergyConfigController {
|
|
|
@Resource
|
|
|
private EnergySourceConfigMapper energySourceConfigMapper;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private DimensionDailyLimitMapper dimensionDailyLimitMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 能量来源配置列表
|
|
|
*/
|
|
|
@@ -95,27 +100,49 @@ public class AdminEnergyConfigController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取每日能量限制(V1 返回硬编码值)
|
|
|
+ * 获取每日能量限制(数据库持久化)
|
|
|
*/
|
|
|
@Operation(summary = "获取每日能量限制")
|
|
|
@PostMapping("/daily-limits")
|
|
|
public Result<List<DimensionDailyLimit>> dailyLimits(@RequestBody Map<String, Object> params) {
|
|
|
- List<DimensionDailyLimit> limits = new ArrayList<>();
|
|
|
- limits.add(new DimensionDailyLimit("body", 50));
|
|
|
- limits.add(new DimensionDailyLimit("mind", 50));
|
|
|
- limits.add(new DimensionDailyLimit("wisdom", 80));
|
|
|
- limits.add(new DimensionDailyLimit("action", 60));
|
|
|
- limits.add(new DimensionDailyLimit("wealth", 50));
|
|
|
+ List<DimensionDailyLimit> limits = dimensionDailyLimitMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<DimensionDailyLimit>()
|
|
|
+ .orderByAsc(DimensionDailyLimit::getDimensionCode)
|
|
|
+ );
|
|
|
return Result.success(limits);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 保存每日能量限制(V1 仅返回成功,实际存储待后续迁移)
|
|
|
+ * 保存每日能量限制(数据库持久化)
|
|
|
*/
|
|
|
@Operation(summary = "保存每日能量限制")
|
|
|
@PostMapping("/daily-limit-save")
|
|
|
public Result<String> dailyLimitSave(@RequestBody DailyLimitSaveRequest request) {
|
|
|
- // V1: 仅返回成功,实际存储待后续迁移到数据库
|
|
|
+ if (request.getLimits() == null || request.getLimits().isEmpty()) {
|
|
|
+ return Result.error("limits不能为空");
|
|
|
+ }
|
|
|
+ Date now = new Date();
|
|
|
+ for (DimensionDailyLimit dto : request.getLimits()) {
|
|
|
+ String code = dto.getDimensionCode();
|
|
|
+ Integer limit = dto.getDailyLimit();
|
|
|
+ if (code == null || limit == null) {
|
|
|
+ return Result.error("dimensionCode和dailyLimit不能为空");
|
|
|
+ }
|
|
|
+ DimensionDailyLimit existing = dimensionDailyLimitMapper.selectOne(
|
|
|
+ new LambdaQueryWrapper<DimensionDailyLimit>().eq(DimensionDailyLimit::getDimensionCode, code));
|
|
|
+ if (existing != null) {
|
|
|
+ existing.setDailyLimit(limit);
|
|
|
+ existing.setUpdatedAt(now);
|
|
|
+ dimensionDailyLimitMapper.updateById(existing);
|
|
|
+ } else {
|
|
|
+ DimensionDailyLimit entity = new DimensionDailyLimit();
|
|
|
+ entity.setDimensionCode(code);
|
|
|
+ entity.setDailyLimit(limit);
|
|
|
+ entity.setCreatedAt(now);
|
|
|
+ entity.setUpdatedAt(now);
|
|
|
+ dimensionDailyLimitMapper.insert(entity);
|
|
|
+ }
|
|
|
+ }
|
|
|
return Result.success("保存成功");
|
|
|
}
|
|
|
|
|
|
@@ -162,13 +189,16 @@ public class AdminEnergyConfigController {
|
|
|
Map<String, Object> data = new HashMap<>();
|
|
|
data.put("sources", sources);
|
|
|
|
|
|
- // 每日限制
|
|
|
+ // 每日限制(从数据库读取)
|
|
|
List<Map<String, Object>> dailyLimits = new ArrayList<>();
|
|
|
- dailyLimits.add(limitMap("body", 50));
|
|
|
- dailyLimits.add(limitMap("mind", 50));
|
|
|
- dailyLimits.add(limitMap("wisdom", 80));
|
|
|
- dailyLimits.add(limitMap("action", 60));
|
|
|
- dailyLimits.add(limitMap("wealth", 50));
|
|
|
+ List<DimensionDailyLimit> limitsFromDb = dimensionDailyLimitMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<DimensionDailyLimit>().orderByAsc(DimensionDailyLimit::getDimensionCode));
|
|
|
+ for (DimensionDailyLimit limit : limitsFromDb) {
|
|
|
+ Map<String, Object> m = new HashMap<>();
|
|
|
+ m.put("dimensionCode", limit.getDimensionCode());
|
|
|
+ m.put("dailyLimit", limit.getDailyLimit());
|
|
|
+ dailyLimits.add(m);
|
|
|
+ }
|
|
|
data.put("dailyLimits", dailyLimits);
|
|
|
|
|
|
return Result.success(data);
|
|
|
@@ -212,22 +242,6 @@ public class AdminEnergyConfigController {
|
|
|
public void setRatio(Integer ratio) { this.ratio = ratio; }
|
|
|
}
|
|
|
|
|
|
- public static class DimensionDailyLimit {
|
|
|
- private String dimensionCode;
|
|
|
- private Integer dailyLimit;
|
|
|
-
|
|
|
- public DimensionDailyLimit() {}
|
|
|
- public DimensionDailyLimit(String dimensionCode, Integer dailyLimit) {
|
|
|
- this.dimensionCode = dimensionCode;
|
|
|
- this.dailyLimit = dailyLimit;
|
|
|
- }
|
|
|
-
|
|
|
- public String getDimensionCode() { return dimensionCode; }
|
|
|
- public void setDimensionCode(String dimensionCode) { this.dimensionCode = dimensionCode; }
|
|
|
- public Integer getDailyLimit() { return dailyLimit; }
|
|
|
- public void setDailyLimit(Integer dailyLimit) { this.dailyLimit = dailyLimit; }
|
|
|
- }
|
|
|
-
|
|
|
public static class DailyLimitSaveRequest {
|
|
|
private List<DimensionDailyLimit> limits;
|
|
|
|