|
@@ -1,5 +1,7 @@
|
|
|
package com.caimei365.commodity.service.impl;
|
|
|
|
|
|
+import com.aliyun.oss.OSS;
|
|
|
+import com.aliyun.oss.OSSClientBuilder;
|
|
|
import com.caimei365.commodity.components.PriceUtilService;
|
|
|
import com.caimei365.commodity.mapper.*;
|
|
|
import com.caimei365.commodity.model.ResponseJson;
|
|
@@ -19,6 +21,8 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -47,6 +51,14 @@ public class PageServiceImpl implements PageService {
|
|
|
private PageService pageService;
|
|
|
@Resource
|
|
|
private CouponMapper couponMapper;
|
|
|
+ @Value("${spring.cloud.config.profile}")
|
|
|
+ private String active;
|
|
|
+
|
|
|
+
|
|
|
+ private String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";
|
|
|
+ private String accessKeyId = "LTAI4GBL3o4YkWnbKYgf2Xia";
|
|
|
+ private String accessKeySecret = "dBjAXqbYiEPP6Ukuk2ZsXQeET7FVkK";
|
|
|
+ private String bucketName = "caimei-oss";
|
|
|
|
|
|
/**
|
|
|
* 获取分类列表
|
|
@@ -878,29 +890,40 @@ public class PageServiceImpl implements PageService {
|
|
|
*/
|
|
|
@Override
|
|
|
public ResponseJson<ArchiveDetailVo> getArchiveDetail(Integer archiveId, Integer userId) {
|
|
|
+ ArchivePo archive = pageMapper.getArchiveByArchiveId(archiveId);
|
|
|
+ if (null == archive) {
|
|
|
+ return ResponseJson.error("商品资料不存在", null);
|
|
|
+ }
|
|
|
// 判断该用户是否拥有访问该资料的权限
|
|
|
- Integer permission = checkArchivePermission(archiveId, userId);
|
|
|
+ int permission = checkArchivePermission(archive, userId);
|
|
|
List<ArchiveContentVo> imageArchiveList = pageMapper.getImageArchiveList(archiveId);
|
|
|
List<ArchiveContentVo> videoArchiveList = pageMapper.getVideoArchiveList(archiveId);
|
|
|
List<ArchiveContentVo> fileArchiveList = pageMapper.getFileArchiveList(archiveId);
|
|
|
+ if (imageArchiveList.size() == 0 && videoArchiveList.size() == 0 && fileArchiveList.size() == 0) {
|
|
|
+ // 没有文件的时候,用户可查看资料
|
|
|
+ permission = 0;
|
|
|
+ }
|
|
|
+ int finalPermission = permission;
|
|
|
imageArchiveList.forEach(imageArchive->{
|
|
|
List<String> imageList = pageMapper.getArchiveImageList(imageArchive.getArchiveContentId());
|
|
|
- if (0 == permission) {
|
|
|
+ if (0 == finalPermission) {
|
|
|
imageArchive.setImageList(imageList);
|
|
|
}
|
|
|
imageArchive.setImageNum(imageList.size());
|
|
|
});
|
|
|
videoArchiveList.forEach(videoArchive->{
|
|
|
ArchiveFilePo archiveFile = pageMapper.getArchiveFile(videoArchive.getArchiveContentId());
|
|
|
- if (0 == permission) {
|
|
|
- videoArchive.setFileUrl(archiveFile.getFileUrl());
|
|
|
+ if (0 == finalPermission) {
|
|
|
+ String fileUrl = generateFileUrl(archiveFile);
|
|
|
+ videoArchive.setFileUrl(fileUrl);
|
|
|
}
|
|
|
});
|
|
|
fileArchiveList.forEach(fileArchive->{
|
|
|
ArchiveFilePo archiveFile = pageMapper.getArchiveFile(fileArchive.getArchiveContentId());
|
|
|
fileArchive.setFileName(archiveFile.getFileName());
|
|
|
- if (0 == permission) {
|
|
|
- fileArchive.setFileUrl(archiveFile.getFileUrl());
|
|
|
+ if (0 == finalPermission) {
|
|
|
+ String fileUrl = generateFileUrl(archiveFile);
|
|
|
+ fileArchive.setFileUrl(fileUrl);
|
|
|
}
|
|
|
});
|
|
|
ArchiveDetailVo archiveDetail = new ArchiveDetailVo();
|
|
@@ -908,44 +931,47 @@ public class PageServiceImpl implements PageService {
|
|
|
archiveDetail.setVideoArchiveList(videoArchiveList);
|
|
|
archiveDetail.setFileArchiveList(fileArchiveList);
|
|
|
archiveDetail.setPermission(permission);
|
|
|
+ archiveDetail.setProductImage(archive.getProductImage());
|
|
|
+ archiveDetail.setProductName(archive.getProductName());
|
|
|
+ archiveDetail.setProductType(archive.getProductType());
|
|
|
+ archiveDetail.setShopName(archive.getShopName());
|
|
|
return ResponseJson.success(archiveDetail);
|
|
|
}
|
|
|
|
|
|
- private Integer checkArchivePermission(Integer archiveId, Integer userId) {
|
|
|
- ArchivePo archive = pageMapper.getArchiveByArchiveId(archiveId);
|
|
|
+ private Integer checkArchivePermission(ArchivePo archive, Integer userId) {
|
|
|
//资料等级:1一类资料,2二类资料,3三类资料
|
|
|
Integer archiveLevel = archive.getArchiveLevel();
|
|
|
- //商品分类:1生美,2医美
|
|
|
+ //商品分类:1医美,2生美
|
|
|
Integer productClassify = archive.getProductClassify();
|
|
|
// 根据用户Id查询用户身份
|
|
|
Integer identity = priceMapper.getIdentityByUserId(userId);
|
|
|
// 1生美机构,2医美机构
|
|
|
Integer clubType = pageMapper.getClubTypeByUserId(userId);
|
|
|
// permission:0可查看,1未登录,2需升级会员机构,3需升级医美会员机构,4需要抵扣采美豆,5无权限查看
|
|
|
- Integer permission = null;
|
|
|
+ int permission;
|
|
|
if (null == identity) {
|
|
|
// 未登录
|
|
|
permission = 1;
|
|
|
} else if (1 == identity) {
|
|
|
//协销可查看所有资料
|
|
|
permission = 0;
|
|
|
- } else if (5 == identity) {
|
|
|
+ } else if (4 == identity) {
|
|
|
// 普通机构
|
|
|
if (archiveLevel > 1) {
|
|
|
// 二级资料,普通机构
|
|
|
- permission = 1 == productClassify ? 2 : 3;
|
|
|
+ permission = 2 == productClassify ? 2 : 3;
|
|
|
} else {
|
|
|
permission = 0;
|
|
|
}
|
|
|
} else if (2 == identity) {
|
|
|
// 会员机构
|
|
|
- if (2 == archiveLevel && 2 == productClassify && (0 == clubType || 1 == clubType)) {
|
|
|
+ if (2 == archiveLevel && 1 == productClassify && (0 == clubType || 2 == clubType)) {
|
|
|
// 二级医美资料,生美会员机构
|
|
|
permission = 3;
|
|
|
} else if (3 == archiveLevel) {
|
|
|
// 查询用户对该资料的抵扣记录
|
|
|
- Integer historyId = pageMapper.findBeansHistoryByArchiveId(userId, archiveId);
|
|
|
- if (2 == productClassify && (0 == clubType || 1 == clubType)) {
|
|
|
+ Integer historyId = pageMapper.findBeansHistoryByArchiveId(userId, archive.getArchiveId());
|
|
|
+ if (1 == productClassify && (0 == clubType || 2 == clubType)) {
|
|
|
// 三级医美资料,生美会员机构
|
|
|
permission = 3;
|
|
|
} else if (null == historyId){
|
|
@@ -961,4 +987,27 @@ public class PageServiceImpl implements PageService {
|
|
|
}
|
|
|
return permission;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public String generateFileUrl(ArchiveFilePo archiveFile) {
|
|
|
+ OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
|
|
+ String ossName = archiveFile.getOssName();
|
|
|
+ // 设置URL过期时间为1个小时
|
|
|
+ Date expiration = new Date(System.currentTimeMillis() + 3600L * 1000);
|
|
|
+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ try {
|
|
|
+ Date dateOne = format.parse("2021-06-01 00:00:00");
|
|
|
+ Date dateTwo = format.parse("2021-09-17 18:00:00");
|
|
|
+ if (archiveFile.getUploadTime() != null && archiveFile.getUploadTime().compareTo(dateOne) > 0 && archiveFile.getUploadTime().compareTo(dateTwo) < 0) {
|
|
|
+ ossName = active + "/" + ossName;
|
|
|
+ } else if (archiveFile.getUploadTime() != null && archiveFile.getUploadTime().compareTo(dateTwo)>0){
|
|
|
+ ossName = active + "/archiveFile/" + ossName;
|
|
|
+ }
|
|
|
+ } catch (ParseException e) {
|
|
|
+ log.info("格式化时间错误", e);
|
|
|
+ }
|
|
|
+ String url = ossClient.generatePresignedUrl(bucketName, ossName, expiration).toString();
|
|
|
+ ossClient.shutdown();
|
|
|
+ return url;
|
|
|
+ }
|
|
|
}
|