FileController.java 1.87 KB
package com.tanpu.community.controller;

import com.fasterxml.jackson.core.type.TypeReference;
import com.tanpu.common.api.CommonResp;
import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.ThemeQo;
import com.tanpu.community.api.beans.resp.FileUploadResp;
import com.tanpu.community.cache.RedisCache;
import com.tanpu.community.manager.FileManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;

@RestController
@Slf4j
@RequestMapping(value = "/api/file")
public class FileController {

    @Autowired
    private FileManager fileManager;
    
    @Autowired
    private RedisCache redisCache;

    @Autowired
    private CaffeineCacheManager localCache;

    @PostMapping("/uploadFile")
    @ResponseBody
    public CommonResp<FileUploadResp> uploadToRemote(@RequestParam(value = "file") MultipartFile file) {
        return CommonResp.success(fileManager.uploadFile(file));
    }

    @GetMapping("/test")
    public String test() {


//        redisCache.put("11111", JsonUtil.toJson(list), 60);
//
//        String v = redisCache.get("11111");
//        System.out.println(v);
//        System.out.println(JsonUtil.toJson(JsonUtil.toBean(v, new TypeReference<List<String>>() {
//        })));

//        localCache.getCache("local").put("999", "6666666");
//        System.out.println((String) localCache.getCache("local").get("999").get());
//
//
//        for (int i = 0; i < 30; i++) {
//            System.out.println(fileManager.getId("" + i / 2));
//        }
//
//        for (int i = 30; i > 0; i--) {
//            System.out.println(fileManager.getId("" + i / 2));
//        }
        return "";
    }
}