|
@@ -1,11 +1,11 @@
|
|
|
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;
|
|
|
-import com.caimei365.commodity.model.po.ProductDetailInfoPo;
|
|
|
-import com.caimei365.commodity.model.po.ProductImagePo;
|
|
|
-import com.caimei365.commodity.model.po.ProductParameterPo;
|
|
|
+import com.caimei365.commodity.model.po.*;
|
|
|
import com.caimei365.commodity.model.search.ProductListVo;
|
|
|
import com.caimei365.commodity.model.vo.*;
|
|
|
import com.caimei365.commodity.service.PageService;
|
|
@@ -21,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;
|
|
|
|
|
@@ -52,6 +54,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";
|
|
|
|
|
|
/**
|
|
|
* 获取分类列表
|
|
@@ -421,6 +431,9 @@ public class PageServiceImpl implements PageService {
|
|
|
Integer appletsBeautyStatus = shopMapper.getAppletsBeautyStatusById(product.getProductId());
|
|
|
product.setPcActType(null != pcBeautyStatus ? 1 : 0);
|
|
|
product.setAppletsActType(null != appletsBeautyStatus ? 1 : 0);
|
|
|
+ // 商品资料id
|
|
|
+ Integer archiveId = pageMapper.getArchiveIdById(product.getProductId());
|
|
|
+ product.setArchiveId(null != archiveId ? archiveId : 0);
|
|
|
//供应商信息
|
|
|
ShopVo shop = shopMapper.getProductShopById(product.getShopId());
|
|
|
if (null != shop) {
|
|
@@ -852,4 +865,155 @@ public class PageServiceImpl implements PageService {
|
|
|
}
|
|
|
return couponsLogo;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商品资料列表
|
|
|
+ * @param keyword 搜索关键词
|
|
|
+ * @param productType 商品属性:1产品,2仪器
|
|
|
+ * @param pageNum 页码
|
|
|
+ * @param pageSize 每页数量
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<PaginationVo<ArchiveVo>> getProductArchive(String keyword, Integer productType, Integer pageNum, Integer pageSize) {
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<ArchiveVo> archiveList = pageMapper.getProductArchiveList(keyword, productType);
|
|
|
+ archiveList.forEach(archive->{
|
|
|
+ if (null != archive.getProductId()) {
|
|
|
+ String imageURL = ImageUtils.getImageURL("product", archive.getProductImage(), 0, domain);
|
|
|
+ archive.setProductImage(imageURL);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ PaginationVo<ArchiveVo> pageData = new PaginationVo<>(archiveList);
|
|
|
+ return ResponseJson.success(pageData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商品资料内容
|
|
|
+ * @param archiveId 商品资料id
|
|
|
+ * @param userId 用户id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<ArchiveDetailVo> getArchiveDetail(Integer archiveId, Integer userId) {
|
|
|
+ ArchivePo archive = pageMapper.getArchiveByArchiveId(archiveId);
|
|
|
+ if (null == archive) {
|
|
|
+ return ResponseJson.error("商品资料不存在", null);
|
|
|
+ }
|
|
|
+ // 判断该用户是否拥有访问该资料的权限
|
|
|
+ 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 == finalPermission) {
|
|
|
+ imageArchive.setImageList(imageList);
|
|
|
+ }
|
|
|
+ imageArchive.setImageNum(imageList.size());
|
|
|
+ });
|
|
|
+ videoArchiveList.forEach(videoArchive->{
|
|
|
+ ArchiveFilePo archiveFile = pageMapper.getArchiveFile(videoArchive.getArchiveContentId());
|
|
|
+ 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 == finalPermission) {
|
|
|
+ String fileUrl = generateFileUrl(archiveFile);
|
|
|
+ fileArchive.setFileUrl(fileUrl);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ ArchiveDetailVo archiveDetail = new ArchiveDetailVo();
|
|
|
+ archiveDetail.setImageArchiveList(imageArchiveList);
|
|
|
+ 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(ArchivePo archive, Integer userId) {
|
|
|
+ //资料等级:1一类资料,2二类资料,3三类资料
|
|
|
+ Integer archiveLevel = archive.getArchiveLevel();
|
|
|
+ //商品分类: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无权限查看
|
|
|
+ int permission;
|
|
|
+ if (null == identity) {
|
|
|
+ // 未登录
|
|
|
+ permission = 1;
|
|
|
+ } else if (1 == identity) {
|
|
|
+ //协销可查看所有资料
|
|
|
+ permission = 0;
|
|
|
+ } else if (4 == identity) {
|
|
|
+ // 普通机构
|
|
|
+ if (archiveLevel > 1) {
|
|
|
+ // 二级资料,普通机构
|
|
|
+ permission = 2 == productClassify ? 2 : 3;
|
|
|
+ } else {
|
|
|
+ permission = 0;
|
|
|
+ }
|
|
|
+ } else if (2 == identity) {
|
|
|
+ // 会员机构
|
|
|
+ if (2 == archiveLevel && 1 == productClassify && (0 == clubType || 2 == clubType)) {
|
|
|
+ // 二级医美资料,生美会员机构
|
|
|
+ permission = 3;
|
|
|
+ } else if (3 == archiveLevel) {
|
|
|
+ // 查询用户对该资料的抵扣记录
|
|
|
+ Integer historyId = pageMapper.findBeansHistoryByArchiveId(userId, archive.getArchiveId());
|
|
|
+ if (1 == productClassify && (0 == clubType || 2 == clubType)) {
|
|
|
+ // 三级医美资料,生美会员机构
|
|
|
+ permission = 3;
|
|
|
+ } else if (null == historyId){
|
|
|
+ permission = 4;
|
|
|
+ } else {
|
|
|
+ permission = 0;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ permission = 0;
|
|
|
+ }
|
|
|
+ } else{
|
|
|
+ permission = 5;
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
}
|