Helius
2021-03-23 0e0c0cc432c12b57600d57af3ff58cb6bf61611f
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
package com.matrix.system.dataMove;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
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.common.bean.SysUsers;
import com.matrix.system.common.constance.AppConstance;
import com.matrix.system.common.dao.SysUsersDao;
import com.matrix.system.common.tools.PasswordUtil;
import com.matrix.system.hive.bean.*;
import com.matrix.system.hive.dao.*;
import com.matrix.system.hive.service.SysVipInfoService;
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.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.*;
 
/**
 * @author wzy
 * @date 2021-03-18
 **/
@Service
public class DateMoveServiceImpl {
 
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private SysShopInfoDao sysShopInfoDao;
    @Autowired
    private SysUsersDao sysUsersDao;
    @Autowired
    private SysVipLevelDao sysVipLevelDao;
    @Autowired
    private SysVipInfoDao sysVipInfoDao;
    @Autowired
    private SysVipInfoService sysVipInfoService;
    @Autowired
    private SysSupplierTypeDao sysSupplierTypeDao;
    @Autowired
    private SysSupplierInfoDao sysSupplierInfoDao;
    @Autowired
    private ShoppingGoodsCategoryDao shoppingGoodsCategoryDao;
    @Autowired
    private SysGoodsTypeDao sysGoodsTypeDao;
    @Autowired
    private ShoppingGoodsDao shoppingGoodsDao;
    @Autowired
    private ShoppingGoodsAssembleDao shoppingGoodsAssembleDao;
 
    @Autowired
    private RedisClient redisClient;
 
    private Long companyId = 35L;
    private Long shopId = 38L;
 
