fix: 修改生态流量小时数据

This commit is contained in:
tangwei 2026-08-19 18:27:04 +08:00
parent 6cba0db429
commit 40ceffcfd6
4 changed files with 163 additions and 0 deletions

View File

@ -16,6 +16,7 @@ import com.yfd.platform.qgc_eng.eq.entity.vo.EngEqMsstbprptVo;
import com.yfd.platform.qgc_eng.eq.entity.vo.EngEqRuleVo;
import com.yfd.platform.qgc_eng.eq.entity.vo.EngEqVmsstbprptVo;
import com.yfd.platform.qgc_eng.eq.entity.vo.EngEqRateCountVo;
import com.yfd.platform.qgc_eng.eq.entity.vo.EqOperateRequest;
import com.yfd.platform.qgc_eng.eq.service.EngEqDataService;
import com.yfd.platform.qgc_eng.eq.entity.vo.QgcQecStaticVo;
import com.yfd.platform.qgc_eng.eq.entity.vo.StcdInfoVo;
@ -203,4 +204,15 @@ public class EngEqDataController {
engEqDataService.removeKendoByIds(batchDeleteAo);
return ResponseResult.success();
}
@Log(module = "生态流量监测数据管理", value = "修改生态流量小时数据")
@PostMapping("/data/updateEqRsData")
@Operation(summary = "修改生态流量小时数据")
public ResponseResult updateEqRsData(@RequestBody EqOperateRequest eqOperateRequest) {
engEqDataService.updateQecRsData(
eqOperateRequest == null ? null : eqOperateRequest.getUpdateData(),
eqOperateRequest == null ? null : eqOperateRequest.getSource()
);
return ResponseResult.success();
}
}

View File

@ -0,0 +1,24 @@
package com.yfd.platform.qgc_eng.eq.entity.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.io.Serializable;
import java.util.Map;
/**
* 生态流量数据操作请求
* <p>updateData: 修改数据其中 stcd/tm 为定位条件其余 key 对应小时表可修改字段</p>
*/
@Data
@Schema(description = "生态流量数据操作请求")
public class EqOperateRequest implements Serializable {
private static final long serialVersionUID = 1L;
@Schema(description = "数据来源")
private String source;
@Schema(description = "修改数据")
private Map<String, Object> updateData;
}

View File

@ -85,4 +85,13 @@ public interface EngEqDataService {
* @param batchDeleteAo dataType: TIME=小时 DATE= MON=dataList: 删除数据列表
*/
boolean removeKendoByIds(BatchDeleteAo batchDeleteAo);
/**
* 修改生态流量小时数据
* <p>修改后会按受影响站点重新聚合日表(SD_QECDAY_S)和月表(SD_QECDRTP_S)</p>
*
* @param updateData 修改数据stcd/tm 为定位条件其余 key 对应小时表可修改字段
* @param source 数据来源
*/
boolean updateQecRsData(Map<String, Object> updateData, String source);
}

View File

