package com.matrix.system.dataMove;
|
|
import com.alibaba.fastjson.JSONObject;
|
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.*;
|
|
/**
|
* @author wzy
|
* @date 2021-08-11
|
**/
|
@Service
|
public class SjfDataMoveServiceImpl {
|
|
@Autowired
|
private JdbcTemplate jdbcTemplate;
|
|
@Autowired
|
private ShopProductAttributeDao shopProductAttributeDao;
|
@Autowired
|
private ShopProductDao shopProductDao;
|
@Autowired
|
private ShopSkuDao shopSkuDao;
|
@Autowired
|
private ShopProductImgDao shopProductImgDao;
|
|
@Autowired
|
private RedisClient redisClient;
|
|
public <T> List<T> mapsToListBean(List<Map<String, Object>> maps, Class<T> t) {
|
List<T> list = new ArrayList<>();
|
for (Map<String, Object> map : maps) {
|
String s = JSONObject.toJSONString(map);
|
T object = JSONObject.parseObject(s, t);
|
list.add(object);
|
}
|
return list;
|
}
|
|
public <T> T mapToBane(Map<String, Object> map, Class<T> t) {
|
String s = JSONObject.toJSONString(map);
|
return JSONObject.parseObject(s, t);
|
}
|
|
private final Long companyId = 37L;
|
private final Long shopId = 53L;
|
|
@DS("slave")
|
public List<ShopProductAttribute> oldProductAttr() {
|
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("id");
|
|
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("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("善吉凡");
|
subAttr.setCreateTime(new Date());
|
subAttr.setUpdateTime(new Date());
|
subAttr.setShopId(shopId);
|
subAttr.setCompanyId(companyId);
|
child.add(subAttr);
|
}
|
|
ShopProductAttribute attr = new ShopProductAttribute();
|
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("善吉凡");
|
attr.setCreateTime(new Date());
|
attr.setUpdateTime(new Date());
|
attr.setShopId(shopId);
|
attr.setCompanyId(companyId);
|
list.add(attr);
|
}
|
return list;
|
}
|
|
public void productAttr(List<ShopProductAttribute> list) {
|
Map<Integer, Integer> map = new HashMap<>();
|
for (ShopProductAttribute shopProductAttribute : list) {
|
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);
|
}
|
}
|
}
|
|
}
|