Authored by mali

Merge branch 'master' of http://git.yoho.cn/ufo/yohoufo-fore

... ... @@ -13,4 +13,6 @@ public interface GoodsImagesMapper {
List<GoodsImages> selectAll();
int updateByPrimaryKey(GoodsImages record);
List<GoodsImages> selectByGoodsId(Integer goodsId);
}
\ No newline at end of file
... ...
... ... @@ -13,4 +13,6 @@ public interface GoodsMapper {
List<Goods> selectAll();
int updateByPrimaryKey(Goods record);
List<Goods> selectByProductId(Integer productId);
}
\ No newline at end of file
... ...
... ... @@ -13,4 +13,6 @@ public interface SizeMapper {
List<Size> selectAll();
int updateByPrimaryKey(Size record);
List<Size> selectByIds(List<Integer> ids);
}
\ No newline at end of file
... ...
... ... @@ -16,5 +16,5 @@ public interface StorageMapper {
int updateByPrimaryKey(Storage record);
StorageGoodProductSize selectStroageProductInfo(Integer id);
List<Storage> selectByGoodsId(Integer goodsId);
}
\ No newline at end of file
... ...
... ... @@ -22,4 +22,6 @@ public interface StoragePriceMapper {
int cancelSaleSkup(Integer skup);
StoragePrice selectLeastPrice(Integer storageId);
List<StoragePrice> selectByStorageIds(List<Integer> storageIds);
}
\ No newline at end of file
... ...
... ... @@ -7,7 +7,7 @@ public class Brand {
private String brandNameEn;
private String brandLog;
private String brandLogo;
private String brandSearch;
... ... @@ -45,12 +45,12 @@ public class Brand {
this.brandNameEn = brandNameEn;
}
public String getBrandLog() {
return brandLog;
public String getBrandLogo() {
return brandLogo;
}
public void setBrandLog(String brandLog) {
this.brandLog = brandLog;
public void setBrandLogo(String brandLogo) {
this.brandLogo = brandLogo;
}
public String getBrandSearch() {
... ...
... ... @@ -5,7 +5,7 @@
<id column="id" jdbcType="INTEGER" property="id" />
<result column="brand_name" jdbcType="VARCHAR" property="brandName" />
<result column="brand_name_en" jdbcType="VARCHAR" property="brandNameEn" />
<result column="brand_log" jdbcType="VARCHAR" property="brandLog" />
<result column="brand_logo" jdbcType="VARCHAR" property="brandLogo" />
<result column="brand_search" jdbcType="VARCHAR" property="brandSearch" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
... ... @@ -19,11 +19,11 @@
</delete>
<insert id="insert" parameterType="com.yohoufo.dal.product.model.Brand">
insert into brand (id, brand_name, brand_name_en,
brand_log, brand_search, status,
brand_logo, brand_search, status,
create_time, edit_time, edit_pid, order_by
)
values (#{id,jdbcType=INTEGER}, #{brandName,jdbcType=VARCHAR}, #{brandNameEn,jdbcType=VARCHAR},
#{brandLog,jdbcType=VARCHAR}, #{brandSearch,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
#{brandLogo,jdbcType=VARCHAR}, #{brandSearch,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER}, #{editTime,jdbcType=INTEGER}, #{editPid,jdbcType=INTEGER}, #{orderBy,jdbcType=INTEGER}
)
</insert>
... ... @@ -31,7 +31,7 @@
update brand
set brand_name = #{brandName,jdbcType=VARCHAR},
brand_name_en = #{brandNameEn,jdbcType=VARCHAR},
brand_log = #{brandLog,jdbcType=VARCHAR},
brand_logo = #{brandLogo,jdbcType=VARCHAR},
brand_search = #{brandSearch,jdbcType=VARCHAR},
status = #{status,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER},
... ... @@ -41,13 +41,13 @@
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, brand_name, brand_name_en, brand_log, brand_search, status, create_time,
select id, brand_name, brand_name_en, brand_logo, brand_search, status, create_time,
edit_time, edit_pid, order_by
from brand
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, brand_name, brand_name_en, brand_log, brand_search, status, create_time,
select id, brand_name, brand_name_en, brand_logo, brand_search, status, create_time,
edit_time, edit_pid, order_by
from brand
</select>
... ...
... ... @@ -39,4 +39,8 @@
select id, goods_id, product_id, is_default, image_url, order_by
from goods_images
</select>
<select id="selectByGoodsId" resultMap="BaseResultMap">
select image_url
from goods_images where goods_id = #{goodsId,jdbcType=INTEGER} order BY order_by;
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -41,4 +41,8 @@
select id, product_id, color_id, color_name, goods_name, color_image, is_default
from goods
</select>
<select id="selectByProductId" resultMap="BaseResultMap">
select id, product_id, color_name, goods_name
from goods where product_id = #{productId,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -32,11 +32,20 @@
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, size_name, sort_id, order_by, create_time, update_time
from size
from `size`
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, size_name, sort_id, order_by, create_time, update_time
from size
from `size`
</select>
<select id="selectByIds" resultMap="BaseResultMap">
select id, size_name, order_by
from `size` where id in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
order by order_by
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -53,10 +53,8 @@
select id, product_id, goods_id, size_id, storage_num, update_time, create_time
from storage
</select>
<select id="selectStroageProductInfo" parameterType="java.lang.Integer" resultMap="StorageGoodProductSizeResultMap">
select * from
(select s.product_id, p.product_name, g.color_id,g.color_name,g.color_image, s.size_id,sz.size_name from
(select * from `storage` s where s.id=#{id,jdbcType=INTEGER}) as s left JOIN goods g on s.goods_id = g.id
left JOIN product p on s.product_id = p.id left JOIN `size` sz on sz.id =s.size_id) r
<select id="selectByGoodsId" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num
from storage where goods_id=#{goodsId,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -72,4 +72,15 @@
<select id="selectLeastPrice" resultMap="BaseResultMap">
select MIN(price) price, skup from storage_price where storage_id = #{storageId,jdbcType=INTEGER} and status = 1
</select>
<select id="selectByStorageIds" resultMap="BaseResultMap">
select id, skup, storage_id, price, status
from storage_price
where storage_id in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
group by storage_id order by price
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -26,5 +26,9 @@
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-dal</artifactId>
</dependency>
<dependency>
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-resource</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
... ...
... ... @@ -49,7 +49,9 @@ public class ProductController {
if (null == productId) {
return new ApiResponse(500, "product_id Is Null", null);
}
LOG.info("queryProductDetailById method=ufo.product.data productId is:{},productId is:{}", productId);
ProductDetailResp resp = productService.queryProductDetailById(productId);
return new ApiResponse.ApiResponseBuilder().data(mockProductDetail(productId)).code(200).message("product data").build();
}
... ...
... ... @@ -4,9 +4,9 @@ import com.alibaba.fastjson.annotation.JSONField;
import java.util.List;
public class Goods {
public class GoodsBO {
@JSONField(name="goods_id")
@JSONField(name = "goods_id")
private Integer id;
@JSONField(name = "goods_name")
... ... @@ -15,13 +15,10 @@ public class Goods {
@JSONField(name = "color_name")
private String colorName;
@JSONField(name="status")
private Integer status;
@JSONField(name = "image_list")
private List<GoodsImage> imageList;
private List<GoodsImageBO> imageList;
@JSONField(name="size_list")
@JSONField(name = "size_list")
private List<GoodsSize> sizeList;
public Integer getId() {
... ... @@ -48,11 +45,11 @@ public class Goods {
this.colorName = colorName;
}
public List<GoodsImage> getImageList() {
public List<GoodsImageBO> getImageList() {
return imageList;
}
public void setImageList(List<GoodsImage> imageList) {
public void setImageList(List<GoodsImageBO> imageList) {
this.imageList = imageList;
}
... ... @@ -63,12 +60,4 @@ public class Goods {
public void setSizeList(List<GoodsSize> sizeList) {
this.sizeList = sizeList;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}
... ...
... ... @@ -8,11 +8,17 @@ import java.io.Serializable;
* 商品图片信息VO
*
*/
public class GoodsImage {
public class GoodsImageBO {
@JSONField(name="image_url")
private String imageUrl;
public static GoodsImageBO create(String imageUrl){
GoodsImageBO goodsImageBO = new GoodsImageBO();
goodsImageBO.setImageUrl(imageUrl);
return goodsImageBO;
}
public String getImageUrl() {
return imageUrl;
}
... ...
... ... @@ -29,7 +29,7 @@ public class ProductInfo {
private BigDecimal leastPrice;
@JSONField(name="goods_list")
private List<Goods> goodsList;
private List<GoodsBO> goodsList;
public Integer getProductId() {
return productId;
... ... @@ -79,11 +79,11 @@ public class ProductInfo {
this.productCode = productCode;
}
public List<Goods> getGoodsList() {
public List<GoodsBO> getGoodsList() {
return goodsList;
}
public void setGoodsList(List<Goods> goodsList) {
public void setGoodsList(List<GoodsBO> goodsList) {
this.goodsList = goodsList;
}
... ...
package com.yohoufo.product.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.yohoufo.dal.product.StorageMapper;
import com.yohoufo.dal.product.model.StorageGoodProductSize;
import com.yoho.core.common.helpers.ImagesHelper;
import com.yohoufo.dal.product.*;
import com.yohoufo.dal.product.model.*;
import com.yohoufo.product.model.GoodsImageBO;
import com.yohoufo.product.model.GoodsSize;
import com.yohoufo.product.model.GoodsBO;
import com.yohoufo.product.model.ProductInfo;
import com.yohoufo.product.response.StorageDataResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.dal.product.ProductMapper;
import com.yohoufo.dal.product.StoragePriceMapper;
import com.yohoufo.dal.product.model.Product;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.request.StoragePriceBo;
import com.yohoufo.product.response.ProductDetailResp;
import com.yohoufo.product.service.ProductService;
import com.yohoufo.resource.util.DateUtils;
import org.springframework.util.CollectionUtils;
@Service
... ... @@ -37,11 +45,118 @@ public class ProductServiceImpl implements ProductService{
@Autowired
private StorageMapper storageMapper;
@Autowired
private BrandMapper brandMapper;
@Autowired
private BrandSeriesMapper brandSeriesMapper;
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private GoodsImagesMapper goodsImagesMapper;
@Autowired
private SizeMapper sizeMapper;
@Override
public ProductDetailResp queryProductDetailById(Integer productId) {
return null;
ProductDetailResp productDetailResp = new ProductDetailResp();
Product product = productMapper.selectByPrimaryKey(productId);
if (product != null) {
ProductInfo productInfo = new ProductInfo();
productInfo.setProductId(product.getId());
productInfo.setProductName(product.getProductName());
productInfo.setProductCode(product.getProductCode());
productInfo.setSaleTime(DateUtils.getDateString(product.getSaleTime()));
if (product.getBrandId() != null) {
Brand brand = brandMapper.selectByPrimaryKey(product.getBrandId());
if (brand != null) {
productInfo.setBrandName(brand.getBrandName());
}
}
if (product.getSeriesId() != null) {
BrandSeries series = brandSeriesMapper.selectByPrimaryKey(product.getSeriesId());
if (series != null) {
productInfo.setSeriesName(series.getSeriesName());
}
}
List<Goods> goodsList = goodsMapper.selectByProductId(productId);
if (!CollectionUtils.isEmpty(goodsList) && goodsList.get(0) != null) {
Goods goods = goodsList.get(0);
List<GoodsBO> goodsBOs = new ArrayList<>();
GoodsBO goodsBO = new GoodsBO();
goodsBO.setId(goods.getId());
goodsBO.setColorName(goods.getColorName());
goodsBO.setGoodsName(goods.getGoodsName());
List<GoodsImageBO> imageList = new ArrayList<>();
goodsBO.setImageList(imageList);
List<GoodsSize> goodSizeList = new ArrayList<>();
goodsBO.setSizeList(goodSizeList);
goodsBOs.add(goodsBO);
List<GoodsImages> goodsImages = goodsImagesMapper.selectByGoodsId(goods.getId());
if (!CollectionUtils.isEmpty(goodsImages)) {
List<String> imageUrlList = goodsImages.stream().map(GoodsImages::getImageUrl).filter(StringUtils::isBlank).map(this::buildImageFullUrl).collect(Collectors.toList());
imageUrlList.forEach(e -> imageList.add(GoodsImageBO.create(e)));
}
List<Storage> storageList = storageMapper.selectByGoodsId(goods.getId());
if (!CollectionUtils.isEmpty(storageList)) {
Map<Integer, Size> sizeMap = new HashMap<>();
List<Integer> sizeIds = storageList.stream().map(Storage::getSizeId).filter(e -> e != null && 0 != e).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(sizeIds)) {
List<Size> sizes = sizeMapper.selectByIds(sizeIds);
if (!CollectionUtils.isEmpty(sizes)) {
sizeMap = sizes.stream().collect(Collectors.toMap(Size::getId, Function.identity()));
}
}
Map<Integer, StoragePrice> storagePriceMap = new HashMap<>();
List<Integer> storageIds = storageList.stream().map(Storage::getId).collect(Collectors.toList());
List<StoragePrice> storagePrices = storagePriceMapper.selectByStorageIds(storageIds);
if (!CollectionUtils.isEmpty(storagePrices)) {
storagePriceMap = storagePrices.stream().collect(Collectors.toMap(StoragePrice::getStorageId, Function.identity()));
}
for (Storage storage : storageList) {
GoodsSize goodsSize = new GoodsSize();
goodsSize.setId(storage.getId());
goodsSize.setStorageNum(storage.getStorageNum());
goodsSize.setSizeId(storage.getSizeId());
Size size = sizeMap.get(storage.getSizeId());
goodsSize.setSizeName(size == null ? "" : size.getSizeName());
goodsSize.setOrderBy(size == null ? 0 : size.getOrderBy());
StoragePrice storagePrice = storagePriceMap.get(storage.getId());
goodsSize.setLeastPrice(storagePrice == null ? null : storagePrice.getPrice());
goodsSize.setStatus(storagePrice == null ? null : storagePrice.getStatus());
goodSizeList.add(goodsSize);
}
}
}
productDetailResp.setProduct_info(productInfo);
}
return productDetailResp;
}
private String buildImageFullUrl(String url) {
if (!StringUtils.startsWith(url, "http")){
return ImagesHelper.template2(url, ImagesHelper.SYS_BUCKET.get(ImagesHelper.SYS_GOODS_NAME)).replaceAll("extent\\/\\{width}x\\{height}\\/","");
}else{
return url;
}
}
@Override
public StorageLeastPriceResp queryStorageLeastPrice(Integer storageId) {
StoragePrice storagePrice = storagePriceMapper.selectLeastPrice(storageId);
... ... @@ -57,21 +172,30 @@ public class ProductServiceImpl implements ProductService{
@Override
public StorageDataResp queryStorageInfo(Integer storageId) {
StorageGoodProductSize sgps = storageMapper.selectStroageProductInfo(storageId);
if (sgps == null) {
StorageDataResp resp = new StorageDataResp();
Storage storage = storageMapper.selectByPrimaryKey(storageId);
if (storage == null) {
return null;
}
StorageDataResp resp = new StorageDataResp();
resp.setProductId(sgps.getProductId());
resp.setProductName(sgps.getProductName());
resp.setColorId(sgps.getColorId() + "");
resp.setColorName(sgps.getColorName());
resp.setImageUrl(sgps.getColorImage());
GoodsSize goodsSize = new GoodsSize();
goodsSize.setSizeId(sgps.getSizeId());
goodsSize.setSizeName(sgps.getSizeName());
goodsSize.setSizeId(storage.getSizeId());
Size size = sizeMapper.selectByPrimaryKey(storage.getSizeId());
if (size != null) {
goodsSize.setSizeName(size.getSizeName());
}
resp.setSize(goodsSize);
Goods goods = goodsMapper.selectByPrimaryKey(storage.getGoodsId());
if (goods != null) {
resp.setColorId(goods.getColorId().toString());
resp.setColorName(goods.getColorName());
resp.setImageUrl(goods.getColorImage());
Product product = productMapper.selectByPrimaryKey(goods.getProductId());
if (product != null) {
resp.setProductId(product.getId());
resp.setProductName(product.getProductName());
}
}
return resp;
}
... ...
... ... @@ -15,7 +15,9 @@ public final class DateUtils {
private final static String DEFAULT_FOMARTPATTER="yyyy-MM-dd HH:mm:ss";
public final static String DEFAULT_FOMART_DATE="yyyy-MM-dd";
public final static String FOMART_DATE_DOT="yyyy.MM.dd";
/**
* 将数据库中的UNIX_Time(该时间是距离1970年的秒数,在转换过程中先要换算成毫秒)转换成UTC时间
* @param time
... ...
... ... @@ -19,7 +19,12 @@ datasources:
- com.yohoufo.dal.product.StoragePriceMapper
- com.yohoufo.dal.product.StorageMapper
- com.yohoufo.dal.product.ProductMapper
- com.yohoufo.dal.product.GoodsMapper
- com.yohoufo.dal.product.GoodsImagesMapper
- com.yohoufo.dal.product.SizeMapper
- com.yohoufo.dal.product.BrandMapper
- com.yohoufo.dal.product.BrandSeriesMapper
yh_inbox:
servers:
- 192.168.102.219:3306
... ...
... ... @@ -19,6 +19,11 @@ datasources:
- com.yohoufo.dal.product.StoragePriceMapper
- com.yohoufo.dal.product.StorageMapper
- com.yohoufo.dal.product.ProductMapper
- com.yohoufo.dal.product.GoodsMapper
- com.yohoufo.dal.product.GoodsImagesMapper
- com.yohoufo.dal.product.SizeMapper
- com.yohoufo.dal.product.BrandMapper
- com.yohoufo.dal.product.BrandSeriesMapper
yh_inbox:
servers:
... ...