Authored by caoyan

UFO比价

  1 +package com.yoho.ufo.dal;
  2 +
  3 +import java.util.List;
  4 +
  5 +import org.apache.ibatis.annotations.Param;
  6 +
  7 +import com.yoho.ufo.model.ChannelSkuCompare;
  8 +import com.yoho.ufo.model.ChannelSkuCompareReq;
  9 +
  10 +/**
  11 + * Created by caoyan.
  12 + */
  13 +public interface ChannelSkuCompareMapper {
  14 +
  15 + int selectTotalByCondition(@Param("channelSkuCompareReq") ChannelSkuCompareReq req);
  16 +
  17 + List<ChannelSkuCompare> selectByCondition(@Param("channelSkuCompareReq") ChannelSkuCompareReq req);
  18 +
  19 +}
@@ -2,7 +2,6 @@ package com.yoho.ufo.dal; @@ -2,7 +2,6 @@ package com.yoho.ufo.dal;
2 2
3 import java.util.List; 3 import java.util.List;
4 4
5 -import com.yoho.ufo.model.brand.Brand;  
6 import org.apache.ibatis.annotations.Param; 5 import org.apache.ibatis.annotations.Param;
7 6
8 import com.yoho.ufo.dal.model.Product; 7 import com.yoho.ufo.dal.model.Product;
@@ -72,4 +71,6 @@ public interface ProductMapper { @@ -72,4 +71,6 @@ public interface ProductMapper {
72 int selectProductStorageCount(@Param("product")Product product); 71 int selectProductStorageCount(@Param("product")Product product);
73 72
74 List<Product> selectProductStorageList(@Param("product")Product product, @Param("start")int start, @Param("rows")Integer rows); 73 List<Product> selectProductStorageList(@Param("product")Product product, @Param("start")int start, @Param("rows")Integer rows);
  74 +
  75 + List<Product> selectByProductName(@Param("productName") String productName);
75 } 76 }
@@ -2,7 +2,6 @@ package com.yoho.ufo.dal; @@ -2,7 +2,6 @@ package com.yoho.ufo.dal;
2 2
3 import java.util.List; 3 import java.util.List;
4 4
5 -import com.yoho.ufo.dal.model.Product;  
6 import org.apache.ibatis.annotations.Param; 5 import org.apache.ibatis.annotations.Param;
7 6
8 import com.yoho.ufo.dal.model.StoragePrice; 7 import com.yoho.ufo.dal.model.StoragePrice;
@@ -47,4 +46,6 @@ public interface StoragePriceMapper { @@ -47,4 +46,6 @@ public interface StoragePriceMapper {
47 46
48 // 根据SKup等信息查询其所属productId列表 最多查询出最新的300 productId 47 // 根据SKup等信息查询其所属productId列表 最多查询出最新的300 productId
49 List<Integer> selectProductIdsBySkupInfo(@Param("storagePrice")StoragePrice storagePrice); 48 List<Integer> selectProductIdsBySkupInfo(@Param("storagePrice")StoragePrice storagePrice);
  49 +
  50 + List<StoragePrice> selectMinPriceByStorageIdList(@Param("list") List<Integer> storageIdList);
50 } 51 }
1 package com.yoho.ufo.dal; 1 package com.yoho.ufo.dal;
2 2
3 -import com.yoho.ufo.model.commoditybasicrole.color.ProductColor;  
4 -import com.yoho.ufo.model.commoditybasicrole.size.Size;  
5 -import com.yohobuy.ufo.model.common.PageModel; 3 +import java.util.List;
  4 +
6 import org.apache.ibatis.annotations.Param; 5 import org.apache.ibatis.annotations.Param;
7 6
8 -import java.util.List; 7 +import com.yoho.ufo.model.commoditybasicrole.size.Size;
  8 +import com.yohobuy.ufo.model.common.PageModel;
9 9
10 /** 10 /**
11 * 品类mapper 11 * 品类mapper
@@ -83,4 +83,11 @@ public interface UfoSizeMapper { @@ -83,4 +83,11 @@ public interface UfoSizeMapper {
83 * @return 83 * @return
84 */ 84 */
85 List<Size> selectAllSize(); 85 List<Size> selectAllSize();
  86 +
  87 + /**
  88 + * 根据尺码名称查询尺码对象
  89 + * @param sizeName
  90 + * @return
  91 + */
  92 + List<Size> selectBySizeName(@Param("sizeName") String sizeName);
