Helius
2021-03-19 e34593d6741b4cf723435978ace8bb642ade67fa
modify
3 files modified
255 ■■■■■ changed files
zq-erp/src/main/java/com/matrix/component/redis/RedisClient.java 2 ●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/dataMove/DateMoveServiceImpl.java 206 ●●●●● patch | view | raw | blame | history
zq-erp/src/test/java/com/matrix/DataMoveTest.java 47 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/component/redis/RedisClient.java
@@ -173,7 +173,7 @@
        if (jsonObject != null) {
            Jedis jedis = getJedis();
            Gson gson = new GsonBuilder().enableComplexMapKeySerialization().create();
            jedis.setex(key, timeOut, gson.toJson(jsonObject));
            jedis.set(key, gson.toJson(jsonObject));
            jedis.close();
        }
    }
zq-erp/src/main/java/com/matrix/system/dataMove/DateMoveServiceImpl.java
@@ -1,15 +1,18 @@
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.SysShopInfo;
import com.matrix.system.hive.dao.SysShopInfoDao;
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;
@@ -28,17 +31,28 @@
    @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 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");
@@ -142,7 +156,7 @@
        return list;
    }
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public void newSysUsers(List<SysUsers> list) {
        if (CollUtil.isNotEmpty(list)) {
            Map<Long, Long> sysUsersOldAndNew = new HashMap<>();
@@ -157,4 +171,186 @@
        }
    }
    @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<ShoppingGoods> shoppingGoodsOld() {
        List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from shopping_goods");
        List<ShoppingGoods> shoppingGoods = mapsToListBean(maps, ShoppingGoods.class);
        return shoppingGoods;
    }
    public void shoppingGoodsNew() {}
}
zq-erp/src/test/java/com/matrix/DataMoveTest.java
@@ -3,6 +3,7 @@
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.hive.bean.SysShopInfo;
import com.matrix.system.dataMove.DateMoveServiceImpl;
import com.matrix.system.hive.bean.SysVipLevel;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,15 +25,61 @@
    @Autowired
    private DateMoveServiceImpl dataMove;
    /**
     * 商铺信息迁移
     */
    @Test
    public void slaveTest() {
        List<SysShopInfo> shopInfos = dataMove.oldShopInfo();
        dataMove.toNewShopInfo(shopInfos);
    }
    /**
     * 后台用户迁移
     * @throws UnsupportedEncodingException
     * @throws NoSuchAlgorithmException
     */
    @Test
    public void sysUsersMoveTest() throws UnsupportedEncodingException, NoSuchAlgorithmException {
        List<SysUsers> sysUsers = dataMove.oldSysUsers();
        dataMove.newSysUsers(sysUsers);
    }
    /**
     * 会员等级迁移
     */
    @Test
    public void vipLevelMove() {
        List<SysVipLevel> sysVipLevels = dataMove.vipLevelOld();
        dataMove.vipLevelNew(sysVipLevels);
    }
    /**
     * 会员信息迁移
     */
//    @Test
    public void vipInfoMoveTest() {
        dataMove.vipInfoNew(dataMove.vipInfoOld());
    }
//    @Test
    public void supplierTypeMoveTest() {
        dataMove.supplierNew(dataMove.supplierTypeOld());
    }
//    @Test
    public void supplierInfoMoveTest() {
        dataMove.supplierInfoNew(dataMove.supplierInfoOld());
    }
//    @Test
    public void shoppingGoodsCateMoveTest() {
        dataMove.goodsCategoryNew(dataMove.goodsCategoryOld());
        dataMove.goodsCategoryParentIdUpdate();
    }
    @Test
    public void shoppingGoodsMoveTest() {
    }
}