    public List<Map<String, Object>> dataMove() {
        return jdbcTemplate.queryForList("select * from sys_vip_info limit 10");
    }
 
    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);
    }
 
    /**
     * 旧系统商店数据
     *
     * @return
     */
    @DS("slave")
    public List<SysShopInfo> oldShopInfo() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_shop_info");
 
        List<SysShopInfo> shopInfos = new ArrayList<>();
        for (Map<String, Object> map : maps) {
            String s = JSONObject.toJSONString(map);
            SysShopInfo sysShopInfo = JSONObject.parseObject(s, SysShopInfo.class);
            shopInfos.add(sysShopInfo);
        }
 
        return shopInfos;
    }
 
    public void toNewShopInfo(List<SysShopInfo>  shopInfos) {
        if (CollUtil.isNotEmpty(shopInfos)) {
            Map<Long, Long> oldAndNewId = new HashMap<>();
            for (SysShopInfo shopInfo : shopInfos) {
                if (shopInfo.getShopName().equals("总部")) {
                    shopInfo.setShopType(1);
                    shopInfo.setIsOpenNet(2);
                } else {
                    shopInfo.setShopType(2);
                    shopInfo.setIsOpenNet(1);
                }
                shopInfo.setShopShortName(shopInfo.getShopName());
                shopInfo.setCompanyId(companyId);
 
                SysShopInfo query = new SysShopInfo();
                query.setShopNo(shopInfo.getShopNo());
                Long oldId = shopInfo.getId();
                shopInfo.setId(null);
                // TODO 若迁往正式环境,这里需要变动
                if (!shopInfo.getShopName().contains("美度") && !shopInfo.getShopName().contains("总店")) {
                    sysShopInfoDao.insert(shopInfo);
                    oldAndNewId.put(oldId, shopInfo.getId());
                } else {
                    SysShopInfo sysShopInfo = sysShopInfoDao.selectByShopName(shopInfo.getShopName());
                    oldAndNewId.put(oldId, sysShopInfo.getId());
                }
            }
            redisClient.saveMapValue("shopId", oldAndNewId);
        }
 
    }
 
    @DS("slave")
    public List<SysUsers> oldSysUsers() throws UnsupportedEncodingException, NoSuchAlgorithmException {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from users");
 
        List<SysUsers> list = new ArrayList<>();
 
        String shopIds = redisClient.getCachedValue("shopId");
        Map shopMap = JSONObject.parseObject(shopIds, Map.class);
        for (Map<String, Object> map : maps) {
            SysUsers sysUsers = new SysUsers();
            sysUsers.setSuAccount((String) map.get("account"));
            sysUsers.setSuId((Long) map.get("id"));
            sysUsers.setSuName((String) map.get("name"));
            sysUsers.setSuTel((String) map.get("tel"));
            sysUsers.setSuPhoto((String) map.get("photo"));
            sysUsers.setSuEmail((String) map.get("email"));
            sysUsers.setSuUserType((String) map.get("user_type"));
            sysUsers.setSuAccountStatus((String) map.get("account_status"));
            sysUsers.setSuValid("Y");
            sysUsers.setCompanyId(companyId);
            Long aaa = (Long) map.get("shop_id");
            System.out.println(aaa);
            if (aaa != null) {
                Integer shopId = (Integer) shopMap.get(aaa.toString());
                if (shopId != null) {
                    sysUsers.setShopId(Long.parseLong(shopId.toString()));
                }
            }
            sysUsers.setSuRegisterTime((Date) map.get("register_time"));
            sysUsers.setCreateBy(AppConstance.SYSTEM_USER);
            sysUsers.setUpdateBy(AppConstance.SYSTEM_USER);
            sysUsers.setSuPassword(PasswordUtil.getEncrypUserPwd(sysUsers));
            list.add(sysUsers);
        }
        return list;
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void newSysUsers(List<SysUsers> list) {
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, Long> sysUsersOldAndNew = new HashMap<>();
            for (SysUsers sysUsers : list) {
                Long oldId = sysUsers.getSuId();
                sysUsers.setSuId(null);
                sysUsersDao.insert(sysUsers);
                sysUsersOldAndNew.put(oldId, sysUsers.getSuId());
            }
 
            redisClient.saveMapValue("sys_users", sysUsersOldAndNew);
        }
    }
 
    @DS("slave")
    public List<SysVipLevel> vipLevelOld() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_vip_level");
        return mapsToListBean(maps, SysVipLevel.class);
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void vipLevelNew(List<SysVipLevel> list) {
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, Long> ids = new HashMap<>();
            for (SysVipLevel sysVipLevel : list) {
                Long oldId = sysVipLevel.getId();
                sysVipLevel.setId(null);
                sysVipLevel.setCompanyId(companyId);
                sysVipLevel.setShopId(38L);
                sysVipLevelDao.insert(sysVipLevel);
                ids.put(oldId, sysVipLevel.getId());
            }
 
            redisClient.saveMapValue("vip_level", ids);
        }
    }
 
    @DS("slave")
    public List<SysVipInfo> vipInfoOld() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_vip_info");
        return mapsToListBean(maps, SysVipInfo.class);
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void vipInfoNew(List<SysVipInfo> list) {
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, Long> vipInfoIds = new HashMap<>();
            String shopIds = redisClient.getCachedValue("shopId");
            Map shopMap = JSONObject.parseObject(shopIds, Map.class);
 
            String sysUsersIds = redisClient.getCachedValue("sys_users");
            Map sysUsersMap = JSONObject.parseObject(sysUsersIds, Map.class);
 
            String vipLevelIds = redisClient.getCachedValue("vip_level");
            Map vipLevelIdsMap = JSONObject.parseObject(vipLevelIds, Map.class);
 
            for (SysVipInfo sysVipInfo : list) {
                Long shopId = sysVipInfo.getShopId();
                if (shopId != null) {
                    Object newId = shopMap.get(shopId.toString());
                    if (newId != null) {
                        sysVipInfo.setShopId(Long.parseLong(newId.toString()));
                    }
                }
 
                Long staffId = sysVipInfo.getStaffId();
                if (staffId != null) {
                    Object o = sysUsersMap.get(staffId.toString());
                    if (o != null) {
                        sysVipInfo.setStaffId(Long.parseLong(o.toString()));
                    }
                }
 
                Long levelId = sysVipInfo.getLevelId();
                if (levelId != null) {
                    Object o = vipLevelIdsMap.get(levelId.toString());
                    if (o != null) {
                        sysVipInfo.setLevelId(Long.parseLong(o.toString()));
                    }
                }
                sysVipInfo.setCompanyId(companyId);
                Long oldId = sysVipInfo.getId();
                sysVipInfo.setId(null);
                if (StrUtil.isNotBlank(sysVipInfo.getVipName())) {
                    sysVipInfo.setZjm(StringUtils.toHanyuPinyin(sysVipInfo.getVipName()) + "," + StringUtils.toHeadWordHanyuPinyin(sysVipInfo.getVipName()));
                }
                sysVipInfoDao.insert(sysVipInfo);
                vipInfoIds.put(oldId, sysVipInfo.getId());
                sysVipInfoService.addVipDefaultCard(sysVipInfo.getId());
            }
        }
    }
 
 
    @DS("slave")
    public List<SysSupplierType> supplierTypeOld() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_supplier_type");
        return mapsToListBean(maps, SysSupplierType.class);
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void supplierNew(List<SysSupplierType> list) {
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, Long> maps = new HashMap<>();
            for (SysSupplierType sysSupplierType : list) {
                sysSupplierType.setShopId(shopId);
                sysSupplierType.setCompanyId(companyId);
                Long oldId = sysSupplierType.getId();
                sysSupplierType.setId(null);
                sysSupplierTypeDao.insert(sysSupplierType);
                maps.put(oldId, sysSupplierType.getId());
            }
 
            redisClient.saveMapValue("supplier_type", maps);
        }
    }
 
    @DS("slave")
    public List<SysSupplierInfo> supplierInfoOld() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_supplier_info");
        return mapsToListBean(maps, SysSupplierInfo.class);
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void supplierInfoNew(List<SysSupplierInfo> list) {
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, Long> maps = new HashMap<>();
 
            String supplierTypeIds = redisClient.getCachedValue("supplier_type");
            Map supplierTypeMap = JSONObject.parseObject(supplierTypeIds, Map.class);
            for (SysSupplierInfo sysSupplierInfo : list) {
                sysSupplierInfo.setShopId(shopId);
                sysSupplierInfo.setCompanyId(companyId);
 
                Object o = supplierTypeMap.get(sysSupplierInfo.getSupplType().toString());
                if (o != null) {
                    sysSupplierInfo.setSupplType(Long.parseLong(o.toString()));
                }
                Long oldId = sysSupplierInfo.getId();
                sysSupplierInfo.setId(null);
                sysSupplierInfo.setSupplNo("MD" + sysSupplierInfo.getSupplNo());
                sysSupplierInfoDao.insert(sysSupplierInfo);
                maps.put(oldId, sysSupplierInfo.getId());
            }
 
            redisClient.saveMapValue("supplier_info", maps);
        }
    }
 
 
    @DS("slave")
    public List<ShoppingGoodsCategory> goodsCategoryOld() {
        String sql = "select * from shopping_goods_category";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);
        return mapsToListBean(maps, ShoppingGoodsCategory.class);
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void goodsCategoryNew(List<ShoppingGoodsCategory> list) {
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, Long> map = new HashMap<>();
            for (ShoppingGoodsCategory shoppingGoodsCategory : list) {
                shoppingGoodsCategory.setShopId(shopId);
                shoppingGoodsCategory.setCompanyId(companyId);
                Long oldId = shoppingGoodsCategory.getId();
                shoppingGoodsCategory.setId(null);
                shoppingGoodsCategoryDao.insert(shoppingGoodsCategory);
                map.put(oldId, shoppingGoodsCategory.getId());
            }
 
            redisClient.saveMapValue("goods_category", map);
        }
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void goodsCategoryParentIdUpdate() {
        String goodsCategoryIds = redisClient.getCachedValue("goods_category");
        Map<String, Integer> maps = JSONObject.parseObject(goodsCategoryIds, HashMap.class);
 
        for (Map.Entry<String, Integer> entry : maps.entrySet()) {
            String sql = "update shopping_goods_category set parent_id=" + entry.getValue().toString() + " where parent_id="+ entry.getKey() +" and company_id=35";
            jdbcTemplate.update(sql);
        }
    }
 
    @DS("slave")
    public List<SysGoodsType> goodsTypeOld() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_goods_type");
        return mapsToListBean(maps, SysGoodsType.class);
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void goodsTypeNew(List<SysGoodsType> goodsTypes) {
        if (CollUtil.isNotEmpty(goodsTypes)) {
            Map<Long, Long> map = new HashMap<>();
            for (SysGoodsType goodsType : goodsTypes) {
                goodsType.setCompanyId(companyId);
                Long oldID = goodsType.getId();
                goodsType.setId(null);
                sysGoodsTypeDao.insert(goodsType);
                map.put(oldID, goodsType.getId());
            }
 
            redisClient.saveMapValue("goods_type", map);
        }
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void updateGoodsTypeParentId() {
        String goodsTypes = redisClient.getCachedValue("goods_type");
        Map<String, Integer> maps = JSONObject.parseObject(goodsTypes, HashMap.class);
        for (Map.Entry<String, Integer> entry : maps.entrySet()) {
            String sql = "update sys_goods_type set PARENT_ID="+ entry.getValue() +" where company_id=35 and PARENT_ID="+entry.getKey();
            jdbcTemplate.update(sql);
        }
    }
 
 
    /**
     * 家具产品
     * @param goodType
     * @return
     */
    @DS("slave")
    public List<ShoppingGoods> shoppingGoodsOld(String goodType) {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from shopping_goods where good_type='"+goodType+"'");
        List<ShoppingGoods> shoppingGoods = mapsToListBean(maps, ShoppingGoods.class);
 
        Map<String, Integer> goodsTypeIds = getRedisIds("goods_type");
        Map<String, Integer> supplierInfoIds = getRedisIds("supplier_info");
        for (ShoppingGoods shoppingGood : shoppingGoods) {
            List<Map<String, Object>> assembleList = jdbcTemplate.queryForList("select * from shopping_goods_assemble where shopping_goods_id=" + shoppingGood.getId());
            if (CollUtil.isNotEmpty(assembleList)) {
                String goodsName = shoppingGood.getName();
;
                for (Map<String, Object> assemble : assembleList) {
                    shoppingGood.setPrice((Double) assemble.get("price"));
                    Long goodsId = (Long) assemble.get("assemble_sku_id");
                    if (goodsId == null) {
                        continue;
                    }
                    Map<String, Object> sku = jdbcTemplate.queryForMap("select * from sku where id=" + goodsId);
                    Map<String, Object> sysGoods = jdbcTemplate.queryForMap("select * from sys_goods where id=" + sku.get("goods_id"));
 
                    shoppingGood.setGoodsNo((String) sysGoods.get("goods_no"));
                    shoppingGood.setCode((String) sysGoods.get("goods_no"));
                    shoppingGood.setName(goodsName+ "->" + sysGoods.get("name"));
                    shoppingGood.setUnit((String) sysGoods.get("unit"));
                    shoppingGood.setMeasure((String) sysGoods.get("measure"));
                    shoppingGood.setAlarmNum((Integer) sku.get("alarm_num"));
                    shoppingGood.setHeadquarters(1);
                    shoppingGood.setIsDel(1);
                    shoppingGood.setZjm(StringUtils.toHanyuPinyin(shoppingGood.getName()) + "," + StringUtils.toHeadWordHanyuPinyin(shoppingGood.getName()));
 
                    shoppingGood.setWeiDescription("数据迁移");
                    Integer goodsSortId = goodsTypeIds.get(sysGoods.get("goods_sort_id").toString());
                    shoppingGood.setGoodsSortId(Long.parseLong(goodsSortId.toString()));
 
                    Integer supplierId = supplierInfoIds.get(sysGoods.get("supplier_id").toString());
                    if (supplierId != null) {
                        shoppingGood.setSupplierId(Long.parseLong(supplierId.toString()));
                    }
 
                    // 因为旧系统 sys_order_item 表中,关联商品与sku的id相关
                    shoppingGood.setId(goodsId);
                }
            } else {
                System.out.println("这是ID啊:"+ shoppingGood.getId());
            }
        }
        return shoppingGoods;
    }
 
    @DS("slave")
    public List<ShoppingGoods> shoppingGoodsProjectOld() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from shopping_goods where good_type='项目'");
        List<ShoppingGoods> shoppingGoods = mapsToListBean(maps, ShoppingGoods.class);
 
        for (ShoppingGoods shoppingGood : shoppingGoods) {
            Map<String, Object> goodsAssemble = jdbcTemplate.queryForMap("select * from shopping_goods_assemble where shopping_goods_id=" + shoppingGood.getId());
            Map<String, Object> projInfo = jdbcTemplate.queryForMap("select * from sys_proj_info where id=" + goodsAssemble.get("assemble_proj_id"));
 
            shoppingGood.setTimeLength((Integer) projInfo.get("time_length"));
            shoppingGood.setCode((String) projInfo.get("proj_no"));
            shoppingGood.setCompanyId(companyId);
            shoppingGood.setHeadquarters(1);
            shoppingGood.setIsDel(1);
            shoppingGood.setZjm(StringUtils.toHanyuPinyin(shoppingGood.getName()) + "," + StringUtils.toHeadWordHanyuPinyin(shoppingGood.getName()));
 
            shoppingGood.setWeiDescription("数据迁移");
 
            shoppingGood.setId((Long) goodsAssemble.get("assemble_proj_id"));
        }
        return shoppingGoods;
    }
 
    @DS("slave")
    public List<ShoppingGoods> shoppingGoodsTcList() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from shopping_goods where good_type='套餐'");
        List<ShoppingGoods> shoppingGoods = mapsToListBean(maps, ShoppingGoods.class);
 
        Map<String, Integer> goodsSku = getRedisIds("shopping_goods_sku");
        Map<String, Integer> goodProj = getRedisIds("shopping_goods_proj");
        Map<String, Integer> goodsTypeIds = getRedisIds("goods_type");
        Map<String, Integer> supplierInfoIds = getRedisIds("supplier_info");
 
        List<Long> projExist = new ArrayList<>();
        List<Long> skuExist = new ArrayList<>();
        for (ShoppingGoods shoppingGood : shoppingGoods) {
            List<Map<String, Object>> assembles = jdbcTemplate.queryForList("select * from shopping_goods_assemble where shopping_goods_id=" + shoppingGood.getId());
 
            shoppingGood.setCompanyId(companyId);
            shoppingGood.setHeadquarters(1);
            shoppingGood.setIsDel(1);
            shoppingGood.setZjm(StringUtils.toHanyuPinyin(shoppingGood.getName()) + "," + StringUtils.toHeadWordHanyuPinyin(shoppingGood.getName()));
 
            shoppingGood.setWeiDescription("数据迁移-tc");
 
            List<ShoppingGoodsAssemble> assembleList = mapsToListBean(assembles, ShoppingGoodsAssemble.class);
 
            for (ShoppingGoodsAssemble assembleGood : assembleList) {
                if(assembleGood.getAssembleSkuId() != null) {
                    Integer skuId = goodsSku.get(assembleGood.getAssembleSkuId().toString());
//                    assembleGood.setAssembleSkuId(null);
 
                    if (skuId == null && !skuExist.contains(assembleGood.getAssembleSkuId())) {
                        Map<String, Object> goodsMap = jdbcTemplate.queryForMap("select * from shopping_goods where id=" + assembleGood.getShoppingGoodsId());
                        ShoppingGoods goods = mapToBane(goodsMap, ShoppingGoods.class);
 
                        Map<String, Object> sku = jdbcTemplate.queryForMap("select * from sku where id=" + assembleGood.getAssembleSkuId());
                        Map<String, Object> sysGoods = jdbcTemplate.queryForMap("select * from sys_goods where id=" + sku.get("goods_id"));
 
                        goods.setGoodsNo((String) sysGoods.get("goods_no"));
                        goods.setCode((String) sysGoods.get("goods_no"));
                        goods.setName(goods.getName()+ "->" + sysGoods.get("name"));
                        goods.setUnit((String) sysGoods.get("unit"));
                        goods.setMeasure((String) sysGoods.get("measure"));
                        goods.setAlarmNum((Integer) sku.get("alarm_num"));
                        goods.setHeadquarters(1);
                        goods.setIsDel(1);
                        goods.setGoodType("家居产品");
                        goods.setZjm(StringUtils.toHanyuPinyin(shoppingGood.getName()) + "," + StringUtils.toHeadWordHanyuPinyin(shoppingGood.getName()));
 
                        goods.setWeiDescription("数据迁移-tc");
                        Integer goodsSortId = goodsTypeIds.get(sysGoods.get("goods_sort_id").toString());
                        goods.setGoodsSortId(Long.parseLong(goodsSortId.toString()));
 
                        Integer supplierId = supplierInfoIds.get(sysGoods.get("supplier_id").toString());
                        if (supplierId != null) {
                            shoppingGood.setSupplierId(Long.parseLong(supplierId.toString()));
                        }
 
                        assembleGood.setShoppingGoods(goods);
                        skuExist.add(assembleGood.getAssembleSkuId());
                    } else {
                        if (skuId != null) {
                            assembleGood.setAssembleGoodId(skuId.longValue());
                        }
                    }
                }
 
                if (assembleGood.getAssembleProjId() != null) {
                    Integer projId = goodProj.get(assembleGood.getAssembleProjId().toString());
 
                    // 若为空,则需创建一个shopping_goods
                    if (projId == null && !projExist.contains(assembleGood.getAssembleProjId())) {
                        Map<String, Object> goodsMap = jdbcTemplate.queryForMap("select * from shopping_goods where id=" + assembleGood.getShoppingGoodsId());
                        ShoppingGoods goods = mapToBane(goodsMap, ShoppingGoods.class);
                        Map<String, Object> projMap = jdbcTemplate.queryForMap("select * from sys_proj_info where id=" + assembleGood.getAssembleProjId());
 
                        goods.setTimeLength((Integer) projMap.get("time_length"));
                        goods.setCode((String) projMap.get("proj_no"));
                        goods.setCompanyId(companyId);
                        goods.setHeadquarters(1);
                        goods.setIsDel(1);
                        goods.setGoodType("项目");
                        goods.setZjm(StringUtils.toHanyuPinyin(goods.getName()) + "," + StringUtils.toHeadWordHanyuPinyin(goods.getName()));
 
                        goods.setWeiDescription("数据迁移-tc");
                        assembleGood.setShoppingGoods(goods);
                        projExist.add(assembleGood.getAssembleProjId());
                    } else {
                        if (projId != null) {
                            assembleGood.setAssembleGoodId(projId.longValue());
                        }
                    }
 
//                    assembleGood.setAssembleProjId(null);
                }
            }
 
            if (CollUtil.isNotEmpty(assembleList)) {
                shoppingGood.setAssembleGoods(assembleList);
            }
        }
        return shoppingGoods;
    }
 
    @DS("slave")
    public List<ShoppingGoods> shoppingGoodsCzkOld() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from shopping_goods where good_type='充值卡'");
        List<ShoppingGoods> shoppingGoods = mapsToListBean(maps, ShoppingGoods.class);
 
        for (ShoppingGoods shoppingGood : shoppingGoods) {
            shoppingGood.setCompanyId(companyId);
            shoppingGood.setHeadquarters(1);
            shoppingGood.setIsDel(1);
            shoppingGood.setZjm(StringUtils.toHanyuPinyin(shoppingGood.getName()) + "," + StringUtils.toHeadWordHanyuPinyin(shoppingGood.getName()));
 
            shoppingGood.setWeiDescription("数据迁移");
        }
 
        return shoppingGoods;
    }
 
    @DS("slave")
    public List<ShoppingGoods> shoppingGoodsZhkOld() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from shopping_goods where good_type='综合卡'");
        List<ShoppingGoods> shoppingGoods = mapsToListBean(maps, ShoppingGoods.class);
 
 
        Map<String, Integer> goodsSku = getRedisIds("shopping_goods_sku");
        Map<String, Integer> goodProj = getRedisIds("shopping_goods_proj");
        Map<String, Integer> goodTc = getRedisIds("shopping_goods_tc");
        Map<String, Integer> goodCzk = getRedisIds("shopping_goods_czk");
        for (ShoppingGoods shoppingGood : shoppingGoods) {
            List<Map<String, Object>> assembles = jdbcTemplate.queryForList("select * from shopping_goods_assemble where shopping_goods_id=" + shoppingGood.getId());
 
            List<ShoppingGoodsAssemble> assembleList = mapsToListBean(assembles, ShoppingGoodsAssemble.class);
            for (ShoppingGoodsAssemble shoppingGoodsAssemble : assembleList) {
                Long goodsId = shoppingGoodsAssemble.getAssembleGoodId();
                System.out.println("----->" + goodsId);
                if (goodsId == 8521 || goodsId == 8522) {
                    continue;
                }
                Map<String, Object> goodsMap = jdbcTemplate.queryForMap("select * from shopping_goods where id=" + goodsId);
                ShoppingGoods goods = mapToBane(goodsMap, ShoppingGoods.class);
                if ("套餐".equals(goods.getGoodType())) {
                    Integer tcId = goodTc.get(goodsId.toString());
                    shoppingGoodsAssemble.setAssembleGoodId(tcId.longValue());
                } else if("充值卡".equals(goods.getGoodType())) {
                    Integer czkId = goodCzk.get(goodsId.toString());
                    shoppingGoodsAssemble.setShoppingGoodsId(czkId.longValue());
                } else if ("家居产品".equals(goods.getGoodType())) {
                    Map<String, Object> skuMap = jdbcTemplate.queryForMap("select * from shopping_goods_assemble where shopping_goods_id=" + goods.getId());
                    ShoppingGoodsAssemble sku = mapToBane(skuMap, ShoppingGoodsAssemble.class);
                    Integer skuId = goodsSku.get(sku.getAssembleSkuId().toString());
                    shoppingGoodsAssemble.setAssembleGoodId(skuId.longValue());
                } else if ("项目".equals(goods.getGoodType())) {
                    Map<String, Object> projMap = jdbcTemplate.queryForMap("select * from shopping_goods_assemble where shopping_goods_id=" + goods.getId());
                    ShoppingGoodsAssemble proj = mapToBane(projMap, ShoppingGoodsAssemble.class);
                    Integer projId = goodProj.get(proj.getAssembleProjId().toString());
                    shoppingGoodsAssemble.setAssembleGoodId(projId.longValue());
                }
            }
 
            shoppingGood.setAssembleGoods(assembleList);
        }
 
        return shoppingGoods;
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void shoppingGoodsNew(List<ShoppingGoods> list, String goodsType) {
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, Long> map = new HashMap<>();
            Map<String, Integer> goodsCategory = getRedisIds("goods_category");
 
            Map<String, Integer> goodsSku = getRedisIds("shopping_goods_sku");
            Map<String, Integer> goodProj = getRedisIds("shopping_goods_proj");
            Map<Long, Long> sku = new HashMap<>();
            Map<Long, Long> proj = new HashMap<>();
            for (ShoppingGoods shoppingGoods : list) {
                shoppingGoods.setCompanyId(companyId);
 
                if (shoppingGoods.getCateId() != null) {
                    Integer cateId = goodsCategory.get(shoppingGoods.getCateId().toString());
                    if (cateId != null) {
                        shoppingGoods.setCateId(Long.parseLong(cateId.toString()));
                    }
                }
 
                Long oldId = shoppingGoods.getId();
                shoppingGoods.setId(null);
                shoppingGoodsDao.insert(shoppingGoods);
                map.put(oldId, shoppingGoods.getId());
 
                if ("套餐".equals(goodsType)) {
                    List<ShoppingGoodsAssemble> assembleGoods = shoppingGoods.getAssembleGoods();
                    if (CollUtil.isNotEmpty(assembleGoods)) {
                        for (ShoppingGoodsAssemble assembleGood : assembleGoods) {
                            assembleGood.setShoppingGoodsId(shoppingGoods.getId());
 
                            Long oldIdTc = assembleGood.getAssembleSkuId() == null ? assembleGood.getAssembleProjId() : assembleGood.getAssembleSkuId();
                            if (assembleGood.getShoppingGoods() != null) {
 
                                assembleGood.getShoppingGoods().setId(null);
                                shoppingGoodsDao.insert(assembleGood.getShoppingGoods());
 
                                if (assembleGood.getAssembleSkuId() == null) {
                                    proj.put(oldIdTc, assembleGood.getShoppingGoods().getId());
                                    goodProj.put(oldIdTc.toString(), assembleGood.getShoppingGoods().getId().intValue());
                                } else {
                                    sku.put(oldIdTc, assembleGood.getShoppingGoods().getId());
                                    goodsSku.put(oldIdTc.toString(), assembleGood.getShoppingGoods().getId().intValue());
                                }
                                assembleGood.setAssembleGoodId(assembleGood.getShoppingGoods().getId());
 
                            } else {
                                if (assembleGood.getAssembleSkuId() == null) {
                                    Integer projTc = goodProj.get(oldIdTc.toString());
                                    Long goodsId = null;
                                    if (projTc == null) {
                                        goodsId = proj.get(oldIdTc);
                                    } else {
                                        goodsId = projTc.longValue();
                                    }
 
                                    assembleGood.setAssembleGoodId(goodsId);
                                } else {
                                    Integer skuTc = goodsSku.get(oldIdTc.toString());
                                    Long goodsId = null;
                                    if (skuTc == null) {
                                        goodsId = sku.get(oldIdTc);
                                    } else {
                                        goodsId = skuTc.longValue();
                                    }
 
                                    assembleGood.setAssembleGoodId(goodsId);
                                }
 
                            }
                            assembleGood.setId(null);
                        }
                        shoppingGoodsAssembleDao.batchInsert(assembleGoods);
                    }
                }
            }
 
            if ("家居产品".equals(goodsType)) {
                redisClient.saveMapValue("shopping_goods_sku", map);
            } else if ("项目".equals(goodsType)) {
                redisClient.saveMapValue("shopping_goods_proj", map);
            } else if ("套餐".equals(goodsType)) {
                redisClient.saveMapValue("shopping_goods_tc", map);
                redisClient.saveMapValue("shopping_goods_sku", goodsSku);
                redisClient.saveMapValue("shopping_goods_proj", goodProj);
            } else if ("充值卡".equals(goodsType)) {
                redisClient.saveMapValue("shopping_goods_czk", map);
            }
        }
    }
 
    @Transactional(rollbackFor = Exception.class)
    public void shoppingGoodsZhkNew(List<ShoppingGoods> list) {
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, Long> map = new HashMap<>();
            Map<String, Integer> goodsCategory = getRedisIds("goods_category");
 
            for (ShoppingGoods shoppingGoods : list) {
                shoppingGoods.setCompanyId(companyId);
 
                if (shoppingGoods.getCateId() != null) {
                    Integer cateId = goodsCategory.get(shoppingGoods.getCateId().toString());
                    if (cateId != null) {
                        shoppingGoods.setCateId(Long.parseLong(cateId.toString()));
                    }
                }
 
                Long oldId = shoppingGoods.getId();
                shoppingGoods.setId(null);
                shoppingGoodsDao.insert(shoppingGoods);
                map.put(oldId, shoppingGoods.getId());
 
                for (ShoppingGoodsAssemble assembleGood : shoppingGoods.getAssembleGoods()) {
                    assembleGood.setShoppingGoodsId(shoppingGoods.getId());
                    assembleGood.setId(null);
                }
 
                shoppingGoodsAssembleDao.batchInsert(shoppingGoods.getAssembleGoods());
 
            }
 
            redisClient.saveMapValue("shopping_goods_zhk", map);
        }
    }
 
    public Map<String, Integer> getRedisIds(String key) {
        String idsStr = redisClient.getCachedValue(key);
        return JSONObject.parseObject(idsStr, HashMap.class);
    }
 
    @DS("slave")
    public List<SysOrder> orderOld() {
        return null;
    }
 
    public void orderNew(List<SysOrder> list) {
 
    }
 
}