Search in sources :

Example 1 with PubConfig

use of com.luastar.swift.tools.model.gui.PubConfig in project swift by luastar.

the class H2Utils method savePubConfig.

/**
 * 保存配置信息
 *
 * @param groupCode
 * @param configCode
 * @param dataContent
 * @return
 */
public static PubConfig savePubConfig(ConfigGroupCode groupCode, ConfigCode configCode, String dataContent) {
    if (groupCode == null || configCode == null || ObjUtils.isEmpty(dataContent)) {
        return null;
    }
    PubConfig pubConfig = new PubConfig();
    pubConfig.setGroup_code(groupCode.getGroupCode());
    pubConfig.setGroup_name(groupCode.getGroupName());
    pubConfig.setConfig_code(configCode.getConfigCode());
    pubConfig.setConfig_name(configCode.getConfigName());
    pubConfig.setData_content(dataContent);
    if (savePubConfig(pubConfig)) {
        return pubConfig;
    } else {
        return null;
    }
}
Also used : PubConfig(com.luastar.swift.tools.model.gui.PubConfig)

Example 2 with PubConfig

use of com.luastar.swift.tools.model.gui.PubConfig in project swift by luastar.

the class H2Utils method savePubConfig.

/**
 * 保存配置信息
 *
 * @param configCode
 * @param dataContent
 * @return
 */
public static PubConfig savePubConfig(ConfigCode configCode, String dataContent) {
    if (configCode == null || ObjUtils.isEmpty(dataContent)) {
        return null;
    }
    PubConfig pubConfig = new PubConfig();
    pubConfig.setConfig_code(configCode.getConfigCode());
    pubConfig.setConfig_name(configCode.getConfigName());
    pubConfig.setData_content(dataContent);
    if (savePubConfig(pubConfig)) {
        return pubConfig;
    } else {
        return null;
    }
}
Also used : PubConfig(com.luastar.swift.tools.model.gui.PubConfig)

Example 3 with PubConfig

use of com.luastar.swift.tools.model.gui.PubConfig in project swift by luastar.

the class H2Utils method getPubConfigMap.

/**
 * 获取一组配置信息
 *
 * @param groupCode
 * @return
 */
public static Map<ConfigCode, PubConfig> getPubConfigMap(ConfigGroupCode groupCode) {
    try {
        if (groupCode == null) {
            return null;
        }
        String sql = "SELECT * FROM PUB_CONFIG WHERE GROUP_CODE=?";
        List<PubConfig> configList = getInstance().getQueryRunner().query(sql, new BeanListHandler<>(PubConfig.class), groupCode.getGroupCode());
        if (ObjUtils.isEmpty(configList)) {
            return null;
        }
        Map<ConfigCode, PubConfig> resMap = Maps.newHashMap();
        for (PubConfig config : configList) {
            ConfigCode configCode = ConfigCode.parse(config.getConfig_code());
            if (configCode == null) {
                continue;
            }
            resMap.put(configCode, config);
        }
        return resMap;
    } catch (Exception e) {
        logger.error("获取常用配置异常:" + e.getMessage(), e);
        return null;
    }
}
Also used : ConfigCode(com.luastar.swift.tools.enums.ConfigCode) PubConfig(com.luastar.swift.tools.model.gui.PubConfig) SQLException(java.sql.SQLException)

Example 4 with PubConfig

use of com.luastar.swift.tools.model.gui.PubConfig in project swift by luastar.

the class H2Utils method savePubConfig.

/**
 * 保存配置信息
 *
 * @param pubConfig
 * @return
 */
