diff --git a/pom.xml b/pom.xml index aa02efe..6540014 100644 --- a/pom.xml +++ b/pom.xml @@ -196,6 +196,18 @@ bcprov-jdk15to18 1.66 + + + commons-io + commons-io + 2.15.1 + + + + org.apache.commons + commons-lang3 + 3.12.0 + @@ -235,7 +247,9 @@ ${docker.username} ${docker.password} - ${docker.registry.url}/${docker.namespace}/${project.build.finalName} + + ${docker.registry.url}/${docker.namespace}/${project.build.finalName} + ${project.version} true diff --git a/src/main/java/org/springblade/modules/system/controller/DeptHospitalController.java b/src/main/java/org/springblade/modules/system/controller/DeptHospitalController.java index edeb489..960293d 100644 --- a/src/main/java/org/springblade/modules/system/controller/DeptHospitalController.java +++ b/src/main/java/org/springblade/modules/system/controller/DeptHospitalController.java @@ -19,8 +19,15 @@ package org.springblade.modules.system.controller; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import io.minio.GetObjectArgs; +import io.minio.MinioClient; +import io.minio.ObjectArgs; +import io.minio.ObjectReadArgs; +import io.minio.errors.*; import io.swagger.annotations.*; import lombok.AllArgsConstructor; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springblade.common.cache.DictCache; import org.springblade.common.cache.UserCache; import org.springblade.common.constant.BusinessConstant; @@ -29,6 +36,8 @@ import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.cache.utils.CacheUtil; import org.springblade.core.launch.constant.AppConstant; import org.springblade.core.mp.support.Condition; +import org.springblade.core.oss.MinioTemplate; +import org.springblade.core.oss.OssTemplate; import org.springblade.core.secure.BladeUser; import org.springblade.core.secure.annotation.PreAuth; import org.springblade.core.secure.constant.AuthConstant; @@ -38,6 +47,8 @@ import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.constant.RoleConstant; import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.modules.resource.builder.oss.OssBuilder; import org.springblade.modules.system.entity.Dept; import org.springblade.modules.system.entity.User; import org.springblade.modules.system.service.IDeptService; @@ -46,7 +57,16 @@ import org.springblade.modules.system.wrapper.DeptWrapper; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; +import javax.annotation.Resource; import javax.validation.Valid; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; +import java.util.Base64; import java.util.List; import java.util.Map; @@ -59,24 +79,97 @@ import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE; */ @NonDS @RestController -@AllArgsConstructor @RequestMapping(AppConstant.APPLICATION_SYSTEM_NAME + "/dept-hospital") @Api(value = "部门", tags = "部门") public class DeptHospitalController extends BladeController { - private final IDeptService deptService; + /** + * minio config + */ + private static final String endpoint = "http://127.0.0.1:9090"; + /** + * minio config + */ + private static final String accessKey = "sCBy0KAcufwBzqXL"; + /** + * minio config + */ + private static final String secretKey = "zgiZQbVrpOwwLyXLxKMGEl5XOYso65WX"; + /** + * minio config + */ + private static final String bucketName = "hcu-cgs"; - /** - * 列表-医院 - */ - @GetMapping("/list-hospital") - @ApiOperationSupport(order = 9) - @ApiOperation(value = "列表-医院", notes = "列表-医院") - public R> listHospital() { - List list = deptService.list(Wrappers.lambdaQuery() - .eq(Dept::getDeptCategory, BusinessConstant.DEPT_CATEGORY_HOSPITAL) - .orderByAsc(Dept::getSort)); - return R.data(DeptWrapper.build().listNodeVO(list)); - } + @Resource + private IDeptService deptService; + /** + * Access Key: + * sCBy0KAcufwBzqXL + * Secret Key: + * zgiZQbVrpOwwLyXLxKMGEl5XOYso65WX + */ + private MinioClient minioClient; + + /** + * 列表-医院 + */ + @GetMapping("/list-hospital") + @ApiOperationSupport(order = 9) + @ApiOperation(value = "列表-医院", notes = "列表-医院") + public R> listHospital() { + List list = deptService.list(Wrappers.lambdaQuery() + .eq(Dept::getDeptCategory, BusinessConstant.DEPT_CATEGORY_HOSPITAL) + .orderByAsc(Dept::getSort)); + List listVo = DeptWrapper.build().listNodeVO(list); + for (DeptVO vo : listVo) { + if (StringUtil.isNotBlank(vo.getImgUrl())) { + // minio + // String domain = "http://www.qdscgs.com:9091"; + // String domain = "http://127.0.0.1:9091"; + String imgUrl = vo.getImgUrl(); + // 替换/hcu-cgs/前缀 + if (StringUtils.isNotBlank(imgUrl) && + StringUtils.startsWith(imgUrl, "/hcu-cgs/")) { + imgUrl = StringUtils.removeStart(imgUrl, "/hcu-cgs/"); + } + vo.setImgBase64(convertImgToBase64(imgUrl)); + } + } + return R.data(listVo); + } + + /** + * 对图片进行base64编码。 + * + * @param imageUrl bucket中文件地址 + * @return + */ + private String convertImgToBase64(final String imageUrl) { + if (minioClient == null) { + minioClient = MinioClient.builder() + .endpoint(endpoint) + .credentials(accessKey, secretKey) + .build(); + } + InputStream in = null; + try { + in = minioClient.getObject( + GetObjectArgs.builder().bucket(bucketName).object(imageUrl).build() + ); + byte[] imageBytes = IOUtils.toByteArray(in); + Base64.Encoder encoder = Base64.getEncoder(); + return encoder.encodeToString(imageBytes); + } catch (IOException | ServerException | InsufficientDataException | + ErrorResponseException | NoSuchAlgorithmException | InvalidKeyException | + InvalidResponseException | XmlParserException | InternalException e) { + throw new RuntimeException(e); + } finally { + try { + IOUtils.close(in); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } } diff --git a/src/main/java/org/springblade/modules/system/vo/DeptVO.java b/src/main/java/org/springblade/modules/system/vo/DeptVO.java index dd451d5..5503620 100644 --- a/src/main/java/org/springblade/modules/system/vo/DeptVO.java +++ b/src/main/java/org/springblade/modules/system/vo/DeptVO.java @@ -37,48 +37,52 @@ import java.util.List; @EqualsAndHashCode(callSuper = true) @ApiModel(value = "DeptVO对象", description = "DeptVO对象") public class DeptVO extends Dept implements INode { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - /** - * 主键ID - */ - @JsonSerialize(using = ToStringSerializer.class) - private Long id; + /** + * 主键ID + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long id; - /** - * 父节点ID - */ - @JsonSerialize(using = ToStringSerializer.class) - private Long parentId; + /** + * 父节点ID + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long parentId; - /** - * 子孙节点 - */ - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private List children; + /** + * 子孙节点 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children; - /** - * 是否有子孙节点 - */ - @JsonInclude(JsonInclude.Include.NON_EMPTY) - private Boolean hasChildren; + /** + * 是否有子孙节点 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private Boolean hasChildren; - @Override - public List getChildren() { - if (this.children == null) { - this.children = new ArrayList<>(); - } - return this.children; - } + @Override + public List getChildren() { + if (this.children == null) { + this.children = new ArrayList<>(); + } + return this.children; + } - /** - * 上级机构 - */ - private String parentName; + /** + * 上级机构 + */ + private String parentName; - /** - * 机构类型名称 - */ - private String deptCategoryName; + /** + * 机构类型名称 + */ + private String deptCategoryName; + /** + * 医院图标图片 + */ + private String imgBase64; }