¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.product.data.center.service; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.beust.jcommander.internal.Lists; |
| | | import com.google.common.collect.Maps; |
| | | import com.product.common.lang.StringUtils; |
| | | import com.product.core.dao.BaseDao; |
| | | import com.product.core.entity.DataTableEntity; |
| | | import com.product.core.entity.FieldSetEntity; |
| | | import com.product.core.exception.BaseException; |
| | | import com.product.core.service.support.AbstractBaseService; |
| | | import com.product.core.spring.context.SpringMVCContextHolder; |
| | | import com.product.data.center.config.CmnConst; |
| | | import com.product.data.center.config.ErrorCode; |
| | | import com.product.datasource.dao.Dao; |
| | | import com.product.datasource.entity.DataBaseEntity; |
| | | import com.product.util.BaseUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * å®ç°åè½ï¼ |
| | | * |
| | | * @author ä½è
[å¤ä¸¶å
] |
| | | * @version 1.0.00 2025-08-04 10:48 |
| | | */ |
| | | @Service |
| | | public class SpDealService extends AbstractBaseService { |
| | | @Autowired |
| | | private BaseDao baseDao; |
| | | @Autowired |
| | | private DataArchivingService dataArchivingService; |
| | | @Autowired |
| | | private JournalManagerService journalManagerService; |
| | | |
| | | /*========================请æ±åå²-start========================*/ |
| | | // æ£å¨å¤çæ è¯ |
| | | private static boolean processingFlag = false; |
| | | // 忢æ è¯ |
| | | private static boolean stopFlag = false; |
| | | // æ°æ®åå
¸åç§°-请æ±åå² |
| | | private static final String DICT_NAME_REQUEST_HISTORY = "请æ±åå²ç¹æ®å¤ç"; |
| | | // é¡µå¤§å° |
| | | private static int pageSize = 0; |
| | | // ååºæä½ç表éåï¼éè¦ä»æ°æ®åºä¸è¯»å |
| | | private static List<String> operateTableList = Lists.newArrayList(); |
| | | // æ´æºååºip |
| | | private static String subDbIp = ""; |
| | | // ååºç«¯å£ |
| | | private static int subDbPort = 0; |
| | | // æ¥è¡¨åºip |
| | | private static String reportDbIp = ""; |
| | | // æ¥è¡¨åºç«¯å£ |
| | | private static int reportDbPort = 0; |
| | | |
| | | /** |
| | | * é叏宿¶ä»»å¡è§¦å-忢æ§è¡ |
| | | */ |
| | | public void stopExecute() { |
| | | SpringMVCContextHolder.getSystemLogger().info("[请æ±åå²ç¹æ®å¤ç-忢]"); |
| | | stopFlag = true; |
| | | } |
| | | |
| | | /** |
| | | * é叏宿¶ä»»å¡è§¦å-请æ±åå²ç¹æ®å¤ç-æµè¯æ¹æ³ |
| | | */ |
| | | public void testRequestHistorySpDeal() { |
| | | requestHistorySpDeal(true); |
| | | } |
| | | |
| | | /** |
| | | * é叏宿¶ä»»å¡è§¦å-请æ±åå²ç¹æ®å¤ç |
| | | */ |
| | | public void requestHistorySpDeal() { |
| | | requestHistorySpDeal(false); |
| | | } |
| | | |
| | | /** |
| | | * 请æ±åå²ç¹æ®å¤ç |
| | | */ |
| | | private void requestHistorySpDeal(boolean testFlag) { |
| | | SpringMVCContextHolder.getSystemLogger().info("[请æ±åå²ç¹æ®å¤ç-å¼å§]"); |
| | | if (processingFlag) { |
| | | SpringMVCContextHolder.getSystemLogger().info("[请æ±åå²ç¹æ®å¤ç-æ£å¨è¿è¡-è·³è¿]"); |
| | | return; |
| | | } |
| | | synchronized ("requestHistorySpDeal") { |
| | | DataBaseEntity subDbe = null; |
| | | DataBaseEntity reportDbe = null; |
| | | DataTableEntity waitInsertDte = null; |
| | | try { |
| | | if (processingFlag) { |
| | | return; |
| | | } |
| | | processingFlag = true; |
| | | |
| | | // è·åç¹æ®å¤çä¿¡æ¯ |
| | | JSONObject spDealInfoObj = getSpDealInfo(); |
| | | if (spDealInfoObj.isEmpty()) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_SP_DEAL_INFO); |
| | | } |
| | | String tableFormat = spDealInfoObj.getString("tableFormat"); |
| | | |
| | | // è·åååºåæ¥è¡¨åºè¿æ¥ä¿¡æ¯ |
| | | DataTableEntity dbLinkDte = baseDao.listTable(CmnConst.PRODUCT_SYS_DATA_SYNC_MANAGER, "ip=? OR (ip=? AND port=?)", new Object[]{subDbIp, reportDbIp, reportDbPort}); |
| | | FieldSetEntity subDbFse = null; |
| | | FieldSetEntity reportDbFse = null; |
| | | for (int i = 0; i < dbLinkDte.getRows(); i++) { |
| | | FieldSetEntity singleFse = dbLinkDte.getFieldSetEntity(i); |
| | | if (subDbIp.equals(singleFse.getString("ip")) && !StringUtils.isEmpty(singleFse.getString("port")) && subDbPort == singleFse.getInteger("port")) { |
| | | subDbFse = singleFse; |
| | | } else if (reportDbIp.equals(singleFse.getString("ip")) && !StringUtils.isEmpty(singleFse.getString("port")) && reportDbPort == singleFse.getInteger("port")) { |
| | | reportDbFse = singleFse; |
| | | } |
| | | } |
| | | if (subDbFse == null || reportDbFse == null) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_DB_LINK_INFO); |
| | | } |
| | | |
| | | // è·åååºå¯¹åºè¡¨çä¿¡æ¯ï¼è¡¨åï¼ä¸»é®åæ®µï¼æ¶é´å段 |
| | | JSONObject subDbTableInfoObj = getSubDbTableInfo(subDbFse.getUUID()); |
| | | if (subDbTableInfoObj.isEmpty()) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_INFO); |
| | | } |
| | | |
| | | // è·åè¿æ¥ |
| | | subDbe = new DataBaseEntity(subDbFse); |
| | | reportDbe = new DataBaseEntity(reportDbFse); |
| | | |
| | | // æä¸»é®æåºï¼å页æåååºæ°æ®ï¼å¯¹æ¯æ¥è¡¨åºæ°æ®ï¼ä¸åå¨åæå
¥ |
| | | if (!stopFlag) { |
| | | int curMaxMasterKeyValue = 0; |
| | | outer: for (String tableNameStr : operateTableList) { |
| | | SpringMVCContextHolder.getSystemLogger().info("[请æ±åå²ç¹æ®å¤ç-æ°æ®å¤ç-å¼å§]-" + tableNameStr); |
| | | int index = 0; |
| | | JSONObject singleSubDbTableInfoObj = subDbTableInfoObj.getJSONObject(tableNameStr); |
| | | // ééé
置表id |
| | | String sourceInfo = singleSubDbTableInfoObj.getString(CmnConst.ID); |
| | | String tableName = String.format(tableFormat, tableNameStr); |
| | | String reportTableNamePrefix = String.format("da_%s", tableNameStr); |
| | | String orderBy = singleSubDbTableInfoObj.getString("auto_field"); |
| | | DataArchivingService.DataArchivingServiceImpl createTableService = getDDLService(tableName, subDbe, reportDbe); |
| | | String masterKeyFieldName = singleSubDbTableInfoObj.getString("auto_field"); |
| | | long initId = spDealInfoObj.getJSONObject(tableNameStr) == null ? 0 : spDealInfoObj.getJSONObject(tableNameStr).getIntValue("dealt_max_id"); |
| | | long curId = initId; |
| | | int count; |
| | | int totalCount = 0; |
| | | // ç»è®¡é¡µæ°ï¼æ¯å¤å°é¡µè®°å½ä¸æ¬¡æå¤§id |
| | | int statisticsPage = 10; |
| | | if (!testFlag) { |
| | | do { |
| | | index++; |
| | | if (stopFlag) { |
| | | break outer; |
| | | } |
| | | DataTableEntity singlePageDataDte; |
| | | try { |
| | | singlePageDataDte = subDbe.getDao().getList(tableName, null, masterKeyFieldName + ">?", new Object[]{curId}, orderBy, 1, pageSize); |
| | | } catch (Exception e) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_WITH_SUB_DB_DATA.getValue(), ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_WITH_SUB_DB_DATA.getText() + ":" + e.getMessage()); |
| | | } |
| | | count = singlePageDataDte.getRows(); |
| | | if (count > 0) { |
| | | curMaxMasterKeyValue = singlePageDataDte.getFieldSetEntity(singlePageDataDte.getRows() - 1).getInteger(singleSubDbTableInfoObj.getString("auto_field")); |
| | | curId = curMaxMasterKeyValue; |
| | | Map<String, Map<String, FieldSetEntity>> monthMap = Maps.newHashMap(); |
| | | dealSubDbData(singlePageDataDte, singleSubDbTableInfoObj, monthMap); |
| | | |
| | | // æ£æ¥æ¯å¦ææè¡¨é½åå¨ï¼è¥æ¯ä¸åå¨ï¼é£ä¹å建 |
| | | checkTableIfNoThenCreate(monthMap.keySet(), reportTableNamePrefix, createTableService); |
| | | |
| | | String querySql = joinReportDbQuerySql(monthMap, reportTableNamePrefix, sourceInfo); |
| | | DataTableEntity reportDbExistsDte = reportDbe.getDao().getList(querySql); |
| | | for (int i = 0; i < reportDbExistsDte.getRows(); i++) { |
| | | FieldSetEntity reportDbExistsFse = reportDbExistsDte.getFieldSetEntity(i); |
| | | for (Map<String, FieldSetEntity> singleMonthMap : monthMap.values()) { |
| | | singleMonthMap.remove(reportDbExistsFse.getString("pre_master_key")); |
| | | } |
| | | } |
| | | for (Map.Entry<String, Map<String, FieldSetEntity>> entry : monthMap.entrySet()) { |
| | | String insertTableName = String.format("%s_%s", reportTableNamePrefix, entry.getKey()); |
| | | waitInsertDte = getSingleMonthInsertDte(entry.getValue(), insertTableName, sourceInfo); |
| | | reportDbe.getDao().addBatch(waitInsertDte); |
| | | totalCount += waitInsertDte.getRows(); |
| | | } |
| | | if (index % statisticsPage == 0) { |
| | | // æ´æ°å½åæä½ç表ç»è®¡æ¥å¿ä¿¡æ¯ï¼æ¯æå®é¡µæ°æ´æ°ä¸æ¬¡ |
| | | updateOperateTableInfo(tableNameStr, initId, curMaxMasterKeyValue, totalCount); |
| | | } |
| | | } |
| | | } while (count > 0); |
| | | if (index % statisticsPage != 0) { |
| | | // æ´æ°å½åæä½ç表ç»è®¡æ¥å¿ä¿¡æ¯ï¼è¥æ¯ä¸æ¯åæ°ï¼é£ä¹éè¦é¢å¤æ§è¡ä¸æ¬¡ |
| | | updateOperateTableInfo(tableNameStr, initId, curMaxMasterKeyValue, totalCount); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | recordErrorLog(waitInsertDte, e); |
| | | throw e; |
| | | } finally { |
| | | stop(subDbe, reportDbe); |
| | | SpringMVCContextHolder.getSystemLogger().info("[请æ±åå²ç¹æ®å¤ç-ç»æ]"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è®°å½é误æ¥å¿ |
| | | * @param waitInsertDte çå¾
æå
¥çæ°æ®dte |
| | | * @param e é误 |
| | | */ |
| | | private void recordErrorLog(DataTableEntity waitInsertDte, Exception e) { |
| | | String errorInfo = journalManagerService.getStackTrace(e); |
| | | String groupUUID = UUID.randomUUID().toString(); |
| | | Date curTime = new Date(); |
| | | if (!DataTableEntity.isEmpty(waitInsertDte)) { |
| | | // è®°å½å½åæ¥éçä¿¡æ¯ |
| | | DataTableEntity logDte = new DataTableEntity(); |
| | | for (int i = 0; i < waitInsertDte.getRows(); i++) { |
| | | FieldSetEntity singlePageDataFse = waitInsertDte.getFieldSetEntity(i); |
| | | FieldSetEntity logFse = new FieldSetEntity("product_sys_sp_deal_log"); |
| | | logFse.setValue("content", BaseUtil.fieldSetEntityToJson(singlePageDataFse).toJSONString()); |
| | | logFse.setValue("error", errorInfo); |
| | | logFse.setValue("group_uuid", groupUUID); |
| | | logFse.setValue("created_utc_datetime", curTime); |
| | | logDte.addFieldSetEntity(logFse); |
| | | } |
| | | baseDao.add(logDte); |
| | | } else { |
| | | FieldSetEntity logFse = new FieldSetEntity("product_sys_sp_deal_log"); |
| | | logFse.setValue("content", "éæ°æ®å¤çé¶æ®µåºé"); |
| | | logFse.setValue("error", errorInfo); |
| | | logFse.setValue("group_uuid", groupUUID); |
| | | logFse.setValue("created_utc_datetime", curTime); |
| | | baseDao.add(logFse); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * è·ååææå
¥dte |
| | | * @param singleMonthMap åææ°æ®map |
| | | * @param insertTableName æ¥è¡¨åºè¡¨å |
| | | * @param sourceInfo ééé
置表id |
| | | * @return åæ¹æ¬¡ä¸åæï¼å 为ææå表ï¼å¾
æå
¥çdte |
| | | */ |
| | | private DataTableEntity getSingleMonthInsertDte(Map<String, FieldSetEntity> singleMonthMap, String insertTableName, String sourceInfo) { |
| | | DataTableEntity waitInsertDte = new DataTableEntity(); |
| | | for (Map.Entry<String, FieldSetEntity> entry : singleMonthMap.entrySet()) { |
| | | FieldSetEntity waitInsertFse = entry.getValue(); |
| | | waitInsertFse.setTableName(insertTableName); |
| | | waitInsertFse.setValue("pre_master_key", entry.getKey()); |
| | | waitInsertFse.setValue("source_info", sourceInfo); |
| | | waitInsertDte.addFieldSetEntity(waitInsertFse); |
| | | } |
| | | return waitInsertDte; |
| | | } |
| | | |
| | | /** |
| | | * è·åå建表çservice |
| | | * @param tableName 表åï¼ååºåå²è¡¨è¡¨å |
| | | * @param subDbe ååºæ°æ®åºè¿æ¥å®ä¾ |
| | | * @param reportDbe æ¥è¡¨æ°æ®åºè¿æ¥å®ä¾ |
| | | * @return è½å¤æ§è¡å建表DDLè¯å¥çservice |
| | | */ |
| | | private DataArchivingService.DataArchivingServiceImpl getDDLService(String tableName, DataBaseEntity subDbe, DataBaseEntity reportDbe) { |
| | | Dao sourceDao = subDbe.getDao(); |
| | | Dao targetDao = reportDbe.getDao(); |
| | | String sourceDbName = subDbe.getDbName(); |
| | | String targetDbName = reportDbe.getDbName(); |
| | | return dataArchivingService.new DataArchivingServiceImpl(sourceDao, targetDao, tableName, "requestHistory", sourceDbName, targetDbName); |
| | | } |
| | | |
| | | /** |
| | | * æ£æ¥æ¯å¦ææè¡¨é½åå¨ï¼è¥æ¯ä¸åå¨ï¼é£ä¹å建 |
| | | * @param tableTailSet 表尾ç¼éåï¼æ¶é´ |
| | | * @param reportTableNamePrefix æ¥è¡¨åºè¡¨ååç¼ |
| | | * @param createTableService å建表çservice |
| | | */ |
| | | private void checkTableIfNoThenCreate(Set<String> tableTailSet, String reportTableNamePrefix, DataArchivingService.DataArchivingServiceImpl createTableService) { |
| | | for (String tableTail : tableTailSet) { |
| | | createTableService.createTable(reportTableNamePrefix, tableTail, null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ´æ°å½åæä½ç表çç»è®¡æ¥å¿ä¿¡æ¯ |
| | | * @param tableName 表åï¼ååºæ£å¼è¡¨è¡¨å |
| | | * @param initId æ¬æ¬¡æ§è¡åï¼ééåºæ°æ®åå
¸ä¸åæ°é对åºè¡¨çæå¤§æ§è¡id |
| | | * @param curMaxMasterKeyValue ä»ååºä¸è·åå°çæ¬æ¹æ¬¡æ°æ®æå¤§çid |
| | | * @param operateCount æå
¥æ¥è¡¨åºæ°æ®çæ»æ¡æ° |
| | | */ |
| | | private void updateOperateTableInfo(String tableName, long initId, int curMaxMasterKeyValue, int operateCount) { |
| | | String maxIdDictLabel = String.format("%s_dealt_max_id", tableName); |
| | | String latestTimeDictLabel = String.format("%s_latest_time", tableName); |
| | | String latestOperateCountDictLabel = String.format("%s_latest_operate_count", tableName); |
| | | DataTableEntity dictDte = baseDao.listTable(CmnConst.PRODUCT_SYS_DICT, "dict_name=? AND dict_label IN (?,?,?)", new Object[]{DICT_NAME_REQUEST_HISTORY, maxIdDictLabel, latestTimeDictLabel, latestOperateCountDictLabel}); |
| | | FieldSetEntity maxIdDictFse = null; |
| | | FieldSetEntity latestTimeDictFse = null; |
| | | FieldSetEntity latestOperateCountDictFse = null; |
| | | if (!DataTableEntity.isEmpty(dictDte)) { |
| | | for (int i = 0; i < dictDte.getRows(); i++) { |
| | | FieldSetEntity dictFse = dictDte.getFieldSetEntity(i); |
| | | if (maxIdDictLabel.equals(dictFse.getString("dict_label"))) { |
| | | maxIdDictFse = dictFse; |
| | | } else if (latestTimeDictLabel.equals(dictFse.getString("dict_label"))) { |
| | | latestTimeDictFse = dictFse; |
| | | } else if (latestOperateCountDictLabel.equals(dictFse.getString("dict_label"))) { |
| | | latestOperateCountDictFse = dictFse; |
| | | } |
| | | } |
| | | } |
| | | |
| | | FieldSetEntity newDictFse = new FieldSetEntity(CmnConst.PRODUCT_SYS_DICT); |
| | | newDictFse.setValue("dict_name", DICT_NAME_REQUEST_HISTORY); |
| | | newDictFse.setValue("is_used", 1); |
| | | newDictFse.setValue("sequence", 1); |
| | | newDictFse.setValue("client_type", "Web"); |
| | | newDictFse.setValue("created_utc_datetime", new Date()); |
| | | newDictFse.setValue("created_by", 1); |
| | | |
| | | // æå¤§id |
| | | if (initId < curMaxMasterKeyValue) { |
| | | saveDictFse(maxIdDictFse, newDictFse, maxIdDictLabel, curMaxMasterKeyValue); |
| | | } |
| | | // æè¿æ§è¡æ¶é´ |
| | | saveDictFse(latestTimeDictFse, newDictFse, latestTimeDictLabel, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); |
| | | // æè¿ä¸æ¬¡æ§è¡æ»æ° |
| | | saveDictFse(latestOperateCountDictFse, newDictFse, latestOperateCountDictLabel, operateCount); |
| | | } |
| | | |
| | | /** |
| | | * ä¿å请æ±åå²å¨æ°æ®åå
¸éé¢çåæ°fse |
| | | * @param saveDictFse éè¦ä¿ådictçfse |
| | | * @param modelDictFse 模æ¿fse |
| | | * @param dictLabel æ ç¾ |
| | | * @param dictValue å¼ |
| | | */ |
| | | private void saveDictFse(FieldSetEntity saveDictFse, FieldSetEntity modelDictFse, String dictLabel, Object dictValue) { |
| | | if (saveDictFse == null) { |
| | | saveDictFse = modelDictFse.clones(); |
| | | saveDictFse.setValue("dict_label", dictLabel); |
| | | } else { |
| | | saveDictFse.setValue("updated_utc_datetime", new Date()); |
| | | saveDictFse.setValue("updated_by", 1); |
| | | } |
| | | saveDictFse.setValue("dict_value", dictValue); |
| | | baseDao.saveFieldSetEntity(saveDictFse); |
| | | } |
| | | |
| | | /** |
| | | * æ¼æ¥æ¥è¡¨åºæ¥è¯¢è¯å¥ |
| | | * @param monthMap æä»½map |
| | | * @param reportTableNamePrefix æ¥è¡¨åºè¡¨ååç¼ |
| | | * @param sourceInfo éé表id |
| | | * @return æ¥è¡¨åºæ¥è¯¢è¯å¥ |
| | | */ |
| | | private String joinReportDbQuerySql(Map<String, Map<String, FieldSetEntity>> monthMap, String reportTableNamePrefix, String sourceInfo) { |
| | | StringBuilder sql = new StringBuilder(128); |
| | | String model = "SELECT * FROM %s_%s WHERE source_info='%s' AND %s"; |
| | | for (Map.Entry<String, Map<String, FieldSetEntity>> entry : monthMap.entrySet()) { |
| | | String month = entry.getKey(); |
| | | Set<String> masterKeySet = entry.getValue().keySet(); |
| | | if (sql.length() > 0) { |
| | | sql.append("\nUNION ALL\n"); |
| | | } |
| | | sql.append(String.format(model, reportTableNamePrefix, month, sourceInfo, BaseUtil.buildQuestionMarkFilter("pre_master_key", masterKeySet.toArray(), true))); |
| | | } |
| | | return sql.toString(); |
| | | } |
| | | |
| | | /** |
| | | * è·åååºå¯¹åºè¡¨çä¿¡æ¯ï¼è¡¨åï¼ä¸»é®åæ®µï¼æ¶é´å段ç |
| | | * @param subDbUuid ååºè¿æ¥é
置表uuid |
| | | * @return JSONObject ååºå¯¹åºè¡¨çä¿¡æ¯ |
| | | */ |
| | | private JSONObject getSubDbTableInfo(String subDbUuid) { |
| | | String filter = String.format("data_source=? AND %s", BaseUtil.buildQuestionMarkFilter("source_table", operateTableList.size(), true)); |
| | | List<String> paramList = Lists.newArrayList(); |
| | | paramList.add(subDbUuid); |
| | | paramList.addAll(operateTableList); |
| | | DataTableEntity tableDte = baseDao.listTable(CmnConst.PRODUCT_SYS_DATA_COLLECT, filter, paramList.toArray()); |
| | | JSONObject resultObj = new JSONObject(); |
| | | for (int i = 0; i < tableDte.getRows(); i++) { |
| | | FieldSetEntity singleFse = tableDte.getFieldSetEntity(i); |
| | | String tableName = singleFse.getString("source_table").toLowerCase(Locale.ROOT); |
| | | resultObj.computeIfAbsent(tableName, s -> BaseUtil.fieldSetEntityToJson(singleFse)); |
| | | } |
| | | return resultObj; |
| | | } |
| | | |
| | | /** |
| | | * è·åç¹æ®å¤çä¿¡æ¯ t_wip_detail_dealt_max_id |
| | | * @return JSONObject ç¹æ®å¤çä¿¡æ¯ |
| | | */ |
| | | private JSONObject getSpDealInfo() { |
| | | DataTableEntity dictDte = baseDao.listTable(CmnConst.PRODUCT_SYS_DICT, "dict_name=?", new Object[]{DICT_NAME_REQUEST_HISTORY}); |
| | | JSONObject resultObj = new JSONObject(); |
| | | for (int i = 0; i < dictDte.getRows(); i++) { |
| | | FieldSetEntity singleFse = dictDte.getFieldSetEntity(i); |
| | | String dictLabel = singleFse.getString("dict_label"); |
| | | String dictValue = singleFse.getString("dict_value"); |
| | | if ("tableFormat".equals(dictLabel)) { |
| | | if (StringUtils.isEmpty(dictValue)) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getValue(), ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getText() + "ååºåå²è¡¨æ ¼å¼"); |
| | | } |
| | | resultObj.put("tableFormat", singleFse.getString("dict_value")); |
| | | } else if ("dealTables".equals(dictLabel)) { |
| | | if (StringUtils.isEmpty(dictValue)) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getValue(), ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getText() + "éè¦å¤çç表å"); |
| | | } |
| | | operateTableList = Arrays.asList(dictValue.split(",")); |
| | | } else if ("pageSize".equals(dictLabel)) { |
| | | if (StringUtils.isEmpty(dictValue)) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getValue(), ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getText() + "å页å¤ç页大å°"); |
| | | } |
| | | pageSize = Integer.parseInt(dictValue); |
| | | if (pageSize <= 0) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getValue(), ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getText() + "æ£ç¡®çå页å¤ç页大å°"); |
| | | } |
| | | } else if ("subDbIp".equals(dictLabel)) { |
| | | if (StringUtils.isEmpty(dictValue)) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getValue(), ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getText() + "ååºå°å"); |
| | | } |
| | | subDbIp = dictValue; |
| | | } else if ("subDbPort".equals(dictLabel)) { |
| | | if (StringUtils.isEmpty(dictValue)) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getValue(), ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getText() + "ååºç«¯å£"); |
| | | } |
| | | subDbPort = Integer.parseInt(dictValue); |
| | | } else if ("reportDbIp".equals(dictLabel)) { |
| | | if (StringUtils.isEmpty(dictValue)) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getValue(), ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getText() + "æ¥è¡¨åºå°å"); |
| | | } |
| | | reportDbIp = dictValue; |
| | | } else if ("reportDbPort".equals(dictLabel)) { |
| | | if (StringUtils.isEmpty(dictValue)) { |
| | | throw new BaseException(ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getValue(), ErrorCode.REQUEST_HISTORY_SP_DEAL_FAIL_NO_TABLE_DATA.getText() + "æ¥è¡¨åºç«¯å£"); |
| | | } |
| | | reportDbPort = Integer.parseInt(dictValue); |
| | | } else { |
| | | String dictLabelLowerCase = dictLabel.toLowerCase(Locale.ROOT); |
| | | for (String tableName : operateTableList) { |
| | | String tablenNameLowerCase = tableName.toLowerCase(Locale.ROOT); |
| | | if (dictLabelLowerCase.startsWith(tablenNameLowerCase)) { |
| | | JSONObject singleObj = (JSONObject) resultObj.computeIfAbsent(tablenNameLowerCase, s -> new JSONObject()); |
| | | singleObj.put(dictLabelLowerCase.replace(String.format("%s_", tablenNameLowerCase), ""), singleFse.getValue("dict_value")); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return resultObj; |
| | | } |
| | | |
| | | /** |
| | | * å¤çååºä¸æ¥è¯¢å°çæ°æ®ï¼æç
§æä»½å主é®åå«ç½®äºä¸åç容å¨ä¸ |
| | | * @param singlePageDataDte ååºæ°æ® |
| | | * @param singleSubDbTableInfoObj è¡¨ä¿¡æ¯ |
| | | * @param monthMap 容å¨ï¼Map<yyyyMM, <masterKey, Fse>> |
| | | */ |
| | | private void dealSubDbData(DataTableEntity singlePageDataDte, JSONObject singleSubDbTableInfoObj, Map<String, Map<String, FieldSetEntity>> monthMap) { |
| | | String masterKeyFieldName = singleSubDbTableInfoObj.getString("auto_field"); |
| | | String timeFieldName = singleSubDbTableInfoObj.getString("time_field"); |
| | | for (int i = 0; i < singlePageDataDte.getRows(); i++) { |
| | | FieldSetEntity singlePageDataFse = singlePageDataDte.getFieldSetEntity(i); |
| | | String timeStr = singlePageDataFse.getDate(timeFieldName, "yyyyMM"); |
| | | String masterValue = singlePageDataFse.getString(masterKeyFieldName); |
| | | monthMap.computeIfAbsent(timeStr, s -> Maps.newHashMap()).put(masterValue, singlePageDataFse); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 忢 |
| | | */ |
| | | private void stop(DataBaseEntity... dbeArr) { |
| | | if (dbeArr != null) { |
| | | for (DataBaseEntity dbe : dbeArr) { |
| | | if (dbe != null && dbe.getDao() != null) { |
| | | dbe.getDao().closeConnection(); |
| | | } |
| | | } |
| | | } |
| | | processingFlag = false; |
| | | stopFlag = false; |
| | | } |
| | | /*========================请æ±åå²-final========================*/ |
| | | } |