Authored by caoyan

添加尺码

package com.yohoufo.dal.product;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yohoufo.dal.product.model.SizeAddRecord;
public interface SizeAddRecordMapper {
int insertBatch(@Param("list") List<SizeAddRecord> list);
}
\ No newline at end of file
... ...
... ... @@ -3,6 +3,8 @@ package com.yohoufo.dal.product;
import com.yohoufo.dal.product.model.Size;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface SizeMapper {
int insert(Size record);
... ... @@ -14,4 +16,11 @@ public interface SizeMapper {
int updateByPrimaryKey(Size record);
List<Size> selectByIds(List<Integer> ids);
/**
* 根据品类查询所有的尺码
* @param sortId
* @return
*/
List<Size> selectAllSizeBySortIdList(@Param("sortIdList") List<Integer> sortIdList);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.product.model;
public class SizeAddRecord {
private Integer id;
private Integer productId;
private Integer goodsId;
private Integer sizeId;
private Integer applyUid;
private Integer createTime;
private Integer auditTime;
private Integer auditUid;
private Integer status;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public Integer getSizeId() {
return sizeId;
}
public void setSizeId(Integer sizeId) {
this.sizeId = sizeId;
}
public Integer getApplyUid() {
return applyUid;
}
public void setApplyUid(Integer applyUid) {
this.applyUid = applyUid;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
public Integer getAuditTime() {
return auditTime;
}
public void setAuditTime(Integer auditTime) {
this.auditTime = auditTime;
}
public Integer getAuditUid() {
return auditUid;
}
public void setAuditUid(Integer auditUid) {
this.auditUid = auditUid;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
}
\ 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.SizeAddRecordMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.product.model.SizeAddRecord">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_id" jdbcType="INTEGER" property="productId" />
<result column="goodsId" jdbcType="INTEGER" property="goodsId" />
<result column="size_id" jdbcType="INTEGER" property="sizeId" />
<result column="apply_id" jdbcType="INTEGER" property="applyId" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="audit_time" jdbcType="INTEGER" property="auditTime" />
<result column="audit_uid" jdbcType="INTEGER" property="auditUid" />
<result column="status" jdbcType="INTEGER" property="status" />
</resultMap>
<insert id="insertBatch">
insert into size_add_record(
product_id,
goods_id,
size_id,
apply_uid,
create_time)values
<foreach collection="list" separator="," item="item">
(#{item.productId},#{item.goodsId},#{item.sizeId},#{item.applyUid},#{item.createTime})
</foreach>
</insert>
</mapper>
\ No newline at end of file
... ...
... ... @@ -45,4 +45,16 @@
</foreach>
order by order_by
</select>
<select id="selectAllSizeBySortIdList" resultMap="BaseResultMap">
select s.id, s.size_name,ss.order_by
from size s inner join sort_size ss on s.id = ss.size_id where ss.del = 0
<if test="sortIdList != null and sortIdList.size() >0 ">
and ss.sort_id in
<foreach item="item" index="index" collection="sortIdList" open="(" separator="," close=")">
#{item}
</foreach>
</if>
order by ss.order_by, ss.id
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -723,5 +723,26 @@ public class ProductController {
ProductDetailResp resp = productService.queryProductInStockNewBriefById(productId);
return new ApiResponse.ApiResponseBuilder().data(resp).code(200).message("product data").build();
}
@ApiOperation(name = "ufo.product.addSize", desc = "添加尺码")
@RequestMapping(params = "method=ufo.product.addSize")
public ApiResponse addSize(
@RequestParam(value = "product_id") Integer productId,
@RequestParam(value = "goods_id") Integer goodsId,
@RequestParam(value = "size_ids") String sizeIds,
@RequestParam(value = "uid") Integer uid) {
if (null == productId || null == goodsId || StringUtils.isBlank(sizeIds) || null == uid) {
LOG.info("in method=ufo.product.addSize product_id or goods_id or size_ids or uid Is Null or empty");
return new ApiResponse(400, "product_id or goods_id or size_ids or uid Is Null or empty", null);
}
LOG.info("in method=ufo.product.addSize goodsId is {},size_ids={}", goodsId, sizeIds);
int result = productService.addSizeForGoods(productId, goodsId, sizeIds, uid);
if(result > 0) {
return new ApiResponse.ApiResponseBuilder().code(200).message("addSize success").build();
}else {
return new ApiResponse.ApiResponseBuilder().code(500).message("addSize fail!").build();
}
}
}
\ No newline at end of file
... ...
... ... @@ -104,4 +104,6 @@ public interface ProductService {
SecondHandProductResp querySecondHandProductData(Integer skup);
ProductDetailResp queryProductInStockNewBriefById(Integer productId);
int addSizeForGoods(Integer productId, Integer goodsId, String sizeIds, Integer applyUid);
}
... ...
package com.yohoufo.product.service.impl;
import java.math.BigDecimal;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.UUID;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.GoodsBO;
import com.yohobuy.ufo.model.GoodsImageBO;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.ProductInfo;
import com.yohobuy.ufo.model.request.StoragePriceBo;
import com.yohobuy.ufo.model.response.ProductDetailResp;
import com.yohobuy.ufo.model.response.StorageInfoResp;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.dal.product.*;
import com.yohoufo.dal.product.model.*;
import com.yohoufo.product.model.*;
import com.yohoufo.product.response.*;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
... ... @@ -32,14 +25,74 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.yoho.core.common.helpers.ImagesHelper;
import com.yoho.core.config.ConfigReader;
import com.yoho.core.dal.datasource.annotation.Database;
import com.yoho.error.exception.ServiceException;
import com.yoho.tools.common.beans.ApiResponse;
import com.yohobuy.ufo.model.GoodsBO;
import com.yohobuy.ufo.model.GoodsImageBO;
import com.yohobuy.ufo.model.GoodsSize;
import com.yohobuy.ufo.model.ProductInfo;
import com.yohobuy.ufo.model.request.StoragePriceBo;
import com.yohobuy.ufo.model.response.ProductDetailResp;
import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohobuy.ufo.model.response.StorageInfoResp;
import com.yohoufo.common.caller.UfoServiceCaller;
import com.yohoufo.common.helper.ImageUrlAssist;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.UfoStringUtils;
import com.yohobuy.ufo.model.response.StorageDataResp;
import com.yohoufo.dal.product.BrandMapper;
import com.yohoufo.dal.product.BrandSeriesMapper;
import com.yohoufo.dal.product.GoodsImagesMapper;
import com.yohoufo.dal.product.GoodsMapper;
import com.yohoufo.dal.product.PriceTrendDayMapper;
import com.yohoufo.dal.product.PriceTrendMonthMapper;
import com.yohoufo.dal.product.ProductLimitSaleMapper;
import com.yohoufo.dal.product.ProductMapper;
import com.yohoufo.dal.product.ProductSalesMapper;
import com.yohoufo.dal.product.ProductSortMapper;
import com.yohoufo.dal.product.SaleCategoryMapper;
import com.yohoufo.dal.product.SecondhandFlawMapper;
import com.yohoufo.dal.product.SecondhandImagesMapper;
import com.yohoufo.dal.product.SecondhandInfoMapper;
import com.yohoufo.dal.product.SizeAddRecordMapper;
import com.yohoufo.dal.product.SizeMapper;
import com.yohoufo.dal.product.StorageMapper;
import com.yohoufo.dal.product.StoragePriceMapper;
import com.yohoufo.dal.product.model.Brand;
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.PriceTrendModel;
import com.yohoufo.dal.product.model.Product;
import com.yohoufo.dal.product.model.ProductLimitSale;
import com.yohoufo.dal.product.model.ProductSales;
import com.yohoufo.dal.product.model.ProductSort;
import com.yohoufo.dal.product.model.SaleCategory;
import com.yohoufo.dal.product.model.SecondhandFlaw;
import com.yohoufo.dal.product.model.SecondhandImages;
import com.yohoufo.dal.product.model.SecondhandInfo;
import com.yohoufo.dal.product.model.Size;
import com.yohoufo.dal.product.model.SizeAddRecord;
import com.yohoufo.dal.product.model.Storage;
import com.yohoufo.dal.product.model.StoragePrice;
import com.yohoufo.product.model.PriceTrendBO;
import com.yohoufo.product.model.ProductSeriesTemplate;
import com.yohoufo.product.model.ProductSortTemplate;
import com.yohoufo.product.model.SkupDetailForScreenInfo;
import com.yohoufo.product.model.SkupInfo;
import com.yohoufo.product.model.SkusBO;
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.SecondHandProductResp;
import com.yohoufo.product.response.SkupDetailForScreenResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import com.yohoufo.product.service.ProductSearchService;
import com.yohoufo.product.service.ProductService;
... ... @@ -80,9 +133,6 @@ public class ProductServiceImpl implements ProductService {
private ProductSearchService productSearchService;
@Autowired
private PriceTrendSixtyDayMapper priceTrendSixtyDayMapper;
@Autowired
private PriceTrendMonthMapper priceTrendMonthMapper;
@Autowired
... ... @@ -108,7 +158,16 @@ public class ProductServiceImpl implements ProductService {
@Autowired
private UfoServiceCaller ufoServiceCaller;
@Autowired
private ProductSortMapper productSortMapper;
@Autowired
private ConfigReader configReader;
@Autowired
private SizeAddRecordMapper sizeAddRecordMapper;
@Override
public ProductDetailResp queryProductDetailById(Integer productId) {
ProductDetailResp productDetailResp = new ProductDetailResp();
... ... @@ -151,6 +210,11 @@ public class ProductServiceImpl implements ProductService {
productInfo.setSecondHandLeastPrice(secondHandLeastPrice);
}
goodsSizes.sort(Comparator.comparing(GoodsSize::getOrderBy));
List<JSONObject> otherAddSizeList = getOtherSizeList(product.getMaxSortId(), product.getMidSortId(), goodsBOList);
if(!CollectionUtils.isEmpty(otherAddSizeList)) {
goodsBO.setCanAddSize(true);
goodsBO.setOtherSizeList(otherAddSizeList);
}
}
}
productInfo.setGoodsList(goodsBOList);
... ... @@ -159,6 +223,76 @@ public class ProductServiceImpl implements ProductService {
return productDetailResp;
}
private List<JSONObject> getOtherSizeList(Integer maxSortId, Integer midSortId, List<GoodsBO> goodsBOList) {
List<JSONObject> result = Lists.newArrayList();
String configMaxSortIds = configReader.getString("ufo.product.addSizeSortId", "");
if(StringUtils.isEmpty(configMaxSortIds)) {
return result;
}
List<Integer> configSortList = Lists.newArrayList();
String[] configSortArr = configMaxSortIds.split(",");
for(int i=0; i<configSortArr.length; i++) {
configSortList.add(Integer.parseInt(configSortArr[i]));
}
//如果没有配置这个品类,则不可以添加尺码
if(!configSortList.contains(maxSortId)) {
return result;
}
List<Size> sizeList = getAllSizeBySortId(midSortId);
if(CollectionUtils.isEmpty(sizeList)) {
return result;
}
List<Integer> sizeIdList = sizeList.stream().map(Size::getId).filter(Objects::nonNull).collect(Collectors.toList());
if(!CollectionUtils.isEmpty(goodsBOList)) {
List<GoodsSize> goodsSizes = goodsBOList.get(0).getSizeList();
if(!CollectionUtils.isEmpty(goodsSizes)) {
List<Integer> goodsSizeIdList = goodsSizes.stream().map(GoodsSize::getSizeId).filter(Objects::nonNull).collect(Collectors.toList());
sizeIdList.removeAll(goodsSizeIdList);
}
}
if(CollectionUtils.isEmpty(sizeIdList)) {
return result;
}
Map<Integer, Size> sizeMap = sizeList.stream().collect(Collectors.toMap(Size::getId, s->s));
List<Size> resultSizeList = Lists.newArrayList();
//排序
for(Integer sizeId : sizeIdList) {
resultSizeList.add(sizeMap.get(sizeId));
}
resultSizeList.sort(Comparator.comparing(Size::getOrderBy));
JSONObject jsonObject;
for(Size item : resultSizeList) {
jsonObject = new JSONObject();
jsonObject.put("id", item.getId());
jsonObject.put("text", item.getSizeName());
result.add(jsonObject);
}
return result;
}
private List<Size> getAllSizeBySortId(Integer sortId) {
ProductSort sort = productSortMapper.selectByPrimaryKey(sortId);
List<Size> sizes = Lists.newArrayList();
if (sort != null) {
List<Integer> idList = new ArrayList<>();
idList.add(sortId);
if (sort.getParentId() != null && sort.getParentId() > 0) {
idList.add(sort.getParentId());
}
sizes = sizeMapper.selectAllSizeBySortIdList(idList);
}
return sizes;
}
@Override
public StorageLeastPriceResp queryStorageLeastPrice(Integer storageId) {
... ... @@ -1475,6 +1609,45 @@ public class ProductServiceImpl implements ProductService {
}
return productDetailResp;
}
public int addSizeForGoods(Integer productId, Integer goodsId, String sizeIds, Integer applyUid) {
Product product = productMapper.selectByPrimaryKey(productId);
if(null == product) {
throw new ServiceException(400, "productId不存在");
}
Goods goods = goodsMapper.selectByPrimaryKey(goodsId);
if(null == goods || !goods.getProductId().equals(productId)) {
throw new ServiceException(400, "goodsId不存在");
}
//校验sizetId
String[] sizeIdArr = sizeIds.split(",");
List<SizeAddRecord> recordList = Lists.newArrayList();
//goodsId现对应的尺码
List<Storage> storageList = storageMapper.selectByGoodsId(goodsId);
List<Integer> existSizeIdList = storageList.stream().map(Storage::getSizeId).collect(Collectors.toList());
List<Size> sizeList = sizeMapper.selectByIds(existSizeIdList);
Map<Integer, String> sizeIdNameMap = sizeList.stream().collect(Collectors.toMap(Size::getId, Size::getSizeName));
for(int i=0; i<sizeIdArr.length; i++) {
Integer sizeId = Integer.parseInt(sizeIdArr[i]);
if(existSizeIdList.contains(sizeId)) {
throw new ServiceException(400, "尺码" + sizeIdNameMap.get(sizeId) + "已存在,不需要添加,请重新选择");
}
SizeAddRecord record = new SizeAddRecord();
record.setProductId(productId);
record.setGoodsId(goodsId);
record.setSizeId(sizeId);
record.setApplyUid(applyUid);
record.setCreateTime(DateUtil.getCurrentTimeSecond());
recordList.add(record);
}
//添加尺码审核记录
return sizeAddRecordMapper.insertBatch(recordList);
}
private String getGoodsDeafultImage(Integer goodsId) {
List<GoodsImages> goodsImages = goodsImagesMapper.selectByGoodsId(goodsId);
... ...
... ... @@ -119,7 +119,8 @@ yoho.message.controller.url=http://message-controller.yohoops.org/yoho-message-c
yoho.reviewed.controller.url=http://172.16.6.54:8063/reviewed
#rabbit address for transaction compensate
rabbit_host=192.168.104.199:30005
#rabbit_host=192.168.104.199:30005
rabbit_host=192.168.102.211:5672
rabbit_user=yoho
rabbit_password=yoho
... ... @@ -143,4 +144,6 @@ ip.port.uic.server = java-yoho-uic.test3.ingress.dev.yohocorp.com
ufo.nfc.syncBlockChain.url=http://192.168.102.49:3030/api/addItem
ufo.invite.productSortLimit=16,20,40
\ No newline at end of file
ufo.invite.productSortLimit=16,20,40
ufo.product.addSizeSortId=40
\ No newline at end of file
... ...
... ... @@ -45,6 +45,7 @@ datasources:
- com.yohoufo.dal.product.SecondhandFlawMapper
- com.yohoufo.dal.product.SecondhandImagesMapper
- com.yohoufo.dal.product.SecondhandInfoMapper
- com.yohoufo.dal.product.SizeAddRecordMapper
ufo_order:
... ...
... ... @@ -114,4 +114,6 @@ offline.store.seller=${offline.store.seller}
ip.port.uic.server = ${ip.port.uic.server}
ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}
\ No newline at end of file
ufo.nfc.syncBlockChain.url=${ufo.nfc.syncBlockChain.url}
ufo.product.addSizeSortId=${ufo.product.addSizeSortId}
\ No newline at end of file
... ...
... ... @@ -45,6 +45,7 @@ datasources:
- com.yohoufo.dal.product.SecondhandFlawMapper
- com.yohoufo.dal.product.SecondhandImagesMapper
- com.yohoufo.dal.product.SecondhandInfoMapper
- com.yohoufo.dal.product.SizeAddRecordMapper
ufo_order:
servers:
... ...