From 4705f9b4084d9ccddb601569b223f0fb41778a94 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Thu, 12 Aug 2021 15:28:46 +0800 Subject: [PATCH] fix --- zq-erp/src/main/java/com/matrix/system/dataMove/DateMoveServiceImpl.java | 1751 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 1,735 insertions(+), 16 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 e181e23..2898b19 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 @@ -1,21 +1,28 @@ 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.DateUtil; +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.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.UnsupportedEncodingException; +import java.math.BigDecimal; import java.security.NoSuchAlgorithmException; import java.util.*; @@ -28,17 +35,36 @@ @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 MoneyCardUseDao moneyCardUseDao; @Autowired private RedisClient redisClient; private Long companyId = 35L; + private Long shopId = 60L; public List<Map<String, Object>> dataMove() { return jdbcTemplate.queryForList("select * from sys_vip_info limit 10"); @@ -52,6 +78,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); } /** @@ -73,11 +104,12 @@ return shopInfos; } + @Transactional(rollbackFor = Exception.class) public void toNewShopInfo(List<SysShopInfo> shopInfos) { if (CollUtil.isNotEmpty(shopInfos)) { Map<Long, Long> oldAndNewId = new HashMap<>(); for (SysShopInfo shopInfo : shopInfos) { - if (shopInfo.getShopName().equals("总部")) { + if (shopInfo.getShopName().equals("总店")) { shopInfo.setShopType(1); shopInfo.setIsOpenNet(2); } else { @@ -91,14 +123,20 @@ 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()); - } + + sysShopInfoDao.insert(shopInfo); + oldAndNewId.put(oldId, shopInfo.getId()); +// // TODO 若迁往正式环境,这里需要变动 +// if (!shopInfo.getShopName().contains("美度") && !shopInfo.getShopName().contains("总店")) { +// sysShopInfoDao.insert(shopInfo); +// oldAndNewId.put(oldId, shopInfo.getId()); +// } else { +// if (shopInfo.getShopName().equals("总店")) { +// shopInfo.setShopName("美度(总部)"); +// } +// SysShopInfo sysShopInfo = sysShopInfoDao.selectByShopName(shopInfo.getShopName()); +// oldAndNewId.put(oldId, sysShopInfo.getId()); +// } } redisClient.saveMapValue("shopId", oldAndNewId); } @@ -136,19 +174,20 @@ sysUsers.setSuRegisterTime((Date) map.get("register_time")); sysUsers.setCreateBy(AppConstance.SYSTEM_USER); sysUsers.setUpdateBy(AppConstance.SYSTEM_USER); - sysUsers.setSuPassword(PasswordUtil.getEncrypUserPwd(sysUsers)); +// sysUsers.setSuPassword(PasswordUtil.getEncrypUserPwd(sysUsers)); list.add(sysUsers); } return list; } - @Transactional - public void newSysUsers(List<SysUsers> list) { + @Transactional(rollbackFor = Exception.class) + public void newSysUsers(List<SysUsers> list) throws UnsupportedEncodingException, NoSuchAlgorithmException { if (CollUtil.isNotEmpty(list)) { Map<Long, Long> sysUsersOldAndNew = new HashMap<>(); for (SysUsers sysUsers : list) { Long oldId = sysUsers.getSuId(); sysUsers.setSuId(null); + sysUsers.setSuPassword(PasswordUtil.getEncrypUserPwd(sysUsers)); sysUsersDao.insert(sysUsers); sysUsersOldAndNew.put(oldId, sysUsers.getSuId()); } @@ -157,4 +196,1684 @@ } } + @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())); + } + } + + // sys_users 中 id 为 200 的无法找到 + 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()); + } + + redisClient.saveMapValue("vip_info", vipInfoIds); + } + } + + + @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())); + + if (shoppingGood.getCarUseCount() != null) { + shoppingGood.setIsCourse("Y"); + shoppingGood.setIsInfinite("N"); + } + + 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); + shoppingGood.setIsInfinite("N"); + } + + 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())); + } + } + + if ("否".equals(shoppingGoods.getIsOnce())) { + shoppingGoods.setIsOnce("0"); + } else { + shoppingGoods.setIsOnce("1"); + } + + if (StrUtil.isNotBlank(shoppingGoods.getIsPresent())) { + if ("否".equals(shoppingGoods.getIsPresent())) { + shoppingGoods.setIsPresent("0"); + } else { + shoppingGoods.setIsPresent("1"); + } + } + + 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) { + + if ("否".equals(assembleGood.getShoppingGoods().getIsOnce())) { + assembleGood.getShoppingGoods().setIsOnce("0"); + } else { + assembleGood.getShoppingGoods().setIsOnce("1"); + } + + if (StrUtil.isNotBlank(assembleGood.getShoppingGoods().getIsPresent())) { + if ("否".equals(assembleGood.getShoppingGoods().getIsPresent())) { + assembleGood.getShoppingGoods().setIsPresent("0"); + } else { + assembleGood.getShoppingGoods().setIsPresent("1"); + } + } + + 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())); + } + } + + if ("否".equals(shoppingGoods.getIsOnce())) { + shoppingGoods.setIsOnce("0"); + } else { + shoppingGoods.setIsOnce("1"); + } + + if (StrUtil.isNotBlank(shoppingGoods.getIsPresent())) { + if ("否".equals(shoppingGoods.getIsPresent())) { + shoppingGoods.setIsPresent("0"); + } else { + shoppingGoods.setIsPresent("1"); + } + } + + 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() { + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_order"); + List<SysOrder> orders = mapsToListBean(maps, SysOrder.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"); + Map<String, Integer> goodZHK = getRedisIds("shopping_goods_zhk"); + Map<String, Integer> shopIds = getRedisIds("shopId"); +// Map<String, Integer> sysUsers = getRedisIds("sys_users"); + Map<String, Integer> vipInfos = getRedisIds("vip_info"); + Map<String, Integer> shopStaff = getRedisIds("shop_staff"); + for (SysOrder order : orders) { + List<Map<String, Object>> itemsMap = jdbcTemplate.queryForList("select * from sys_order_item where ORDER_ID=" + order.getId()); + + Integer shopId = shopIds.get(order.getShopId().toString()); + order.setShopId(shopId.longValue()); + + if ("已付款".equals(order.getStatu()) || "欠款".equals(order.getStatu())) { + order.setPayTime(order.getOrderTime()); + } + + Integer statffId = shopStaff.get(order.getStaffId().toString()); + if (statffId != null) { + order.setStaffId(statffId.longValue()); + } else { + order.setStaffId(-order.getStaffId()); + } + Integer vipId = vipInfos.get(order.getVipId().toString()); + if (vipId != null) { + order.setVipId(vipId.longValue()); + } else { + order.setVipId(-order.getVipId()); + } + + order.setCompanyId(companyId); + + List<SysOrderItem> items = mapsToListBean(itemsMap, SysOrderItem.class); + + Double cardPay = 0D; + Double cashPay = 0D; + Double arrears = 0D; + Map<Long, Long> shoppingGoodsIds = new HashMap<>(); + if (CollUtil.isNotEmpty(items)) { + Long goodsId = items.get(0).getGoodsId(); + Map<String, Object> goods = jdbcTemplate.queryForMap("select * from shopping_goods where id=" + goodsId); + order.setShopShortName((String) goods.get("name")); + for (SysOrderItem item : items) { + Double itemCard = item.getCardPay() == null ? 0D : item.getCardPay(); + Double itemCash = item.getCashPay() == null ? 0D : item.getCashPay(); + Double itemArrears = item.getArrears() == null ? 0D : item.getArrears(); + + cardPay += itemCard; + cashPay += itemCash; + arrears += itemArrears; + + if (itemCard != 0) { + item.setPayMethod("划扣"); + } else { + item.setPayMethod("现金"); + } + + Long oldID = item.getGoodsId(); + switch (item.getType()) { + case "家居产品" : + Map<String, Object> skuMap = jdbcTemplate.queryForMap("select * from shopping_goods_assemble where id=" + item.getAssembleId()); + Long skuId = (Long) skuMap.get("assemble_sku_id"); + Integer skuGoodsId = goodsSku.get(skuId.toString()); + if (skuGoodsId != null) { + item.setGoodsId(skuGoodsId.longValue()); + } else { + item.setGoodsId(-item.getAssembleId()); + } + break; + case "项目" : + Map<String, Object> projMap = jdbcTemplate.queryForMap("select * from shopping_goods_assemble where id=" + item.getAssembleId()); + Long projId = (Long) projMap.get("assemble_proj_id"); + Integer projGoodsId = goodProj.get(projId.toString()); + if (projGoodsId != null) { + item.setGoodsId(projGoodsId.longValue()); + } else { + item.setGoodsId(-item.getAssembleId()); + } + break; + case "套餐" : + Integer tcId = goodTc.get(item.getGoodsId().toString()); + if (tcId != null) { + item.setGoodsId(tcId.longValue()); + } else { + item.setGoodsId(-item.getGoodsId()); + } + break; + case "充值卡" : + Integer czkId = goodCZK.get(item.getGoodsId().toString()); + if (czkId != null) { + item.setGoodsId(czkId.longValue()); + } else { + item.setGoodsId(-item.getGoodsId()); + } + break; + case "综合卡" : + Integer zhkId = goodZHK.get(item.getGoodsId().toString()); + if (zhkId != null) { + item.setGoodsId(zhkId.longValue()); + } else { + item.setGoodsId(-item.getGoodsId()); + } + break; + default: + } + + shoppingGoodsIds.put(oldID, item.getGoodsId()); + } + order.setItems(items); + } + + List<SysOrderFlow> flows = new ArrayList<>(); + if (cardPay != 0D) { + flows.add(setOrderFLow(order, "储值卡", cardPay, 1)); + } + + if (cashPay != 0D) { + flows.add(setOrderFLow(order, "现金支付", cashPay, 1)); + } + + if (arrears != 0D) { + flows.add(setOrderFLow(order, "欠款", arrears, 1)); + } + order.setFlows(flows); + + List<Map<String, Object>> achievesMap = jdbcTemplate.queryForList("select sale_id, beault_id, shop_id, datatime, order_id, order_item_id, shopping_goods_id, vip_id, order_type, sum(t1) as t1 from achieve_new where order_type='订单' and order_id="+ order.getId() + " group by sale_id, beault_id, shop_id, datatime, order_id, order_item_id, shopping_goods_id, vip_id, order_type"); + if (CollUtil.isNotEmpty(achievesMap)) { + List<AchieveNew> achieves = mapsToListBean(achievesMap, AchieveNew.class); + for (AchieveNew achieve : achieves) { + Integer achiShopId = shopIds.get(achieve.getShopId().toString()); + achieve.setShopId(achiShopId.longValue()); + + if (achieve.getBeaultId() == null) { + achieve.setBeaultId(achieve.getSaleId()); + achieve.setAchieveType("顾问业绩"); + } else { + achieve.setAchieveType("美疗师业绩"); + } + Integer beaultId = shopStaff.get(achieve.getBeaultId().toString()); + if (beaultId != null) { + achieve.setBeaultId(beaultId.longValue()); + } else { + achieve.setBeaultId(-achieve.getBeaultId()); + } + + Integer saleId = shopStaff.get(achieve.getSaleId().toString()); + if (saleId != null) { + achieve.setSaleId(saleId.longValue()); + } else { + achieve.setSaleId(-achieve.getSaleId()); + } + + Integer achiVipId = vipInfos.get(achieve.getVipId().toString()); + if (achiVipId != null) { + achieve.setVipId(achiVipId.longValue()); + } else { + achieve.setVipId(-achieve.getVipId()); + } + achieve.setGoodsCash(Double.parseDouble(achieve.getT1())); + achieve.setCompanyId(companyId); + achieve.setShoppingGoodsId(shoppingGoodsIds.get(achieve.getShoppingGoodsId())); + + } + order.setAchieveNews(achieves); + } + } + return orders; + } + + public SysOrderFlow setOrderFLow(SysOrder sysOrder, String type, Double amount, int index) { + SysOrderFlow flow = new SysOrderFlow(); + flow.setFlowContent(sysOrder.getShopShortName() + "等" + sysOrder.getItems().size() + "件产品"); + flow.setFlowType(SysOrderFlow.FLOW_TYPE_BUY); + flow.setAmount(new BigDecimal(amount)); + flow.setFlowNo("F" + sysOrder.getOrderNo() + "-" + index); + flow.setVipId(sysOrder.getVipId()); + flow.setShopId(sysOrder.getShopId()); + flow.setCompanyId(sysOrder.getCompanyId()); + flow.setPayMethod(type); + return flow; + } + + @Autowired + private SysOrderDao sysOrderDao; + @Autowired + private SysOrderItemDao sysOrderItemDao; + @Autowired + private SysOrderFlowDao sysOrderFlowDao; + @Autowired + private AchieveNewDao achieveNewDao; + + @Transactional(rollbackFor = Exception.class) + public void orderNew(List<SysOrder> list) { + if (CollUtil.isNotEmpty(list)) { + Map<Long, Long> orderIds = new HashMap<>(); + Map<Long, Long> itemIds = new HashMap<>(); + + for (SysOrder sysOrder : list) { + Long oldOrderId = sysOrder.getId(); + sysOrder.setId(null); + sysOrder.setCreateBy("数据迁移"); + sysOrder.setCreateTime(sysOrder.getOrderTime() == null ? DateUtil.stringToDate("2018-10-17 19:03:28", DateUtil.DATE_FORMAT_SS) : sysOrder.getOrderTime()); + sysOrder.setUpdateTime(sysOrder.getOrderTime() == null ? DateUtil.stringToDate("2018-10-17 19:03:28", DateUtil.DATE_FORMAT_SS) : sysOrder.getOrderTime()); + sysOrderDao.insert(sysOrder); + orderIds.put(oldOrderId, sysOrder.getId()); + + if (CollUtil.isNotEmpty(sysOrder.getItems())) { + for (SysOrderItem item : sysOrder.getItems()) { + Long oldItemId = item.getId(); + item.setOrderId(sysOrder.getId()); + item.setId(null); + sysOrderItemDao.insert(item); + itemIds.put(oldItemId, item.getId()); + } + } + + if (CollUtil.isNotEmpty(sysOrder.getFlows())) { + for (SysOrderFlow flow : sysOrder.getFlows()) { + if ("储值卡".equals(flow.getPayMethod())) { + MoneyCardUse moneyCardUse = new MoneyCardUse(); + moneyCardUse.setIsVipCar("Y"); + moneyCardUse.setVipId(flow.getVipId()); + List<MoneyCardUse> moneyCardUses = moneyCardUseDao.selectVipCardUse(moneyCardUse); + if (CollUtil.isNotEmpty(moneyCardUses)) { + flow.setCardId(moneyCardUses.get(0).getId()); + } + } + flow.setOrderId(sysOrder.getId()); + flow.setCreateBy("数据迁移"); + flow.setCreateTime(sysOrder.getCreateTime()); + flow.setUpdateTime(sysOrder.getUpdateTime()); + sysOrderFlowDao.insert(flow); + } + } + + if (CollUtil.isNotEmpty(sysOrder.getAchieveNews())) { + for (AchieveNew achieveNew : sysOrder.getAchieveNews()) { + achieveNew.setOrderId(sysOrder.getId()); + Long item = itemIds.get(achieveNew.getOrderItemId()); + achieveNew.setT9("数据迁移"); + achieveNew.setOrderItemId(item); + achieveNew.setId(null); + } + + achieveNewDao.batchInsert(sysOrder.getAchieveNews()); + } + } + + redisClient.saveMapValue("order", orderIds); + redisClient.saveMapValue("order_item", itemIds); + } + } + + @DS("slave") + public List<SysBedInfo> bedInfoOld() { + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_bed_info"); + List<SysBedInfo> beds = mapsToListBean(maps, SysBedInfo.class); + + Map<String, Integer> shopIds = getRedisIds("shopId"); + for (SysBedInfo bed : beds) { + Integer shopId = shopIds.get(bed.getShopId().toString()); + if (shopId != null) { + bed.setShopId(shopId.longValue()); + } else { + bed.setShopId(-bed.getShopId()); + } + } + return beds; + } + + @Autowired + private SysBedInfoDao sysBedInfoDao; + + @Transactional(rollbackFor = Exception.class) + public void bedInfoNew(List<SysBedInfo> list) { + if (CollUtil.isNotEmpty(list)) { + Map<Long, Long> map = new HashMap<>(); + for (SysBedInfo bed : list) { + Long oldId = bed.getId(); + bed.setId(null); + sysBedInfoDao.insert(bed); + map.put(oldId, bed.getId()); + } + + redisClient.saveMapValue("bed_info", map); + } + } + + @DS("slave") + public List<SysProjUse> projUseMoveOld() { + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select\n" + + "\t\ta.ID,\n" + + "\t\ta.VIP_ID,\n" + + "\t\ta.TAOCAN_ID,\n" + + "\t\ta.FAIL_TIME,\n" + + "\t\ta.SOURCE,\n" + + "\t\ta.STATUS,\n" + + "\t\ta.ORDER_ITEM_ID,\n" + + "\t\ta.PLATFORM_FLAG,\n" + + "\t\ta.type,\n" + + "\t\ta.balance,\n" + + "\t\ta.remark,\n" + + " b.name projName,\n" + + " a.SURPLUS_COUNT\n" + + "\t\tfrom sys_proj_use a\n" + + "\t\tleft join shopping_goods b on a.TAOCAN_ID= b.ID\n" + + "where TAOCAN_ID IS NOT NULL\n" + + "GROUP BY PLATFORM_FLAG\n" + + "order by a.status"); + List<SysProjUse> projUses = mapsToListBean(maps, SysProjUse.class); + + Map<String, Integer> goodProj = getRedisIds("shopping_goods_proj"); + Map<String, Integer> goodTc = getRedisIds("shopping_goods_tc"); + Map<String, Integer> vipInfos = getRedisIds("vip_info"); + Map<String, Integer> order_item = getRedisIds("order_item"); + for (SysProjUse projUse : projUses) { + projUse.setType("套餐"); + if (projUse.getTaocanId() != null) { + Integer tcId = goodTc.get(projUse.getTaocanId().toString()); + if (tcId != null) { + projUse.setProjId(tcId.longValue()); + } else { + projUse.setProjId(-projUse.getTaocanId()); + } + } + + Integer vipId = vipInfos.get(projUse.getVipId().toString()); + if (vipId != null) { + projUse.setVipId(vipId.longValue()); + } else { + projUse.setVipId(-projUse.getVipId()); + } + + if (projUse.getOrderItemId() != null && projUse.getOrderItemId() != 1) { + Integer itemID = order_item.get(projUse.getOrderItemId().toString()); + if (itemID != null) { + projUse.setOrderItemId(itemID.longValue()); + } else { + projUse.setOrderItemId(-projUse.getOrderItemId()); + } + } + + if ("无效".equals(projUse.getStatus())) { + projUse.setIsOver("Y"); + } + + List<Map<String, Object>> projInfos = jdbcTemplate.queryForList("select a.*, b.PROJ_NAME from sys_proj_use a\n" + + "left join sys_proj_info b on a.PROJ_ID=b.ID\n" + + "where PLATFORM_FLAG='" + projUse.getPlatformFlag()+"'"); + + List<SysProjUse> projInfoUses = mapsToListBean(projInfos, SysProjUse.class); + for (SysProjUse projInfoUse : projInfoUses) { + if (projInfoUse.getProjId() != null) { + Integer projId = goodProj.get(projInfoUse.getProjId().toString()); + if (projId != null) { + projInfoUse.setProjId(projId.longValue()); + } else { + projInfoUse.setProjId(-projInfoUse.getProjId()); + } + } + + Integer vipId2 = vipInfos.get(projInfoUse.getVipId().toString()); + if (vipId2 != null) { + projInfoUse.setVipId(vipId2.longValue()); + } else { + projInfoUse.setVipId(-projInfoUse.getVipId()); + } + projInfoUse.setType("项目"); + } + + projUse.setTaocanProjUse(projInfoUses); + } + + List<Map<String, Object>> projUsesInfoMap = jdbcTemplate.queryForList("select a.*, b.PROJ_NAME from sys_proj_use a left join sys_proj_info b on a.PROJ_ID=b.id where TAOCAN_ID is null"); + List<SysProjUse> sysProjUses = mapsToListBean(projUsesInfoMap, SysProjUse.class); + for (SysProjUse sysProjUse : sysProjUses) { + sysProjUse.setType("项目"); + sysProjUse.setDeductionNum(1); + + if (sysProjUse.getProjId() != null) { + Integer projId = goodProj.get(sysProjUse.getProjId().toString()); + if (projId != null) { + sysProjUse.setProjId(projId.longValue()); + } else { + sysProjUse.setProjId(-sysProjUse.getProjId()); + } + } + + Integer vipId2 = vipInfos.get(sysProjUse.getVipId().toString()); + if (vipId2 != null) { + sysProjUse.setVipId(vipId2.longValue()); + } else { + sysProjUse.setVipId(-sysProjUse.getVipId()); + } + + if (sysProjUse.getOrderItemId() != null && sysProjUse.getOrderItemId() != 1) { + Integer itemID = order_item.get(sysProjUse.getOrderItemId().toString()); + if (itemID != null) { + sysProjUse.setOrderItemId(itemID.longValue()); + } else { + sysProjUse.setOrderItemId(-sysProjUse.getOrderItemId()); + } + } + projUses.add(sysProjUse); + } + return projUses; + } + + @Autowired + private SysProjUseDao sysProjUseDao; + + @Transactional(rollbackFor = Exception.class) + public void projUseNew(List<SysProjUse> list) { + if (CollUtil.isNotEmpty(list)) { + Map<Long, Long> map = new HashMap<>(); + for (SysProjUse sysProjUse : list) { + Long oldId = sysProjUse.getId(); + sysProjUse.setId(null); + sysProjUse.setCreateBy("数据迁移"); + sysProjUse.setTaocanId(null); + + List<SysProjUse> taocanProjUses = sysProjUse.getTaocanProjUse(); + if (CollUtil.isNotEmpty(taocanProjUses)) { + sysProjUse.setIsCourse("N"); + sysProjUseDao.insert(sysProjUse); + for (SysProjUse taocanProjUse : taocanProjUses) { + taocanProjUse.setTaocanId(sysProjUse.getId()); + Long projOldId = taocanProjUse.getId(); + taocanProjUse.setId(null); + taocanProjUse.setCreateBy("数据迁移"); + taocanProjUse.setDeductionNum(1); + sysProjUseDao.insert(taocanProjUse); + map.put(projOldId, taocanProjUse.getId()); + } + } else { + sysProjUseDao.insert(sysProjUse); + } + + map.put(oldId, sysProjUse.getId()); + } + + redisClient.saveMapValue("proj_use", map); + } + } + + @DS("slave") + public List<SysProjServices> serviceOrderOld() { + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_proj_services"); + List<SysProjServices> list = mapsToListBean(maps, SysProjServices.class); + + + Map<String, Integer> vipInfos = getRedisIds("vip_info"); + Map<String, Integer> bedInfos = getRedisIds("bed_info"); +// Map<String, Integer> sysUsers = getRedisIds("sys_users"); + Map<String, Integer> projUses = getRedisIds("proj_use"); + Map<String, Integer> goodProj = getRedisIds("shopping_goods_proj"); + Map<String, Integer> shopIds = getRedisIds("shopId"); + Map<String, Integer> shopStaff = getRedisIds("shop_staff"); + for (SysProjServices sysProjServices : list) { + List<Map<String, Object>> beauticiansMap = jdbcTemplate.queryForList("select * from sys_beautician_state where SERVICES_ID=" + sysProjServices.getId()); +// Map<String, Object> bedStatesMap = jdbcTemplate.queryForMap("select * from sys_bed_state where SERVICE_ID=" + sysProjServices.getId()); +// List<Map<String, Object>> achieveMaps = jdbcTemplate.queryForList("select * from achieve_new where service_order_id=" + sysProjServices.getId()); + + + SysBedState query = new SysBedState(); + query.setServiceId(sysProjServices.getId()); + List<SysBedState> queryBeds = sysBedStateDao.selectByModel(query); + SysBedState bedStates = null; + if (CollUtil.isNotEmpty(queryBeds)) { + bedStates = queryBeds.get(0); + } + List<SysBeauticianState> beauticians = mapsToListBean(beauticiansMap, SysBeauticianState.class); + List<AchieveNew> achieveNews = achieveNewDao.selectAchieveByServiceOrderId(sysProjServices.getId()); +// SysBedState bedStates = mapToBane(bedStatesMap, SysBedState.class); + + Integer shopId = shopIds.get(sysProjServices.getShopId().toString()); + if (shopId != null) { + sysProjServices.setShopId(shopId.longValue()); + } else { + sysProjServices.setShopId(-sysProjServices.getShopId()); + } + + if (sysProjServices.getBedId() != null) { + Integer bedId = bedInfos.get(sysProjServices.getBedId().toString()); + if (bedId != null) { + sysProjServices.setBedId(bedId.longValue()); + bedStates.setBedId(bedId.longValue()); + } else { + sysProjServices.setBedId(-sysProjServices.getBedId()); + bedStates.setBedId(-sysProjServices.getBedId()); + } + sysProjServices.setBedState(bedStates); + } + + if (sysProjServices.getBeauticianId() != null) { + Integer beautyId = shopStaff.get(sysProjServices.getBeauticianId().toString()); + if (beautyId != null) { + sysProjServices.setBeauticianId(beautyId.longValue()); + } else { + sysProjServices.setBeauticianId(-sysProjServices.getBeauticianId()); + } + } + + if (sysProjServices.getDevisionId() != null) { + Integer devisionId = shopStaff.get(sysProjServices.getDevisionId().toString()); + if (devisionId != null) { + sysProjServices.setDevisionId(devisionId.longValue()); + } else { + sysProjServices.setDevisionId(-sysProjServices.getDevisionId()); + } + } + + if (sysProjServices.getCreateStaffId() != null) { + Integer staffId = shopStaff.get(sysProjServices.getCreateStaffId().toString()); + if (staffId != null) { + sysProjServices.setCreateStaffId(staffId.longValue()); + } else { + sysProjServices.setCreateStaffId(-sysProjServices.getCreateStaffId()); + } + } + Integer vipId = null; + if (sysProjServices.getVipId() != null) { + vipId = vipInfos.get(sysProjServices.getVipId().toString()); + if (vipId != null) { + sysProjServices.setVipId(vipId.longValue()); + } else { + sysProjServices.setVipId(-sysProjServices.getVipId()); + } + } + + if (CollUtil.isNotEmpty(beauticians)) { + List<SysBeauticianState> newBeautician = new ArrayList<>(); + for (SysBeauticianState beautician : beauticians) { + List<Map<String, Object>> beaProjMaps = jdbcTemplate.queryForList("select distinct proj_id from service_bea_proj where ser_proj_id is not null and bea_state_id=" + beautician.getId()); + for (Map<String, Object> beaProjMap : beaProjMaps) { + SysBeauticianState beauticianState = new SysBeauticianState(); + BeanUtils.copyProperties(beautician, beauticianState); + String puseIdStr = beaProjMap.get("proj_id").toString(); + Integer puseId = projUses.get(puseIdStr); + beauticianState.setPuseId(puseId != null ? puseId.longValue() : -Long.parseLong(puseIdStr)); + + SysProjUse sysProjUse = sysProjUseDao.selectById(Long.parseLong(puseIdStr)); +// Map<String, Object> projUseMap = jdbcTemplate.queryForMap("select * from sys_proj_use where id=" + puseIdStr); + if (sysProjUse != null) { + Integer goodsProjId = goodProj.get(sysProjUse.getProjId().toString()); + beauticianState.setProjId(goodsProjId != null ? goodsProjId.longValue() : -Long.parseLong(sysProjUse.getProjId().toString())); + } + + beauticianState.setCount(1); +// beauticianState.setcreate("数据迁移"); + newBeautician.add(beauticianState); + } + } + sysProjServices.setServiceItems(newBeautician); + } + + if (CollUtil.isNotEmpty(achieveNews)) { + for (AchieveNew achieveNew : achieveNews) { + achieveNew.setShopId(shopId != null ? shopId.longValue() : -achieveNew.getShopId()); + achieveNew.setVipId(vipId != null ? vipId.longValue() : -achieveNew.getVipId()); + + Integer saleIdInt = shopStaff.get(achieveNew.getSaleId() == null ? "" : achieveNew.getSaleId().toString()); + achieveNew.setSaleId(saleIdInt == null ? -achieveNew.getSaleId() : saleIdInt); + + Integer beaultyIdInt = shopStaff.get(achieveNew.getBeaultId() == null ? "" : achieveNew.getBeaultId().toString()); + achieveNew.setBeaultId(beaultyIdInt == null ? -achieveNew.getBeaultId() : beaultyIdInt); + + if (achieveNew.getShoppingGoodsId() != null) { + Integer goodsId = goodProj.get(achieveNew.getShoppingGoodsId().toString()); + achieveNew.setShoppingGoodsId(goodsId == null ? -achieveNew.getShoppingGoodsId() : goodsId.longValue()); + } + + achieveNew.setT9("数据迁移"); + } + } + sysProjServices.setAchieveNews(achieveNews); + + } + + + return list; + } + + @Autowired + private SysProjServicesDao sysProjServicesDao; + @Autowired + private SysBeauticianStateDao sysBeauticianStateDao; + @Autowired + private SysBedStateDao sysBedStateDao; + + @Transactional(rollbackFor = Exception.class) + public void serviceOrderNew(List<SysProjServices> list) { + if (CollUtil.isNotEmpty(list)) { + Map<Long, Long> maps = new HashMap<>(); + Map<Long, Long> beautyMaps = new HashMap<>(); + for (SysProjServices sysProjServices : list) { + Long oldId = sysProjServices.getId(); + sysProjServices.setId(null); + sysProjServices.setComment("数据迁移"); + sysProjServices.setCompanyId(companyId); + sysProjServicesDao.insert(sysProjServices); + Long newId = sysProjServices.getId(); + List<SysBeauticianState> serviceItems = sysProjServices.getServiceItems(); + if (CollUtil.isNotEmpty(serviceItems)) { + for (SysBeauticianState serviceItem : serviceItems) { + serviceItem.setServicesId(newId); + Long beautyOldId = serviceItem.getId(); + serviceItem.setId(null); +// serviceItem.setExtract("数据迁移"); + sysBeauticianStateDao.insert(serviceItem); + beautyMaps.put(beautyOldId, serviceItem.getId()); + } + } + SysBedState bedState = sysProjServices.getBedState(); + if (bedState != null) { + bedState.setId(null); + bedState.setServiceId(newId); + sysBedStateDao.insert(bedState); + } + + List<AchieveNew> achieveNews = sysProjServices.getAchieveNews(); + if (CollUtil.isNotEmpty(achieveNews)) { + for (AchieveNew achieveNew : achieveNews) { + achieveNew.setId(null); + achieveNew.setOrderItemId(beautyMaps.get(achieveNew.getOrderItemId())); + achieveNew.setServiceOrderId(newId); + achieveNew.setCompanyId(companyId); + } + achieveNewDao.batchInsert(achieveNews); + } + maps.put(oldId, newId); + } + + redisClient.saveMapValue("service_order", maps); + } + } + + @DS("slave") + public List<SysUsers> shopStaffInfoOld() throws UnsupportedEncodingException, NoSuchAlgorithmException { + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_shopstaff_info"); + Map<String, Integer> sysUsersMap = getRedisIds("sys_users"); + Map<String, Integer> shopMap = getRedisIds("shopId"); + Map<Long, Long> staffMap = new HashMap<>(); + + List<SysUsers> list = new ArrayList<>(); + // EmptyResultDataAccessException + for (Map<String, Object> map : maps) { + try { + Map<String, Object> staffUser = jdbcTemplate.queryForMap("select * from users where staff_id=" + map.get("id")); + Integer id = sysUsersMap.get(staffUser.get("id").toString()); + staffMap.put(Long.parseLong(map.get("id").toString()), id.longValue()); + } catch (EmptyResultDataAccessException e) { + SysUsers sysUsers = new SysUsers(); + sysUsers.setSuAccount((String) map.get("staff_no")); + sysUsers.setSuId((Long) map.get("id")); + sysUsers.setSuName((String) map.get("staff_name")); + sysUsers.setSuSex((String) map.get("sex")); + sysUsers.setSuUserType("employee"); + sysUsers.setSuAccountStatus(AppConstance.ACCOUNT_STATUS_INACTIVATED); + sysUsers.setSuValid("N"); + sysUsers.setCompanyId(companyId); + Long aaa = (Long) map.get("shop_id"); + if (aaa != null) { + Integer shopId = shopMap.get(aaa.toString()); + if (shopId != null) { + sysUsers.setShopId(Long.parseLong(shopId.toString())); + } + } + sysUsers.setSuRegisterTime(new Date()); + sysUsers.setCreateBy(AppConstance.SYSTEM_USER); + sysUsers.setUpdateBy(AppConstance.SYSTEM_USER); + sysUsers.setSuPassword(PasswordUtil.getEncrypUserPwd(sysUsers)); + list.add(sysUsers); + } + } + redisClient.saveMapValue("shop_staff", staffMap); + return list; + } + + @Transactional(rollbackFor = Exception.class) + public void shopStaffInfoNew(List<SysUsers> list) { + Map<String, Integer> shopStaff = getRedisIds("shop_staff"); + for (SysUsers sysUsers : list) { + Long oldId = sysUsers.getSuId(); + sysUsers.setSuId(null); + sysUsersDao.insert(sysUsers); + shopStaff.put(oldId.toString(), sysUsers.getSuId().intValue()); + } + + redisClient.saveMapValue("shop_staff", shopStaff); + } + + @DS("slave") + public List<MoneyCardUse> moneyCardUseOld() { + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from money_card_use"); + List<MoneyCardUse> moneyCardUses = mapsToListBean(maps, MoneyCardUse.class); + + Map<String, Integer> goodCzk = getRedisIds("shopping_goods_czk"); + Map<String, Integer> vipInfos = getRedisIds("vip_info"); + for (MoneyCardUse moneyCardUse : moneyCardUses) { + moneyCardUse.setIsVipCar("N"); + + ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(moneyCardUse.getGoodsId()); + if (shoppingGoods != null) + { moneyCardUse.setCardName(shoppingGoods.getName());} + + Integer vipId = null; + if (moneyCardUse.getVipId() != null) { + vipId = vipInfos.get(moneyCardUse.getVipId().toString()); + if (vipId != null) { + moneyCardUse.setVipId(vipId.longValue()); + } else { + moneyCardUse.setVipId(-moneyCardUse.getVipId()); + } + } + + if (moneyCardUse.getGoodsId() != null) { + Integer goodsId = goodCzk.get(moneyCardUse.getGoodsId().toString()); + if (goodsId != null) { + moneyCardUse.setGoodsId(goodsId.longValue()); + } else { + moneyCardUse.setGoodsId(-moneyCardUse.getGoodsId()); + } + } + } + + return moneyCardUses; + } + + @Transactional(rollbackFor = Exception.class) + public void moneyCardUseNew(List<MoneyCardUse> list) { + if (CollUtil.isNotEmpty(list)) { + for (MoneyCardUse moneyCardUse : list) { + moneyCardUse.setId(null); + moneyCardUse.setSource("美度-数据迁移"); + moneyCardUseDao.insert(moneyCardUse); + } + } + } + + + @Transactional(rollbackFor = Exception.class) + public void tyOrderAndAchieveMove() { + jdbcTemplate.update("update sys_order set orderType=1, is_has_refund=2 where 1=1"); + + List<SysOrderFlow> flows = sysOrderFlowDao.selectOrderFlowByType(); + if (CollUtil.isNotEmpty(flows)) { + for (SysOrderFlow flow : flows) { + SysOrder sysOrder = sysOrderDao.selectById(flow.getOrderId()); + sysOrder.setIsHasRefund(1); + sysOrderDao.update(sysOrder); + } + } + + List<AchieveNew> achieveNews = achieveNewDao.selectAchieveForOrder(); + if (CollUtil.isNotEmpty(achieveNews)) { + for (AchieveNew achieveNew : achieveNews) { + if ("现金业绩".equalsIgnoreCase(achieveNew.getAchieveType())) { + achieveNew.setPayMethod("现金"); + } else { + achieveNew.setPayMethod("划扣"); + } + +// if (achieveNew.getConsume() == null) { +// achieveNew.setPayMethod("现金"); +// } else { +// achieveNew.setPayMethod("划扣"); +// } + achieveNew.setAchieveType("顾问业绩"); + achieveNew.setGoodsCash(Double.parseDouble(achieveNew.getT1())); + achieveNewDao.updateByModel(achieveNew); + } + + } + + } + + + @DS("slave") + public Map<String, List<Long>> roleOld() { + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select a.id, a.name, a.role_id, b.role_name from users a inner join sys_role b on find_in_set(b.role_id, a.role_id)"); + + List<Long> jkgw = new ArrayList<>(); + List<Long> mls = new ArrayList<>(); + for (Map<String, Object> map : maps) { + String roleName = map.get("role_name").toString(); + + if ("健康顾问".equals(roleName)) { + jkgw.add((Long) map.get("id")); + } else { + mls.add((Long) map.get("id")); + } + } + + Map<String, List<Long>> result = new HashMap<>(); + result.put("jkgw", jkgw); + result.put("mls", mls); + return result; + } + + public void roleNew(Map<String, List<Long>> role) { + List<Long> jkgw = role.get("jkgw"); + List<Long> mls = role.get("mls"); + Map<String, Integer> sysUsersMap = getRedisIds("sys_users"); + + for (Long aLong : jkgw) { + Integer id = sysUsersMap.get(aLong.toString()); + SysUsers sysUsers = new SysUsers(); + sysUsers.setSuId(id.longValue()); + sysUsers.setRoleIds("56"); + sysUsersDao.updateByModel(sysUsers); + } + + for (Long ml : mls) { + Integer id = sysUsersMap.get(ml.toString()); + SysUsers sysUsers = new SysUsers(); + sysUsers.setSuId(id.longValue()); + sysUsers.setRoleIds("55"); + sysUsersDao.updateByModel(sysUsers); + } + + } + + @DS("slave") + public Map<String, String> roleOld2() { + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_shopstaff_info where find_in_set('美疗师', POST_TYPE_NAME) or find_in_set('健康顾问', POST_TYPE_NAME)"); + Map<String, String> result = new HashMap<>(); + for (Map<String, Object> map : maps) { + + result.put(map.get("id").toString(), map.get("POST_TYPE_NAME").toString()); + } + + return result; + } + + public void roleNew2(Map<String, String> map) { + + Map<String, Integer> shopStaff = getRedisIds("shop_staff"); + for (Map.Entry<String, String> entry : map.entrySet()) { + String id = entry.getKey(); + Integer newId = shopStaff.get(id); + + SysUsers sysUsers = new SysUsers(); + sysUsers.setSuId(newId.longValue()); + if (entry.getValue().contains("健康顾问,")) { + sysUsers.setRoleIds("56"); + } + + if (entry.getValue().contains("美疗师,")) { + sysUsers.setRoleIds("55"); + } + + if (entry.getValue().contains("健康顾问,美疗师,")) { + sysUsers.setRoleIds("55,56"); + } + + sysUsersDao.updateByModel(sysUsers); + } + } + + public void updateServiceOrderStaff() { + Map<String, Integer> shopStaff = getRedisIds("shop_staff"); + + List<SysBeauticianState> sysBeauticianStates = sysBeauticianStateDao.selectByModel(null); + for (SysBeauticianState state : sysBeauticianStates) { + Long staffId = state.getStaffId(); + + if (staffId == null) { + continue; + } + Integer integer = shopStaff.get(staffId.toString()); + + if (integer == null) { + state.setStaffId(-staffId); + } else { + state.setStaffId(integer.longValue()); + } + sysBeauticianStateDao.update(state); + } + } + + public void updateVipInfoStaff() { + Map<String, Integer> shopStaff = getRedisIds("shop_staff"); + + List<SysVipInfo> sysVipInfos = sysVipInfoDao.selectStaff(); + + for (SysVipInfo sysVipInfo : sysVipInfos) { + Long staffId = sysVipInfo.getStaffId(); + + Integer integer = shopStaff.get(staffId.toString()); + if (integer == null) { + continue; + } + + SysVipInfo update = new SysVipInfo(); + update.setStaffId(integer.longValue()); + update.setId(sysVipInfo.getId()); + sysVipInfoDao.update(update); + } + } + + @Transactional + public void updateVipInfoStaff(List<SysVipInfo> sysVipInfos) { + Map<String, Integer> shopStaff = getRedisIds("shop_staff"); + + for (SysVipInfo sysVipInfo : sysVipInfos) { + if (sysVipInfo.getStaffId() == null) { + continue; + } + + Integer integer = shopStaff.get(sysVipInfo.getStaffId().toString()); + if (integer == null) { + continue; + } + + SysVipInfo exist = sysVipInfoDao.selectByPhone(sysVipInfo.getPhone()); + if (exist.getStaffId() == integer.longValue()) { + continue; + } + + sysVipInfoDao.updateStaffIdByPhone(integer.longValue(), sysVipInfo.getPhone()); + } + } + + @Transactional(rollbackFor = Exception.class) + public void updateProjUseIsCourse() { + List<SysProjUse> sysProjUses = sysProjUseDao.selectProjUse(); + + for (SysProjUse sysProjUs : sysProjUses) { + ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(sysProjUs.getProjId()); + + SysProjUse update = new SysProjUse(); + + if (shoppingGoods == null) { + continue; + } + + if ("Y".equals(shoppingGoods.getIsCourse())) { + update.setIsCourse("Y"); + } else { + continue; + } + + update.setId(sysProjUs.getId()); + sysProjUseDao.update(update); + } + } + + @DS("slave") + public List<SysUsers> fixSysUsersOld() throws UnsupportedEncodingException, NoSuchAlgorithmException { + List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from sys_shopstaff_info"); + + Map<String, Integer> shopMap = getRedisIds("shopId"); + List<SysUsers> list = new ArrayList<>(); + for (Map<String, Object> map : maps) { + SysUsers sysUsers = new SysUsers(); + sysUsers.setSuAccount((String) map.get("staff_no")); + sysUsers.setSuId((Long) map.get("id")); + sysUsers.setSuName((String) map.get("staff_name")); + sysUsers.setSuSex((String) map.get("sex")); + sysUsers.setSuUserType("employee"); + sysUsers.setSuAccountStatus(AppConstance.ACCOUNT_STATUS_INACTIVATED); + sysUsers.setSuValid("Y"); + sysUsers.setCompanyId(companyId); + Long aaa = (Long) map.get("shop_id"); + if (aaa != null) { + Integer shopId = shopMap.get(aaa.toString()); + if (shopId != null) { + sysUsers.setShopId(Long.parseLong(shopId.toString())); + } + } + sysUsers.setSuRegisterTime(new Date()); + 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 fixSysUsersNew(List<SysUsers> list) { + Map<String, Integer> shopStaff = getRedisIds("shop_staff"); + + for (SysUsers sysUsers : list) { + SysUsers exist = sysUsersDao.selectSysUsersByName(sysUsers.getSuName()); + if (exist != null) { + continue; + } + + Integer newId = shopStaff.get(sysUsers.getSuId().toString()); + sysUsers.setSuId(newId.longValue()); + sysUsers.setCreateBy(AppConstance.SYSTEM_USER); + sysUsers.setUpdateBy(AppConstance.SYSTEM_USER); + sysUsersDao.insert(sysUsers); + } + + } + + + @Transactional(rollbackFor = Exception.class) + public void fixShoppingGoods() { + List<ShoppingGoodsAssemble> shoppingGoodsAssembles = shoppingGoodsAssembleDao.selectProjIdNotNull(); + + for (ShoppingGoodsAssemble shoppingGoodsAssemble : shoppingGoodsAssembles) { + Map<String, Object> map = shoppingGoodsAssembleDao.selectProjInfoById(shoppingGoodsAssemble.getAssembleProjId()); + + String proj_name = map.get("PROJ_NAME").toString(); + ShoppingGoods exist = shoppingGoodsDao.selectByNameAndDesc(proj_name, "数据修复"); + if (exist != null) { + ShoppingGoodsAssemble update = new ShoppingGoodsAssemble(); + update.setId(shoppingGoodsAssemble.getId()); + update.setAssembleGoodId(exist.getId()); + shoppingGoodsAssembleDao.update(update); + continue; + } + + ShoppingGoods shoppingGoods = new ShoppingGoods(); + shoppingGoods.setName(proj_name); + shoppingGoods.setTimeLength(Integer.parseInt(map.get("TIME_LENGTH").toString())); + + shoppingGoods.setCompanyId(companyId); + shoppingGoods.setHeadquarters(1); + shoppingGoods.setIsDel(1); + shoppingGoods.setZjm(StringUtils.toHanyuPinyin(shoppingGoods.getName()) + "," + StringUtils.toHeadWordHanyuPinyin(shoppingGoods.getName())); + + shoppingGoods.setWeiDescription("数据迁移"); + shoppingGoods.setStaus("下架"); + shoppingGoods.setGoodType("项目"); + shoppingGoods.setIsPresent("否"); + shoppingGoods.setIsOnce("0"); + shoppingGoods.setWeiDescription("数据修复"); + + shoppingGoodsDao.insert(shoppingGoods); + + ShoppingGoodsAssemble update = new ShoppingGoodsAssemble(); + update.setId(shoppingGoodsAssemble.getId()); + update.setAssembleGoodId(shoppingGoods.getId()); + shoppingGoodsAssembleDao.update(update); + } + } + } -- Gitblit v1.9.1