public static boolean savePubConfig(PubConfig pubConfig) {
    try {
        if (pubConfig == null || ObjUtils.isEmpty(pubConfig.getConfig_code())) {
            logger.warn("需要保存的常用配置编码为空,不保存!");
            return false;
        }
        String querySQL = "SELECT * FROM PUB_CONFIG WHERE CONFIG_CODE=? LIMIT 1";
        PubConfig dbPubConfig = getInstance().getQueryRunner().query(querySQL, new BeanHandler<>(PubConfig.class), pubConfig.getConfig_code());
        if (dbPubConfig == null) {
            // 设置默认值
            pubConfig.setData_sort(ObjUtils.ifNull(pubConfig.getData_sort(), System.currentTimeMillis()));
            pubConfig.setData_status(ObjUtils.ifNull(pubConfig.getData_status(), ConfigStatus.ENABLE.getStatus()));
            pubConfig.setCreate_time(new Date());
            String insertSQL = "INSERT INTO PUB_CONFIG(GROUP_CODE, GROUP_NAME, CONFIG_CODE, CONFIG_NAME, DATA_ID, DATA_TYPE, DATA_CONTENT, DATA_SORT, DATA_STATUS, DATA_P1, DATA_P2, DATA_P3, DATA_P4, DATA_P5, CREATE_TIME) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
            Object[] rsAry = getInstance().getQueryRunner().insert(insertSQL, new ArrayHandler(), pubConfig.getGroup_code(), pubConfig.getGroup_name(), pubConfig.getConfig_code(), pubConfig.getConfig_name(), pubConfig.getData_id(), pubConfig.getData_type(), pubConfig.getData_content(), pubConfig.getData_sort(), pubConfig.getData_status(), pubConfig.getData_p1(), pubConfig.getData_p2(), pubConfig.getData_p3(), pubConfig.getData_p4(), pubConfig.getData_p5(), pubConfig.getCreate_time());
            Integer id = ObjUtils.toInteger(rsAry[0], 0);
            pubConfig.setId(id);
            return id > 0;
        } else {
            // 如果值没有设置,则取数据库中的值
            pubConfig.setGroup_code(ObjUtils.ifNull(pubConfig.getGroup_code(), dbPubConfig.getGroup_code()));
            pubConfig.setGroup_name(ObjUtils.ifNull(pubConfig.getGroup_name(), dbPubConfig.getGroup_name()));
            pubConfig.setConfig_name(ObjUtils.ifNull(pubConfig.getConfig_name(), dbPubConfig.getConfig_name()));
            pubConfig.setData_id(ObjUtils.ifNull(pubConfig.getData_id(), dbPubConfig.getData_id()));
            pubConfig.setData_type(ObjUtils.ifNull(pubConfig.getData_type(), dbPubConfig.getData_type()));
            pubConfig.setData_content(ObjUtils.ifNull(pubConfig.getData_content(), dbPubConfig.getData_content()));
            pubConfig.setData_sort(ObjUtils.ifNull(pubConfig.getData_sort(), dbPubConfig.getData_sort()));
            pubConfig.setData_status(ObjUtils.ifNull(pubConfig.getData_status(), dbPubConfig.getData_status()));
            pubConfig.setData_p1(ObjUtils.ifNull(pubConfig.getData_p1(), dbPubConfig.getData_p1()));
            pubConfig.setData_p2(ObjUtils.ifNull(pubConfig.getData_p2(), dbPubConfig.getData_p2()));
            pubConfig.setData_p3(ObjUtils.ifNull(pubConfig.getData_p3(), dbPubConfig.getData_p3()));
            pubConfig.setData_p4(ObjUtils.ifNull(pubConfig.getData_p4(), dbPubConfig.getData_p4()));
            pubConfig.setData_p5(ObjUtils.ifNull(pubConfig.getData_p5(), dbPubConfig.getData_p5()));
            pubConfig.setUpdate_time(new Date());
            String updateSQL = "UPDATE PUB_CONFIG SET GROUP_CODE=?, GROUP_NAME=?, CONFIG_NAME=?, DATA_ID=?, DATA_TYPE=?, DATA_CONTENT=?, DATA_SORT=?, DATA_STATUS=?, DATA_P1=?, DATA_P2=?, DATA_P3=?, DATA_P4=?, DATA_P5=? WHERE CONFIG_CODE=?";
            return getInstance().getQueryRunner().update(updateSQL, pubConfig.getGroup_code(), pubConfig.getGroup_name(), pubConfig.getConfig_name(), pubConfig.getData_id(), pubConfig.getData_type(), pubConfig.getData_content(), pubConfig.getData_sort(), pubConfig.getData_status(), pubConfig.getData_p1(), pubConfig.getData_p2(), pubConfig.getData_p3(), pubConfig.getData_p4(), pubConfig.getData_p5(), pubConfig.getConfig_code()) > 0;
        }
    } catch (Exception e) {
        logger.error("获取常用配置异常:" + e.getMessage(), e);
        return false;
    }
}
Also used : ArrayHandler(org.apache.commons.dbutils.handlers.ArrayHandler) PubConfig(com.luastar.swift.tools.model.gui.PubConfig) Date(java.util.Date) SQLException(java.sql.SQLException)

Example 5 with PubConfig

use of com.luastar.swift.tools.model.gui.PubConfig in project swift by luastar.

the class MybatisController method initDefaultValue.

/**
 * 设置默认值
 */
private void initDefaultValue() {
    Map<ConfigCode, PubConfig> configMap = H2Utils.getPubConfigMap(ConfigGroupCode.mybatis);
    if (ObjUtils.isEmpty(configMap)) {
        return;
    }
    // 设置默认的数据库
    dbIdCofig = configMap.get(ConfigCode.mybatis_db_id);
    setDbChoiceBoxValue();
    // 设置默认的输出目录
    PubConfig outputConfig = configMap.get(ConfigCode.mybatis_output);
    if (outputConfig != null) {
        outputTextField.setText(outputConfig.getData_content());
    }
    // 设置包名
    PubConfig modelConfig = configMap.get(ConfigCode.mybatis_model_package);
    if (modelConfig != null) {
        modelTextField.setText(modelConfig.getData_content());
    }
    PubConfig daoConfig = configMap.get(ConfigCode.mybatis_dao_package);
    if (daoConfig != null) {
        daoTextField.setText(daoConfig.getData_content());
    }
}
Also used : ConfigCode(com.luastar.swift.tools.enums.ConfigCode) PubConfig(com.luastar.swift.tools.model.gui.PubConfig)

Aggregations

PubConfig (com.luastar.swift.tools.model.gui.PubConfig)5 ConfigCode (com.luastar.swift.tools.enums.ConfigCode)2 SQLException (java.sql.SQLException)2 Date (java.util.Date)1 ArrayHandler (org.apache.commons.dbutils.handlers.ArrayHandler)1