@ -3,6 +3,7 @@ package com.yfd.platform.qgc_eng.eq.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.yfd.platform.common.exception.BizException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yfd.platform.common.DataSourceLoadOptionsBase;
import com.yfd.platform.common.DataSourceRequest;
@ -112,6 +113,26 @@ public class EngEqDataServiceImpl implements EngEqDataService {
QEC_FIELD_MEANING_MAP.put("SHOW_FLAG", "数据显示类型");
}
private static final LinkedHashMap<String, String> QEC_UPDATE_COLUMN_MAP = new LinkedHashMap<>();
static {
QEC_UPDATE_COLUMN_MAP.put("qec", "QEC");
QEC_UPDATE_COLUMN_MAP.put("waterflow", "WATERFLOW");
QEC_UPDATE_COLUMN_MAP.put("tpqec", "TPQEC");
QEC_UPDATE_COLUMN_MAP.put("sfdb", "SFDB");
QEC_UPDATE_COLUMN_MAP.put("mwrSfdb", "MWR_SFDB");
QEC_UPDATE_COLUMN_MAP.put("avqSfdb", "AVQ_SFDB");
QEC_UPDATE_COLUMN_MAP.put("qecLimit", "QEC_LIMIT");
QEC_UPDATE_COLUMN_MAP.put("mwrLimit", "MWR_LIMIT");
QEC_UPDATE_COLUMN_MAP.put("avqLimit", "AVQ_LIMIT");
QEC_UPDATE_COLUMN_MAP.put("qecC", "QEC_C");
QEC_UPDATE_COLUMN_MAP.put("mwrC", "MWR_C");
QEC_UPDATE_COLUMN_MAP.put("avqC", "AVQ_C");
QEC_UPDATE_COLUMN_MAP.put("qecRuleDid", "QEC_RULE_DID");
QEC_UPDATE_COLUMN_MAP.put("qecMwrruleDid", "QEC_MWRRULE_DID");
QEC_UPDATE_COLUMN_MAP.put("showFlag", "SHOW_FLAG");
}
@Override
public DataSourceResult getKendoListCust(DataSourceRequest dataSourceRequest) {
DataSourceLoadOptionsBase loadOptions = dataSourceRequest == null ? null : dataSourceRequest.toDevRequest();
@ -6716,6 +6737,103 @@ public class EngEqDataServiceImpl implements EngEqDataService {
return "tm".equalsIgnoreCase(field);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean updateQecRsData(Map<String, Object> updateData, String source) {
if (updateData == null || updateData.isEmpty()) {
return true;
}
String stcd = asString(updateData.get("stcd"));
String tm = asString(updateData.get("tm"));
Map<String, Object> beforeHour = queryQecHourRow(stcd, tm);
updateQecHourData(updateData);
recordQecUpdateLog(beforeHour, updateData, source);
if (StrUtil.isNotBlank(stcd) && StrUtil.isNotBlank(tm) && tm.length() >= 10) {
String dateStr = tm.substring(0, 10);
statisticsQecDayDataFromHour(stcd, dateStr, dateStr);
String[] ym = dateStr.substring(0, 7).split("-");
if (ym.length == 2) {
Integer year = Integer.parseInt(ym[0]);
Integer month = Integer.parseInt(ym[1]);
String startDate = year + "-" + String.format("%02d", month) + "-01";
String endDate = getMonthEndDate(year, month);
statisticsQecMonthDataFromDay(stcd, startDate, endDate);
}
}
return true;
}
private void updateQecHourData(Map<String, Object> updateData) {
List<String> setClauses = new ArrayList<>();
List<Object> params = new ArrayList<>();
for (Map.Entry<String, String> entry : QEC_UPDATE_COLUMN_MAP.entrySet()) {
if (updateData.containsKey(entry.getKey())) {
setClauses.add(entry.getValue() + " = ?");
params.add(updateData.get(entry.getKey()));
}
}
if (setClauses.isEmpty()) {
return;
}
String stcd = asString(updateData.get("stcd"));
String tm = asString(updateData.get("tm"));
if (StrUtil.isBlank(stcd) || StrUtil.isBlank(tm)) {
throw new BizException("站点编码和时间不能为空");
}
String sql = "UPDATE SD_QEC_R SET " + String.join(", ", setClauses)
+ " WHERE STCD = ? AND TM = TO_DATE(?, 'YYYY-MM-DD HH24:MI:SS')";
params.add(stcd);
params.add(tm);
jdbcTemplate.update(sql, params.toArray());
}
private Map<String, Object> queryQecHourRow(String stcd, String tm) {
if (StrUtil.isBlank(stcd) || StrUtil.isBlank(tm)) {
return new HashMap<>();
}
String sql = "SELECT " + buildQecHourLogSelectColumns() +
" FROM SD_QEC_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<>() : normalizeLogRow(rows.get(0));
}
private void recordQecUpdateLog(Map<String, Object> beforeHour,
Map<String, Object> updateData,
String source) {
if (updateData == null || updateData.isEmpty()) {
return;
}
String stcd = asString(updateData.get("stcd"));
List<MsOperationLogDetail> details = new ArrayList<>();
for (Map.Entry<String, String> entry : QEC_UPDATE_COLUMN_MAP.entrySet()) {
if (!updateData.containsKey(entry.getKey())) {
continue;
}
String column = entry.getValue();
Object oldValue = beforeHour == null ? null : beforeHour.get(column);
Object newValue = updateData.get(entry.getKey());
if (StrUtil.equals(formatLogValue(oldValue), formatLogValue(newValue))) {
continue;
}
details.add(buildQecDetail(null, QEC_HOUR_TABLE_NAME, stcd, column,
oldValue, resolveQecDisplayValue(column, oldValue),
newValue, resolveQecDisplayValue(column, newValue), "修改字段值"));
}
if (details.isEmpty()) {
return;
}
String recordId = beforeHour != null && !beforeHour.isEmpty()
&& beforeHour.get("ID") != null ? beforeHour.get("ID").toString() : null;
MsOperationLog mainLog = buildQecMainLog(recordId, "修改生态流量小时数据", source,"02");
msOperationLogMapper.insert(mainLog);
for (MsOperationLogDetail detail : details) {
detail.setMainId(mainLog.getId());
}
batchInsertQecLogDetails(details);
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeKendoByIds(BatchDeleteAo batchDeleteAo) {