Authored by kun

Merge remote-tracking branch 'origin/master'

Showing 26 changed files with 1987 additions and 0 deletions
... ... @@ -13,3 +13,11 @@ product/target/
web/target/
deploy/target/
common/target/
*.project
*.classpath
web/.settings/
product/.settings/
order/.settings/
deploy/.settings/
common/.settings/
.settings/
... ...
package com.yoho.ufo.util;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
*
*
* @author Lixiaodi
*
*/
public class CollectionUtil {
/**
* 抽取集合对象中某个字段作为key,对象作为value的map.
*
* @param collection 集合
* @param keyMapper key字段获取方法
* @param U 对象类型
* @param T key类型
*
* @return map
*/
public static <T, U> Map<T, U> extractMap(Collection<U> collection, Function<? super U, ? extends T> keyMapper) {
Map<T, U> map = new HashMap<T, U>();
collection.forEach(item -> map.put(keyMapper.apply(item), item));
return map;
}
/**
* 抽取集合对象中某个字段作为key,某个字段作为value的map.
*
* @param collection 集合
* @param keyMapper key字段获取方法
* @param valueMapper value获取方法
* @param U 对象类型
* @param T key类型
* @param K value类型
*
* @return map
*/
public static <T, K, U> Map<T, K> extractMap(Collection<U> collection, Function<? super U, ? extends T> keyMapper, Function<? super U, ? extends K> valueMapper) {
Map<T, K> map = new HashMap<T, K>();
collection.forEach(item -> map.put(keyMapper.apply(item), valueMapper.apply(item)));
return map;
}
/**
* 抽取集合中:对象的属性,组成新的list返回
*
* @param collection 集合
* @param fieldDefiner 属性抽取方法
* @return 抽取属性的list
*/
public static <T, U> List<T> map(Collection<U> collection, Function<? super U, ? extends T> fieldDefiner) {
return collection.stream().map(fieldDefiner).collect(Collectors.toList());
}
/**
* 抽取不重复的属性集(自定义去重复方法,返回值)
*
* @param collection 集合
* @param fieldDefiner 定义重复及返回值
* @return 属性集list
*/
public static <T, U> List<T> distinct(Collection<U> collection, Function<? super U, ? extends T> fieldDefiner) {
List<T> result = new ArrayList<>();
Set<T> set = new HashSet<>();
collection.stream().forEach(u -> {
T v = fieldDefiner.apply(u);
if (!set.contains(v)) {
result.add(v);
}
set.add(v);
});
return result;
}
/**
* 集合去重复
*
* @param collection 集合
* @return 去重复后的集合
*/
public static <U> List<U> distinct(Collection<U> collection) {
return distinct(collection, e -> e);
}
/**
* 抽取不重复的属性集(自定义去重复方法,返回值)
*
* @param collection 集合
* @param key 定义重复及返回值
* @return 属性集list
*/
public static <T, U> List<U> distinctByKey(Collection<U> collection, Function<? super U, ? extends T> key) {
List<U> result = new ArrayList<>();
Set<T> set = new HashSet<>();
collection.stream().forEach(u -> {
T v = key.apply(u);
if (!set.contains(v)) {
result.add(u);
}
set.add(v);
});
return result;
}
/**
* 将集合进行分组.
*
* @param collection 集合
* @param groupKey 分组方法
* @return 分组结果
*/
public static <T, U> Map<T, List<U>> groupingBy(Collection<U> collection,
Function<? super U, ? extends T> groupKey) {
return groupingBy(collection.stream(), groupKey);
}
/**
* 将集合进行分组.
*
* @param stearm 集合stream
* @param groupKey 分组方法
* @return 分组结果
*/
public static <T, U> Map<T, List<U>> groupingBy(Stream<U> stearm, Function<? super U, ? extends T> groupKey) {
return stearm.collect(Collectors.groupingBy(groupKey));
}
/**
* 按照key进行分组,分组结果类型由U转换为R
*
* @param collection 集合
* @param groupKey 分组key
* @param valueMapper 值提取方法
* @return 分组结果
*/
public static <T, U, R> Map<T, List<R>> groupingBy(Collection<U> collection,
Function<? super U, ? extends T> groupKey, Function<? super U, ? extends R> valueMapper) {
Map<T, List<U>> r0 = groupingBy(collection.stream(), groupKey);
Map<T, List<R>> r = new HashMap<>();
r0.forEach((k, v) -> {
List<R> elements = new ArrayList<>();
r.put(k, elements);
v.forEach(e -> elements.add(valueMapper.apply(e)));
});
return r;
}
/**
* 多个条件分组.
*
* @param collection 集合
* @param groupKey 多个分组方法
* @return 分组结果
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T, U> Map groupingByMulti(Collection<U> collection, Function<? super U, ?>... groupKey) {
return groupingByMulti(collection.stream(), groupKey);
}
/**
* 多个条件分组.
*
* @param stearm 集合stearm
* @param groupKey 多个分组方法
* @return 分组结果
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T, U> Map groupingByMulti(Stream<U> stearm, Function<? super U, ?>... groupKey) {
Collector c = Collectors.groupingBy(groupKey[groupKey.length - 1]);
for (int i = groupKey.length - 2; i >= 0; i--) {
c = Collectors.groupingBy(groupKey[i], c);
}
return (Map) stearm.collect(c);
}
/**
* 多条件排序
*
* @param list 集合
* @param groupKey 多个排序key定义
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T, U> void sortByMulti(List<U> list, Function<? super U, ? extends Comparable>... groupKey) {
list.sort(getMultiComparator(groupKey));
}
/**
* 获取联合排序器
*
* @param groupKey 多个key定义
* @return 比较器
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T, U> Comparator<U> getMultiComparator(Function<? super U, ? extends Comparable>... groupKey) {
Comparator<U> c = (e1, e2) -> groupKey[0].apply(e1).compareTo(groupKey[0].apply(e2));
for (int i = 1; i <= groupKey.length; i++) {
final int j = i;
c = c.thenComparing((e1, e2) -> groupKey[j].apply(e1).compareTo(groupKey[j].apply(e2)));
}
return c;
}
/**
* 集合计算(求和,最大值,最小值,concat等)
*
* @param list 集合
* @param initValue 结果默认值
* @param bi 二值计算方法
* @param calKey 单值提取方法
* @return 计算结果
*/
public static <U, P> P collectionCal(Collection<U> list, P initValue, BiFunction<P, P, P> bi,
Function<? super U, ? extends P> calKey) {
return list.stream().reduce(initValue, (r, u) -> r = bi.apply(r, calKey.apply(u)),
(u1, u2) -> bi.apply(u1, u2));
}
@SuppressWarnings("unchecked")
public static <T> List<T> asList(T... elements) {
List<T> list = new ArrayList<>(elements.length);
for(T t : elements) {
list.add(t);
}
return list;
}
// 集合操作:子集分割
public static <T> List<List<T>> split(Collection<T> collection, int subCount) {
List<List<T>> pieceList = new ArrayList<>();
List<T> p = new ArrayList<>();
for (T t : collection) {
if (p.size() >= subCount) {
pieceList.add(p);
p = new ArrayList<>();
}
p.add(t);
}
if (!p.isEmpty()) {
pieceList.add(p);
}
return pieceList;
}
}
... ...
... ... @@ -60,4 +60,6 @@ public interface BrandMapper {
* @return
*/
List<Brand> getAllBrand();
List<Brand> selectBrandByIdList(@Param("list") List<Integer> brandIdList);
}
... ...
package com.yoho.ufo.dal;
import com.yoho.ufo.dal.model.GoodsImages;
import java.util.List;
public interface GoodsImagesMapper {
int deleteByPrimaryKey(Integer id);
int insert(GoodsImages record);
GoodsImages selectByPrimaryKey(Integer id);
List<GoodsImages> selectAll();
int updateByPrimaryKey(GoodsImages record);
int deleteByGoodsId(Integer goodsId);
List<GoodsImages> selectByGoodsId(Integer goodsId);
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal;
import com.yoho.ufo.dal.model.Goods;
import java.util.List;
public interface GoodsMapper {
int deleteByPrimaryKey(Integer id);
int insert(Goods record);
Goods selectByPrimaryKey(Integer id);
List<Goods> selectAll();
int updateByPrimaryKey(Goods record);
List<Goods> selectByProductId(List<Integer> productIds);
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yoho.ufo.dal.model.Product;
public interface ProductMapper {
int deleteByPrimaryKey(Integer id);
int insert(Product record);
Product selectByPrimaryKey(Integer id);
List<Product> selectAll();
int updateByPrimaryKey(Product record);
List<Product> selectPage(@Param("productCode") String productCode,
@Param("productName") String productName,
@Param("maxSortId") Integer maxSortId,
@Param("midSortId") Integer midSortId,
@Param("brandId") Integer brandId,
@Param("shelveStatus") Integer shelveStatus,
@Param("start") Integer start,
@Param("rows") Integer rows);
int selectCount(@Param("productCode") String productCode,
@Param("productName") String productName,
@Param("maxSortId") Integer maxSortId,
@Param("midSortId") Integer midSortId,
@Param("brandId") Integer brandId,
@Param("shelveStatus") Integer shelveStatus);
List<Product> selectSkuPage(@Param("productCode") String productCode,
@Param("productName") String productName,
@Param("maxSortId") Integer maxSortId,
@Param("midSortId") Integer midSortId,
@Param("brandId") Integer brandId,
@Param("shelveStatus") Integer shelveStatus,
@Param("skuCondition") Integer skuCondition,
@Param("skupCondition") Integer skupCondition,
@Param("storageId") Integer storageId,
@Param("sellerUid") Integer sellerUid,
@Param("hasStock") Integer hasStock,
@Param("skup") Integer skup,
@Param("start") Integer start,
@Param("rows") Integer rows);
int selectSkuCount(@Param("productCode") String productCode,
@Param("productName") String productName,
@Param("maxSortId") Integer maxSortId,
@Param("midSortId") Integer midSortId,
@Param("brandId") Integer brandId,
@Param("shelveStatus") Integer shelveStatus,
@Param("skuCondition") Integer skuCondition,
@Param("skupCondition") Integer skupCondition,
@Param("storageId") Integer storageId,
@Param("sellerUid") Integer sellerUid,
@Param("hasStock") Integer hasStock,
@Param("skup") Integer skup);
}
\ No newline at end of file
... ...
... ... @@ -68,4 +68,6 @@ public interface ProductSortMapper {
* @return
*/
List<ProductSort> getAllProcutSort();
List<ProductSort> selectSortByIdList(@Param("list") List<Integer> sortIdList);
}
... ...
package com.yoho.ufo.dal;
import com.yoho.ufo.dal.model.Storage;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface StorageMapper {
int deleteByPrimaryKey(Integer id);
int insert(Storage record);
Storage selectByPrimaryKey(Integer id);
List<Storage> selectAll();
int updateByPrimaryKey(Storage record);
List<Storage> selectByGoodsId(Integer goodsId);
List<Storage> selectByGoodsIdList(@Param("list") List<Integer> goodsIdList);
int addStorageNum(@Param("storageId")Integer storageId, @Param("storageNum")Integer storageNum);
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal;
import java.util.List;
import org.apache.ibatis.annotations.Param;
import com.yoho.ufo.dal.model.StoragePrice;
public interface StoragePriceMapper {
int deleteByPrimaryKey(Integer id);
int insert(StoragePrice record);
StoragePrice selectByPrimaryKey(Integer id);
List<StoragePrice> selectAll();
int updateByPrimaryKey(StoragePrice record);
List<StoragePrice> selectMinPriceByProductIdList(@Param("list") List<Integer> productIdList);
List<StoragePrice> selectByGoodsIdList(@Param("list") List<Integer> goodsIdList);
List<StoragePrice> selectPage(@Param("sellerUid") Integer sellerUid,
@Param("status") Integer status,
@Param("skup") Integer skup,
@Param("storageId") Integer storageId,
@Param("start") Integer start,
@Param("rows") Integer rows);
int selectCount(@Param("sellerUid") Integer sellerUid,
@Param("status") Integer status,
@Param("skup") Integer skup,
@Param("storageId") Integer storageId);
StoragePrice selectBySkup(Integer skup);
int cancelSaleSkup(Integer skup);
}
\ No newline at end of file
... ...
... ... @@ -63,4 +63,6 @@ public interface UfoSizeMapper {
* @return
*/
List<Size> selectAllSizeBySortId(@Param("sortId") Integer sortId);
List<Size> selectByIdList(@Param("list")List<Integer> idList);
}
... ...
package com.yoho.ufo.dal.model;
public class Goods {
private Integer id;
private Integer productId;
private Integer colorId;
private String colorName;
private String goodsName;
private String colorImage;
private String isDefault;
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 getColorId() {
return colorId;
}
public void setColorId(Integer colorId) {
this.colorId = colorId;
}
public String getColorName() {
return colorName;
}
public void setColorName(String colorName) {
this.colorName = colorName;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public String getColorImage() {
return colorImage;
}
public void setColorImage(String colorImage) {
this.colorImage = colorImage;
}
public String getIsDefault() {
return isDefault;
}
public void setIsDefault(String isDefault) {
this.isDefault = isDefault;
}
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal.model;
public class GoodsImages {
private Integer id;
private Integer goodsId;
private Integer productId;
private String isDefault;
private String imageUrl;
private Integer orderBy;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getGoodsId() {
return goodsId;
}
public void setGoodsId(Integer goodsId) {
this.goodsId = goodsId;
}
public Integer getProductId() {
return productId;
}
public void setProductId(Integer productId) {
this.productId = productId;
}
public String getIsDefault() {
return isDefault;
}
public void setIsDefault(String isDefault) {
this.isDefault = isDefault;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public Integer getOrderBy() {
return orderBy;
}
public void setOrderBy(Integer orderBy) {
this.orderBy = orderBy;
}
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal.model;
import java.math.BigDecimal;
public class Product {
private Integer id;
private String productName;
private String productCode;
private Integer maxSortId;
private Integer midSortId;
private Integer brandId;
private Integer seriesId;
private String gender;
private Integer saleTime;
private BigDecimal minPrice;
private BigDecimal maxPrice;
private Integer createTime;
private Integer updateTime;
private Integer shelveTime;
private Integer editTime;
/** 0待上架 1上架 2下架. */
private Integer shelveStatus;
private Integer storage;
private String keyWords;
// 0未删除 1已删除
private Integer delStatus;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public Integer getMaxSortId() {
return maxSortId;
}
public void setMaxSortId(Integer maxSortId) {
this.maxSortId = maxSortId;
}
public Integer getMidSortId() {
return midSortId;
}
public void setMidSortId(Integer midSortId) {
this.midSortId = midSortId;
}
public Integer getBrandId() {
return brandId;
}
public void setBrandId(Integer brandId) {
this.brandId = brandId;
}
public Integer getSeriesId() {
return seriesId;
}
public void setSeriesId(Integer seriesId) {
this.seriesId = seriesId;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public Integer getSaleTime() {
return saleTime;
}
public void setSaleTime(Integer saleTime) {
this.saleTime = saleTime;
}
public BigDecimal getMinPrice() {
return minPrice;
}
public void setMinPrice(BigDecimal minPrice) {
this.minPrice = minPrice;
}
public BigDecimal getMaxPrice() {
return maxPrice;
}
public void setMaxPrice(BigDecimal maxPrice) {
this.maxPrice = maxPrice;
}
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 getShelveTime() {
return shelveTime;
}
public void setShelveTime(Integer shelveTime) {
this.shelveTime = shelveTime;
}
public Integer getEditTime() {
return editTime;
}
public void setEditTime(Integer editTime) {
this.editTime = editTime;
}
public Integer getShelveStatus() {
return shelveStatus;
}
public void setShelveStatus(Integer shelveStatus) {
this.shelveStatus = shelveStatus;
}
public Integer getStorage() {
return storage;
}
public void setStorage(Integer storage) {
this.storage = storage;
}
public String getKeyWords() {
return keyWords;
}
public void setKeyWords(String keyWords) {
this.keyWords = keyWords;
}
public Integer getDelStatus() {
return delStatus;
}
public void setDelStatus(Integer delStatus) {
this.delStatus = delStatus;
}
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal.model;
public class Storage {
private Integer id;
private Integer productId;
private Integer goodsId;
private Integer sizeId;
private Integer storageNum;
private Integer updateTime;
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 getStorageNum() {
return storageNum;
}
public void setStorageNum(Integer storageNum) {
this.storageNum = storageNum;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
package com.yoho.ufo.dal.model;
import java.math.BigDecimal;
public class StoragePrice {
private Integer id;
private Integer skup;
private Integer productId;
private Integer goodsId;
private Integer storageId;
private Integer depotNum;
private Integer sellerUid;
private BigDecimal price;
private Integer status;
private Integer updateTime;
private Integer createTime;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getSkup() {
return skup;
}
public void setSkup(Integer skup) {
this.skup = skup;
}
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 getStorageId() {
return storageId;
}
public void setStorageId(Integer storageId) {
this.storageId = storageId;
}
public Integer getDepotNum() {
return depotNum;
}
public void setDepotNum(Integer depotNum) {
this.depotNum = depotNum;
}
public Integer getSellerUid() {
return sellerUid;
}
public void setSellerUid(Integer sellerUid) {
this.sellerUid = sellerUid;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getUpdateTime() {
return updateTime;
}
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public Integer getCreateTime() {
return createTime;
}
public void setCreateTime(Integer createTime) {
this.createTime = createTime;
}
}
\ No newline at end of file
... ...
... ... @@ -94,4 +94,12 @@
select id, brand_name
from brand
</select>
<select id="selectBrandByIdList" resultMap="brandMap">
select id, brand_name
from brand where id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</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.yoho.ufo.dal.GoodsImagesMapper">
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.GoodsImages">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="goods_id" jdbcType="INTEGER" property="goodsId" />
<result column="product_id" jdbcType="INTEGER" property="productId" />
<result column="is_default" jdbcType="CHAR" property="isDefault" />
<result column="image_url" jdbcType="VARCHAR" property="imageUrl" />
<result column="order_by" jdbcType="INTEGER" property="orderBy" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from goods_images
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.dal.model.GoodsImages">
insert into goods_images (id, goods_id, product_id,
is_default, image_url, order_by
)
values (#{id,jdbcType=INTEGER}, #{goodsId,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER},
#{isDefault,jdbcType=CHAR}, #{imageUrl,jdbcType=VARCHAR}, #{orderBy,jdbcType=INTEGER}
)
</insert>
<update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.GoodsImages">
update goods_images
set goods_id = #{goodsId,jdbcType=INTEGER},
product_id = #{productId,jdbcType=INTEGER},
is_default = #{isDefault,jdbcType=CHAR},
image_url = #{imageUrl,jdbcType=VARCHAR},
order_by = #{orderBy,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, goods_id, product_id, is_default, image_url, order_by
from goods_images
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, goods_id, product_id, is_default, image_url, order_by
from goods_images
</select>
<delete id="deleteByGoodsId" parameterType="java.lang.Integer">
delete from goods_images
where goods_id = #{goodsId,jdbcType=INTEGER}
</delete>
<select id="selectByGoodsId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, goods_id, product_id, is_default, image_url, order_by
from goods_images
where goods_id = #{goodsId,jdbcType=INTEGER}
</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.yoho.ufo.dal.GoodsMapper">
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.Goods">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_id" jdbcType="INTEGER" property="productId" />
<result column="color_id" jdbcType="INTEGER" property="colorId" />
<result column="color_name" jdbcType="VARCHAR" property="colorName" />
<result column="goods_name" jdbcType="VARCHAR" property="goodsName" />
<result column="color_image" jdbcType="VARCHAR" property="colorImage" />
<result column="is_default" jdbcType="CHAR" property="isDefault" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from goods
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.dal.model.Goods" useGeneratedKeys="true" keyProperty="id" >
insert into goods (id, product_id, color_id,
color_name, goods_name, color_image,
is_default)
values (#{id,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{colorId,jdbcType=INTEGER},
#{colorName,jdbcType=VARCHAR}, #{goodsName,jdbcType=VARCHAR}, #{colorImage,jdbcType=VARCHAR},
#{isDefault,jdbcType=CHAR})
</insert>
<update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.Goods">
update goods
set product_id = #{productId,jdbcType=INTEGER},
color_id = #{colorId,jdbcType=INTEGER},
color_name = #{colorName,jdbcType=VARCHAR},
goods_name = #{goodsName,jdbcType=VARCHAR},
color_image = #{colorImage,jdbcType=VARCHAR},
is_default = #{isDefault,jdbcType=CHAR}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, product_id, color_id, color_name, goods_name, color_image, is_default
from goods
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, product_id, color_id, color_name, goods_name, color_image, is_default
from goods
</select>
<select id="selectByProductId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, product_id, color_id, color_name, goods_name, color_image, is_default
from goods
where product_id in
<foreach item="item" index="index" collection="productIds" open="(" separator="," close=")">
#{item}
</foreach>
</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.yoho.ufo.dal.ProductMapper">
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.Product">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="product_name" jdbcType="VARCHAR" property="productName" />
<result column="product_code" jdbcType="VARCHAR" property="productCode" />
<result column="max_sort_id" jdbcType="INTEGER" property="maxSortId" />
<result column="mid_sort_id" jdbcType="INTEGER" property="midSortId" />
<result column="brand_id" jdbcType="INTEGER" property="brandId" />
<result column="series_id" jdbcType="INTEGER" property="seriesId" />
<result column="gender" jdbcType="CHAR" property="gender" />
<result column="sale_time" jdbcType="INTEGER" property="saleTime" />
<result column="min_price" jdbcType="DECIMAL" property="minPrice" />
<result column="max_price" jdbcType="DECIMAL" property="maxPrice" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
<result column="shelve_time" jdbcType="INTEGER" property="shelveTime" />
<result column="edit_time" jdbcType="INTEGER" property="editTime" />
<result column="shelve_status" jdbcType="INTEGER" property="shelveStatus" />
<result column="storage" jdbcType="INTEGER" property="storage" />
<result column="key_words" jdbcType="VARCHAR" property="keyWords" />
<result column="del_status" jdbcType="INTEGER" property="delStatus" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from product
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.dal.model.Product" useGeneratedKeys="true" keyProperty="id" >
insert into product (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)
values (#{id,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR}, #{productCode,jdbcType=VARCHAR},
#{maxSortId,jdbcType=INTEGER}, #{midSortId,jdbcType=INTEGER}, #{brandId,jdbcType=INTEGER},
#{seriesId,jdbcType=INTEGER}, #{gender,jdbcType=CHAR}, #{saleTime,jdbcType=INTEGER},
#{minPrice,jdbcType=DECIMAL}, #{maxPrice,jdbcType=DECIMAL}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER}, #{shelveTime,jdbcType=INTEGER}, #{editTime,jdbcType=INTEGER},
#{shelveStatus,jdbcType=INTEGER}, #{storage,jdbcType=INTEGER}, #{keyWords,jdbcType=VARCHAR},
#{delStatus,jdbcType=INTEGER})
</insert>
<update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.Product">
update product
set product_name = #{productName,jdbcType=VARCHAR},
product_code = #{productCode,jdbcType=VARCHAR},
max_sort_id = #{maxSortId,jdbcType=INTEGER},
mid_sort_id = #{midSortId,jdbcType=INTEGER},
brand_id = #{brandId,jdbcType=INTEGER},
series_id = #{seriesId,jdbcType=INTEGER},
gender = #{gender,jdbcType=CHAR},
sale_time = #{saleTime,jdbcType=INTEGER},
min_price = #{minPrice,jdbcType=DECIMAL},
max_price = #{maxPrice,jdbcType=DECIMAL},
create_time = #{createTime,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER},
shelve_time = #{shelveTime,jdbcType=INTEGER},
edit_time = #{editTime,jdbcType=INTEGER},
shelve_status = #{shelveStatus,jdbcType=INTEGER},
storage = #{storage,jdbcType=INTEGER},
key_words = #{keyWords,jdbcType=VARCHAR},
del_status = #{delStatus,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" 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 = #{id,jdbcType=INTEGER}
</select>
<select id="selectAll" 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
</select>
<select id="selectPage" 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 1=1 and <include refid="pageCondition" /> order by product.id desc limit #{start},#{rows}
</select>
<select id="selectCount" resultMap="java.lang.Integer">
select count(*) from product where 1=1 and <include refid="pageCondition" />
</select>
<sql id="pageCondition" >
<if test="productCode != null and productCode !=''">
and product_code = #{productCode}
</if>
<if test="productName != null and productName !=''">
and product_name like "%"#{productName}"%"
</if>
<if test="maxSortId != null and maxSortId > 0">
and max_sort_id = #{maxSortId}
</if>
<if test="midSortId != null and midSortId > 0">
and mid_sort_id = #{midSortId}
</if>
<if test="brandId != null and brandId > 0">
and brand_id = #{brandId}
</if>
<if test="shelveStatus != null and shelveStatus > -1">
and shelve_status = #{shelveStatus}
</if>
</sql>
<select id="selectSkuPage" resultMap="BaseResultMap">
select distinct p.id from product p <include refid="skuPageCondition" /> order by p.id desc limit #{start},#{rows}
</select>
<select id="selectSkuCount" resultMap="java.lang.Integer">
select count(*) from (select distinct p.id from product p <include refid="skuPageCondition" /> ) sub
</select>
<sql id="skuPageCondition" >
<if test="skuCondition == 1">
inner join storage s on p.id = s.product_id
</if>
<if test="skupCondition == 1">
inner join storage_price sp on p.id = sp.product_id
</if>
<if test="productCode != null and productCode !=''">
and product_code = #{productCode}
</if>
<if test="productName != null and productName !=''">
and product_name like "%"#{productName}"%"
</if>
<if test="maxSortId != null and maxSortId > 0">
and max_sort_id = #{maxSortId}
</if>
<if test="midSortId != null and midSortId > 0">
and mid_sort_id = #{midSortId}
</if>
<if test="brandId != null and brandId > 0">
and brand_id = #{brandId}
</if>
<if test="shelveStatus != null and shelveStatus > -1">
and shelve_status = #{shelveStatus}
</if>
<if test="storageId != null and storageId > 0">
and s.id = #{storageId}
</if>
<if test="sellerUid != null and sellerUid > 0">
and sp.seller_uid = #{sellerUid}
</if>
<if test="hasStock != null and hasStock == 0">
and s.storage_num = 0
</if>
<if test="hasStock != null and hasStock == 1">
and s.storage_num &gt; 0
</if>
<if test="skup != null and skup > 0">
and sp.skup = #{skup}
</if>
</sql>
</mapper>
\ No newline at end of file
... ...
... ... @@ -91,4 +91,11 @@
select <include refid="queryColumns"/>
from product_sort
</select>
<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=")">
#{item}
</foreach>
</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.yoho.ufo.dal.StorageMapper">
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.Storage">
<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="storage_num" jdbcType="INTEGER" property="storageNum" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from storage
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.dal.model.Storage">
insert into storage (id, product_id, goods_id,
size_id, storage_num, update_time,
create_time)
values (#{id,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER}, #{goodsId,jdbcType=INTEGER},
#{sizeId,jdbcType=INTEGER}, #{storageNum,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER},
#{createTime,jdbcType=INTEGER})
</insert>
<update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.Storage">
update storage
set product_id = #{productId,jdbcType=INTEGER},
goods_id = #{goodsId,jdbcType=INTEGER},
size_id = #{sizeId,jdbcType=INTEGER},
storage_num = #{storageNum,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num, update_time, create_time
from storage
where id = #{id,jdbcType=INTEGER}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num, update_time, create_time
from storage
</select>
<select id="selectByGoodsId" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num, update_time, create_time
from storage where goods_id = #{goodsId,jdbcType=INTEGER}
</select>
<select id="selectByGoodsIdList" resultMap="BaseResultMap">
select id, product_id, goods_id, size_id, storage_num, update_time, create_time
from storage where goods_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<update id="addStorageNum">
update storage set storage_num = storage_num + #{storageNum,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER},
where id = #{storageId,jdbcType=INTEGER}
</update>
</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.yoho.ufo.dal.StoragePriceMapper">
<resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.StoragePrice">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="skup" jdbcType="INTEGER" property="skup" />
<result column="product_id" jdbcType="INTEGER" property="productId" />
<result column="goods_id" jdbcType="INTEGER" property="goodsId" />
<result column="storage_id" jdbcType="INTEGER" property="storageId" />
<result column="depot_num" jdbcType="INTEGER" property="depotNum" />
<result column="seller_uid" jdbcType="INTEGER" property="sellerUid" />
<result column="price" jdbcType="DECIMAL" property="price" />
<result column="status" jdbcType="INTEGER" property="status" />
<result column="update_time" jdbcType="INTEGER" property="updateTime" />
<result column="create_time" jdbcType="INTEGER" property="createTime" />
</resultMap>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
delete from storage_price
where id = #{id,jdbcType=INTEGER}
</delete>
<insert id="insert" parameterType="com.yoho.ufo.dal.model.StoragePrice">
insert into storage_price (id, skup, product_id,
goods_id, storage_id, depot_num,
seller_uid, price, status,
update_time, create_time)
values (#{id,jdbcType=INTEGER}, #{skup,jdbcType=INTEGER}, #{productId,jdbcType=INTEGER},
#{goodsId,jdbcType=INTEGER}, #{storageId,jdbcType=INTEGER}, #{depotNum,jdbcType=INTEGER},
#{sellerUid,jdbcType=INTEGER}, #{price,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER}, #{createTime,jdbcType=INTEGER})
</insert>
<update id="updateByPrimaryKey" parameterType="com.yoho.ufo.dal.model.StoragePrice">
update storage_price
set skup = #{skup,jdbcType=INTEGER},
product_id = #{productId,jdbcType=INTEGER},
goods_id = #{goodsId,jdbcType=INTEGER},
storage_id = #{storageId,jdbcType=INTEGER},
depot_num = #{depotNum,jdbcType=INTEGER},
seller_uid = #{sellerUid,jdbcType=INTEGER},
price = #{price,jdbcType=DECIMAL},
status = #{status,jdbcType=INTEGER},
update_time = #{updateTime,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=INTEGER}
where id = #{id,jdbcType=INTEGER}
</update>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" 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 id = #{id,jdbcType=INTEGER}
</select>
<select id="selectAll" resultMap="BaseResultMap">
select id, skup, product_id, goods_id, storage_id, depot_num, seller_uid, price,
status, update_time, create_time
from storage_price
</select>
<select id="selectMinPriceByProductIdList" resultMap="BaseResultMap">
select product_id, min(price) as price,
from storage_price where product_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
and status = 1 group by product_id
</select>
<select id="selectByGoodsIdList" 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 goods_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="selectPage" 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 storage_id = #{storageId}
<include refid="skupPageCondition" /> order by id desc limit #{start},#{rows}
</select>
<select id="selectCount" resultMap="BaseResultMap">
select count(*)
from storage_price where storage_id = #{storageId}
<include refid="skupPageCondition" />
</select>
<sql id="skupPageCondition" >
<if test="sellerUid != null and sellerUid > 0">
and seller_uid = #{sellerUid}
</if>
<if test="status != null">
and status = #{status}
</if>
<if test="skup != null and skup > 0">
and skup = #{skup}
</if>
</sql>
<update id="cancelSaleSkup" parameterType="java.lang.Integer">
update storage_price set status = 1,
update_time = unix_timestamp(),
where skup = #{skup,jdbcType=INTEGER} and status = 2
</update>
<select id="selectBySkup" parameterType="java.lang.Integer" 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 skup = #{skup,jdbcType=INTEGER}
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -84,4 +84,12 @@
select <include refid="queryColumns"/>
from size where sort_id = #{sortId}
</select>
<select id="selectAllSizeBySortId" resultMap="sizeMap">
select id,size_name
from size where sort_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;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yoho.ufo.service.IProductService;
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.ProductEditResponceBo;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
@RestController
@RequestMapping(value = "/product")
public class ProductController {
private static final Logger LOGGER = LoggerFactory.getLogger(ProductController.class);
@Resource
private IProductService productService;
/** 基础商品创建 */
@RequestMapping(value = "/addOrUpdate")
public ApiResponse<Void> addOrUpdate(@RequestBody ProductRequestBo bo) {
LOGGER.info("product.addOrUpdate param = {}", bo);
return productService.addOrUpdate(bo);
}
/** 基础商品创建 - 编辑查询 */
@RequestMapping(value = "/find")
public ApiResponse<ProductEditResponceBo> find(Integer id) {
LOGGER.info("product.find id = {}", id);
return productService.findProductDetailById(id);
}
@RequestMapping(value = "/list")
public ApiResponse<PageResponseBO<ProductResponceBo>> list(ProductRequestBo bo) {
LOGGER.info("product.list param = {}", bo);
return productService.list(bo);
}
@RequestMapping(value = "/skuList")
public ApiResponse<PageResponseBO<ProductResponceBo>> skuList(ProductRequestBo bo) {
LOGGER.info("product.skuList param = {}", bo);
return productService.getSkuList(bo);
}
@RequestMapping(value = "/detailList")
public ApiResponse<PageResponseBO<ProductResponceBo>> detailList(ProductRequestBo bo) {
LOGGER.info("product.detailList param = {}", bo);
return productService.getSkupDetailList(bo);
}
}
... ...
package com.yoho.ufo.service;
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.ProductEditResponceBo;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
public interface IProductService {
ApiResponse<Void> addOrUpdate(ProductRequestBo bo);
ApiResponse<ProductEditResponceBo> findProductDetailById(Integer id);
ApiResponse<PageResponseBO<ProductResponceBo>> list(ProductRequestBo bo);
ApiResponse<PageResponseBO<ProductResponceBo>> getSkuList(ProductRequestBo bo);
ApiResponse<PageResponseBO<ProductResponceBo>> getSkupDetailList(ProductRequestBo bo);
ApiResponse<PageResponseBO<ProductResponceBo>> cancelSaleSkup(ProductRequestBo bo);
}
... ...
package com.yoho.ufo.service.impl;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Param;
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 com.alibaba.fastjson.JSON;
import com.yoho.ufo.dal.BrandMapper;
import com.yoho.ufo.dal.GoodsImagesMapper;
import com.yoho.ufo.dal.GoodsMapper;
import com.yoho.ufo.dal.ProductMapper;
import com.yoho.ufo.dal.ProductSortMapper;
import com.yoho.ufo.dal.StorageMapper;
import com.yoho.ufo.dal.StoragePriceMapper;
import com.yoho.ufo.dal.UfoSizeMapper;
import com.yoho.ufo.dal.model.Goods;
import com.yoho.ufo.dal.model.GoodsImages;
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.exception.CommonException;
import com.yoho.ufo.model.brand.Brand;
import com.yoho.ufo.model.commoditybasicrole.category.ProductSort;
import com.yoho.ufo.model.commoditybasicrole.size.Size;
import com.yoho.ufo.service.IProductService;
import com.yoho.ufo.util.CollectionUtil;
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.ProductEditResponceBo;
import com.yohobuy.ufo.model.resp.product.ProductResponceBo;
@Service
public class ProductServiceImpl implements IProductService {
private static final Logger LOGGER = LoggerFactory.getLogger(ProductServiceImpl.class);
@Autowired
private ProductSortMapper productSortMapper;
@Autowired
private ProductMapper productMapper;
@Autowired
private BrandMapper brandMapper;
@Autowired
private GoodsMapper goodsMapper;
@Autowired
private GoodsImagesMapper goodsImagesMapper;
@Autowired
private StorageMapper storageMapper;
@Autowired
private StoragePriceMapper storagePriceMapper;
@Autowired
private UfoSizeMapper sizeMapper;
@Override
public ApiResponse<Void> addOrUpdate(ProductRequestBo bo) {
checkProductInfo(bo);
Product product = getProductFromBo(bo);
Goods goods = getGoodsFromBo(bo);
List<Storage> storageList = getStoragesFromBo(bo);
List<GoodsImages> goodsImagesList = getGoodsImagesFromBo(bo);
Integer productId;
Integer goodsId;
// 新增
if (bo.getId() == null || bo.getId() < 1) {
if (productMapper.insert(product) == 0) {
return new ApiResponse<Void>(500, "创建商品失败");
}
productId = product.getId();
goods.setProductId(productId);
goodsMapper.insert(goods);
if (goodsMapper.insert(goods) == 0) {
return new ApiResponse<Void>(500, "创建商品颜色失败");
}
goodsId = goods.getId();
} else {
productMapper.updateByPrimaryKey(product);
productId = product.getId();
goodsId = goods.getId();
goods.setProductId(productId);
goodsMapper.updateByPrimaryKey(goods);
if (bo.getEditImage() != null && bo.getEditImage() == 1) {
goodsImagesMapper.deleteByGoodsId(goodsId);
}
}
for (Storage s : storageList) {
s.setProductId(productId);
s.setGoodsId(goodsId);
storageMapper.insert(s);
}
if (bo.getEditImage() != null && bo.getEditImage() == 1) {
for (GoodsImages gi : goodsImagesList) {
gi.setProductId(productId);
gi.setGoodsId(goodsId);
goodsImagesMapper.insert(gi);
}
}
return new ApiResponse<Void>(null);
}
private List<GoodsImages> getGoodsImagesFromBo(ProductRequestBo bo) {
List<GoodsImages> goodsImagesList = new ArrayList<>();
for (int i = 0; i < bo.getImageUrlList().size(); i++) {
String image = bo.getImageUrlList().get(i);
GoodsImages gi = new GoodsImages();
if (i == 0) {
gi.setIsDefault("Y");
} else {
gi.setIsDefault("N");
}
gi.setImageUrl(image);
gi.setOrderBy(i + 1);
goodsImagesList.add(gi);
}
return goodsImagesList;
}
private List<Storage> getStoragesFromBo(ProductRequestBo bo) {
List<Storage> storageList = new ArrayList<>();
for(Integer id : bo.getSizeIdList()) {
Storage s = new Storage();
s.setCreateTime((int) (System.currentTimeMillis() / 1000));
s.setSizeId(id);
s.setStorageNum(0);
storageList.add(s);
}
return storageList;
}
private Goods getGoodsFromBo(ProductRequestBo bo) {
Goods g = new Goods();
BeanUtils.copyProperties(bo, g);
g.setIsDefault("Y");
if (CollectionUtils.isNotEmpty(bo.getImageUrlList())) {
g.setColorImage(bo.getImageUrlList().get(0));
}
return g;
}
private Product getProductFromBo(ProductRequestBo bo) {
Product p = new Product();
BeanUtils.copyProperties(bo, p);
p.setShelveStatus(0);
p.setDelStatus(0);
p.setCreateTime((int) (System.currentTimeMillis() / 1000));
p.setMinPrice(new BigDecimal(bo.getMinPrice()));
p.setMaxPrice(new BigDecimal(bo.getMaxPrice()));
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
try {
p.setSaleTime((int) (sdf.parse(bo.getSaleTime()).getTime() / 1000));
} catch (ParseException e) {
}
p.setGender(bo.getGender().toString());
return p;
}
private void checkProductInfo(ProductRequestBo bo) {
if (bo.getBrandId() == null || bo.getBrandId() < 1) {
throw new CommonException(400, "请选择品牌");
}
if (bo.getSeriesId() == null || bo.getSeriesId() < 1) {
throw new CommonException(400, "请选择系列");
}
if (StringUtils.isBlank(bo.getProductName())) {
throw new CommonException(400, "请输入商品名称");
}
if (StringUtils.isBlank(bo.getSaleTime())) {
throw new CommonException(400, "请选择发售日期");
}
if (bo.getGender() == null || bo.getGender() < 1 || bo.getGender() > 3) {
throw new CommonException(400, "请选择性别");
}
if (bo.getMaxSortId() == null || bo.getMaxSortId() < 1) {
throw new CommonException(400, "请选择大分类");
}
if (bo.getMidSortId() == null || bo.getMidSortId() < 1) {
throw new CommonException(400, "请选择中分类");
}
if (StringUtils.isBlank(bo.getProductCode())) {
throw new CommonException(400, "请输入货号");
}
BigDecimal min, max;
if (StringUtils.isBlank(bo.getMinPrice())) {
throw new CommonException(400, "请输入价格限制最低");
}
if (StringUtils.isBlank(bo.getMaxPrice())) {
throw new CommonException(400, "请输入价格限制最高");
}
try {
min = new BigDecimal(bo.getMinPrice());
} catch (Exception e) {
throw new CommonException(400, "价格限制最低输入有误");
}
try {
max = new BigDecimal(bo.getMaxPrice());
} catch (Exception e) {
throw new CommonException(400, "价格限制最高输入有误");
}
if (min.compareTo(max) > 0) {
throw new CommonException(400, "价格限制最低>最高");
}
if (bo.getColorId() == null || bo.getColorId() < 1) {
throw new CommonException(400, "请选择颜色");
}
if (CollectionUtils.isEmpty(bo.getSizeIdList())) {
throw new CommonException(400, "请选择至少选择一个尺寸");
}
if (CollectionUtils.isEmpty(bo.getImageUrlList())) {
throw new CommonException(400, "请上传至少一张图片");
}
}
@Override
public ApiResponse<ProductEditResponceBo> findProductDetailById(Integer id) {
Product product = productMapper.selectByPrimaryKey(id);
if (product == null) {
throw new CommonException(400, "商品不存在");
}
List<Goods> goodsList = goodsMapper.selectByProductId(Arrays.asList(id));
Goods goods = null;
List<GoodsImages> goodsImages = null;
List<Storage> storages = null;
if (CollectionUtils.isNotEmpty(goodsList)) {
goods = goodsList.get(0);
goodsImages = goodsImagesMapper.selectByGoodsId(goods.getId());
storages = storageMapper.selectByGoodsId(goods.getId());
}
return mergeProductEditResponceBo(product, goods, goodsImages, storages);
}
private ApiResponse<ProductEditResponceBo> mergeProductEditResponceBo(Product product, Goods goods,
List<GoodsImages> goodsImages, List<Storage> storages) {
ProductEditResponceBo bo = new ProductEditResponceBo();
BeanUtils.copyProperties(product, bo);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
bo.setSaleTime(sdf.format(product.getSaleTime() * 1000L));
bo.setGender(new Integer(product.getGender()));
bo.setMinPrice(product.getMinPrice().toString());
bo.setMaxPrice(product.getMaxPrice().toString());
if (goods != null) {
bo.setGoodsName(goods.getGoodsName());
bo.setGoodsId(goods.getId());
bo.setColorId(goods.getColorId());
}
if (CollectionUtils.isNotEmpty(goodsImages)) {
bo.setImageUrlList(CollectionUtil.map(goodsImages, GoodsImages::getImageUrl));
}
if (CollectionUtils.isNotEmpty(storages)) {
bo.setStorageIdList(CollectionUtil.map(storages, Storage::getId));
bo.setSizeIdList(CollectionUtil.map(storages, Storage::getSizeId));
}
return new ApiResponse<ProductEditResponceBo>(bo);
}
public static void main(String[] args) {
ProductEditResponceBo bo = new ProductEditResponceBo();
Product product = new Product();product.setGender("1");product.setMaxPrice(new BigDecimal("99"));
product.setId(99);
BeanUtils.copyProperties(product, bo);
System.out.println(JSON.toJSONString(bo));
}
@Override
public ApiResponse<PageResponseBO<ProductResponceBo>> list(ProductRequestBo bo) {
int count = productMapper.selectCount(bo.getProductCode(),
bo.getProductName(),
bo.getMaxSortId(),
bo.getMidSortId(),
bo.getBrandId(),
bo.getShelveStatus());
List<ProductResponceBo> boList = new ArrayList<>();
if (count > 0) {
List<Product> productList = productMapper.selectPage(bo.getProductCode(),
bo.getProductName(),
bo.getMaxSortId(),
bo.getMidSortId(),
bo.getBrandId(),
bo.getShelveStatus(),
bo.getStart(),
bo.getRows());
productList.forEach(p -> {
ProductResponceBo b = new ProductResponceBo();
BeanUtils.copyProperties(p, b);
boList.add(b);
});
List<Integer> productIdList = CollectionUtil.distinct(productList, Product::getId);
List<Goods> goodsList = goodsMapper.selectByProductId(productIdList);
Map<Integer, Goods> goodsMap = CollectionUtil.extractMap(goodsList, Goods::getProductId);
List<Brand> brandList = brandMapper.selectBrandByIdList(CollectionUtil.distinct(productList, Product::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);
boList.forEach(respBo -> {
// 图片
Goods goods = goodsMap.get(respBo.getId());
if (goods != null) {
respBo.setColorImage(goods.getColorImage());
}
// 分类
ProductSort maxSort = productSortMap.get(respBo.getMaxSortId());
ProductSort midSort = productSortMap.get(respBo.getMidSortId());
String sort = "";
if (maxSort != null) {
sort += maxSort.getSortName();
}
if (StringUtils.isNotBlank(sort)) {
sort += "/";
}
if (midSort != null) {
sort += midSort.getSortName();
}
respBo.setSortName(sort);
// 品牌
Brand brand = brandMap.get(respBo.getBrandId());
if (brand != null) {
respBo.setBrandName(brand.getBrandName());
}
});
}
PageResponseBO<ProductResponceBo> pageBo = new PageResponseBO<>(count, boList, bo.getPage(), bo.getRows());
return new ApiResponse<>(pageBo);
}
@Override
public ApiResponse<PageResponseBO<ProductResponceBo>> getSkuList(ProductRequestBo bo) {
if ((bo.getHasStock() != null && bo.getHasStock() >= 0)
|| (bo.getStorageId() != null && bo.getStorageId() > 0)) {
bo.setSkuCondition(1);
} else {
bo.setSkuCondition(0);
}
if ((bo.getSkup() != null && bo.getSkup() > 0)
|| (bo.getSellerUid() != null && bo.getSellerUid() > 0)) {
bo.setSkupCondition(1);
} else {
bo.setSkupCondition(0);
}
int count = productMapper.selectSkuCount(bo.getProductCode(),
bo.getProductName(),
bo.getMaxSortId(),
bo.getMidSortId(),
bo.getBrandId(),
bo.getShelveStatus(),
bo.getSkuCondition(),
bo.getSkupCondition(),
bo.getStorageId(),
bo.getSellerUid(),
bo.getHasStock(),
bo.getSkup());
List<ProductResponceBo> boList = new ArrayList<>();
if (count > 0) {
List<Product> productList = productMapper.selectSkuPage(bo.getProductCode(),
bo.getProductName(),
bo.getMaxSortId(),
bo.getMidSortId(),
bo.getBrandId(),
bo.getShelveStatus(),
bo.getSkuCondition(),
bo.getSkupCondition(),
bo.getStorageId(),
bo.getSellerUid(),
bo.getHasStock(),
bo.getSkup(),
bo.getStart(),
bo.getRows());
productList.forEach(p -> {
ProductResponceBo b = new ProductResponceBo();
BeanUtils.copyProperties(p, b);
boList.add(b);
});
List<Integer> productIdList = CollectionUtil.distinct(productList, Product::getId);
List<Goods> goodsList = goodsMapper.selectByProductId(productIdList);
Map<Integer, Goods> goodsMap = CollectionUtil.extractMap(goodsList, Goods::getProductId);
List<Brand> brandList = brandMapper.selectBrandByIdList(CollectionUtil.distinct(productList, Product::getBrandId));
Map<Integer, Brand> brandMap = CollectionUtil.extractMap(brandList, Brand::getId);
List<Storage> storageList = storageMapper.selectByGoodsIdList(CollectionUtil.distinct(goodsList, Goods::getId));
Map<Integer, List<Storage>> storageMap = CollectionUtil.groupingBy(storageList, Storage::getGoodsId);
List<StoragePrice> storagePriceList = storagePriceMapper.selectMinPriceByProductIdList(productIdList);
Map<Integer, StoragePrice> storagePriceMap = CollectionUtil.extractMap(storagePriceList, StoragePrice::getProductId);
List<Size> sizeList = sizeMapper.selectByIdList(CollectionUtil.distinct(storageList, Storage::getSizeId));
Map<Integer, Size> sizeMap = CollectionUtil.extractMap(sizeList, Size::getId);
for(ProductResponceBo respBo : boList) {
Integer productId = respBo.getId();
// 品牌
Brand brand = brandMap.get(respBo.getBrandId());
if (brand != null) {
respBo.setBrandName(brand.getBrandName());
}
// 最低价
StoragePrice sp = storagePriceMap.get(productId);
if (sp != null) {
respBo.setCurrentPrice(sp.getPrice().toString());
}
// 可售库存
Goods goods = goodsMap.get(productId);
if(goods==null) {
continue;
}
List<Storage> aStorageList = storageMap.get(goods.getId());
int countStock = 0;
for(Storage s : aStorageList) {
countStock += s.getStorageNum();
}
respBo.setStorage(countStock);
List<ProductResponceBo> skuList = new ArrayList<>();
respBo.setSkuList(skuList);
//respBo
for(Storage s : aStorageList) {
ProductResponceBo skuBo = new ProductResponceBo();
skuBo.setId(s.getId());
skuBo.setGoodsName(goods.getGoodsName());
// 尺码
Size size = sizeMap.get(s.getSizeId());
if (size != null) {
skuBo.setSizeName(size.getSizeName());
}
skuBo.setStorage(s.getStorageNum());
skuList.add(skuBo);
}
}
}
PageResponseBO<ProductResponceBo> pageBo = new PageResponseBO<>(count, boList, bo.getPage(), bo.getRows());
return new ApiResponse<>(pageBo);
}
@Override
public ApiResponse<PageResponseBO<ProductResponceBo>> getSkupDetailList(ProductRequestBo bo) {
int count = storagePriceMapper.selectCount(
bo.getSellerUid(),
bo.getStatus(),
bo.getSkup(),
bo.getStorageId());
List<ProductResponceBo> boList = new ArrayList<>();
if (count > 0) {
List<StoragePrice> storagePrice = storagePriceMapper.selectPage(
bo.getSellerUid(),
bo.getStatus(),
bo.getSkup(),
bo.getStorageId(),
bo.getStart(),
bo.getRows());
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
storagePrice.forEach(sp -> {
ProductResponceBo b = new ProductResponceBo();
b.setSkup(sp.getSkup());
b.setSellerUid(sp.getSellerUid());
b.setCurrentPrice(sp.getPrice().toString());
b.setStatus(sp.getStatus());
b.setSkupCreateTime(sdf.format(sp.getCreateTime() * 1000L));
boList.add(b);
});
}
PageResponseBO<ProductResponceBo> pageBo = new PageResponseBO<>(count, boList, bo.getPage(), bo.getRows());
return new ApiResponse<>(pageBo);
}
@Override
public ApiResponse<PageResponseBO<ProductResponceBo>> cancelSaleSkup(ProductRequestBo bo) {
StoragePrice sp = storagePriceMapper.selectBySkup(bo.getSkup());
if (sp == null) {
return new ApiResponse<>(400, "SKUP不存在");
}
if (sp.getStatus() == null || sp.getStatus() != 1) {
return new ApiResponse<>(400, "SKUP不可取消");
}
int n = storagePriceMapper.cancelSaleSkup(bo.getSkup());
if (n == 1) {
storageMapper.addStorageNum(sp.getStorageId(), -1);
return new ApiResponse<>(400, "操作成功");
}
return new ApiResponse<>(400, "SKUP取消失败,状态已变更!");
}
}
... ...