Authored by mali

库存管理

... ... @@ -69,4 +69,7 @@ public interface ProductMapper {
int updateStatusByPrimaryKey(@Param("id") Integer id,
@Param("shelveStatus") Integer shelveStatus);
int selectProductStorageCount(@Param("product")Product product);
List<Product> selectProductStorageList(@Param("product")Product product, @Param("start")int start, @Param("rows")Integer rows);
}
\ No newline at end of file
... ...
... ... @@ -38,11 +38,10 @@ public interface StoragePriceMapper {
int cancelSaleSkup(Integer skup);
int selectProductStorageCount(@Param("product")Product product);
List<Product> selectProductStorageList(@Param("product")Product product, @Param("start")int start, @Param("rows")Integer rows);
int selectStoragePriceCount(@Param("storagePrice")StoragePrice storagePrice);
List<StoragePrice> selectStoragePriceList(@Param("storagePrice")StoragePrice storagePrice, @Param("start")int start, @Param("rows")Integer rows);
// 查询状态可售的skup集合
List<StoragePrice> selectByProductIds(@Param("list")List<Integer> productIdList);
}
\ No newline at end of file
... ...
... ... @@ -42,6 +42,46 @@ public class Product {
// 0未删除 1已删除
private Integer delStatus;
public Integer getStorageId() {
return storageId;
}
public void setStorageId(Integer storageId) {
this.storageId = storageId;
}
public Integer getSellerUid() {
return sellerUid;
}
public void setSellerUid(Integer sellerUid) {
this.sellerUid = sellerUid;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getSkup() {
return skup;
}
public void setSkup(Integer skup) {
this.skup = skup;
}
private Integer storageId;
private Integer sellerUid;
private Integer status;
private Integer skup;
public Integer getId() {
return id;
}
... ...
... ... @@ -178,5 +178,32 @@
</if>
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectProductStorageCount" resultMap="java.lang.Integer">
select count(*) from from product p where <include refid="skuPageCondition" />
</select>
<select id="selectProductStorageList" resultMap="BaseResultMap">
select id, brand_id, product_name
from product p
where <include refid="skuPageCondition" /> limit #{start},#{rows}
</select>
<sql id="skuPageCondition">
<if test="product.id != null and product.id > 0">
and p.id = #{product.id}
</if>
<if test="product.productName != null and product.productName != ''">
and p.product_name like concat('%', #{product.productName}, '%')
</if>
<if test="product.maxSortId != null and product.maxSortId > 0">
and p.max_sort_id = #{product.maxSortId}
</if>
<if test="product.midSortId != null and product.midSortId > 0">
and p.mid_sort_id = #{product.midSortId}
</if>
<if test="product.brandId != null and product.brandId > 0">
and p.brand_id = #{product.brandId}
</if>
</sql>
</mapper>
\ No newline at end of file
... ...
... ... @@ -136,4 +136,14 @@
and skup = #{storagePrice.skup}
</if>
</sql>
<select id="selectByProductIds" resultMap="BaseResultMap">
select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price, status,
update_time, create_time
from storage_price
where where product_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach> and status = 1
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.convert;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.ufo.dal.model.Product;
import com.yoho.ufo.dal.model.StoragePrice;
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
... ... @@ -40,4 +41,18 @@ public class ProductConvertService {
bo.setId(storagePrice.getProductId());
return bo;
}
public ProductResponceBo convertProductDo2Bo(Product productItem) {
ProductResponceBo bo = new ProductResponceBo();
if (null == productItem) {
return bo;
}
bo.setSkup(productItem.getSkup());
bo.setStorageId(productItem.getStorageId());
bo.setSellerUid(productItem.getSellerUid());
bo.setId(productItem.getId());
bo.setBrandId(productItem.getBrandId());
bo.setProductName(productItem.getProductName());
return bo;
}
}
... ...
... ... @@ -4,6 +4,7 @@ import com.yoho.ufo.dal.*;
import com.yoho.ufo.dal.model.Goods;
import com.yoho.ufo.dal.model.Product;
import com.yoho.ufo.dal.model.Storage;
import com.yoho.ufo.dal.model.StoragePrice;
import com.yoho.ufo.model.brand.Brand;
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
import com.yoho.ufo.model.commoditybasicrole.color.ProductColor;
... ... @@ -15,6 +16,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
... ... @@ -26,9 +28,6 @@ import java.util.Map;
public class ProductAssistService {
@Autowired
private ProductSortMapper productSortMapper;
@Autowired
private ProductMapper productMapper;
@Autowired
... ... @@ -38,12 +37,6 @@ public class ProductAssistService {
private GoodsMapper goodsMapper;
@Autowired
private GoodsImagesMapper goodsImagesMapper;
@Autowired
private UfoProductColorMapper productColorMapper;
@Autowired
private StorageMapper storageMapper;
@Autowired
... ... @@ -138,4 +131,36 @@ public class ProductAssistService {
});
return this;
}
public ProductAssistService fillSkupInfo(List<ProductResponceBo> productResponceBos) {
if (CollectionUtils.isEmpty(productResponceBos)) {
return this;
}
Map<Integer, ProductResponceBo> productMap = CollectionUtil.extractMap(productResponceBos, ProductResponceBo::getId);
List<Integer> productIdList = CollectionUtil.distinct(productResponceBos, ProductResponceBo::getId);
List<StoragePrice> storagePriceList = storagePriceMapper.selectByProductIds(productIdList);
storagePriceList.stream().forEach(item -> {
ProductResponceBo productResponceBo = productMap.get(item.getProductId());
productResponceBo.setCurrentPrice(minPrice(productResponceBo.getCurrentPrice(), item.getPrice()));
productResponceBo.setStorage(null == productResponceBo.getStorage() ? 1 :productResponceBo.getStorage() + 1);
});
return this;
}
private String minPrice(String currentPrice, BigDecimal skupPrice) {
if (StringUtils.isEmpty(currentPrice)) {
return skupPrice.toString();
}
if (new BigDecimal(currentPrice).compareTo(skupPrice) > 0) {
return skupPrice.toString();
} else {
return currentPrice;
}
}
}
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.ufo.service.impl;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.ufo.convert.ProductConvertService;
import com.yoho.ufo.dal.ProductMapper;
import com.yoho.ufo.dal.StoragePriceMapper;
import com.yoho.ufo.dal.model.Product;
import com.yoho.ufo.dal.model.StoragePrice;
... ... @@ -35,27 +36,32 @@ public class StorageService {
private StoragePriceMapper storagePriceMapper;
@Autowired
private ProductAssistService productAssistService;
private ProductMapper productMapper;
@Autowired
private ProductAssistService productAssistService;
//商品编码 商品名称 品牌 最低价 可售库存
public PageResponseBO<ProductResponceBo> storageList(ProductRequestBo bo) {
LOGGER.info("StorageService storageList param = {}", bo);
Product product = OrikaUtils.map(bo, Product.class);
int count = storagePriceMapper.selectProductStorageCount(product);
int count = productMapper.selectProductStorageCount(product);
if (count == 0) {
LOGGER.warn("StorageService storageList count is 0.param = {}", bo);
return new PageResponseBO<>();
}
List<Product> productList = storagePriceMapper.selectProductStorageList(product, bo.getStart(), bo.getRows());
List<Product> productList = productMapper.selectProductStorageList(product, bo.getStart(), bo.getRows());
List<ProductResponceBo> responseBos = new ArrayList<>();
ProductResponceBo productResponseBo;
for (Product productItem : productList) {
productResponseBo = OrikaUtils.map(productItem, ProductResponceBo.class);
//productResponseBo.setCreateTime(DateUtil.getDateStrBySecond(productItem.getCreateTime(), DateUtil.DATE_TIME_FORMAT));
productResponseBo = productConvertService.convertProductDo2Bo(productItem);
responseBos.add(productResponseBo);
}
productAssistService.fillBrandName(responseBos).fillSkupInfo(responseBos);
return new PageResponseBO<>(count, responseBos, bo.getPage(), bo.getRows());
}
... ...