Browse Source

百科相关推荐

Aslee 2 years ago
parent
commit
00615809e2

+ 10 - 4
pom.xml

@@ -102,12 +102,12 @@
         <dependency>
             <groupId>com.aliyun</groupId>
             <artifactId>aliyun-java-sdk-core</artifactId>
-            <version>4.5.18</version>
+            <version>4.0.6</version>
         </dependency>
         <dependency>
             <groupId>com.aliyun</groupId>
             <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
-            <version>2.1.0</version>
+            <version>1.1.0</version>
         </dependency>
         <!--邮箱发送-->
         <dependency>
@@ -160,8 +160,14 @@
         <dependency>
             <groupId>com.aliyun.oss</groupId>
             <artifactId>aliyun-sdk-oss</artifactId>
-            <version>3.12.0</version>
-        </dependency>
+            <version>3.10.2</version>
+        </dependency>
+        <!-- oss获取token -->
+<!--        <dependency>-->
+<!--            <groupId>com.aliyun</groupId>-->
+<!--            <artifactId>aliyun-java-sdk-sts</artifactId>-->
+<!--            <version>3.0.0</version>-->
+<!--        </dependency>-->
     </dependencies>
 
     <profiles>

+ 8 - 0
src/main/java/com/caimei365/user/controller/BaseApi.java

@@ -1,5 +1,6 @@
 package com.caimei365.user.controller;
 
+import com.aliyuncs.exceptions.ClientException;
 import com.caimei365.user.model.ResponseJson;
 import com.caimei365.user.model.dto.MobileDto;
 import com.caimei365.user.model.dto.PasswordDto;
@@ -10,6 +11,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -189,4 +191,10 @@ public class BaseApi {
     public ResponseJson findPackage(){
         return baseService.findPackage();
     }
+
+    @ApiOperation("获取阿里云token")
+    @GetMapping("/oss/token")
+    public ResponseJson<HashMap<String, String>> ossTokenGet() throws ClientException {
+        return baseService.ossTokenGet();
+    }
 }

+ 72 - 0
src/main/java/com/caimei365/user/controller/ShopApi.java

@@ -5,6 +5,7 @@ import com.caimei365.user.model.dto.BaikeProductDto;
 import com.caimei365.user.model.dto.ShopArticleDto;
 import com.caimei365.user.model.dto.ShopBannerDto;
 import com.caimei365.user.model.dto.ShopUpdateDto;
+import com.caimei365.user.model.po.BaikeProductPo;
 import com.caimei365.user.model.vo.*;
 import com.caimei365.user.service.ShopService;
 import com.github.pagehelper.PageInfo;
@@ -236,12 +237,14 @@ public class ShopApi {
     }
 
     @ApiOperation("百科商品分类列表")
+    @ApiImplicitParam(required = true, name = "commodityType",value = "百科分类:1产品,2仪器")
     @GetMapping("/baike/product/type/list")
     public ResponseJson<List<BaikeProductTypeVo>> getBaikeProductTypeList(Integer commodityType){
         return shopService.getBaikeProductTypeList(commodityType);
     }
 
     @ApiOperation("删除百科商品")
