Authored by liangyi.chen@yoho.cn

ufo后台页面更新

... ... @@ -2,6 +2,8 @@ package com.yoho.ufo.dal;
import com.yoho.ufo.dal.model.SearchSortRelation;
import java.util.List;
/**
* 映射yoho的品类
*
... ... @@ -17,4 +19,12 @@ public interface SearchSortRelationMapper {
int insertRelation(SearchSortRelation searchSortRelation);
List<SearchSortRelation> selectByYohoSortIds(List<Integer> yohoSortIds);
List<SearchSortRelation> selectByYohoSmallSortIds(List<Integer> yohoSmallSortIds);
SearchSortRelation selectByYohoSortId(Integer yohoSortId);
SearchSortRelation selectByYohoSmallSortId(Integer yohoSmallSortId);
}
... ...
package com.yoho.ufo.dal;
import com.yoho.ufo.dal.model.Yoho2ufoProduct;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface Yoho2ufoProductMapper {
int deleteByPrimaryKey(Integer id);
int insert(Yoho2ufoProduct record);
int insertSelective(Yoho2ufoProduct record);
Yoho2ufoProduct selectByPrimaryKey(Integer id);
Yoho2ufoProduct selectByProductSkn(Integer productSkn);
List<Yoho2ufoProduct> selectByProductSkns(List<Integer> productSknList);
int updateByPrimaryKeySelective(Yoho2ufoProduct record);
int selectCount(@Param("productSkn") Integer productSkn,
@Param("productName") String productName,
@Param("brandName") String brandName);
List<Yoho2ufoProduct> selectPage(@Param("productSkn") Integer productSkn,
@Param("productName") String productName,
@Param("brandName") String brandName,
@Param("start") Integer start,
@Param("rows") Integer rows);
int deleteBatchByIds(String ids);
int batchInsert(List<Yoho2ufoProduct> yoho2ufoProductList);
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal.model;
import lombok.Data;
@Data
public class Yoho2ufoProduct {
private Integer id;
private Integer productSkn;
private String productName;
private String brandName;
private String yohoImage;
private String ufoImage;
private Integer updateTime;
}
\ No newline at end of file
... ...
... ... @@ -28,6 +28,32 @@
values (#{ufoSortId}, #{yohoSortId}, #{yohoSmallSortId})
</insert>
<select id="selectByYohoSortIds" resultMap="sizeMap">
select <include refid="queryColumns"/>
from search_sort_relation where yoho_sort_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectByYohoSmallSortIds" resultMap="sizeMap">
select <include refid="queryColumns"/>
from search_sort_relation where yoho_small_sort_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectByYohoSortId" resultMap="sizeMap">
select <include refid="queryColumns"/>
from search_sort_relation where yoho_sort_id = #{yohoSortId}
</select>
<select id="selectByYohoSmallSortId" resultMap="sizeMap">
select <include refid="queryColumns"/>
from search_sort_relation where yoho_small_sort_id = #{yohoSmallSortId}
</select>
</mapper>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.yoho.ufo.dal.Yoho2ufoProductMapper" >
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.Yoho2ufoProduct" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="product_skn" property="productSkn" jdbcType="INTEGER" />
<result column="product_name" property="productName" jdbcType="VARCHAR" />
<result column="brand_name" property="brandName" jdbcType="VARCHAR" />
<result column="yoho_image" property="yohoImage" jdbcType="VARCHAR" />
<result column="ufo_image" property="ufoImage" jdbcType="VARCHAR" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
</resultMap>
<sql id="Base_Column_List" >
id, product_skn, product_name, brand_name, yoho_image, ufo_image, update_time
</sql>
<sql id="pageCondition" >
<if test="productSkn != null and productSkn > 0">
and product_skn = #{productSkn}
</if>
<if test="productName != null and productName !=''">
and product_name like "%"#{productName}"%"
</if>
<if test="brandName != null and brandName !=''">
and brand_name like "%"#{brandName}"%"
</if>
</sql>
<select id="selectCount" resultType="java.lang.Integer">
select count(*) from yoho2ufo_product where 1=1 <include refid="pageCondition" />
</select>
<select id="selectPage" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from yoho2ufo_product
where 1=1 <include refid="pageCondition" /> order by update_time desc limit #{start},#{rows}
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from yoho2ufo_product
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectByProductSkn" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from yoho2ufo_product
where product_skn = #{productSkn,jdbcType=INTEGER}
</select>
<select id="selectByProductSkns" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from yoho2ufo_product
where product_skn in
<foreach item="item" collection="skns" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from yoho2ufo_product
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.dal.model.Yoho2ufoProduct" >
insert into yoho2ufo_product (id, product_skn, product_name,
brand_name, yoho_image, ufo_image,
update_time)
values (#{id,jdbcType=INTEGER}, #{productSkn,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR},
#{brandName,jdbcType=VARCHAR}, #{yohoImage,jdbcType=VARCHAR}, #{ufoImage,jdbcType=VARCHAR},
#{updateTime,jdbcType=INTEGER})
</insert>
<insert id="insertSelective" parameterType="com.yoho.ufo.dal.model.Yoho2ufoProduct" >
insert into yoho2ufo_product
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
id,
</if>
<if test="productSkn != null" >
product_skn,
</if>
<if test="productName != null" >
product_name,
</if>
<if test="brandName != null" >
brand_name,
</if>
<if test="yohoImage != null" >
yoho_image,
</if>
<if test="ufoImage != null" >
ufo_image,
</if>
<if test="updateTime != null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
#{id,jdbcType=INTEGER},
</if>
<if test="productSkn != null" >
#{productSkn,jdbcType=INTEGER},
</if>
<if test="productName != null" >
#{productName,jdbcType=VARCHAR},
</if>
<if test="brandName != null" >
#{brandName,jdbcType=VARCHAR},
</if>
<if test="yohoImage != null" >
#{yohoImage,jdbcType=VARCHAR},
</if>
<if test="ufoImage != null" >
#{ufoImage,jdbcType=VARCHAR},
</if>
<if test="updateTime != null" >
#{updateTime,jdbcType=INTEGER},
</if>
</trim>
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.Yoho2ufoProduct" >
update yoho2ufo_product
<set >
<if test="productSkn != null" >
product_skn = #{productSkn,jdbcType=INTEGER},
</if>
<if test="productName != null" >
product_name = #{productName,jdbcType=VARCHAR},
</if>
<if test="brandName != null" >
brand_name = #{brandName,jdbcType=VARCHAR},
</if>
<if test="yohoImage != null" >
yoho_image = #{yohoImage,jdbcType=VARCHAR},
</if>
<if test="ufoImage != null" >
ufo_image = #{ufoImage,jdbcType=VARCHAR},
</if>
<if test="updateTime != null" >
update_time = #{updateTime,jdbcType=INTEGER},
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<delete id="deleteBatchByIds" parameterType="java.lang.String" >
delete from yoho2ufo_product where id in
<foreach item="item" index="index" collection="ids.split(',')" open="(" separator="," close=")">
'${item}'
</foreach>
</delete>
<insert id="batchInsert" parameterType="java.util.List">
insert into (id, product_skn, product_name,brand_name, yoho_image, ufo_image,update_time) values
<foreach collection="list" item="item" index="index" separator=",">
(#{id,jdbcType=INTEGER}, #{productSkn,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR},
#{brandName,jdbcType=VARCHAR}, #{yohoImage,jdbcType=VARCHAR}, #{ufoImage,jdbcType=VARCHAR},
#{updateTime,jdbcType=INTEGER})
</foreach>
</insert>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.service;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.yoho2ufoproduct.Yoho2ufoProductReqBo;
import com.yohobuy.ufo.model.response.yoho2ufoproduct.Yoho2ufoProductRespBo;
public interface Yoho2ufoProductService {
ApiResponse<PageResponseBO<Yoho2ufoProductRespBo>> list(Yoho2ufoProductReqBo bo);
ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductBySkn(Integer skn);
ApiResponse<Void> deleteYoho2ufoProductById(Integer id);
ApiResponse<Void> deleteBatchYoho2ufoProduct(String ids);
ApiResponse<Void> addOrUpdate(Yoho2ufoProductReqBo bo);
ApiResponse<Void> insertBatch(String sknStr);
}
... ...
package com.yoho.ufo.service.impl;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.product.model.GoodsBo;
import com.yoho.product.model.GoodsImagesBo;
import com.yoho.product.model.ProductBo;
import com.yoho.product.request.BatchBaseRequest;
import com.yoho.ufo.dal.ProductSortMapper;
import com.yoho.ufo.dal.SearchSortRelationMapper;
import com.yoho.ufo.dal.Yoho2ufoProductMapper;
import com.yoho.ufo.dal.model.SearchSortRelation;
import com.yoho.ufo.dal.model.Yoho2ufoProduct;
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
import com.yoho.ufo.service.Yoho2ufoProductService;
import com.yoho.ufo.util.CollectionUtil;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.yoho2ufoproduct.Yoho2ufoProductReqBo;
import com.yohobuy.ufo.model.response.yoho2ufoproduct.Yoho2ufoProductRespBo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
public class Yoho2ufoProductServiceImpl implements Yoho2ufoProductService {
@Resource
Yoho2ufoProductMapper yoho2ufoProductMapper;
@Resource
ServiceCaller serviceCaller;
@Resource
SearchSortRelationMapper searchSortRelationMapper;
@Resource
private ProductSortMapper productSortMapper;
@Override
public ApiResponse<PageResponseBO<Yoho2ufoProductRespBo>> list(Yoho2ufoProductReqBo bo) {
int count = yoho2ufoProductMapper.selectCount(bo.getProductSkn(), bo.getProductName(), bo.getBrandName());
List<Yoho2ufoProductRespBo> respBoList = new ArrayList<>();
Map<Integer, ProductBo> productBoMap = new HashMap<>();
if (count > 0) {
List<Yoho2ufoProduct> productList = yoho2ufoProductMapper.selectPage(bo.getProductSkn(),
bo.getProductName(),
bo.getBrandName(),
bo.getStartIndex(),
bo.getRows());
List<Integer> sknList = CollectionUtil.distinct(productList, Yoho2ufoProduct::getProductSkn);
List<ProductBo> productBoList = getProductBoBySknList(sknList);
if (productBoList != null && productBoList.size() > 0) {
//yoho大分类
List<Integer> yohoMaxSortList = CollectionUtil.distinct(productBoList, ProductBo::getMaxSortId);
List<SearchSortRelation> searchMaxSortRelations = searchSortRelationMapper.selectByYohoSortIds(yohoMaxSortList);
Map<Integer, SearchSortRelation> searchMaxSortRelationsMap = CollectionUtils.isEmpty(searchMaxSortRelations) ? new HashMap<>() :
CollectionUtil.extractMap(searchMaxSortRelations, SearchSortRelation::getYohoSortId);
//yoho小分类
List<Integer> yohoSmallSortList = CollectionUtil.distinct(productBoList, ProductBo::getSmallSortId);
List<SearchSortRelation> searchSmallSortRelations = searchSortRelationMapper.selectByYohoSortIds(yohoSmallSortList);
Map<Integer, SearchSortRelation> searchSmallSortRelationsMap = CollectionUtils.isEmpty(searchSmallSortRelations) ? new HashMap<>() :
CollectionUtil.extractMap(searchSmallSortRelations, SearchSortRelation::getYohoSmallSortId);
//ufo大分类
List<Integer> ufoMaxSortList = CollectionUtil.distinct(searchMaxSortRelations, SearchSortRelation::getUfoSortId);
List<ProductSort> productMaxSortList = productSortMapper.selectSortByIdList(ufoMaxSortList);
Map<Integer, ProductSort> ufoMaxSortMap = CollectionUtils.isEmpty(productMaxSortList) ? new HashMap<>() :
CollectionUtil.extractMap(productMaxSortList, ProductSort::getId);
//ufo小分类
List<Integer> ufoSmallSortList = CollectionUtil.distinct(searchSmallSortRelations, SearchSortRelation::getYohoSmallSortId);
List<ProductSort> productSmallSortList = productSortMapper.selectSortByIdList(ufoSmallSortList);
Map<Integer, ProductSort> ufoSmallSortMap = CollectionUtils.isEmpty(productSmallSortList) ? new HashMap<>() :
CollectionUtil.extractMap(productSmallSortList, ProductSort::getId);
productBoList.forEach(p -> {
Integer skn = p.getProductPriceBo().getProductSkn();
productBoMap.put(skn, p);
});
productList.forEach(p -> {
ProductBo yohoProductBo = productBoMap.get(p.getProductSkn());
String yohoSortStr = yohoProductBo.getMaxSortName() + ":" + yohoProductBo.getMiddleSortName() + ":"
+ yohoProductBo.getSmallSortName();
SearchSortRelation searchMaxSortRelation = searchMaxSortRelationsMap.get(yohoProductBo.getMaxSortId());
ProductSort ufoMaxSort = searchMaxSortRelation == null ? null :
ufoMaxSortMap.get(searchMaxSortRelation.getUfoSortId());
SearchSortRelation searchSmallSortRelation = searchSmallSortRelationsMap.get(yohoProductBo.getSmallSortId());
ProductSort ufoSmallSort = searchSmallSortRelation == null ? null :
ufoSmallSortMap.get(searchSmallSortRelation.getUfoSortId());
String ufoSortStr = ufoMaxSort == null ? "":(ufoMaxSort.getSortName() + ":" + ufoSmallSort.getSortName());
Yoho2ufoProductRespBo yoho2ufoProductRespBo = new Yoho2ufoProductRespBo();
yoho2ufoProductRespBo.setProductSkn(p.getProductSkn());
yoho2ufoProductRespBo.setProductName(p.getProductName());
yoho2ufoProductRespBo.setBrandName(p.getBrandName());
yoho2ufoProductRespBo.setId(p.getId());
yoho2ufoProductRespBo.setYohoSortStr(yohoSortStr);
yoho2ufoProductRespBo.setUfoSortStr(ufoSortStr);
yoho2ufoProductRespBo.setYohoImage(getProductUrl(yohoProductBo));
yoho2ufoProductRespBo.setUfoImage(p.getUfoImage());
respBoList.add(yoho2ufoProductRespBo);
});
}
}
PageResponseBO<Yoho2ufoProductRespBo> pageBo = new PageResponseBO<>(count, respBoList, bo.getPage(), bo.getRows());
return new ApiResponse<>(pageBo);
}
@Override
public ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductBySkn(Integer skn) {
List<Integer> skns = new ArrayList<>();
skns.add(skn);
List<ProductBo> productBoList = getProductBoBySknList(skns);
Yoho2ufoProductRespBo yoho2ufoProductRespBo = new Yoho2ufoProductRespBo();
if(CollectionUtils.isEmpty(productBoList)){
return new ApiResponse<>();
}
ProductBo yohoProductBo = productBoList.get(0);
Yoho2ufoProduct yoho2ufoProductFromDB = yoho2ufoProductMapper.selectByProductSkn(skn);
if(yoho2ufoProductFromDB != null){
yoho2ufoProductRespBo.setUfoImage(yoho2ufoProductFromDB.getUfoImage());
}
yoho2ufoProductRespBo.setProductName(yohoProductBo.getProductName());
yoho2ufoProductRespBo.setBrandName(yohoProductBo.getBrand().getBrandName());
yoho2ufoProductRespBo.setYohoImage(getProductUrl(yohoProductBo));
String yohoSortStr = yohoProductBo.getMaxSortName() + ":" + yohoProductBo.getMiddleSortName() + ":"
+ yohoProductBo.getSmallSortName();
yoho2ufoProductRespBo.setYohoSortStr(yohoSortStr);
//ufo大分类
SearchSortRelation searchMaxSortRelation = searchSortRelationMapper.selectByYohoSortId(yohoProductBo.getMaxSortId());
ProductSort ufoMaxSort = searchMaxSortRelation == null ? null :
productSortMapper.selectOneById(searchMaxSortRelation.getUfoSortId());
//ufo小分类
SearchSortRelation searchSmallSortRelation = searchSortRelationMapper.selectByYohoSmallSortId(yohoProductBo.getSmallSortId());
ProductSort ufoSmallSort = searchMaxSortRelation == null ? null :
productSortMapper.selectOneById(searchSmallSortRelation.getUfoSortId());
String ufoSortStr = (ufoMaxSort == null ? "" : ufoMaxSort.getSortName()) +":" +
(ufoSmallSort == null ? "" : ufoSmallSort.getSortName());
yoho2ufoProductRespBo.setUfoSortStr(ufoSortStr);
return new ApiResponse<>(yoho2ufoProductRespBo);
}
/**
* 根据skn集合调用服务查询对应商品详情.
*
* @param sknList skn集合list
* @return ProductBo集合
*/
public List<ProductBo> getProductBoBySknList(Collection<Integer> sknList) {
// 构建请求对象
BatchBaseRequest<Integer> request = new BatchBaseRequest<>();
request.setParams(new ArrayList<>(sknList));
return Arrays.asList(serviceCaller.call("product.batchQueryProductsBySkns", request, ProductBo[].class));
}
@Override
public ApiResponse<Void> deleteYoho2ufoProductById(Integer id) {
yoho2ufoProductMapper.deleteByPrimaryKey(id);
return new ApiResponse<>();
}
@Override
public ApiResponse<Void> deleteBatchYoho2ufoProduct(String ids) {
yoho2ufoProductMapper.deleteBatchByIds(ids);
return new ApiResponse<>();
}
@Override
public ApiResponse<Void> addOrUpdate(Yoho2ufoProductReqBo reqBo) {
List<Integer> skns = new ArrayList<>();
skns.add(reqBo.getProductSkn());
List<ProductBo> productBoList = getProductBoBySknList(skns);
if(CollectionUtils.isEmpty(productBoList)){
return new ApiResponse<>();
}
ProductBo yohoProductBo = productBoList.get(0);
Yoho2ufoProduct yoho2ufoProduct = new Yoho2ufoProduct();
yoho2ufoProduct.setUfoImage(reqBo.getUfoImage());
yoho2ufoProduct.setProductSkn(reqBo.getProductSkn());
yoho2ufoProduct.setProductName(yohoProductBo.getProductName());
yoho2ufoProduct.setBrandName(yohoProductBo.getBrand().getBrandName());
yoho2ufoProduct.setYohoImage(getProductUrl(yohoProductBo));
yoho2ufoProduct.setUpdateTime((int) (System.currentTimeMillis() / 1000));
Yoho2ufoProduct yoho2ufoProductFromDB = yoho2ufoProductMapper.selectByProductSkn(reqBo.getProductSkn());
if(yoho2ufoProductFromDB != null){
yoho2ufoProduct.setId(reqBo.getId());
yoho2ufoProductMapper.updateByPrimaryKeySelective(yoho2ufoProduct);
}else{
yoho2ufoProductMapper.insert(yoho2ufoProduct);
}
return new ApiResponse<>();
}
@Override
public ApiResponse<Void> insertBatch(String sknStr) {
Map<Integer, ProductBo> productBoMap = new HashMap<>();
List<Yoho2ufoProduct> yoho2ufoProductList = new ArrayList<>();
String skns = sknStr.trim();
String addskns = skns.replaceAll("\\s*", "");
String[] addSknArray = addskns.split(",");
List<String> sknStrList = Arrays.asList(addSknArray);
List<Integer> sknList = sknStrList.stream().map(Integer::valueOf).collect(Collectors.toList());
List<Yoho2ufoProduct> yoho2ufoProductExsit = yoho2ufoProductMapper.selectByProductSkns(sknList);
if(!CollectionUtils.isEmpty(yoho2ufoProductExsit)){
List<Integer> exsitSkns = yoho2ufoProductExsit.stream().map(Yoho2ufoProduct::getProductSkn)
.collect(Collectors.toList());
sknList = sknList.stream().filter(item -> !exsitSkns.contains(item))
.collect(Collectors.toList());
}
List<ProductBo> productBoList = getProductBoBySknList(sknList);
if (productBoList != null && productBoList.size() > 0) {
productBoList.forEach(p -> {
Integer skn = p.getProductPriceBo().getProductSkn();
productBoMap.put(skn, p);
});
sknList.forEach(skn -> {
ProductBo yohoProductBo = productBoMap.get(skn);
Yoho2ufoProduct yoho2ufoProduct = new Yoho2ufoProduct();
yoho2ufoProduct.setProductSkn(skn);
yoho2ufoProduct.setProductName(yohoProductBo.getProductName());
yoho2ufoProduct.setBrandName(yohoProductBo.getBrand().getBrandName());
yoho2ufoProduct.setYohoImage(getProductUrl(yohoProductBo));
yoho2ufoProduct.setUpdateTime((int) (System.currentTimeMillis() / 1000));
yoho2ufoProductList.add(yoho2ufoProduct);
});
yoho2ufoProductMapper.batchInsert(yoho2ufoProductList);
}
return new ApiResponse<>();
}
//获取商品图片的url
private String getProductUrl(ProductBo productBo) {
List<GoodsBo> goodsList = productBo.getGoodsList();
String imageUrl = "";
if (goodsList != null && goodsList.size() > 0) {
for (GoodsBo goodsBo : goodsList) {
if ("Y".equals(goodsBo.getIsDefault())) {
List<GoodsImagesBo> goodsImagesBoList = goodsBo.getGoodsImagesList();
if (goodsImagesBoList != null && goodsImagesBoList.size() > 0) {
for (GoodsImagesBo goodsImagesBo : goodsImagesBoList) {
if ("Y".equals(goodsImagesBo.getIsDefault())) {
imageUrl = goodsImagesBo.getImageUrl();
break;
}
}
}
break;
}
}
if (StringUtils.isEmpty(imageUrl)) {
List<GoodsImagesBo> goodsImagesBoList = goodsList.get(0).getGoodsImagesList();
if (goodsImagesBoList != null && goodsImagesBoList.size() > 0) {
imageUrl = goodsImagesBoList.get(0).getImageUrl();
}
}
}
return imageUrl;
}
}
... ...