Browse Source

fix: 修复汇聚缺陷记录按时间查询;暂时不统计轻微缺陷数量

feature/agg
yinhuaiwei 2 weeks ago
parent
commit
aa604167e0
6 changed files with 79 additions and 16 deletions
  1. +8
    -0
      inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/config/AggProperties.java
  2. +4
    -3
      inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/mapper/AggDefectRecordMapper.java
  3. +17
    -4
      inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/service/AggStatisticService.java
  4. +2
    -2
      inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/service/DefectRecordSyncService.java
  5. +41
    -3
      inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/web/AggDefectRecordController.java
  6. +7
    -4
      inspect-main/inspect-main-agg/src/main/resources/mapper/AggDefectRecordMapper.xml

+ 8
- 0
inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/config/AggProperties.java View File

@ -24,6 +24,8 @@ public class AggProperties {
private Http http = new Http();
private Statistic statistic = new Statistic();
@Data
public static class Sync {
/** 基础数据同步公共配置(轮询周期见 SyncDefaults,已写死在代码) */
@ -92,4 +94,10 @@ public class AggProperties {
private int connectTimeoutMs = 10_000;
private int readTimeoutMs = 30_000;
}
@Data
public static class Statistic {
/** 是否统计轻微缺陷;false 时 minorCount 恒为 0,且不计入 defectCount */
private boolean minorDefectEnabled = false;
}
}

+ 4
- 3
inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/mapper/AggDefectRecordMapper.java View File

@ -17,9 +17,10 @@ public interface AggDefectRecordMapper {
List<AggDefectRecord> selectList(@Param("stationCode") String stationCode,
@Param("pointName") String pointName,
@Param("patrolTimeBegin") String patrolTimeBegin,
@Param("patrolTimeEnd") String patrolTimeEnd,
@Param("algName") String algName);
@Param("beginTime") String beginTime,
@Param("endTime") String endTime,
@Param("algName") String algName,
@Param("defectLevel") Integer defectLevel);
List<String> selectDistinctAlgNames(@Param("stationCode") String stationCode);
}

+ 17
- 4
inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/service/AggStatisticService.java View File

