From b703a9c6b5c952c3a90f7ac86253499956dec294 Mon Sep 17 00:00:00 2001 From: "382696293@qq.com" <382696293@qq.com> Date: Mon, 29 Jan 2024 13:34:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=89=93=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/domain/req/WxClockLogReq.java | 3 +- .../controller/WxClockLogController.java | 47 +++++++++++++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/req/WxClockLogReq.java b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/req/WxClockLogReq.java index d1a7da7..30c1eeb 100644 --- a/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/req/WxClockLogReq.java +++ b/flossom-common/flossom-common-core/src/main/java/com/flossom/common/core/domain/req/WxClockLogReq.java @@ -3,6 +3,7 @@ package com.flossom.common.core.domain.req; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; +import java.util.ArrayList; import java.util.List; /** @@ -23,8 +24,6 @@ public class WxClockLogReq { /** * 打卡照片 */ - @NotNull(message = "请上传打卡图片") - @Size(min = 1, max = 3, message = "打卡图片数限制在3张以内") List clockImageList; public String getClockContent() { diff --git a/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/controller/WxClockLogController.java b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/controller/WxClockLogController.java index 75dbf22..a6c7c80 100644 --- a/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/controller/WxClockLogController.java +++ b/flossom-modules/flossom-mini-program/src/main/java/com/flossom/miniProgram/controller/WxClockLogController.java @@ -1,14 +1,20 @@ package com.flossom.miniProgram.controller; +import com.flossom.common.core.constant.Constants; import com.flossom.common.core.domain.R; +import com.flossom.common.core.domain.SysFile; import com.flossom.common.core.domain.req.WxClockLogReq; +import com.flossom.common.core.exception.ServiceException; import com.flossom.common.core.web.controller.BaseController; import com.flossom.miniProgram.service.IWxClockLogService; +import com.flossom.system.api.RemoteFileService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.validation.constraints.NotNull; +import java.util.ArrayList; /** * 用户打卡Controller @@ -23,6 +29,9 @@ public class WxClockLogController extends BaseController { @Autowired private IWxClockLogService wxClockLogService; + @Autowired + private RemoteFileService remoteFileService; + /** * 添加用户使用仪器记录表 */ @@ -35,14 +44,46 @@ public class WxClockLogController extends BaseController { /** * 新增用户打卡 * 需要记录当天使用过的全部仪器(打卡前后的全部仪器) + * firstClockImg 第一张图片是必须的 */ @PostMapping("/insertClockLog") - public R insertClockLog(@Validated @RequestBody WxClockLogReq wxClockLogReq) { + public R insertClockLog(@RequestParam(value = "firstClockImg") MultipartFile firstClockImg, + @RequestParam(value = "secondClockImg", required = false) MultipartFile secondClockImg, + @RequestParam(value = "thirdClockImg", required = false) MultipartFile thirdClockImg, + @Validated WxClockLogReq wxClockLogReq) { + wxClockLogReq.setClockImageList(new ArrayList<>()); + if (firstClockImg != null) { + R result = remoteFileService.upload(firstClockImg); + if (result.getCode() != Constants.SUCCESS) { + logger.error("上传打卡图片失败"); + throw new ServiceException("上传打卡图片失败"); + } + wxClockLogReq.getClockImageList().add(result.getData().getUrl()); + } + if (secondClockImg != null) { + R result = remoteFileService.upload(secondClockImg); + if (result.getCode() != Constants.SUCCESS) { + logger.error("上传打卡图片失败"); + throw new ServiceException("上传打卡图片失败"); + } + wxClockLogReq.getClockImageList().add(result.getData().getUrl()); + } + if (thirdClockImg != null) { + R result = remoteFileService.upload(thirdClockImg); + if (result.getCode() != Constants.SUCCESS) { + logger.error("上传打卡图片失败"); + throw new ServiceException("上传打卡图片失败"); + } + wxClockLogReq.getClockImageList().add(result.getData().getUrl()); + } + + if (wxClockLogReq.getClockImageList() == null || wxClockLogReq.getClockImageList().size() == 0) { + logger.error("请上传打卡图片"); + throw new ServiceException("请上传打卡图片"); + } wxClockLogService.insertWxClockLog(wxClockLogReq); return R.ok(); } - - }