Blame view

src/main/java/com/objecteye/controller/DataSourceController.java 2.08 KB
c83b5b39   Liu Haoyu   项目创建, 集成spring-se...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  package com.objecteye.controller;
  
  import com.objecteye.common.CommonResult;
  import com.objecteye.handle.PictureHandle;
  import io.swagger.annotations.Api;
  import io.swagger.annotations.ApiOperation;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.data.redis.core.RedisTemplate;
  import org.springframework.web.bind.annotation.CrossOrigin;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  
  import java.io.File;
  
  @RestController
  @Api(tags = "DataSourceController", description = "数据源上传")
  @RequestMapping("/upload")
  @CrossOrigin
  public class DataSourceController {
  
      @Autowired
      private RedisTemplate redisTemplate;
  
      @Autowired
      private PictureHandle pictureHandle;
  
      @Value("${picture.storePath}")
      private String storePath;
  
      /**
       * 上传图片绝对路径到队列中
       *
       * @param path
       * @return
       */
      @ApiOperation("根据绝对路径上传数据")
      @RequestMapping(value = "/findPage", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
      public CommonResult uploadPicByPath(String path) {
  
          File file = new File(path);
          boolean directory = file.isDirectory();
          boolean exists = file.exists();
          if (directory && exists) {
              File[] files = file.listFiles();
              if (files != null && files.length > 0) {
                  int length = files.length;
                  for (int i = 0; i < length; i++) {
                      File file1 = files[i];
                      String name = file1.getName();
                      String newPath = storePath + name;
                      File file2 = new File(newPath);
                      file1.renameTo(file2);
                      redisTemplate.opsForList().leftPush("picPath", name);
                      pictureHandle.handlePic();
                  }
              }
          }
          return CommonResult.success("{}");
      }
  }