fix: 优化逻辑
This commit is contained in:
parent
e68500343e
commit
2149d7c4e8
@ -32,4 +32,8 @@ public class MsOperationLog implements Serializable {
|
||||
|
||||
@TableField("TABLE_NAME")
|
||||
private String tableName;
|
||||
|
||||
@TableField("RECORD_ID")
|
||||
private String recordId;
|
||||
|
||||
}
|
||||
|
||||
@ -275,7 +275,7 @@ public class MsOperationLogServiceImpl implements IMsOperationLogService {
|
||||
if (engInfo == null) {
|
||||
return;
|
||||
}
|
||||
MsOperationLog mainLog = buildMainLog("新增电站", source);
|
||||
MsOperationLog mainLog = buildMainLog(null,"新增电站", source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
@ -311,7 +311,7 @@ public class MsOperationLogServiceImpl implements IMsOperationLogService {
|
||||
return;
|
||||
}
|
||||
|
||||
MsOperationLog mainLog = buildMainLog("修改电站", source);
|
||||
MsOperationLog mainLog = buildMainLog(before.getStcd(),"修改电站", source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
@ -348,7 +348,7 @@ public class MsOperationLogServiceImpl implements IMsOperationLogService {
|
||||
if (engInfo == null) {
|
||||
return;
|
||||
}
|
||||
MsOperationLog mainLog = buildMainLog("删除电站", source);
|
||||
MsOperationLog mainLog = buildMainLog(engInfo.getStcd(),"删除电站", source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
@ -378,11 +378,12 @@ public class MsOperationLogServiceImpl implements IMsOperationLogService {
|
||||
batchInsertDetails(details);
|
||||
}
|
||||
|
||||
private MsOperationLog buildMainLog(String remark, String source) {
|
||||
private MsOperationLog buildMainLog(String recordId,String remark, String source) {
|
||||
MsOperationLog log = new MsOperationLog();
|
||||
log.setOperator(resolveOperator());
|
||||
log.setOperateTime(new Date());
|
||||
log.setTableName(ENG_TABLE_NAME);
|
||||
log.setRecordId(recordId);
|
||||
log.setSource(StrUtil.trimToNull(source));
|
||||
log.setRemark(remark);
|
||||
return log;
|
||||
|
||||
@ -2,6 +2,7 @@ package com.yfd.platform.qgc_env.wq.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.yfd.platform.common.*;
|
||||
@ -4071,7 +4072,7 @@ public class EnvWqDataServiceImpl implements EnvWqDataService {
|
||||
}
|
||||
|
||||
private String buildWqHourLogSelectColumns() {
|
||||
return "STCD, TO_CHAR(TM, 'YYYY-MM-DD HH24:MI:SS') AS TM, " +
|
||||
return "ID,STCD, TO_CHAR(TM, 'YYYY-MM-DD HH24:MI:SS') AS TM, " +
|
||||
"WTMP, PH, DOX, CODMN, CODCR, BOD5, NH3N, TP, TN, CU, ZN, F, SE, ARS, HG, CD, CR6, PB, CN, " +
|
||||
"VLPH, OIL, LAS, S2, FCG, CL, SO4, NO3, THRD, COND, FE, MN, AL, CHLA, CLARITY, TU, CYANO, " +
|
||||
"WQGRD, SFDB, WQ_SFDBHN_YS";
|
||||
@ -4148,7 +4149,9 @@ public class EnvWqDataServiceImpl implements EnvWqDataService {
|
||||
if (details.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
MsOperationLog mainLog = buildWqMainLog("修改水质小时数据", source);
|
||||
String recordId = ObjectUtil.isNotEmpty(beforeHour) && ObjectUtil.isNotEmpty(beforeHour.get("ID"))
|
||||
? beforeHour.get("ID").toString()
|
||||
: null; MsOperationLog mainLog = buildWqMainLog(recordId,"修改水质小时数据", source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
for (MsOperationLogDetail detail : details) {
|
||||
detail.setMainId(mainLog.getId());
|
||||
@ -4160,11 +4163,12 @@ public class EnvWqDataServiceImpl implements EnvWqDataService {
|
||||
if (CollUtil.isEmpty(rows)) {
|
||||
return;
|
||||
}
|
||||
MsOperationLog mainLog = buildWqMainLog(remark, source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
String stcd = asString(row.get("STCD"));
|
||||
String recordId = asString(row.get("ID"));
|
||||
MsOperationLog mainLog = buildWqMainLog(recordId,remark, source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
for (Map.Entry<String, Object> entry : row.entrySet()) {
|
||||
String fieldCode = entry.getKey();
|
||||
if (StrUtil.isBlank(fieldCode)) {
|
||||
@ -4182,9 +4186,10 @@ public class EnvWqDataServiceImpl implements EnvWqDataService {
|
||||
batchInsertWqLogDetails(details);
|
||||
}
|
||||
|
||||
private MsOperationLog buildWqMainLog(String remark, String source) {
|
||||
private MsOperationLog buildWqMainLog(String recordId,String remark, String source) {
|
||||
MsOperationLog log = new MsOperationLog();
|
||||
log.setOperator(resolveLogOperator());
|
||||
log.setRecordId(recordId);
|
||||
log.setOperateTime(new Date());
|
||||
log.setTableName(WQ_HOUR_TABLE_NAME);
|
||||
log.setSource(StrUtil.trimToNull(source));
|
||||
|
||||
@ -1170,6 +1170,7 @@ public class AlongDetailServiceImpl extends ServiceImpl<AlongDetailMapper, SdAlo
|
||||
return;
|
||||
}
|
||||
String stcd = asString(getValueIgnoreCase(updateData, "stcd"));
|
||||
String recordId = asString(getValueIgnoreCase(beforeRow, "id"));
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : WT_UPDATE_COLUMN_MAP.entrySet()) {
|
||||
if (!containsKeyIgnoreCase(updateData, entry.getKey())) {
|
||||
@ -1188,7 +1189,7 @@ public class AlongDetailServiceImpl extends ServiceImpl<AlongDetailMapper, SdAlo
|
||||
if (details.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
MsOperationLog mainLog = buildWtMainLog("修改表层水温日数据", source);
|
||||
MsOperationLog mainLog = buildWtMainLog(recordId,"修改表层水温日数据", source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
for (MsOperationLogDetail detail : details) {
|
||||
detail.setMainId(mainLog.getId());
|
||||
@ -1200,11 +1201,13 @@ public class AlongDetailServiceImpl extends ServiceImpl<AlongDetailMapper, SdAlo
|
||||
if (CollUtil.isEmpty(rows)) {
|
||||
return;
|
||||
}
|
||||
MsOperationLog mainLog = buildWtMainLog(remark, source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
String stcd = asString(row.get("STCD"));
|
||||
String recordId = asString(row.get("ID"));
|
||||
MsOperationLog mainLog = buildWtMainLog(recordId,remark, source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
for (Map.Entry<String, Object> entry : row.entrySet()) {
|
||||
String fieldCode = entry.getKey();
|
||||
Object oldValue = entry.getValue();
|
||||
@ -1219,10 +1222,12 @@ public class AlongDetailServiceImpl extends ServiceImpl<AlongDetailMapper, SdAlo
|
||||
batchInsertWtLogDetails(details);
|
||||
}
|
||||
|
||||
private MsOperationLog buildWtMainLog(String remark, String source) {
|
||||
private MsOperationLog buildWtMainLog(String recordId,String remark, String source) {
|
||||
MsOperationLog log = new MsOperationLog();
|
||||
log.setOperator(resolveWtLogOperator());
|
||||
log.setOperateTime(new Date());
|
||||
log.setRecordId(recordId);
|
||||
log.setTableName(WT_HOUR_TABLE_NAME);
|
||||
log.setSource(StrUtil.trimToNull(source));
|
||||
log.setRemark(remark);
|
||||
return log;
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.yfd.platform.qgc_env.zq.controller;
|
||||
|
||||
import com.yfd.platform.annotation.Log;
|
||||
import com.yfd.platform.common.DataSourceRequest;
|
||||
import com.yfd.platform.config.ResponseResult;
|
||||
import com.yfd.platform.qgc_base.entity.vo.BatchDeleteAo;
|
||||
@ -57,6 +58,7 @@ public class ZqMonitorController {
|
||||
return ResponseResult.successData(zqMonitorService.getRiverDrtpKendoListCust(dataSourceRequest));
|
||||
}
|
||||
|
||||
@Log(module = "水文流量站监测", value = "删除流量站小时/日/月数据")
|
||||
@PostMapping("/river/removeKendoByIds")
|
||||
@Operation(summary = "删除流量站小时/日/月数据")
|
||||
public ResponseResult removeKendoByIds(@RequestBody BatchDeleteAo batchDeleteAo) {
|
||||
@ -64,10 +66,14 @@ public class ZqMonitorController {
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
@Log(module = "水文流量站监测", value = "修改流量站小时数据")
|
||||
@PostMapping("/river/updateRiverRData")
|
||||
@Operation(summary = "修改流量站小时数据")
|
||||
public ResponseResult updateRiverRData(@RequestBody ZqOperateRequest zqOperateRequest) {
|
||||
zqMonitorService.updateRiverRData(zqOperateRequest.getUpdateData());
|
||||
zqMonitorService.updateRiverRData(
|
||||
zqOperateRequest == null ? null : zqOperateRequest.getUpdateData(),
|
||||
zqOperateRequest == null ? null : zqOperateRequest.getSource()
|
||||
);
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ public interface ZqMonitorService {
|
||||
|
||||
boolean removeKendoByIds(BatchDeleteAo batchDeleteAo);
|
||||
|
||||
boolean updateRiverRData(java.util.Map<String, Object> updateData);
|
||||
boolean updateRiverRData(java.util.Map<String, Object> updateData, String source);
|
||||
|
||||
ZqBaseInfoVo getStcdInfo(String stcd);
|
||||
}
|
||||
|
||||
@ -10,8 +10,12 @@ import com.yfd.platform.common.GroupHelper;
|
||||
import com.yfd.platform.common.GroupingInfo;
|
||||
import com.yfd.platform.common.MicroservicDynamicSQLMapper;
|
||||
import com.yfd.platform.common.exception.BizException;
|
||||
import com.yfd.platform.qgc_base.domain.MsOperationLog;
|
||||
import com.yfd.platform.qgc_base.domain.MsOperationLogDetail;
|
||||
import com.yfd.platform.qgc_base.entity.vo.BatchDeleteAo;
|
||||
import com.yfd.platform.qgc_base.entity.vo.DataParam;
|
||||
import com.yfd.platform.qgc_base.mapper.MsOperationLogDetailMapper;
|
||||
import com.yfd.platform.qgc_base.mapper.MsOperationLogMapper;
|
||||
import com.yfd.platform.qgc_env.fh.entity.vo.HabitatVo;
|
||||
import com.yfd.platform.qgc_env.zq.entity.vo.ZqBaseInfoVo;
|
||||
import com.yfd.platform.qgc_env.zq.entity.vo.ZqRiverDayDataVo;
|
||||
@ -19,23 +23,58 @@ import com.yfd.platform.qgc_env.zq.entity.vo.ZqRiverDrtpDataVo;
|
||||
import com.yfd.platform.qgc_env.zq.entity.vo.ZqRiverDataVo;
|
||||
import com.yfd.platform.qgc_env.zq.service.ZqMonitorService;
|
||||
import com.yfd.platform.utils.QgcQueryWrapperUtil;
|
||||
import com.yfd.platform.utils.SecurityUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class ZqMonitorServiceImpl implements ZqMonitorService {
|
||||
private static final String ZQ_HOUR_TABLE_NAME = "SD_RIVER_R";
|
||||
private static final String ZQ_DAY_TABLE_NAME = "SD_RIVERDAY_S";
|
||||
private static final String ZQ_MONTH_TABLE_NAME = "SD_RIVERDRTP_S";
|
||||
private static final Map<String, String> ZQ_UPDATE_COLUMN_MAP = new LinkedHashMap<>();
|
||||
private static final Map<String, String> ZQ_FIELD_MEANING_MAP = new LinkedHashMap<>();
|
||||
|
||||
static {
|
||||
ZQ_UPDATE_COLUMN_MAP.put("z", "Z");
|
||||
ZQ_UPDATE_COLUMN_MAP.put("q", "Q");
|
||||
ZQ_UPDATE_COLUMN_MAP.put("v", "V");
|
||||
|
||||
ZQ_FIELD_MEANING_MAP.put("ID", "主键ID");
|
||||
ZQ_FIELD_MEANING_MAP.put("STCD", "站码");
|
||||
ZQ_FIELD_MEANING_MAP.put("TM", "时间");
|
||||
ZQ_FIELD_MEANING_MAP.put("DT", "时间");
|
||||
ZQ_FIELD_MEANING_MAP.put("DRTP", "维度类型");
|
||||
ZQ_FIELD_MEANING_MAP.put("YEAR", "年");
|
||||
ZQ_FIELD_MEANING_MAP.put("MONTH", "月");
|
||||
ZQ_FIELD_MEANING_MAP.put("DR", "时段类型");
|
||||
ZQ_FIELD_MEANING_MAP.put("Z", "水位");
|
||||
ZQ_FIELD_MEANING_MAP.put("Q", "流量");
|
||||
ZQ_FIELD_MEANING_MAP.put("V", "流速");
|
||||
ZQ_FIELD_MEANING_MAP.put("MSQMT", "测流方法");
|
||||
ZQ_FIELD_MEANING_MAP.put("RECORD_USER", "创建人");
|
||||
ZQ_FIELD_MEANING_MAP.put("RECORD_TIME", "创建时间");
|
||||
ZQ_FIELD_MEANING_MAP.put("MODIFY_USER", "更新人");
|
||||
ZQ_FIELD_MEANING_MAP.put("MODIFY_TIME", "更新时间");
|
||||
ZQ_FIELD_MEANING_MAP.put("IS_DELETED", "是否已删除");
|
||||
ZQ_FIELD_MEANING_MAP.put("DELETE_USER", "删除人");
|
||||
ZQ_FIELD_MEANING_MAP.put("DELETE_TIME", "删除时间");
|
||||
ZQ_FIELD_MEANING_MAP.put("FID", "附件ID");
|
||||
ZQ_FIELD_MEANING_MAP.put("REMARK", "备注");
|
||||
}
|
||||
|
||||
@Resource
|
||||
private MicroservicDynamicSQLMapper microservicDynamicSQLMapper;
|
||||
@ -43,6 +82,12 @@ public class ZqMonitorServiceImpl implements ZqMonitorService {
|
||||
@Resource
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Resource
|
||||
private MsOperationLogMapper msOperationLogMapper;
|
||||
|
||||
@Resource
|
||||
private MsOperationLogDetailMapper msOperationLogDetailMapper;
|
||||
|
||||
@Override
|
||||
public DataSourceResult getMsstbprptList(DataSourceRequest dataSourceRequest) {
|
||||
return getMsstbprptListInternal(dataSourceRequest, false);
|
||||
@ -170,11 +215,14 @@ public class ZqMonitorServiceImpl implements ZqMonitorService {
|
||||
}
|
||||
String dataType = batchDeleteAo.getDataType();
|
||||
List<DataParam> dataList = batchDeleteAo.getDataList();
|
||||
String source = batchDeleteAo.getSource();
|
||||
int batchSize = 500;
|
||||
for (int i = 0; i < dataList.size(); i += batchSize) {
|
||||
List<DataParam> subList = dataList.subList(i, Math.min(i + batchSize, dataList.size()));
|
||||
if ("TIME".equals(dataType)) {
|
||||
List<Map<String, Object>> beforeRows = queryRiverHourRows(subList);
|
||||
deleteRiverRData(subList);
|
||||
recordRiverDeleteLog(beforeRows, ZQ_HOUR_TABLE_NAME, "删除流量站小时数据", source);
|
||||
Map<String, String[]> dateRangeMap = new HashMap<>();
|
||||
Map<String, String[]> monthRangeMap = new HashMap<>();
|
||||
for (DataParam param : subList) {
|
||||
@ -209,10 +257,14 @@ public class ZqMonitorServiceImpl implements ZqMonitorService {
|
||||
}
|
||||
}
|
||||
if ("DATE".equals(dataType)) {
|
||||
List<Map<String, Object>> beforeRows = queryRiverDayRows(subList);
|
||||
deleteRiverDayData(subList);
|
||||
recordRiverDeleteLog(beforeRows, ZQ_DAY_TABLE_NAME, "删除流量站日数据", source);
|
||||
}
|
||||
if ("MON".equals(dataType)) {
|
||||
List<Map<String, Object>> beforeRows = queryRiverMonthRows(subList);
|
||||
deleteRiverMonthData(subList);
|
||||
recordRiverDeleteLog(beforeRows, ZQ_MONTH_TABLE_NAME, "删除流量站月数据", source);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -220,10 +272,12 @@ public class ZqMonitorServiceImpl implements ZqMonitorService {
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public boolean updateRiverRData(Map<String, Object> updateData) {
|
||||
updateRiverHourData(updateData);
|
||||
public boolean updateRiverRData(Map<String, Object> updateData, String source) {
|
||||
String stcd = updateData == null ? null : asString(updateData.get("stcd"));
|
||||
String tm = updateData == null ? null : asString(updateData.get("tm"));
|
||||
Map<String, Object> beforeRow = queryRiverHourRow(stcd, tm);
|
||||
updateRiverHourData(updateData);
|
||||
recordRiverUpdateLog(beforeRow, updateData, source);
|
||||
if (StrUtil.isNotBlank(stcd) && StrUtil.isNotBlank(tm) && tm.length() >= 10) {
|
||||
String dateStr = tm.substring(0, 10);
|
||||
statisticsDayDataFromHour(stcd, dateStr, dateStr);
|
||||
@ -1612,6 +1666,273 @@ public class ZqMonitorServiceImpl implements ZqMonitorService {
|
||||
return value == null ? null : String.valueOf(value);
|
||||
}
|
||||
|
||||
private Map<String, Object> queryRiverHourRow(String stcd, String tm) {
|
||||
if (StrUtil.isBlank(stcd) || StrUtil.isBlank(tm)) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
String sql = "SELECT ID, STCD, TO_CHAR(TM, 'YYYY-MM-DD HH24:MI:SS') AS TM, Z, Q, V, MSQMT, RECORD_USER, " +
|
||||
"RECORD_TIME, MODIFY_USER, MODIFY_TIME, IS_DELETED, DELETE_USER, DELETE_TIME, FID, REMARK " +
|
||||
"FROM SD_RIVER_R WHERE STCD = ? AND TM = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')";
|
||||
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, stcd, tm);
|
||||
return rows.isEmpty() ? new HashMap<>() : normalizeRiverLogRow(rows.getFirst());
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> queryRiverHourRows(List<DataParam> dataList) {
|
||||
if (CollUtil.isEmpty(dataList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
StringBuilder sql = new StringBuilder("SELECT ID, STCD, TO_CHAR(TM, 'YYYY-MM-DD HH24:MI:SS') AS TM, Z, Q, V, MSQMT, RECORD_USER, ")
|
||||
.append("RECORD_TIME, MODIFY_USER, MODIFY_TIME, IS_DELETED, DELETE_USER, DELETE_TIME, FID, REMARK ")
|
||||
.append("FROM SD_RIVER_R WHERE ");
|
||||
List<Object> args = new ArrayList<>();
|
||||
List<String> conditions = new ArrayList<>();
|
||||
for (DataParam item : dataList) {
|
||||
if (item == null || StrUtil.isBlank(item.getId()) || StrUtil.isBlank(item.getTm())) {
|
||||
continue;
|
||||
}
|
||||
conditions.add("(STCD = ? AND TM = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'))");
|
||||
args.add(item.getId());
|
||||
args.add(item.getTm());
|
||||
}
|
||||
if (conditions.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
sql.append(String.join(" OR ", conditions));
|
||||
return normalizeRiverLogRows(jdbcTemplate.queryForList(sql.toString(), args.toArray()));
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> queryRiverDayRows(List<DataParam> dataList) {
|
||||
if (CollUtil.isEmpty(dataList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
StringBuilder sql = new StringBuilder("SELECT ID, STCD, TO_CHAR(DT, 'YYYY-MM-DD HH24:MI:SS') AS DT, Z, Q, V, MSQMT, RECORD_USER, ")
|
||||
.append("RECORD_TIME, MODIFY_USER, MODIFY_TIME, IS_DELETED, DELETE_USER, DELETE_TIME ")
|
||||
.append("FROM SD_RIVERDAY_S WHERE ");
|
||||
List<Object> args = new ArrayList<>();
|
||||
List<String> conditions = new ArrayList<>();
|
||||
for (DataParam item : dataList) {
|
||||
if (item == null || StrUtil.isBlank(item.getId()) || StrUtil.isBlank(item.getDt())) {
|
||||
continue;
|
||||
}
|
||||
conditions.add("(STCD = ? AND DT = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS'))");
|
||||
args.add(item.getId());
|
||||
args.add(item.getDt());
|
||||
}
|
||||
if (conditions.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
sql.append(String.join(" OR ", conditions));
|
||||
return normalizeRiverLogRows(jdbcTemplate.queryForList(sql.toString(), args.toArray()));
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> queryRiverMonthRows(List<DataParam> dataList) {
|
||||
if (CollUtil.isEmpty(dataList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
StringBuilder sql = new StringBuilder("SELECT ID, STCD, TO_CHAR(TM, 'YYYY-MM-DD HH24:MI:SS') AS TM, DRTP, YEAR, MONTH, DR, Z, Q, V, MSQMT, ")
|
||||
.append("RECORD_USER, RECORD_TIME, MODIFY_USER, MODIFY_TIME, IS_DELETED, DELETE_USER, DELETE_TIME ")
|
||||
.append("FROM SD_RIVERDRTP_S WHERE ");
|
||||
List<Object> args = new ArrayList<>();
|
||||
List<String> conditions = new ArrayList<>();
|
||||
for (DataParam item : dataList) {
|
||||
if (item == null || StrUtil.isBlank(item.getId()) || StrUtil.isBlank(item.getDrtp())
|
||||
|| StrUtil.isBlank(item.getYear()) || StrUtil.isBlank(item.getMonth())) {
|
||||
continue;
|
||||
}
|
||||
conditions.add("(STCD = ? AND DRTP = ? AND YEAR = ? AND MONTH = ?)");
|
||||
args.add(item.getId());
|
||||
args.add(item.getDrtp());
|
||||
args.add(Integer.parseInt(item.getYear()));
|
||||
args.add(Integer.parseInt(item.getMonth()));
|
||||
}
|
||||
if (conditions.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
sql.append(String.join(" OR ", conditions));
|
||||
return normalizeRiverLogRows(jdbcTemplate.queryForList(sql.toString(), args.toArray()));
|
||||
}
|
||||
|
||||
private List<Map<String, Object>> normalizeRiverLogRows(List<Map<String, Object>> rows) {
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
if (CollUtil.isEmpty(rows)) {
|
||||
return result;
|
||||
}
|
||||
for (Map<String, Object> row : rows) {
|
||||
result.add(normalizeRiverLogRow(row));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Map<String, Object> normalizeRiverLogRow(Map<String, Object> row) {
|
||||
Map<String, Object> normalized = new LinkedHashMap<>();
|
||||
if (row == null || row.isEmpty()) {
|
||||
return normalized;
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : row.entrySet()) {
|
||||
normalized.put(entry.getKey() == null ? null : entry.getKey().toUpperCase(), entry.getValue());
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
private void recordRiverUpdateLog(Map<String, Object> beforeRow, Map<String, Object> updateData, String source) {
|
||||
if (updateData == null || updateData.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String stcd = asString(updateData.get("stcd"));
|
||||
String recordId = asString(beforeRow.get("ID"));
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
for (Map.Entry<String, String> entry : ZQ_UPDATE_COLUMN_MAP.entrySet()) {
|
||||
if (!containsKeyIgnoreCase(updateData, entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
String column = entry.getValue();
|
||||
Object oldValue = beforeRow == null ? null : beforeRow.get(column);
|
||||
Object newValue = getValueIgnoreCase(updateData, entry.getKey());
|
||||
if (StrUtil.equals(formatRiverLogValue(oldValue), formatRiverLogValue(newValue))) {
|
||||
continue;
|
||||
}
|
||||
details.add(buildRiverLogDetail(null, ZQ_HOUR_TABLE_NAME, stcd, column,
|
||||
oldValue, resolveRiverDisplayValue(column, oldValue),
|
||||
newValue, resolveRiverDisplayValue(column, newValue), "修改字段值"));
|
||||
}
|
||||
if (details.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
MsOperationLog mainLog = buildRiverMainLog(recordId,"修改流量站小时数据", source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
for (MsOperationLogDetail detail : details) {
|
||||
detail.setMainId(mainLog.getId());
|
||||
}
|
||||
batchInsertRiverLogDetails(details);
|
||||
}
|
||||
|
||||
private void recordRiverDeleteLog(List<Map<String, Object>> rows, String tableName, String remark, String source) {
|
||||
if (CollUtil.isEmpty(rows)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<MsOperationLogDetail> details = new ArrayList<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
String stcd = asString(row.get("STCD"));
|
||||
String recordId = asString(row.get("ID"));
|
||||
MsOperationLog mainLog = buildRiverMainLog(recordId,remark, source);
|
||||
msOperationLogMapper.insert(mainLog);
|
||||
for (Map.Entry<String, Object> entry : row.entrySet()) {
|
||||
String fieldCode = entry.getKey();
|
||||
Object oldValue = entry.getValue();
|
||||
if (StrUtil.isBlank(fieldCode) || oldValue == null) {
|
||||
continue;
|
||||
}
|
||||
details.add(buildRiverLogDetail(mainLog.getId(), tableName, stcd, fieldCode,
|
||||
oldValue, resolveRiverDisplayValue(fieldCode, oldValue),
|
||||
null, null, "删除字段值"));
|
||||
}
|
||||
}
|
||||
batchInsertRiverLogDetails(details);
|
||||
}
|
||||
|
||||
private MsOperationLog buildRiverMainLog(String recordId,String remark, String source) {
|
||||
MsOperationLog log = new MsOperationLog();
|
||||
log.setOperator(resolveRiverLogOperator());
|
||||
log.setOperateTime(new Date());
|
||||
log.setRecordId(recordId);
|
||||
log.setTableName(ZQ_HOUR_TABLE_NAME);
|
||||
log.setSource(StrUtil.trimToNull(source));
|
||||
log.setRemark(remark);
|
||||
return log;
|
||||
}
|
||||
|
||||
private MsOperationLogDetail buildRiverLogDetail(String mainId,
|
||||
String tableName,
|
||||
String stationCode,
|
||||
String fieldCode,
|
||||
Object oldValueCode,
|
||||
Object oldValueName,
|
||||
Object newValueCode,
|
||||
Object newValueName,
|
||||
String remark) {
|
||||
MsOperationLogDetail detail = new MsOperationLogDetail();
|
||||
detail.setMainId(mainId);
|
||||
detail.setTableName(tableName);
|
||||
detail.setStationCode(stationCode);
|
||||
detail.setFieldCode(fieldCode);
|
||||
detail.setFieldMeaning(ZQ_FIELD_MEANING_MAP.getOrDefault(fieldCode, fieldCode));
|
||||
detail.setOldValueCode(formatRiverLogValue(oldValueCode));
|
||||
detail.setOldValueName(formatRiverLogValue(oldValueName));
|
||||
detail.setNewValueCode(formatRiverLogValue(newValueCode));
|
||||
detail.setNewValueName(formatRiverLogValue(newValueName));
|
||||
detail.setRemark(remark);
|
||||
return detail;
|
||||
}
|
||||
|
||||
private void batchInsertRiverLogDetails(List<MsOperationLogDetail> details) {
|
||||
if (CollUtil.isEmpty(details)) {
|
||||
return;
|
||||
}
|
||||
for (MsOperationLogDetail detail : details) {
|
||||
if (detail == null) {
|
||||
continue;
|
||||
}
|
||||
msOperationLogDetailMapper.insert(detail);
|
||||
}
|
||||
}
|
||||
|
||||
private Object resolveRiverDisplayValue(String fieldCode, Object rawValue) {
|
||||
return formatRiverLogValue(rawValue);
|
||||
}
|
||||
|
||||
private Object getValueIgnoreCase(Map<String, Object> data, String key) {
|
||||
if (data == null || StrUtil.isBlank(key)) {
|
||||
return null;
|
||||
}
|
||||
if (data.containsKey(key)) {
|
||||
return data.get(key);
|
||||
}
|
||||
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
||||
if (StrUtil.equalsIgnoreCase(entry.getKey(), key)) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean containsKeyIgnoreCase(Map<String, Object> data, String key) {
|
||||
if (data == null || StrUtil.isBlank(key)) {
|
||||
return false;
|
||||
}
|
||||
if (data.containsKey(key)) {
|
||||
return true;
|
||||
}
|
||||
for (String mapKey : data.keySet()) {
|
||||
if (StrUtil.equalsIgnoreCase(mapKey, key)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String resolveRiverLogOperator() {
|
||||
try {
|
||||
return SecurityUtils.getCurrentUsername();
|
||||
} catch (Exception ignored) {
|
||||
try {
|
||||
return SecurityUtils.getUserId();
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String formatRiverLogValue(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (value instanceof Date date) {
|
||||
return cn.hutool.core.date.DateUtil.formatDateTime(date);
|
||||
}
|
||||
return String.valueOf(value);
|
||||
}
|
||||
|
||||
private void statisticsDayDataFromHour(String stcd, String startDate, String endDate) {
|
||||
String deleteSql = "DELETE FROM SD_RIVERDAY_S T " +
|
||||
"WHERE T.STCD = ? " +
|
||||
|
||||
Loading…
Reference in New Issue
Block a user