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
68 lines
2.3 KiB
package com.example.demo.controller.cash;
|
|
|
|
import com.example.demo.Util.JWTUtil;
|
|
import com.example.demo.domain.DTO.IdRequest;
|
|
import com.example.demo.domain.entity.Admin;
|
|
import com.example.demo.domain.vo.cash.Status;
|
|
import com.example.demo.domain.vo.coin.Result;
|
|
import com.example.demo.service.cash.MessageService;
|
|
import com.example.demo.service.coin.MarketService;
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @program: GOLD
|
|
* @ClassName MessageController
|
|
* @description:
|
|
* @author: huangqizhen
|
|
* @create: 2025−11-14 22:12
|
|
* @Version 1.0
|
|
**/
|
|
@RestController
|
|
@RequestMapping("/getMessage")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
@CrossOrigin
|
|
public class MessageController {
|
|
@Autowired
|
|
private MessageService messageService;
|
|
@Autowired
|
|
private MarketService marketService;
|
|
@PostMapping
|
|
public Result getMessage(@RequestBody Status status) throws Exception {
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
String token = request.getHeader("token");
|
|
|
|
// 解析 token 获取用户信息
|
|
Admin admin = (Admin) JWTUtil.getUserDetailsList(String.valueOf(token), Admin.class);
|
|
List<String> userMarkets = Arrays.asList(StringUtils.split(admin.getMarkets(), ","));
|
|
List<String> markets = marketService.getMarketIds(userMarkets);
|
|
|
|
// 权限校验逻辑
|
|
if (markets.contains("9") || markets.contains("9999")) {
|
|
markets=null;
|
|
}
|
|
return Result.success(messageService.getMessage(markets, status.getStatus()));
|
|
}
|
|
@PostMapping("/update")
|
|
public Result update(@RequestBody IdRequest idRequest) throws Exception {
|
|
try {
|
|
Integer id = idRequest.getId();
|
|
messageService.update(id);
|
|
return Result.success();
|
|
}
|
|
catch (Exception e) {
|
|
return Result.error("更新失败");
|
|
}
|
|
}
|
|
}
|