@ApiOperation(value = "上传人员照片", notes = "上传人员照片")
@PostMapping(value = "/uploadBasePersonPic")
public JsonResult<String> handleFileUpload(
@ApiParam(name = "file", value = "人员照片")
@RequestParam("file") MultipartFile file,
@ApiParam(name = "pPersonId", value = "人员id", required = true)
@RequestParam String pPersonId) {
logger.info("上传人员照片接口请求参数");
UserInfo info = this.getUserInfo();
//得到文件名
String fileName = file.getOriginalFilename();
//截取文件扩展名
String fileExtension = "";
fileExtension = fileName.substring(fileName.lastIndexOf('.')).toLowerCase();
//保存不更新图片
String imageType = ".jpg";
if (!imageType.equals(fileExtension)) {
String msg = "只能上传JPG格式的图片文件";
return JsonResult.get(HttpReturnEnums.ParaError, null, msg);
}
//上传文件 自动生成新的唯一文件名 路径前面追加日期 yyyyMMdd格式
String url=null;
try {
String fileKeyName = UploadPath.UPLOAD_PATH_PERSON_PIC + info.getDid() + "/" + fileName;
String filePrefixDateGenerateNewName = fileStrorage.putFileGenerateNewName(fileKeyName, file.getBytes());
url=fileStrorage.getFilePresignedUrl(filePrefixDateGenerateNewName,1*60*60*1000).toString();
basePersonService.updatePersonPic(info.getDid(),pPersonId,filePrefixDateGenerateNewName);
logger.info("fileKeyName:{}", fileKeyName);
logger.info("filePrefixDateGenerateNewName:{}", filePrefixDateGenerateNewName);
logger.info("url:{}", url);
} catch (IOException e) {
return JsonResult.get(HttpReturnEnums.ParaError, null, "上传图片服务器失败");
}
return JsonResult.get(url);
}