小程序头像上传
This commit is contained in:
parent
5adc8f6770
commit
cdbf4e2034
@ -0,0 +1,69 @@
|
|||||||
|
package com.xinelu.applet.controller.uploadfile;
|
||||||
|
|
||||||
|
import com.xinelu.applet.service.uploadfile.IUploadFileService;
|
||||||
|
import com.xinelu.common.constant.Constants;
|
||||||
|
import com.xinelu.common.core.domain.AjaxResult;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
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 javax.annotation.Resource;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ljh
|
||||||
|
* @version 1.0
|
||||||
|
* Create by 2022/11/2 10:38
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/nurseApplet/uploadFile")
|
||||||
|
public class UploadFileController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IUploadFileService uploadFileService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员App头像图片上传
|
||||||
|
*
|
||||||
|
* @param patientId 会员主键id
|
||||||
|
* @param multipartFile 文件
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/uploadHeadPictureUrl")
|
||||||
|
public AjaxResult uploadHeadPictureUrl(@RequestParam("file") MultipartFile multipartFile, @RequestParam(value = "patientId") Long patientId) throws Exception {
|
||||||
|
if (Objects.isNull(patientId)) {
|
||||||
|
return AjaxResult.error("会员头像信息不能为空!");
|
||||||
|
}
|
||||||
|
if (Objects.isNull(multipartFile) || StringUtils.isBlank(multipartFile.getOriginalFilename())) {
|
||||||
|
return AjaxResult.error("当前文件视频不存在,无法上传!");
|
||||||
|
}
|
||||||
|
if (multipartFile.getOriginalFilename().contains(Constants.EMPTY)) {
|
||||||
|
return AjaxResult.error("当前视频文件名含有空格,请先去除空格在上传!");
|
||||||
|
}
|
||||||
|
return uploadFileService.uploadHeadPictureUrl(multipartFile, patientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 护理员App确认任务完成图片上传
|
||||||
|
*
|
||||||
|
* @param orderNo 编号
|
||||||
|
* @param multipartFile 文件
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@PostMapping("/uploadPictureUrl")
|
||||||
|
public AjaxResult uploadPictureUrl(@RequestParam("file") MultipartFile multipartFile, @RequestParam(value = "orderNo") String orderNo) throws Exception {
|
||||||
|
if (StringUtils.isBlank(orderNo)) {
|
||||||
|
return AjaxResult.error("订单信息不能为空!");
|
||||||
|
}
|
||||||
|
if (Objects.isNull(multipartFile) || StringUtils.isBlank(multipartFile.getOriginalFilename())) {
|
||||||
|
return AjaxResult.error("当前文件不存在,无法上传!");
|
||||||
|
}
|
||||||
|
if (multipartFile.getOriginalFilename().contains(Constants.EMPTY)) {
|
||||||
|
return AjaxResult.error("当前文件名含有空格,请先去除空格在上传!");
|
||||||
|
}
|
||||||
|
return uploadFileService.uploadPictureUrl(multipartFile, orderNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,32 @@
|
|||||||
|
package com.xinelu.applet.service.uploadfile;
|
||||||
|
|
||||||
|
import com.xinelu.common.core.domain.AjaxResult;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description APP和小程序头像图片上传方法
|
||||||
|
* @Author zh
|
||||||
|
* @Date 2022-11-2
|
||||||
|
*/
|
||||||
|
public interface IUploadFileService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员App头像图片上传
|
||||||
|
*
|
||||||
|
* @param patientId 会员主键id
|
||||||
|
* @param multipartFile 文件
|
||||||
|
* @return 结果
|
||||||
|
* @throws Exception 异常信息
|
||||||
|
*/
|
||||||
|
AjaxResult uploadHeadPictureUrl(MultipartFile multipartFile, Long patientId) throws Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 护理员App确认任务完成图片上传
|
||||||
|
*
|
||||||
|
* @param orderNo 订单编号
|
||||||
|
* @param multipartFile 文件
|
||||||
|
* @return 结果
|
||||||
|
* @throws Exception 异常信息
|
||||||
|
**/
|
||||||
|
AjaxResult uploadPictureUrl(MultipartFile multipartFile, String orderNo) throws Exception;
|
||||||
|
}
|
||||||
@ -0,0 +1,70 @@
|
|||||||
|
package com.xinelu.applet.service.uploadfile.Impl;
|
||||||
|
|
||||||
|
import com.xinelu.applet.service.uploadfile.IUploadFileService;
|
||||||
|
import com.xinelu.common.config.XinELuConfig;
|
||||||
|
import com.xinelu.common.core.domain.AjaxResult;
|
||||||
|
import com.xinelu.common.exception.ServiceException;
|
||||||
|
import com.xinelu.common.utils.file.FileUploadUtils;
|
||||||
|
import com.xinelu.common.utils.file.MimeTypeUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description 头像上传
|
||||||
|
* @Author ZH
|
||||||
|
* @Date 2022-10-28
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class UploadFileServiceImpl implements IUploadFileService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private XinELuConfig xinELuConfig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员App头像图片上传
|
||||||
|
*
|
||||||
|
* @param patientId 会员主键id
|
||||||
|
* @param multipartFile 文件
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AjaxResult uploadHeadPictureUrl(MultipartFile multipartFile, Long patientId) throws Exception {
|
||||||
|
//获取路径名称
|
||||||
|
String uploadPathUrl = XinELuConfig.getProfile() + xinELuConfig.getHeadPictureUrl() + "/" + patientId;
|
||||||
|
//上传图片
|
||||||
|
String pictureName = FileUploadUtils.uploadPictureUrlPath(uploadPathUrl, multipartFile, MimeTypeUtils.IMAGE_EXTENSION);
|
||||||
|
if (StringUtils.isBlank(pictureName)) {
|
||||||
|
throw new ServiceException("头像上传失败,请联系管理员!");
|
||||||
|
}
|
||||||
|
//获取返回值
|
||||||
|
AjaxResult ajax = AjaxResult.success("上传成功!");
|
||||||
|
ajax.put("imgUrl", pictureName);
|
||||||
|
return ajax;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 护理员App确认任务完成图片上传
|
||||||
|
*
|
||||||
|
* @param orderNo 订单编号
|
||||||
|
* @param multipartFile 文件
|
||||||
|
* @return 结果
|
||||||
|
* @throws Exception 异常信息
|
||||||
|
**/
|
||||||
|
@Override
|
||||||
|
public AjaxResult uploadPictureUrl(MultipartFile multipartFile, String orderNo) throws Exception {
|
||||||
|
//获取路径名称
|
||||||
|
String uploadPathUrl = XinELuConfig.getProfile() + xinELuConfig.getAppointmentOrderDetailsUrl() + "/" + orderNo;
|
||||||
|
//上传图片
|
||||||
|
String pictureName = FileUploadUtils.uploadPictureUrlPath(uploadPathUrl, multipartFile, MimeTypeUtils.IMAGE_EXTENSION);
|
||||||
|
if (StringUtils.isBlank(pictureName)) {
|
||||||
|
throw new ServiceException("图片上传失败,请联系管理员!");
|
||||||
|
}
|
||||||
|
//获取返回值
|
||||||
|
AjaxResult ajax = AjaxResult.success("上传成功!");
|
||||||
|
ajax.put("imgUrl", pictureName);
|
||||||
|
return ajax;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user