From 1e1f62274473b9168ea19d38fe70fbc16d455df0 Mon Sep 17 00:00:00 2001 From: gongzhenkun <1658878546@qq.com> Date: Fri, 19 Aug 2022 11:52:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BB=E7=94=9F=E6=89=A7=E7=85=A7=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=9C=B0=E5=9D=80=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/api/AppController.java | 28 ++----------------- .../ruoyi/common/utils/file/FileUtils.java | 26 +++++++++++++++++ .../web/service/SysLoginService.java | 3 +- .../service/impl/WechatServiceImpl.java | 3 +- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java index 94c88c2..d64a149 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/AppController.java @@ -419,7 +419,7 @@ public class AppController extends BaseController tImage.setThirdId(recordId); tImage.setCreateTime(new Date()); tImage.setName(name); - String path=GenerateImage(value,name); + String path=FileUtils.GenerateImage(value,name); tImage.setPath(path); imageService.insertTImage(tImage); } @@ -465,7 +465,7 @@ public class AppController extends BaseController { String imageKey=keys[i]; String imgStr=parents.get(i).getJSONObject(imageKey).getString("v"); - String path=GenerateImage(imgStr,imageKey); + String path=FileUtils.GenerateImage(imgStr,imageKey); parents.get(i).getJSONObject(keys[i]).put("v",null); TImage tImage = new TImage(); tImage.setName(imageKey); @@ -494,28 +494,4 @@ public class AppController extends BaseController return jsonObject; } - - public static String GenerateImage(String imgStr,String imageName) - { - - BASE64Decoder decoder = new BASE64Decoder(); - try - { - //Base64解码 - byte[] b = decoder.decodeBuffer(imgStr); - for (int i = 0; i < b.length; ++i) - { - if (b[i] < 0) - { - b[i] += 256; - } - } - return FileUtils.writeImportBytes(b); - - } - catch (Exception e) - { - throw new ServiceException(imageName + " :Base64转图片错误"); - } - } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java index f844270..2421c6c 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUtils.java @@ -11,6 +11,8 @@ import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + +import com.ruoyi.common.exception.ServiceException; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.ArrayUtils; import com.ruoyi.common.config.RuoYiConfig; @@ -18,6 +20,7 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.uuid.IdUtils; import org.apache.commons.io.FilenameUtils; +import sun.misc.BASE64Decoder; /** * 文件处理工具类 @@ -290,4 +293,27 @@ public class FileUtils return baseName; } + public static String GenerateImage(String imgStr,String imageName) + { + + BASE64Decoder decoder = new BASE64Decoder(); + try + { + //Base64解码 + byte[] b = decoder.decodeBuffer(imgStr); + for (int i = 0; i < b.length; ++i) + { + if (b[i] < 0) + { + b[i] += 256; + } + } + return FileUtils.writeImportBytes(b); + + } + catch (Exception e) + { + throw new ServiceException(imageName + " :Base64转图片错误"); + } + } } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index b8e4154..a94ed69 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -7,6 +7,7 @@ import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.enums.UserStatus; import com.ruoyi.common.utils.*; import com.ruoyi.common.utils.file.FileUploadUtils; +import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.system.domain.TDoctor; import com.ruoyi.system.domain.req.AppRegisterReq; import com.ruoyi.system.mapper.TDoctorMapper; @@ -150,7 +151,7 @@ public class SysLoginService public AjaxResult loginForAppFillInfo(AppRegisterReq req) { if (StringUtils.isNotEmpty(req.getMedicalLicense())) { log.info("MedicalLicense is not null."); - req.setMedicalLicense(FileUploadUtils.generateImage(req.getMedicalLicense(), uploadFilePath)); + req.setMedicalLicense(FileUtils.GenerateImage(req.getMedicalLicense(), "医生执照")); } log.info("login for app fill info req :{}", req); // 查询sys_user数据 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java index b467451..288fbc3 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/WechatServiceImpl.java @@ -7,6 +7,7 @@ import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.file.FileUploadUtils; +import com.ruoyi.common.utils.file.FileUtils; import com.ruoyi.common.utils.http.HttpUtils; import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.common.utils.wechat.WechatKeys; @@ -151,7 +152,7 @@ public class WechatServiceImpl implements IWechatService { // 查询手机号是否存在医生信息 TDoctor tDoctor = new TDoctor(); if (StringUtils.isNotEmpty(req.getMedicalLicense())) { - req.setMedicalLicense(FileUploadUtils.generateImage(req.getMedicalLicense(), uploadFilePath)); + req.setMedicalLicense(FileUtils.GenerateImage(req.getMedicalLicense(), "医生执照")); } BeanUtils.copyProperties(req, tDoctor); TDoctor currentDoctor = tDoctorMapper.selectTDoctorByPhone(req.getPhone());