Authored by mali

库存管理

package com.yoho.ufo.dal;
import com.yoho.ufo.dal.model.Goods;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface GoodsMapper {
... ... @@ -15,4 +17,6 @@ public interface GoodsMapper {
int updateByPrimaryKey(Goods record);
List<Goods> selectByProductId(List<Integer> productIds);
List<Goods> selectByIds(@Param("goodsIdList")List<Integer> goodsIdList);
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.ufo.dal;
import java.util.List;
import com.yoho.ufo.model.brand.Brand;
import org.apache.ibatis.annotations.Param;
import com.yoho.ufo.dal.model.Product;
... ... @@ -60,4 +61,7 @@ public interface ProductMapper {
@Param("sellerUid") Integer sellerUid,
@Param("hasStock") Integer hasStock,
@Param("skup") Integer skup);
// 根据Id列表查询商品列表
List<Product> selectProductListByIds(@Param("productIdList")List<Integer> productIdList);
}
\ No newline at end of file
... ...
... ... @@ -22,4 +22,5 @@ public interface StorageMapper {
int addStorageNum(@Param("storageId")Integer storageId, @Param("storageNum")Integer storageNum);
List<Storage> selectByIds(@Param("storageIdList")List<Integer> storageIdList);
}
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@ package com.yoho.ufo.dal;
import java.util.List;
import com.yoho.ufo.dal.model.Product;
import org.apache.ibatis.annotations.Param;
import com.yoho.ufo.dal.model.StoragePrice;
... ... @@ -36,5 +37,12 @@ public interface StoragePriceMapper {
StoragePrice selectBySkup(Integer skup);
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);
}
\ No newline at end of file
... ...
... ... @@ -55,4 +55,10 @@ public interface UfoProductColorMapper {
* @return
*/
List<ProductColor> getProductColorPageList(@Param("productColor") ProductColor productColor, @Param("page") PageModel pageModel);
/**
* 查询所有的颜色列表
* @return
*/
List<ProductColor> selectAllColor();
}
... ...
... ... @@ -64,5 +64,10 @@ public interface UfoSizeMapper {
*/
List<Size> selectAllSizeBySortId(@Param("sortId") Integer sortId);
/**
* 根据尺码ID查询尺码信息
* @param idList
* @return
*/
List<Size> selectByIdList(@Param("list")List<Integer> idList);
}
... ...
... ... @@ -49,4 +49,11 @@
#{item}
</foreach>
</select>
<select id="selectByIds" resultMap="BaseResultMap">
select id, product_id, color_id, color_name, goods_name, color_image, is_default
from goods where id in
<foreach item="item" index="index" collection="goodsIdList" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -157,4 +157,14 @@
and sp.skup = #{skup}
</if>
</sql>
<select id="selectProductListByIds" resultMap="BaseResultMap">
select id, product_name, product_code, max_sort_id, mid_sort_id, brand_id, series_id,
gender, sale_time, min_price, max_price, create_time, update_time, shelve_time, edit_time,
shelve_status, storage, key_words, del_status
from product where id in
<foreach item="item" index="index" collection="productIdList" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -91,7 +91,7 @@
select <include refid="queryColumns"/>
from product_sort
</select>
<select id=selectSortByIdList resultMap="productSortMap">
<select id="selectSortByIdList" resultMap="productSortMap">
select id,sort_name
from product_sort where id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
... ...
... ... @@ -57,4 +57,11 @@
update_time = #{updateTime,jdbcType=INTEGER},
where id = #{storageId,jdbcType=INTEGER}
</update>
<select id="selectByIds" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num, update_time, create_time
from storage where id in
<foreach item="item" index="index" collection="storageIdList" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -107,4 +107,33 @@
from storage_price
where skup = #{skup,jdbcType=INTEGER}
</select>
<select id="selectStoragePriceCount" resultMap="java.lang.Integer">
select count(*) from from storage_price where <include refid="skupPageCondition" />
</select>
<select id="selectStoragePriceList" 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 <include refid="skupPageCondition" /> limit #{start},#{rows}
</select>
<sql id="skupPageCondition" >
<if test="storagePrice.status != null and storagePrice.status > -1">
and status = #{storagePrice.status}
</if>
<if test="storagePrice.storageId != null and storagePrice.storageId > 0">
and storage_id = #{storagePrice.storageId}
</if>
<if test="storagePrice.sellerUid != null and storagePrice.sellerUid > 0">
and seller_uid = #{storagePrice.sellerUid}
</if>
<if test="storagePrice.productId != null and storagePrice.productId > 0">
and product_id = #{storagePrice.productId}
</if>
<if test="storagePrice.skup != null and storagePrice.skup > 0">
and skup = #{storagePrice.skup}
</if>
</sql>
</mapper>
\ No newline at end of file
... ...
... ... @@ -71,4 +71,8 @@
limit #{page.startIndex}, #{page.pageSize}
</select>
<select id="selectAllColor" resultMap="productColorMap">
select <include refid="queryColumns" />
from product_color limit 100
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -91,5 +91,12 @@
#{item}
</foreach>
</select>
<select id="selectByIdList" resultMap="sizeMap">
select id, size_name
from size where id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
package com.yoho.ufo.controller.product;
import com.yoho.ufo.service.IProductService;
import com.yoho.ufo.service.impl.StorageService;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
/**
* Created by li.ma on 2018/9/18.
*/
@RestController
@RequestMapping(value = "/storage")
public class StorageController {
private static final Logger LOGGER = LoggerFactory.getLogger(StorageController.class);
@Resource
private StorageService storageService;
@RequestMapping(value = "/storageList")
public ApiResponse<PageResponseBO<ProductResponceBo>> storageList(ProductRequestBo bo) {
LOGGER.info("StorageController.storageList param = {}", bo);
return new ApiResponse(storageService.storageList(bo));
}
@RequestMapping(value = "/storagePriceList")
public ApiResponse<PageResponseBO<ProductResponceBo>> storagePriceList(ProductRequestBo bo) {
LOGGER.info("StorageController.storagePriceList param = {}", bo);
return new ApiResponse(storageService.storagePriceList(bo));
}
}
... ...
package com.yoho.ufo.convert;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.ufo.dal.model.StoragePrice;
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
import org.springframework.stereotype.Service;
/**
* Created by li.ma on 2018/9/18.
*/
@Service
public class ProductConvertService {
public StoragePrice convertBo2Skup(ProductRequestBo bo) {
StoragePrice storagePrice = new StoragePrice();
if (null == bo) {
return storagePrice;
}
storagePrice.setSellerUid(bo.getSellerUid());
storagePrice.setStatus(bo.getStatus());
storagePrice.setStorageId(bo.getStorageId());
storagePrice.setSkup(bo.getSkup());
return storagePrice;
}
public ProductResponceBo convertSkupDo2Bo(StoragePrice storagePrice) {
ProductResponceBo bo = new ProductResponceBo();
if (null == storagePrice) {
return bo;
}
bo.setGoodsId(storagePrice.getGoodsId());
bo.setSkup(storagePrice.getSkup());
bo.setStorageId(storagePrice.getStorageId());
bo.setSkupPrice(storagePrice.getPrice().toString());
bo.setStatus(storagePrice.getStatus());
bo.setSkupCreateTime(DateUtil.getDateStrBySecond(storagePrice.getCreateTime(), DateUtil.DATE_TIME_FORMAT));
bo.setSellerUid(storagePrice.getSellerUid());
bo.setId(storagePrice.getProductId());
return bo;
}
}
... ...
package com.yoho.ufo.service.impl;
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.model.brand.Brand;
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
import com.yoho.ufo.model.commoditybasicrole.color.ProductColor;
import com.yoho.ufo.model.commoditybasicrole.size.Size;
import com.yoho.ufo.util.CollectionUtil;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* Created by li.ma on 2018/9/18.
*/
@Service
public class ProductAssistService {
@Autowired
private ProductSortMapper productSortMapper;
@Autowired
private ProductMapper productMapper;
@Autowired
private BrandMapper brandMapper;
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private GoodsImagesMapper goodsImagesMapper;
@Autowired
private UfoProductColorMapper productColorMapper;
@Autowired
private StorageMapper storageMapper;
@Autowired
private StoragePriceMapper storagePriceMapper;
@Autowired
private UfoSizeMapper sizeMapper;
// 商品列表填充品牌名称
public ProductAssistService fillBrandName(List<ProductResponceBo> productResponceBos) {
if (CollectionUtils.isEmpty(productResponceBos)) {
return this;
}
//List<Integer> productIdList = CollectionUtil.distinct(productResponceBos, ProductResponceBo::getId);
//List<Goods> goodsList = goodsMapper.selectByProductId(productIdList);
//Map<Integer, Goods> goodsMap = CollectionUtil.extractMap(goodsList, Goods::getProductId);
List<Brand> brandList = brandMapper.selectBrandByIdList(CollectionUtil.distinct(productResponceBos, ProductResponceBo::getBrandId));
Map<Integer, Brand> brandMap = CollectionUtil.extractMap(brandList, Brand::getId);
//List<Integer> sortIdList = CollectionUtil.distinct(productList, Product::getMaxSortId);
//sortIdList.addAll(CollectionUtil.distinct(productList, Product::getMidSortId));
//List<ProductSort> productSortList = productSortMapper.selectSortByIdList(sortIdList);
//Map<Integer, ProductSort> productSortMap = CollectionUtil.extractMap(productSortList, ProductSort::getId);
productResponceBos.forEach(respBo -> {
Brand brand = brandMap.get(respBo.getBrandId());
if (brand != null) {
respBo.setBrandName(brand.getBrandName());
}
});
return this;
}
// 商品列表填充商品表信息
public ProductAssistService fillProductDetail(List<ProductResponceBo> productResponceBos) {
if (CollectionUtils.isEmpty(productResponceBos)) {
return this;
}
List<Integer> productIdList = CollectionUtil.distinct(productResponceBos, ProductResponceBo::getId);
List<Product> products = productMapper.selectProductListByIds(productIdList);
Map<Integer, Product> productMap = CollectionUtil.extractMap(products, Product::getId);
productResponceBos.forEach(respBo -> {
Product item = productMap.get(respBo.getId());
if (item != null) {
respBo.setBrandId(item.getBrandId());
respBo.setMaxSortId(item.getMaxSortId());
respBo.setMaxSortId(item.getMidSortId());
}
});
return this;
}
// 商品列表填充商品表信息
public ProductAssistService fillGoodsColor(List<ProductResponceBo> productResponceBos) {
if (CollectionUtils.isEmpty(productResponceBos)) {
return this;
}
List<Integer> goodsIdList = CollectionUtil.distinct(productResponceBos, ProductResponceBo::getGoodsId);
List<Goods> goodsList = goodsMapper.selectByIds(goodsIdList);
Map<Integer, String> goodsNamesMap = CollectionUtil.extractMap(goodsList, Goods::getId, Goods::getGoodsName);
productResponceBos.forEach(respBo -> {
respBo.setGoodsName(goodsNamesMap.get(respBo.getGoodsId()));
});
return this;
}
// 商品列表填充商品表信息
public ProductAssistService fillSortName(List<ProductResponceBo> productResponceBos) {
if (CollectionUtils.isEmpty(productResponceBos)) {
return this;
}
List<Integer> storageIdList = CollectionUtil.distinct(productResponceBos, ProductResponceBo::getStorageId);
List<Storage> storageList = storageMapper.selectByIds(storageIdList);
Map<Integer, Integer> storageMap = CollectionUtil.extractMap(storageList, Storage::getId, Storage::getSizeId);
List<Size> sizes = sizeMapper.selectByIdList(new ArrayList<>(storageMap.values()));
Map<Integer, String> sizeNameMap = CollectionUtil.extractMap(sizes, Size::getId, Size::getSizeName);
productResponceBos.forEach(respBo -> {
Integer storageId = respBo.getStorageId();
String sizeName = sizeNameMap.get(storageMap.get(storageId));
respBo.setSizeName(sizeName);
});
return this;
}
}
... ...
package com.yoho.ufo.service.impl;
import com.yoho.core.common.utils.DateUtil;
import com.yoho.ufo.convert.ProductConvertService;
import com.yoho.ufo.dal.StoragePriceMapper;
import com.yoho.ufo.dal.model.Product;
import com.yoho.ufo.dal.model.StoragePrice;
import com.yoho.ufo.model.goodsmanage.ProductPool;
import com.yoho.ufo.util.OrikaUtils;
import com.yohobuy.ufo.model.common.ApiResponse;
import com.yohobuy.ufo.model.common.PageModel;
import com.yohobuy.ufo.model.common.PageResponseBO;
import com.yohobuy.ufo.model.request.product.ProductRequestBo;
import com.yohobuy.ufo.model.request.productpool.ProductPoolResponseBo;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
* Created by li.ma on 2018/9/18.
*/
@Service
public class StorageService {
private static final Logger LOGGER = LoggerFactory.getLogger(StorageService.class);
@Autowired
private ProductConvertService productConvertService;
@Autowired
private StoragePriceMapper storagePriceMapper;
@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);
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<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));
responseBos.add(productResponseBo);
}
return new PageResponseBO<>(count, responseBos, bo.getPage(), bo.getRows());
}
public PageResponseBO<ProductResponceBo> storagePriceList(ProductRequestBo bo) {
LOGGER.info("StorageService storagePriceList param = {}", bo);
StoragePrice storagePrice = productConvertService.convertBo2Skup(bo);
int count = storagePriceMapper.selectStoragePriceCount(storagePrice);
if (count == 0) {
LOGGER.warn("StorageService storagePriceList count is 0.param = {}", bo);
return new PageResponseBO<>();
}
List<StoragePrice> storagePriceList = storagePriceMapper.selectStoragePriceList(storagePrice, bo.getStart(), bo.getRows());
List<ProductResponceBo> responseBos = new ArrayList<>();
ProductResponceBo productResponseBo;
for (StoragePrice storagePriceItem : storagePriceList) {
productResponseBo = productConvertService.convertSkupDo2Bo(storagePriceItem);
responseBos.add(productResponseBo);
}
productAssistService.fillProductDetail(responseBos).fillGoodsColor(responseBos).fillSortName(responseBos);
return new PageResponseBO<>(count, responseBos, bo.getPage(), bo.getRows());
}
}
... ...