Files
invyone/backend-spring/src/main/java/com/erp/service/RiskAlertService.java
T

81 lines
5.5 KiB
Java

package com.erp.service;
import com.erp.common.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
@Service
@Slf4j
public class RiskAlertService extends BaseService {
@Autowired private CommonService commonService;
// ──────────────────────────────────────────────────────────────────────────
// 전체 알림 목록 조회
// ──────────────────────────────────────────────────────────────────────────
public Map<String, Object> getAllAlerts(Map<String, Object> params) {
commonService.applyPagination(params);
Number cntNum = sqlSession.selectOne("riskAlert.getAllAlertsCnt", params);
int totalCount = cntNum != null ? cntNum.intValue() : 0;
List<Map<String, Object>> list = sqlSession.selectList("riskAlert.getAllAlerts", params);
return commonService.buildListResponse(list, totalCount, params);
}
// ──────────────────────────────────────────────────────────────────────────
// 알림 새로고침 (외부 데이터 갱신 트리거)
// ──────────────────────────────────────────────────────────────────────────
public Map<String, Object> refreshAlerts(Map<String, Object> params) {
// 현재 활성 알림 현황 반환
int weatherCount = sqlSession.selectList("riskAlert.getAlertsByType", buildTypeParams(params, "weather")).size();
int accidentCount = sqlSession.selectList("riskAlert.getAlertsByType", buildTypeParams(params, "accident")).size();
int roadworkCount = sqlSession.selectList("riskAlert.getAlertsByType", buildTypeParams(params, "roadwork")).size();
Map<String, Object> result = new LinkedHashMap<>();
result.put("refreshed", true);
result.put("weather_count", weatherCount);
result.put("accident_count", accidentCount);
result.put("roadwork_count", roadworkCount);
result.put("total_count", weatherCount + accidentCount + roadworkCount);
return result;
}
// ──────────────────────────────────────────────────────────────────────────
// 기상 알림 조회
// ──────────────────────────────────────────────────────────────────────────
public List<Map<String, Object>> getWeatherAlerts(Map<String, Object> params) {
params.put("alert_type", "weather");
params.put("is_active", "Y");
return sqlSession.selectList("riskAlert.getAlertsByType", params);
}
// ──────────────────────────────────────────────────────────────────────────
// 사고 알림 조회
// ──────────────────────────────────────────────────────────────────────────
public List<Map<String, Object>> getAccidentAlerts(Map<String, Object> params) {
params.put("alert_type", "accident");
params.put("is_active", "Y");
return sqlSession.selectList("riskAlert.getAlertsByType", params);
}
// ──────────────────────────────────────────────────────────────────────────
// 공사 알림 조회
// ──────────────────────────────────────────────────────────────────────────
public List<Map<String, Object>> getRoadworkAlerts(Map<String, Object> params) {
params.put("alert_type", "roadwork");
params.put("is_active", "Y");
return sqlSession.selectList("riskAlert.getAlertsByType", params);
}
// ──────────────────────────────────────────────────────────────────────────
// 유틸리티
// ──────────────────────────────────────────────────────────────────────────
private Map<String, Object> buildTypeParams(Map<String, Object> base, String alertType) {
Map<String, Object> p = new HashMap<>(base);
p.put("alert_type", alertType);
p.put("is_active", "Y");
return p;
}
}