@ -13,6 +13,7 @@ import java.util.Map;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.inspect.agg.config.AggProperties;
import com.inspect.agg.entity.AggAnalysisDefectMonth;
import com.inspect.agg.entity.AggStation;
import com.inspect.agg.enums.AlgCategory;
@ -34,6 +35,7 @@ public class AggStatisticService {
private final AggAnalysisDefectMonthMapper defectMonthMapper;
private final AggPatrolTaskStatusMapper taskStatusMapper;
private final AggStationMapper stationMapper;
private final AggProperties props;
public List<Map<String, Object>> defectStatistic(String stationCode, String algCategory,
String dateType) {
@ -159,12 +161,12 @@ public class AggStatisticService {
item.put("stationCode", stationCode);
item.put("stationName", stationName != null ? stationName : stationCode);
}
item.put("minorCount", counts.minor);
item.put("minorCount", minorCount(counts));
item.put("generalCount", counts.general);
item.put("seriousCount", counts.serious);
item.put("urgentCount", counts.urgent);
item.put("normalCount", counts.normal);
item.put("defectCount", counts.defectCount());
item.put("defectCount", defectCount(counts));
return item;
}
@ -179,14 +181,25 @@ public class AggStatisticService {
}
result.put("inspectedTaskCount", number(taskStats, "inspected_task_count"));
result.put("completedTaskCount", number(taskStats, "completed_task_count"));
result.put("defectCount", defectStats.defectCount());
result.put("minorCount", defectStats.minor);
result.put("defectCount", defectCount(defectStats));
result.put("minorCount", minorCount(defectStats));
result.put("generalCount", defectStats.general);
result.put("seriousCount", defectStats.serious);
result.put("urgentCount", defectStats.urgent);
return result;
}
private int minorCount(Counts counts) {
return props.getStatistic().isMinorDefectEnabled() ? counts.minor : 0;
}
private long defectCount(Counts counts) {
if (props.getStatistic().isMinorDefectEnabled()) {
return counts.defectCount();
}
return (long) counts.general + counts.serious + counts.urgent;
}
private String stationDisplayName(String stationCode) {
if (!StringUtils.hasText(stationCode)) {
return null;


+ 2
- 2
inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/service/DefectRecordSyncService.java View File

@ -95,8 +95,8 @@ public class DefectRecordSyncService {
String message = null;
try {
Map<String, String> query = new HashMap<>();
query.put("patrolTimeBegin", LocalDate.now().minusDays(7).toString());
query.put("patrolTimeEnd", LocalDate.now().toString());
query.put("beginTime", LocalDate.now().minusDays(7).toString());
query.put("endTime", LocalDate.now().toString());
List<JsonNode> rows = stationApiClient.fetchAllRows(station, PATH,
props.getSync().getBase().getPageSize(), 200, query, "lineId");
for (JsonNode row : rows) {


+ 41
- 3
inspect-main/inspect-main-agg/src/main/java/com/inspect/agg/web/AggDefectRecordController.java View File

@ -33,19 +33,27 @@ public class AggDefectRecordController {
return AjaxResult.success(defectRecordMapper.selectDistinctAlgNames(stationCode));
}
/**
* 缺陷记录分页查询。
* beginTime / endTime 按 patrol_time 过滤,支持 yyyy-MM-dd 或 yyyy-MM-dd HH:mm:ss;
* 只传日期时自动补 00:00:00 / 23:59:59。
*/
@GetMapping("/defect/list")
public TableDataInfo defectList(@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String pointName,
@RequestParam(required = false) String patrolTimeBegin,
@RequestParam(required = false) String patrolTimeEnd,
@RequestParam(required = false) String beginTime,
@RequestParam(required = false) String endTime,
@RequestParam(required = false) String algName,
@RequestParam(required = false) Integer defectLevel,
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize) {
int safePageNum = pageNum == null || pageNum < 1 ? 1 : pageNum;
int safePageSize = pageSize == null || pageSize < 1 ? 10 : pageSize;
String rangeBegin = beginOf(beginTime);
String rangeEnd = endOf(endTime);
PageHelper.startPage(safePageNum, safePageSize);
List<AggDefectRecord> list = defectRecordMapper.selectList(
stationCode, pointName, patrolTimeBegin, patrolTimeEnd, algName);
stationCode, pointName, rangeBegin, rangeEnd, algName, defectLevel);
rewriteImageUrls(stationCode, list);
PageInfo<AggDefectRecord> pageInfo = new PageInfo<>(list);
TableDataInfo result = new TableDataInfo();
@ -56,6 +64,36 @@ public class AggDefectRecordController {
return result;
}
/** 日期 -> 当天 00:00:00;带时分秒时原样使用。 */
private static String beginOf(String value) {
String normalized = normalize(value);
if (normalized == null) {
return null;
}
return normalized.length() <= 10 ? normalized + " 00:00:00" : normalized;
}
/** 日期 -> 当天 23:59:59;带时分秒时原样使用。 */
private static String endOf(String value) {
String normalized = normalize(value);
if (normalized == null) {
return null;
}
return normalized.length() <= 10 ? normalized + " 23:59:59" : normalized;
}
private static String normalize(String value) {
if (value == null) {
return null;
}
String trimmed = value.trim();
if (trimmed.isEmpty()) {
return null;
}
return trimmed.replace('T', ' ');
}
/**
* 出参图片字段仍是站端 SFTP 相对路径,按 stationCode 统一拼为集控 nginx 反代地址,
* 前端字段名和用法不变,直接作为 <img src> 使用。


+ 7
- 4
inspect-main/inspect-main-agg/src/main/resources/mapper/AggDefectRecordMapper.xml View File

@ -133,15 +133,18 @@
<if test="pointName != null and pointName != ''">
AND d.point_name LIKE CONCAT('%', #{pointName}, '%')
</if>
<if test="patrolTimeBegin != null and patrolTimeBegin != ''">
AND d.patrol_time &gt;= CONCAT(#{patrolTimeBegin}, ' 00:00:00')
<if test="beginTime != null and beginTime != ''">
AND d.patrol_time &gt;= #{beginTime}
</if>
<if test="patrolTimeEnd != null and patrolTimeEnd != ''">
AND d.patrol_time &lt;= CONCAT(#{patrolTimeEnd}, ' 23:59:59')
<if test="endTime != null and endTime != ''">
AND d.patrol_time &lt;= #{endTime}
</if>
<if test="algName != null and algName != ''">
AND d.alg_name = #{algName}
</if>
<if test="defectLevel != null">
AND d.defect_level = #{defectLevel}
</if>
ORDER BY d.patrol_time DESC, d.id DESC
</select>


Loading…
Cancel
Save