26 changed files with 776 additions and 28 deletions
@ -0,0 +1,106 @@ |
|||||
|
package com.epmet.cloud; |
||||
|
|
||||
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
||||
|
import com.epmet.commons.tools.exception.EpmetException; |
||||
|
import com.epmet.commons.tools.exception.ExceptionUtils; |
||||
|
import io.minio.MinioClient; |
||||
|
import io.minio.ObjectWriteResponse; |
||||
|
import io.minio.PutObjectArgs; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.http.MediaType; |
||||
|
import org.springframework.http.MediaTypeFactory; |
||||
|
|
||||
|
import java.io.ByteArrayInputStream; |
||||
|
import java.io.IOException; |
||||
|
import java.io.InputStream; |
||||
|
import java.nio.file.Paths; |
||||
|
|
||||
|
/** |
||||
|
* minio 文件服务 |
||||
|
*/ |
||||
|
@Slf4j |
||||
|
public class MinioStorageService extends AbstractCloudStorageService { |
||||
|
|
||||
|
private MinioClient minioClient; |
||||
|
|
||||
|
public MinioStorageService(CloudStorageConfig config) { |
||||
|
this.config = config; |
||||
|
|
||||
|
CloudStorageConfig.MinioStorageConfigProps props = config.getMinio().getConfigByPrivacy(null); |
||||
|
|
||||
|
log.info("Minio客户端连接所用的域名:{}", props.getMinioInternalDomain()); |
||||
|
|
||||
|
/** |
||||
|
* minio和服务在同一个局域网,则可以使用内网域名上传,速度更快更稳定 |
||||
|
*/ |
||||
|
minioClient = MinioClient.builder() |
||||
|
.endpoint(props.getMinioInternalDomain()) // 保证和nginx的proxy_set_header Host 一致
|
||||
|
.credentials(props.getMinioAccessKey(), props.getMinioSecretKey()) |
||||
|
.build(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getOssDomain(String privacy) { |
||||
|
return this.config.getMinio().getConfigByPrivacy(privacy).getMinioExternalDomain(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String getOssPrefix(String privacy) { |
||||
|
return this.config.getMinio().getConfigByPrivacy(privacy).getMinioPrefix(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String upload(byte[] data, String path, String privacyType) { |
||||
|
return upload(new ByteArrayInputStream(data), path, privacyType); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String uploadSuffix(byte[] data, String suffix, String privacyType) { |
||||
|
return uploadSuffix(new ByteArrayInputStream(data), suffix, privacyType); |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 此处bucket已经做为path |
||||
|
* @param inputStream 字节流 |
||||
|
* @param path 文件路径,包含文件名 |
||||
|
* @param privacyType |
||||
|
* @return |
||||
|
*/ |
||||
|
@Override |
||||
|
public String upload(InputStream inputStream, String path, String privacyType) { |
||||
|
CloudStorageConfig.MinioStorageConfigProps props = this.config.getMinio().getConfigByPrivacy(privacyType); |
||||
|
String contentType = MediaTypeFactory.getMediaType(path).orElse(MediaType.APPLICATION_OCTET_STREAM).toString(); |
||||
|
try { |
||||
|
ObjectWriteResponse resp = minioClient.putObject(PutObjectArgs.builder() |
||||
|
.bucket(props.getMinioBucketName()) |
||||
|
.object(path) |
||||
|
.stream(inputStream, inputStream.available(), -1) |
||||
|
.contentType(contentType) |
||||
|
.build()); |
||||
|
|
||||
|
log.debug("minio上传文件成功。bucket:{}, object:{}, privacyType:{}", resp.bucket(), resp.object(), privacyType); |
||||
|
|
||||
|
// 返回值要存储到数据库,供用户访问,因此使用外网域名
|
||||
|
return props.getMinioExternalDomain() + "/" + Paths.get(resp.bucket()).resolve(resp.object()).toString(); |
||||
|
} catch (Exception e) { |
||||
|
String errorMsg = ExceptionUtils.getErrorStackTrace(e); |
||||
|
throw new EpmetException(EpmetErrorCode.SERVER_ERROR.getCode(), errorMsg); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public String uploadSuffix(InputStream inputStream, String suffix, String privacyType) { |
||||
|
CloudStorageConfig.MinioStorageConfigProps props = this.config.getMinio().getConfigByPrivacy(privacyType); |
||||
|
return upload(inputStream, getPath(props.getMinioPrefix(), suffix, privacyType), privacyType); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public void down(String privacyType) throws IOException { |
||||
|
|
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean delete(String objectName, String privacyType) { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
package com.epmet.dto; |
||||
|
|
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Description |
||||
|
* @Author yzm |
||||
|
* @Date 2023/3/2 13:52 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class TagScopeDTO implements Serializable { |
||||
|
/** |
||||
|
* 标签ID |
||||
|
*/ |
||||
|
private String tagId; |
||||
|
|
||||
|
/** |
||||
|
* 应用范围,这里只能是社区id |
||||
|
*/ |
||||
|
private String agencyId; |
||||
|
/** |
||||
|
* agency_id全路径,包含自身 |
||||
|
*/ |
||||
|
private String orgIdPath; |
||||
|
|
||||
|
/** |
||||
|
* 组织名称 |
||||
|
*/ |
||||
|
private String agencyName; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,56 @@ |
|||||
|
package com.epmet.dto.form; |
||||
|
|
||||
|
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; |
||||
|
import com.epmet.dto.TagScopeDTO; |
||||
|
import lombok.Data; |
||||
|
import org.hibernate.validator.constraints.Length; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import java.io.Serializable; |
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @Description |
||||
|
* @Author yzm |
||||
|
* @Date 2023/3/2 12:47 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class TagCustomerFormDTO implements Serializable { |
||||
|
private static final long serialVersionUID = -5631868409077026783L; |
||||
|
|
||||
|
public interface AddUserInternalGroup { |
||||
|
} |
||||
|
|
||||
|
public interface AddUserShowGroup extends CustomerClientShowGroup { |
||||
|
} |
||||
|
|
||||
|
public interface UpdateUserInternalGroup { |
||||
|
} |
||||
|
|
||||
|
public interface UpdateUserShowGroup extends CustomerClientShowGroup { |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 主键ID |
||||
|
*/ |
||||
|
@NotBlank(message = "id不能为空", groups = {UpdateUserInternalGroup.class}) |
||||
|
private String id; |
||||
|
|
||||
|
/** |
||||
|
* 标签名称 |
||||
|
*/ |
||||
|
@Length(max = 30, message = "标签名称最多输入30字", groups = {AddUserShowGroup.class, UpdateUserShowGroup.class}) |
||||
|
@NotBlank(message = "标签名称不能为空", groups = {AddUserShowGroup.class, UpdateUserShowGroup.class}) |
||||
|
private String tagName; |
||||
|
|
||||
|
/** |
||||
|
* 应用范围,只能选社区 |
||||
|
*/ |
||||
|
private List<TagScopeDTO> agencyIds; |
||||
|
/** |
||||
|
* 客户ID |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,44 @@ |
|||||
|
package com.epmet.dto.form; |
||||
|
|
||||
|
import com.epmet.commons.tools.validator.group.CustomerClientShowGroup; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
import javax.validation.constraints.NotNull; |
||||
|
import java.io.Serializable; |
||||
|
|
||||
|
/** |
||||
|
* @Description pc标签管理-分页查询入参 |
||||
|
* @Author yzm |
||||
|
* @Date 2023/3/2 11:34 |
||||
|
*/ |
||||
|
@Data |
||||
|
public class TagCustomerPageFormDTO implements Serializable { |
||||
|
private static final long serialVersionUID = -2311491158902019019L; |
||||
|
|
||||
|
public interface PageUserInternalGroup { |
||||
|
} |
||||
|
|
||||
|
public interface PageUserShowGroup extends CustomerClientShowGroup { |
||||
|
} |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* 客户ID |
||||
|
*/ |
||||
|
@NotBlank(message = "customerId不能为空", groups = PageUserInternalGroup.class) |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 标签名称 |
||||
|
*/ |
||||
|
private String tagName; |
||||
|
|
||||
|
|
||||
|
@NotNull(message = "页码不能为空", groups = PageUserInternalGroup.class) |
||||
|
private Integer pageNo; |
||||
|
|
||||
|
@NotNull(message = "每页数量不能为空", groups = PageUserInternalGroup.class) |
||||
|
private Integer pageSize; |
||||
|
} |
||||
|
|
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.epmet.dao; |
||||
|
|
||||
|
import com.epmet.commons.mybatis.dao.BaseDao; |
||||
|
import com.epmet.entity.TagScopeEntity; |
||||
|
import org.apache.ibatis.annotations.Mapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
|
||||
|
/** |
||||
|
* 标签应用范围表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2023-03-02 |
||||
|
*/ |
||||
|
@Mapper |
||||
|
public interface TagScopeDao extends BaseDao<TagScopeEntity> { |
||||
|
|
||||
|
int deleteByTagId(@Param("tagId") String tagId, @Param("customerId") String customerId); |
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
package com.epmet.entity; |
||||
|
|
||||
|
import com.baomidou.mybatisplus.annotation.TableName; |
||||
|
import com.epmet.commons.mybatis.entity.BaseEpmetEntity; |
||||
|
import lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
|
||||
|
/** |
||||
|
* 标签应用范围表 |
||||
|
* |
||||
|
* @author generator generator@elink-cn.com |
||||
|
* @since v1.0.0 2023-03-02 |
||||
|
*/ |
||||
|
@Data |
||||
|
@EqualsAndHashCode(callSuper=false) |
||||
|
@TableName("tag_scope") |
||||
|
public class TagScopeEntity extends BaseEpmetEntity { |
||||
|
|
||||
|
private static final long serialVersionUID = 1L; |
||||
|
|
||||
|
/** |
||||
|
* 客户ID(0302因烟台需求增加此表) |
||||
|
*/ |
||||
|
private String customerId; |
||||
|
|
||||
|
/** |
||||
|
* 标签ID |
||||
|
*/ |
||||
|
private String tagId; |
||||
|
|
||||
|
/** |
||||
|
* 应用范围,这里只能是社区id |
||||
|
*/ |
||||
|
private String agencyId; |
||||
|
|
||||
|
/** |
||||
|
* agency_id全路径,包含自身 |
||||
|
*/ |
||||
|
private String orgIdPath; |
||||
|
|
||||
|
/** |
||||
|
* 组织名称 |
||||
|
*/ |
||||
|
private String agencyName; |
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
alter table tag_customer add COLUMN SHOW_FLAG TINYINT(1) DEFAULT 1 comment '1:展示;0:隐藏;0302因烟台需求增加此列默认1' after USE_COUNT; |
||||
|
|
||||
|
CREATE TABLE `tag_scope` ( |
||||
|
`ID` varchar(64) NOT NULL COMMENT '主键(0302因烟台需求增加此表)', |
||||
|
`CUSTOMER_ID` varchar(64) NOT NULL COMMENT '客户ID(0302因烟台需求增加此表)', |
||||
|
`TAG_ID` varchar(64) NOT NULL COMMENT '标签ID', |
||||
|
`AGENCY_ID` varchar(64) NOT NULL COMMENT '应用范围,这里只能是社区id', |
||||
|
`ORG_ID_PATH` varchar(255) NOT NULL COMMENT 'agency_id全路径,包含自身', |
||||
|
`AGENCY_NAME` varchar(255) NOT NULL COMMENT '组织名称', |
||||
|
`DEL_FLAG` int(11) NOT NULL DEFAULT '0' COMMENT '删除标识 0.未删除 1.已删除', |
||||
|
`REVISION` int(11) NOT NULL COMMENT '乐观锁', |
||||
|
`CREATED_BY` varchar(32) NOT NULL COMMENT '创建人', |
||||
|
`CREATED_TIME` datetime NOT NULL COMMENT '创建时间', |
||||
|
`UPDATED_BY` varchar(32) NOT NULL COMMENT '更新人', |
||||
|
`UPDATED_TIME` datetime NOT NULL COMMENT '更新时间', |
||||
|
PRIMARY KEY (`ID`) |
||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='标签应用范围表'; |
||||
|
|
||||
|
|
||||
@ -0,0 +1,24 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
||||
|
|
||||
|
<mapper namespace="com.epmet.dao.TagScopeDao"> |
||||
|
|
||||
|
<resultMap type="com.epmet.entity.TagScopeEntity" id="tagScopeMap"> |
||||
|
<result property="id" column="ID"/> |
||||
|
<result property="customerId" column="CUSTOMER_ID"/> |
||||
|
<result property="tagId" column="TAG_ID"/> |
||||
|
<result property="agencyId" column="AGENCY_ID"/> |
||||
|
<result property="delFlag" column="DEL_FLAG"/> |
||||
|
<result property="revision" column="REVISION"/> |
||||
|
<result property="createdBy" column="CREATED_BY"/> |
||||
|
<result property="createdTime" column="CREATED_TIME"/> |
||||
|
<result property="updatedBy" column="UPDATED_BY"/> |
||||
|
<result property="updatedTime" column="UPDATED_TIME"/> |
||||
|
</resultMap> |
||||
|
|
||||
|
<delete id="deleteByTagId" parameterType="map"> |
||||
|
delete from tag_scope |
||||
|
where TAG_ID=#{tagId} |
||||
|
and CUSTOMER_ID=#{customerId} |
||||
|
</delete> |
||||
|
</mapper> |
||||
Loading…
Reference in new issue