From 47069bbff045825088bb6251ee3697960162760d Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Tue, 23 Mar 2021 19:13:32 +0800
Subject: [PATCH] modify
---
zq-erp/src/main/java/com/matrix/system/dataMove/DateMoveServiceImpl.java | 413 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 410 insertions(+), 3 deletions(-)
diff --git a/zq-erp/src/main/java/com/matrix/system/dataMove/DateMoveServiceImpl.java b/zq-erp/src/main/java/com/matrix/system/dataMove/DateMoveServiceImpl.java
index de1f3ca..2692c46 100644
--- a/zq-erp/src/main/java/com/matrix/system/dataMove/DateMoveServiceImpl.java
+++ b/zq-erp/src/main/java/com/matrix/system/dataMove/DateMoveServiceImpl.java
@@ -47,6 +47,12 @@
private SysSupplierInfoDao sysSupplierInfoDao;
@Autowired
private ShoppingGoodsCategoryDao shoppingGoodsCategoryDao;
+ @Autowired
+ private SysGoodsTypeDao sysGoodsTypeDao;
+ @Autowired
+ private ShoppingGoodsDao shoppingGoodsDao;
+ @Autowired
+ private ShoppingGoodsAssembleDao shoppingGoodsAssembleDao;
@Autowired
private RedisClient redisClient;
@@ -66,6 +72,11 @@
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);
}
/**
@@ -342,15 +353,411 @@
}
}
+ @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> shoppingGoodsOld() {
- List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from shopping_goods");
+ 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;
}
- public void shoppingGoodsNew() {}
+ @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);
+ }
}
--
Gitblit v1.9.1