码迷,mamicode.com
首页 > 其他好文 > 详细

排课结果基础版本备份

时间:2019-11-22 17:48:28      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:get   back   false   ike   OLE   ace   ack   code   创建失败   

 /**
     * 
     * @Title:paikeJieGuoBackup
     * @author:彭嘉
     * @date:2019年11月13日 上午11:31:14
     * @Description:TODO(排课结果备份)
     * @param pkJieGuoBackUp
     *            --排课结果备份备份表对象
     * @return Map<String,String> <br>
     *         key=> code value=> fail:备份失败,success:备份成功,error:方法出错 <br>
     *         key=> tip value=> 提示信息
     * @throws Exception
     */
    public Map<String, String> paikeJieGuoBackup(PkJieGuoBackUp pkJieGuoBackUp) throws Exception {
        // 需要返回的对象
        Map<String,String> map=new HashMap<String,String>();
        if (QwyUtil.isNullAndEmpty(pkJieGuoBackUp)) {
            logger.info("pkJieGuoBackUp排课结果备份对象为空");
            map.put("code", "fail");
            map.put("tip", "pkJieGuoBackUp排课结果为空");
            return map;
        }
        // 备份类型
        String backupType = QwyUtil.getIsNULL(pkJieGuoBackUp.getType());
        if (QwyUtil.isNullAndEmpty(backupType)) {
            logger.info("backupType备份类型为空");
            map.put("code", "fail");
            map.put("tip", "backupType备份类型为空");
            return map;
        }
        // 排课结果id
        String pkJieGuoId = QwyUtil.getIsNULL(pkJieGuoBackUp.getJieguo_id());
        if (QwyUtil.isNullAndEmpty(pkJieGuoId)) {
            logger.info("pkJieGuoId排课结果为空");
            map.put("code", "fail");
            map.put("tip", "pkJieGuoId排课结果为空");
            return map;
        }

        // 1.获取学校代码
        SystemParameter systemParameter = systemParameterDao.findSystemParameter();
        String schoolCode = systemParameter.getStr("schoolCode");
        logger.info("schoolCode:" + schoolCode);
        // 备份数据库的名称
        String dbName = "";
        // 备份数据库是否存在
        boolean isExistDB = false;
        if (!QwyUtil.isNullAndEmpty(schoolCode)) {
            dbName = schoolCode + "_pk_jieguo_backup_db";
        } else {
            logger.info("schoolCode学校代码为空");
            map.put("code", "fail");
            map.put("tip", "schoolCode学校代码为空");
            return map;
        }

        isExistDB = pkjgBackUpDao.isExistDB(dbName);
        logger.info("排课结果备份数据库是否存在:" + isExistDB);
        // 2.判断数据库是否存在
        if (!isExistDB) {
            // 数据库不存在,创建数据库
            boolean isCreateSuccess = pkjgBackUpDao.createPkJieGuoBackUpDB(schoolCode);
            logger.info("排课结果备份数据库是否创建成功:" + isCreateSuccess);
            if (isCreateSuccess) {
                // 备份库创建成功将isExistDB改为true
                isExistDB = true;
            } else {
                // 创建失败
                logger.info("排课结果备份数据库创建失败");
                map.put("code", "fail");
                map.put("tip", "排课结果备份数据库创建失败");
                return map;
            }
        }
        // 3.判断排课结果备份表是否存在
        boolean isExistBackUpTable = pkjgBackUpDao.isExistTable(dbName, "pk_jieguo_backup");
        logger.info("排课结果备份表是否存在: " + isExistBackUpTable);
        // 不存在创建
        if (!isExistBackUpTable) {
            boolean isSuccessCreateBackUpTable = pkjgBackUpDao.createBackUpTable(dbName);
            logger.info("排课结果备份表是否创建成功: " + isSuccessCreateBackUpTable);
            if (!isSuccessCreateBackUpTable) {
                map.put("code", "fail");
                map.put("tip", "排课结果备份表创建失败");
                return map;
            }

        }
        // 4.判断是否备份
        synchronized (pkJieGuoId) {
            Boolean isBackUp = false;
            if ("0".equals(backupType)) {
                isBackUp = pkjgBackUpDao.isBackUpPaikeJieGuo(dbName, pkJieGuoId, backupType, null);
            } else {
                isBackUp = pkjgBackUpDao.isBackUpPaikeJieGuo(dbName, pkJieGuoId, backupType,
                    pkJieGuoBackUp.getBf_jieguo_name());
            }

            logger.info("是否备份过: " + isBackUp);
            if (isBackUp) {// 备份过不需要再次备份
                map.put("code", "success");
                map.put("tip", "已经备份过,请不要重复备份");
                return map;
            } else {// 没有备份开始备份
                // 在排课结果备份表保存一条备份记录
                String pkJieGuoBackupId = pkjgBackUpDao.pkJieGuoBackupSava(pkJieGuoBackUp, dbName);
                logger.info("排课结果备份表的新增记录id:" + pkJieGuoBackupId);
                boolean isSava = !QwyUtil.isNullAndEmpty(pkJieGuoBackupId);
                logger.info("排课结果备份记录是否保存成功: " + isSava);
                // 备份记录保存成功
                if (isSava) {
                    // 排课结果备份记录保存成功后,备份排课结果详情

                    // 排课结果详情备份表的表名
                    String pjd_backup_table_name = "pk_jieguo_detail_backup_" + pkJieGuoId.replace("-", "_");

                    // 判断排课结果详情备份表是否存在
                    boolean isCreatePjdBackupTable = pkjgBackUpDao.isExistTable(dbName, pjd_backup_table_name);
                    logger.info("排课结果详情备份表是否存在:" + isCreatePjdBackupTable);
                    // 排课结果详情备份表备份
                    boolean backupPkJieGuoDetail = pkjgBackUpDao.backupPkJieGuoDetail(isCreatePjdBackupTable, dbName,
                        pkJieGuoBackupId, pkJieGuoId);
                    logger.info("排课结果详情备份是否成功:" + backupPkJieGuoDetail);
                    if (backupPkJieGuoDetail) {
                        map.put("code", "success");
                        map.put("tip", "备份成功");
                        return map;
                    } else {
                        map.put("code", "fail");
                        map.put("tip", "排课结果详情备份失败");
                        return map;
                    }

                } else {
                    map.put("code", "fail");
                    map.put("tip", "排课结果备份表保存记录失败");
                    return map;
                }
            }
        }

    }

 

排课结果基础版本备份

标签:get   back   false   ike   OLE   ace   ack   code   创建失败   

原文地址:https://www.cnblogs.com/mjtabu/p/11913018.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!