|
|
@@ -1,52 +1,51 @@
|
|
|
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.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
import cn.hutool.core.lang.tree.Tree;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
-import jakarta.validation.constraints.*;
|
|
|
-import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import jakarta.validation.constraints.NotEmpty;
|
|
|
+import jakarta.validation.constraints.NotNull;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.dromara.backstage.cardCenter.domain.bo.PtCardBo;
|
|
|
import org.dromara.backstage.cardCenter.domain.vo.PtCardVo;
|
|
|
import org.dromara.backstage.cardCenter.service.IPtCardService;
|
|
|
import org.dromara.backstage.payment.domain.bo.PtBagBo;
|
|
|
+import org.dromara.backstage.payment.domain.bo.PtUserAccountBo;
|
|
|
import org.dromara.backstage.payment.domain.vo.PtBagVo;
|
|
|
import org.dromara.backstage.payment.domain.vo.PtUserAccount4SelectVo;
|
|
|
import org.dromara.backstage.payment.domain.vo.PtUserAccountInfoVo;
|
|
|
+import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
|
import org.dromara.backstage.payment.service.IPtBagService;
|
|
|
-import org.dromara.common.core.utils.StreamUtils;
|
|
|
+import org.dromara.backstage.payment.service.IPtUserAccountService;
|
|
|
+import org.dromara.common.core.domain.R;
|
|
|
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;
|
|
|
-import org.dromara.common.log.annotation.Log;
|
|
|
-import org.dromara.common.web.core.BaseController;
|
|
|
-import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
-import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.core.validate.AddGroup;
|
|
|
import org.dromara.common.core.validate.EditGroup;
|
|
|
-import org.dromara.common.log.enums.BusinessType;
|
|
|
import org.dromara.common.excel.utils.ExcelUtil;
|
|
|
-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.idempotent.annotation.RepeatSubmit;
|
|
|
+import org.dromara.common.log.annotation.Log;
|
|
|
+import org.dromara.common.log.enums.BusinessType;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.web.core.BaseController;
|
|
|
+import org.dromara.system.api.RemoteDeptService;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
/**
|
|
|
* 一卡通账户
|
|
|
* 前端访问路由地址为:/payment/ptUserAccount
|
|
|
@@ -67,9 +66,9 @@ public class PtUserAccountController extends BaseController {
|
|
|
@DubboReference
|
|
|
private final RemoteDeptService remoteDeptService;
|
|
|
|
|
|
- @Value("${upload.upload-path}/")
|
|
|
+ @Value("${upload.upload-path}/") // 文件上传路径
|
|
|
private String uploadPath;
|
|
|
- @Value("${upload.image.user}/")
|
|
|
+ @Value("${upload.image.user}/") // 用户头像路径
|
|
|
private String userPath;
|
|
|
|
|
|
/**
|
|
|
@@ -147,37 +146,23 @@ public class PtUserAccountController extends BaseController {
|
|
|
@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,
|
|
|
+ @PostMapping(value = "/photoUpload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
+ public R<String> photoUpload(@RequestPart("file") MultipartFile file,
|
|
|
@RequestParam("userId") Long userId) throws IOException {
|
|
|
if (!file.isEmpty()) {
|
|
|
- String extension = FileUtil.extName(file.getOriginalFilename());
|
|
|
+ String extension = FileUtils.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));
|
|
|
+ //1. 拼接文件完整路径
|
|
|
+ String path = uploadPath + userPath;
|
|
|
+ String newFileName = UUID.randomUUID() + "." + extension;
|
|
|
+ //2. 保存照片
|
|
|
+ FileUtils.upload(file, path, newFileName);
|
|
|
|
|
|
//4.保存图片路径到数据库
|
|
|
- String photoUrl = userPath + formatDate + newFileName;
|
|
|
+ String photoUrl = userPath + newFileName;
|
|
|
ptUserAccountService.updateByBo(PtUserAccountBo.builder().userId(userId).photo(photoUrl).build());
|
|
|
|
|
|
return R.ok("上传图片成功");
|
|
|
@@ -185,6 +170,15 @@ public class PtUserAccountController extends BaseController {
|
|
|
return R.fail("上传图片异常,请联系管理员");
|
|
|
}
|
|
|
|
|
|
+ @SaCheckPermission("payment:ptUserAccount:edit")
|
|
|
+ @Log(title = "一卡通账户", businessType = BusinessType.UPDATE)
|
|
|
+ @RepeatSubmit()
|
|
|
+ @PostMapping(value = "/photoBatchUpload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
+ public R<String> photoBatchUpload(@RequestPart("file") MultipartFile[] files) throws IOException {
|
|
|
+ int okNum = ptUserAccountService.photoBatchUpload(files, uploadPath, userPath);
|
|
|
+ return R.ok("上传图片成功数量: "+ okNum);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 删除一卡通账户
|
|
|
*
|