|
@@ -5,7 +5,6 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.google.common.collect.ImmutableBiMap;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
-import com.google.gson.Gson;
|
|
|
import com.kmall.admin.dao.*;
|
|
|
import com.kmall.admin.dto.GoodsDetailsDto;
|
|
|
import com.kmall.admin.dto.GoodsDto;
|
|
@@ -27,6 +26,7 @@ import com.kmall.api.entity.exportpdf.PDFGoodsDto;
|
|
|
import com.kmall.common.constant.Dict;
|
|
|
import com.kmall.admin.fromcomm.entity.SysUserEntity;
|
|
|
import com.kmall.common.utils.*;
|
|
|
+import com.kmall.manager.manager.redis.JedisUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -903,9 +903,9 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
supplierEntity.setIsShow("0");
|
|
|
|
|
|
// TODO 这里改成批量插入 SupplierEntity
|
|
|
- insertSupplierList.add(supplierEntity);
|
|
|
+// insertSupplierList.add(supplierEntity);
|
|
|
|
|
|
-// supplierDao.save(supplierEntity);
|
|
|
+ supplierDao.save(supplierEntity);
|
|
|
// supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
|
|
|
goodsEntity.setSupplierId(supplierEntity.getId());
|
|
|
} else {
|
|
@@ -913,35 +913,17 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
}
|
|
|
}
|
|
|
//商品配置校验
|
|
|
- /*CategoryEntity categoryEntity = categoryDao.queryObjectByName(goodsDto.getCategoryName(),goodsDto.getMerchSn());
|
|
|
- if(categoryEntity==null){
|
|
|
- isFail = true;
|
|
|
- failCateGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
- }else{
|
|
|
- if(categoryEntity.getLevel().equalsIgnoreCase("L2")) {
|
|
|
- goodsEntity.setCategoryId(categoryEntity.getId());
|
|
|
- goodsEntity.setAttributeCategory(categoryEntity.getParentId());
|
|
|
- }else{
|
|
|
- isFail = true;
|
|
|
- failCateL2GoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
- }
|
|
|
- }
|
|
|
- BrandEntity brandEntity = brandDao.queryObjectByName(goodsDto.getBrandName(),goodsDto.getMerchSn());
|
|
|
- if (brandEntity == null) {
|
|
|
- isFail = true;
|
|
|
- failBrandGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
- } else {
|
|
|
- goodsEntity.setBrandId(brandEntity.getId());
|
|
|
- }
|
|
|
- //运费
|
|
|
- FreightEntity freightEntity = freightDao.queryObjectByName(goodsDto.getDefaultFreight(),goodsDto.getMerchSn());
|
|
|
- if(freightEntity==null){
|
|
|
- isFail = true;
|
|
|
- failFreightGoodsSnList.add(goodsDto.getGoodsSn());
|
|
|
- failFreightList.add(goodsDto.getDefaultFreight());
|
|
|
- }else {
|
|
|
- goodsEntity.setFreightId(freightEntity.getId());
|
|
|
- }*/
|
|
|
+ /*
|
|
|
+ 先在redis在查询该品牌是否存在,如果存在获取品牌id,如果不存在,先新增该品牌,在将品牌存入到redis中,在获取品牌id
|
|
|
+ */
|
|
|
+ // 获取品牌唯一简码
|
|
|
+ checkBrand(goodsDto, goodsEntity);
|
|
|
+
|
|
|
+
|
|
|
+ // 获取二级分类id
|
|
|
+ checkCategory(goodsDto, goodsEntity);
|
|
|
+
|
|
|
+
|
|
|
if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
|
|
|
SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
|
|
|
if (sysCusUnitCodeEntity == null) {
|
|
@@ -1025,7 +1007,6 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
mngChangeEntity.setChangeNum(Integer.parseInt(goodsDto.getGoodsNumber()));//变化数
|
|
|
mngChangeEntity.setChangeType(Dict.changeType.item_2.getItem());
|
|
|
|
|
|
- // TODO 这里改成批量插入 GoodsEntity
|
|
|
|
|
|
goodsDao.save(goodsEntity);
|
|
|
insertGoodsList.add(goodsEntity);
|
|
@@ -1083,8 +1064,8 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
|
|
|
|
|
|
// TODO 这里改成批量插入 ProductEntity
|
|
|
- insertProductList.add(product);
|
|
|
-// productDao.save(product);
|
|
|
+// insertProductList.add(product);
|
|
|
+ productDao.save(product);
|
|
|
}else{
|
|
|
product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
|
|
|
product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
|
|
@@ -1098,18 +1079,18 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
}
|
|
|
|
|
|
// 批量插入数据
|
|
|
- if(insertProductList != null && insertProductList.size() > 0) {
|
|
|
- // 长度限制,如果大于50,就分多次插入
|
|
|
- if(insertProductList.size() > 50){
|
|
|
- List<List<ProductEntity>> partition = Lists.partition(insertProductList, 50);
|
|
|
- for (List<ProductEntity> productEntities : partition) {
|
|
|
- productDao.saveBatch(productEntities);
|
|
|
- }
|
|
|
- }else{
|
|
|
- productDao.saveBatch(insertProductList);;
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+// if(insertProductList != null && insertProductList.size() > 0) {
|
|
|
+// // 长度限制,如果大于50,就分多次插入
|
|
|
+// if(insertProductList.size() > 50){
|
|
|
+// List<List<ProductEntity>> partition = Lists.partition(insertProductList, 50);
|
|
|
+// for (List<ProductEntity> productEntities : partition) {
|
|
|
+// productDao.saveBatch(productEntities);
|
|
|
+// }
|
|
|
+// }else{
|
|
|
+// productDao.saveBatch(insertProductList);;
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
// if(insertSpecificationList != null && insertSpecificationList.size() > 0) {
|
|
|
// goodsSpecificationDao.saveBatch(insertSpecificationList);
|
|
|
// }
|
|
@@ -1127,17 +1108,17 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
// if(insertGoodsList != null && insertGoodsList.size() > 0 ){
|
|
|
// goodsDao.saveBatch(insertGoodsList);
|
|
|
// }
|
|
|
- if(insertSupplierList != null && insertSupplierList.size() > 0 ){
|
|
|
- if(insertSupplierList.size() > 50){
|
|
|
- List<List<SupplierEntity>> partition = Lists.partition(insertSupplierList, 50);
|
|
|
- for (List<SupplierEntity> supplierEntities : partition) {
|
|
|
- supplierDao.saveBatch(supplierEntities);
|
|
|
- }
|
|
|
- }else{
|
|
|
- supplierDao.saveBatch(insertSupplierList);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
+// if(insertSupplierList != null && insertSupplierList.size() > 0 ){
|
|
|
+// if(insertSupplierList.size() > 50){
|
|
|
+// List<List<SupplierEntity>> partition = Lists.partition(insertSupplierList, 50);
|
|
|
+// for (List<SupplierEntity> supplierEntities : partition) {
|
|
|
+// supplierDao.saveBatch(supplierEntities);
|
|
|
+// }
|
|
|
+// }else{
|
|
|
+// supplierDao.saveBatch(insertSupplierList);
|
|
|
+//
|
|
|
+// }
|
|
|
+// }
|
|
|
// 批量更新数据
|
|
|
if(updateProductList != null && updateProductList.size() > 0 ){
|
|
|
|
|
@@ -1160,16 +1141,16 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
goodsSpecificationDao.updateBatch(updateSpecificationList);
|
|
|
}
|
|
|
}
|
|
|
- if(updateGoodsList != null && updateGoodsList.size() > 0 ){
|
|
|
- if(updateGoodsList.size() > 50){
|
|
|
- List<List<GoodsEntity>> partition = Lists.partition(updateGoodsList, 50);
|
|
|
- for (List<GoodsEntity> goodsEntities : partition) {
|
|
|
- goodsDao.updateBatch(goodsEntities);
|
|
|
- }
|
|
|
- }else{
|
|
|
- goodsDao.updateBatch(updateGoodsList);
|
|
|
- }
|
|
|
- }
|
|
|
+// if(updateGoodsList != null && updateGoodsList.size() > 0 ){
|
|
|
+// if(updateGoodsList.size() > 50){
|
|
|
+// List<List<GoodsEntity>> partition = Lists.partition(updateGoodsList, 50);
|
|
|
+// for (List<GoodsEntity> goodsEntities : partition) {
|
|
|
+// goodsDao.updateBatch(goodsEntities);
|
|
|
+// }
|
|
|
+// }else{
|
|
|
+// goodsDao.updateBatch(updateGoodsList);
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
|
|
|
|
|
@@ -1297,6 +1278,172 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+ private void checkCategory(GoodsDto goodsDto, GoodsEntity goodsEntity) {
|
|
|
+ String secondLevel = goodsDto.getSecondLevel(); // 二级分类名称
|
|
|
+ Map<String, String> categoryCache = JedisUtil.getMap(secondLevel);
|
|
|
+ if(categoryCache != null){
|
|
|
+ String categoryId = categoryCache.get("categoryId");
|
|
|
+ String level = categoryCache.get("level");
|
|
|
+ if(categoryId == null){
|
|
|
+ CategoryEntity category = categoryDao.queryByName(secondLevel);
|
|
|
+ if (category == null) {
|
|
|
+
|
|
|
+ // 将该id存入带缓存中
|
|
|
+ Map<String,String> categoryCacheData = new HashMap<>();
|
|
|
+ categoryCacheData.put("level",Dict.Level.item_L2.getItem());
|
|
|
+
|
|
|
+ // 查询数据库中是否有一级分类
|
|
|
+ String firstLevel = goodsDto.getFirstLevel();
|
|
|
+ CategoryEntity firstCategory = categoryDao.queryByName(firstLevel);
|
|
|
+ if(firstCategory == null){
|
|
|
+ // 一级分类不存在
|
|
|
+ // 新增一级分类
|
|
|
+ CategoryEntity firstCategoryEntity = initCategory(firstLevel, 0, Dict.Level.item_L1);
|
|
|
+ categoryDao.save(firstCategoryEntity);
|
|
|
+ // 新增二级分类
|
|
|
+ CategoryEntity secondCategoryEntity = initCategory(secondLevel, firstCategoryEntity.getId(), Dict.Level.item_L2);
|
|
|
+ categoryDao.save(secondCategoryEntity);
|
|
|
+ categoryId = secondCategoryEntity.getId()+"";
|
|
|
+ }else{
|
|
|
+ // 新增二级分类
|
|
|
+ CategoryEntity saveCategoryEntity = initCategory(secondLevel, firstCategory.getId(), Dict.Level.item_L2);
|
|
|
+ categoryDao.save(saveCategoryEntity);
|
|
|
+ categoryId = saveCategoryEntity.getId()+"";
|
|
|
+
|
|
|
+ }
|
|
|
+ categoryCacheData.put("categoryId",categoryId);
|
|
|
+ JedisUtil.setMap(secondLevel,categoryCacheData,0);
|
|
|
+ goodsEntity.setCategoryId(Integer.parseInt(categoryId));
|
|
|
+
|
|
|
+ }else if(category != null && Dict.Level.item_L2.getItem().equals(category.getLevel())){
|
|
|
+ // 缓存中没有,数据库中有,直接存入数据库中查询到的数据
|
|
|
+ goodsEntity.setCategoryId(category.getId());
|
|
|
+ // 将该id存入带缓存中
|
|
|
+ Map<String,String> categoryCacheData = new HashMap<>();
|
|
|
+ categoryCacheData.put("level",Dict.Level.item_L2.getItem());
|
|
|
+ categoryCacheData.put("categoryId",category.getId()+"");
|
|
|
+ JedisUtil.setMap(secondLevel,categoryCacheData,0);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("该分类不是二级分类,请检查,对应sku是:"+ goodsDto.getSku()+",分类名称为:"+ goodsDto.getSecondLevel());
|
|
|
+ }
|
|
|
+ }else if(Dict.Level.item_L2.getItem().equals(level)){
|
|
|
+ // 二级分类id在缓存中有,直接存入商品
|
|
|
+ goodsEntity.setCategoryId(Integer.parseInt(categoryId));
|
|
|
+ }else {
|
|
|
+ throw new RuntimeException("该分类不是二级分类,请检查,对应sku是:"+ goodsDto.getSku()+",分类名称为:"+ goodsDto.getSecondLevel());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ String categoryId = "";
|
|
|
+ CategoryEntity category = categoryDao.queryByName(secondLevel);
|
|
|
+ if (category == null) {
|
|
|
+ // 将该id存入带缓存中
|
|
|
+ Map<String,String> categoryCacheData = new HashMap<>();
|
|
|
+ categoryCacheData.put("level",Dict.Level.item_L2.getItem());
|
|
|
+
|
|
|
+ // 查询数据库中是否有一级分类
|
|
|
+ String firstLevel = goodsDto.getFirstLevel();
|
|
|
+ CategoryEntity firstCategory = categoryDao.queryByName(firstLevel);
|
|
|
+ if(firstCategory == null){
|
|
|
+ // 一级分类不存在
|
|
|
+ // 新增一级分类
|
|
|
+ CategoryEntity firstCategoryEntity = initCategory(firstLevel, 0, Dict.Level.item_L1);
|
|
|
+ categoryDao.save(firstCategoryEntity);
|
|
|
+ // 新增二级分类
|
|
|
+ CategoryEntity secondCategoryEntity = initCategory(secondLevel, firstCategoryEntity.getId(), Dict.Level.item_L2);
|
|
|
+ categoryDao.save(secondCategoryEntity);
|
|
|
+ categoryId = secondCategoryEntity.getId()+"";
|
|
|
+ }else{
|
|
|
+ // 新增二级分类
|
|
|
+ CategoryEntity saveCategoryEntity = initCategory(secondLevel, firstCategory.getId(), Dict.Level.item_L2);
|
|
|
+ categoryDao.save(saveCategoryEntity);
|
|
|
+ categoryId = saveCategoryEntity.getId()+"";
|
|
|
+
|
|
|
+ }
|
|
|
+ categoryCacheData.put("categoryId",categoryId);
|
|
|
+ JedisUtil.setMap(secondLevel,categoryCacheData,0);
|
|
|
+ goodsEntity.setCategoryId(Integer.parseInt(categoryId));
|
|
|
+
|
|
|
+ }else if(category != null && Dict.Level.item_L2.getItem().equals(category.getLevel())){
|
|
|
+ // 缓存中没有,数据库中有,直接存入数据库中查询到的数据
|
|
|
+ goodsEntity.setCategoryId(category.getId());
|
|
|
+ // 将该id存入带缓存中
|
|
|
+ Map<String,String> categoryCacheData = new HashMap<>();
|
|
|
+ categoryCacheData.put("level",Dict.Level.item_L2.getItem());
|
|
|
+ categoryCacheData.put("categoryId",category.getId()+"");
|
|
|
+ JedisUtil.setMap(secondLevel,categoryCacheData,0);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ throw new RuntimeException("该分类不是二级分类,请检查,对应sku是:"+ goodsDto.getSku()+",分类名称为:"+ goodsDto.getSecondLevel());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkBrand(GoodsDto goodsDto, GoodsEntity goodsEntity) {
|
|
|
+ String uniqueIdentifier = goodsDto.getUniqueIdentifier();
|
|
|
+ String brandName = goodsDto.getBrand();
|
|
|
+ Map<String, String> brandCache = JedisUtil.getMap(uniqueIdentifier);
|
|
|
+ if(brandCache != null) {
|
|
|
+ String brandId = brandCache.get("brandId");
|
|
|
+ if (brandId == null) {
|
|
|
+ Map<String, String> brandCacheData = new HashMap<>();
|
|
|
+ // 数据库里面查询
|
|
|
+ BrandEntity queryBrand = brandService.queryByUniqueIdentifier(uniqueIdentifier);
|
|
|
+ if (queryBrand == null) {
|
|
|
+ BrandEntity brandEntity = new BrandEntity();
|
|
|
+ brandEntity.setName(brandName);
|
|
|
+ brandEntity.setUniqueIdentifier(uniqueIdentifier);
|
|
|
+ brandEntity.setSimpleDesc(brandName);
|
|
|
+ brandEntity.setIsShow(1);
|
|
|
+ brandEntity.setIsNew(0);
|
|
|
+ brandService.save(brandEntity);
|
|
|
+ brandCacheData.put("brandId", brandEntity.getId() + "");
|
|
|
+ brandCacheData.put("brandName", brandName);
|
|
|
+ goodsEntity.setBrandId(brandEntity.getId());
|
|
|
+ } else {
|
|
|
+ brandCacheData.put("brandId", queryBrand.getId() + "");
|
|
|
+ brandCacheData.put("brandName", queryBrand.getName());
|
|
|
+ goodsEntity.setBrandId(queryBrand.getId());
|
|
|
+ }
|
|
|
+ JedisUtil.setMap(uniqueIdentifier, brandCacheData, 0);
|
|
|
+ } else {
|
|
|
+ goodsEntity.setBrandId(Integer.parseInt(brandId));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ Map<String, String> brandCacheData = new HashMap<>();
|
|
|
+ // 数据库里面查询
|
|
|
+ BrandEntity queryBrand = brandService.queryByUniqueIdentifier(uniqueIdentifier);
|
|
|
+ if (queryBrand == null) {
|
|
|
+ BrandEntity brandEntity = new BrandEntity();
|
|
|
+ brandEntity.setName(brandName);
|
|
|
+ brandEntity.setUniqueIdentifier(uniqueIdentifier);
|
|
|
+ brandEntity.setSimpleDesc(brandName);
|
|
|
+ brandEntity.setIsShow(1);
|
|
|
+ brandEntity.setIsNew(0);
|
|
|
+ brandService.save(brandEntity);
|
|
|
+ brandCacheData.put("brandId", brandEntity.getId() + "");
|
|
|
+ brandCacheData.put("brandName", brandName);
|
|
|
+ goodsEntity.setBrandId(brandEntity.getId());
|
|
|
+ } else {
|
|
|
+ brandCacheData.put("brandId", queryBrand.getId() + "");
|
|
|
+ brandCacheData.put("brandName", queryBrand.getName());
|
|
|
+ goodsEntity.setBrandId(queryBrand.getId());
|
|
|
+ }
|
|
|
+ JedisUtil.setMap(uniqueIdentifier, brandCacheData, 0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private CategoryEntity initCategory(String firstLevel, int parentId, Dict.Level item) {
|
|
|
+ CategoryEntity firstCategoryEntity = new CategoryEntity();
|
|
|
+ firstCategoryEntity.setName(firstLevel);
|
|
|
+ firstCategoryEntity.setParentId(parentId);
|
|
|
+ firstCategoryEntity.setIsShow(1);
|
|
|
+ firstCategoryEntity.setFrontDesc(firstLevel);
|
|
|
+ firstCategoryEntity.setType(0);
|
|
|
+ firstCategoryEntity.setLevel(item.getItem());
|
|
|
+ return firstCategoryEntity;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public int uploadExcelByCover(List<GoodsDto> goodsEntityList, int exportDataType) {
|
|
@@ -2027,7 +2174,7 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
public void syncGoodsRate() {
|
|
|
String storeId = "163"; // 市场部说所有门店价格一致,并且活动一致,可直接取其中一个门店价格进行计算税率
|
|
|
// 查询出所有商品
|
|
|
- List<GoodsEntity> allGoodsList = goodsDao.queryAllList();
|
|
|
+ List<GoodsEntity> allGoodsList = goodsDao.queryAllList(null,null);
|
|
|
for (GoodsEntity goodsEntity : allGoodsList) {
|
|
|
// 同步过海关商品编码才可以算税率
|
|
|
if ("1".equals(goodsEntity.getIsSyncHsCode())) {
|
|
@@ -2091,8 +2238,8 @@ public class GoodsServiceImpl implements GoodsService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<GoodsEntity> queryAllList() {
|
|
|
- return goodsDao.queryAllList();
|
|
|
+ public List<GoodsEntity> queryAllList(Integer page,Integer pageSize) {
|
|
|
+ return goodsDao.queryAllList(page,pageSize);
|
|
|
}
|
|
|
|
|
|
private void calculeatePromotion(SysUserEntity user, GoodsEntity goods, List<Map<String, String>> errorPriceSkuList, List<ShopErrorPriceRecordEntity> shopErrorPriceRecordEntities) {
|