package com.product.data.center.service; import com.alibaba.fastjson.JSONObject; import com.product.common.utils.StringUtils; import com.product.common.utils.spring.SpringUtils; import com.product.core.service.support.QueryFilterService; import io.logz.sender.com.google.common.collect.Maps; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.product.core.dao.BaseDao; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.service.support.AbstractBaseService; import com.product.data.center.config.CmnConst; import com.product.data.center.entity.JournalEntity; import com.product.util.BaseUtil; import javax.annotation.Resource; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Map; import java.util.Random; /** * 操作日志 * * @author */ @Component public class JournalManagerService extends AbstractBaseService { @Autowired BaseDao baseDao; @Autowired QueryFilterService queryFilterService; @Resource MesExternalService mesExternalService; public void timingClearDataCenterLog(){ // select uuid from product_sys_data_center_log a // where created_utc_datetime<=date(date_add(now(),interval -7 day)) and (result=1 or (deal_flag=1 and deal_result=1)) and type>1 // union all // select a.uuid from product_sys_data_center_log a // join product_sys_data_center_log b on a.uuid=b.pre_step_uuid // where a.type=1 and b.type=2 and (b.result=1 or (b.deal_flag=1 and b.deal_result=1)) // and b.created_utc_datetime<=date(date_add(now(),interval -7 day)) } /** * 日志列表 * * @param fse * @return */ public DataTableEntity listJournal(FieldSetEntity fse, boolean getErrorLog) { String queryFilter1 = queryFilterService.getQueryFilter(fse); //获取配置信息和操作类型 String config_uuid = fse.getString(CmnConst.CONFIG_UUID); String type = fse.getString(CmnConst.TYPE); //设置SQL拼接成分(查询列,排序列,过滤条件) Object[] showFields = new Object[]{CmnConst.TYPE, CmnConst.DETAIL, CmnConst.CREATED_UTC_DATETIME, CmnConst.RESULT, CmnConst.DEAL_FLAG, CmnConst.COUNT, CmnConst.UUID, CmnConst.CONFIG_UUID}; DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG, getFilter(type, queryFilter1, true), new Object[]{type, config_uuid}, showFields, CmnConst.CREATED_UTC_DATETIME, fse.getInteger("pagesize"), fse.getInteger("cpage")); if (DataTableEntity.isEmpty(dt)) { dt = baseDao.listTable(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG, getFilter(type, queryFilter1, false), new Object[]{type, config_uuid}, showFields, CmnConst.CREATED_UTC_DATETIME, fse.getInteger("pagesize"), fse.getInteger("cpage")); } baseDao.loadPromptData(dt); return dt; } private String getFilter(String type, String queryFilter1, boolean getErrorLog) { StringBuilder queryFilter = new StringBuilder(); queryFilter.append(" type=? AND config_uuid=?"); //判断细项是否为空 if (getErrorLog) { queryFilter.append(" AND result=0 and deal_flag=0"); } //过滤归档日志 if ("5".equals(type)) { queryFilter.append(" AND detail=4"); } if (!StringUtils.isEmpty(queryFilter1)) { queryFilter.append(" and ").append(queryFilter1); } return queryFilter.toString(); } /** * 日志列表 已弃用 2023年3月16日 15:47:29 * * @param fse * @return */ public DataTableEntity listJournal1(FieldSetEntity fse, boolean getErrorLog) { String queryFilter1 = queryFilterService.getQueryFilter(fse); //获取配置信息和操作类型 String config_uuid = fse.getString(CmnConst.CONFIG_UUID); String type = fse.getString(CmnConst.TYPE); //设置SQL拼接成分(查询列,排序列,过滤条件) Object[] showFields = new Object[]{CmnConst.TYPE, CmnConst.DETAIL, CmnConst.CREATED_UTC_DATETIME, CmnConst.RESULT, CmnConst.DEAL_FLAG, CmnConst.COUNT, CmnConst.UUID, CmnConst.CONFIG_UUID}; StringBuilder orderFields = new StringBuilder(); orderFields.append(CmnConst.RESULT); orderFields.append(","); orderFields.append(CmnConst.DEAL_FLAG); orderFields.append(","); orderFields.append(CmnConst.CREATED_UTC_DATETIME); StringBuilder queryFilter = new StringBuilder(); queryFilter.append("type=? AND config_uuid=?"); //判断细项是否为空 if (getErrorLog) { queryFilter.append(" AND result=0"); } //过滤归档日志 if ("5".equals(type)) { queryFilter.append(" AND detail=4"); } if (!StringUtils.isEmpty(queryFilter1)) { queryFilter.append("and ").append(queryFilter1); } DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG, queryFilter.toString(), new Object[]{type, config_uuid}, showFields, orderFields.toString(), fse.getInteger("pagesize"), fse.getInteger("cpage")); baseDao.loadPromptData(dt); return dt; } /** * 日志详情 * * @param fse * @return */ public FieldSetEntity findJournal(FieldSetEntity fse) { //根据UUID获取日志信息 FieldSetEntity fseInfo = baseDao.getFieldSet(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG, new String[]{CmnConst.TYPE, "detail", "created_utc_datetime", "result", "deal_flag", "error", "count", CmnConst.CONFIG_UUID}, fse.getUUID(), false); //判断是否为归档日志并确定是否删除了MES主子库,如删除,则返回相应的日志 if ("5".equals(fseInfo.getString(CmnConst.TYPE)) && BaseUtil.strIsNull(fseInfo.getString(CmnConst.PRE_STEP_UUID))) { //查询删除主库日志 FieldSetEntity fseDelMain = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG, "pre_step_uuid=? AND detail=6", new Object[]{fseInfo.getString(CmnConst.PRE_STEP_UUID)}, false); if (fseDelMain == null) { //查询删除子库日志 FieldSetEntity fseDelSub = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG, "pre_step_uuid=? AND detail=5", new Object[]{fseInfo.getString(CmnConst.PRE_STEP_UUID)}, false); if (fseDelSub != null) { //装载删除子库日志 DataTableEntity dtSub = new DataTableEntity(); fseDelSub.setTableName("delSub"); dtSub.addFieldSetEntity(fseDelSub); fseInfo.addSubDataTable(dtSub); } } else { //装载删除主库日志 DataTableEntity dtMain = new DataTableEntity(); fseDelMain.setTableName("delMain"); dtMain.addFieldSetEntity(fseDelMain); fseInfo.addSubDataTable(dtMain); //查询删除子库日志 FieldSetEntity fseDelSub = baseDao.getFieldSetByFilter(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG, "pre_step_uuid=? AND detail=5", new Object[]{fseDelMain.getString(CmnConst.PRE_STEP_UUID)}, false); if (fseDelSub != null) { DataTableEntity dtSub = new DataTableEntity(); fseDelSub.setTableName("delSub"); dtSub.addFieldSetEntity(fseDelSub); fseInfo.addSubDataTable(dtSub); } } } return fseInfo; } /** * 模拟新增数据 */ public void insertData() { new Thread() { @Override public void run() { for (int i = 1; i <= 5; i++) { System.out.println("i=" + i); Random rd = new Random(); //创建一个Random类对象实例 int x = rd.nextInt(2); int y = rd.nextInt(6) + 1; FieldSetEntity fseEntity = new FieldSetEntity(); fseEntity.setTableName(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG); fseEntity.setValue("count", "500"); fseEntity.setValue("result", x); fseEntity.setValue("type", y); fseEntity.setValue("deal_flag", "0"); fseEntity.setValue(CmnConst.CREATED_UTC_DATETIME, new Date()); baseDao.add(fseEntity); } } }.start(); } /** * 日志监控首页(左侧监控分组) */ public DataTableEntity journalServerView() { DataTableEntity dtTypeAndConfig = baseDao.listTable("SELECT type,data_source,target_data_source FROM product_sys_data_center_log_view GROUP BY type,data_source,target_data_source", new Object[]{}); return dtTypeAndConfig; } /** * 日志监控视图(右侧监控数据) 弃用 2023年2月21日 14:49:39 * * @return */ public DataTableEntity groupCountErrorLog1(FieldSetEntity fse) { //获取类型(type:-1 左侧未选,加载所有 type:>0选中单个操作) int type = fse.getInteger(CmnConst.TYPE); //创建查询SQL StringBuilder sbSql = new StringBuilder(); sbSql.append(" SELECT A.type,A.uuid config_uuid,A.name,A.source_table,B.time,IF(status=0 AND IFNULL(count,0)=0,'正常','异常')status,data_source,target_data_source "); sbSql.append(" FROM PRODUCT_SYS_DATA_CENTER_LOG_VIEW A "); sbSql.append(" LEFT JOIN ( "); sbSql.append(" SELECT config_uuid, "); sbSql.append(" DATE_FORMAT(Max(statistics_final_time),'%Y-%m-%d %H:%i:%s')time, "); sbSql.append(" SUM(CASE WHEN result=0 AND (deal_flag=0 OR deal_flag IS NULL) THEN 1 ELSE 0 END) count "); sbSql.append(" FROM product_sys_data_center_log "); if (type > 0) { sbSql.append(" WHERE type=? "); } sbSql.append(" GROUP BY config_uuid "); sbSql.append(" ) B ON A.uuid = B.config_uuid "); if (type > 0) { sbSql.append(" WHERE A.type=? AND data_source=? AND target_data_source=? "); } sbSql.append(" ORDER BY count DESC"); //获取查询数据 DataTableEntity dt = null; if (type < 0) { dt = baseDao.listTable(sbSql.toString(), new Object[]{}); } else { String dataSource = fse.getString(CmnConst.DATA_SOURCE); String targetDataSource = fse.getString(CmnConst.TARGET_DATA_SOURCE); dt = baseDao.listTable(sbSql.toString(), new Object[]{type, type, dataSource, targetDataSource}); } return dt; } /** * 日志监控视图(右侧监控数据) * * @return */ public DataTableEntity groupCountErrorLog(FieldSetEntity fse) { //获取类型(type:-1 左侧未选,加载所有 type:>0选中单个操作) int type = fse.getInteger(CmnConst.TYPE); //创建查询SQL StringBuilder sbSql = new StringBuilder(); sbSql.append(" SELECT A.type,A.uuid config_uuid,A.name,A.source_table,data_source,target_data_source,status"); sbSql.append(" FROM PRODUCT_SYS_DATA_CENTER_LOG_VIEW A "); if (type > 0) { sbSql.append(" WHERE A.type=? AND data_source=? AND target_data_source=? "); } //获取查询数据 DataTableEntity dt; if (type < 0) { dt = baseDao.listTable(sbSql.toString(), new Object[]{}); } else { String dataSource = fse.getString(CmnConst.DATA_SOURCE); String targetDataSource = fse.getString(CmnConst.TARGET_DATA_SOURCE); dt = baseDao.listTable(sbSql.toString(), new Object[]{type, dataSource, targetDataSource}); } Map resultMap = dt2Map(dt, CmnConst.CONFIG_UUID); StringBuilder sql = new StringBuilder(128); sql.append("\nselect t1.config_uuid,DATE_FORMAT(t1.statistics_final_time,'%Y-%m-%d %H:%i:%s') time,t2.count"); sql.append("\nfrom ("); sql.append("\n select config_uuid,statistics_final_time"); sql.append("\n from product_sys_data_center_log l1"); sql.append("\n inner join ("); sql.append("\n SELECT Max(id) id"); sql.append("\n FROM product_sys_data_center_log "); sql.append("\n GROUP BY config_uuid"); sql.append("\n ) l2 on l1.id=l2.id"); sql.append("\n) t1"); sql.append("\nleft join ("); sql.append("\n select distinct config_uuid,1 count from product_sys_data_center_log where result=0 AND deal_flag=0"); sql.append("\n) t2 on t1.config_uuid=t2.config_uuid"); DataTableEntity errorDte = baseDao.listTable(sql.toString(), new Object[]{}); Map errorMap = dt2Map(errorDte, CmnConst.CONFIG_UUID); DataTableEntity resultDte = new DataTableEntity(); DataTableEntity commonDte = new DataTableEntity(); errorMap.forEach((configUUID, tempFse) -> { FieldSetEntity resultFse = resultMap.get(configUUID); resultMap.remove(configUUID); if (FieldSetEntity.isEmpty(resultFse)) { return; } for (Object fieldNameObj : tempFse.getFields()) { if (fieldNameObj == null) { continue; } String fieldName = fieldNameObj.toString(); resultFse.setValue(fieldName, tempFse.getString(fieldName)); } if (resultFse.getInteger("count") != null && resultFse.getInteger("count") > 0) { if ("0".equals(resultFse.getString("status"))) { resultFse.setValue("status", "异常"); } resultDte.addFieldSetEntity(resultFse); } else { if ("0".equals(resultFse.getString("status"))) { resultFse.setValue("status", "正常"); } commonDte.addFieldSetEntity(resultFse); } }); resultDte.addFieldSetEntity(commonDte); resultMap.forEach((fieldName, tempFse) -> { tempFse.setValue("status", "正常"); resultDte.addFieldSetEntity(tempFse); }); return resultDte; } /** * dte转为map * * @param dte * @param fieldName * @return */ private Map dt2Map(DataTableEntity dte, String fieldName) { Map map = Maps.newHashMap(); FieldSetEntity fse; for (int i = 0; i < dte.getRows(); i++) { fse = dte.getFieldSetEntity(i); map.put(fse.getString(fieldName), fse); } return map; } /** * 日志二次处理 * * @param uuids 日志uuid */ public void secondOperation(String uuids) { String[] uuidArray = uuids.split(","); new Thread(() -> { for (String uuid : uuidArray) { FieldSetEntity fseJournal = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG, uuid, false); secondOperation(fseJournal); } }).start(); } public void autoSecondOperation() { StringBuilder sql = new StringBuilder(); sql.append(" SELECT * FROM product_sys_data_center_log a "); sql.append(" where type IN ( 1, 2 ) AND result = 0 AND deal_flag = 0 "); sql.append(" AND DATE_FORMAT( created_utc_datetime, '%Y-%m-%d' )>= DATE_FORMAT( now(), '%Y-%m-%d' ) "); sql.append(" AND (( type = 2 AND ("); sql.append(" SELECT 1 FROM product_sys_data_center_log b where b.uuid = a.pre_step_uuid AND "); sql.append(" ( b.source_uuid IS NULL OR b.source_uuid = '' ))) or (type =1 and (source_uuid IS NULL OR source_uuid = '')) ) "); DataTableEntity dataTableEntity = getBaseDao().listTable(sql.toString(), new Object[]{}); if (DataTableEntity.isEmpty(dataTableEntity)) { return; } for (int i = 0; i < dataTableEntity.getRows(); i++) { secondOperation(dataTableEntity.getFieldSetEntity(i)); } } private void secondOperation(FieldSetEntity fseJournal) { if (!FieldSetEntity.isEmpty(fseJournal)) { String uuid = fseJournal.getUUID(); String type = fseJournal.getString(CmnConst.TYPE);//类型 if (!BaseUtil.strIsNull(type)) { String dataSystemName = mesExternalService.getDataSystemName(); if ("ch-kt".equals(dataSystemName) && mesExternalService.remoteRehandle(fseJournal)) { return; } if ("1".equals(type)) { //数据采集 DataCollectService dataCollectService = SpringUtils.getBean(DataCollectService.class); mesExternalService.remoteSaveCollectLog(dataCollectService.reDeal(uuid)); } else if ("2".equals(type)) { //数据提取 DataCollectService dataCollectService = SpringUtils.getBean(DataCollectService.class); mesExternalService.remoteSaveCollectLog(dataCollectService.reDeal(fseJournal.getString(CmnConst.PRE_STEP_UUID), fseJournal)); } else if ("3".equals(type)) { //数据同步 SpringUtils.getBean(DataSyncService.class).reDeal(uuid); } else if ("5".equals(type)) { //数据归档不做操作 DataArchivingService dataArchivingService = SpringUtils.getBean(DataArchivingService.class); dataArchivingService.reDeal(uuid); } } } } /** * 日志标识处理 * * @param uuid 日志uuid */ public void signOperation(String uuid) { //获取原日志数据 FieldSetEntity fseJournal = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG, uuid, false); String result = fseJournal.getString(CmnConst.RESULT); String dealFlag = fseJournal.getString(CmnConst.DEAL_FLAG); //判断是否符合标识处理 if ("0".equals(result) && (BaseUtil.isStrNum(dealFlag) || "0".equals(dealFlag))) { fseJournal.setValue(CmnConst.DEAL_FLAG, 1); fseJournal.setValue(CmnConst.DEAL_RESULT, 1); baseDao.update(fseJournal); } } /** * 定时任务自动创建日志 * * @param journalEntity * @return */ public FieldSetEntity autoCreateJournal(JournalEntity journalEntity) { FieldSetEntity fseLog = new FieldSetEntity(); fseLog.setTableName(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG); //日志归属 fseLog.setValue(CmnConst.TYPE, journalEntity.getType()); //日志类型 fseLog.setValue(CmnConst.DETAIL, journalEntity.getDetail()); //细类型(两器,整机,电控) //操作结果1:成功 0:失败(error不能为空) if (journalEntity.getResult() == 0) { fseLog.setValue(CmnConst.ERROR, journalEntity.getError()); //错误日志 fseLog.setValue(CmnConst.RESULT, 0); } else { fseLog.setValue(CmnConst.RESULT, 1); } fseLog.setValue(CmnConst.COUNT, journalEntity.getCount()); //执行条数 fseLog.setValue(CmnConst.MIN_ID, journalEntity.getMin_id()); //操作数据的最小id fseLog.setValue(CmnConst.MAX_ID, journalEntity.getMax_id()); //操作数据的最大id //默认数据 fseLog.setValue(CmnConst.DEAL_FLAG, 0); //手动处理 1:是 0:否(手动触发就算处理) fseLog.setValue(CmnConst.DEAL_RESULT, 1); //处理结果 1:成功 0:失败(会再生成一条错误日志) // fseLog.setValue(CmnConst.SOURCE_UUID, null); fseLog.setValue(CmnConst.SOURCE_UUID, journalEntity.getSource_uuid());//源日志UUID(deal_flag=1;deal_result=0的数据) fseLog.setValue(CmnConst.SINGLE_DURATION, journalEntity.getSingle_duration()); fseLog.setValue(CmnConst.CONFIG_UUID, journalEntity.getConfigUuid()); fseLog.setValue(CmnConst.STATISTICS_START_TIME, journalEntity.getStatistics_start_time()); fseLog.setValue(CmnConst.STATISTICS_FINAL_TIME, journalEntity.getStatistics_final_time()); fseLog.setValue(CmnConst.OTHER_INFO, journalEntity.getOther_info()); fseLog.setValue(CmnConst.NEXT_STEP_STATUS, journalEntity.getNext_step_status()); //下一步处理状态 0:暂未操作 1:下一步处理成功 2:下一步执行失败 fseLog.setValue(CmnConst.PRE_STEP_UUID, journalEntity.getPre_step_uuid()); //上一步UUID fseLog.setValue(CmnConst.CREATED_UTC_DATETIME, journalEntity.getCreated_utc_datetime() != null ? journalEntity.getCreated_utc_datetime() : new Date()); baseDao.add(fseLog); return fseLog; } /** * 手动处理自动生成日志 * * @param fseNewInfo 新数据 * @param fsePreInfo 上一步数据 * @return */ public boolean autoCreateLog(FieldSetEntity fseNewInfo, FieldSetEntity fsePreInfo) { FieldSetEntity fseLog = new FieldSetEntity(); fseLog.setTableName(CmnConst.PRODUCT_SYS_DATA_CENTER_LOG); //日志归属 fseLog.setValue(CmnConst.TYPE, fsePreInfo.getString(CmnConst.TYPE)); //日志类型 fseLog.setValue(CmnConst.DETAIL, fsePreInfo.getString(CmnConst.DETAIL)); //细类型(两器,整机,电控) //操作结果1:成功 0:失败(error不能为空) if ("0".equals(fseNewInfo.getString(CmnConst.RESULT))) { fsePreInfo.setValue(CmnConst.NEXT_STEP_STATUS, 2); //下一步处理失败 fseLog.setValue(CmnConst.ERROR, fseNewInfo.getString(CmnConst.ERROR)); //错误日志 } else { fsePreInfo.setValue(CmnConst.NEXT_STEP_STATUS, 1); //下一步处理成功 fseLog.setValue(CmnConst.RESULT, 1); } fseLog.setValue(CmnConst.COUNT, fsePreInfo.getInteger(CmnConst.COUNT)); //执行条数 fseLog.setValue(CmnConst.MIN_ID, fsePreInfo.getInteger(CmnConst.MIN_ID)); //操作数据的最小id fseLog.setValue(CmnConst.MAX_ID, fsePreInfo.getInteger(CmnConst.MAX_ID)); //操作数据的最大id //默认数据 fseLog.setValue(CmnConst.DEAL_FLAG, 0); //手动处理 1:是 0:否(手动触发就算处理) fseLog.setValue(CmnConst.DEAL_RESULT, 1); //处理结果 1:成功 0:失败(会再生成一条错误日志) fseLog.setValue(CmnConst.SOURCE_UUID, null); //源日志UUID(deal_flag=1;deal_result=0的数据) fseLog.setValue(CmnConst.NEXT_STEP_STATUS, 0); //下一步处理状态 0:暂未操作 1:下一步处理成功 2:下一步执行失败 fseLog.setValue(CmnConst.PRE_STEP_UUID, fsePreInfo.getUUID()); //上一步UUID //生成新日志 baseDao.add(fseLog); //修改源日志 baseDao.update(fsePreInfo); return true; } /** * 获取异常信息 * * @param e * @return */ public String getStackTrace(Throwable e) { StringWriter sw = null; PrintWriter pw = null; try { sw = new StringWriter(); pw = new PrintWriter(sw); e.printStackTrace(pw); pw.flush(); sw.flush(); } catch (Exception e2) { e2.printStackTrace(); } finally { if (sw != null) { try { sw.close(); } catch (IOException e1) { e1.printStackTrace(); } } if (pw != null) { pw.close(); } } return sw.toString(); } /** * 提取数据集中的首尾范围信息 * * @param dte * @param timeField * @return */ public JSONObject getRangeInfo(DataTableEntity dte, String timeField) { FieldSetEntity fse; JSONObject resultObj = new JSONObject(); for (int i = 0; i < dte.getRows(); i++) { fse = dte.getFieldSetEntity(i); recordBorder(resultObj, fse, timeField, CmnConst.DATE); } return resultObj; } /** * 回写重新处理的结果到源日志 * * @param sourceLogFse * @param resultFlag */ public void writeBackReDealResult(FieldSetEntity sourceLogFse, boolean resultFlag) { sourceLogFse.setValue(CmnConst.DEAL_FLAG, 1); sourceLogFse.setValue(CmnConst.DEAL_RESULT, resultFlag ? 1 : 0); sourceLogFse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date()); baseDao.saveFieldSetEntity(sourceLogFse); } /** * 记录边界 * * @param jsonObject 结果集 * @param fse 数据记录 * @param fieldName 字段名称 * @param symbol 标识,date:记录统计开始时间,统计截止时间;int:记录最小ID,最大ID */ private void recordBorder(JSONObject jsonObject, FieldSetEntity fse, String fieldName, String symbol) { if (fse.getValue(fieldName) == null) { return; } if (CmnConst.DATE.equals(symbol)) { if (jsonObject.get(CmnConst.STATISTICS_START_TIME) == null) { jsonObject.put(CmnConst.STATISTICS_START_TIME, fse.getDate(fieldName)); jsonObject.put(CmnConst.STATISTICS_FINAL_TIME, fse.getDate(fieldName)); } else { if (((Date) jsonObject.get(CmnConst.STATISTICS_START_TIME)).compareTo(fse.getDate(fieldName)) > 0) { jsonObject.put(CmnConst.STATISTICS_START_TIME, fse.getDate(fieldName)); } else if (((Date) jsonObject.get(CmnConst.STATISTICS_FINAL_TIME)).compareTo(fse.getDate(fieldName)) < 0) { jsonObject.put(CmnConst.STATISTICS_FINAL_TIME, fse.getDate(fieldName)); } } } else if (CmnConst.INT.equals(symbol)) { if (jsonObject.get(CmnConst.MIN_ID) == null) { jsonObject.put(CmnConst.MIN_ID, fse.getInteger(fieldName)); jsonObject.put(CmnConst.MAX_ID, fse.getInteger(fieldName)); } else { if (jsonObject.getInteger(CmnConst.MIN_ID) > fse.getInteger(fieldName)) { jsonObject.put(CmnConst.MIN_ID, fse.getInteger(fieldName)); } else if (jsonObject.getInteger(CmnConst.MAX_ID) < fse.getInteger(fieldName)) { jsonObject.put(CmnConst.MAX_ID, fse.getInteger(fieldName)); } } } } public static void main(String[] args) throws ParseException { Date d1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2021-05-06 12:15:16"); Date d2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2022-05-06 12:15:16"); System.out.println(d1.compareTo(d2)); int minID = 46; int maxID = 98; System.out.println(minID > maxID); } }