Browse Source

增加getS3FileUrl

master
review512jwy@163.com 1 week ago
parent
commit
6835d230f4
  1. 20
      dongjian-dashboard-back-controller/src/main/java/com/dongjian/dashboard/back/controller/CommonController.java
  2. 5
      dongjian-dashboard-back-controller/src/main/resources/config/application.properties
  3. 96
      dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/auto/S3FileMappingMapper.java
  4. 9
      dongjian-dashboard-back-dao/src/main/java/com/dongjian/dashboard/back/dao/ex/S3FileMappingMapperExt.java
  5. 257
      dongjian-dashboard-back-dao/src/main/resources/mappers/auto/S3FileMappingMapper.xml
  6. 5
      dongjian-dashboard-back-dao/src/main/resources/mybatis-generator/generatorConfig.xml
  7. 18
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/dto/common/BatchGetFileTemporaryParams.java
  8. 166
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMapping.java
  9. 562
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/model/S3FileMappingExample.java
  10. 11
      dongjian-dashboard-back-model/src/main/java/com/dongjian/dashboard/back/vo/common/TemporaryInfo.java
  11. 5
      dongjian-dashboard-back-service/pom.xml
  12. 4
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/CommonService.java
  13. 156
      dongjian-dashboard-back-service/src/main/java/com/dongjian/dashboard/back/service/impl/CommonServiceImpl.java
  14. 13
      pom.xml

20
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);
}
}

5
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}

96
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<S3FileMapping> 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);
}

9
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 {
}

257
dongjian-dashboard-back-dao/src/main/resources/mappers/auto/S3FileMappingMapper.xml

@ -0,0 +1,257 @@
<?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.dongjian.dashboard.back.dao.auto.S3FileMappingMapper">
<resultMap id="BaseResultMap" type="com.dongjian.dashboard.back.model.S3FileMapping">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="file_key" jdbcType="VARCHAR" property="fileKey" />
<result column="s3_path" jdbcType="VARCHAR" property="s3Path" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
</resultMap>
<sql id="Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
id, file_key, s3_path, create_time
</sql>
<select id="selectByExample" parameterType="com.dongjian.dashboard.back.model.S3FileMappingExample" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<if test="distinct">
distinct
</if>
'true' as QUERYID,
<include refid="Base_Column_List" />
from s3_file_mapping
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
from s3_file_mapping
where id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from s3_file_mapping
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.dongjian.dashboard.back.model.S3FileMappingExample">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from s3_file_mapping
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.dongjian.dashboard.back.model.S3FileMapping">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into s3_file_mapping (file_key, s3_path, create_time
)
values (#{fileKey,jdbcType=VARCHAR}, #{s3Path,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}
)
</insert>
<insert id="insertSelective" parameterType="com.dongjian.dashboard.back.model.S3FileMapping">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
SELECT LAST_INSERT_ID()
</selectKey>
insert into s3_file_mapping
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="fileKey != null">
file_key,
</if>
<if test="s3Path != null">
s3_path,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="fileKey != null">
#{fileKey,jdbcType=VARCHAR},
</if>
<if test="s3Path != null">
#{s3Path,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.dongjian.dashboard.back.model.S3FileMappingExample" resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select count(*) from s3_file_mapping
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update s3_file_mapping
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.fileKey != null">
file_key = #{record.fileKey,jdbcType=VARCHAR},
</if>
<if test="record.s3Path != null">
s3_path = #{record.s3Path,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
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}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.dongjian.dashboard.back.model.S3FileMapping">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
update s3_file_mapping
<set>
<if test="fileKey != null">
file_key = #{fileKey,jdbcType=VARCHAR},
</if>
<if test="s3Path != null">
s3_path = #{s3Path,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.dongjian.dashboard.back.model.S3FileMapping">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
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}
</update>
</mapper>

5
dongjian-dashboard-back-dao/src/main/resources/mybatis-generator/generatorConfig.xml

@ -144,5 +144,10 @@
<generatedKey column="id" sqlStatement="Mysql" identity="true" />
</table>
<table tableName="s3_file_mapping" domainObjectName="S3FileMapping" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
<property name="useActualColumnNames" value="false" />
<generatedKey column="id" sqlStatement="Mysql" identity="true" />
</table>
</context>
</generatorConfiguration>

18
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<String> keys;
}

166
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();
}
}

562
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<Criteria> 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<Criteria>();
}
/**
* 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<Criteria> 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<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> 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<Long> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<Long> 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<String> values) {
addCriterion("file_key in", values, "fileKey");
return (Criteria) this;
}
public Criteria andFileKeyNotIn(List<String> 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<String> values) {
addCriterion("s3_path in", values, "s3Path");
return (Criteria) this;
}
public Criteria andS3PathNotIn(List<String> 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<Long> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Long> 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);
}
}
}

11
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;
}

5
dongjian-dashboard-back-service/pom.xml

@ -45,6 +45,11 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
<dependency>
<groupId>com.github.penggle</groupId>
<artifactId>kaptcha</artifactId>

4
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);
}

156
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<String, Object> 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<TemporaryInfo> 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<S3FileMapping> 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");
}
}

13
pom.xml

@ -200,6 +200,19 @@
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.20.113</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>

Loading…
Cancel
Save