|
@@ -1,27 +1,23 @@
|
|
|
package space.anyi.BI.controller;
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
-import cn.hutool.poi.excel.ExcelUtil;
|
|
|
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-import space.anyi.BI.BIApplication;
|
|
|
import space.anyi.BI.entity.Chart;
|
|
|
import space.anyi.BI.entity.ResponseResult;
|
|
|
import space.anyi.BI.entity.dto.ChartDTO;
|
|
|
import space.anyi.BI.entity.vo.ChartVO;
|
|
|
import space.anyi.BI.entity.vo.PageVO;
|
|
|
+import space.anyi.BI.handler.redisson.RRateLimiterHandler;
|
|
|
import space.anyi.BI.service.ChartService;
|
|
|
-import space.anyi.BI.util.BeanCopyUtil;
|
|
|
import space.anyi.BI.util.SecurityUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
-import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -37,6 +33,8 @@ public class ChartController {
|
|
|
private final static Logger log = LoggerFactory.getLogger(ChartController.class);
|
|
|
@Resource
|
|
|
private ChartService chartService;
|
|
|
+ @Resource
|
|
|
+ private RRateLimiterHandler rRateLimiterHandler;
|
|
|
@PreAuthorize("@ps.hasRole('用户')")
|
|
|
@GetMapping("/getChartById/{id}")
|
|
|
@ResponseBody
|
|
@@ -82,6 +80,10 @@ public class ChartController {
|
|
|
@ResponseBody
|
|
|
public ResponseResult generateChartByAI(ChartDTO chartDTO, MultipartFile file) throws IOException {
|
|
|
log.info("分析目标:{}图标名称:{}",chartDTO.getAnalysisTarget(),chartDTO.getName());
|
|
|
+ //限流判断
|
|
|
+ if (!rRateLimiterHandler.accessAble("generateChartByAI_"+SecurityUtils.getUserId())){
|
|
|
+ return ResponseResult.errorResult(ResponseResult.AppHttpCodeEnum.RATE_LIMIT_ERROR);
|
|
|
+ }
|
|
|
if (file == null || file.isEmpty()) {
|
|
|
return ResponseResult.errorResult(ResponseResult.AppHttpCodeEnum.FILE_NOT_NULL);
|
|
|
}
|
|
@@ -89,6 +91,10 @@ public class ChartController {
|
|
|
if (!file.getContentType().equals("application/vnd.ms-excel") && !file.getContentType().equals("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) {
|
|
|
return ResponseResult.errorResult(ResponseResult.AppHttpCodeEnum.FILE_TYPE_ERROR);
|
|
|
}
|
|
|
+ //文件大小判断
|
|
|
+ if (file.getSize()>1024*1024*2L) {
|
|
|
+ return ResponseResult.errorResult(ResponseResult.AppHttpCodeEnum.FILE_SIZE_ERROR);
|
|
|
+ }
|
|
|
ChartVO vo = chartService.generateChartByAI(chartDTO,file);
|
|
|
|
|
|
return ResponseResult.okResult(vo);
|