+    @ApiImplicitParam(required = true, name = "productId",value = "百科商品id")
     @PostMapping("/baike/product/delete")
     public ResponseJson<Void> deleteBaikeProduct(Integer productId){
         return shopService.deleteBaikeProduct(productId);
@@ -257,5 +260,74 @@ public class ShopApi {
         return shopService.getSensitiveWords(checkPoint);
     }
 
+    @ApiOperation("百科相关推荐表单")
+    @ApiImplicitParam(required = true, name = "productId", value = "百科产品id")
+    @GetMapping("/baike/recommend/form")
+    public ResponseJson<Map<String,Object>> baikeRecommendForm(Integer productId){
+        return shopService.getBaikeRecommendForm(productId);
+    }
+
+    @ApiOperation("百科相关推荐添加产品列表")
+    @ApiImplicitParams({
+            @ApiImplicitParam(required = true, name = "productId", value = "百科产品id"),
+            @ApiImplicitParam(required = false, name = "typeId", value = "分类id"),
+            @ApiImplicitParam(required = false, name = "name", value = "名称"),
+            @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+            @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
+    })
+    @GetMapping("/baike/recommend/add/list")
+    public ResponseJson<PageInfo<BaikeProductListVo>> addRecommendList(Integer productId, Integer typeId, String name,
+                                                                     @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
+                                                                     @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
+        if (null == productId) {
+            return ResponseJson.error("百科产品id不能为空", null);
+        }
+        if (null == typeId) {
+            return ResponseJson.error("分类id不能为空", null);
+        }
+        return shopService.getAddRecommendList(productId, typeId, name, pageNum, pageSize);
+    }
+
+    @ApiOperation("百科相关推荐添加产品")
+    @PostMapping("/baike/recommend/add")
+    public ResponseJson<Void> addBaikeRecommend(BaikeProductDto baikeProduct){
+        if (null == baikeProduct.getProductId()) {
+            return ResponseJson.error("商品id不能为空", null);
+        }
+        return shopService.addBaikeRecommend(baikeProduct);
+    }
 
+    @ApiOperation("百科相关推荐删除产品")
+    @ApiImplicitParam(required = true, name = "recommendId", value = "相关推荐id")
+    @PostMapping("/baike/recommend/delete")
+    public ResponseJson<Void> deleteBaikeRecommend(Integer recommendId){
+        if (null == recommendId) {
+            return ResponseJson.error("相关推荐id不能为空", null);
+        }
+        return shopService.deleBaikeRecommend(recommendId);
+    }
+
+    @ApiOperation("百科相关推荐更改排序")
+    @PostMapping("/baike/recommend/sort/save")
+    public ResponseJson<Void> saveRecommendSort(BaikeRecommendVo baikeRecommend){
+        if (null == baikeRecommend.getRecommendId()) {
+            return ResponseJson.error("相关推荐id不能为空", null);
+        }
+        if (null == baikeRecommend.getSort()) {
+            return ResponseJson.error("排序值不能为空", null);
+        }
+        return shopService.saveRecommendSort(baikeRecommend);
+    }
+
+    @ApiOperation("百科相关推荐更改推荐方式")
+    @PostMapping("/baike/recommend/type/save")
+    public ResponseJson<Void> saveRecommendType(BaikeProductDto baikeProduct){
+        if (null == baikeProduct.getProductId()) {
+            return ResponseJson.error("商品id不能为空", null);
+        }
+        if (null == baikeProduct.getRecommendType()) {
+            return ResponseJson.error("推荐类型不能为空", null);
+        }
+        return shopService.saveRecommendType(baikeProduct);
+    }
 }

+ 17 - 0
src/main/java/com/caimei365/user/mapper/BaikeProductMapper.java

@@ -8,6 +8,7 @@ import com.caimei365.user.model.po.BaikeProductQuestionPo;
 import com.caimei365.user.model.vo.BaikeProductFormVo;
 import com.caimei365.user.model.vo.BaikeProductListVo;
 import com.caimei365.user.model.vo.BaikeProductTypeVo;
+import com.caimei365.user.model.vo.BaikeRecommendVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -79,4 +80,20 @@ public interface BaikeProductMapper {
     void insertProductFile(@Param("fileTitle") String fileTitle, @Param("fileName") String fileName, @Param("ossName") String ossName, @Param("productId") Integer productId);
 
     List<BaikeProductFilePo> getVideoList(Integer productId);
+
+    List<BaikeRecommendVo> getManualRecommendList(Integer productId);
+
+    List<BaikeRecommendVo> getAutoRecommendList(@Param("shopId") Integer shopId, @Param("productTypeId") Integer productTypeId, @Param("productId") Integer productId);
+
+    void updateRecommendType(Integer productId, Integer recommendType);
+
+    void clearRecommendData(Integer productId);
+
+    void insertRecommend(BaikeRecommendVo recommond);
+
+    String getRecommendProductIds(Integer productId);
+
+    void deleteBaikeRecommend(Integer recommendId);
+
+    void updateRecommendSort(BaikeRecommendVo baikeRecommend);
 }

+ 11 - 3
src/main/java/com/caimei365/user/model/dto/BaikeProductDto.java

