Browse Source

Merge branch 'master' of http://git.ds-bay.com/project/kmall-pt-general

lsp 4 years ago
parent
commit
2667ed4096

+ 62 - 11
kmall-admin/src/main/java/com/kmall/admin/service/impl/ProductStoreRelaServiceImpl.java

@@ -851,24 +851,38 @@ public class ProductStoreRelaServiceImpl implements ProductStoreRelaService {
                     throw new RRException("商品[" + storeGoodsDto.getGoodsSn() + "]未录入系统");
                 }
                 CategoryEntity parentCategoryEntity = categoryDao.queryObjectByName(storeGoodsDto.getCategoryName(), store.getMerchSn(),0);
+                CategoryEntity categoryEntity;//二级分类
                 if (parentCategoryEntity != null) {
-                    storeRelaEntity.setCategoryId(parentCategoryEntity.getId());
-                    CategoryEntity categoryEntity = categoryDao.queryObjectByName(storeGoodsDto.getAttributeCategory(), store.getMerchSn(),parentCategoryEntity.getId());
-                    if (categoryEntity != null) {
-                        storeRelaEntity.setAttributeCategory(categoryEntity.getId());
-                    }else{
-                        throw new RRException("商品[" + storeGoodsDto.getGoodsSn() + "]的二级类别输入有误");
+                    categoryEntity = categoryDao.queryObjectByName(storeGoodsDto.getAttributeCategory(), store.getMerchSn(),parentCategoryEntity.getId());
+                    if (categoryEntity == null) {
+                        categoryEntity = initSaveCategoryEntity(storeGoodsDto.getAttributeCategory(), store.getMerchSn(), parentCategoryEntity.getId());
+                        categoryDao.save(categoryEntity);
+                        categoryEntity = categoryDao.queryObjectByName(storeGoodsDto.getAttributeCategory(), store.getMerchSn(),parentCategoryEntity.getId());
                     }
                 }else{
-                    throw new RRException("商品[" + storeGoodsDto.getGoodsSn() + "]的一级类别输入有误");
+//                    throw new RRException("商品[" + storeGoodsDto.getGoodsSn() + "]的一级类别输入有误");
+                    // 如果没有一级分类就自动创建一二级分类
+                    parentCategoryEntity = initSaveCategoryEntity(storeGoodsDto.getCategoryName(), store.getMerchSn(),0);
+                    categoryDao.save(parentCategoryEntity);
+                    // 保存后再查出来
+                    parentCategoryEntity = categoryDao.queryObjectByName(storeGoodsDto.getCategoryName(), store.getMerchSn(),0);
+                    categoryEntity = initSaveCategoryEntity(storeGoodsDto.getAttributeCategory(),store.getMerchSn(),parentCategoryEntity.getId());
+                    categoryDao.save(categoryEntity);
+                    categoryEntity = categoryDao.queryObjectByName(storeGoodsDto.getAttributeCategory(), store.getMerchSn(),parentCategoryEntity.getId());
                 }
 
+                storeRelaEntity.setCategoryId(parentCategoryEntity.getId());
+                storeRelaEntity.setAttributeCategory(categoryEntity.getId());
+
                 BrandEntity brandEntity = brandDao.queryObjectByName(storeGoodsDto.getBrandName(), store.getMerchSn(),storeRelaEntity.getAttributeCategory());
-                if (brandEntity != null) {
-                    storeRelaEntity.setBrandId(brandEntity.getId());
-                }else{
-                    throw new RRException("商品[" + storeGoodsDto.getGoodsSn() + "]的品牌输入有误");
+                if (brandEntity == null) {
+                    // throw new RRException("商品[" + storeGoodsDto.getGoodsSn() + "]的品牌输入有误");
+                    brandEntity = initSaveBrandEntity(storeGoodsDto.getBrandName(), store.getMerchSn(),storeRelaEntity.getAttributeCategory());
+                    brandDao.save(brandEntity);
+                    brandEntity = brandDao.queryObjectByName(storeGoodsDto.getBrandName(), store.getMerchSn(),storeRelaEntity.getAttributeCategory());
                 }
+
+                storeRelaEntity.setBrandId(brandEntity.getId());
                 /*FreightEntity freightEntity = freightDao.queryFreightByFreightNameAndStoreId(storeGoodsDto.getFreightName(), store.getId());
                 if (freightEntity != null) {
                     storeRelaEntity.setFreightId(freightEntity.getId());
@@ -901,5 +915,42 @@ public class ProductStoreRelaServiceImpl implements ProductStoreRelaService {
         return 1;
     }
 
+    private BrandEntity initSaveBrandEntity(String brandName, String merchSn, Integer categroyId) {
+        BrandEntity brandEntity = new BrandEntity();
+        brandEntity.setName(brandName);
+        brandEntity.setMerchSn(merchSn);
+        brandEntity.setCategoryId(categroyId);
+        brandEntity.setSimpleDesc(brandName);
+        brandEntity.setIsShow(1);
+        brandEntity.setIsNew(0);
+        // 图片随便填
+        brandEntity.setListPicUrl("http://120.76.26.84:80/group1/M00/00/58/rBJEdV-X_ReANxuzAABXBxj7KoY326.jpg");
+        brandEntity.setPicUrl("http://120.76.26.84:80/group1/M00/00/58/rBJEdV-X_ReANxuzAABXBxj7KoY326.jpg");
+        brandEntity.setAppListPicUrl("http://120.76.26.84:80/group1/M00/00/58/rBJEdV-X_ReANxuzAABXBxj7KoY326.jpg");
+        brandEntity.setNewPicUrl("http://120.76.26.84:80/group1/M00/00/58/rBJEdV-X_ReANxuzAABXBxj7KoY326.jpg");
+        return brandEntity;
+    }
+
+
+    private CategoryEntity initSaveCategoryEntity(String categoryName, String merchSn, Integer parentId){
+        CategoryEntity saveCategoryEntity = new CategoryEntity();
+        saveCategoryEntity.setName(categoryName);
+        saveCategoryEntity.setParentId(parentId);
+        saveCategoryEntity.setIsShow(1);
+        saveCategoryEntity.setFrontDesc(categoryName);
+        saveCategoryEntity.setMerchSn(merchSn);
+        // 如果是一级分类
+        if (parentId.intValue()==0){
+            saveCategoryEntity.setLevel("L1");
+        }else{
+            saveCategoryEntity.setLevel("L2");
+        }
+        saveCategoryEntity.setType(0);
+        // 给个默认图片即可
+        saveCategoryEntity.setIconUrl("http://120.76.26.84:80/group1/M00/00/54/rBJEdV9hfU2AVyZHAAAK_hSw3F0952.png");
+        saveCategoryEntity.setWapBannerUrl("http://120.76.26.84:80/group1/M00/00/54/rBJEdV9hfU2AVyZHAAAK_hSw3F0952.png");
+        return saveCategoryEntity;
+    }
+
 
 }