|
|
@@ -0,0 +1,53 @@
|
|
|
+package com.etotem.cfc.controller.admin;
|
|
|
+
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.service.EnergyService;
|
|
|
+import com.etotem.cfc.service.SysConfigService;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 通关奖励重复发放·能量追回(一次性,2026-11-30)。
|
|
|
+ *
|
|
|
+ * <p>历史 bug:unlock_gates 每 gate_type 被播种4份,refreshFamilyGates 逐条发奖导致
|
|
|
+ * 一次通关发4次能量。CF 已通过 admin_adjust 追回;本接口追回3家庭对应能量。</p>
|
|
|
+ *
|
|
|
+ * <p>幂等:用 sys_config.unlock_energy_clawback_done 标记,重复调用直接返回已执行;
|
|
|
+ * 每成员每逻辑关卡只保留最早一笔 gate_id,其余按 dimension=action 扣回。</p>
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/unlock-clawback")
|
|
|
+public class AdminUnlockClawbackController {
|
|
|
+
|
|
|
+ @Resource private EnergyService energyService;
|
|
|
+ @Resource private SysConfigService sysConfigService;
|
|
|
+
|
|
|
+ private static final String IDEMPOTENT_KEY = "unlock_energy_clawback_done";
|
|
|
+ private static final String REASON = "通关奖励重复发放追回(unlock_gates历史重复4份)";
|
|
|
+
|
|
|
+ @PostMapping("/energy")
|
|
|
+ public Result<?> clawbackEnergy(@RequestAttribute(value = "role", required = false) String role) {
|
|
|
+ if (!"admin".equals(role)) return Result.error("无权限");
|
|
|
+ String done = sysConfigService.getValue(IDEMPOTENT_KEY);
|
|
|
+ if (done != null && !done.trim().isEmpty()) {
|
|
|
+ return Result.success("已执行过,跳过: " + done);
|
|
|
+ }
|
|
|
+ // 每成员按逻辑关卡扣回多余的3笔:dimension=action(id=4)
|
|
|
+ // member19: 邀请3笔×15 + 创建3笔×10 = 75
|
|
|
+ // member68: 邀请3笔×15 + 创建3笔×10 = 75
|
|
|
+ // member75: 创建3笔×10 = 30
|
|
|
+ long[][] items = {{19L, 75}, {68L, 75}, {75L, 30}};
|
|
|
+ int applied = 0;
|
|
|
+ for (long[] it : items) {
|
|
|
+ int after = energyService.deductEnergy(it[0], 4L, (int) it[1], REASON);
|
|
|
+ if (after >= 0) applied++;
|
|
|
+ }
|
|
|
+ sysConfigService.update(IDEMPOTENT_KEY, new Date().toString(), "能量重复发放追回完成标记");
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ data.put("applied", applied);
|
|
|
+ data.put("totalClawback", 180);
|
|
|
+ return Result.success(data);
|
|
|
+ }
|
|
|
+}
|