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 +++++++++++++++++++++++++++++++++++--
 zq-erp/src/main/resources/config/application.yml                            |    6 
 zq-erp/src/main/java/com/matrix/system/shopXcx/bean/ShopProduct.java        |   29 +++++++
 zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopProductDao.xml         |   10 ++
 zq-erp/src/test/java/com/matrix/SjfDataMoveTest.java                        |    5 +
 5 files changed, 185 insertions(+), 16 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);
+            }
+        }
+    }
+
 }
diff --git a/zq-erp/src/main/java/com/matrix/system/shopXcx/bean/ShopProduct.java b/zq-erp/src/main/java/com/matrix/system/shopXcx/bean/ShopProduct.java
index ca48c7e..d52dd6c 100644
--- a/zq-erp/src/main/java/com/matrix/system/shopXcx/bean/ShopProduct.java
+++ b/zq-erp/src/main/java/com/matrix/system/shopXcx/bean/ShopProduct.java
@@ -244,7 +244,36 @@
 
 	private Long companyId;
 
+	private Long scoreCategoryId;
 
+	private Integer ableSales;
+
+	private Integer ableScorePay;
+
+
+	public Long getScoreCategoryId() {
+		return scoreCategoryId;
+	}
+
+	public void setScoreCategoryId(Long scoreCategoryId) {
+		this.scoreCategoryId = scoreCategoryId;
+	}
+
+	public Integer getAbleSales() {
+		return ableSales;
+	}
+
+	public void setAbleSales(Integer ableSales) {
+		this.ableSales = ableSales;
+	}
+
+	public Integer getAbleScorePay() {
+		return ableScorePay;
+	}
+
+	public void setAbleScorePay(Integer ableScorePay) {
+		this.ableScorePay = ableScorePay;
+	}
 
 	public Long getCompanyId() {
 		return companyId;
diff --git a/zq-erp/src/main/resources/config/application.yml b/zq-erp/src/main/resources/config/application.yml
index 40c46a7..24dd0a1 100644
--- a/zq-erp/src/main/resources/config/application.yml
+++ b/zq-erp/src/main/resources/config/application.yml
@@ -26,9 +26,9 @@
           password: xc_shop123!@#
           driver-class-name: com.mysql.jdbc.Driver
         slave:
-          url: jdbc:mysql://159.75.200.233:3306/cereshop?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
-          username: shanjifan
-          password: Shanjf123!@#
+          url: jdbc:mysql://159.75.200.233:3306/crmebv3?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&allowMultiQueries=true&transformedBitIsBoolean=true&serverTimezone=GMT%2B8
+          username: root
+          password: Shanjifan123!@#
           driver-class-name: com.mysql.jdbc.Driver
       druid:
         filters: stat,slf4j
diff --git a/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopProductDao.xml b/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopProductDao.xml
index 2c2cf8c..3af0e60 100644
--- a/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopProductDao.xml
+++ b/zq-erp/src/main/resources/mybatis/mapper/xcxShop/ShopProductDao.xml
@@ -113,7 +113,10 @@
 			is_service,
 			service_time,
 			shop_ids,
-			company_id
+			company_id,
+            score_category_id,
+            able_sales,
+            able_score_pay
 	</sql>
 
     <!-- 属性sql -->
@@ -148,7 +151,10 @@
 			#{item.isService},
 			#{item.serviceTime},
 			#{item.shopIds},
-			#{item.companyId}
+			#{item.companyId},
+            #{item.scoreCategoryId},
+            #{item.ableSales},
+            #{item.ableScorePay}
 	</sql>
     <!-- where sql -->
     <sql id="where_sql">
diff --git a/zq-erp/src/test/java/com/matrix/SjfDataMoveTest.java b/zq-erp/src/test/java/com/matrix/SjfDataMoveTest.java
index a3c5ed7..9be6464 100644
--- a/zq-erp/src/test/java/com/matrix/SjfDataMoveTest.java
+++ b/zq-erp/src/test/java/com/matrix/SjfDataMoveTest.java
@@ -20,4 +20,9 @@
     public void productAttrTest() {
         sjfDataMoveService.productAttr(sjfDataMoveService.oldProductAttr());
     }
+
+    @Test
+    public void productTest() {
+        sjfDataMoveService.newShopProduct(sjfDataMoveService.oldProduct());
+    }
 }

--
Gitblit v1.9.1