FileController.java 1.87 KB
Newer Older
张辰's avatar
张辰 committed
1 2
package com.tanpu.community.controller;

张辰's avatar
张辰 committed
3
import com.fasterxml.jackson.core.type.TypeReference;
张辰's avatar
张辰 committed
4
import com.tanpu.common.api.CommonResp;
张辰's avatar
张辰 committed
5 6
import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.ThemeQo;
刘基明's avatar
刘基明 committed
7
import com.tanpu.community.api.beans.resp.FileUploadResp;
张辰's avatar
张辰 committed
8
import com.tanpu.community.cache.RedisCache;
张辰's avatar
张辰 committed
9 10 11
import com.tanpu.community.manager.FileManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
张辰's avatar
张辰 committed
12
import org.springframework.cache.caffeine.CaffeineCacheManager;
张辰's avatar
张辰 committed
13 14 15
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

张辰's avatar
张辰 committed
16 17 18
import java.util.Arrays;
import java.util.List;

张辰's avatar
张辰 committed
19 20 21 22 23 24 25
@RestController
@Slf4j
@RequestMapping(value = "/api/file")
public class FileController {

    @Autowired
    private FileManager fileManager;
张辰's avatar
张辰 committed
26 27 28
    
    @Autowired
    private RedisCache redisCache;
张辰's avatar
张辰 committed
29

张辰's avatar
张辰 committed
30 31 32
    @Autowired
    private CaffeineCacheManager localCache;

张辰's avatar
张辰 committed
33 34
    @PostMapping("/uploadFile")
    @ResponseBody
刘基明's avatar
刘基明 committed
35
    public CommonResp<FileUploadResp> uploadToRemote(@RequestParam(value = "file") MultipartFile file) {
张辰's avatar
张辰 committed
36 37
        return CommonResp.success(fileManager.uploadFile(file));
    }
张辰's avatar
张辰 committed
38 39 40

    @GetMapping("/test")
    public String test() {
张辰's avatar
张辰 committed
41

张辰's avatar
张辰 committed
42

张辰's avatar
张辰 committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
//        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));
//        }
张辰's avatar
张辰 committed
61 62
        return "";
    }
张辰's avatar
张辰 committed
63
}