|
|
@@ -13,18 +13,21 @@ import java.util.LinkedHashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
+import java.util.UUID;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.ufo.base.common.exception.ServiceException;
|
|
|
+import com.ufo.base.common.utils.SecurityUtils;
|
|
|
import com.ufo.base.common.utils.StringUtils;
|
|
|
import com.ufo.module.system.domain.SysDictData;
|
|
|
import com.ufo.module.system.service.ISysDictTypeService;
|
|
|
import com.ufo.project.config.domain.ConfigStation;
|
|
|
import com.ufo.project.config.service.IConfigStationService;
|
|
|
import com.ufo.project.forecast.fileupload.domain.DataReportLog;
|
|
|
+import com.ufo.project.forecast.fileupload.domain.vo.ReUploadCountRow;
|
|
|
import com.ufo.project.forecast.fileupload.domain.vo.UploadRateCountRow;
|
|
|
import com.ufo.project.forecast.fileupload.domain.vo.UploadRateStatQuery;
|
|
|
import com.ufo.project.forecast.fileupload.domain.vo.UploadRateStatVO;
|
|
|
@@ -132,6 +135,136 @@ public class DataReportLogServiceImpl implements IDataReportLogService
|
|
|
return buildDayVos(range[0], range[1], query.getStationCode());
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public String reUpload(String stationCode)
|
|
|
+ {
|
|
|
+ if (StringUtils.isEmpty(stationCode))
|
|
|
+ {
|
|
|
+ throw new ServiceException("stationCode不能为空");
|
|
|
+ }
|
|
|
+ Map<String, Integer> nums = loadNums();
|
|
|
+ Map<String, String> labels = loadLabels();
|
|
|
+ LocalDate today = LocalDate.now(ZoneId.of("Asia/Shanghai"));
|
|
|
+ List<ReUploadCountRow> rows = dataReportLogMapper.selectTodayCounts(stationCode, today.toString());
|
|
|
+ Map<String, Long> successCnt = new HashMap<>();
|
|
|
+ Map<String, Long> pendingCnt = new HashMap<>();
|
|
|
+ for (ReUploadCountRow row : rows)
|
|
|
+ {
|
|
|
+ if (row.getStatus() == null)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (row.getStatus() == 1)
|
|
|
+ {
|
|
|
+ successCnt.merge(row.getType(), row.getCnt() == null ? 0L : row.getCnt(), Long::sum);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pendingCnt.merge(row.getType(), row.getCnt() == null ? 0L : row.getCnt(), Long::sum);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按ALL_TYPES固定顺序逐类决策: 成功数>=num视为已完成; 存在待发送(上传中/处理中)则跳过; 否则补插缺失条数
|
|
|
+ List<String> pendingLabels = new ArrayList<>();
|
|
|
+ int insertCount = 0;
|
|
|
+ Date now = new Date();
|
|
|
+ String username = SecurityUtils.getUsername();
|
|
|
+ for (String type : ALL_TYPES)
|
|
|
+ {
|
|
|
+ int num = nums.get(type);
|
|
|
+ long ok = successCnt.getOrDefault(type, 0L);
|
|
|
+ long pending = pendingCnt.getOrDefault(type, 0L);
|
|
|
+ if (ok >= num)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (pending > 0)
|
|
|
+ {
|
|
|
+ pendingLabels.add(labels.getOrDefault(type, type));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < num - ok; i++)
|
|
|
+ {
|
|
|
+ dataReportLogMapper.insert(buildReUploadLog(type, stationCode, now, username));
|
|
|
+ insertCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (insertCount == 0 && pendingLabels.isEmpty())
|
|
|
+ {
|
|
|
+ return "当日文件已全部上传,无需补传";
|
|
|
+ }
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ if (insertCount > 0)
|
|
|
+ {
|
|
|
+ sb.append("补传成功 ").append(insertCount).append(" 条");
|
|
|
+ }
|
|
|
+ if (!pendingLabels.isEmpty())
|
|
|
+ {
|
|
|
+ if (sb.length() > 0)
|
|
|
+ {
|
|
|
+ sb.append(",");
|
|
|
+ }
|
|
|
+ sb.append("以下类型正在上传/处理中,未补传: ").append(String.join("、", pendingLabels));
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造补传记录: 固定模拟字段值(curve_id=9999/省调/通道1/ACK:OK/模拟生成), message_no随机保证唯一
|
|
|
+ */
|
|
|
+ private DataReportLog buildReUploadLog(String type, String stationCode, Date now, String username)
|
|
|
+ {
|
|
|
+ DataReportLog log = new DataReportLog();
|
|
|
+ log.setType(type);
|
|
|
+ log.setStationCode(stationCode);
|
|
|
+ log.setCurveId(9999L);
|
|
|
+ log.setEstReportTime(now);
|
|
|
+ log.setReportTime(now);
|
|
|
+ log.setTargetDispatch("省调");
|
|
|
+ log.setChannel(1);
|
|
|
+ log.setMessageNo("SUP" + now.getTime() + type
|
|
|
+ + UUID.randomUUID().toString().replace("-", "").substring(0, 8).toUpperCase());
|
|
|
+ log.setStatus(1);
|
|
|
+ log.setResponseMsg("ACK:OK");
|
|
|
+ log.setRemark("模拟生成");
|
|
|
+ log.setCreateTime(now);
|
|
|
+ log.setUpdateTime(now);
|
|
|
+ log.setCreateBy(username);
|
|
|
+ log.setUpdateBy(username);
|
|
|
+ return log;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读字典 daily_file_upload_config → type→中文label(用于提示消息), 解析失败回退type编码
|
|
|
+ */
|
|
|
+ private Map<String, String> loadLabels()
|
|
|
+ {
|
|
|
+ Map<String, String> labels = new HashMap<>();
|
|
|
+ List<SysDictData> dictDatas = dictTypeService.selectDictDataByType(DICT_TYPE);
|
|
|
+ if (dictDatas == null || dictDatas.isEmpty())
|
|
|
+ {
|
|
|
+ return labels;
|
|
|
+ }
|
|
|
+ for (SysDictData dict : dictDatas)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ JSONObject obj = JSON.parseObject(dict.getDictValue());
|
|
|
+ String type = obj == null ? null : obj.getString("type");
|
|
|
+ if (StringUtils.isNotEmpty(type) && StringUtils.isNotEmpty(dict.getDictLabel()))
|
|
|
+ {
|
|
|
+ labels.put(type, dict.getDictLabel());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ // label解析失败时该type回退为type编码
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return labels;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 按计划上报时间过滤单日(queryDate, yyyy-MM-dd)
|
|
|
*/
|