whycxzp
2022-01-12 39ea9c6918f33c37ddd0441a7e98f6fc9aec8662
src/main/java/com/whyc/service/ClearTableService.java
@@ -1,10 +1,11 @@
package com.whyc.service;
import com.whyc.dto.TableDTO;
import com.whyc.mapper.ClearTableMapper;
import com.whyc.pojo.User_inf;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;
@Service
@@ -14,9 +15,168 @@
    private ClearTableMapper mapper;
    public void clearTable(){
        List<User_inf> userInfList = mapper.clearTable();
        System.out.println(userInfList);
        System.out.println("清除表完成");
        List<TableDTO> tableList = new LinkedList<>();
        //传入需要清空的表对应的库名,表名
        tableList.add(new TableDTO("db_alarm","tb_battalarm_data"));
        tableList.add(new TableDTO("db_alarm","tb_battalarm_data_history"));
        tableList.add(new TableDTO("db_alarm","tb_bts_station_event"));
        tableList.add(new TableDTO("db_alarm","tb_devalarm_data"));
        tableList.add(new TableDTO("db_alarm","tb_devalarm_data_history"));
        tableList.add(new TableDTO("db_app_sys","tb_app_bts_battgroup"));
        tableList.add(new TableDTO("db_app_sys","tb_app_bts_comm_task"));
        tableList.add(new TableDTO("db_app_sys","tb_dashboard_chart_type"));
        tableList.add(new TableDTO("db_app_sys","tb_dashboard_module"));
        tableList.add(new TableDTO("db_app_sys","tb_dashboard_module_chart"));
        tableList.add(new TableDTO("db_app_sys","tb_fbsdev_statechange_inf"));
        tableList.add(new TableDTO("db_batt_history","tb_btsstaechange_inf"));
        tableList.add(new TableDTO("db_batt_testdata","tb_battresdata_inf"));
        tableList.add(new TableDTO("db_batt_testdata","tb_batttestdata_inf"));
        tableList.add(new TableDTO("db_battinf","tb_batt_alm_param"));
        tableList.add(new TableDTO("db_battinf","tb_batt_maint_inf"));
        tableList.add(new TableDTO("db_battinf","tb_batt_maint_process"));
        tableList.add(new TableDTO("db_battinf","tb_battcurr_inf"));
        tableList.add(new TableDTO("db_battinf","tb_battinf"));
        tableList.add(new TableDTO("db_battinf","tb_battinf_apply"));
        tableList.add(new TableDTO("db_battinf","tb_battinf_ex"));
        tableList.add(new TableDTO("db_battinf","tb_battinf_rebuild"));
        tableList.add(new TableDTO("db_battinf","tb_battmon_testcap"));
        tableList.add(new TableDTO("db_battinf","tb_deverror_record"));
        tableList.add(new TableDTO("db_ld9_testdata","tb_ld9testdata_inf"));
        tableList.add(new TableDTO("db_param","tb_alarm_param"));
        tableList.add(new TableDTO("db_param","tb_dev_param"));
        tableList.add(new TableDTO("db_pwrdev_alarm","tb_pwrdev_alarm"));
        tableList.add(new TableDTO("db_pwrdev_alarm","tb_pwrdev_alarm_history"));
        tableList.add(new TableDTO("db_pwrdev_alarm","tb_pwrdev_alarm_param"));
        tableList.add(new TableDTO("db_pwrdev_alarm","tb_pwrdev_time_adj_alarm"));
        tableList.add(new TableDTO("db_pwrdev_alarm","tb_pwrdev_time_out_alarm"));
        tableList.add(new TableDTO("db_pwrdev_data_history","tb_pwrdev_acdata"));
        tableList.add(new TableDTO("db_pwrdev_data_rt","tb_pwrdev_acdcdata"));
        tableList.add(new TableDTO("db_pwrdev_data_rt","tb_pwrdev_dcdata"));
        tableList.add(new TableDTO("db_pwrdev_inf","tb_pwrdev_inf"));
        tableList.add(new TableDTO("db_ram_db","cmcc_power_data"));
        tableList.add(new TableDTO("db_ram_db","tb_61850_jhstate"));
        tableList.add(new TableDTO("db_ram_db","tb_batt_rsalarm"));
        tableList.add(new TableDTO("db_ram_db","tb_batt_rtalarm"));
        tableList.add(new TableDTO("db_ram_db","tb_batt_rtdata"));
        tableList.add(new TableDTO("db_ram_db","tb_batt_rtstate"));
        tableList.add(new TableDTO("db_ram_db","tb_bpm7100_state"));
        tableList.add(new TableDTO("db_ram_db","tb_bts_gprs_state"));
        tableList.add(new TableDTO("db_ram_db","tb_bts_station_state"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100_battparam"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100_chargerstate"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100_collectionstate"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100_insulatstate"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100_offlineyhplan"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100_offlineyhplan"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100_state"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100_sysparam"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100s_dcdc_state"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100s_dfu_state"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100s_fod_param"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100s_fod_state"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9100s_nibian_state"));
        tableList.add(new TableDTO("db_ram_db","tb_fbs9600_state"));
        tableList.add(new TableDTO("db_ram_db","tb_hard_dev_sms_state"));
        tableList.add(new TableDTO("db_ram_db","tb_ld9_concentrateparam"));
        tableList.add(new TableDTO("db_ram_db","tb_ld9_concentratestate"));
        tableList.add(new TableDTO("db_ram_db","tb_ld9_setparam"));
        tableList.add(new TableDTO("db_ram_db","tb_ld9_state"));
        tableList.add(new TableDTO("db_ram_db","tb_ld9_updatestatue"));
        tableList.add(new TableDTO("db_ram_db","tb_lithium_data"));
        tableList.add(new TableDTO("db_ram_db","tb_socketclient_state"));
        tableList.add(new TableDTO("db_user","tb_user_battgroup_baojigroup_battgroup"));
        tableList.add(new TableDTO("db_user","tb_user_battmaint_check"));
        tableList.add(new TableDTO("db_user","tb_user_battmaint_check_process"));
        tableList.add(new TableDTO("db_user","tb_user_face"));
        tableList.add(new TableDTO("db_user","tb_user_jiejiari"));
        tableList.add(new TableDTO("db_user","tb_user_limit"));
        tableList.add(new TableDTO("db_user","tb_user_log"));
        tableList.add(new TableDTO("db_user","tb_user_paixiu"));
        tableList.add(new TableDTO("db_user","tb_user_sms"));
        tableList.add(new TableDTO("db_user","tb_user_sms_format"));
        tableList.add(new TableDTO("db_user","tb_user_task"));
        tableList.add(new TableDTO("db_user","tb_user_task_batt_check"));
        tableList.add(new TableDTO("db_user","tb_user_task_batt_template"));
        tableList.add(new TableDTO("db_user","tb_user_task_batt_test"));
        tableList.add(new TableDTO("db_user","tb_user_task_change"));
        tableList.add(new TableDTO("db_user","tb_user_task_param"));
        tableList.add(new TableDTO("db_user","tb_user_task_template"));
        tableList.add(new TableDTO("db_user","tb_user_task_user_list"));
        tableList.add(new TableDTO("web_site","mac_license"));
        tableList.add(new TableDTO("web_site","tb_3d_station"));
        tableList.add(new TableDTO("web_site","tb_announce"));
        tableList.add(new TableDTO("web_site","tb_avoid_plan"));
        tableList.add(new TableDTO("web_site","tb_badbatt_mon"));
        tableList.add(new TableDTO("web_site","tb_badbatt_mon_flag"));
        tableList.add(new TableDTO("web_site","tb_batt_attention"));
        tableList.add(new TableDTO("web_site","tb_batt_devdischarge_cm"));
        tableList.add(new TableDTO("web_site","tb_batt_devdischarge_cm1"));
        tableList.add(new TableDTO("web_site","tb_batt_devdischarge_ct"));
        tableList.add(new TableDTO("web_site","tb_batt_devdischarge_ct1"));
        tableList.add(new TableDTO("web_site","tb_batt_devdischarge_cu"));
        tableList.add(new TableDTO("web_site","tb_batt_devdischarge_cu1"));
        tableList.add(new TableDTO("web_site","tb_batt_discharge"));
        tableList.add(new TableDTO("web_site","tb_batt_electricity"));
        tableList.add(new TableDTO("web_site","tb_batt_electricity1"));
        tableList.add(new TableDTO("web_site","tb_batt_electricity2"));
        tableList.add(new TableDTO("web_site","tb_batt_endurance"));
        tableList.add(new TableDTO("web_site","tb_batt_replace"));
        tableList.add(new TableDTO("web_site","tb_battdischarge_plan"));
        tableList.add(new TableDTO("web_site","tb_battinf_change"));
        tableList.add(new TableDTO("web_site","tb_battmap_information"));
        tableList.add(new TableDTO("web_site","tb_battpower_off"));
        tableList.add(new TableDTO("web_site","tb_dev_restart_plan"));
        tableList.add(new TableDTO("web_site","tb_devstate_usr"));
        tableList.add(new TableDTO("web_site","tb_devtmp_record"));
        tableList.add(new TableDTO("web_site","tb_stationtraffic"));
        tableList.add(new TableDTO("web_site","tb_database_backup"));
        tableList.add(new TableDTO("db_analysis","tb_mon_cap"));
        tableList.add(new TableDTO("db_analysis","tb_mon_res"));
        tableList.add(new TableDTO("db_analysis","tb_mon_tmp"));
        tableList.add(new TableDTO("db_analysis","tb_mon_vol"));
        //进行一次过滤,查询出来所有的库中表
        List<TableDTO> tableList2 = mapper.findAllTables();
        for (int i = 0; i < tableList.size(); i++) {
            boolean compareFlag = false;
            for (int j = 0; j < tableList2.size(); j++) {
                if((tableList.get(i).getDbName()+tableList.get(i).getTableName())
                .equals(tableList2.get(j).getDbName()+tableList2.get(j).getTableName())){
                    compareFlag = true;
                    break;
                }
            }
            //匹配ok
            if(!compareFlag){
                tableList.remove(i);
                i--;
            }
        }
        mapper.clearTable(tableList);
    }
    public void dropTable(){
        List<TableDTO> tableList = new LinkedList<>();
        tableList.add(new TableDTO("db_batt_history","tb_batt_realdata_"));
        tableList.add(new TableDTO("db_pwrdev_alarm","tb_pwrdev_alarm_param_"));
        tableList.add(new TableDTO("db_pwrdev_data_history","tb_pwrdev_historydata_"));
        tableList.add(new TableDTO("db_pwrdev_data_history","tb_pwrdev_historydata_"));
        tableList.add(new TableDTO("db_batt_testdata","tb_battresdata_"));
        tableList.add(new TableDTO("db_batt_testdata","tb_batttestdatastop_"));
        //查询库中需要删除的表名
        List<TableDTO> resTableList = findTableListLike(tableList);
        //传入需要删除的表对应的库名,表名
        if(!resTableList.isEmpty()){
            mapper.dropTable(resTableList);
        }
    }
    private List<TableDTO> findTableListLike(List<TableDTO> tableList) {
        return mapper.findTableListLike(tableList);
    }
    public void clearColumn() {
        mapper.clearColumn();
    }
}