From a722fc15c47e2e41f558f14bd2ed2c85ef02ada0 Mon Sep 17 00:00:00 2001 From: niujiyi <18272501226@163.com> Date: Tue, 2 Jun 2026 18:37:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=A7=E6=B3=95=E7=AB=AF-=E4=BF=AE=E6=94=B9b?= =?UTF-8?q?ug=E5=BB=BA=E8=AE=A1=E5=88=92=E6=8F=90=E7=A4=BA=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E4=BA=86=EF=BC=8C=E4=BD=86=E6=98=AF=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=AE=A1=E5=88=92=E9=A1=B5=E9=9D=A2=E8=BF=98=E6=98=AF=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=87=BA=E6=9D=A5=E4=BA=86=EF=BC=8C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=81=9A=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...forcementInspectionProgramServiceImpl.java | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/service/impl/EnforcementInspectionProgramServiceImpl.java b/zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/service/impl/EnforcementInspectionProgramServiceImpl.java index bb98d114..c15ae2ea 100644 --- a/zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/service/impl/EnforcementInspectionProgramServiceImpl.java +++ b/zdxt-modules/zdxt-enforcement-code/src/main/java/com/zdxt/enforcementcode/service/impl/EnforcementInspectionProgramServiceImpl.java @@ -15,7 +15,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.dromara.common.satoken.utils.LoginHelper; +import org.dromara.common.translation.annotation.Translation; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import com.zdxt.enforcementcode.domain.bo.EnforcementInspectionProgramBo; import com.zdxt.enforcementcode.domain.vo.EnforcementInspectionProgramVo; import com.zdxt.enforcementcode.domain.EnforcementInspectionProgram; @@ -269,14 +271,22 @@ public class EnforcementInspectionProgramServiceImpl implements IEnforcementInsp * @return 是否新增成功 */ @Override + @Transactional(rollbackFor = Exception.class) public Boolean insertByBo(EnforcementInspectionProgramBo bo) { + Long userId = LoginHelper.getUserId(); + String username = LoginHelper.getUsername(); + + if (userId == null) { + throw new IllegalArgumentException("用户未登录或登录已过期"); + } + EnforcementInspectionProgram add = MapstructUtils.convert(bo, EnforcementInspectionProgram.class); add.setCreateTime(DateUtils.getNowDate()); add.setId(IdUtil.simpleUUID()); - add.setUserId(LoginHelper.getUserId() +""); + add.setUserId(userId.toString()); add.setDeptId(LoginHelper.getDeptId()); - add.setCreateBy(LoginHelper.getUserId()); - add.setCreateByName(LoginHelper.getUsername()); + add.setCreateBy(userId); + add.setCreateByName(username); validEntityBeforeSave(add); boolean flag = baseMapper.insert(add) > 0; if (flag && bo.getFileList() != null && !bo.getFileList().isEmpty()) { @@ -285,25 +295,26 @@ public class EnforcementInspectionProgramServiceImpl implements IEnforcementInsp ZdxtFile zdxtFile = new ZdxtFile(); zdxtFile.setGuid(IdUtil.simpleUUID()); zdxtFile.setBusinessId(add.getId()); - zdxtFile.setUploadPath(file.getUploadPath()); + + String uploadPath = file.getUploadPath(); + if (StringUtils.isBlank(uploadPath)) { + throw new IllegalArgumentException("文件上传路径不能为空"); + } + zdxtFile.setUploadPath(uploadPath); zdxtFile.setFileName(file.getFileName()); // 从文件路径中截取文件名称 - String fileUrl = file.getUploadPath(); String fileSaveName = null; - if (fileUrl != null && !fileUrl.isEmpty()) { - // 处理 URL 路径或文件路径 - int lastSlashIndex = Math.max(fileUrl.lastIndexOf("/"), fileUrl.lastIndexOf("\\")); - if (lastSlashIndex != -1 && lastSlashIndex < fileUrl.length() - 1) { - fileSaveName = fileUrl.substring(lastSlashIndex + 1); - } else { - fileSaveName = fileUrl; - } - // 去除 URL 参数(如果有) - int questionMarkIndex = fileSaveName.indexOf("?"); - if (questionMarkIndex != -1) { - fileSaveName = fileSaveName.substring(0, questionMarkIndex); - } + int lastSlashIndex = Math.max(uploadPath.lastIndexOf("/"), uploadPath.lastIndexOf("\\")); + if (lastSlashIndex != -1 && lastSlashIndex < uploadPath.length() - 1) { + fileSaveName = uploadPath.substring(lastSlashIndex + 1); + } else { + fileSaveName = uploadPath; + } + // 去除 URL 参数(如果有) + int questionMarkIndex = fileSaveName.indexOf("?"); + if (questionMarkIndex != -1) { + fileSaveName = fileSaveName.substring(0, questionMarkIndex); } zdxtFile.setFileSaveName(fileSaveName); @@ -316,11 +327,11 @@ public class EnforcementInspectionProgramServiceImpl implements IEnforcementInsp } // 设置上传人信息 - zdxtFile.setUploadPersonId(LoginHelper.getUserId().toString()); - zdxtFile.setUploadPersonName(LoginHelper.getUsername()); + zdxtFile.setUploadPersonId(userId.toString()); + zdxtFile.setUploadPersonName(username); zdxtFile.setUploadTime(DateUtils.getNowDate()); - zdxtFile.setCreateBy(LoginHelper.getUserId()); - zdxtFile.setUpdateBy(LoginHelper.getUserId()); + zdxtFile.setCreateBy(userId); + zdxtFile.setUpdateBy(userId); zdxtFile.setCreateTime(DateUtils.getNowDate()); zdxtFile.setUpdateTime(DateUtils.getNowDate());