From d95cf290f93206d8eb103dfd51b34d5af0dee36a Mon Sep 17 00:00:00 2001 From: "382696293@qq.com" <382696293@qq.com> Date: Mon, 29 Jan 2024 14:56:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=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 | 2 +- .../resources/mapper/WxClockLogMapper.xml | 2 +- .../controller/WxClockLogController.java | 31 ++++++++++++++----- 3 files changed, 26 insertions(+), 9 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 30c1eeb..b7d625d 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 @@ -24,7 +24,7 @@ public class WxClockLogReq { /** * 打卡照片 */ - List clockImageList; + List clockImageList = new ArrayList<>(); public String getClockContent() { return clockContent; diff --git a/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockLogMapper.xml b/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockLogMapper.xml index e2dcbd1..7d77db9 100644 --- a/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockLogMapper.xml +++ b/flossom-common/flossom-common-core/src/main/resources/mapper/WxClockLogMapper.xml @@ -19,7 +19,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select id, user_id, instrument_id, instrument_name, clock_content, status, create_by, create_time from wx_clock_log - select count(1) from wx_clock_log where user_id = #{userId} 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 5aafa50..e68f45a 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 @@ -8,6 +8,7 @@ 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.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -59,36 +60,52 @@ public class WxClockLogController extends BaseController { @RequestParam(value = "secondClockImg") MultipartFile secondClockImg, @RequestParam(value = "thirdClockImg") MultipartFile thirdClockImg, @Validated WxClockLogReq wxClockLogReq) { - wxClockLogReq.setClockImageList(new ArrayList<>()); - if (firstClockImg != null) { + if (firstClockImg != null && StringUtils.isNotBlank(firstClockImg.getOriginalFilename())) { R result = remoteFileService.upload(firstClockImg); if (result.getCode() != Constants.SUCCESS) { logger.error("上传打卡图片失败"); throw new ServiceException("上传打卡图片失败"); } - wxClockLogReq.getClockImageList().add(result.getData().getUrl()); + if (wxClockLogReq.getClockImageList() != null && wxClockLogReq.getClockImageList().size() > 0) { + wxClockLogReq.getClockImageList().set(0, result.getData().getUrl()); + } else { + wxClockLogReq.getClockImageList().add(result.getData().getUrl()); + } } - if (secondClockImg != null) { + if (secondClockImg != null && StringUtils.isNotBlank(secondClockImg.getOriginalFilename())) { R result = remoteFileService.upload(secondClockImg); if (result.getCode() != Constants.SUCCESS) { logger.error("上传打卡图片失败"); throw new ServiceException("上传打卡图片失败"); } - wxClockLogReq.getClockImageList().add(result.getData().getUrl()); + if (wxClockLogReq.getClockImageList() != null && wxClockLogReq.getClockImageList().size() > 1) { + wxClockLogReq.getClockImageList().set(1, result.getData().getUrl()); + } else { + wxClockLogReq.getClockImageList().add(result.getData().getUrl()); + } } - if (thirdClockImg != null) { + if (thirdClockImg != null && StringUtils.isNotBlank(thirdClockImg.getOriginalFilename())) { 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() > 2 + && StringUtils.isNotBlank(wxClockLogReq.getClockImageList().get(2))) { + wxClockLogReq.getClockImageList().set(2, result.getData().getUrl()); + } else { + wxClockLogReq.getClockImageList().add(result.getData().getUrl()); + } } if (wxClockLogReq.getClockImageList() == null || wxClockLogReq.getClockImageList().size() == 0) { logger.error("请上传打卡图片"); throw new ServiceException("请上传打卡图片"); } + if (wxClockLogReq.getClockImageList().size() > 3) { + logger.error("打卡图片只能上传3张以下"); + throw new ServiceException("打卡图片只能上传3张以下"); + } wxClockLogService.insertWxClockLog(wxClockLogReq); return R.ok(); }