From 4705f9b4084d9ccddb601569b223f0fb41778a94 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Thu, 12 Aug 2021 15:28:46 +0800
Subject: [PATCH] fix
---
zq-erp/src/main/java/com/matrix/system/dataMove/SjfDataMoveServiceImpl.java | 151 ++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 140 insertions(+), 11 deletions(-)
diff --git a/zq-erp/src/main/java/com/matrix/system/dataMove/SjfDataMoveServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/dataMove/SjfDataMoveServiceImpl.java
index ea66b66..47245c3 100644
--- a/zq-erp/src/main/java/com/matrix/system/dataMove/SjfDataMoveServiceImpl.java
+++ b/zq-erp/src/main/java/com/matrix/system/dataMove/SjfDataMoveServiceImpl.java
@@ -4,12 +4,21 @@
import com.baomidou.dynamic.datasource.annotation.DS;
import com.matrix.component.redis.RedisClient;
import com.matrix.core.tools.StringUtils;
+import com.matrix.system.shopXcx.bean.ShopProduct;
import com.matrix.system.shopXcx.bean.ShopProductAttribute;
+import com.matrix.system.shopXcx.bean.ShopProductImg;
+import com.matrix.system.shopXcx.bean.ShopSku;
import com.matrix.system.shopXcx.dao.ShopProductAttributeDao;
+import com.matrix.system.shopXcx.dao.ShopProductDao;
+import com.matrix.system.shopXcx.dao.ShopProductImgDao;
+import com.matrix.system.shopXcx.dao.ShopSkuDao;
+import org.apache.commons.lang3.StringEscapeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import java.math.BigDecimal;
import java.util.*;
/**
@@ -24,6 +33,12 @@
@Autowired
private ShopProductAttributeDao shopProductAttributeDao;
+ @Autowired
+ private ShopProductDao shopProductDao;
+ @Autowired
+ private ShopSkuDao shopSkuDao;
+ @Autowired
+ private ShopProductImgDao shopProductImgDao;
@Autowired
private RedisClient redisClient;
@@ -48,21 +63,23 @@
@DS("slave")
public List<ShopProductAttribute> oldProductAttr() {
- List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from cere_product_classify where classify_pid=0");
+ List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from eb_store_category where is_show=1 and pid=0");
List<ShopProductAttribute> list = new ArrayList<>();
for (Map<String, Object> map : maps) {
- Object classifyId = map.get("classify_id");
+ Object classifyId = map.get("id");
- List<Map<String, Object>> subMaps = jdbcTemplate.queryForList("select * from cere_product_classify where classify_pid=" + classifyId.toString());
+ List<Map<String, Object>> subMaps = jdbcTemplate.queryForList("select * from eb_store_category where pid=" + classifyId.toString());
+ List<ShopProductAttribute> child = new ArrayList<>();
for (Map<String, Object> subMap : subMaps) {
ShopProductAttribute subAttr = new ShopProductAttribute();
- subAttr.setAttrId((int) Long.parseLong(subMap.get("classify_id").toString()));
- subAttr.setParentId(Integer.parseInt(subMap.get("classify_pid").toString()));
- String subName = subMap.get("classify_name").toString();
+ subAttr.setAttrId((int) Long.parseLong(subMap.get("id").toString()));
+ subAttr.setParentId(Integer.parseInt(subMap.get("pid").toString()));
+ String subName = subMap.get("cate_name").toString();
subAttr.setAttrName(subName);
subAttr.setAttrCode(StringUtils.toHanyuPinyin(subName));
+ subAttr.setAttrUrl(map.get("pic").toString());
subAttr.setCreateBy("善吉凡");
subAttr.setUpdateBy("善吉凡");
@@ -70,15 +87,17 @@
subAttr.setUpdateTime(new Date());
subAttr.setShopId(shopId);
subAttr.setCompanyId(companyId);
- list.add(subAttr);
+ child.add(subAttr);
}
ShopProductAttribute attr = new ShopProductAttribute();
- attr.setAttrId((int) Long.parseLong(map.get("classify_id").toString()));
- attr.setParentId(Integer.parseInt(map.get("classify_pid").toString()));
- String name = map.get("classify_name").toString();
+ attr.setAttrId((int) Long.parseLong(map.get("id").toString()));
+ attr.setParentId(198);
+ attr.setAttrUrl(map.get("pic").toString());
+ String name = map.get("cate_name").toString();
attr.setAttrName(name);
attr.setAttrCode(StringUtils.toHanyuPinyin(name));
+ attr.setChild(child);
attr.setCreateBy("善吉凡");
attr.setUpdateBy("善吉凡");
@@ -87,7 +106,6 @@
attr.setShopId(shopId);
attr.setCompanyId(companyId);
list.add(attr);
-
}
return list;
}
@@ -98,10 +116,121 @@
Integer oldId = shopProductAttribute.getAttrId();
shopProductAttribute.setAttrId(null);
shopProductAttributeDao.insert(shopProductAttribute);
+
+ for (ShopProductAttribute productAttribute : shopProductAttribute.getChild()) {
+ Integer oldChildId = productAttribute.getAttrId();
+ productAttribute.setAttrId(null);
+ productAttribute.setParentId(shopProductAttribute.getAttrId());
+ shopProductAttributeDao.insert(productAttribute);
+ map.put(oldChildId, productAttribute.getAttrId());
+ }
map.put(oldId, shopProductAttribute.getAttrId());
}
redisClient.saveMapValue("attrIds", map);
}
+ @DS("slave")
+ public List<ShopProduct> oldProduct() {
+ List<Map<String, Object>> products = jdbcTemplate.queryForList("select * from eb_store_product where is_show=1 and is_del=0");
+
+ List<ShopProduct> result = new ArrayList<>();
+ for (Map<String, Object> product : products) {
+ ShopProduct shopProduct = new ShopProduct();
+ shopProduct.setCategoryId(Integer.parseInt(product.get("cate_id").toString()));
+ shopProduct.setTitle(product.get("store_name").toString());
+ shopProduct.setBriefIntroduction(product.get("store_info").toString());
+ shopProduct.setImgMobile(product.get("image").toString());
+ shopProduct.setPrice(Double.parseDouble(product.get("price").toString()));
+ shopProduct.setMarkedPrice(Double.parseDouble(product.get("ot_price").toString()));
+ shopProduct.setRsVolume(Integer.parseInt(product.get("sales").toString()));
+ shopProduct.setDsVolume(Integer.parseInt(product.get("ficti").toString()));
+
+ String imagesStr = product.get("slider_image").toString();
+ List<String> images = JSONObject.parseArray(imagesStr, String.class);
+ int i = 1;
+ List<ShopProductImg> imgs = new ArrayList<>();
+ for (String image : images) {
+ ShopProductImg shopProductImg = new ShopProductImg();
+ shopProductImg.setImgPath(image);
+ shopProductImg.setSort(i);
+ shopProductImg.setCreateBy("善吉凡");
+ shopProductImg.setUpdateBy("善吉凡");
+ shopProductImg.setCreateTime(new Date());
+ shopProductImg.setUpdateTime(new Date());
+ i++;
+
+ imgs.add(shopProductImg);
+ }
+ shopProduct.setProductImgs(imgs);
+
+ // 商品属性 即sku
+ Map<String, Object> attrValue = jdbcTemplate.queryForMap("select * from eb_store_product_attr_value where product_id=" + product.get("id"));
+ ShopSku shopSku = new ShopSku();
+ shopSku.setName(product.get("store_name").toString());
+ shopSku.setStock(Integer.parseInt(attrValue.get("stock").toString()));
+ shopSku.setImgPath(attrValue.get("image").toString());
+ shopSku.setPrice(new BigDecimal(attrValue.get("price").toString()));
+ shopSku.setCreateBy("善吉凡");
+ shopSku.setUpdateBy("善吉凡");
+ shopSku.setCreateTime(new Date());
+ shopSku.setUpdateTime(new Date());
+ shopSku.setScore(0);
+ shopSku.setSort(0);
+ shopSku.setSealCount(Integer.parseInt(product.get("ficti").toString()));
+ List<ShopSku> skus = new ArrayList<>();
+ skus.add(shopSku);
+ shopProduct.setSkus(skus);
+
+ Map<String, Object> desc = jdbcTemplate.queryForMap("select * from eb_store_product_description where product_id=" + product.get("id"));
+ shopProduct.setMobileDetails(desc.get("description").toString());
+
+
+ shopProduct.setDelFlag(2);
+ shopProduct.setShopIds(shopId.toString());
+ shopProduct.setCompanyId(companyId);
+ shopProduct.setAbleSales(1);
+ shopProduct.setAbleScorePay(2);
+ shopProduct.setStatus(1);
+ shopProduct.setCreateBy("善吉凡");
+ shopProduct.setUpdateBy("善吉凡");
+ shopProduct.setCreateTime(new Date());
+ shopProduct.setUpdateTime(new Date());
+ result.add(shopProduct);
+ }
+ return result;
+ }
+
+ @Transactional
+ public void newShopProduct(List<ShopProduct> list) {
+ String sysUsersIds = redisClient.getCachedValue("attrIds");
+ Map attrIds = JSONObject.parseObject(sysUsersIds, Map.class);
+
+
+ for (ShopProduct shopProduct : list) {
+ Object o = attrIds.get(shopProduct.getCategoryId().toString());
+ shopProduct.setCategoryId(Integer.parseInt(o.toString()));
+
+ shopProduct.setAttrValues("");
+ shopProduct.setScoreCategoryId(202L);
+ shopProduct.setId(null);
+ String s = StringEscapeUtils.unescapeHtml4(shopProduct.getMobileDetails());
+ shopProduct.setMobileDetails(s);
+
+ shopProductDao.insert(shopProduct);
+
+ for (ShopProductImg productImg : shopProduct.getProductImgs()) {
+ productImg.setPId(shopProduct.getId());
+
+ shopProductImgDao.insert(productImg);
+ }
+
+ for (ShopSku skus : shopProduct.getSkus()) {
+ skus.setPId(shopProduct.getId());
+
+ shopSkuDao.insert(skus);
+ }
+ }
+ }
+
}
--
Gitblit v1.9.1