You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.3 KiB

  1. package com.example.demo.controller.cash;
  2. import com.example.demo.Util.JWTUtil;
  3. import com.example.demo.domain.DTO.IdRequest;
  4. import com.example.demo.domain.entity.Admin;
  5. import com.example.demo.domain.vo.cash.Status;
  6. import com.example.demo.domain.vo.coin.Result;
  7. import com.example.demo.service.cash.MessageService;
  8. import com.example.demo.service.coin.MarketService;
  9. import jakarta.servlet.http.HttpServletRequest;
  10. import lombok.RequiredArgsConstructor;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.apache.commons.lang3.StringUtils;
  13. import org.springframework.beans.factory.annotation.Autowired;
  14. import org.springframework.web.bind.annotation.*;
  15. import org.springframework.web.context.request.RequestContextHolder;
  16. import org.springframework.web.context.request.ServletRequestAttributes;
  17. import java.util.Arrays;
  18. import java.util.List;
  19. /**
  20. * @program: GOLD
  21. * @ClassName MessageController
  22. * @description:
  23. * @author: huangqizhen
  24. * @create: 202511-14 22:12
  25. * @Version 1.0
  26. **/
  27. @RestController
  28. @RequestMapping("/getMessage")
  29. @RequiredArgsConstructor
  30. @Slf4j
  31. @CrossOrigin
  32. public class MessageController {
  33. @Autowired
  34. private MessageService messageService;
  35. @Autowired
  36. private MarketService marketService;
  37. @PostMapping
  38. public Result getMessage(@RequestBody Status status) throws Exception {
  39. HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
  40. String token = request.getHeader("token");
  41. // 解析 token 获取用户信息
  42. Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
  43. List<String> userMarkets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
  44. List<String> markets = marketService.getMarketIds(userMarkets);
  45. // 权限校验逻辑
  46. if (markets.contains("9") || markets.contains("9999")) {
  47. markets=null;
  48. }
  49. return Result.success(messageService.getMessage(markets, status.getStatus()));
  50. }
  51. @PostMapping("/update")
  52. public Result update(@RequestBody IdRequest idRequest) throws Exception {
  53. try {
  54. Integer id = idRequest.getId();
  55. messageService.update(id);
  56. return Result.success();
  57. }
  58. catch (Exception e) {
  59. return Result.error("更新失败");
  60. }
  61. }
  62. }