Authored by liangyi.chen@yoho.cn

Merge branch 'dev_6.8.5_yoho2ufo' into test6.8.5

... ... @@ -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 deleteBatchBySkns(@Param("skns")String skns);
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
... ...
package com.yoho.ufo.model.goodsmanage;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
@Data
@EqualsAndHashCode(callSuper=false)
@ToString
public class YohoProductInfo {
private Integer productSkn;
private String brandName;
private String imageUrl;
private String productName;
private String maxSortName;
private Integer maxSortId;
private String middleSortName;
private Integer middleSortId;
private String smallSortName;
private Integer smallSortId;
}
... ...
... ... @@ -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 like concat('%', #{productSkn}, '%')
</if>
<if test="productName != null and productName !=''">
and product_name like concat('%', #{productName}, '%')
</if>
<if test="brandName != null and brandName !=''">
and brand_name like concat('%', #{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 yoho_image = #{yohoImage,jdbcType=VARCHAR},
product_name = #{productName,jdbcType=VARCHAR},
brand_name = #{brandName,jdbcType=VARCHAR},update_time = #{updateTime,jdbcType=INTEGER},
ufo_image = #{ufoImage,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<delete id="deleteBatchBySkns" parameterType="java.lang.String" >
delete from yoho2ufo_product where product_skn in
<foreach item="item" index="index" collection="skns.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.controller.product;
import com.yoho.ufo.dal.model.Yoho2ufoProduct;
import com.yoho.ufo.service.Yoho2ufoProductService;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping(value = "/yoho2ufoProduct")
public class Yoho2ufoProductController {
private static final Logger LOGGER = LoggerFactory.getLogger(Yoho2ufoProductController.class);
@Resource
private Yoho2ufoProductService yoho2ufoProductService;
@RequestMapping(value = "/addOrUpdate" , method = RequestMethod.POST)
public ApiResponse<Void> addOrUpdate(Yoho2ufoProduct bo) {
LOGGER.info("Yoho2ufoProduct.addOrUpdate param = {}", bo);
return yoho2ufoProductService.addOrUpdate(bo);
}
@RequestMapping(value = "/getYoho2ufoProductBySkn")
public ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductBySkn(Integer skn) {
LOGGER.info("Yoho2ufoProduct.getYoho2ufoProductBySkn skn = {}", skn);
return yoho2ufoProductService.getYoho2ufoProductBySkn(skn);
}
@RequestMapping(value = "/list")
public ApiResponse<PageResponseBO<Yoho2ufoProductRespBo>> list(Yoho2ufoProductReqBo bo) {
LOGGER.info("Yoho2ufoProduct.list param = {}", bo);
return yoho2ufoProductService.list(bo);
}
@RequestMapping(value = "/deleteYoho2ufoProductById")
public ApiResponse<Void> deleteYoho2ufoProductById(Integer id) {
LOGGER.info("Yoho2ufoProduct.deleteYoho2ufoProductById param = {}", id);
return yoho2ufoProductService.deleteYoho2ufoProductById(id);
}
@RequestMapping(value = "/deleteBatchYoho2ufoProduct")
public ApiResponse<Void> deleteBatchYoho2ufoProduct(String skns) {
LOGGER.info("Yoho2ufoProduct.deleteBatchYoho2ufoProduct param = {}", skns);
return yoho2ufoProductService.deleteBatchYoho2ufoProduct(skns);
}
@RequestMapping(value = "/insertBatch")
public ApiResponse<Void> insertBatch(String sknStr) {
LOGGER.info("Yoho2ufoProduct.insertBatch param = {}", sknStr);
return yoho2ufoProductService.insertBatch(sknStr);
}
@RequestMapping(value = "/getYoho2ufoProductById")
public ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductById(Integer id) {
LOGGER.info("Yoho2ufoProduct.getYoho2ufoProductById id = {}", id);
return yoho2ufoProductService.getYoho2ufoProductById(id);
}
}
... ...
package com.yoho.ufo.service;
import com.yoho.ufo.dal.model.Yoho2ufoProduct;
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 skns);
ApiResponse<Void> addOrUpdate(Yoho2ufoProduct bo);
ApiResponse<Void> insertBatch(String sknStr);
ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductById(Integer id);
}
... ...
package com.yoho.ufo.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.rest.client.ServiceCaller;
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.model.goodsmanage.YohoProductInfo;
import com.yoho.ufo.service.Yoho2ufoProductService;
import com.yoho.ufo.util.CollectionUtil;
import com.yoho.ufo.util.ImagesConstant;
import com.yoho.ufo.util.ImagesHelper;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class Yoho2ufoProductServiceImpl implements Yoho2ufoProductService {
@Resource
Yoho2ufoProductMapper yoho2ufoProductMapper;
@Resource
ServiceCaller serviceCaller;
@Resource
SearchSortRelationMapper searchSortRelationMapper;
@Resource
ProductSortMapper productSortMapper;
@Value("${search.server.address}")
private String searchServerAddress;
private static final Logger logger = LoggerFactory.getLogger(Yoho2ufoProductServiceImpl.class);
@Override
public ApiResponse<PageResponseBO<Yoho2ufoProductRespBo>> list(Yoho2ufoProductReqBo bo) {
int count = yoho2ufoProductMapper.selectCount(bo.getProductSkn(), bo.getProductName(), bo.getBrandName());
List<Yoho2ufoProductRespBo> respBoList = new ArrayList<>();
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<YohoProductInfo> productBoList = getProductBoBySknList(sknList);
if (productBoList.size() > 0) {
//yoho大分类
List<Integer> yohoMaxSortList = CollectionUtil.distinct(productBoList, YohoProductInfo::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, YohoProductInfo::getSmallSortId);
List<SearchSortRelation> searchSmallSortRelations = searchSortRelationMapper.selectByYohoSmallSortIds(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 = new ArrayList<>();
if(!CollectionUtils.isEmpty(ufoMaxSortList)){
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::getUfoSortId);
List<ProductSort> productSmallSortList = new ArrayList<>();
if(!CollectionUtils.isEmpty(ufoSmallSortList)){
productSmallSortList = productSortMapper.selectSortByIdList(ufoSmallSortList);
}
Map<Integer, ProductSort> ufoSmallSortMap = CollectionUtils.isEmpty(productSmallSortList) ? new HashMap<>() :
CollectionUtil.extractMap(productSmallSortList, ProductSort::getId);
Map<Integer, YohoProductInfo> productBoMap = CollectionUtil.extractMap(productBoList, YohoProductInfo::getProductSkn);
productList.forEach(p -> {
YohoProductInfo yohoProductBo = productBoMap.get(p.getProductSkn());
String yohoSortStr = "";
if(!StringUtils.isEmpty(yohoProductBo.getMaxSortName())){
yohoSortStr += yohoProductBo.getMaxSortName();
}
if(!StringUtils.isEmpty(yohoProductBo.getMiddleSortName())){
yohoSortStr += "/" + yohoProductBo.getMiddleSortName();
}
if(!StringUtils.isEmpty(yohoProductBo.getSmallSortName())){
yohoSortStr += "/" + 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 = "";
if(ufoMaxSort != null && (!StringUtils.isEmpty(ufoMaxSort.getSortName()))){
ufoSortStr += ufoMaxSort.getSortName();
}
if(ufoSmallSort != null && (!StringUtils.isEmpty(ufoSmallSort.getSortName()))){
ufoSortStr += "/" + ufoSmallSort.getSortName();
}
Yoho2ufoProductRespBo yoho2ufoProductRespBo = new Yoho2ufoProductRespBo();
yoho2ufoProductRespBo.setProductSkn(p.getProductSkn());
yoho2ufoProductRespBo.setProductName(yohoProductBo.getProductName());
yoho2ufoProductRespBo.setBrandName(yohoProductBo.getBrandName());
yoho2ufoProductRespBo.setId(p.getId());
yoho2ufoProductRespBo.setYohoSortStr(yohoSortStr);
yoho2ufoProductRespBo.setUfoSortStr(ufoSortStr);
yoho2ufoProductRespBo.setYohoImage(yohoProductBo.getImageUrl());
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<YohoProductInfo> productBoList = getProductBoBySknList(skns);
Yoho2ufoProductRespBo yoho2ufoProductRespBo = new Yoho2ufoProductRespBo();
if(CollectionUtils.isEmpty(productBoList)){
return new ApiResponse<>(yoho2ufoProductRespBo);
}
YohoProductInfo yohoProductBo = productBoList.get(0);
Yoho2ufoProduct yoho2ufoProductFromDB = yoho2ufoProductMapper.selectByProductSkn(skn);
if(yoho2ufoProductFromDB != null){
yoho2ufoProductRespBo.setUfoImage(yoho2ufoProductFromDB.getUfoImage());
}
yoho2ufoProductRespBo.setProductSkn(skn);
yoho2ufoProductRespBo.setProductName(yohoProductBo.getProductName());
yoho2ufoProductRespBo.setBrandName(yohoProductBo.getBrandName());
yoho2ufoProductRespBo.setYohoImage(yohoProductBo.getImageUrl());
String yohoSortStr = "";
if(!StringUtils.isEmpty(yohoProductBo.getMaxSortName())){
yohoSortStr += yohoProductBo.getMaxSortName();
}
if(!StringUtils.isEmpty(yohoProductBo.getMiddleSortName())){
yohoSortStr += "/" + yohoProductBo.getMiddleSortName();
}
if(!StringUtils.isEmpty(yohoProductBo.getSmallSortName())){
yohoSortStr += "/" + 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 = searchSmallSortRelation == null ? null :
productSortMapper.selectOneById(searchSmallSortRelation.getUfoSortId());
String ufoSortStr = "";
if(ufoMaxSort != null && (!StringUtils.isEmpty(ufoMaxSort.getSortName()))){
ufoSortStr += ufoMaxSort.getSortName();
}
if(ufoSmallSort != null && (!StringUtils.isEmpty(ufoSmallSort.getSortName()))){
ufoSortStr += "/" + ufoSmallSort.getSortName();
}
yoho2ufoProductRespBo.setUfoSortStr(ufoSortStr);
return new ApiResponse<>(yoho2ufoProductRespBo);
}
/**
* 根据skn集合调用服务查询对应商品详情
* 调用搜索的接口批量查询产品信息
*
* @param sknList skn集合list
* @return ProductBo集合
*/
public List<YohoProductInfo> getProductBoBySknList(Collection<Integer> sknList) {
List<YohoProductInfo> productBoList = new ArrayList<>();
//调用搜索的接口批量查询产品信息
String url = searchServerAddress + "productindex/productListBySkn.json?product_skn=" +
org.apache.commons.lang.StringUtils.join(sknList, ",");
JSONObject jsonObject = serviceCaller.get("", url, null, JSONObject.class, null).get(1);
if(jsonObject != null && jsonObject.getJSONObject("data") != null){
JSONArray productArray = jsonObject.getJSONObject("data").getJSONArray("product_list");
if(org.apache.commons.collections.CollectionUtils.isNotEmpty(productArray)){
for(int index = 0; index < productArray.size(); index++){
JSONObject jsonObject1 = (JSONObject)productArray.get(index);
YohoProductInfo yohoProductInfo = new YohoProductInfo();
yohoProductInfo.setBrandName(jsonObject1.getString("brand_name"));
yohoProductInfo.setImageUrl(ImagesHelper.getImageAbsoluteUrl(jsonObject1.getString("default_images"), ImagesConstant.BUCKET_GOODS_IMG));
yohoProductInfo.setMaxSortId(jsonObject1.getInteger("max_sort_id"));
yohoProductInfo.setMiddleSortId(jsonObject1.getInteger("middle_sort_id"));
yohoProductInfo.setMaxSortName(jsonObject1.getString("max_sort_name"));
yohoProductInfo.setMiddleSortName(jsonObject1.getString("middle_sort_name"));
yohoProductInfo.setSmallSortId(jsonObject1.getInteger("small_sort_id"));
yohoProductInfo.setSmallSortName(jsonObject1.getString("small_sort_name"));
yohoProductInfo.setProductName(jsonObject1.getString("product_name"));
yohoProductInfo.setProductSkn(jsonObject1.getInteger("product_skn"));
productBoList.add(yohoProductInfo);
}
}
}
return productBoList;
}
@Override
public ApiResponse<Void> deleteYoho2ufoProductById(Integer id) {
yoho2ufoProductMapper.deleteByPrimaryKey(id);
return new ApiResponse<>();
}
@Override
public ApiResponse<Void> deleteBatchYoho2ufoProduct(String skns) {
if(!StringUtils.isEmpty(skns)){
yoho2ufoProductMapper.deleteBatchBySkns(skns);
}
return new ApiResponse<>();
}
@Override
public ApiResponse<Void> addOrUpdate(Yoho2ufoProduct reqBo) {
List<Integer> skns = new ArrayList<>();
skns.add(reqBo.getProductSkn());
List<YohoProductInfo> productBoList = getProductBoBySknList(skns);
if(CollectionUtils.isEmpty(productBoList)){
return new ApiResponse<>();
}
YohoProductInfo yohoProductBo = productBoList.get(0);
Yoho2ufoProduct yoho2ufoProduct = new Yoho2ufoProduct();
yoho2ufoProduct.setUfoImage(reqBo.getUfoImage());
yoho2ufoProduct.setProductSkn(reqBo.getProductSkn());
yoho2ufoProduct.setProductName(yohoProductBo.getProductName());
yoho2ufoProduct.setBrandName(yohoProductBo.getBrandName());
yoho2ufoProduct.setYohoImage(yohoProductBo.getImageUrl());
yoho2ufoProduct.setUpdateTime((int) (System.currentTimeMillis() / 1000));
Yoho2ufoProduct yoho2ufoProductFromDB = yoho2ufoProductMapper.selectByProductSkn(reqBo.getProductSkn());
if(reqBo.getId() != null && reqBo.getId() > 0){ //更新操作
yoho2ufoProduct.setId(reqBo.getId());
yoho2ufoProductMapper.updateByPrimaryKeySelective(yoho2ufoProduct);
}else if(yoho2ufoProductFromDB == null){ //新增
yoho2ufoProductMapper.insert(yoho2ufoProduct);
}else{
return new ApiResponse<>(201,"该skn数据库已存在");
}
return new ApiResponse<>();
}
@Override
public ApiResponse<Void> insertBatch(String sknStr) {
Map<Integer, YohoProductInfo> productBoMap;
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<YohoProductInfo> productBoList = getProductBoBySknList(sknList);
if (productBoList != null && productBoList.size() > 0) {
productBoMap = CollectionUtil.extractMap
(productBoList, YohoProductInfo::getProductSkn);
sknList.forEach(skn -> {
YohoProductInfo yohoProductBo = productBoMap.get(skn);
Yoho2ufoProduct yoho2ufoProduct = new Yoho2ufoProduct();
yoho2ufoProduct.setProductSkn(skn);
yoho2ufoProduct.setProductName(yohoProductBo.getProductName());
yoho2ufoProduct.setBrandName(yohoProductBo.getBrandName());
yoho2ufoProduct.setYohoImage(yohoProductBo.getImageUrl());
yoho2ufoProduct.setUpdateTime((int) (System.currentTimeMillis() / 1000));
yoho2ufoProductList.add(yoho2ufoProduct);
});
yoho2ufoProductMapper.batchInsert(yoho2ufoProductList);
}
return new ApiResponse<>();
}
@Override
public ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductById(Integer id) {
Yoho2ufoProduct yoho2ufoProduct = yoho2ufoProductMapper.selectByPrimaryKey(id);
if(yoho2ufoProduct != null){
return getYoho2ufoProductBySkn(yoho2ufoProduct.getProductSkn());
}
return new ApiResponse<>();
}
}
... ...
... ... @@ -40,4 +40,6 @@ ip.port.uic.server = ${ip.port.uic.server}
ufo.live.notify.url = ${ufo.live.notify.url}
ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}
\ No newline at end of file
ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}
search.server.address=${search.server.address}
\ No newline at end of file
... ...
<!DOCTYPE html>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="sknEditForm" id="sknEditForm" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" id="id"/>
<div style="margin-top: 20px;margin-left: 30px">
<table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
<tr style="height: 60px">
<td width="12%">有货SKN<span class="requriedInput">*</span></td>
<td width="50%">
<input id="productSkn" name="productSkn" class="easyui-numberbox" style="width: 100px"/>
<!--<button type="button" class="btn-info" onclick="queryProductInfo()">查询</button>-->
</td>
</tr>
<tr style="height: 60px" id="productNameTR">
<td width="12%">商品名称</td>
<td width="50%">
<input id="productName" name="productName" class="easyui-textbox" style="width: 360px;" readonly="readonly"/>
</td>
</tr>
<tr style="height: 60px" id="brandNameTR">
<td width="12%">品牌</td>
<td width="20%">
<input id="brandName" name="brandName" class="easyui-textbox" style="width: 200px;" readonly="readonly"/>
</td>
</tr>
<tr style="height: 60px" id="yohoSortStrTR">
<td width="12%">有货类目</td>
<td width="20%">
<input id="yohoSortStr" name="yohoSortStr" class="easyui-textbox" style="width: 200px;" readonly="readonly"/>
</td>
</tr>
<tr style="height: 60px" id="ufoSortStrTR">
<td width="12%">UFO类目</td>
<td width="20%">
<input id="ufoSortStr" name="ufoSortStr" class="easyui-textbox" style="width: 200px;" readonly="readonly"/>
</td>
</tr>
<tr style="height: 60px" id="yohoImageTR">
<td width="20%">有货封面图</td>
<td>
<img id="yohoImage" name="yohoImage" src="" style="height: 120px;width: 171px"></img>
</td>
</tr>
<tr style="height: 60px">
<td width="20%">UFO封面图</td>
<td>
<div id="ufoImage" name="ufoImage"></div>
</td>
</tr>
</table>
</div>
</form>
</div>
<script>
/*function queryProductInfo() {
if(editId <= 0){
var skn = $("#sknEditForm #productSkn").numberbox("getValue");
alert(skn);
if(skn != null && skn != ""){
$.post(contextPath + "/yoho2ufoProduct/getYoho2ufoProductBySkn", {
skn: skn
}, function (data) {
$("#sknEditForm").form("load", data.data);
$("#sknEditForm #yohoImage").attr("src", data.data.yohoImage);
$("#productNameTR").show();
$("#brandNameTR").show();
$("#yohoSortStrTR").show();
$("#ufoSortStrTR").show();
$("#yohoImageTR").show();
});
}
}
}
*/
$(function () {
$("input",$("#sknEditForm #productSkn").next("span")).blur(function(){
if(editId <= 0){
var skn = $("#sknEditForm #productSkn").numberbox("getValue");
if(skn != null && skn != ""){
$.post(contextPath + "/yoho2ufoProduct/getYoho2ufoProductBySkn", {
skn: skn
}, function (data) {
if(jQuery.isEmptyObject(data.data)){
var sknData = $("#sknEditForm #productSkn").numberbox("getValue");
$("#sknEditForm").form("clear");
$("#sknEditForm #productSkn").numberbox("setValue",sknData);
$("#productNameTR").hide();
$("#brandNameTR").hide();
$("#yohoSortStrTR").hide();
$("#ufoSortStrTR").hide();
$("#yohoImageTR").hide();
}else{
$("#sknEditForm").form("load", data.data);
$("#sknEditForm #yohoImage").attr("src", data.data.yohoImage);
$("#productNameTR").show();
$("#brandNameTR").show();
$("#yohoSortStrTR").show();
$("#ufoSortStrTR").show();
$("#yohoImageTR").show();
}
});
}
}
});
$("#sknEditForm #ufoImage").imageUpload({
width: 171,
height: 120,
realInputName: "ufoImage",
url: contextPath + '/fileupload/upload',
queryParams: {
bucket: "goodsimg"
},
onBeforeSubmit: function () {
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
},
filterFileName: function (data) {
if (!data || data.code != 200) {
$.messager.progress("close");
$.messager.alert("错误", data.message);
return "";
}
return data.data;
},
onLoadSuccess: function (data) {
$.messager.progress("close");
return false;
}
});
// 隐藏域赋值
$('#sknEditForm #id').val(editId);
if (editId > 0) {
$.post(contextPath + "/yoho2ufoProduct/getYoho2ufoProductById", {
id: editId
}, function (data) {
$("#sknEditForm #productSkn").numberbox('readonly', true);
$("#sknEditForm").form("load", data.data);
$("#sknEditForm #ufoImage").imageUpload("setValue", data.data.ufoImage);
$("#sknEditForm #yohoImage").attr("src", data.data.yohoImage);
});
}else{
$("#productNameTR").hide();
$("#brandNameTR").hide();
$("#yohoSortStrTR").hide();
$("#ufoSortStrTR").hide();
$("#yohoImageTR").hide();
}
});
</script>
\ No newline at end of file
... ...
<!DOCTYPE html>
<body class="easyui-layout" fit="true">
<div id="editDivId">
<form id="sknBatchDelForm" name="sknBatchDelForm" method="post">
<table id="sknBatchDelTable" border="0" align="center" style="line-height: 30px;width:95%">
<tr>
<td width="10%"><span style="color:red">&nbsp;*</span>skn</td>
<td>
<textarea id="skns" name="skns" style="height:100px;width:280px;" onKeyUp="javascript:this.value=this.value.replace(/[^\r\n0-9\,]/g,'');"/>
<span>&nbsp;(skn,逗号分隔)</span>
</td>
</tr>
<tr>
</table>
</form>
</div>
</body>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Yoho!Buy运营平台</title>
<script src="/ufoPlatform/js/include.js"></script>
<script src="/ufoPlatform/js/ajaxfileupload.js"></script>
</head>
<body class="easyui-layout" fit="true">
<div region="north" style="height: 230px">
<script>
document.write(addHead('UFO显示有货商品配置', ''));
</script>
<style>
.div_search input {
margin-top: 20px;
}
.div_search .textbox {
margin-top: 20px;
}
.div_search .easyui-linkbutton {
margin-top: 20px;
}
</style>
<div style="margin-left: 30px;" class="div_search">
<input id="productSkn" type="text">
<input id="productName" type="text">
<input id="brandName" type="text">
<a id="searchLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">筛选</a>
<a id="searchAllLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">全部</a>
<a id="addSkn" class="easyui-linkbutton btn-success" data-options="iconCls:'icon-search'">新增</a>
<a id="delSknBatch" style="margin-left: 200px;" class="easyui-linkbutton btn-danger" data-options="iconCls:'icon-search'">批量删除</a>
</div>
</div>
<div region="center">
<div style="margin-left: 30px;margin-top: 20px;height: 660px">
<table id="sknListTable"></table>
</div>
</div>
<script type="text/javascript">
var editId;
$(function () {
$("#productSkn").textbox({
prompt: "有货SKN"
});
$("#productName").textbox({
prompt: "商品名称"
});
$("#brandName").textbox({
prompt: "品牌名称"
});
$('#addSkn').linkbutton({
iconCls: "icon-edit",
onClick: function () {
editRow(0);
}
});
$("#sknListTable").myDatagrid({
fit: true,
fitColumns: true,
nowrap: false,
url: contextPath + "/yoho2ufoProduct/list",
method: 'POST',
loadFilter: function (data) {
var temp = defaultLoadFilter(data);
temp.rows = temp.list;
return temp;
},
columns: [[{
title: "ID",
field: "id",
align: "center",
hidden: true
}, {
title: "有货SKN",
field: "productSkn",
width: 80,
align: "center"
}, {
title: "商品名称",
field: "productName",
width: 120,
align: "center",
},{
title: "品牌",
field: "brandName",
width: 80,
align: "center"
},{
title: "有货类目",
field: "yohoSortStr",
width: 120,
align: "center"
},{
title: "UFO类目",
field: "ufoSortStr",
width: 120,
align: "center"
}, {
title: "有货封面图",
field: "yohoImage",
width: 80,
align: "center",
formatter: function(value) {
return '<img src="' + value + '" style="width: 48px; height: 48px;vertical-align: middle;">'
}
}, {
title: "UFO封面图",
field: "ufoImage",
width: 80,
align: "center",
formatter: function(value) {
return '<img src="' + value + '" style="width: 48px; height: 48px;vertical-align: middle;">'
}
}, {
title: "操作",
field: "operations",
width: 80,
align: "center",
formatter: function (value, rowData) {
var str = "<a role='edit' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #5bc0de'>编辑</a>";
str += "<a role='del' dataId='" + rowData.id + "' style='margin-left:10px;background-color: red'>删除</a>";
return str;
}
}]],
cache: false,
pagination: true,
pageSize: 10,
pageList: [10],
idField: "id",
singleSelect: false,
checkOnSelect: false,
onLoadSuccess: function () {
// 编辑
$(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls: "icon-edit",
onClick: function () {
var id = $(this).attr("dataId");
editRow(id);
}
});
// 删除
$(this).myDatagrid("getPanel").find("a[role='del']").linkbutton({
iconCls: "icon-more",
onClick: function () {
del($(this).attr("dataId"));
}
});
}
});
// 搜索
$("#searchLinkButton").linkbutton({
onClick: function () {
var param = getParams();
$("#sknListTable").myDatagrid("load", param);
}
});
// 搜索全部
$("#searchAllLinkButton").linkbutton({
onClick: function () {
$('#productSkn').textbox('clear');
$('#brandName').textbox('clear');
$('#productName').textbox('clear');
var param = {};
$("#sknListTable").myDatagrid("load", param);
}
});
$("#delSknBatch").linkbutton({
text : "批量删除",
iconCls : "icon-add",
onClick : function() {
delSknBatch();
}
});
/**
* 提取出搜索参数
*/
function getParams() {
// skn
var productSkn = $('#productSkn').textbox('getText');
// 品牌名称
var brandName = $('#brandName').textbox('getText');
// 产品名称
var productName = $('#productName').textbox('getText');
var param = {};
if (undefined !== productSkn && null !== productSkn && "" !== productSkn) {
param.productSkn = productSkn;
}
if (undefined !== brandName && null !== brandName && "" !== brandName) {
param.brandName = brandName;
}
if (undefined !== productName && null !== productName && "" !== productName) {
param.productName = productName;
}
return param;
}
function editRow(id) {
editId = id;
var div = $("<div>").appendTo($(document.body));
var title = "编辑";
var message = "确认修改吗?";
if (id == 0) {
title = "添加";
message = "确认添加吗?";
}
$(div).myDialog({
width: "600px",
height: "800px",
title: title,
href: contextPath + "/html/yoho2ufoproduct/editYoho2UfoProduct.html",
queryParams: {
id: id
},
modal: true,
collapsible: true,
cache: false,
buttons: [{
id: "saveBtn",
text: "保存",
handler: function () {
$.messager.confirm("确认", message, function (flag) {
if (flag) {
var url = contextPath + "/yoho2ufoProduct/addOrUpdate";
$("#sknEditForm").form("submit", {
url: url,
onSubmit: function () {
if (!$("#sknEditForm").form("validate")) {
return false;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后..."
});
return true;
},
success: function (data) {
$.messager.progress("close");
data = JSON.parse(data);
if (data.code == 200) {
$(div).dialog("close");
$("#sknListTable").myDatagrid("reload");
$.messager.show({
title: "提示",
msg: title + "成功!",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$(div).dialog("close");
}
}]
});
}
function del(id) {
var message = "确定要删除吗?";
var msg = "删除成功";
$.messager.confirm("确认", message, function (flag) {
if (flag) {
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
$.post(contextPath + "/yoho2ufoProduct/deleteYoho2ufoProductById", {
"id": id
}, function (data) {
$.messager.progress("close");
if (data.code == 200) {
$("#sknListTable").myDatagrid("reload");
$.messager.show({
title: "提示",
msg: msg,
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}, "json");
}
});
}
function delSknBatch() {
var title="批量删除";
var div = $("<div>").appendTo($(window.self.document.body));
window.self.$(div).myDialog({
title: title,
width: "40%",
height: "30%",
resizable:true,
buttons:[{
id : "saveBtnAdd",
text:'删除',
iconCls : "icon-save",
handler:function(){
var url = contextPath + "/yoho2ufoProduct/deleteBatchYoho2ufoProduct";
window.self.$("#sknBatchDelForm").form("submit", {
url : url,
onSubmit : function(param) {
if (!$("#sknBatchDelForm").form("validate")) {
return false;
}
$.messager.progress({
title : "正在执行",
msg : "正在执行,请稍后..."
});
return true;
},
success : function(data) {
$.messager.progress("close");
data = JSON.parse(data);
if (data.code == 200) {
window.self.$(div).myDialog("close");
$("#sknListTable").datagrid("reload");
$.messager.show({
title : "提示",
msg : title + "成功!"
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
},{
id : "closeBtnAdd",
text:'取消',
iconCls : "icon-cancel",
handler:function(){
window.self.$(div).dialog('close');
}
}],
modal: true,
href: contextPath + "/html/yoho2ufoproduct/yoho2UfoProductBatchDel.html",
onOpen : function() {
window.setTimeout(function() {
$("#saveBtnAdd").addClass("btn-success");
$("#closeBtnAdd").addClass("btn-danger");
}, 100);
}
});
}
});
</script>
</body>
</html>
\ No newline at end of file
... ...