Helius
2021-08-11 ddb90cc393ab5b80ed58c99a16a78528588dd73c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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);
    }
 
}