86 } 93 }
1 package com.yoho.ufo.dal.model; 1 package com.yoho.ufo.dal.model;
2 2
  3 +import java.math.BigDecimal;
  4 +
3 public class Storage { 5 public class Storage {
4 private Integer id; 6 private Integer id;
5 7
@@ -14,6 +16,10 @@ public class Storage { @@ -14,6 +16,10 @@ public class Storage {
14 private Integer updateTime; 16 private Integer updateTime;
15 17
16 private Integer createTime; 18 private Integer createTime;
  19 +
  20 + private BigDecimal suggestLowPrice;
  21 +
  22 + private BigDecimal suggestHighPrice;
17 23
18 public Integer getId() { 24 public Integer getId() {
19 return id; 25 return id;
@@ -70,4 +76,21 @@ public class Storage { @@ -70,4 +76,21 @@ public class Storage {
70 public void setCreateTime(Integer createTime) { 76 public void setCreateTime(Integer createTime) {
71 this.createTime = createTime; 77 this.createTime = createTime;
72 } 78 }
  79 +
  80 + public BigDecimal getSuggestLowPrice() {
  81 + return suggestLowPrice;
  82 + }
  83 +
  84 + public void setSuggestLowPrice(BigDecimal suggestLowPrice) {
  85 + this.suggestLowPrice = suggestLowPrice;
  86 + }
  87 +
  88 + public BigDecimal getSuggestHighPrice() {
  89 + return suggestHighPrice;
  90 + }
  91 +
  92 + public void setSuggestHighPrice(BigDecimal suggestHighPrice) {
  93 + this.suggestHighPrice = suggestHighPrice;
  94 + }
  95 +
73 } 96 }
  1 +package com.yoho.ufo.model;
  2 +
  3 +import java.io.Serializable;
  4 +import java.math.BigDecimal;
  5 +
  6 +/**
  7 + * 爬虫跟毒价
  8 + */
  9 +public class ChannelSkuCompare implements Serializable {
  10 +
  11 +
  12 + private static final long serialVersionUID = 1613330087543482073L;
  13 +
  14 + /**
  15 + * 主键
  16 + */
  17 + private Integer id;
  18 +
  19 + /**
  20 + * 商品ID
  21 + */
  22 + private Integer productId;
  23 +
  24 + private Integer sku;
  25 +
  26 + private Integer sizeId;
  27 +
  28 + private BigDecimal channelPrice;
  29 +
  30 + private BigDecimal lowRate;
  31 +
  32 + private BigDecimal highRate;
  33 +
  34 + private Integer updateTime;
  35 +
  36 + private String channelUrl;
  37 +
  38 + public Integer getId() {
  39 + return id;
  40 + }
  41 +
  42 + public void setId(Integer id) {
  43 + this.id = id;
  44 + }
  45 +
  46 + public Integer getProductId() {
  47 + return productId;
  48 + }
  49 +
  50 + public void setProductId(Integer productId) {
  51 + this.productId = productId;
  52 + }
  53 +
  54 + public Integer getSku() {
  55 + return sku;
  56 + }
  57 +
  58 + public void setSku(Integer sku) {
  59 + this.sku = sku;
  60 + }
  61 +
  62 + public Integer getSizeId() {
  63 + return sizeId;
  64 + }
  65 +
  66 + public void setSizeId(Integer sizeId) {
  67 + this.sizeId = sizeId;
  68 + }
  69 +
  70 + public BigDecimal getChannelPrice() {
  71 + return channelPrice;
  72 + }
  73 +
  74 + public void setChannelPrice(BigDecimal channelPrice) {
  75 + this.channelPrice = channelPrice;
  76 + }
  77 +
  78 + public BigDecimal getLowRate() {
  79 + return lowRate;
  80 + }
  81 +
  82 + public void setLowRate(BigDecimal lowRate) {
  83 + this.lowRate = lowRate;
  84 + }
  85 +
  86 + public BigDecimal getHighRate() {
  87 + return highRate;
  88 + }
  89 +
  90 + public void setHighRate(BigDecimal highRate) {
  91 + this.highRate = highRate;
  92 + }
  93 +
  94 + public Integer getUpdateTime() {
  95 + return updateTime;
  96 + }
  97 +
  98 + public void setUpdateTime(Integer updateTime) {
  99 + this.updateTime = updateTime;
  100 + }
  101 +
  102 + public String getChannelUrl() {
  103 + return channelUrl;
  104 + }
  105 +
  106 + public void setChannelUrl(String channelUrl) {
  107 + this.channelUrl = channelUrl;
  108 + }
  109 +
  110 + @Override
  111 + public String toString() {
  112 + return "ProductPool{" +
  113 + "id=" + id +
  114 + ", productId='" + productId +
  115 + ", sku=" + sku +
  116 + ", sizeId=" + sizeId +
  117 + ", channelPrice=" + channelPrice +
  118 + ", lowRate=" + lowRate +
  119 + ", highRate=" + highRate +
  120 + ", updateTime=" + updateTime +
  121 + ", channelUrl=" + channelUrl +
  122 + '}';
  123 + }
  124 +}
  1 +package com.yoho.ufo.model;
  2 +
  3 +import java.util.List;
  4 +
  5 +import com.alibaba.fastjson.JSONObject;
  6 +import com.yoho.ufo.service.model.PageRequestBO;
  7 +
  8 +public class ChannelSkuCompareReq extends PageRequestBO {
  9 +
  10 + /**
  11 + *
  12 + */
  13 + private static final long serialVersionUID = 1L;
  14 +
  15 + private Integer sku;
  16 +
  17 + private Integer productId;
  18 +
  19 + private Integer status;
  20 +
  21 + private String productName;
  22 +
  23 + private String sizeName;
  24 +
  25 + private List<Integer> productIdList;
  26 +
  27 + private List<Integer> sizeIdList;
  28 +
  29 + public Integer getSku() {
  30 + return sku;
  31 + }
  32 +
  33 + public void setSku(Integer sku) {
  34 + this.sku = sku;
  35 + }
  36 +
  37 + public Integer getProductId() {
  38 + return productId;
  39 + }
  40 +
  41 + public void setProductId(Integer productId) {
  42 + this.productId = productId;
  43 + }
  44 +
  45 + public Integer getStatus() {
  46 + return status;
  47 + }
  48 +
  49 + public void setStatus(Integer status) {
  50 + this.status = status;
  51 + }
  52 +
  53 + public String getProductName() {
  54 + return productName;
  55 + }
  56 +
  57 + public void setProductName(String productName) {
  58 + this.productName = productName;
  59 + }
  60 +
  61 + public String getSizeName() {
  62 + return sizeName;
  63 + }
  64 +
  65 + public void setSizeName(String sizeName) {
  66 + this.sizeName = sizeName;
  67 + }
  68 +
  69 + public List<Integer> getProductIdList() {
  70 + return productIdList;
  71 + }
  72 +
  73 + public void setProductIdList(List<Integer> productIdList) {
  74 + this.productIdList = productIdList;
  75 + }
  76 +
  77 + public List<Integer> getSizeIdList() {
  78 + return sizeIdList;
  79 + }
  80 +
  81 + public void setSizeIdList(List<Integer> sizeIdList) {
  82 + this.sizeIdList = sizeIdList;
  83 + }
  84 +
  85 + public String toString() {
  86 + return JSONObject.toJSONString(this);
  87 + }
  88 +}
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.yoho.ufo.dal.ChannelSkuCompareMapper">
  4 + <resultMap id="BaseResultMap" type="com.yoho.ufo.model.ChannelSkuCompare">
  5 + <result column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="product_id" property="productId" jdbcType="INTEGER" />
  7 + <result column="sku" property="sku" jdbcType="INTEGER" />
  8 + <result column="size_id" property="sizeId" jdbcType="INTEGER" />
  9 + <result column="channel_price" property="channelPrice" jdbcType="DECIMAL" />
  10 + <result column="low_rate" property="lowRate" jdbcType="DECIMAL" />
  11 + <result column="high_rate" property="highRate" jdbcType="DECIMAL" />
  12 + <result column="update_time" property="updateTime" jdbcType="INTEGER" />
  13 + <result column="channel_url" property="channelUrl" jdbcType="VARCHAR" />
  14 + </resultMap>
  15 +
  16 + <sql id="Base_Column_List">
  17 + id, product_id, sku, size_id, channel_price, low_rate, high_rate, update_time, channel_url
  18 + </sql>
  19 +
  20 + <sql id="Query_Sql" >
  21 + <if test="channelSkuCompareReq.sku != null and channelSkuCompareReq.sku != 0 ">
  22 + and a.sku = #{channelSkuCompareReq.sku}
  23 + </if>
  24 + <if test="channelSkuCompareReq.productId != null and channelSkuCompareReq.productId != 0 ">
  25 + and a.product_id = #{channelSkuCompareReq.productId}
  26 + </if>
  27 + <if test="channelSkuCompareReq.productIdList != null and channelSkuCompareReq.productIdList.size()>0">
  28 + and a.product_id in
  29 + <foreach collection="channelSkuCompareReq.productIdList" item="productId" open="(" close=")" separator=",">
  30 + #{productId}
  31 + </foreach>
  32 + </if>
  33 + <if test="channelSkuCompareReq.sizeIdList != null and channelSkuCompareReq.sizeIdList.size()>0">
  34 + and a.size_id in
  35 + <foreach collection="channelSkuCompareReq.sizeIdList" item="sizeId" open="(" close=")" separator=",">
  36 + #{sizeId}
  37 + </foreach>
  38 + </if>
  39 + <if test="channelSkuCompareReq.status != null and channelSkuCompareReq.status == 0 ">
  40 + and b.min_price &lt; a.channel_price
  41 + </if>
  42 + <if test="channelSkuCompareReq.status != null and channelSkuCompareReq.status == 1 ">
  43 + and b.min_price &gt; a.channel_price
  44 + </if>
  45 + </sql>
  46 +
  47 + <select id="selectTotalByCondition" resultType="java.lang.Integer" parameterType="com.yoho.ufo.model.ChannelSkuCompareReq">
  48 + select count(a.id)
  49 + from channel_sku_compare a
  50 + <if test="channelSkuCompareReq.status != null">
  51 + LEFT JOIN product b
  52 + ON( b.id=a.product_id)
  53 + </if>
  54 + where 1=1
  55 + <include refid="Query_Sql" />
  56 + </select>
  57 +
  58 + <select id="selectByCondition" resultMap="BaseResultMap" parameterType="com.yoho.ufo.model.ChannelSkuCompareReq">
  59 + select a.*
  60 + from channel_sku_compare a
  61 + <if test="channelSkuCompareReq.status != null">
  62 + LEFT JOIN product b
  63 + ON( b.id=a.product_id)
  64 + </if>
  65 + where 1=1
  66 + <include refid="Query_Sql" />
  67 + order by a.product_id desc, a.sku asc
  68 + <if test="channelSkuCompareReq.start!=null and channelSkuCompareReq.size != null">
  69 + limit #{channelSkuCompareReq.start},#{channelSkuCompareReq.size}
  70 + </if>
  71 + </select>
  72 +</mapper>
@@ -222,4 +222,7 @@ @@ -222,4 +222,7 @@
222 </foreach> 222 </foreach>
223 </if> 223 </if>
224 </sql> 224 </sql>
  225 + <select id="selectByProductName" resultMap="BaseResultMap">
  226 + select id, product_name from product where product_name like "%"#{productName}"%"
  227 + </select>
225 </mapper> 228 </mapper>
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 <result column="storage_num" jdbcType="INTEGER" property="storageNum" /> 9 <result column="storage_num" jdbcType="INTEGER" property="storageNum" />
10 <result column="update_time" jdbcType="INTEGER" property="updateTime" /> 10 <result column="update_time" jdbcType="INTEGER" property="updateTime" />
11 <result column="create_time" jdbcType="INTEGER" property="createTime" /> 11 <result column="create_time" jdbcType="INTEGER" property="createTime" />
  12 + <result column="suggest_low_price" jdbcType="DECIMAL" property="suggestLowPrice" />
  13 + <result column="suggest_high_price" jdbcType="DECIMAL" property="suggestHighPrice" />
12 </resultMap> 14 </resultMap>
13 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> 15 <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
14 delete from storage 16 delete from storage
@@ -58,7 +60,7 @@ @@ -58,7 +60,7 @@
58 where id = #{storageId,jdbcType=INTEGER} and storage_num = #{oldStorageNum,jdbcType=INTEGER} 60 where id = #{storageId,jdbcType=INTEGER} and storage_num = #{oldStorageNum,jdbcType=INTEGER}
59 </update> 61 </update>
60 <select id="selectByIds" resultMap="BaseResultMap"> 62 <select id="selectByIds" resultMap="BaseResultMap">
61 - select id, product_id, goods_id, size_id, storage_num, update_time, create_time 63 + select id, product_id, goods_id, size_id, storage_num, update_time, create_time, suggest_low_price, suggest_high_price
62 from storage where id in 64 from storage where id in
63 <foreach item="item" index="index" collection="storageIdList" open="(" separator="," close=")"> 65 <foreach item="item" index="index" collection="storageIdList" open="(" separator="," close=")">
64 #{item} 66 #{item}
@@ -161,4 +161,13 @@ @@ -161,4 +161,13 @@
161 </if> 161 </if>
162 order by create_time desc limit 300 162 order by create_time desc limit 300
163 </select> 163 </select>
  164 +
  165 + <select id="selectMinPriceByStorageIdList" resultMap="BaseResultMap">
  166 + select storage_id, min(price) as price
  167 + from storage_price where storage_id in
  168 + <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
  169 + #{item}
  170 + </foreach>
  171 + and status = 1 group by storage_id
  172 + </select>
164 </mapper> 173 </mapper>
@@ -103,4 +103,7 @@ @@ -103,4 +103,7 @@
103 select id, sort_id, size_name from size 103 select id, sort_id, size_name from size
104 </select> 104 </select>
105 105
  106 + <select id="selectBySizeName" resultMap="sizeMap">
  107 + select id, size_name from size where size_name = #{sizeName}
  108 + </select>
106 </mapper> 109 </mapper>
  1 +package com.yoho.ufo.controller;
  2 +
  3 +import org.slf4j.Logger;
  4 +import org.slf4j.LoggerFactory;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.web.bind.annotation.RequestBody;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RestController;
  9 +
  10 +import com.yoho.ufo.model.ChannelSkuCompareReq;
  11 +import com.yoho.ufo.service.IChannelSkuCompareService;
  12 +import com.yoho.ufo.service.model.ApiResponse;
  13 +import com.yoho.ufo.service.model.PageResponseBO;
  14 +import com.yohobuy.ufo.model.resp.product.ChannelSkuCompareRspBo;
  15 +
  16 +@RestController
  17 +@RequestMapping(value = "/channelSkuCompare")
  18 +public class ChannelSkuCompareController {
  19 +
  20 + private static final Logger LOGGER = LoggerFactory.getLogger(ChannelSkuCompareController.class);
  21 +
  22 + @Autowired
  23 + private IChannelSkuCompareService channelSkuCompareService;
  24 +
  25 + @RequestMapping(value = "/queryList")
  26 + public ApiResponse queryList(@RequestBody ChannelSkuCompareReq req) {
  27 + LOGGER.info("queryOrderList in. req is {}", req);
  28 + PageResponseBO<ChannelSkuCompareRspBo> result = channelSkuCompareService.queryList(req);
  29 + return new ApiResponse.ApiResponseBuilder().code(200).message("查询成功").data(result).build();
  30 + }
  31 +}
  1 +package com.yoho.ufo.service;
  2 +
  3 +import com.yoho.ufo.model.ChannelSkuCompareReq;
  4 +import com.yoho.ufo.service.model.PageResponseBO;
  5 +import com.yohobuy.ufo.model.resp.product.ChannelSkuCompareRspBo;
  6 +
  7 +/**
  8 + * @author caoyan
  9 + */
  10 +public interface IChannelSkuCompareService {
  11 + PageResponseBO<ChannelSkuCompareRspBo> queryList(ChannelSkuCompareReq req);
  12 +
  13 +}
  1 +package com.yoho.ufo.service.impl;
  2 +
  3 +import java.math.BigDecimal;
  4 +import java.util.List;
  5 +import java.util.Map;
  6 +import java.util.stream.Collectors;
  7 +
  8 +import org.apache.commons.collections.CollectionUtils;
  9 +import org.apache.commons.lang3.StringUtils;
  10 +import org.elasticsearch.common.collect.Lists;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.stereotype.Service;
  15 +
  16 +import com.yoho.ufo.dal.ChannelSkuCompareMapper;
  17 +import com.yoho.ufo.dal.ProductMapper;
  18 +import com.yoho.ufo.dal.StorageMapper;
  19 +import com.yoho.ufo.dal.StoragePriceMapper;
  20 +import com.yoho.ufo.dal.UfoSizeMapper;
  21 +import com.yoho.ufo.dal.model.Product;
  22 +import com.yoho.ufo.dal.model.Storage;
  23 +import com.yoho.ufo.dal.model.StoragePrice;
  24 +import com.yoho.ufo.model.ChannelSkuCompare;
  25 +import com.yoho.ufo.model.ChannelSkuCompareReq;
  26 +import com.yoho.ufo.model.commoditybasicrole.size.Size;
  27 +import com.yoho.ufo.service.IChannelSkuCompareService;
  28 +import com.yoho.ufo.service.model.PageResponseBO;
  29 +import com.yohobuy.ufo.model.resp.product.ChannelSkuCompareRspBo;
  30 +
  31 +/**
  32 + * @author caoyan
  33 + */
  34 +@Service
  35 +public class ChannelSkuCompareServiceImpl implements IChannelSkuCompareService {
  36 +
  37 + private static final Logger LOGGER = LoggerFactory.getLogger(ChannelSkuCompareServiceImpl.class);
  38 +
  39 + @Autowired
  40 + private ChannelSkuCompareMapper channelSkuCompareMapper;
  41 +
  42 + @Autowired
  43 + private ProductMapper productMapper;
  44 +
  45 + @Autowired
  46 + private UfoSizeMapper ufoSizeMapper;
  47 +
  48 + @Autowired
  49 + private StorageMapper storageMapper;
  50 +
  51 + @Autowired
  52 + private StoragePriceMapper storagePriceMapper;
  53 +
  54 + @Override
  55 + public PageResponseBO<ChannelSkuCompareRspBo> queryList(ChannelSkuCompareReq req) {
  56 + LOGGER.info("queryList in. req is {}", req);
  57 + if(!checkAndBuildParam(req)) {
  58 + return null;
  59 + }
  60 + int total = channelSkuCompareMapper.selectTotalByCondition(req);
  61 + if(total == 0) {
  62 + return null;
  63 + }
  64 +
  65 + List<ChannelSkuCompare> cscList = channelSkuCompareMapper.selectByCondition(req);
  66 + if(CollectionUtils.isEmpty(cscList)) {
  67 + return null;
  68 + }
  69 +
  70 + //查询商品名称
  71 + List<Integer> productIdList = cscList.stream().map(ChannelSkuCompare::getProductId).collect(Collectors.toList());
  72 + List<Product> productList = productMapper.selectProductListByIds(productIdList);
  73 + if(CollectionUtils.isEmpty(productList)) {
  74 + return null;
  75 + }
  76 + Map<Integer, Product> productMap = productList.stream().collect(Collectors.toMap(Product::getId, p->p));
  77 +
  78 + //查询尺码名称
  79 + List<Integer> sizeIdList = cscList.stream().map(ChannelSkuCompare::getSizeId).collect(Collectors.toList());
  80 + List<Size> sizeList = ufoSizeMapper.selectByIdList(sizeIdList);
  81 + Map<Integer, String> sizeIdNameMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
  82 +
  83 + //查询平台建议价
  84 + List<Integer> skuList = cscList.stream().map(ChannelSkuCompare::getSku).collect(Collectors.toList());
  85 + List<Storage> storageList = storageMapper.selectByIds(skuList);
  86 + Map<Integer, Storage> storageMap = storageList.stream().collect(Collectors.toMap(Storage::getId, s->s));
  87 +
  88 + //计算UFO当前价,可售sku最低价
  89 + List<StoragePrice> storagePriceList = storagePriceMapper.selectMinPriceByStorageIdList(skuList);
  90 + Map<Integer, BigDecimal> storageMinPriceMap = storagePriceList.stream().collect(Collectors.toMap(StoragePrice::getStorageId, StoragePrice::getPrice));
  91 +
  92 + List<ChannelSkuCompareRspBo> respList = convertToResp(cscList, productMap, sizeIdNameMap, storageMap, storageMinPriceMap);
  93 +
  94 + PageResponseBO<ChannelSkuCompareRspBo> result=new PageResponseBO<>();
  95 + result.setList(respList);
  96 + result.setPage(req.getPage());
  97 + result.setSize(req.getSize());
  98 + result.setTotal(total);
  99 +
  100 + return result;
  101 + }
  102 +
  103 + private List<ChannelSkuCompareRspBo> convertToResp(List<ChannelSkuCompare> cscList, Map<Integer, Product> productMap,
  104 + Map<Integer, String> sizeIdNameMap, Map<Integer, Storage> storageMap, Map<Integer, BigDecimal> storageMinPriceMap){
  105 + List<ChannelSkuCompareRspBo> boList = Lists.newArrayList();
  106 + for(ChannelSkuCompare csc : cscList) {
  107 + ChannelSkuCompareRspBo bo = new ChannelSkuCompareRspBo();
  108 + bo.setProductId(csc.getProductId());
  109 + bo.setSku(csc.getSku());
  110 + bo.setProductName(productMap.get(csc.getProductId()).getProductName());
  111 + bo.setSizeName(sizeIdNameMap.get(csc.getSizeId()));
  112 + bo.setChannelPrice(getFormatPrice(csc.getChannelPrice()));
  113 + bo.setChannelUrl(csc.getChannelUrl());
  114 + bo.setLowRate(csc.getLowRate().multiply(BigDecimal.valueOf(100)) + "%");
  115 + bo.setHighRate(csc.getHighRate().multiply(BigDecimal.valueOf(100)) + "%");
  116 + BigDecimal channelLowPrice = csc.getChannelPrice().multiply(BigDecimal.valueOf(1).subtract(csc.getLowRate()));
  117 + BigDecimal channelHighPrice = csc.getChannelPrice().multiply(BigDecimal.valueOf(1).add(csc.getHighRate()));
  118 + bo.setChannelPriceRange(getFormatPrice(channelLowPrice) + "~" + getFormatPrice(channelHighPrice));
  119 + bo.setUfoCurrentPrice(getFormatPrice(storageMinPriceMap.get(csc.getSku())));
  120 + BigDecimal ufoMinPrice = productMap.get(csc.getProductId()).getMinPrice();
  121 + bo.setUfoMinPrice(getFormatPrice(ufoMinPrice));
  122 + //毒当前价低于UFO价格红线则为异常,那么显示上回的建议价
  123 + BigDecimal suggestLowPrice = storageMap.get(csc.getSku()).getSuggestLowPrice();
  124 + BigDecimal suggestHighPrice = storageMap.get(csc.getSku()).getSuggestHighPrice();
  125 + if(null != suggestLowPrice && null != suggestHighPrice) {
  126 + bo.setSuggestPriceRange(getFormatPrice(suggestLowPrice) + "~" + getFormatPrice(suggestHighPrice));
  127 + }
  128 + if(csc.getChannelPrice().compareTo(ufoMinPrice) < 0) {//异常
  129 + bo.setStatus(1);
  130 + }else {
  131 + bo.setStatus(0);//正常
  132 + }
  133 + boList.add(bo);
  134 + }
  135 +
  136 + return boList;
  137 + }
  138 +
  139 + private static String getFormatPrice(BigDecimal price) {
  140 + return String.format("%d", price.intValue());
  141 + }
  142 +
  143 + private boolean checkAndBuildParam(ChannelSkuCompareReq req) {
  144 + if(StringUtils.isNotEmpty(req.getProductName())) {
  145 + List<Product> productList = productMapper.selectByProductName(req.getProductName());
  146 + if(CollectionUtils.isEmpty(productList)) {
  147 + return false;
  148 + }else {
  149 + req.setProductIdList(productList.stream().map(Product::getId).collect(Collectors.toList()));
  150 + }
  151 + }
  152 +
  153 + if(StringUtils.isNotEmpty(req.getSizeName())) {
  154 + List<Size> sizeList = ufoSizeMapper.selectBySizeName(req.getSizeName());
  155 + if(CollectionUtils.isEmpty(sizeList)) {
  156 + return false;
  157 + }else {
  158 + req.setSizeIdList(sizeList.stream().map(Size::getId).collect(Collectors.toList()));
  159 + }
  160 + }
  161 +
  162 + return true;
  163 +
  164 + }
  165 +}