|
|
@@ -0,0 +1,84 @@
|
|
|
+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.PromotionTier;
|
|
|
+import com.etotem.cfc.entity.PromotionTierConfig;
|
|
|
+import com.etotem.cfc.mapper.PromotionTierConfigMapper;
|
|
|
+import com.etotem.cfc.service.PromotionTierEvalService;
|
|
|
+import com.etotem.cfc.service.PromotionTierService;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/admin/promotion-tier")
|
|
|
+public class AdminPromotionTierController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PromotionTierConfigMapper configMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PromotionTierEvalService evalService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private PromotionTierService promotionTierService;
|
|
|
+
|
|
|
+ @PostMapping("/list")
|
|
|
+ public Result<List<PromotionTierConfig>> list() {
|
|
|
+ return Result.success(configMapper.selectList(
|
|
|
+ new LambdaQueryWrapper<PromotionTierConfig>().orderByAsc(PromotionTierConfig::getSortOrder)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/get")
|
|
|
+ public Result<PromotionTierConfig> get(@RequestBody Map<String, Object> params) {
|
|
|
+ Long id = Long.valueOf(params.get("id").toString());
|
|
|
+ return Result.success(configMapper.selectById(id));
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/save")
|
|
|
+ public Result<String> save(@RequestBody PromotionTierConfig config) {
|
|
|
+ if (config.getId() != null) {
|
|
|
+ config.setUpdatedAt(new Date());
|
|
|
+ configMapper.updateById(config);
|
|
|
+ } else {
|
|
|
+ config.setCreatedAt(new Date());
|
|
|
+ config.setUpdatedAt(new Date());
|
|
|
+ if (config.getEnabled() == null) {
|
|
|
+ config.setEnabled(1);
|
|
|
+ }
|
|
|
+ configMapper.insert(config);
|
|
|
+ }
|
|
|
+ return Result.success("已保存");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/delete")
|
|
|
+ public Result<String> delete(@RequestBody Map<String, Object> params) {
|
|
|
+ Long id = Long.valueOf(params.get("id").toString());
|
|
|
+ configMapper.deleteById(id);
|
|
|
+ return Result.success("已删除");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/evaluate-all")
|
|
|
+ public Result<String> evaluateAll() {
|
|
|
+ int changed = evalService.evaluateAllUsers();
|
|
|
+ return Result.success("评估完成,共变更" + changed + "个用户等级");
|
|
|
+ }
|
|
|
+
|
|
|
+ @PostMapping("/user-tier")
|
|
|
+ public Result<Map<String, Object>> getUserTier(@RequestBody Map<String, Object> params) {
|
|
|
+ Long userId = Long.valueOf(params.get("userId").toString());
|
|
|
+ PromotionTier tier = promotionTierService.getCurrentTier(userId);
|
|
|
+ String evaluatedTier = evalService.evaluateTier(userId);
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("currentTier", tier);
|
|
|
+ result.put("evaluatedTier", evaluatedTier);
|
|
|
+ result.put("matched", tier != null && evaluatedTier.equals(tier.getTier()));
|
|
|
+ return Result.success(result);
|
|
|
+ }
|
|
|
+}
|