Authored by Lixiaodi

销售类目查询

package com.yohoufo.dal.product;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yohoufo.dal.product.model.SaleCategory;
public interface SaleCategoryMapper {
SaleCategory selectByPrimaryKey(Integer id);
List<SaleCategory> selectValid();
List<SaleCategory> selectByPidList(@Param("pidList") List<Integer> pidList);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.product.model;
public class SaleCategory {
private Integer id;
private String categoryName;
private Short level;
private Integer parentId;
private Byte status;
private Integer createTime;
private Integer updateTime;
private Integer orderBy;
private String linkType;
private String linkDetail;
private String imageUrl;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCategoryName() {
return categoryName;
}
public void setCategoryName(String categoryName) {
this.categoryName = categoryName == null ? null : categoryName.trim();
}
public Short getLevel() {
return level;
}
public void setLevel(Short level) {
this.level = level;
}
public Integer getParentId() {
return parentId;
}
public void setParentId(Integer parentId) {
this.parentId = parentId;
}
public Byte getStatus() {
return status;
}
public void setStatus(Byte status) {
this.status = status;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Integer getOrderBy() {
return orderBy;
}
public void setOrderBy(Integer orderBy) {
this.orderBy = orderBy;
}
public String getLinkType() {
return linkType;
}
public void setLinkType(String linkType) {
this.linkType = linkType == null ? null : linkType.trim();
}
public String getLinkDetail() {
return linkDetail;
}
public void setLinkDetail(String linkDetail) {
this.linkDetail = linkDetail == null ? null : linkDetail.trim();
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
}
\ 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.yohoufo.dal.product.SaleCategoryMapper" >
<resultMap id="BaseResultMap" type="com.yohoufo.dal.product.model.SaleCategory" >
<id column="id" property="id" jdbcType="INTEGER" />
<result column="category_name" property="categoryName" jdbcType="VARCHAR" />
<result column="level" property="level" jdbcType="SMALLINT" />
<result column="parent_id" property="parentId" jdbcType="INTEGER" />
<result column="status" property="status" jdbcType="TINYINT" />
<result column="create_time" property="createTime" jdbcType="INTEGER" />
<result column="update_time" property="updateTime" jdbcType="INTEGER" />
<result column="order_by" property="orderBy" jdbcType="INTEGER" />
<result column="link_type" property="linkType" jdbcType="VARCHAR" />
<result column="link_detail" property="linkDetail" jdbcType="VARCHAR" />
<result column="image_url" property="imageUrl" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List" >
id, category_name, level, parent_id, status, create_time, update_time, order_by,
link_type, link_detail,image_url
</sql>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from sale_category
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectValid" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
<include refid="Base_Column_List" />
from sale_category where status=0
order by order_by
</select>
<select id="selectByPidList" resultMap="BaseResultMap">
select <include refid="Base_Column_List" />
from sale_category where parent_id in
<foreach item="item" index="index" collection="pidList" open="(" separator="," close=")">
#{item}
</foreach>
and status=0 order by order_by
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -28,6 +28,7 @@ import com.yohoufo.product.response.ProductDetailResp;
import com.yohoufo.product.response.ProductSeriesTemplateResp;
import com.yohoufo.product.response.ProductSimpleResp;
import com.yohoufo.product.response.ProductSortTemplateResp;
import com.yohoufo.product.response.SaleCategoryBo;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import com.yohoufo.product.service.ProductService;
... ... @@ -399,4 +400,29 @@ public class ProductController {
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("storage data").build();
}
@ApiOperation(name = "ufo.product.saleCategory", desc="商品销售类目")
@IgnoreSignature
@IgnoreSession
@RequestMapping(params = "method=ufo.product.saleCategory")
@Cachable(expire = 180)
public ApiResponse querySaleCategory() {
LOG.info("in method=ufo.product.querySaleCategory");
List<SaleCategoryBo> resp = productService.querySaleCategory();
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("saleCategory data").build();
}
@ApiOperation(name = "ufo.product.saleCategoryDetail", desc="商品销售类目二级三级")
@RequestMapping(params = "method=ufo.product.saleCategoryDetail")
@Cachable(expire = 180)
public ApiResponse querySaleCategoryDetail(@RequestParam(value = "id") Integer id) {
if (id == null || id < 1) {
LOG.info("in method=ufo.product.saleCategoryDetail id Is Null");
return null;
}
LOG.info("in method=ufo.product.saleCategoryDetail id = {}", id);
List<SaleCategoryBo> resp = productService.querySaleCategoryDetail(id);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("saleCategoryDetail data").build();
}
}
\ No newline at end of file
... ...
... ... @@ -7,6 +7,7 @@ import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.product.helper.SearchHelpService;
import com.yohoufo.product.request.ProductSearchReq;
import com.yohoufo.product.request.SortIdLevel;
import com.yohoufo.product.response.ProductBrandSeriesResp;
import com.yohoufo.product.response.SearchBrandListResp;
import com.yohoufo.product.response.SearchProductListFilterResp;
import com.yohoufo.product.response.SearchProductRecommendResp;
... ... @@ -22,6 +23,7 @@ import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.cache.Cachable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
... ... @@ -133,4 +135,16 @@ public class ProductSearchController {
return new ApiResponse.ApiResponseBuilder().code(200).message("product.search.brandList").data(resp).build();
}
@IgnoreSignature
@ApiOperation(name = "ufo.product.search.seriesList", desc="品牌系列列表")
@RequestMapping(params = "method=ufo.product.search.seriesList")
@IgnoreSession
@Cachable(expire = 180)
public ApiResponse searchSeriesList() {
List<ProductBrandSeriesResp> resp = productSearchService.searchSeriesList();
return new ApiResponse.ApiResponseBuilder().code(200).message("product.search.seriesList").data(resp).build();
}
}
\ No newline at end of file
... ...
package com.yohoufo.product.response;
import com.yohoufo.product.model.ProductSeriesTemplate;
import com.yohoufo.product.response.SearchBrandListResp.BrandIntro;
import lombok.Data;
import java.util.List;
@Data
public class ProductBrandSeriesResp {
private BrandIntro brand;
private List<ProductSeriesTemplate> series;
}
... ...
package com.yohoufo.product.response;
import java.util.List;
import lombok.Data;
@Data
public class SaleCategoryBo {
private Integer id;
private String name;
private String image;
private String linkType;
private String link;
private Integer pid;
private List<SaleCategoryBo> sub;
}
... ...
package com.yohoufo.product.service;
import java.util.List;
import com.alibaba.fastjson.JSONObject;
import com.yohoufo.product.request.ProductSearchReq;
import com.yohoufo.product.request.SortIdLevel;
import com.yohoufo.product.response.ProductBrandSeriesResp;
import com.yohoufo.product.response.SearchBrandListResp;
import com.yohoufo.product.response.SearchProductListFilterResp;
import com.yohoufo.product.response.SearchProductRecommendResp;
... ... @@ -20,4 +23,6 @@ public interface ProductSearchService {
SearchProductRecommendResp searchProductRecommendById(Integer productId);
List<ProductBrandSeriesResp> searchSeriesList();
}
... ...
... ... @@ -8,6 +8,7 @@ import com.yohoufo.product.response.ProductDetailResp;
import com.yohoufo.product.response.ProductSeriesTemplateResp;
import com.yohoufo.product.response.ProductSimpleResp;
import com.yohoufo.product.response.ProductSortTemplateResp;
import com.yohoufo.product.response.SaleCategoryBo;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
... ... @@ -65,4 +66,8 @@ public interface ProductService {
* @return
*/
StorageLeastPriceResp querStorageLeastPriceEx(Integer storageId);
List<SaleCategoryBo> querySaleCategory();
List<SaleCategoryBo> querySaleCategoryDetail(Integer id);
}
... ...
... ... @@ -17,11 +17,15 @@ import com.yohoufo.dal.product.model.Product;
import com.yohoufo.dal.product.model.ProductSort;
import com.yohoufo.product.helper.SearchParam;
import com.yohoufo.product.model.FilterItem;
import com.yohoufo.product.model.ProductSeriesTemplate;
import com.yohoufo.product.request.ProductSearchReq;
import com.yohoufo.product.request.SortIdLevel;
import com.yohoufo.product.response.ProductBrandSeriesResp;
import com.yohoufo.product.response.SearchBrandListResp;
import com.yohoufo.product.response.SearchProductListFilterResp;
import com.yohoufo.product.response.SearchProductRecommendResp;
import com.yohoufo.product.response.SearchBrandListResp.BrandIntro;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
... ... @@ -61,6 +65,8 @@ public class ProductSearchServiceImpl implements ProductSearchService {
public static final String BRAND_LIST_URL = "/yohosearch/ufo/brandList.json";
public static final String SERIES_LIST_URL = "/yohosearch/ufo/seriesList.json";
public static final String PRODUCT_RECOMMEND_LIST_URL = "/yohosearch/ufo/recommendList.json";
... ... @@ -295,4 +301,35 @@ public class ProductSearchServiceImpl implements ProductSearchService {
return sortIdLevel;
}
@Override
public List<ProductBrandSeriesResp> searchSeriesList() {
List<ProductBrandSeriesResp> respList = new ArrayList<>();
SearchParam searchParam = new SearchParam();
JSONObject data = search(searchParam.getParam(), SERIES_LIST_URL);
JSONArray series;
if (data != null && !CollectionUtils.isEmpty(series = data.getJSONArray("series_list"))) {
for (int i = 0; i < series.size(); i++) {
JSONObject jo = series.getJSONObject(i);
ProductBrandSeriesResp resp = new ProductBrandSeriesResp();
BrandIntro brand = new BrandIntro();
brand.setId(jo.getInteger("brand_id"));
brand.setBrandLogo(jo.getString("brand_logo"));
resp.setBrand(brand);
List<ProductSeriesTemplate> seriesList = new ArrayList<>();
JSONArray brandSeries = jo.getJSONArray("brand_series");
for (int j = 0; j < brandSeries.size(); j++) {
JSONObject jo2 = brandSeries.getJSONObject(j);
ProductSeriesTemplate t = new ProductSeriesTemplate();
t.setSeriesId(jo2.getString("series_id"));
t.setSeriesName(jo2.getString("series_name"));
t.setImageUrl(jo2.getString("series_image"));
seriesList.add(t);
}
resp.setSeries(seriesList);
respList.add(resp);
}
}
return respList;
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yohoufo.product.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
... ... @@ -29,6 +30,7 @@ import com.yohoufo.dal.product.BrandSeriesMapper;
import com.yohoufo.dal.product.GoodsImagesMapper;
import com.yohoufo.dal.product.GoodsMapper;
import com.yohoufo.dal.product.ProductMapper;
import com.yohoufo.dal.product.SaleCategoryMapper;
import com.yohoufo.dal.product.SizeMapper;
import com.yohoufo.dal.product.StorageMapper;
import com.yohoufo.dal.product.StoragePriceMapper;
... ... @@ -37,6 +39,7 @@ import com.yohoufo.dal.product.model.BrandSeries;
import com.yohoufo.dal.product.model.Goods;
import com.yohoufo.dal.product.model.GoodsImages;
import com.yohoufo.dal.product.model.Product;
import com.yohoufo.dal.product.model.SaleCategory;
import com.yohoufo.dal.product.model.Size;
import com.yohoufo.dal.product.model.Storage;
import com.yohoufo.dal.product.model.StoragePrice;
... ... @@ -51,6 +54,7 @@ import com.yohoufo.product.response.ProductDetailResp;
import com.yohoufo.product.response.ProductSeriesTemplateResp;
import com.yohoufo.product.response.ProductSimpleResp;
import com.yohoufo.product.response.ProductSortTemplateResp;
import com.yohoufo.product.response.SaleCategoryBo;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import com.yohoufo.product.service.ProductService;
... ... @@ -84,7 +88,10 @@ public class ProductServiceImpl implements ProductService{
@Autowired
private SizeMapper sizeMapper;
@Autowired
private SaleCategoryMapper saleCategoryMapper;
@Override
public ProductDetailResp queryProductDetailById(Integer productId) {
ProductDetailResp productDetailResp = new ProductDetailResp();
... ... @@ -641,6 +648,14 @@ public class ProductServiceImpl implements ProductService{
return url;
}
}
private String buildSaleCategoryFullUrl(String url) {
if (!StringUtils.startsWith(url, "http")){
return ImagesHelper.template2(url, "salecategoryimg").replaceAll("extent\\/\\{width}x\\{height}\\/","");
}else{
return url;
}
}
@Override
public ProductSimpleResp queryPriceLimit(Integer productId) {
... ... @@ -683,4 +698,48 @@ public class ProductServiceImpl implements ProductService{
public int sellerBatchUpdatePrice(List<Integer> skupList, Double price) {
return storagePriceMapper.updateBatchPrice(skupList, price);
}
@Override
public List<SaleCategoryBo> querySaleCategory() {
// 查数据库List
List<SaleCategory> dbData = saleCategoryMapper.selectValid();
List<SaleCategoryBo> result = new ArrayList<>();
dbData.forEach(data -> {
result.add(exchange(data));
});
return result;
}
@Override
public List<SaleCategoryBo> querySaleCategoryDetail(Integer id) {
List<SaleCategoryBo> result = new ArrayList<>();
List<SaleCategory> secondCat = saleCategoryMapper.selectByPidList(Arrays.asList(id));
if (!CollectionUtils.isEmpty(secondCat)) {
secondCat.forEach(data -> {
result.add(exchange(data));
});
Map<Integer, SaleCategoryBo> map = result.stream().collect(Collectors.toMap(SaleCategoryBo::getId, Function.identity()));
List<Integer> secondCatIds = secondCat.stream().map(SaleCategory::getId).collect(Collectors.toList());
List<SaleCategory> thirdCat = saleCategoryMapper.selectByPidList(secondCatIds);
thirdCat.forEach(t -> {
SaleCategoryBo bo = map.get(t.getParentId());
if (bo != null) {
bo.getSub().add(exchange(t));
}
});
}
return result;
}
private SaleCategoryBo exchange(SaleCategory data) {
SaleCategoryBo sc = new SaleCategoryBo();
sc.setId(data.getId());
sc.setName(data.getCategoryName());
sc.setLinkType(data.getLinkType());
sc.setLink(data.getLinkDetail());
sc.setImage(buildSaleCategoryFullUrl(data.getImageUrl()));
sc.setSub(new ArrayList<>());
return null;
}
}
... ...