Merge branch 'master-高质量运营' into 'uat_code'
Master 高质量运营 See merge request eshop/biz_service_ebtp_extend!11
This commit is contained in:
@ -5,13 +5,16 @@ import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.entity.*;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.service.*;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.vo.HighQualityQueryInVO;
|
||||
import com.chinaunicom.mall.ebtp.extend.partyMemberEvent.entity.MockDataValue;
|
||||
import com.chinaunicom.mall.ebtp.extend.signature.entity.ExpertSignature;
|
||||
import com.chinaunicom.mall.ebtp.extend.uploadOss.service.IUploadOssService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -26,6 +29,12 @@ public class HighQualityClientController {
|
||||
private HighQualityStyleService highQualityStyleService;
|
||||
@Resource
|
||||
private HighQualityContactService highQualityContactService;
|
||||
@Resource
|
||||
private HighQualityLikesService highQualityLikesService;
|
||||
@Resource
|
||||
private HighQualityCommentService highQualityCommentService;
|
||||
@Resource
|
||||
private IUploadOssService iUploadOssService;
|
||||
|
||||
|
||||
@ApiOperation("右侧专业线数据")
|
||||
@ -71,5 +80,22 @@ public class HighQualityClientController {
|
||||
public BaseResponse<Boolean> saveContact(@RequestBody HighQualityContact inVO) {
|
||||
return BaseResponse.success(highQualityContactService.saveContact(inVO));
|
||||
}
|
||||
@ApiOperation("点赞")
|
||||
@PostMapping("/saveLikes")
|
||||
public BaseResponse saveLikes(@RequestBody HighQualityLikes inVO) {
|
||||
return highQualityLikesService.saveLikes(inVO);
|
||||
}
|
||||
|
||||
@ApiOperation("评论")
|
||||
@PostMapping("/saveComment")
|
||||
public BaseResponse saveComment(@RequestBody HighQualityComment inVO) {
|
||||
return highQualityCommentService.saveComment(inVO);
|
||||
}
|
||||
|
||||
@ApiOperation("oss文件下载")
|
||||
@PostMapping("/download")
|
||||
public void download(@RequestParam String key, HttpServletResponse response) throws IOException {
|
||||
iUploadOssService.download(response,key);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,12 +10,15 @@ import com.chinaunicom.mall.ebtp.extend.highquality.service.*;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.vo.HighQualityMaintainInVO;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.vo.HighQualityMaintainOutVO;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.vo.HighQualityRightDataVO;
|
||||
import com.chinaunicom.mall.ebtp.extend.uploadOss.service.IUploadOssService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -34,7 +37,8 @@ public class HighQualityMaintainController {
|
||||
private HighQualityStyleService highQualityStyleService;
|
||||
@Resource
|
||||
private HighQualityContactService highQualityContactService;
|
||||
|
||||
@Resource
|
||||
private IUploadOssService iUploadOssService;
|
||||
|
||||
@ApiOperation("保存联系人")
|
||||
@PostMapping("/save/contact")
|
||||
@ -94,6 +98,11 @@ public class HighQualityMaintainController {
|
||||
return BaseResponse.success(highQualityStyleService.deleteStyleOrProject(id));
|
||||
}
|
||||
|
||||
@ApiOperation("oss文件上传")
|
||||
@PostMapping("/upload")
|
||||
public BaseResponse upload(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
return BaseResponse.success(iUploadOssService.uploadFile(file,"oss/highquality"));
|
||||
}
|
||||
|
||||
|
||||
public void exportGetlist(HttpServletResponse response, ExcelTable table) {
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.highquality.dao;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.entity.HighQualityComment;
|
||||
|
||||
/**
|
||||
* @auto.generated
|
||||
*/
|
||||
public interface HighQualityCommentMapper extends BaseMapper<HighQualityComment> {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.highquality.dao;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.entity.HighQualityLikes;
|
||||
|
||||
/**
|
||||
* @auto.generated
|
||||
*/
|
||||
public interface HighQualityLikesMapper extends BaseMapper<HighQualityLikes> {
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
<?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.chinaunicom.mall.ebtp.extend.highquality.dao.HighQualityCommentMapper">
|
||||
<resultMap id="BaseResultMap"
|
||||
type="com.chinaunicom.mall.ebtp.extend.highquality.entity.HighQualityComment">
|
||||
<result column="id" jdbcType="VARCHAR" property="id"/>
|
||||
<result column="re_id" jdbcType="VARCHAR" property="reId"/>
|
||||
<result column="context" jdbcType="VARCHAR" property="context"/>
|
||||
<result column="creater_id" jdbcType="VARCHAR" property="createrId"/>
|
||||
<result column="creater_name" jdbcType="VARCHAR" property="createrName"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
<result column="delete_flag" jdbcType="VARCHAR" property="deleteFlag"/>
|
||||
</resultMap>
|
||||
|
||||
<!--逻辑删除方法 此方法为代码生成器生成 不允许修改 如有特殊需求 请自行新建SQL语句-->
|
||||
<update id="deleteOff" parameterType="java.lang.Long">
|
||||
update high_quality_comment
|
||||
set
|
||||
delete_flag="deleted"
|
||||
where ID=#{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
</mapper>
|
@ -0,0 +1,20 @@
|
||||
<?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.chinaunicom.mall.ebtp.extend.highquality.dao.HighQualityLikesMapper">
|
||||
<resultMap id="BaseResultMap"
|
||||
type="com.chinaunicom.mall.ebtp.extend.highquality.entity.HighQualityLikes">
|
||||
<result column="id" jdbcType="VARCHAR" property="id"/>
|
||||
<result column="re_id" jdbcType="VARCHAR" property="reId"/>
|
||||
<result column="account" jdbcType="VARCHAR" property="account"/>
|
||||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
|
||||
</resultMap>
|
||||
|
||||
<!--逻辑删除方法 此方法为代码生成器生成 不允许修改 如有特殊需求 请自行新建SQL语句-->
|
||||
<update id="deleteOff" parameterType="java.lang.Long">
|
||||
update high_quality_likes
|
||||
set
|
||||
delete_flag="deleted"
|
||||
where ID=#{id,jdbcType=BIGINT}
|
||||
</update>
|
||||
</mapper>
|
@ -0,0 +1,70 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.highquality.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.chinaunicom.mall.ebtp.common.config.CustomLocalDateTimeTypeHandler;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实体类 HighQualityComment
|
||||
*
|
||||
* @auto.generated
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName(value = "high_quality_comment", autoResultMap = true)
|
||||
public class HighQualityComment implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ApiModelProperty(value = "")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 关联表的主键id
|
||||
*/
|
||||
@ApiModelProperty(value = "关联表的主键id")
|
||||
private String reId;
|
||||
|
||||
/**
|
||||
* 评论内容
|
||||
*/
|
||||
@ApiModelProperty(value = "评论内容")
|
||||
private String context;
|
||||
|
||||
/**
|
||||
* 评论人id
|
||||
*/
|
||||
@ApiModelProperty(value = "评论人id")
|
||||
private String createrId;
|
||||
|
||||
/**
|
||||
* 评论人姓名
|
||||
*/
|
||||
@ApiModelProperty(value = "评论人姓名")
|
||||
private String createrName;
|
||||
|
||||
/**
|
||||
* 评论时间
|
||||
*/
|
||||
@ApiModelProperty(value = "评论时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@TableField(typeHandler = CustomLocalDateTimeTypeHandler.class)
|
||||
private java.time.LocalDateTime createTime;
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.highquality.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.chinaunicom.mall.ebtp.common.config.CustomLocalDateTimeTypeHandler;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 实体类 HighQualityLikes
|
||||
*
|
||||
* @auto.generated
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@ApiModel
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName(value = "high_quality_likes", autoResultMap = true)
|
||||
public class HighQualityLikes implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@ApiModelProperty(value = "主键")
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 关联表的主键id
|
||||
*/
|
||||
@ApiModelProperty(value = "关联表的主键id")
|
||||
private String reId;
|
||||
|
||||
/**
|
||||
* 点赞账户
|
||||
*/
|
||||
@ApiModelProperty(value = "点赞账户")
|
||||
private String account;
|
||||
|
||||
/**
|
||||
* 点赞时间
|
||||
*/
|
||||
@ApiModelProperty(value = "点赞时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@TableField(typeHandler = CustomLocalDateTimeTypeHandler.class)
|
||||
private java.time.LocalDateTime createTime;
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.highquality.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.entity.HighQualityComment;
|
||||
|
||||
/**
|
||||
* 对数据表 high_quality_comment 操作的 service
|
||||
* @author Auto create
|
||||
*
|
||||
*/
|
||||
public interface HighQualityCommentService extends IService<HighQualityComment>{
|
||||
|
||||
|
||||
BaseResponse saveComment(HighQualityComment inVo);
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.highquality.service;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.entity.HighQualityLikes;
|
||||
|
||||
/**
|
||||
* 对数据表 high_quality_likes 操作的 service
|
||||
* @author Auto create
|
||||
*
|
||||
*/
|
||||
public interface HighQualityLikesService extends IService<HighQualityLikes>{
|
||||
|
||||
|
||||
BaseResponse saveLikes(HighQualityLikes inVo);
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.highquality.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
|
||||
import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.dao.HighQualityCommentMapper;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.entity.HighQualityComment;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.entity.HighQualityLikes;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.service.HighQualityCommentService;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 对数据表 high_quality_comment 操作的 serviceImpl
|
||||
* @auto.generated
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class HighQualityCommentServiceImpl extends ServiceImpl<HighQualityCommentMapper,HighQualityComment> implements HighQualityCommentService {
|
||||
|
||||
@Resource
|
||||
private IBaseCacheUserService iBaseCacheUserService;
|
||||
|
||||
@Override
|
||||
public BaseResponse saveComment(HighQualityComment inVo){
|
||||
BaseCacheUser cacheUser = iBaseCacheUserService.getCacheUser();
|
||||
if(StringUtils.isBlank(inVo.getReId()) || StringUtils.isBlank(inVo.getContext())){
|
||||
return BaseResponse.fail("评论失败:评论内容或评论对象不能为空");
|
||||
}
|
||||
inVo.setId(PropertyUtils.getSnowflakeId());
|
||||
inVo.setCreaterId(cacheUser.getUserId());
|
||||
inVo.setCreaterName(cacheUser.getFullName());
|
||||
inVo.setCreateTime(LocalDateTime.now());
|
||||
if(this.save(inVo)){
|
||||
return BaseResponse.success("评论成功");
|
||||
}
|
||||
return BaseResponse.fail("评论失败");
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.highquality.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ParameterUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseCacheUser;
|
||||
import com.chinaunicom.mall.ebtp.common.base.entity.BaseResponse;
|
||||
import com.chinaunicom.mall.ebtp.common.base.service.IBaseCacheUserService;
|
||||
import com.chinaunicom.mall.ebtp.common.util.PropertyUtils;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.dao.HighQualityLikesMapper;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.entity.HighQualityLikes;
|
||||
import com.chinaunicom.mall.ebtp.extend.highquality.service.HighQualityLikesService;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 对数据表 high_quality_likes 操作的 serviceImpl
|
||||
* @auto.generated
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class HighQualityLikesServiceImpl extends ServiceImpl<HighQualityLikesMapper,HighQualityLikes> implements HighQualityLikesService {
|
||||
|
||||
@Resource
|
||||
private IBaseCacheUserService iBaseCacheUserService;
|
||||
|
||||
@Override
|
||||
public BaseResponse saveLikes(HighQualityLikes inVo){
|
||||
BaseCacheUser cacheUser = iBaseCacheUserService.getCacheUser();
|
||||
LambdaQueryWrapper<HighQualityLikes> query= Wrappers.lambdaQuery();
|
||||
query.eq(HighQualityLikes::getReId,inVo.getReId());
|
||||
query.eq(HighQualityLikes::getAccount,cacheUser.getUserId());
|
||||
List<HighQualityLikes> list=this.list(query);
|
||||
if(list!=null && list.size()>0){
|
||||
return BaseResponse.fail("您已点赞");
|
||||
}
|
||||
inVo.setId(PropertyUtils.getSnowflakeId());
|
||||
inVo.setAccount(cacheUser.getUserId());
|
||||
inVo.setCreateTime(LocalDateTime.now());
|
||||
if(this.save(inVo)){
|
||||
return BaseResponse.success("点赞成功");
|
||||
}
|
||||
return BaseResponse.fail("点赞失败");
|
||||
}
|
||||
}
|
@ -73,14 +73,6 @@ public class HighQualityStyleServiceImpl extends ServiceImpl<HighQualityStyleMap
|
||||
|
||||
@Override
|
||||
public boolean saveStyle(HighQualityStyle inVO) {
|
||||
if(inVO.getCategory().equals("4")){
|
||||
try {
|
||||
String filepath=iUploadOssService.uploadFile(inVO.getFile(),"oss/highquality");
|
||||
inVO.setImage(filepath);
|
||||
} catch (IOException e) {
|
||||
HighQualityExceptionEnum.FRAME_EXCEPTION_NO.customValidName("文件上传失败",true);
|
||||
}
|
||||
}
|
||||
if (StrUtil.isNotBlank(inVO.getId())) {
|
||||
return this.updateById(inVO);
|
||||
}
|
||||
@ -94,7 +86,6 @@ public class HighQualityStyleServiceImpl extends ServiceImpl<HighQualityStyleMap
|
||||
inVO.setId(PropertyUtils.getSnowflakeId());
|
||||
inVO.setStatus("1");
|
||||
inVO.setCreateTime(LocalDateTime.now());
|
||||
|
||||
return this.save(inVO);
|
||||
}
|
||||
@Override
|
||||
|
@ -2,8 +2,11 @@ package com.chinaunicom.mall.ebtp.extend.uploadOss.service;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
public interface IUploadOssService {
|
||||
String uploadFile(MultipartFile file, String prefix) throws IOException;
|
||||
|
||||
void download(HttpServletResponse response, String path);
|
||||
}
|
||||
|
@ -1,18 +1,30 @@
|
||||
package com.chinaunicom.mall.ebtp.extend.uploadOss.service.impl;
|
||||
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.OSSObject;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import com.chinaunicom.mall.ebtp.extend.uploadOss.service.IUploadOssService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
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.multipart.MultipartFile;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@ -38,7 +50,53 @@ public class UploadOssServiceImpl implements IUploadOssService {
|
||||
String filePathPrefix = prefix + File.separator + yearMonthPath.format(new Date((System.currentTimeMillis())));
|
||||
String objectName = filePathPrefix + File.separator + RandomUtil.randomString(32).toUpperCase(Locale.ROOT) + "." + fileType;
|
||||
client.putObject(new PutObjectRequest(bucketName, objectName, file.getInputStream(), new ObjectMetadata()));
|
||||
return objectName;
|
||||
return bucketName+":"+objectName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(HttpServletResponse response, String path){
|
||||
// String decryptStr = destool.decryptStr(path);
|
||||
String decryptStr = path;
|
||||
InputStream inputStream = null;
|
||||
BufferedInputStream bis = null;
|
||||
OSSObject ossObject = null;
|
||||
OSS ossClient = null;
|
||||
try {
|
||||
log.info("文件位置:{}", decryptStr);
|
||||
ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
//如果cfsPath路径种含有冒号,为oss下载
|
||||
String[] split = decryptStr.split(":");
|
||||
String s = split[0];
|
||||
String bucketName = s.substring(s.lastIndexOf("/") + 1);
|
||||
log.info("bucketName:{}, objectName:{}", bucketName, split[1]);
|
||||
String suffix = split[1].substring(split[1].lastIndexOf("."));
|
||||
response.setHeader("Content-Disposition", String.format("attachment; filename=\"%s\"",
|
||||
URLEncoder.ALL.encode(RandomUtil.randomString(32), StandardCharsets.UTF_8)));
|
||||
|
||||
ossObject = ossClient.getObject(bucketName, split[1]);
|
||||
inputStream = ossObject.getObjectContent();
|
||||
byte[] buffs = new byte[1024];
|
||||
bis = new BufferedInputStream(inputStream, 1024);
|
||||
int read;
|
||||
while ((read = bis.read(buffs, 0, 1024)) != -1) {
|
||||
response.getOutputStream().write(buffs, 0, read);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage());
|
||||
}finally {
|
||||
try {
|
||||
inputStream.close();
|
||||
bis.close();
|
||||
response.getOutputStream().close();
|
||||
ossObject.close();
|
||||
if (ossClient != null) {
|
||||
ossClient.shutdown();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.info("流关闭失败");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user