From 637d130f18d82b758dd999f2a02cd1047de528cd Mon Sep 17 00:00:00 2001 From: zhaoxiaohao <913652501@qq.com> Date: Sun, 02 Aug 2020 17:20:15 +0800 Subject: [PATCH] 修改上传接口,修改医院父类的默认值 --- kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java | 6 ++ kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-biz/src/main/java/com/kidgrow/filecenter/service/impl/AbstractIFileService.java | 110 ++++++++++++++++++++++++++++-------- kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/resources/application.yml | 2 kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/DictionariesConstants.java | 2 kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/CommonConstant.java | 4 kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java | 2 kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/resources/application.yml | 39 ++++++++---- 7 files changed, 121 insertions(+), 44 deletions(-) diff --git a/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-biz/src/main/java/com/kidgrow/filecenter/service/impl/AbstractIFileService.java b/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-biz/src/main/java/com/kidgrow/filecenter/service/impl/AbstractIFileService.java index eb8531c..1a547e3 100644 --- a/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-biz/src/main/java/com/kidgrow/filecenter/service/impl/AbstractIFileService.java +++ b/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-biz/src/main/java/com/kidgrow/filecenter/service/impl/AbstractIFileService.java @@ -19,12 +19,16 @@ import lombok.extern.slf4j.Slf4j; import net.coobird.thumbnailator.Thumbnails; import org.apache.commons.collections4.MapUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.multipart.MultipartFile; import sun.misc.BASE64Decoder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import sun.misc.BASE64Encoder; import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; import java.util.*; /** @@ -40,6 +44,8 @@ private static final String FILE_SPLIT = "."; private static Logger logger = LoggerFactory.getLogger(AbstractIFileService.class); + @Value("${kidgrow.file-server.oss.domain}") + private String DOMAIN; @Override public FileInfo upload(MultipartFile file) throws Exception { FileInfo fileInfo = FileUtil.getFileInfo(file); @@ -221,40 +227,94 @@ @Override public ResultBody baseDownLoad(Map<String, Object> map) throws Exception { - List<FileInfo> fileInfos = baseMapper.selectByMap(map); - if(fileInfos.size()>0){ - FileInfo fileInfo = fileInfos.get(0); - OSSObject down1 = this.down(fileInfo.getUrl().replace("https://kidgrow.oss-accelerate.aliyuncs.com/","")); - InputStream objectContent = down1.getObjectContent(); - //返回Base64编码过的字节数组字符串 - byte[] data = null; - // 读取图片字节数组 + String urlDiZhi=MapUtils.getString(map,"url"); + if(!urlDiZhi.contains(DOMAIN)){ + ByteArrayOutputStream outPut = new ByteArrayOutputStream(); + byte[] data = new byte[1024]; try { - ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); - byte[] buff = new byte[100]; - int rc = 0; - while ((rc = objectContent.read(buff, 0, 100)) > 0) { - swapStream.write(buff, 0, rc); + // 创建URL + URL url = new URL("http://192.168.2.25:8008/123/J-1.jpg"); + // 创建链接 + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + conn.setConnectTimeout(10 * 1000); + InputStream inStream = conn.getInputStream(); + int len = -1; + while ((len = inStream.read(data)) != -1) { + outPut.write(data, 0, len); } - data = swapStream.toByteArray(); + inStream.close(); } catch (IOException e) { e.printStackTrace(); - } finally { - if (objectContent != null) { - try { - objectContent.close(); - down1.close(); - } catch (IOException e) { - throw new Exception("输入流关闭异常"); + } + String substring = urlDiZhi.substring(urlDiZhi.lastIndexOf(".") + 1, urlDiZhi.length()); + String str="data:image/" + substring + ";base64,"; + // 对字节数组Base64编码 + BASE64Encoder encoder = new BASE64Encoder(); + System.out.println(encoder.encode(outPut.toByteArray())); + return ResultBody.ok().data(str+encoder.encode(outPut.toByteArray()).replaceAll("\n", "").replaceAll("\r", "")); + }else { + List<FileInfo> fileInfos = baseMapper.selectByMap(map); + if (fileInfos.size() > 0) { + FileInfo fileInfo = fileInfos.get(0); + OSSObject down = this.down(fileInfo.getUrl().replace(DOMAIN, "")); + InputStream objectContent = down.getObjectContent(); + //返回Base64编码过的字节数组字符串 + byte[] data = null; + // 读取图片字节数组 + try { + ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); + byte[] buff = new byte[100]; + int rc = 0; + while ((rc = objectContent.read(buff, 0, 100)) > 0) { + swapStream.write(buff, 0, rc); + } + data = swapStream.toByteArray(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (objectContent != null) { + try { + objectContent.close(); + down.close(); + } catch (IOException e) { + throw new Exception("输入流关闭异常"); + } } } + String encode = "data:" + fileInfo.getContentType() + ";base64," + Base64.getEncoder().encodeToString(data); + return ResultBody.ok().data(encode); + } else { + return ResultBody.failed("获取数据失败"); } - String encode="data:"+fileInfo.getContentType()+";base64,"+Base64.getEncoder().encodeToString(data); - return ResultBody.ok().data(encode); - }else { - return ResultBody.failed("获取数据失败"); } } + public static void main(String[] args) { + + ByteArrayOutputStream outPut = new ByteArrayOutputStream(); + byte[] data = new byte[1024]; + try { + // 创建URL + URL url = new URL("http://192.168.2.25:8008/123/J-1.jpg"); + // 创建链接 + HttpURLConnection conn = (HttpURLConnection) url.openConnection(); + conn.setRequestMethod("GET"); + conn.setConnectTimeout(10 * 1000); + InputStream inStream = conn.getInputStream(); + int len = -1; + while ((len = inStream.read(data)) != -1) { + outPut.write(data, 0, len); + } + inStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + // 对字节数组Base64编码 + BASE64Encoder encoder = new BASE64Encoder(); + System.out.println(encoder.encode(outPut.toByteArray())); + + } + } diff --git a/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java b/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java index 3bf53b8..4341125 100644 --- a/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java +++ b/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/java/com/kidgrow/filecenter/controller/FileController.java @@ -5,6 +5,8 @@ import com.kidgrow.common.model.ResultBody; import com.kidgrow.filecenter.model.FileInfo; import com.kidgrow.filecenter.service.IFileService; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -74,6 +76,10 @@ */ @PostMapping(value="baseDownLoad") public ResultBody baseDownLoad(@RequestBody Map<String,Object> map) throws Exception{ + String url = MapUtils.getString(map, "url"); + if (StringUtils.isBlank(url)) { + return ResultBody.failed("请输入地址"); + } return fileService.baseDownLoad(map); } diff --git a/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/resources/application.yml b/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/resources/application.yml index 4e54fca..9ce6fd3 100644 --- a/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/resources/application.yml +++ b/kidgrow-business/kidgrow-filecenter/kidgrow-filecenter-server/src/main/resources/application.yml @@ -13,7 +13,7 @@ url: jdbc:mysql://${kidgrow.datasource.ip}:3306/file_center?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai username: ${kidgrow.datasource.username} password: ${kidgrow.datasource.password} -# driver-class-name: com.mysql.jdbc.Driver + # driver-class-name: com.mysql.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource druid: aop-patterns: com.kidgrow.filecenter.controller.* @@ -38,30 +38,41 @@ kidgrow: -# fdfs: -# web-url: 192.168.28.130 -# trackerList: ${kidgrow.fdfs.web-url}:22122 + # fdfs: + # web-url: 192.168.28.130 + # trackerList: ${kidgrow.fdfs.web-url}:22122 file-server: type: aliyun fdfs: web-url: ${kidgrow.fdfs.web-url} #oss配置 oss: -# access-key: j977Ii3DODvQXzE241Z6ouW9so4Q6_6PeOPwN5UZ -# accessKeySecret: W8ArRp3mr-w3n4R-lHEvSFzGdgdrYfC9wHkZlqec -# endpoint: http://q68nl7reu.bkt.clouddn.com + # access-key: j977Ii3DODvQXzE241Z6ouW9so4Q6_6PeOPwN5UZ + # accessKeySecret: W8ArRp3mr-w3n4R-lHEvSFzGdgdrYfC9wHkZlqec + # endpoint: http://q68nl7reu.bkt.clouddn.com + # bucketName: kidgrow + # domain: kidgrow.s3-cn-east-1.qiniucs.com + +# access-key: LTAI4GG27Q85eTB5YvVKZAyg +# accessKeySecret: thEEFtCxYTPQGrHl0KmUUBXr7gWKdh +## endpoint: kidgrow.oss-cn-beijing-internal.aliyuncs.com +# endpoint: 123.kidgrow.cloud +## endpoint: oss-accelerate.aliyuncs.com # bucketName: kidgrow -# domain: kidgrow.s3-cn-east-1.qiniucs.com +# #注意加上/ +# domain: http://123.kidgrow.cloud/ +## domain: https://kidgrow.oss-accelerate.aliyuncs.com/ +# folder: kidgrow/ access-key: LTAI4FennfcwZupz3B6hkK3N accessKeySecret: NzBBGe8SS41qJlp0nA3tlJ3t74lBZM -# endpoint: oss-accelerate.aliyuncs.com - endpoint: kidgrow.oss-cn-beijing-internal.aliyuncs.com + # endpoint: kidgrow.oss-cn-beijing-internal.aliyuncs.com + endpoint: 123.kidgrow.cloud + # endpoint: oss-accelerate.aliyuncs.com bucketName: kidgrow - #注意加上/ http://123.kidgrow.cloud - domain: / + #注意加上/ + domain: http://123.kidgrow.cloud/ + # domain: https://kidgrow.oss-accelerate.aliyuncs.com/ folder: kidgrow/ - #oss内网访问的地址 -# neiwang: kidgrow.oss-cn-beijing-internal.aliyuncs.com swagger: base-package: com.kidgrow.filecenter.controller diff --git a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java index ad9770f..c470c14 100644 --- a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java +++ b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-biz/src/main/java/com/kidgrow/usercenter/service/impl/SysDoctorServiceImpl.java @@ -207,7 +207,7 @@ sysUser.setNickname(sysDoctor.getHospitalName()); sysUser.setHeadImgUrl(sysDoctor.getDoctorLogo()); sysUser.setMobile(sysDoctor.getDoctorTel()); - sysUser.setType(CommonConstant.H_DOCTOR); + sysUser.setType(UserType.DOCTOR.name()); sysUser.setTenantId(CommonConstant.H_TENANT); sysUser.setCreateTime(new Date()); SysUser byId = iSysUserService.getById(id); diff --git a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/resources/application.yml b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/resources/application.yml index 944f1a9..b482f49 100644 --- a/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/resources/application.yml +++ b/kidgrow-business/kidgrow-usercenter/kidgrow-usercenter-server/src/main/resources/application.yml @@ -10,7 +10,7 @@ application: name: usercenter-server datasource: - url: jdbc:mysql://${kidgrow.datasource.ip}:3306/user_center?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai + url: jdbc:mysql://${kidgrow.datasource.ip}:3306/user_center_default?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai username: ${kidgrow.datasource.username} password: ${kidgrow.datasource.password} # driver-class-name: com.mysql.jdbc.Driver diff --git a/kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/CommonConstant.java b/kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/CommonConstant.java index a17380d..9a8defc 100644 --- a/kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/CommonConstant.java +++ b/kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/CommonConstant.java @@ -250,8 +250,8 @@ /** * 生成缩略图需要的图片暂存目录 */ -// public static final String TEMP_IMAGE_PATH="D:/resources/images/"; - public static final String TEMP_IMAGE_PATH="/root/data"; + public static final String TEMP_IMAGE_PATH="D:/resources/images/"; +// public static final String TEMP_IMAGE_PATH="/root/kidgrow"; /** * 普通医生角色ID */ diff --git a/kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/DictionariesConstants.java b/kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/DictionariesConstants.java index 0c6607a..eb89414 100644 --- a/kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/DictionariesConstants.java +++ b/kidgrow-commons/kidgrow-common-spring-boot-starter/src/main/java/com/kidgrow/common/constant/DictionariesConstants.java @@ -28,5 +28,5 @@ /** * 最高组织ID */ - Long ORG_PARENT_ID=1L; + Long ORG_PARENT_ID=15321234561L; } -- Gitblit v1.8.0