93 lines
3.1 KiB
Java
93 lines
3.1 KiB
Java
package com.designhub.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.designhub.common.Result;
|
|
import com.designhub.entity.RewardRule;
|
|
import com.designhub.service.RewardRuleService;
|
|
import com.designhub.util.JwtUtil;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import lombok.RequiredArgsConstructor;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 自动奖励规则 Controller
|
|
*/
|
|
@Tag(name = "自动奖励规则", description = "自动奖励规则管理API")
|
|
@RestController
|
|
@RequestMapping("/api/reward-rules")
|
|
@RequiredArgsConstructor
|
|
public class RewardRuleController {
|
|
|
|
private final RewardRuleService rewardRuleService;
|
|
private final JwtUtil jwtUtil;
|
|
|
|
@Operation(summary = "创建奖励规则")
|
|
@PostMapping
|
|
public Result<RewardRule> createRule(
|
|
@RequestBody RewardRule rule,
|
|
@RequestHeader("Authorization") String authHeader) {
|
|
String token = jwtUtil.extractTokenFromHeader(authHeader);
|
|
Long userId = jwtUtil.getUserIdFromToken(token);
|
|
rule.setCreatorId(userId);
|
|
return Result.success(rewardRuleService.createRule(rule));
|
|
}
|
|
|
|
@Operation(summary = "更新奖励规则")
|
|
@PutMapping("/{id}")
|
|
public Result<RewardRule> updateRule(@PathVariable Long id, @RequestBody RewardRule rule) {
|
|
return Result.success(rewardRuleService.updateRule(id, rule));
|
|
}
|
|
|
|
@Operation(summary = "启用规则")
|
|
@PostMapping("/{id}/enable")
|
|
public Result<Void> enableRule(@PathVariable Long id) {
|
|
rewardRuleService.toggleRule(id, true);
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "禁用规则")
|
|
@PostMapping("/{id}/disable")
|
|
public Result<Void> disableRule(@PathVariable Long id) {
|
|
rewardRuleService.toggleRule(id, false);
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "删除规则")
|
|
@DeleteMapping("/{id}")
|
|
public Result<Void> deleteRule(@PathVariable Long id) {
|
|
rewardRuleService.deleteRule(id);
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "获取规则列表")
|
|
@GetMapping
|
|
public Result<IPage<RewardRule>> getRuleList(
|
|
@RequestParam(defaultValue = "1") Integer page,
|
|
@RequestParam(defaultValue = "10") Integer pageSize,
|
|
@RequestParam(required = false) String ruleType) {
|
|
return Result.success(rewardRuleService.getRuleList(page, pageSize, ruleType));
|
|
}
|
|
|
|
@Operation(summary = "获取规则详情")
|
|
@GetMapping("/{id}")
|
|
public Result<RewardRule> getRuleById(@PathVariable Long id) {
|
|
return Result.success(rewardRuleService.getRuleById(id));
|
|
}
|
|
|
|
@Operation(summary = "获取所有启用的规则")
|
|
@GetMapping("/enabled")
|
|
public Result<List<RewardRule>> getEnabledRules() {
|
|
return Result.success(rewardRuleService.getEnabledRules());
|
|
}
|
|
|
|
@Operation(summary = "初始化默认规则")
|
|
@PostMapping("/init")
|
|
public Result<Void> initDefaultRules() {
|
|
rewardRuleService.initDefaultRules();
|
|
return Result.success();
|
|
}
|
|
}
|