diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index d85600a..162496b 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -9,7 +9,7 @@ ruoyi: # 实例演示开关 demoEnabled: true # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath) - profile: D:/ruoyi/uploadPath/tongue + profile: C:/ruoyi/uploadPath/tongue/ # 获取ip地址开关 addressEnabled: false # 验证码类型 math 数组计算 char 字符验证 diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java index 23b4cf1..62be0fc 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/file/FileUploadUtils.java @@ -1,10 +1,16 @@ package com.ruoyi.common.utils.file; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStream; import java.nio.file.Paths; +import java.util.Base64; import java.util.Objects; +import java.util.UUID; + import org.apache.commons.io.FilenameUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.multipart.MultipartFile; import com.ruoyi.common.config.RuoYiConfig; import com.ruoyi.common.constant.Constants; @@ -15,6 +21,8 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.uuid.Seq; +import javax.servlet.http.HttpServletRequest; + /** * 文件上传工具类 * @@ -230,4 +238,32 @@ public class FileUploadUtils } return extension; } + + public static String generateImage(String file, String uploadFilePath) { + // 解密 + try { + // 图片分类路径+图片名+图片后缀 + String imgClassPath = UUID.randomUUID().toString().concat(".jpg"); + // 解密 + Base64.Decoder decoder = Base64.getDecoder(); + // 去掉base64前缀 data:image/jpeg;base64, + file = file.substring(file.indexOf(",", 1) + 1, file.length()); + byte[] b = decoder.decode(file); + // 处理数据 + for (int i = 0; i < b.length; ++i) { + if (b[i] < 0) { + b[i] += 256; + } + } + // 保存图片 + OutputStream out = new FileOutputStream(uploadFilePath.concat(imgClassPath)); + out.write(b); + out.flush(); + out.close(); + // 返回图片的相对路径 = 图片分类路径+图片名+图片后缀 + return imgClassPath; + } catch (IOException e) { + return null; + } + } } 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 2c9f3de..75fa379 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 @@ -5,6 +5,7 @@ import javax.annotation.Resource; 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.system.domain.TDoctor; import com.ruoyi.system.domain.req.AppRegisterReq; import com.ruoyi.system.mapper.TDoctorMapper; @@ -12,6 +13,7 @@ import com.ruoyi.system.service.impl.UserTokenService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -44,6 +46,9 @@ import java.util.Objects; public class SysLoginService { private static final Logger log = LoggerFactory.getLogger(SysLoginService.class); + + @Value("${ruoyi.profile}") + private String uploadFilePath; @Autowired private TokenService tokenService; @@ -141,6 +146,9 @@ public class SysLoginService } public AjaxResult loginForAppFillInfo(AppRegisterReq req) { + if (StringUtils.isNotEmpty(req.getMedicalLicense())) { + req.setMedicalLicense(FileUploadUtils.generateImage(req.getMedicalLicense(), uploadFilePath)); + } // 查询sys_user数据 SysUser sysUser = userService.selectUserByPhone(req.getPhone()); if (Objects.nonNull(sysUser)) { 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 095e50f..3719712 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 @@ -6,6 +6,7 @@ import com.ruoyi.common.core.domain.model.LoginUser; 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.http.HttpUtils; import com.ruoyi.common.utils.ip.IpUtils; import com.ruoyi.common.utils.wechat.WechatKeys; @@ -55,6 +56,9 @@ public class WechatServiceImpl implements IWechatService { @Value("${wx.wechatSecret}") private String wechatSecret; + @Value("${ruoyi.profile}") + private String uploadFilePath; + @Resource private TWechatUserMapper tWechatUserMapper; @@ -144,6 +148,9 @@ public class WechatServiceImpl implements IWechatService { public String loginForApp(LoginForAppReq req) { // 查询手机号是否存在医生信息 TDoctor tDoctor = new TDoctor(); + if (StringUtils.isNotEmpty(req.getMedicalLicense())) { + req.setMedicalLicense(FileUploadUtils.generateImage(req.getMedicalLicense(), uploadFilePath)); + } BeanUtils.copyProperties(req, tDoctor); TDoctor currentDoctor = tDoctorMapper.selectTDoctorByPhone(req.getPhone()); TWechatUser wechatUser = new TWechatUser();