diff --git a/pom.xml b/pom.xml index c5ae44c..93b9ac9 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ http://maven.apache.org - 4.0.2.RELEASE + 5.1.1.RELEASE 3.2.6 diff --git a/src/main/java/com/lq/api/package-info.java b/src/main/java/com/lq/api/package-info.java new file mode 100644 index 0000000..da9ca92 --- /dev/null +++ b/src/main/java/com/lq/api/package-info.java @@ -0,0 +1 @@ +package com.lq.api; \ No newline at end of file diff --git a/src/main/java/com/lq/wap/vo/UeditorVo.java b/src/main/java/com/lq/api/vo/UeditorVo.java similarity index 97% rename from src/main/java/com/lq/wap/vo/UeditorVo.java rename to src/main/java/com/lq/api/vo/UeditorVo.java index 4eb1341..c6cfb13 100644 --- a/src/main/java/com/lq/wap/vo/UeditorVo.java +++ b/src/main/java/com/lq/api/vo/UeditorVo.java @@ -1,4 +1,4 @@ -package com.lq.wap.vo; +package com.lq.api.vo; public class UeditorVo { diff --git a/src/main/java/com/lq/api/web/SysFileController.java b/src/main/java/com/lq/api/web/SysFileController.java new file mode 100644 index 0000000..8ac5b5f --- /dev/null +++ b/src/main/java/com/lq/api/web/SysFileController.java @@ -0,0 +1,46 @@ +package com.lq.api.web; + +import com.lq.code.entity.AjaxResult; +import com.lq.code.util.FileUtil; +import com.lq.entity.SysFile; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +@Controller +@RequestMapping("/file") +public class SysFileController { + + + @Value("${file.upload}") + private String FILE_LOAD_PATH; + + + @RequestMapping("/upload") + @ResponseBody + public Object upload(@RequestParam("files")MultipartFile[] files){ + AjaxResult ajaxResult = new AjaxResult(); + ajaxResult.setMsg("上传成功"); + Date nowTime = new Date(); + SimpleDateFormat sdf =new SimpleDateFormat("yyyyMMdd"); + File fileDir = new File(FILE_LOAD_PATH+sdf.format(nowTime)); + if (!fileDir.exists()){ + fileDir.mkdirs(); + } + for (MultipartFile multipartFile:files){ + SysFile sysFile = new SysFile(); + sysFile.setCreateTime(nowTime); + String fileType = FileUtil.getFileType(multipartFile.getName()); + sysFile.setFileType(fileType); + sysFile.setFileName(multipartFile.getName()); + + } + return ajaxResult; + } +} diff --git a/src/main/java/com/lq/wap/web/UmUeditorFileController.java b/src/main/java/com/lq/api/web/UmUeditorFileController.java similarity index 89% rename from src/main/java/com/lq/wap/web/UmUeditorFileController.java rename to src/main/java/com/lq/api/web/UmUeditorFileController.java index af8f5c8..5ee9ffb 100644 --- a/src/main/java/com/lq/wap/web/UmUeditorFileController.java +++ b/src/main/java/com/lq/api/web/UmUeditorFileController.java @@ -1,7 +1,7 @@ -package com.lq.wap.web; +package com.lq.api.web; import com.lq.code.util.FileUtil; -import com.lq.wap.vo.UeditorVo; +import com.lq.api.vo.UeditorVo; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -12,11 +12,10 @@ import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.io.IOException; -import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random; -import java.util.UUID; +import java.util.concurrent.ThreadLocalRandom; /** @@ -43,8 +42,8 @@ public class UmUeditorFileController { fileDir.mkdirs(); } for (MultipartFile file:files){ - Random random = new Random(); - Integer uuid = random.nextInt(1000000000); + ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); + Integer uuid = threadLocalRandom.nextInt(1000000000); String fileType = FileUtil.fileFormat(file.getOriginalFilename()); File file1 = new File(fileDir.getPath()+"/"+uuid.toString()+"."+fileType); if (!file1.exists()){ diff --git a/src/main/java/com/lq/code/cache/RedisCache.java b/src/main/java/com/lq/code/cache/RedisCache.java index f13f382..ea0112f 100644 --- a/src/main/java/com/lq/code/cache/RedisCache.java +++ b/src/main/java/com/lq/code/cache/RedisCache.java @@ -7,6 +7,8 @@ import org.springframework.data.redis.core.RedisCallback; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.util.SerializationUtils; +import java.util.concurrent.Callable; + /** * Created by qi_liang on 2018/3/31. */ @@ -57,6 +59,11 @@ public class RedisCache implements Cache { return null; } + @Override + public T get(Object o, Callable callable) { + return null; + } + @Override public void put(Object key, Object value) { final String keyf=key.toString(); @@ -73,6 +80,11 @@ public class RedisCache implements Cache { }); } + @Override + public ValueWrapper putIfAbsent(Object o, Object o1) { + return null; + } + @Override public void evict(Object key) { final String keyf=key.toString(); diff --git a/src/main/java/com/lq/code/util/FileUtil.java b/src/main/java/com/lq/code/util/FileUtil.java index 98fd38b..322fe32 100644 --- a/src/main/java/com/lq/code/util/FileUtil.java +++ b/src/main/java/com/lq/code/util/FileUtil.java @@ -20,7 +20,6 @@ public class FileUtil { FileReader reader=new FileReader(filePath); while (reader.ready()){ stringBuffer.append((char) reader.read()); - } reader.close(); } catch (FileNotFoundException e) { @@ -29,7 +28,6 @@ public class FileUtil { e.printStackTrace(); } - return stringBuffer.toString(); } @@ -72,20 +70,29 @@ public class FileUtil { * @return */ public static String getFileType(String fileName){ + String fileType=null; if (StringUtil.isNotNull(fileName)){ String fileFormat=fileFormat(fileName); - String fileType=null; switch (fileFormat.toUpperCase()){ case "BMP": case "JPEG": case "ICO": case "PNG": case "JNG": - fileType= FileTypeEnum.FILE_TYPE_IMAGE.getValue();break; - + fileType = FileTypeEnum.FILE_TYPE_IMAGE.getValue();break; + case "AVI": + case "MOV": + case "FLV": + case "MP4": + case "MPG": + fileType = FileTypeEnum.FILE_TYPE_VIEDO.getValue();break; + case "PDF": + fileType = FileTypeEnum.FILE_TYPE_PDF.getValue();break; + default: + fileType = FileTypeEnum.FILE_TYPE_OTHER.getValue();break; } } - return null; + return fileType; } diff --git a/src/main/java/com/lq/entity/SysFile.java b/src/main/java/com/lq/entity/SysFile.java index 1101d24..1ca9317 100644 --- a/src/main/java/com/lq/entity/SysFile.java +++ b/src/main/java/com/lq/entity/SysFile.java @@ -13,7 +13,7 @@ public class SysFile extends IdEntity { private String fileName; //文件路径(相对路径) private String path; - //上传事件 + //上传时间 private Date createTime; //文件类型(image:图片,viedo:视频,other:其他) private String fileType; diff --git a/src/main/java/com/lq/wap/package-info.java b/src/main/java/com/lq/wap/package-info.java deleted file mode 100644 index 31a3f78..0000000 --- a/src/main/java/com/lq/wap/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Created by qi_liang on 2018/5/10. - */ -package com.lq.wap; \ No newline at end of file diff --git a/src/main/java/com/lq/wap/web/WapIndexController.java b/src/main/java/com/lq/wap/web/WapIndexController.java deleted file mode 100644 index 171e239..0000000 --- a/src/main/java/com/lq/wap/web/WapIndexController.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.lq.wap.web; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; - -/** - * Created by qi_liang on 2018/5/10. - */ -@Controller -@RequestMapping("/wap") -public class WapIndexController { - - @RequestMapping("/index") - public String index(){ - - return "/wap/index"; - } -}