whycrzg
2021-03-30 cb6beb6c390d4dc68617fef6b7ddb356dab1dbf9
src/main/java/com/whyc/controller/ProjectManageController.java
@@ -1,24 +1,24 @@
package com.whyc.controller;
import com.whyc.config.MyProps;
import com.whyc.dto.Response;
import com.whyc.pojo.ProjectArchiveManage;
import com.whyc.pojo.ProjectManage;
import com.whyc.service.ProjectArchiveManageService;
import com.whyc.service.ProjectProcessManageService;
import com.whyc.util.FileUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.*;
/**
@@ -28,6 +28,9 @@
@RequestMapping("projectManage")
@Api(tags = "项目管理")
public class ProjectManageController {
    @Autowired
    private MyProps myProps;
    @Autowired
    private ProjectProcessManageService service;
@@ -98,7 +101,7 @@
        // 获取后缀名
        // String suffixName = fileName.substring(fileName.lastIndexOf("."));
        // 文件保存路径、后期考虑按日期或者月份建dir
        String filePath = "c:/upload/";
        String filePath = myProps.getFilePath();
        // 文件重命名,防止重复,预览时需要显示原文件名 _ 切割
        String fileName = filePath + UUID.randomUUID() + "_" + originalFilename;
        // 文件对象
@@ -127,6 +130,45 @@
        response.setData(map);
        return response;
    }
    @PostMapping("/uploads")
    @ApiOperation(notes = "返回文件地址,确认时提交保存到字段", value = "文档材料添加(多选)")
    public Response uploads(MultipartFile[] files) throws IOException {
        Response<Object> response = new Response<>();
        if (files.length == 0) {
            return response.setMsg(0, "请选择要上传的文件");
        }
        ArrayList<Object> list = new ArrayList<>();
        for (MultipartFile multipartFile : files) {
            if (multipartFile.isEmpty()) {
                return response.setMsg(0, "请选择要上传的文件");
            }
            byte[] fileBytes = multipartFile.getBytes();
            String filePath = myProps.getFilePath();
            //取得当前上传文件的文件名称
            String originalFilename = multipartFile.getOriginalFilename();
            //生成文件名
            String fileName = UUID.randomUUID() + "_" + originalFilename;
            HashMap<Object, Object> map = new HashMap<>();
            try {
                FileUtils.uploadFile(fileBytes, filePath, fileName);
            } catch (IOException e) {
                e.printStackTrace();
                return response.setMsg(0, "上传失败");
            }
            map.put("原文件名:", originalFilename);
            map.put("文件地址:", filePath + fileName);
            list.add(map);
        }
        response.setData(list);
        return response.setMsg(1, "上传成功");
    }
    @GetMapping("/download")
    @ApiOperation(notes = "需要在地址栏测试",value = "文档材料下载")
@@ -310,48 +352,7 @@
    /**
     * 文件上传
     * achievement_name 成果类型
     */
/*
    @RequestMapping("/upload")
    public Response upload(MultipartFile file) {
        try {
            if (file != null) {
                File parentFile = createParentFile();
                String fileName = file.getOriginalFilename();
                String suffix = fileName.substring(fileName.lastIndexOf("."));
                String uuid = IdUtil.simpleUUID();
                fileName = uuid + suffix;
                File imageFile = new File(parentFile, fileName);
                FileUtil.writeFromStream(file.getInputStream(), imageFile);
                */
/**
                 * 年月日目录
                 *//*
                String fileDay = DateUtil.thisYear() + "/" + (DateUtil.thisMonth() + 1) + "/"
                        + DateUtil.thisDayOfMonth();
                String imagePath = SystemConstant.FILE + "/document/" + fileDay + "/" + fileName;
                */
/**
                 * 实时转换
                 *//*
                File toFile = new File(parentFile, uuid + ".pdf");
                documentConverter.convert(imageFile).to(toFile).execute();
                return Result.ok(imagePath);
            } else {
                return Result.error();
            }
        } catch (Exception e) {
            LOGGER.error("转换异常{}",e);
            return Result.error();
        }
    }
*/
}