fix
Helius
2021-08-12 4705f9b4084d9ccddb601569b223f0fb41778a94
zq-erp/src/main/java/com/matrix/system/dataMove/DateMoveServiceImpl.java
@@ -5,6 +5,7 @@
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;
@@ -63,7 +64,7 @@
    private RedisClient redisClient;
    private Long companyId = 35L;
    private Long shopId = 38L;
    private Long shopId = 60L;
    public List<Map<String, Object>> dataMove() {
        return jdbcTemplate.queryForList("select * from sys_vip_info limit 10");
@@ -103,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 {
@@ -121,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);
        }
@@ -166,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(rollbackFor = Exception.class)
    public void newSysUsers(List<SysUsers> list) {
    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());
            }
@@ -238,6 +247,7 @@
                    }
                }
                // sys_users 中 id 为 200 的无法找到
                Long staffId = sysVipInfo.getStaffId();
                if (staffId != null) {
                    Object o = sysUsersMap.get(staffId.toString());
@@ -491,6 +501,11 @@
            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);
@@ -658,6 +673,20 @@
                    }
                }
                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);
@@ -671,6 +700,20 @@
                            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());
@@ -742,6 +785,20 @@
                    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");
                    }
                }
@@ -976,6 +1033,9 @@
            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());
@@ -1002,6 +1062,8 @@
                        }
                        flow.setOrderId(sysOrder.getId());
                        flow.setCreateBy("数据迁移");
                        flow.setCreateTime(sysOrder.getCreateTime());
                        flow.setUpdateTime(sysOrder.getUpdateTime());
                        sysOrderFlowDao.insert(flow);
                    }
                }
@@ -1074,7 +1136,7 @@
                                                                            "\t\ta.balance,\n" +
                                                                            "\t\ta.remark,\n" +
                                                                            "        b.name projName,\n" +
                                                                            "        sum(a.SURPLUS_COUNT) SURPLUS_COUNT\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" +
@@ -1379,7 +1441,7 @@
                        serviceItem.setServicesId(newId);
                        Long beautyOldId = serviceItem.getId();
                        serviceItem.setId(null);
                        serviceItem.setExtract("数据迁移");
//                        serviceItem.setExtract("数据迁移");
                        sysBeauticianStateDao.insert(serviceItem);
                        beautyMaps.put(beautyOldId, serviceItem.getId());
                    }
@@ -1473,6 +1535,10 @@
        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());
@@ -1507,4 +1573,307 @@
        }
    }
    @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);
        }
    }
}