|
|
@@ -1,7 +1,13 @@
|
|
|
package org.dromara.backstage.payment.controller;
|
|
|
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
@@ -17,8 +23,13 @@ import org.dromara.backstage.payment.domain.vo.PtUserAccount4SelectVo;
|
|
|
import org.dromara.backstage.payment.domain.vo.PtUserAccountInfoVo;
|
|
|
import org.dromara.backstage.payment.service.IPtBagService;
|
|
|
import org.dromara.common.core.utils.StreamUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.core.utils.file.FileUtils;
|
|
|
+import org.dromara.common.core.utils.file.MimeTypeUtils;
|
|
|
import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
import org.dromara.system.api.RemoteDeptService;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
|
|
@@ -34,6 +45,7 @@ import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
|
import org.dromara.backstage.payment.domain.bo.PtUserAccountBo;
|
|
|
import org.dromara.backstage.payment.service.IPtUserAccountService;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
|
* 一卡通账户
|
|
|
@@ -54,6 +66,21 @@ public class PtUserAccountController extends BaseController {
|
|
|
|
|
|
@DubboReference
|
|
|
private final RemoteDeptService remoteDeptService;
|
|
|
+
|
|
|
+ @Value("${upload.upload-path}/")
|
|
|
+ private String uploadPath;
|
|
|
+ @Value("${upload.image.user}/")
|
|
|
+ private String userPath;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日期路径格式
|
|
|
+ */
|
|
|
+ private final String datePathFormat = "yyyy/MM/dd/";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日期格式
|
|
|
+ */
|
|
|
+ private final SimpleDateFormat sdf = new SimpleDateFormat(datePathFormat);
|
|
|
/**
|
|
|
* 查询一卡通账户列表
|
|
|
*/
|
|
|
@@ -114,6 +141,50 @@ public class PtUserAccountController extends BaseController {
|
|
|
return toAjax(ptUserAccountService.updateByBo(bo));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 上传人脸照片
|
|
|
+ */
|
|
|
+ @SaCheckPermission("payment:ptUserAccount:edit")
|
|
|
+ @Log(title = "一卡通账户", businessType = BusinessType.UPDATE)
|
|
|
+ @RepeatSubmit()
|
|
|
+ @PostMapping(value = "/avatar", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
+ public R<String> avatar(@RequestPart("file") MultipartFile file,
|
|
|
+ @RequestParam("userId") Long userId) throws IOException {
|
|
|
+ if (!file.isEmpty()) {
|
|
|
+ String extension = FileUtil.extName(file.getOriginalFilename());
|
|
|
+ if (!StringUtils.equalsAnyIgnoreCase(extension, MimeTypeUtils.IMAGE_EXTENSION)) {
|
|
|
+ return R.fail("文件格式不正确,请上传" + Arrays.toString(MimeTypeUtils.IMAGE_EXTENSION) + "格式");
|
|
|
+ }
|
|
|
+ //1.获取日期字符串
|
|
|
+ String formatDate = sdf.format(new Date());
|
|
|
+
|
|
|
+ //2.获取新文件名
|
|
|
+ String newFileName = FileUtils.getNewFileName(file.getOriginalFilename());
|
|
|
+
|
|
|
+ //3.保存图片
|
|
|
+
|
|
|
+ //3.1 判断文件夹是否存在,不存在则创建
|
|
|
+ String imageDirPath = uploadPath + userPath + formatDate;
|
|
|
+ File imageDir = new File(imageDirPath);
|
|
|
+ if (!imageDir.exists()){
|
|
|
+ imageDir.mkdirs();
|
|
|
+ }
|
|
|
+
|
|
|
+ //3.2 拼接文件完整路径
|
|
|
+ String imageFilePath = imageDirPath + newFileName;
|
|
|
+
|
|
|
+ //3.3 保存照片
|
|
|
+ file.transferTo(new File(imageDir.getAbsoluteFile(), newFileName));
|
|
|
+
|
|
|
+ //4.保存图片路径到数据库
|
|
|
+ String photoUrl = userPath + formatDate + newFileName;
|
|
|
+ ptUserAccountService.updateByBo(PtUserAccountBo.builder().userId(userId).photo(photoUrl).build());
|
|
|
+
|
|
|
+ return R.ok("上传图片成功");
|
|
|
+ }
|
|
|
+ return R.fail("上传图片异常,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 删除一卡通账户
|
|
|
*
|