gaoaoy
2024-03-06 90400afc2e72950229506fa76d474c25b6c8eed3
cnas-server/src/main/java/com/yuanchu/mom/controller/DeviceController.java
@@ -14,9 +14,7 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -28,6 +26,7 @@
@RestController
@RequestMapping("/deviceScope")
public class DeviceController {
    private DeviceService deviceService;
@@ -80,31 +79,32 @@
    //图片上传
    @ApiOperation(value = "图片上传")
    @RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
    public Result uploadFile(MultipartFile file, HttpServletRequest request) throws IOException {
        //获取文件名称
        HashMap<String, String> list = new HashMap<>();
    @PostMapping("/uploadFile")
    public Result uploadFile(MultipartFile file) {
        System.out.println(file.getOriginalFilename());
        String urlString = null;
        String pathName = null;
        String filename = file.getOriginalFilename();
        String s = filename.substring(filename.lastIndexOf("."), filename.length());
        System.out.println(filename);
        //获取真实路径
        String realPath = request.getServletContext().getRealPath("/Users/gaoaoy/webapp/images");
        //创建文件
        File file1 = new File(realPath);
        if (!file1.exists()) {
            file1.mkdirs();
        try {
            String path = "/Users/gaoaoy/webapp/images";
            File realpath = new File(path);
            if (!realpath.exists()) {
                realpath.mkdirs();
            }
            pathName = UUID.randomUUID() + "_" + file.getOriginalFilename();
            urlString = realpath + "/" + pathName;
            file.transferTo(new File(urlString));
            System.out.println(pathName);
            HashMap<String, String> map = new HashMap<>();
            map.put("name", filename);
            map.put("url", pathName);
            return Result.success(map);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("图片上传错误");
            return null;
        }
        file.transferTo(new File(file1 + "/" + filename));
        String ss= filename;
        UUID uuid = UUID.randomUUID();
        ss = uuid.toString() + s;
        String ful = "/Users/gaoaoy/webapp/images" + ss;
        System.out.println(file1);
        list.put("url", ful);
        list.put("name", filename);
        return Result.success(list);
    }
    @ApiOperation(value = "获取设备负责人")