@@ -1,12 +1,10 @@
 package com.caimei365.user.model.dto;
 
-import com.caimei365.user.model.po.BaikeProductParamPo;
-import com.caimei365.user.model.po.BaikeProductQuestionPo;
+import com.caimei365.user.model.vo.BaikeRecommendVo;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
-import java.util.Date;
 import java.util.List;
 
 
@@ -113,4 +111,14 @@ public class BaikeProductDto {
 
 	@ApiModelProperty("视频文件列表")
 	private String videoList;
+
+	@ApiModelProperty("已选中的商品id,以,隔开")
+	private String productIds;
+
+	@ApiModelProperty("推荐类型:1手动推荐,2自动推荐")
+	private Integer recommendType;
+
+	@ApiModelProperty("百科相关推荐商品列表")
+    private String baikeRecommendList;
+
 }

+ 10 - 0
src/main/java/com/caimei365/user/model/vo/BaikeProductFormVo.java

@@ -25,6 +25,11 @@ public class BaikeProductFormVo {
 	 */
 	private Integer productId;
 
+	/**
+	 * 供应商id
+	 */
+	private Integer shopId;
+
 	/**
 	 * 分类:1产品,2仪器
 	 */
@@ -164,4 +169,9 @@ public class BaikeProductFormVo {
 	 * 视频列表
 	 */
 	private List<BaikeProductFilePo> videoList;
+
+	/**
+	 * 推荐类型:1手动推荐,2自动推荐
+	 */
+	private Integer recommendType;
 }

+ 45 - 0
src/main/java/com/caimei365/user/model/vo/BaikeRecommendVo.java

@@ -0,0 +1,45 @@
+package com.caimei365.user.model.vo;
+
+import com.caimei365.user.model.po.BaikeProductFilePo;
+import com.caimei365.user.model.po.BaikeProductParamPo;
+import com.caimei365.user.model.po.BaikeProductQuestionPo;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+
+/**
+ * Description
+ * @author Aslee
+ * @version 2021-12-10
+ */
+@ApiModel("百科商品相关推荐")
+@Data
+public class BaikeRecommendVo {
+	/**
+	 * 相关推荐id
+	 */
+	private Integer recommendId;
+
+	/**
+	 * 百科商品id
+	 */
+	private Integer productId;
+
+	/**
+	 * 相关推荐产品/仪器id
+	 */
+	private Integer recommendProductId;
+
+	/**
+	 * 排序值
+	 */
+	private Integer sort;
+
+	/**
+	 * 相关推荐产品/仪器名称
+	 */
+	private String recommendProductName;
+}

+ 4 - 0
src/main/java/com/caimei365/user/service/BaseService.java

@@ -1,9 +1,11 @@
 package com.caimei365.user.service;
 
+import com.aliyuncs.exceptions.ClientException;
 import com.caimei365.user.model.ResponseJson;
 import com.caimei365.user.model.dto.MobileDto;
 import com.caimei365.user.model.dto.PasswordDto;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
@@ -100,4 +102,6 @@ public interface BaseService {
      * @return
      */
     ResponseJson findPackage();
+
+    ResponseJson<HashMap<String, String>> ossTokenGet() throws ClientException;
 }

+ 44 - 1
src/main/java/com/caimei365/user/service/ShopService.java

@@ -155,7 +155,7 @@ public interface ShopService {
 
     /**
      * 获取供应商百科商品表单数据
-     * @param baikeProductId     百科商品id
+     * @param productId     百科商品id
      * @return
      */
     ResponseJson<BaikeProductFormVo> getBaikeProductById(Integer productId);
@@ -194,4 +194,47 @@ public interface ShopService {
      * @return
      */
     ResponseJson<String> getSensitiveWords(Integer checkPoint);
+
+    /**
+     * 获取供应商百科商品相关推荐表单数据
+     * @param productId  百科商品id
+     * @return
+     */
+    ResponseJson<Map<String, Object>> getBaikeRecommendForm(Integer productId);
+
+    /**
+     * 保存百科相关推荐推荐类型
+     * @param baikeProductDto
+     * @return
+     */
+    ResponseJson<Void> saveRecommendType(BaikeProductDto baikeProductDto);
+
+    /**
+     * 百科相关推荐添加产品列表
+     *
+     * @param productId
+     * @return
+     */
+    ResponseJson<PageInfo<BaikeProductListVo>> getAddRecommendList(Integer productId, Integer typeId, String name, int pageNum, int pageSize);
+
+    /**
+     * 添加百科相关推荐
+     * @param baikeRecommend
+     * @return
+     */
+    ResponseJson<Void> addBaikeRecommend(BaikeProductDto baikeProduct);
+
+    /**
+     * 删除百科相关推荐
+     * @param recommendId
+     * @return
+     */
+    ResponseJson<Void> deleBaikeRecommend(Integer recommendId);
+
+    /**
+     * 保存百科相关推荐排序
+     * @param baikeRecommend
+     * @return
+     */
+    ResponseJson<Void> saveRecommendSort(BaikeRecommendVo baikeRecommend);
 }

+ 7 - 0
src/main/java/com/caimei365/user/service/impl/BaseServiceImpl.java

@@ -1,5 +1,7 @@
 package com.caimei365.user.service.impl;
 
+import com.aliyun.oss.internal.OSSUtils;
+import com.aliyuncs.exceptions.ClientException;
 import com.caimei365.user.components.CommonService;
 import com.caimei365.user.components.RedisService;
 import com.caimei365.user.mapper.BaseMapper;
@@ -519,6 +521,11 @@ public class BaseServiceImpl implements BaseService {
         return ResponseJson.success(pac);
     }
 
+    @Override
+    public ResponseJson<HashMap<String, String>> ossTokenGet() throws ClientException {
+        return ResponseJson.success(OssUtil.getToken());
+    }
+
     /**
      * 根据userId查是否过期,返回dto对象,flag=0未买过,-1过期,1有效,endTime过期时间
      */

+ 67 - 1
src/main/java/com/caimei365/user/service/impl/ShopServiceImpl.java

@@ -593,7 +593,7 @@ public class ShopServiceImpl implements ShopService {
         // 保存展示图片
         List<String> displayImageList = baikeProductDto.getDisplayImageList();
         if (null != displayImageList) {
-            displayImageList.forEach(diplayImage-> baikeProductMapper.insertProductImage(diplayImage, productId, 2));
+            displayImageList.forEach(displayImage-> baikeProductMapper.insertProductImage(displayImage, productId, 2));
         }
         // 保存问题
         JSONArray questionArray = JSONArray.parseArray(baikeProductDto.getQuestionList());
@@ -693,4 +693,70 @@ public class ShopServiceImpl implements ShopService {
         return ResponseJson.success(sensitiveWords);
     }
 
+    @Override
+    public ResponseJson<Map<String, Object>> getBaikeRecommendForm(Integer productId) {
+        HashMap<String, Object> map = new HashMap<>();
+        BaikeProductFormVo baikeProduct = baikeProductMapper.getBaikeProductById(productId);
+        Integer productTypeId = baikeProduct.getTypeId();
+        Integer recommendType = baikeProduct.getRecommendType();
+        Integer shopId = baikeProduct.getShopId();
+        // 手动推荐列表
+        List<BaikeRecommendVo> manualRecommendList = baikeProductMapper.getManualRecommendList(productId);
+        // 自动推荐列表
+        List<BaikeRecommendVo> autoRecommendList = baikeProductMapper.getAutoRecommendList(shopId, productTypeId, productId);
+        autoRecommendList.forEach(authRecommend->{
+            authRecommend.setProductId(productId);
+        });
+        map.put("manualRecommendList", manualRecommendList);
+        map.put("autoRecommendList", autoRecommendList);
+        map.put("recommendType", recommendType);
+        return ResponseJson.success(map);
+    }
+
+    @Override
+    public ResponseJson<Void> saveRecommendType(BaikeProductDto baikeProductDto) {
+        baikeProductMapper.updateRecommendType(baikeProductDto.getProductId(), baikeProductDto.getRecommendType());
+        return ResponseJson.success(null);
+    }
+
+    @Override
+    public ResponseJson<PageInfo<BaikeProductListVo>> getAddRecommendList(Integer productId, Integer typeId, String name, int pageNum, int pageSize) {
+        BaikeProductDto baikeProductDto = new BaikeProductDto();
+        baikeProductDto.setTypeId(typeId);
+        baikeProductDto.setName(name);
+        BaikeProductFormVo baikeProduct = baikeProductMapper.getBaikeProductById(productId);
+        baikeProductDto.setShopId(baikeProduct.getShopId());
+        // 已推荐产品id,以,隔开
+        String productIds = baikeProductMapper.getRecommendProductIds(productId);
+        productIds += "".equals(productIds) ? productId : "," + productId;
+        baikeProductDto.setProductIds(productIds);
+        PageHelper.startPage(pageNum, pageSize);
+        List<BaikeProductListVo> addRecommendList = baikeProductMapper.getBaikeProductList(baikeProductDto);
+        PageInfo<BaikeProductListVo> pageInfo = new PageInfo<>(addRecommendList);
+        return ResponseJson.success(pageInfo);
+    }
+
+    @Override
+    public ResponseJson<Void> addBaikeRecommend(BaikeProductDto baikeProduct) {
+        String baikeRecommendList = baikeProduct.getBaikeRecommendList();
+        List<BaikeRecommendVo> recommendList = JSONObject.parseArray(baikeRecommendList, BaikeRecommendVo.class);
+        recommendList.forEach(baikeRecommend -> {
+            baikeRecommend.setProductId(baikeProduct.getProductId());
+            baikeProductMapper.insertRecommend(baikeRecommend);
+        });
+        return ResponseJson.success(null);
+    }
+
+    @Override
+    public ResponseJson<Void> deleBaikeRecommend(Integer recommendId) {
+        baikeProductMapper.deleteBaikeRecommend(recommendId);
+        return ResponseJson.success(null);
+    }
+
+    @Override
+    public ResponseJson<Void> saveRecommendSort(BaikeRecommendVo baikeRecommend) {
+        baikeProductMapper.updateRecommendSort(baikeRecommend);
+        return ResponseJson.success(null);
+    }
+
 }

+ 1 - 1
src/main/java/com/caimei365/user/utils/AliyunSmsUtil.java

@@ -110,7 +110,7 @@ public class AliyunSmsUtil {
             //请求成功
             return sendSmsResponse.getCode() != null && "OK".equals(sendSmsResponse.getCode());
         } catch (ClientException e) {
-            log.error(e.getErrCode(), e.getErrMsg(), e.getErrorDescription());
+            log.error(e.getErrCode(), e.getErrMsg(), e.getMessage());
             return false;
         }
     }

+ 81 - 0
src/main/java/com/caimei365/user/utils/OssUtil.java

@@ -5,6 +5,14 @@ import com.aliyun.oss.OSSClientBuilder;
 import com.aliyun.oss.model.GetObjectRequest;
 import com.aliyun.oss.model.ObjectMetadata;
 import com.aliyun.oss.model.UploadFileRequest;
+import com.aliyuncs.DefaultAcsClient;
+import com.aliyuncs.IAcsClient;
+import com.aliyuncs.auth.sts.AssumeRoleRequest;
+import com.aliyuncs.auth.sts.AssumeRoleResponse;
+import com.aliyuncs.exceptions.ClientException;
+import com.aliyuncs.http.MethodType;
+import com.aliyuncs.profile.DefaultProfile;
+import com.aliyuncs.profile.IClientProfile;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
 import org.springframework.web.multipart.MultipartFile;
@@ -12,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile;
 import java.io.File;
 import java.io.IOException;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.UUID;
 
 
@@ -35,6 +44,78 @@ public class OssUtil {
     }
 
 
+    public static HashMap<String, String> getToken() {
+        //构建一个阿里云客户端,用于发起请求。
+        //设置调用者(RAM用户或RAM角色)的AccessKey ID和AccessKey Secret。
+//        DefaultProfile.addEndpoint("oss-cn-shenzhen", "Sts", endpoint.replace("https://",""));
+        DefaultProfile profile = DefaultProfile.getProfile("oss-cn-shenzhen", accessKeyId, accessKeySecret);
+        IAcsClient client = new DefaultAcsClient(profile);
+
+        //构造请求,设置参数。
+        AssumeRoleRequest request = new AssumeRoleRequest();
+        request.setRegionId(endpoint);
+        request.setRoleArn("acs:ram::1565565840178476:role/caimeitst");
+        request.setRoleSessionName("TSTtest");
+        AssumeRoleResponse response = null;
+        try {
+            response = client.getAcsResponse(request);
+        } catch (ClientException e) {
+            e.printStackTrace();
+        }
+        String requestId = response.getRequestId();
+        String securityToken = response.getCredentials().getSecurityToken();
+        String accessKeySecret = response.getCredentials().getAccessKeySecret();
+        String accessKeyId = response.getCredentials().getAccessKeyId();
+        HashMap<String, String> tokenMap = new HashMap<>(5);
+        tokenMap.put("requestId", requestId);
+        tokenMap.put("accessKeyId", accessKeyId);
+        tokenMap.put("accessKeySecret", accessKeySecret);
+        tokenMap.put("securityToken", securityToken);
+        tokenMap.put("bucket", privateBucket);
+        return tokenMap;
+    }
+
+
+    /*public static HashMap<String, String> getToken() throws ClientException {
+        // regionId表示RAM的地域ID。以华东1(杭州)地域为例,regionID填写为cn-hangzhou。也可以保留默认值,默认值为空字符串("")。
+        String regionId = "";
+        // 添加endpoint。适用于Java SDK 3.12.0及以上版本。
+        DefaultProfile.addEndpoint(regionId, "Sts", endpoint.replace("https://",""));
+        // 添加endpoint。适用于Java SDK 3.12.0以下版本。
+        // DefaultProfile.addEndpoint("",regionId, "Sts", endpoint);
+        // 构造default profile。
+        IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyId, accessKeySecret);
+        // 构造client。
+        DefaultAcsClient client = new DefaultAcsClient(profile);
+        final AssumeRoleRequest request = new AssumeRoleRequest();
+        // 适用于Java SDK 3.12.0及以上版本。
+        request.setSysMethod(MethodType.POST);
+        // 适用于Java SDK 3.12.0以下版本。
+        //request.setMethod(MethodType.POST);
+        request.setRoleArn("acs:ram::1565565840178476:role/caimeitst");
+        request.setRoleSessionName("TSTtest");
+        request.setPolicy();
+//        request.setPolicy(null); // 如果policy为空,则用户将获得该角色下所有权限。
+        request.setDurationSeconds(3600L); // 设置临时访问凭证的有效时间为3600秒。
+        final AssumeRoleResponse response = client.getAcsResponse(request);
+        System.out.println("Expiration: " + response.getCredentials().getExpiration());
+        System.out.println("Access Key Id: " + response.getCredentials().getAccessKeyId());
+        System.out.println("Access Key Secret: " + response.getCredentials().getAccessKeySecret());
+        System.out.println("Security Token: " + response.getCredentials().getSecurityToken());
+        System.out.println("RequestId: " + response.getRequestId());
+
+        String requestId = response.getRequestId();
+        String securityToken = response.getCredentials().getSecurityToken();
+        String accessKeySecret = response.getCredentials().getAccessKeySecret();
+        String accessKeyId = response.getCredentials().getAccessKeyId();
+        HashMap<String, String> tokenMap = new HashMap<>(5);
+        tokenMap.put("requestId", requestId);
+        tokenMap.put("accessKeyId", accessKeyId);
+        tokenMap.put("accessKeySecret", accessKeySecret);
+        tokenMap.put("securityToken", securityToken);
+        tokenMap.put("bucket", privateBucket);
+        return tokenMap;
+    }*/
 
     public static String ossUpload(String fileName, File file, String contentType) {
         String url = null;

+ 68 - 1
src/main/resources/mapper/BaikeProductMapper.xml

@@ -30,6 +30,14 @@
         insert into cm_baike_product_file (productId, fileTitle, fileName, ossName)
         values (#{productId}, #{fileTitle}, #{fileName}, #{ossName})
     </insert>
+    <insert id="insertRecommend">
+        INSERT INTO cm_baike_product_recommend(productId,
+                                               recommendProductId,
+                                               sort)
+        VALUES (#{productId},
+                #{recommendProductId},
+                #{sort})
+    </insert>
     <update id="updateBaikeProduct">
         update cm_baike_product
         set name            = #{name},
@@ -64,6 +72,14 @@
     <update id="deleteBaikeProduct">
         update cm_baike_product set delFlag = 1 where id = #{productId}
     </update>
+    <update id="updateRecommendType">
+        update cm_baike_product
+        set recommendType = #{recommendType}
+        where id = #{productId}
+    </update>
+    <update id="updateRecommendSort">
+        update cm_baike_product_recommend set sort = #{sort} where id = #{recommendId}
+    </update>
     <delete id="deleteParamsByProductId">
         delete from cm_baike_product_param where productId = #{productId}
     </delete>
@@ -76,8 +92,19 @@
     <delete id="deleteFilesByProductId">
         delete from cm_baike_product_file where productId = #{productId}
     </delete>
+    <delete id="clearRecommendData">
+        delete
+        from cm_baike_product_recommend
+        where productId = #{productId}
+    </delete>
+    <delete id="deleteBaikeRecommend">
+        delete
+        from cm_baike_product_recommend
+        where id = #{recommendId}
+    </delete>
     <select id="getBaikeProductById" resultType="com.caimei365.user.model.vo.BaikeProductFormVo">
         select id as productId,
+               shopId,
                commodityType,
                name,
                alias,
@@ -99,6 +126,7 @@
                unAdaptiveMan,
                aroundOperation,
                typeId,
+               recommendType,
                status
         from cm_baike_product
         where id = #{productId} and delFlag = 0
@@ -120,7 +148,10 @@
                p.status
         from cm_baike_product p
                  left join cm_baike_type cbt on p.typeId = cbt.id
-        where shopId = #{shopId} and publishSource = 2 and commodityType = #{commodityType} and delFlag = 0
+        where shopId = #{shopId} and publishSource = 2 and delFlag = 0
+        <if test="commodityType != null">
+            and p.commodityType = #{commodityType}
+        </if>
         <if test="productId != null">
             and p.id = #{productId}
         </if>
@@ -139,6 +170,12 @@
         <if test="onlineStatus != null">
             and onlineStatus = #{onlineStatus}
         </if>
+        <if test="productIds != null and productIds != ''">
+            and p.id not in
+            <foreach item="productId" collection="productIds.split(',')" open="(" separator="," close=")">
+                #{productId}
+            </foreach>
+        </if>
         order by p.addTime desc
     </select>
     <select id="getParamList" resultType="com.caimei365.user.model.po.BaikeProductParamPo">
@@ -157,4 +194,34 @@
         from cm_baike_product_file
         where productId = #{productId}
     </select>
+    <select id="getManualRecommendList" resultType="com.caimei365.user.model.vo.BaikeRecommendVo">
+        select cbpr.id as recommendId, productId, recommendProductId, p.name as recommendProductName, sort
+        from cm_baike_product_recommend cbpr
+                 left join cm_baike_product p on cbpr.recommendProductId = p.id
+        where productId = #{productId}
+          and p.delFlag = 0
+        order by -cbpr.sort desc
+    </select>
+    <select id="getAutoRecommendList" resultType="com.caimei365.user.model.vo.BaikeRecommendVo">
+        select p.id as recommendProductId, p.name as recommendProductName
+        from cm_baike_product p
+        where typeId = #{productTypeId}
+          <if test="shopId != null">
+              and shopId = #{shopId}
+          </if>
+          <if test="productId != null">
+              and id != #{productId}
+          </if>
+          and p.delFlag = 0
+          and p.status = 1
+          and p.onlineStatus = 2
+        order by p.addTime desc
+        limit 15
+    </select>
+    <select id="getRecommendProductIds" resultType="java.lang.String">
+        select group_concat(recommendProductId)
+        from cm_baike_product_recommend
+        where productId = #{productId}
+        group by productId;
+    </select>
 </mapper>