소스 검색

商品资料bug fix

Aslee 3 년 전
부모
커밋
d2720547ec

+ 6 - 4
pom.xml

@@ -157,10 +157,6 @@
             <version>3.0.0</version>
         </dependency>
 
-
-
-
-
 		<dependency>
 			<groupId>org.springframework.boot</groupId>
 			<artifactId>spring-boot-starter-test</artifactId>
@@ -179,6 +175,12 @@
             <version>3.2.1-1.3</version>
         </dependency>
 
+        <!--对象存储oss-->
+        <dependency>
+            <groupId>com.aliyun.oss</groupId>
+            <artifactId>aliyun-sdk-oss</artifactId>
+            <version>3.10.2</version>
+        </dependency>
     </dependencies>
 
     <profiles>

+ 11 - 0
src/main/java/com/caimei365/commodity/model/po/ArchiveFilePo.java

@@ -1,10 +1,12 @@
 package com.caimei365.commodity.model.po;
 
 import com.caimei365.commodity.model.vo.ArchiveContentVo;
+import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -25,4 +27,13 @@ public class ArchiveFilePo implements Serializable {
      * 文件oss链接
      */
     private String fileUrl;
+    /**
+     * oss名称
+     */
+    private String ossName;
+    /**
+     * 上传时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date uploadTime;
 }

+ 4 - 0
src/main/java/com/caimei365/commodity/model/vo/ArchiveContentVo.java

@@ -37,6 +37,10 @@ public class ArchiveContentVo implements Serializable {
      * 文件oss链接
      */
     private String fileUrl;
+    /**
+     * 文件oss链接
+     */
+    private String htmlUrl;
     /**
      * 资料标题
      */

+ 64 - 15
src/main/java/com/caimei365/commodity/service/impl/PageServiceImpl.java

@@ -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;
+    }
 }

+ 6 - 0
src/main/java/com/caimei365/commodity/utils/AppletsLinkUtil.java

@@ -134,6 +134,10 @@ public class AppletsLinkUtil {
      * 24美博会优惠券页
      */
     public static final Pattern pattern40 = Pattern.compile("/user/beautyfair");
+    /**
+     * 25商品资料库列表
+     */
+    public static final Pattern pattern41 = Pattern.compile("/document/beauty-archive.html");
 
     /**
      * 根据链接判断链接类型
@@ -190,6 +194,8 @@ public class AppletsLinkUtil {
                 return 23;
             } else if (pattern40.matcher(link).find()) {
                 return 24;
+            } else if (pattern41.matcher(link).find()) {
+                return 25;
             } else {
                 return -1;
             }

+ 16 - 3
src/main/resources/mapper/PageMapper.xml

@@ -429,32 +429,45 @@
                 cpa.productType = #{productType})
             </if>
         </where>
+        order by cpa.addTime desc
     </select>
     <select id="getImageArchiveList" resultType="com.caimei365.commodity.model.vo.ArchiveContentVo">
         select id as archiveContentId, title, addTime
         from cm_product_archive_content
         where productArchiveId = #{archiveId} and type = 1
+        order by addTime desc
     </select>
     <select id="getVideoArchiveList" resultType="com.caimei365.commodity.model.vo.ArchiveContentVo">
         select id as archiveContentId, title, addTime
         from cm_product_archive_content
         where productArchiveId = #{archiveId} and type = 2
+        order by addTime desc
     </select>
     <select id="getFileArchiveList" resultType="com.caimei365.commodity.model.vo.ArchiveContentVo">
         select id as archiveContentId, title, addTime
         from cm_product_archive_content
         where productArchiveId = #{archiveId} and type = 3
+        order by addTime desc
     </select>
     <select id="getArchiveImageList" resultType="java.lang.String">
         select ossUrl from cm_product_archive_file where archiveContentId = #{archiveContentId}
     </select>
     <select id="getArchiveFile" resultType="com.caimei365.commodity.model.po.ArchiveFilePo">
-        select fileName,ossUrl as fileUrl from cm_product_archive_file where archiveContentId = #{archiveContentId}
+        select fileName,ossName,uploadTime from cm_product_archive_file where archiveContentId = #{archiveContentId}
     </select>
     <select id="getArchiveByArchiveId" resultType="com.caimei365.commodity.model.po.ArchivePo">
-        select cpa.archiveLevel    AS "archiveLevel",
-               cpa.productClassify AS "productClassify"
+        select cpa.id                                                                                   AS "archiveId",
+               cpa.productId                                                                            AS "productId",
+               if(cpa.productId is not null, p.name, cpa.productName)                                   AS "productName",
+               if(cpa.productId is not null, s.name, cpa.shopName)                                      AS "shopName",
+               if(cpa.productId is not null, p.mainImage, cpa.productImage)                             AS "productImage",
+               cpa.archiveLevel                                                                         AS "archiveLevel",
+               if(cpa.productId is not null, ifnull(p.commodityType, cpa.productType),
+                  cpa.productType)                                                                      AS "productType",
+               cpa.productClassify                                                                      AS "productClassify"
         from cm_product_archive cpa
+                 left join product p on cpa.productId = p.productID
+                 left join shop s on p.shopID = s.shopID
         where cpa.id = #{archiveId}
     </select>
     <select id="getClubTypeByUserId" resultType="java.lang.Integer">