From 6835d230f4de1d64a72cd85ec7413373b5f4650d Mon Sep 17 00:00:00 2001 From: "review512jwy@163.com" <“review512jwy@163.com”> Date: Tue, 18 Nov 2025 16:18:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0getS3FileUrl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../back/controller/CommonController.java | 20 +- .../resources/config/application.properties | 5 +- .../back/dao/auto/S3FileMappingMapper.java | 96 +++ .../back/dao/ex/S3FileMappingMapperExt.java | 9 + .../mappers/auto/S3FileMappingMapper.xml | 257 ++++++++ .../mybatis-generator/generatorConfig.xml | 5 + .../common/BatchGetFileTemporaryParams.java | 18 + .../dashboard/back/model/S3FileMapping.java | 166 ++++++ .../back/model/S3FileMappingExample.java | 562 ++++++++++++++++++ .../back/vo/common/TemporaryInfo.java | 11 + dongjian-dashboard-back-service/pom.xml | 5 + .../dashboard/back/service/CommonService.java | 4 +- .../back/service/impl/CommonServiceImpl.java | 156 +++++ pom.xml | 13 + 14 files changed, 1318 insertions(+), 9 deletions(-) create mode 100644 dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/auto/S3FileMappingMapper.java create mode 100644 dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/S3FileMappingMapperExt.java create mode 100644 dongjian-dashboard-back-dao/src/main/resources/mappers/auto/S3FileMappingMapper.xml create mode 100644 dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/common/BatchGetFileTemporaryParams.java create mode 100644 dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMapping.java create mode 100644 dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMappingExample.java create mode 100644 dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/common/TemporaryInfo.java diff --git a/dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/CommonController.java b/dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/CommonController.java index 17533eb..f7a7d5b 100644 --- a/dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/CommonController.java +++ b/dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/CommonController.java @@ -1,15 +1,13 @@ package com.dongjian.dashboard.back.controller; import java.util.List; + +import com.dongjian.dashboard.back.dto.common.BatchGetFileTemporaryParams; +import io.swagger.v3.oas.annotations.media.Schema; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.alibaba.fastjson.JSONObject; import com.dongjian.dashboard.back.common.response.SimpleDataResponse; @@ -78,4 +76,14 @@ public class CommonController{ ){ return commonService.destroyAurora(companyId); } + + @Operation(summary = "batch get temporary link") + @RequestMapping(value = "/getS3FileUrl", method = RequestMethod.POST) + public SimpleDataResponse getS3FileUrl( + @RequestBody BatchGetFileTemporaryParams batchGetFileTemporaryParams, + @Parameter(name = "Apikey", description = "API key", required = false, schema = @Schema(defaultValue = "123456")) @RequestHeader(required = false) String Apikey, + @Parameter(name = "CompanyId", description = "companyId", required = false, schema = @Schema(defaultValue = "2")) @RequestHeader(required = false) Long CompanyId + ){ + return commonService.getS3FileUrl(batchGetFileTemporaryParams, Apikey, CompanyId); + } } diff --git a/dongjian-dashboard-back-controller/src/main/resources/config/application.properties b/dongjian-dashboard-back-controller/src/main/resources/config/application.properties index d2ad357..5c6ec8d 100644 --- a/dongjian-dashboard-back-controller/src/main/resources/config/application.properties +++ b/dongjian-dashboard-back-controller/src/main/resources/config/application.properties @@ -109,8 +109,9 @@ springdoc.swagger-ui.tags-sorter=alpha web.login.url=${webLoginUrl} web.admin.login.url=${webAdminLoginUrl} -amazon.aws.accesskey=${awsAccessKey} -amazon.aws.secretkey=${awsSecretKey} +amazon.aws.accesskey=${awsAccessKey:AKIA5OFH5OOZHM3U3KX4} +amazon.aws.secretkey=${awsSecretKey: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} +amazon.aws.bucket.asset=${awsBucketAsset:tokyobuild-stg-databucket-923770123186} amazon.aws.actionable.region=ap-northeast-1 amazon.aws.actionable.bucket=${awsActionableBucket} amazon.aws.actionable.directory=${awsActionableDirectory} diff --git a/dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/auto/S3FileMappingMapper.java b/dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/auto/S3FileMappingMapper.java new file mode 100644 index 0000000..6cd6a17 --- /dev/null +++ b/dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/auto/S3FileMappingMapper.java @@ -0,0 +1,96 @@ +package com.dongjian.dashboard.back.dao.auto; + +import com.dongjian.dashboard.back.model.S3FileMapping; +import com.dongjian.dashboard.back.model.S3FileMappingExample; +import java.util.List; +import org.apache.ibatis.annotations.Param; + +public interface S3FileMappingMapper { + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + long countByExample(S3FileMappingExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + int deleteByExample(S3FileMappingExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + int deleteByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + int insert(S3FileMapping record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + int insertSelective(S3FileMapping record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + List selectByExample(S3FileMappingExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + S3FileMapping selectByPrimaryKey(Long id); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + int updateByExampleSelective(@Param("record") S3FileMapping record, @Param("example") S3FileMappingExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + int updateByExample(@Param("record") S3FileMapping record, @Param("example") S3FileMappingExample example); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + int updateByPrimaryKeySelective(S3FileMapping record); + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + int updateByPrimaryKey(S3FileMapping record); +} \ No newline at end of file diff --git a/dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/S3FileMappingMapperExt.java b/dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/S3FileMappingMapperExt.java new file mode 100644 index 0000000..64f01eb --- /dev/null +++ b/dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/S3FileMappingMapperExt.java @@ -0,0 +1,9 @@ +package com.dongjian.dashboard.back.dao.ex; + +import com.dongjian.dashboard.back.dao.auto.S3FileMappingMapper; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface S3FileMappingMapperExt extends S3FileMappingMapper { + +} diff --git a/dongjian-dashboard-back-dao/src/main/resources/mappers/auto/S3FileMappingMapper.xml b/dongjian-dashboard-back-dao/src/main/resources/mappers/auto/S3FileMappingMapper.xml new file mode 100644 index 0000000..95d474d --- /dev/null +++ b/dongjian-dashboard-back-dao/src/main/resources/mappers/auto/S3FileMappingMapper.xml @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + id, file_key, s3_path, create_time + + + + + + delete from s3_file_mapping + where id = #{id,jdbcType=BIGINT} + + + + delete from s3_file_mapping + + + + + + + + SELECT LAST_INSERT_ID() + + insert into s3_file_mapping (file_key, s3_path, create_time + ) + values (#{fileKey,jdbcType=VARCHAR}, #{s3Path,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT} + ) + + + + + SELECT LAST_INSERT_ID() + + insert into s3_file_mapping + + + file_key, + + + s3_path, + + + create_time, + + + + + #{fileKey,jdbcType=VARCHAR}, + + + #{s3Path,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=BIGINT}, + + + + + + + update s3_file_mapping + + + id = #{record.id,jdbcType=BIGINT}, + + + file_key = #{record.fileKey,jdbcType=VARCHAR}, + + + s3_path = #{record.s3Path,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=BIGINT}, + + + + + + + + + update s3_file_mapping + set id = #{record.id,jdbcType=BIGINT}, + file_key = #{record.fileKey,jdbcType=VARCHAR}, + s3_path = #{record.s3Path,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=BIGINT} + + + + + + + update s3_file_mapping + + + file_key = #{fileKey,jdbcType=VARCHAR}, + + + s3_path = #{s3Path,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=BIGINT}, + + + where id = #{id,jdbcType=BIGINT} + + + + update s3_file_mapping + set file_key = #{fileKey,jdbcType=VARCHAR}, + s3_path = #{s3Path,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=BIGINT} + where id = #{id,jdbcType=BIGINT} + + \ No newline at end of file diff --git a/dongjian-dashboard-back-dao/src/main/resources/mybatis-generator/generatorConfig.xml b/dongjian-dashboard-back-dao/src/main/resources/mybatis-generator/generatorConfig.xml index a51a05c..aee55c1 100644 --- a/dongjian-dashboard-back-dao/src/main/resources/mybatis-generator/generatorConfig.xml +++ b/dongjian-dashboard-back-dao/src/main/resources/mybatis-generator/generatorConfig.xml @@ -144,5 +144,10 @@ + + + +
+ \ No newline at end of file diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/common/BatchGetFileTemporaryParams.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/common/BatchGetFileTemporaryParams.java new file mode 100644 index 0000000..148a6c7 --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/common/BatchGetFileTemporaryParams.java @@ -0,0 +1,18 @@ +package com.dongjian.dashboard.back.dto.common; + +import java.util.List; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** +* @author Mr.Jiang +* @time 2022年7月21日 下午8:50:31 +*/ +@Data +public class BatchGetFileTemporaryParams{ + + @Schema(description ="s3 file key)", example = "testMonitoringAsset1.pdf", required = true) + private List keys; + +} diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMapping.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMapping.java new file mode 100644 index 0000000..5c7624e --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMapping.java @@ -0,0 +1,166 @@ +package com.dongjian.dashboard.back.model; + +import java.io.Serializable; + +public class S3FileMapping implements Serializable { + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column s3_file_mapping.id + * + * @mbg.generated + */ + private Long id; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column s3_file_mapping.file_key + * + * @mbg.generated + */ + private String fileKey; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column s3_file_mapping.s3_path + * + * @mbg.generated + */ + private String s3Path; + + /** + * + * This field was generated by MyBatis Generator. + * This field corresponds to the database column s3_file_mapping.create_time + * + * @mbg.generated + */ + private Long createTime; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + private static final long serialVersionUID = 1L; + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column s3_file_mapping.id + * + * @return the value of s3_file_mapping.id + * + * @mbg.generated + */ + public Long getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column s3_file_mapping.id + * + * @param id the value for s3_file_mapping.id + * + * @mbg.generated + */ + public void setId(Long id) { + this.id = id; + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column s3_file_mapping.file_key + * + * @return the value of s3_file_mapping.file_key + * + * @mbg.generated + */ + public String getFileKey() { + return fileKey; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column s3_file_mapping.file_key + * + * @param fileKey the value for s3_file_mapping.file_key + * + * @mbg.generated + */ + public void setFileKey(String fileKey) { + this.fileKey = fileKey == null ? null : fileKey.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column s3_file_mapping.s3_path + * + * @return the value of s3_file_mapping.s3_path + * + * @mbg.generated + */ + public String getS3Path() { + return s3Path; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column s3_file_mapping.s3_path + * + * @param s3Path the value for s3_file_mapping.s3_path + * + * @mbg.generated + */ + public void setS3Path(String s3Path) { + this.s3Path = s3Path == null ? null : s3Path.trim(); + } + + /** + * This method was generated by MyBatis Generator. + * This method returns the value of the database column s3_file_mapping.create_time + * + * @return the value of s3_file_mapping.create_time + * + * @mbg.generated + */ + public Long getCreateTime() { + return createTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method sets the value of the database column s3_file_mapping.create_time + * + * @param createTime the value for s3_file_mapping.create_time + * + * @mbg.generated + */ + public void setCreateTime(Long createTime) { + this.createTime = createTime; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", fileKey=").append(fileKey); + sb.append(", s3Path=").append(s3Path); + sb.append(", createTime=").append(createTime); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMappingExample.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMappingExample.java new file mode 100644 index 0000000..7834480 --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMappingExample.java @@ -0,0 +1,562 @@ +package com.dongjian.dashboard.back.model; + +import java.util.ArrayList; +import java.util.List; + +public class S3FileMappingExample { + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + protected String orderByClause; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + protected boolean distinct; + + /** + * This field was generated by MyBatis Generator. + * This field corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + protected List oredCriteria; + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public S3FileMappingExample() { + oredCriteria = new ArrayList(); + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public String getOrderByClause() { + return orderByClause; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public boolean isDistinct() { + return distinct; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public List getOredCriteria() { + return oredCriteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.size() == 0) { + oredCriteria.add(criteria); + } + return criteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + protected Criteria createCriteriaInternal() { + Criteria criteria = new Criteria(); + return criteria; + } + + /** + * This method was generated by MyBatis Generator. + * This method corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + protected abstract static class GeneratedCriteria { + protected List criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList(); + } + + public boolean isValid() { + return criteria.size() > 0; + } + + public List getAllCriteria() { + return criteria; + } + + public List getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); + } + criteria.add(new Criterion(condition, value1, value2)); + } + + public Criteria andIdIsNull() { + addCriterion("id is null"); + return (Criteria) this; + } + + public Criteria andIdIsNotNull() { + addCriterion("id is not null"); + return (Criteria) this; + } + + public Criteria andIdEqualTo(Long value) { + addCriterion("id =", value, "id"); + return (Criteria) this; + } + + public Criteria andIdNotEqualTo(Long value) { + addCriterion("id <>", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThan(Long value) { + addCriterion("id >", value, "id"); + return (Criteria) this; + } + + public Criteria andIdGreaterThanOrEqualTo(Long value) { + addCriterion("id >=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThan(Long value) { + addCriterion("id <", value, "id"); + return (Criteria) this; + } + + public Criteria andIdLessThanOrEqualTo(Long value) { + addCriterion("id <=", value, "id"); + return (Criteria) this; + } + + public Criteria andIdIn(List values) { + addCriterion("id in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdNotIn(List values) { + addCriterion("id not in", values, "id"); + return (Criteria) this; + } + + public Criteria andIdBetween(Long value1, Long value2) { + addCriterion("id between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andIdNotBetween(Long value1, Long value2) { + addCriterion("id not between", value1, value2, "id"); + return (Criteria) this; + } + + public Criteria andFileKeyIsNull() { + addCriterion("file_key is null"); + return (Criteria) this; + } + + public Criteria andFileKeyIsNotNull() { + addCriterion("file_key is not null"); + return (Criteria) this; + } + + public Criteria andFileKeyEqualTo(String value) { + addCriterion("file_key =", value, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyNotEqualTo(String value) { + addCriterion("file_key <>", value, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyGreaterThan(String value) { + addCriterion("file_key >", value, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyGreaterThanOrEqualTo(String value) { + addCriterion("file_key >=", value, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyLessThan(String value) { + addCriterion("file_key <", value, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyLessThanOrEqualTo(String value) { + addCriterion("file_key <=", value, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyLike(String value) { + addCriterion("file_key like", value, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyNotLike(String value) { + addCriterion("file_key not like", value, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyIn(List values) { + addCriterion("file_key in", values, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyNotIn(List values) { + addCriterion("file_key not in", values, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyBetween(String value1, String value2) { + addCriterion("file_key between", value1, value2, "fileKey"); + return (Criteria) this; + } + + public Criteria andFileKeyNotBetween(String value1, String value2) { + addCriterion("file_key not between", value1, value2, "fileKey"); + return (Criteria) this; + } + + public Criteria andS3PathIsNull() { + addCriterion("s3_path is null"); + return (Criteria) this; + } + + public Criteria andS3PathIsNotNull() { + addCriterion("s3_path is not null"); + return (Criteria) this; + } + + public Criteria andS3PathEqualTo(String value) { + addCriterion("s3_path =", value, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathNotEqualTo(String value) { + addCriterion("s3_path <>", value, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathGreaterThan(String value) { + addCriterion("s3_path >", value, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathGreaterThanOrEqualTo(String value) { + addCriterion("s3_path >=", value, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathLessThan(String value) { + addCriterion("s3_path <", value, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathLessThanOrEqualTo(String value) { + addCriterion("s3_path <=", value, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathLike(String value) { + addCriterion("s3_path like", value, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathNotLike(String value) { + addCriterion("s3_path not like", value, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathIn(List values) { + addCriterion("s3_path in", values, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathNotIn(List values) { + addCriterion("s3_path not in", values, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathBetween(String value1, String value2) { + addCriterion("s3_path between", value1, value2, "s3Path"); + return (Criteria) this; + } + + public Criteria andS3PathNotBetween(String value1, String value2) { + addCriterion("s3_path not between", value1, value2, "s3Path"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNull() { + addCriterion("create_time is null"); + return (Criteria) this; + } + + public Criteria andCreateTimeIsNotNull() { + addCriterion("create_time is not null"); + return (Criteria) this; + } + + public Criteria andCreateTimeEqualTo(Long value) { + addCriterion("create_time =", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotEqualTo(Long value) { + addCriterion("create_time <>", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThan(Long value) { + addCriterion("create_time >", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) { + addCriterion("create_time >=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThan(Long value) { + addCriterion("create_time <", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeLessThanOrEqualTo(Long value) { + addCriterion("create_time <=", value, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeIn(List values) { + addCriterion("create_time in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotIn(List values) { + addCriterion("create_time not in", values, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeBetween(Long value1, Long value2) { + addCriterion("create_time between", value1, value2, "createTime"); + return (Criteria) this; + } + + public Criteria andCreateTimeNotBetween(Long value1, Long value2) { + addCriterion("create_time not between", value1, value2, "createTime"); + return (Criteria) this; + } + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table s3_file_mapping + * + * @mbg.generated do_not_delete_during_merge + */ + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + /** + * This class was generated by MyBatis Generator. + * This class corresponds to the database table s3_file_mapping + * + * @mbg.generated + */ + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + public String getCondition() { + return condition; + } + + public Object getValue() { + return value; + } + + public Object getSecondValue() { + return secondValue; + } + + public boolean isNoValue() { + return noValue; + } + + public boolean isSingleValue() { + return singleValue; + } + + public boolean isBetweenValue() { + return betweenValue; + } + + public boolean isListValue() { + return listValue; + } + + public String getTypeHandler() { + return typeHandler; + } + + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + } +} \ No newline at end of file diff --git a/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/common/TemporaryInfo.java b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/common/TemporaryInfo.java new file mode 100644 index 0000000..f401a5c --- /dev/null +++ b/dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/common/TemporaryInfo.java @@ -0,0 +1,11 @@ +package com.dongjian.dashboard.back.vo.common; + +import lombok.Data; + +@Data +public class TemporaryInfo { + + private String key; + private String url; + +} diff --git a/dongjian-dashboard-back-service/pom.xml b/dongjian-dashboard-back-service/pom.xml index 9540b2d..98f4bca 100644 --- a/dongjian-dashboard-back-service/pom.xml +++ b/dongjian-dashboard-back-service/pom.xml @@ -45,6 +45,11 @@ test + + software.amazon.awssdk + s3 + + com.github.penggle kaptcha diff --git a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/CommonService.java b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/CommonService.java index ee24bf2..ae25595 100644 --- a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/CommonService.java +++ b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/CommonService.java @@ -3,6 +3,7 @@ package com.dongjian.dashboard.back.service; import java.util.List; import com.dongjian.dashboard.back.common.response.SimpleDataResponse; +import com.dongjian.dashboard.back.dto.common.BatchGetFileTemporaryParams; import com.dongjian.dashboard.back.dto.common.DatacenterV1QueryParams; /** @@ -19,5 +20,6 @@ public interface CommonService { SimpleDataResponse initAurora(Long companyId); SimpleDataResponse destroyAurora(Long companyId); - + + SimpleDataResponse getS3FileUrl(BatchGetFileTemporaryParams batchGetFileTemporaryParams, String apikey, Long companyId); } diff --git a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/CommonServiceImpl.java b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/CommonServiceImpl.java index 6e851d7..62aa690 100644 --- a/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/CommonServiceImpl.java +++ b/dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/CommonServiceImpl.java @@ -1,18 +1,42 @@ package com.dongjian.dashboard.back.service.impl; +import java.time.Duration; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import com.dongjian.dashboard.back.common.Constants; +import com.dongjian.dashboard.back.common.config.DataSourceContextHolder; +import com.dongjian.dashboard.back.common.response.ResponseCode; +import com.dongjian.dashboard.back.dto.common.BatchGetFileTemporaryParams; +import com.dongjian.dashboard.back.model.S3FileMapping; +import com.dongjian.dashboard.back.model.S3FileMappingExample; +import com.dongjian.dashboard.back.vo.common.TemporaryInfo; +import com.dongjian.dashboard.back.vo.company.AuroraInfo; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; 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.stereotype.Service; import com.dongjian.dashboard.back.common.response.SimpleDataResponse; import com.dongjian.dashboard.back.dao.ex.BasicCompanyMapperExt; +import com.dongjian.dashboard.back.dao.ex.S3FileMappingMapperExt; import com.dongjian.dashboard.back.model.BasicCompanyExample; import com.dongjian.dashboard.back.service.CommonService; import com.dongjian.dashboard.back.service.common.CommonOpt; +import software.amazon.awssdk.auth.credentials.AwsBasicCredentials; +import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.s3.S3Client; +import software.amazon.awssdk.services.s3.model.HeadObjectRequest; +import software.amazon.awssdk.services.s3.model.NoSuchKeyException; +import software.amazon.awssdk.services.s3.presigner.S3Presigner; +import software.amazon.awssdk.services.s3.presigner.model.GetObjectPresignRequest; +import software.amazon.awssdk.services.s3.presigner.model.PresignedGetObjectRequest; /** * @@ -24,12 +48,23 @@ public class CommonServiceImpl implements CommonService { private static Logger logger = LoggerFactory.getLogger(CommonServiceImpl.class); + @Value("${amazon.aws.accesskey}") + private String awsAccessKeyId; + + @Value("${amazon.aws.secretkey}") + private String awsAccessSecret; + + @Value("${amazon.aws.bucket.asset:tokyobuild-stg-databucket-923770123186}") + private String awsBucketAdress; + @Autowired private CommonOpt commonOpt; @Autowired private BasicCompanyMapperExt basicCompanyMapperExt; + @Autowired + private S3FileMappingMapperExt s3FileMappingMapperExt; @Override @@ -74,5 +109,126 @@ public class CommonServiceImpl implements CommonService { // commonOpt.destroyAurora(comList); return SimpleDataResponse.success(); } + + @Override + public SimpleDataResponse getS3FileUrl(BatchGetFileTemporaryParams batchGetFileTemporaryParams, String apikey, Long companyId) { + if (CollectionUtils.isEmpty(batchGetFileTemporaryParams.getKeys())) { + return new SimpleDataResponse(ResponseCode.MSG_ERROR, "keys required"); + } + + Map paramMap = new HashMap<>(); + paramMap.put("apikey", apikey); + paramMap.put("companyId", companyId); + AuroraInfo apikeyInfo = commonOpt.getAuroraInfoByApikey(paramMap); + + if (null == apikeyInfo) { + return SimpleDataResponse.fail(ResponseCode.MSG_ERROR, "Apikey is invalid"); + } + + DataSourceContextHolder.clearCurrentDataSourceKey(); + DataSourceContextHolder.setCurrentDataSourceKey(Constants.DATASOURCE_PREFIX+ apikeyInfo.getId()); + + String bucketName = awsBucketAdress; + String accessKey = awsAccessKeyId; + String secretKey = awsAccessSecret; + + AwsBasicCredentials awsCredentials = AwsBasicCredentials.create(accessKey, secretKey); + Region region = Region.AP_NORTHEAST_1; + + S3Presigner presigner = null; + List result = new ArrayList<>(); + + try { + presigner = S3Presigner.builder() + .region(region) + .credentialsProvider(StaticCredentialsProvider.create(awsCredentials)) + .build(); + + S3Client s3Client = S3Client.builder() + .region(region) + .credentialsProvider(StaticCredentialsProvider.create(awsCredentials)) + .build(); + + for (String s3FileKey : batchGetFileTemporaryParams.getKeys()) { + TemporaryInfo temporaryInfo = new TemporaryInfo(); + if (StringUtils.isBlank(s3FileKey)) { + continue; + } + temporaryInfo.setKey(s3FileKey); + temporaryInfo.setUrl(""); + + // 查询数据库获取实际S3路径 + S3FileMappingExample example = new S3FileMappingExample(); + example.createCriteria().andFileKeyEqualTo(s3FileKey); + List mappings = s3FileMappingMapperExt.selectByExample(example); + if (CollectionUtils.isEmpty(mappings)) { + result.add(temporaryInfo); + continue; + } + + String objectKey = mappings.get(0).getS3Path(); + + // 设置有效期 + int expire = 6; + if (isPdf(s3FileKey)) expire = 24; + if (isImage(s3FileKey)) expire = 2; + + try { + // 检查对象是否存在 + HeadObjectRequest headRequest = HeadObjectRequest.builder() + .bucket(bucketName) + .key(objectKey) + .build(); + s3Client.headObject(headRequest); + + // 构建预签名URL + software.amazon.awssdk.services.s3.model.GetObjectRequest getRequest = + software.amazon.awssdk.services.s3.model.GetObjectRequest.builder() + .bucket(bucketName) + .key(objectKey) + .build(); + + GetObjectPresignRequest presignRequest = GetObjectPresignRequest.builder() + .signatureDuration(Duration.ofHours(expire)) + .getObjectRequest(getRequest) + .build(); + + PresignedGetObjectRequest presignedRequest = presigner.presignGetObject(presignRequest); + temporaryInfo.setUrl(presignedRequest.url().toString());; + + } catch (NoSuchKeyException e) { + logger.error("Key not found: {}", s3FileKey); + } + + result.add(temporaryInfo); + } + + return SimpleDataResponse.success(result); + } catch (Exception e) { + logger.error("Batch getTemporaryLinks error", e); + return new SimpleDataResponse(ResponseCode.SERVER_ERROR, "Internal error"); + } finally { + if (presigner != null) { + presigner.close(); + } + } + } + + public static boolean isPdf(String fileName) { + return fileName != null && fileName.toLowerCase().endsWith(".pdf"); + } + + public static boolean isImage(String fileName) { + if (fileName == null) return false; + String lower = fileName.toLowerCase(); + return lower.endsWith(".jpg") || lower.endsWith(".jpeg") || + lower.endsWith(".png") || lower.endsWith(".gif") || + lower.endsWith(".bmp") || lower.endsWith(".webp") || + lower.endsWith(".tiff") || lower.endsWith(".tif") || + lower.endsWith(".svg") || lower.endsWith(".ico") || + lower.endsWith(".heic") || lower.endsWith(".heif") || + lower.endsWith(".raw") || lower.endsWith(".cr2") || + lower.endsWith(".nef"); + } } diff --git a/pom.xml b/pom.xml index c0b41d6..330d982 100644 --- a/pom.xml +++ b/pom.xml @@ -200,6 +200,19 @@ + + + + + software.amazon.awssdk + bom + 2.20.113 + pom + import + + + +