wuweihao %!s(int64=5) %!d(string=hai) anos
pai
achega
49ad8fcebc

+ 12 - 2
src/main/java/com/fd/controller/LoginController.java

@@ -24,7 +24,7 @@ import javax.servlet.http.HttpServletRequest;
  */
 @Log4j2
 @RestController
-public class LoginController {
+public class UserController {
 
     @Autowired
     private UserRepository userRepository;
@@ -41,7 +41,17 @@ public class LoginController {
             // 密码不相等
             throw new UnauthorizedException();
         }
-        return new R(200, JWTUtil.sign(username, password));
+        return new R(200, (Object) JWTUtil.sign(username, password));
+    }
+
+
+    @GetMapping("/logout")
+    public R logout() {
+        log.info("run logout");
+        Subject subject = SecurityUtils.getSubject();
+        subject.logout();
+
+        return new R(200, MsgCode.SUCCESS);
     }
 
     /**

+ 0 - 12
src/main/java/com/fd/server/IBaseServer.java

@@ -1,12 +0,0 @@
-package com.fd.server;
-
-import java.io.Serializable;
-
-/**
- * Created by Owen on 2019/11/12 0012 14:15
- */
-public interface IBaseServer<T, ID extends Serializable> {
-
-    public abstract T find(ID id);
-
-}

+ 1 - 1
src/main/java/com/fd/server/ModelServer.java

@@ -12,7 +12,7 @@ import java.util.List;
 /**
  * Created by Owen on 2019/11/21 0021 15:29
  */
-public interface ModelServer {
+public interface ModelServer extends OutputFileServer {
 
     // 大文件上传
     R uploadBigFile(MultipartFile file);

+ 0 - 252
src/main/java/com/fd/server/impl/FileServerImpl.java

@@ -1,252 +0,0 @@
-//package com.fd.server.impl;
-//
-//import com.fd.constant.MsgCode;
-//import com.fd.dto.PageDto;
-//import com.fd.entity.FileEntity;
-//import com.fd.repository.FileRepository;
-//import com.fd.server.FileServer;
-//import com.fd.util.FileUtils;
-//import com.fd.util.R;
-//import lombok.extern.log4j.Log4j2;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.beans.factory.annotation.Value;
-//import org.springframework.data.domain.Page;
-//import org.springframework.data.domain.PageRequest;
-//import org.springframework.data.domain.Sort;
-//import org.springframework.stereotype.Service;
-//import org.springframework.web.multipart.MultipartFile;
-//
-//import javax.servlet.http.HttpServletResponse;
-//import javax.transaction.Transactional;
-//import java.io.File;
-//import java.io.IOException;
-//import java.io.InputStream;
-//import java.util.Base64;
-//import java.util.Date;
-//import java.util.Optional;
-//
-///**
-// * Created by Owen on 2019/11/12 0012 10:05
-// */
-//@Log4j2
-//@Service
-//@Transactional
-//public class FileServerImpl implements FileServer {
-//
-//    @Value("${input.file.path}")
-//    private String INPUT_FILE_PATH;
-//
-//    @Value("${output.file.path}")
-//    private String OUTPUT_FILE_PATH;
-//
-//    @Autowired
-//    private FileRepository fileRepository;
-//
-//    @Override
-//    public R uploadBigFile(MultipartFile file, String type) {
-//        log.warn("run uploadBigFile");
-//        long start = System.currentTimeMillis();
-//        if (file.isEmpty() || file.getSize() <= 0) {
-//            log.info("文件为空");
-//            return new R(50001, MsgCode.E50001);
-//        }
-//
-//        // 文件名全名
-//        String fullFileName = file.getOriginalFilename();
-//
-//        // 创建目录路径
-//        FileUtils.createDir(INPUT_FILE_PATH);
-//
-//        // 拼接唯一文件名
-//        long timeMillis = System.currentTimeMillis();
-////        String fileName = timeMillis + "_" + fullFileName;
-//        String fileName = fullFileName;
-//
-//        // 文件保存路径
-//        String filePath = INPUT_FILE_PATH + fileName;
-//
-//        // 写文件到本地
-//        try {
-//            FileUtils.bigFileWrite(file.getInputStream(), filePath);
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//        }
-//        log.info("filePath: {}", filePath);
-//
-//        // 保存信息到db
-//        FileEntity entity = new FileEntity();
-//        entity.setFileName(fileName);
-//        entity.setFileUrl(filePath);
-//        entity.setCreateTime(new Date());
-//        entity.setUpdateTime(new Date());
-//        entity.setType(type);
-//        entity.setStatus(1);
-//        fileRepository.save(entity);
-//        long end = System.currentTimeMillis();
-//        log.info("end uploadBigFile, total time: {} s", (end - start)/1000);
-//        return new R(200, entity);
-//    }
-//
-//
-//    @Override
-//    public R uploadRasterBigFile(MultipartFile file, String type) {
-//        log.warn("run uploadBigFile");
-//        long start = System.currentTimeMillis();
-//        if (file.isEmpty() || file.getSize() <= 0) {
-//            log.info("文件为空");
-//            return new R(50001, MsgCode.E50001);
-//        }
-//
-//        // 文件名全名
-//        String fullFileName = file.getOriginalFilename();
-//
-//        // 创建目录路径
-//        FileUtils.createDir(INPUT_FILE_PATH);
-//
-//        // 拼接唯一文件名
-//        long timeMillis = System.currentTimeMillis();
-////        String fileName = timeMillis + "_" + fullFileName;
-//        String fileName = fullFileName;
-//
-//        // 文件保存路径
-//        String filePath = INPUT_FILE_PATH + fileName;
-//
-//        // 写文件到本地
-//
-//        try {
-//            FileUtils.bigFileWrite(file.getInputStream(), filePath);
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//        }
-//        log.info("filePath: {}", filePath);
-//
-//        // 保存信息到db
-//        FileEntity entity = new FileEntity();
-//        entity.setFileName(fileName);
-//        entity.setFileUrl(filePath);
-//        entity.setCreateTime(new Date());
-//        entity.setUpdateTime(new Date());
-//        entity.setType(type);
-//        entity.setStatus(2);
-//        fileRepository.save(entity);
-//        long end = System.currentTimeMillis();
-//        log.info("end uploadBigFile, total time: {} s", (end - start)/1000);
-//        return new R(200, entity);
-//    }
-//
-//    @Override
-//    public R uploadFile(MultipartFile file, String directoryName, String type) {
-//        if (file.isEmpty() || file.getSize() <= 0) {
-//            log.info("文件为空");
-//            return new R(50001, MsgCode.E50001);
-//        }
-//
-//        // 文件名全名
-//        String fullFileName = file.getOriginalFilename();
-//
-//        // 创建目录路径
-//        FileUtils.createDir(INPUT_FILE_PATH + directoryName);
-//
-//        // 拼接唯一文件名
-////        String fileName = FileUtils.dateStr() + fullFileName;
-//
-//        // 文件保存路径
-//        String filePath = INPUT_FILE_PATH + directoryName + File.separator + fullFileName;
-//        log.info("filePath: {}", filePath);
-//
-//        // 写文件到本地
-//        try {
-//            byte[] bytes = file.getBytes();
-//            String content = Base64.getEncoder().encodeToString(bytes);
-//            FileUtils.base64ToFileWriter(content, filePath);
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//        }
-//
-//        // 保存信息到db
-//        FileEntity entity = new FileEntity();
-//        entity.setFileName(fullFileName);
-//        entity.setFileUrl(filePath);
-//        entity.setCreateTime(new Date());
-//        entity.setUpdateTime(new Date());
-//        entity.setType(type);
-//        fileRepository.save(entity);
-//
-//        log.info("end uploadBigFile");
-//        return new R(200, entity);
-//    }
-//
-//
-//    @Override
-//    public R findByType(String type, PageDto pageDto) {
-//        Page<FileEntity> page = fileRepository.findByType(type, PageRequest.of(pageDto.getPageNum(), pageDto.getPageSize(), Sort.by("createTime").descending()));
-//        return new R(200, page);
-//    }
-//
-//    @Override
-//    public R findByType(String type1, String type2, PageDto pageDto) {
-//        Page<FileEntity> page = fileRepository.findByType(type1, type2, PageRequest.of(pageDto.getPageNum(), pageDto.getPageSize(), Sort.by("createTime").descending()));
-//        return new R(200, page);
-//    }
-//
-//    @Override
-//    public R deleteById(Long fileId) {
-//        // 删除服务器文件
-//        Optional<FileEntity> e = fileRepository.findById(fileId);
-//        if (!e.isPresent()) {
-//            return new R(50002, MsgCode.E50002);
-//        }
-//        FileEntity fileEntity = e.get();
-//        String fileName = fileEntity.getFileName();
-//        // 文件
-//        if (fileName.contains(".")) {
-//            File file = new File(fileEntity.getFileUrl());
-//            file.delete();
-//        } else { // 目录
-//            FileUtils.delAllFile(fileEntity.getFileUrl());
-//        }
-//
-//        // 删除数据库记录
-//        fileRepository.deleteById(fileId);
-//
-//        return new R(200, MsgCode.SUCCESS);
-//    }
-//
-//    @Override
-//    public Integer getGeoData(HttpServletResponse response, String filePath) {
-//        // 判断文件是否存在
-//        filePath = OUTPUT_FILE_PATH + filePath;
-////        log.info("filePath: {}", filePath);
-//        File file = new File(filePath);
-//        if (!file.exists()) {
-////            log.info("文件不存在: {}", filePath);
-//            return null;
-//
-//        }
-//
-//        try {
-//            FileUtils.fileDownload(response, filePath);
-//        } catch (Exception e) {
-//            e.printStackTrace();
-//        }
-//        // 文件下载,不能有返回值
-//        return null;
-//    }
-//
-//    @Override
-//    public FileEntity findById(Long fileId) {
-//        Optional<FileEntity> o = fileRepository.findById(fileId);
-//        if (!o.isPresent()) {
-//            log.info("id:{} 不存在");
-//            return null;
-//        }
-//
-//        FileEntity entity = o.get();
-//        return entity;
-//    }
-//
-//    @Override
-//    public FileEntity save(FileEntity entity) {
-//        return fileRepository.save(entity);
-//    }
-//}

+ 1 - 1
src/main/java/com/fd/server/impl/ModelServerImpl.java

@@ -39,7 +39,7 @@ import java.util.Optional;
  */
 @Log4j2
 @Service
-public class ModelServerImpl implements ModelServer  {
+public class ModelServerImpl extends OutputFileServerImpl implements ModelServer  {
 
     @Value("${input.file.path.model}")
     private String INPUT_FILE_PATH;