| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package com.train.controller.admin;
- import com.train.common.Result;
- import com.train.service.BadgeService;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import org.springframework.web.bind.annotation.*;
- import javax.annotation.Resource;
- import java.util.Map;
- @Tag(name = "管理端-徽章", description = "徽章手动颁发")
- @RestController
- @RequestMapping("/api/admin/badge")
- public class AdminBadgeController {
- @Resource
- private BadgeService badgeService;
- @Operation(summary = "手动颁发徽章")
- @PostMapping("/grant")
- public Result<?> grant(@RequestBody Map<String, Object> body,
- @org.springframework.web.bind.annotation.RequestAttribute("adminId") Long adminId) {
- Object uidObj = body.get("uid");
- if (uidObj == null) {
- return Result.error("学员ID不能为空");
- }
- Long uid;
- try {
- uid = Long.valueOf(uidObj.toString());
- } catch (NumberFormatException e) {
- return Result.error("学员ID不合法");
- }
- String badgeKey = body.get("badgeKey") == null ? null : body.get("badgeKey").toString().trim();
- if (badgeKey == null || badgeKey.isEmpty()) {
- return Result.error("徽章键不能为空");
- }
- String remark = body.get("remark") == null ? null : body.get("remark").toString();
- boolean ok = badgeService.grantBadge(uid, badgeKey, adminId, remark);
- if (!ok) {
- return Result.error("徽章键不存在或用户不存在");
- }
- return Result.success();
- }
- }
|