Authored by caoyan

自助尺码

package com.yohoufo.dal.product;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yohoufo.dal.product.model.SelfSize;
public interface SelfSizeMapper {
int insertBatch(@Param("list") List<SelfSize> list);
List<SelfSize> selectByProductIdAndSizeId(@Param("productId") Integer productId, @Param("sizeIds") String sizeIds);
}
\ No newline at end of file
... ...
package com.yohoufo.dal.product;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yohoufo.dal.product.model.SelfSizeUid;
public interface SelfSizeUidMapper {
int insertBatch(@Param("list") List<SelfSizeUid> list);
List<SelfSizeUid> selectByProductIdAndSizeId(@Param("productId") Integer productId, @Param("sizeIds") String sizeIds);
}
\ No newline at end of file
... ...
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);
int updateBatchApplyUid(@Param("recordList") List<SizeAddRecord> recordList);
List<SizeAddRecord> selectByProductIdAndSizeId(@Param("productId") Integer productId, @Param("sizeIds") String sizeIds);
}
\ No newline at end of file
package com.yohoufo.dal.product.model;
public class SizeAddRecord {
public class SelfSize {
private Integer id;
private Integer productId;
... ... @@ -9,12 +9,6 @@ public class SizeAddRecord {
private Integer sizeId;
private String applyUid;
private Integer createTime;
private Integer updateTime;
private Integer auditTime;
private Integer auditUid;
... ... @@ -53,30 +47,6 @@ public class SizeAddRecord {
this.sizeId = sizeId;
}
public String getApplyUid() {
return applyUid;
}
public void setApplyUid(String applyUid) {
this.applyUid = applyUid;
}
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 getAuditTime() {
return auditTime;
}
... ...
package com.yohoufo.dal.product.model;
public class SelfSizeUid {
private Integer id;
private Integer productId;
private Integer goodsId;
private Integer sizeId;
private Integer uid;
private Integer createTime;
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 getUid() {
return uid;
}
public void setUid(Integer uid) {
this.uid = uid;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ 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.SelfSizeMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.product.model.SelfSize">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_id" jdbcType="INTEGER" property="productId" />
<result column="goods_id" jdbcType="INTEGER" property="goodsId" />
<result column="size_id" jdbcType="INTEGER" property="sizeId" />
<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 self_size(
product_id,
goods_id,
size_id)values
<foreach collection="list" separator="," item="item">
(#{item.productId},#{item.goodsId},#{item.sizeId})
</foreach>
</insert>
<select id="selectByProductIdAndSizeId" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id
from self_size
where product_id=#{productId} and size_id in (#{sizeIds}) and status=0
</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.yohoufo.dal.product.SelfSizeUidMapper">
<resultMap id="BaseResultMap" type="com.yohoufo.dal.product.model.SelfSizeUid">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_id" jdbcType="INTEGER" property="productId" />
<result column="goods_id" jdbcType="INTEGER" property="goodsId" />
<result column="size_id" jdbcType="INTEGER" property="sizeId" />
<result column="uid" jdbcType="INTEGER" property="uid" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
</resultMap>
<insert id="insertBatch">
insert into self_size_uid(
product_id,
goods_id,
size_id,
uid,
create_time)values
<foreach collection="list" separator="," item="item">
(#{item.productId}, #{item.goodsId}, #{item.sizeId}, #{item.uid}, UNIX_TIMESTAMP())
</foreach>
</insert>
<select id="selectByProductIdAndSizeId" resultMap="BaseResultMap">
select product_id, goods_id, size_id, uid, create_time
from self_size_uid
where product_id=#{productId} and size_id in (#{sizeIds})
</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.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_uid" jdbcType="VARCHAR" property="applyUid" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
<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>
<select id="selectByProductIdAndSizeId" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, apply_uid
from size_add_record
where product_id=#{productId} and size_id in (#{sizeIds})
</select>
<update id="updateBatchApplyUid" parameterType="java.util.List">
update size_add_record
<trim prefix="set" suffixOverrides=",">
<trim prefix="apply_uid=case" suffix="end,">
<foreach collection="recordList" item="item" index="index">
<if test="item.applyUid!=null">
when product_id=#{item.productId,jdbcType=INTEGER} and size_id=#{item.sizeId,jdbcType=INTEGER} then #{item.applyUid,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="update_time=case" suffix="end,">
<foreach collection="recordList" item="item" index="index">
<if test="item.updateTime!=null">
when product_id=#{item.productId,jdbcType=INTEGER} and size_id=#{item.sizeId,jdbcType=INTEGER} then #{item.updateTime,jdbcType=INTEGER}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="recordList" separator="or" item="item" index="index" >
product_id = #{item.productId,jdbcType=INTEGER} and size_id = #{item.sizeId, jdbcType=INTEGER}
</foreach>
</update>
</mapper>
\ No newline at end of file
... ... @@ -753,8 +753,12 @@ public class ProductController {
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);
productService.addSizeForGoods(productId, goodsId, sizeIds, uid);
return new ApiResponse.ApiResponseBuilder().code(200).message("addSize success").build();
try {
productService.addSizeForGoods(productId, goodsId, sizeIds, uid);
return new ApiResponse.ApiResponseBuilder().code(200).message("addSize success").build();
}catch (ServiceException e) {
return new ApiResponse.ApiResponseBuilder().data(e.getErrorMessage()).code(e.getCode()).message(e.getMessage()).build();
}
}
@ApiOperation(name = "ufo.product.otherSizeList", desc = "可添加的尺码列表")
... ...
... ... @@ -23,10 +23,12 @@ import org.apache.commons.lang3.tuple.Pair;
import org.elasticsearch.common.collect.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;
import org.springframework.util.CollectionUtils;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
... ... @@ -62,7 +64,8 @@ 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.SelfSizeMapper;
import com.yohoufo.dal.product.SelfSizeUidMapper;
import com.yohoufo.dal.product.SizeMapper;
import com.yohoufo.dal.product.StorageMapper;
import com.yohoufo.dal.product.StoragePriceMapper;
... ... @@ -79,8 +82,9 @@ 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.SelfSize;
import com.yohoufo.dal.product.model.SelfSizeUid;
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;
... ... @@ -98,7 +102,6 @@ import com.yohoufo.product.response.SkupDetailForScreenResp;
import com.yohoufo.product.response.StorageLeastPriceResp;
import com.yohoufo.product.service.ProductSearchService;
import com.yohoufo.product.service.ProductService;
import org.springframework.web.servlet.ModelAndView;
@Service
... ... @@ -170,7 +173,10 @@ public class ProductServiceImpl implements ProductService {
private ConfigReader configReader;
@Autowired
private SizeAddRecordMapper sizeAddRecordMapper;
private SelfSizeMapper selfSizeMapper;
@Autowired
private SelfSizeUidMapper selfSizeUidMapper;
@Override
public ProductDetailResp queryProductDetailById(Integer productId) {
... ... @@ -214,7 +220,7 @@ public class ProductServiceImpl implements ProductService {
productInfo.setSecondHandLeastPrice(secondHandLeastPrice);
}
goodsSizes.sort(Comparator.comparing(GoodsSize::getOrderBy));
List<JSONObject> otherAddSizeList = getOtherSizeList(product.getMaxSortId(), product.getMidSortId(), goodsBOList);
List<JSONObject> otherAddSizeList = getOtherSizeList(product.getMaxSortId(), product.getMidSortId(), goodsSizes);
if(!CollectionUtils.isEmpty(otherAddSizeList)) {
goodsBO.setCanAddSize(true);
goodsBO.setOtherSizeList(otherAddSizeList);
... ... @@ -264,7 +270,7 @@ public class ProductServiceImpl implements ProductService {
}
private List<JSONObject> getOtherSizeList(Integer maxSortId, Integer midSortId, List<GoodsBO> goodsBOList) {
private List<JSONObject> getOtherSizeList(Integer maxSortId, Integer midSortId, List<GoodsSize> goodsSizes) {
List<JSONObject> result = Lists.newArrayList();
if(!canAddSize(maxSortId)) {
return result;
... ... @@ -276,12 +282,9 @@ public class ProductServiceImpl implements ProductService {
}
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(goodsSizes)) {
List<Integer> goodsSizeIdList = goodsSizes.stream().map(GoodsSize::getSizeId).filter(Objects::nonNull).collect(Collectors.toList());
sizeIdList.removeAll(goodsSizeIdList);
}
if(CollectionUtils.isEmpty(sizeIdList)) {
... ... @@ -1696,50 +1699,75 @@ public class ProductServiceImpl implements ProductService {
throw new ServiceException(400, "goodsId不存在");
}
//校验sizetId
//校验sizeId
String[] sizeIdArr = sizeIds.split(",");
List<SizeAddRecord> needAddRecordList = Lists.newArrayList();
List<SizeAddRecord> needUpdateRecordList = Lists.newArrayList();
List<SelfSize> needAddRecordList = Lists.newArrayList();
List<SelfSizeUid> needRelateUidList = 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));
List<SizeAddRecord> existRecordList = sizeAddRecordMapper.selectByProductIdAndSizeId(productId, sizeIds);
Map<Integer, String> dbSizeIdApplyUidMap = existRecordList.stream().collect(Collectors.toMap(SizeAddRecord::getSizeId, SizeAddRecord::getApplyUid));
if(MapUtils.isEmpty(dbSizeIdApplyUidMap)) {
dbSizeIdApplyUidMap = Maps.newHashMap();
List<SelfSize> existRecordList = selfSizeMapper.selectByProductIdAndSizeId(productId, sizeIds);
Map<Integer, SelfSize> selfSizeMap = existRecordList.stream().collect(Collectors.toMap(SelfSize::getSizeId, s->s));
if(MapUtils.isEmpty(selfSizeMap)) {
selfSizeMap = Maps.newHashMap();
}
//自助尺码uid关联表
List<SelfSizeUid> selfSizeUidList = selfSizeUidMapper.selectByProductIdAndSizeId(productId, sizeIds);
Map<Integer, List<SelfSizeUid>> sizeIdUidMap = selfSizeUidList.stream().collect(Collectors.groupingBy(SelfSizeUid::getSizeId));
List<String> warnSizeNameList = Lists.newArrayList();
for(int i=0; i<sizeIdArr.length; i++) {
Integer sizeId = Integer.parseInt(sizeIdArr[i]);
if(existSizeIdList.contains(sizeId)) {
throw new ServiceException(506, "尺码" + sizeIdNameMap.get(sizeId) + "已存在,不需要添加,请重新选择");
warnSizeNameList.add(sizeIdNameMap.get(sizeId));
}
SizeAddRecord record = new SizeAddRecord();
record.setProductId(productId);
record.setGoodsId(goodsId);
record.setSizeId(sizeId);
record.setCreateTime(DateUtil.getCurrentTimeSecond());
if(dbSizeIdApplyUidMap.keySet().contains(sizeId)) {
record.setApplyUid(dbSizeIdApplyUidMap.get(sizeId) + "," + applyUid);
record.setUpdateTime(DateUtil.getCurrentTimeSecond());
needUpdateRecordList.add(record);
if(selfSizeMap.keySet().contains(sizeId)) {
List<SelfSizeUid> selfSizeUids = sizeIdUidMap.get(sizeId);
List<Integer> uidList = Lists.newArrayList();
if(!CollectionUtils.isEmpty(selfSizeUids)) {
uidList = selfSizeUids.stream().map(SelfSizeUid::getUid).collect(Collectors.toList());
}
if(!uidList.contains(applyUid)) {
SelfSize selfSize = selfSizeMap.get(sizeId);
SelfSizeUid selfSizeUid = new SelfSizeUid();
BeanUtils.copyProperties(selfSize, selfSizeUid);
selfSizeUid.setUid(applyUid);
needRelateUidList.add(selfSizeUid);
}
}else {
record.setApplyUid(applyUid.toString());
SelfSize record = new SelfSize();
record.setProductId(productId);
record.setGoodsId(goodsId);
record.setSizeId(sizeId);
needAddRecordList.add(record);
SelfSizeUid selfSizeUid = new SelfSizeUid();
selfSizeUid.setProductId(productId);
selfSizeUid.setGoodsId(goodsId);
selfSizeUid.setSizeId(sizeId);
selfSizeUid.setUid(applyUid);
needRelateUidList.add(selfSizeUid);
}
}
if(!CollectionUtils.isEmpty(warnSizeNameList)) {
throw new ServiceException(506, "你的提交的添加尺码申请中,尺码:" + String.join(",", warnSizeNameList) + "信息已存在,请刷页面重新选择");
}
if(!CollectionUtils.isEmpty(needAddRecordList)) {
//添加尺码审核记录
sizeAddRecordMapper.insertBatch(needAddRecordList);
selfSizeMapper.insertBatch(needAddRecordList);
}
if(!CollectionUtils.isEmpty(needUpdateRecordList)) {
//更新尺码审核记录
sizeAddRecordMapper.updateBatchApplyUid(needUpdateRecordList);
if(!CollectionUtils.isEmpty(needRelateUidList)) {
//增加尺码uid关联记录
selfSizeUidMapper.insertBatch(needRelateUidList);
}
}
... ...
... ... @@ -45,7 +45,8 @@ datasources:
- com.yohoufo.dal.product.SecondhandFlawMapper
- com.yohoufo.dal.product.SecondhandImagesMapper
- com.yohoufo.dal.product.SecondhandInfoMapper
- com.yohoufo.dal.product.SizeAddRecordMapper
- com.yohoufo.dal.product.SelfSizeMapper
- com.yohoufo.dal.product.SelfSizeUidMapper
ufo_order:
... ...
... ... @@ -45,7 +45,8 @@ datasources:
- com.yohoufo.dal.product.SecondhandFlawMapper
- com.yohoufo.dal.product.SecondhandImagesMapper
- com.yohoufo.dal.product.SecondhandInfoMapper
- com.yohoufo.dal.product.SizeAddRecordMapper
- com.yohoufo.dal.product.SelfSizeMapper
- com.yohoufo.dal.product.SelfSizeUidMapper
ufo_order:
servers:
... ...