|  | @ -3,7 +3,9 @@ package com.yihu.jw.hospital.endpoint.file_upload;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.fasterxml.jackson.databind.ObjectMapper;
 | 
	
		
			
				|  |  | import com.yihu.jw.file_upload.FileManageService;
 | 
	
		
			
				|  |  | import com.yihu.jw.file_upload.FileUploadService;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.MutilFileInfo;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.iot.common.UploadVO;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.ObjEnvelop;
 | 
	
		
			
				|  |  | import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
 | 
	
	
		
			
				|  | @ -11,17 +13,21 @@ import com.yihu.jw.rm.base.BaseRequestMapping;
 | 
	
		
			
				|  |  | import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  | import io.swagger.annotations.ApiParam;
 | 
	
		
			
				|  |  | import org.apache.commons.io.IOUtils;
 | 
	
		
			
				|  |  | import org.apache.commons.lang.StringUtils;
 | 
	
		
			
				|  |  | import org.slf4j.Logger;
 | 
	
		
			
				|  |  | import org.slf4j.LoggerFactory;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Value;
 | 
	
		
			
				|  |  | import org.springframework.mock.web.MockMultipartFile;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.PostMapping;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RequestMapping;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RequestParam;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RestController;
 | 
	
		
			
				|  |  | import org.springframework.web.multipart.MultipartFile;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.io.File;
 | 
	
		
			
				|  |  | import java.io.FileInputStream;
 | 
	
		
			
				|  |  | import java.io.InputStream;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -46,6 +52,8 @@ public class FileUploadEndpoint extends EnvelopRestEndpoint {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ObjectMapper objectMapper;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private FileManageService fileManageService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @PostMapping(value = BaseRequestMapping.FileUpload.UPLOAD_STREAM_IMG)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "文件流上传图片", notes = "文件流上传图片")
 | 
	
	
		
			
				|  | @ -120,6 +128,66 @@ public class FileUploadEndpoint extends EnvelopRestEndpoint {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return success("上传成功", uploadVO);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  |     @PostMapping(value = BaseRequestMapping.FileUpload.UPLOAD_STREAM_video)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "文件流上传文件", notes = "文件流上传文件")
 | 
	
		
			
				|  |  |     public ObjEnvelop<UploadVO> uploadStreamVideo(@ApiParam(value = "文件", required = true)
 | 
	
		
			
				|  |  |                                              @RequestParam(value = "file", required = true) MultipartFile file,
 | 
	
		
			
				|  |  |                                                   @ApiParam(value = "文件", required = false)
 | 
	
		
			
				|  |  |                                                   @RequestParam(value = "filename", required = false) String filename,
 | 
	
		
			
				|  |  |                                                   @ApiParam(value = "taskId", required = false)
 | 
	
		
			
				|  |  |                                                       @RequestParam(value = "taskId", required = false) String taskId,
 | 
	
		
			
				|  |  |                                                   @ApiParam(value = "chunk", required = false)
 | 
	
		
			
				|  |  |                                                       @RequestParam(value = "chunk", required = false) Integer chunk,
 | 
	
		
			
				|  |  |                                                   @ApiParam(value = "文件", required = false)
 | 
	
		
			
				|  |  |                                                       @RequestParam(value = "sizesize", required = false) Long size,
 | 
	
		
			
				|  |  |                                                   @ApiParam(value = "chunkTotal", required = false)
 | 
	
		
			
				|  |  |                                                       @RequestParam(value = "chunkTotal", required = false) Integer chunkTotal,
 | 
	
		
			
				|  |  |                                                   @ApiParam(value = "objectType", required = false)
 | 
	
		
			
				|  |  |                                                       @RequestParam(value = "objectType", required = false) Integer objectType
 | 
	
		
			
				|  |  |                                              ) throws Exception{
 | 
	
		
			
				|  |  |         UploadVO uploadVO = new UploadVO();
 | 
	
		
			
				|  |  |         MutilFileInfo files = new MutilFileInfo();
 | 
	
		
			
				|  |  |         files.setChunk(chunk);
 | 
	
		
			
				|  |  |         files.setChunkTotal(chunkTotal);
 | 
	
		
			
				|  |  |         files.setFile(file);
 | 
	
		
			
				|  |  |         files.setObjectType(objectType);
 | 
	
		
			
				|  |  |         files.setSize(file.getSize());
 | 
	
		
			
				|  |  |         files.setTaskId(taskId);
 | 
	
		
			
				|  |  |         String taskid = fileManageService.chunkUploadByMappedByteBuffer(files);
 | 
	
		
			
				|  |  |         if ("unCompelete".equalsIgnoreCase(taskid)){
 | 
	
		
			
				|  |  |             System.out.println("第"+files.getChunk());
 | 
	
		
			
				|  |  |             return success("未传完",uploadVO);
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             File file1 = new File(taskid);
 | 
	
		
			
				|  |  |             FileInputStream input = new FileInputStream(file1);
 | 
	
		
			
				|  |  |             MultipartFile multipartFile = new MockMultipartFile("file", file1.getName(), "text/plain", IOUtils.toByteArray(input));
 | 
	
		
			
				|  |  |             if (isClose.equalsIgnoreCase("1")){
 | 
	
		
			
				|  |  |                 Map<String, Object> map = fileUploadService.uploadImg(multipartFile);
 | 
	
		
			
				|  |  |                 uploadVO.setFullUri(map.get("accessory").toString());
 | 
	
		
			
				|  |  |             }else if(isClose.equals("2")){
 | 
	
		
			
				|  |  |                 //内网上传
 | 
	
		
			
				|  |  |                 String rs = fileUploadService.request(remote_inner_url,multipartFile,null);
 | 
	
		
			
				|  |  |                 logger.info(rs);
 | 
	
		
			
				|  |  |                 JSONObject json = JSON.parseObject(rs);
 | 
	
		
			
				|  |  |                 uploadVO = objectMapper.readValue(json.getJSONObject("obj").toJSONString(),UploadVO.class);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }else {
 | 
	
		
			
				|  |  |                 // 得到文件的完整名称  xxx.txt
 | 
	
		
			
				|  |  |                 String originalFilename = multipartFile.getOriginalFilename();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 //判断文件名称是否有包含后缀,及前端是否有传后缀名称,有的话拼接图片后缀
 | 
	
		
			
				|  |  |                 if(originalFilename.lastIndexOf(".") == 0 && StringUtils.isNotEmpty(filename)){
 | 
	
		
			
				|  |  |                     originalFilename = originalFilename +"."+filename;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 InputStream inputStream = multipartFile.getInputStream();
 | 
	
		
			
				|  |  |                 uploadVO = fileUploadService.uploadStream(inputStream,originalFilename,fastdfs_file_url);
 | 
	
		
			
				|  |  |                 file1.delete();
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             return success("上传成功", uploadVO);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @PostMapping(value = BaseRequestMapping.FileUpload.UPLOAD_STRING)
 | 
	
		
			
				|  |  |     @ApiOperation(value = "base64上传图片",notes = "base64上传图片")
 |