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.ShopProductAttribute;
|
import com.matrix.system.shopXcx.dao.ShopProductAttributeDao;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.stereotype.Service;
|
|
import java.util.*;
|
|
/**
|
* @author wzy
|
* @date 2021-08-11
|
**/
|
@Service
|
public class SjfDataMoveServiceImpl {
|
|
@Autowired
|
private JdbcTemplate jdbcTemplate;
|
|
@Autowired
|
private ShopProductAttributeDao shopProductAttributeDao;
|
|
@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 cere_product_classify where classify_pid=0");
|
|
List<ShopProductAttribute> list = new ArrayList<>();
|
for (Map<String, Object> map : maps) {
|
Object classifyId = map.get("classify_id");
|
|
List<Map<String, Object>> subMaps = jdbcTemplate.queryForList("select * from cere_product_classify where classify_pid=" + classifyId.toString());
|
|
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.setAttrName(subName);
|
subAttr.setAttrCode(StringUtils.toHanyuPinyin(subName));
|
|
subAttr.setCreateBy("善吉凡");
|
subAttr.setUpdateBy("善吉凡");
|
subAttr.setCreateTime(new Date());
|
subAttr.setUpdateTime(new Date());
|
subAttr.setShopId(shopId);
|
subAttr.setCompanyId(companyId);
|
list.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.setAttrName(name);
|
attr.setAttrCode(StringUtils.toHanyuPinyin(name));
|
|
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);
|
map.put(oldId, shopProductAttribute.getAttrId());
|
}
|
|
redisClient.saveMapValue("attrIds", map);
|
}
|
|
}
|