|
@@ -1,11 +1,22 @@
|
|
|
package com.kmall.admin.service.impl;
|
|
|
|
|
|
+import com.google.common.collect.ImmutableBiMap;
|
|
|
+import com.kmall.admin.dao.GoodsDao;
|
|
|
+import com.kmall.admin.dao.GoodsSpecificationDao;
|
|
|
+import com.kmall.admin.dao.ProductDao;
|
|
|
import com.kmall.admin.dao.ProductStoreRelaDao;
|
|
|
+import com.kmall.admin.entity.GoodsEntity;
|
|
|
+import com.kmall.admin.entity.GoodsSpecificationEntity;
|
|
|
+import com.kmall.admin.entity.ProductEntity;
|
|
|
import com.kmall.admin.entity.ProductStoreRelaEntity;
|
|
|
import com.kmall.admin.service.ProductStoreRelaService;
|
|
|
+import com.kmall.api.contants.Dict;
|
|
|
+import com.kmall.common.entity.SysUserEntity;
|
|
|
+import com.kmall.common.utils.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -20,6 +31,12 @@ import java.util.Map;
|
|
|
public class ProductStoreRelaServiceImpl implements ProductStoreRelaService {
|
|
|
@Autowired
|
|
|
private ProductStoreRelaDao productStoreRelaDao;
|
|
|
+ @Autowired
|
|
|
+ private GoodsDao goodsDao;
|
|
|
+ @Autowired
|
|
|
+ private GoodsSpecificationDao goodsSpecificationDao;
|
|
|
+ @Autowired
|
|
|
+ private ProductDao productDao;
|
|
|
|
|
|
@Override
|
|
|
public ProductStoreRelaEntity queryObject(Integer id) {
|
|
@@ -43,11 +60,86 @@ public class ProductStoreRelaServiceImpl implements ProductStoreRelaService {
|
|
|
|
|
|
@Override
|
|
|
public int save(ProductStoreRelaEntity productStoreRela) {
|
|
|
+ Map<String, Object> valideDate = MapBeanUtil.fromObject(productStoreRela);
|
|
|
+ ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
|
|
|
+ builder.put("storeId", "门店");
|
|
|
+ builder.put("goodsId", "商品");
|
|
|
+ builder.put("goodsNumber", "库存");
|
|
|
+
|
|
|
+ GoodsEntity goodsEntity = goodsDao.queryObject(productStoreRela.getGoodsId());
|
|
|
+ if (Dict.orderBizType.item_11.getItem().equals(goodsEntity.getGoodsBizType())) {
|
|
|
+ // 普通商品校验商品规格
|
|
|
+ builder.put("specification", "规格");
|
|
|
+ builder.put("retailPrice", "零售价");
|
|
|
+ }
|
|
|
+ R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
|
|
|
+ if (Integer.valueOf(r.get("code").toString()) != 0) {
|
|
|
+ throw new RRException(r.get("msg").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUserEntity user = ShiroUtils.getUserEntity();
|
|
|
+ if (Dict.orderBizType.item_11.getItem().equals(goodsEntity.getGoodsBizType())) {
|
|
|
+ // 添加商品规格
|
|
|
+ GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
|
|
|
+ goodsSpecification.setGoodsId(goodsEntity.getId());
|
|
|
+ goodsSpecification.setValue(productStoreRela.getSpecification());
|
|
|
+ goodsSpecification.setSpecificationId(1);
|
|
|
+ goodsSpecificationDao.save(goodsSpecification);
|
|
|
+
|
|
|
+ // 修改产品
|
|
|
+ ProductEntity product = productDao.queryObjectBySn(goodsEntity.getGoodsSn());
|
|
|
+ product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
|
|
|
+ product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
|
|
|
+ productDao.update(product);
|
|
|
+ } else {
|
|
|
+ productStoreRela.setRetailPrice(goodsEntity.getRetailPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ productStoreRela.setCreaterSn(user.getUserId().toString());
|
|
|
+ productStoreRela.setCreateTime(new Date());
|
|
|
+ productStoreRela.setModerSn(user.getUserId().toString());
|
|
|
+ productStoreRela.setModTime(new Date());
|
|
|
return productStoreRelaDao.save(productStoreRela);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int update(ProductStoreRelaEntity productStoreRela) {
|
|
|
+ Map<String, Object> valideDate = MapBeanUtil.fromObject(productStoreRela);
|
|
|
+ ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
|
|
|
+ builder.put("storeId", "门店");
|
|
|
+ builder.put("goodsId", "商品");
|
|
|
+ builder.put("goodsNumber", "库存");
|
|
|
+ builder.put("retailPrice", "零售价");
|
|
|
+
|
|
|
+ GoodsEntity goodsEntity = goodsDao.queryObject(productStoreRela.getGoodsId());
|
|
|
+ if (Dict.orderBizType.item_11.getItem().equals(goodsEntity.getGoodsBizType())) {
|
|
|
+ // 普通商品校验商品规格
|
|
|
+ builder.put("specification", "规格");
|
|
|
+ }
|
|
|
+ R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
|
|
|
+ if (Integer.valueOf(r.get("code").toString()) != 0) {
|
|
|
+ throw new RRException(r.get("msg").toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ SysUserEntity user = ShiroUtils.getUserEntity();
|
|
|
+ if (Dict.orderBizType.item_11.getItem().equals(goodsEntity.getGoodsBizType())) {
|
|
|
+ // 添加商品规格
|
|
|
+ GoodsSpecificationEntity goodsSpecification = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
|
|
|
+ goodsSpecification.setValue(productStoreRela.getSpecification());
|
|
|
+ goodsSpecificationDao.update(goodsSpecification);
|
|
|
+
|
|
|
+ // 修改产品
|
|
|
+ ProductEntity product = productDao.queryObjectBySn(goodsEntity.getGoodsSn());
|
|
|
+ product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
|
|
|
+ product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
|
|
|
+ productDao.update(product);
|
|
|
+ } else {
|
|
|
+ productStoreRela.setRetailPrice(goodsEntity.getRetailPrice());
|
|
|
+ }
|
|
|
+
|
|
|
+ productStoreRela.setModerSn(user.getUserId().toString());
|
|
|
+ productStoreRela.setModTime(new Date());
|
|
|
return productStoreRelaDao.update(productStoreRela);
|
|
|
}
|
|
|
|