260515_01_ENH: 다른 설문들도 공통 포맷으로 data 조회 되도록 수정 및 필요 상수 추가
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
package com.kri.kfpa.dash.common.consts;
|
||||
|
||||
import com.kri.kfpa.dash.dto.CsiDataDto;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public final class KfpaDashConstant {
|
||||
|
||||
public static final String KFPA_DASH_PKEY = "2601009_A";
|
||||
public static final String KFPA_COMMENT_PKEY = "2604005_F";
|
||||
|
||||
public static final String SAFETY_INSPECTION_PKEY = KFPA_DASH_PKEY;
|
||||
public static final String UCSI_PKEY = "2604005_E";
|
||||
public static final String BRIDGE_PLATFORM_PKEY = "2604005_D";
|
||||
public static final String CONSULTING_PKEY = "2604005_C";
|
||||
public static final String INSURANCE_OPERATIONS_PKEY = "2604005_A";
|
||||
public static final String FIRE_INVESTIGATION_PKEY = "2604005_B";
|
||||
|
||||
public static final String TOTAL = "-1";
|
||||
public static final String SEOUL = "1";
|
||||
public static final String GYEONGGI = "3";
|
||||
@@ -14,27 +23,65 @@ public final class KfpaDashConstant {
|
||||
public static final String DAEGU = "5";
|
||||
public static final String DAEJEON = "6";
|
||||
public static final String GWANGJU = "4";
|
||||
public static final String RISK_MANAGEMENT = "11";
|
||||
public static final String INSEUDATA = "21";
|
||||
|
||||
private static final String IDKEY_PREFIX = "Q1003_";
|
||||
|
||||
public static final List<String> QUERY_QIDS = List.of("q1", "q2", "q4", "q5");
|
||||
public static final Map<String, List<String>> REAL_QIDS = Map.of(
|
||||
SAFETY_INSPECTION_PKEY, List.of("Q1", "Q2", "Q7", "Q10"),
|
||||
UCSI_PKEY, List.of("Q2", "Q5", "Q6", "Q11"),
|
||||
BRIDGE_PLATFORM_PKEY, List.of("Q2", "Q4", "Q5", "Q6"),
|
||||
CONSULTING_PKEY, List.of("Q10", "Q8", "Q12", "Q15"),
|
||||
INSURANCE_OPERATIONS_PKEY, List.of("Q3", "Q4", "Q5", "Q6"),
|
||||
FIRE_INVESTIGATION_PKEY, List.of("Q1", "Q3", "Q5", "Q14")
|
||||
);
|
||||
public static final Map<String, Map<String, Double>> WEIGHTS = Map.of(
|
||||
SAFETY_INSPECTION_PKEY, Map.of("q1", 0.4,"q2", 0.4,"q4", 0.1,"q5", 0.1),
|
||||
UCSI_PKEY, Map.of("q1", 0.4,"q2", 0.4,"q4", 0.1,"q5", 0.1),
|
||||
BRIDGE_PLATFORM_PKEY, Map.of("q1", 0.4,"q2", 0.4,"q4", 0.1,"q5", 0.1),
|
||||
CONSULTING_PKEY, Map.of("q1", 0.35,"q2", 0.35,"q4", 0.15,"q5", 0.15),
|
||||
INSURANCE_OPERATIONS_PKEY, Map.of("q1", 0.35,"q2", 0.35,"q4", 0.15,"q5", 0.15),
|
||||
FIRE_INVESTIGATION_PKEY, Map.of("q1", 0.35,"q2", 0.35,"q4", 0.15,"q5", 0.15)
|
||||
);
|
||||
|
||||
public static final Map<String, String> IDKEY_MAP = Map.of(
|
||||
SEOUL, IDKEY_PREFIX + SEOUL,
|
||||
GYEONGGI, IDKEY_PREFIX + GYEONGGI,
|
||||
BUSAN, IDKEY_PREFIX + BUSAN,
|
||||
DAEGU, IDKEY_PREFIX + DAEGU,
|
||||
DAEJEON, IDKEY_PREFIX + DAEJEON,
|
||||
GWANGJU, IDKEY_PREFIX + GWANGJU
|
||||
GWANGJU, IDKEY_PREFIX + GWANGJU,
|
||||
RISK_MANAGEMENT, IDKEY_PREFIX + RISK_MANAGEMENT,
|
||||
INSEUDATA, IDKEY_PREFIX + INSEUDATA
|
||||
);
|
||||
|
||||
public static final Map<String, CsiDataDto> DATA_2025 = Map.of(
|
||||
TOTAL, CsiDataDto.of(2025,4.47, 4.46, null, 4.43, 4.63),
|
||||
SEOUL, CsiDataDto.of(2025,4.39, 4.36, null, 4.37, 4.63),
|
||||
GYEONGGI, CsiDataDto.of(2025,4.48, 4.46, null, 4.44, 4.65),
|
||||
BUSAN, CsiDataDto.of(2025,4.43, 4.41, null, 4.39, 4.62),
|
||||
DAEGU, CsiDataDto.of(2025,4.56, 4.55, null, 4.54, 4.66),
|
||||
DAEJEON, CsiDataDto.of(2025,4.47, 4.47, null, 4.40, 4.57),
|
||||
GWANGJU, CsiDataDto.of(2025,4.52, 4.51, null, 4.46, 4.67)
|
||||
public static final Map<String, Map<String, CsiDataDto>> DATA_2025 = Map.of(
|
||||
SAFETY_INSPECTION_PKEY, Map.of(
|
||||
TOTAL, CsiDataDto.of(2025, null,4.47, 4.46, null, 4.43, 4.63),
|
||||
SEOUL, CsiDataDto.of(2025, null,4.39, 4.36, null, 4.37, 4.63),
|
||||
GYEONGGI, CsiDataDto.of(2025, null,4.48, 4.46, null, 4.44, 4.65),
|
||||
BUSAN, CsiDataDto.of(2025, null,4.43, 4.41, null, 4.39, 4.62),
|
||||
DAEGU, CsiDataDto.of(2025, null,4.56, 4.55, null, 4.54, 4.66),
|
||||
DAEJEON, CsiDataDto.of(2025, null,4.47, 4.47, null, 4.40, 4.57),
|
||||
GWANGJU, CsiDataDto.of(2025, null,4.52, 4.51, null, 4.46, 4.67)
|
||||
),
|
||||
UCSI_PKEY, Map.of(
|
||||
TOTAL, CsiDataDto.of(2025, null,4.37, 4.40, 4.36, 4.33, null)
|
||||
),
|
||||
BRIDGE_PLATFORM_PKEY, Map.of(
|
||||
TOTAL, CsiDataDto.of(2025, null,4.43, 4.44, null, 4.38, 4.41)
|
||||
),
|
||||
CONSULTING_PKEY, Map.of(
|
||||
TOTAL, CsiDataDto.of(2025, null,4.82, 4.81, 4.76, 4.90, 4.90)
|
||||
),
|
||||
INSURANCE_OPERATIONS_PKEY, Map.of(
|
||||
TOTAL, CsiDataDto.of(2025, null,4.89, 4.94, 4.84, 4.88, 4.94)
|
||||
),
|
||||
FIRE_INVESTIGATION_PKEY, Map.of(
|
||||
TOTAL, CsiDataDto.of(2025, null,4.46, 4.50, null, 4.75, 4.00)
|
||||
)
|
||||
);
|
||||
|
||||
private KfpaDashConstant() {}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.kri.kfpa.dash.controller;
|
||||
|
||||
import com.kri.kfpa.dash.dto.CsiDataDto;
|
||||
import com.kri.kfpa.dash.dto.CsiSummaryDto;
|
||||
import com.kri.kfpa.dash.dto.DivDetailDataDto;
|
||||
import com.kri.kfpa.dash.service.StatisticsService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -11,6 +12,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@@ -21,18 +23,31 @@ public class StatisticsController {
|
||||
|
||||
private final StatisticsService statisticsService;
|
||||
|
||||
@Operation(summary = "전체 summary 조회")
|
||||
@GetMapping("/csi-summary")
|
||||
public Map<String, List<CsiSummaryDto>> getCsiSummary(
|
||||
@RequestParam(name = "dt") String searchDateTime
|
||||
) {
|
||||
return statisticsService.getCsiSummary(searchDateTime);
|
||||
}
|
||||
|
||||
@Operation(summary = "csi 데이터 조회")
|
||||
@GetMapping("/csi")
|
||||
public Map<String, List<CsiDataDto>> getCsiData() {
|
||||
return statisticsService.getCsiData();
|
||||
public Map<String, List<CsiDataDto>> getCsiData(
|
||||
@RequestParam(name = "pkey") String pkey,
|
||||
@RequestParam(name = "dt") String searchDateTime
|
||||
) {
|
||||
return statisticsService.getCsiData(pkey, searchDateTime);
|
||||
}
|
||||
|
||||
@Operation(summary = "지역 본부 상세 조회")
|
||||
@GetMapping("/div-detail/{div}")
|
||||
public Map<String, DivDetailDataDto> getDivDetailData(
|
||||
@PathVariable String div
|
||||
@PathVariable String div,
|
||||
@RequestParam(name = "pkey") String pkey,
|
||||
@RequestParam(name = "dt") String searchDateTime
|
||||
) {
|
||||
return statisticsService.getDivDetailData(div);
|
||||
return statisticsService.getDivDetailData(div, pkey, searchDateTime);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,51 +7,47 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@SuperBuilder
|
||||
@Schema(description = "CSI 계산결과 Dto")
|
||||
public class CsiDataDto {
|
||||
public class CsiDataDto extends CsiSummaryDto {
|
||||
|
||||
@Schema(description = "연도")
|
||||
private Integer wave;
|
||||
@Schema(description = "직접요소 1")
|
||||
private Double direct1;
|
||||
|
||||
@Schema(description = "CSI 점수")
|
||||
private Double csi;
|
||||
@Schema(description = "직접요소 2")
|
||||
private Double direct2;
|
||||
|
||||
@Schema(description = "현장 안전점검 도움 정도")
|
||||
private Double safeHelp;
|
||||
@Schema(description = "간접요소 1")
|
||||
private Double indirect1;
|
||||
|
||||
@Schema(description = "위험개선권고사항 도움 정도")
|
||||
private Double recHelp;
|
||||
@Schema(description = "간접요소 2")
|
||||
private Double indirect2;
|
||||
|
||||
@Schema(description = "점검직원 전문성")
|
||||
private Double staffProf;
|
||||
|
||||
@Schema(description = "점검직원 태도")
|
||||
private Double staffAtt;
|
||||
|
||||
public static CsiDataDto of(Integer wave, Double csi, Double safeHelp, Double recHelp, Double staffProf, Double staffAtt) {
|
||||
public static CsiDataDto of(Integer wave, Integer sampleCount, Double csi, Double direct1, Double direct2, Double indirect1, Double indirect2) {
|
||||
return CsiDataDto.builder()
|
||||
.wave(wave)
|
||||
.sampleCount(sampleCount)
|
||||
.csi(csi)
|
||||
.safeHelp(safeHelp)
|
||||
.recHelp(recHelp)
|
||||
.staffProf(staffProf)
|
||||
.staffAtt(staffAtt)
|
||||
.direct1(direct1)
|
||||
.direct2(direct2)
|
||||
.indirect1(indirect1)
|
||||
.indirect2(indirect2)
|
||||
.build();
|
||||
}
|
||||
|
||||
public static CsiDataDto from(Integer wave,CsiDataEntity entity) {
|
||||
return CsiDataDto.builder()
|
||||
.wave(wave)
|
||||
.sampleCount(entity.getSampleCount())
|
||||
.csi(entity.getCsi())
|
||||
.safeHelp(entity.getSafeHelp())
|
||||
.recHelp(entity.getRecHelp())
|
||||
.staffProf(entity.getStaffProf())
|
||||
.staffAtt(entity.getStaffAtt())
|
||||
.direct1(entity.getDirect1())
|
||||
.direct2(entity.getDirect2())
|
||||
.indirect1(entity.getIndirect1())
|
||||
.indirect2(entity.getIndirect2())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
33
src/main/java/com/kri/kfpa/dash/dto/CsiSummaryDto.java
Normal file
33
src/main/java/com/kri/kfpa/dash/dto/CsiSummaryDto.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package com.kri.kfpa.dash.dto;
|
||||
|
||||
import com.kri.kfpa.dash.entity.CsiDataEntity;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@Schema(description = "CSI Summary Dto")
|
||||
public class CsiSummaryDto {
|
||||
@Schema(description = "연도")
|
||||
private Integer wave;
|
||||
|
||||
@Schema(description = "응답 건수")
|
||||
private Integer sampleCount;
|
||||
|
||||
@Schema(description = "CSI 점수")
|
||||
private Double csi;
|
||||
|
||||
public static CsiSummaryDto from(CsiDataDto dto) {
|
||||
if (dto == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CsiSummaryDto(dto.getWave(), dto.getSampleCount(), dto.getCsi());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,13 +9,15 @@ public class CsiDataEntity {
|
||||
|
||||
private String div;
|
||||
|
||||
private Integer sampleCount;
|
||||
|
||||
private Double csi;
|
||||
|
||||
private Double safeHelp;
|
||||
private Double direct1;
|
||||
|
||||
private Double recHelp;
|
||||
private Double direct2;
|
||||
|
||||
private Double staffProf;
|
||||
private Double indirect1;
|
||||
|
||||
private Double staffAtt;
|
||||
private Double indirect2;
|
||||
}
|
||||
|
||||
@@ -12,10 +12,18 @@ import org.apache.ibatis.annotations.Param;
|
||||
@Mapper
|
||||
public interface DataMapper {
|
||||
|
||||
List<CsiDataEntity> selectDivCsiData(@Param("pkey") String pkey);
|
||||
List<CsiDataEntity> selectDivCsiData(
|
||||
@Param("pkey") String pkey,
|
||||
@Param("qids") List<Map<String, String>> qids,
|
||||
@Param("weights") Map<String, Double> weights,
|
||||
@Param("dt") String dt
|
||||
);
|
||||
|
||||
List<ObjectTypeCsiRankEntity> selectDivObjectTypeCsiRank(
|
||||
@Param("pkey") String pkey
|
||||
@Param("pkey") String pkey,
|
||||
@Param("qids") List<Map<String, String>> qids,
|
||||
@Param("weights") Map<String, Double> weights,
|
||||
@Param("dt") String dt
|
||||
);
|
||||
|
||||
DivCommentEntity selectDivComment(
|
||||
|
||||
@@ -3,16 +3,22 @@ package com.kri.kfpa.dash.service;
|
||||
import static com.kri.kfpa.dash.common.consts.KfpaDashConstant.DATA_2025;
|
||||
import static com.kri.kfpa.dash.common.consts.KfpaDashConstant.IDKEY_MAP;
|
||||
import static com.kri.kfpa.dash.common.consts.KfpaDashConstant.KFPA_COMMENT_PKEY;
|
||||
import static com.kri.kfpa.dash.common.consts.KfpaDashConstant.KFPA_DASH_PKEY;
|
||||
import static com.kri.kfpa.dash.common.consts.KfpaDashConstant.QUERY_QIDS;
|
||||
import static com.kri.kfpa.dash.common.consts.KfpaDashConstant.REAL_QIDS;
|
||||
import static com.kri.kfpa.dash.common.consts.KfpaDashConstant.WEIGHTS;
|
||||
|
||||
import com.kri.common.feature.web.BusinessException;
|
||||
import com.kri.kfpa.dash.dto.CsiDataDto;
|
||||
import com.kri.kfpa.dash.dto.CsiRankDto;
|
||||
import com.kri.kfpa.dash.dto.CsiSummaryDto;
|
||||
import com.kri.kfpa.dash.dto.DivDetailDataDto;
|
||||
import com.kri.kfpa.dash.entity.CsiDataEntity;
|
||||
import com.kri.kfpa.dash.entity.DivCommentEntity;
|
||||
import com.kri.kfpa.dash.entity.ObjectTypeCsiRankEntity;
|
||||
import com.kri.kfpa.dash.mapper.DataMapper;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.DateTimeParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
@@ -27,14 +33,38 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RequiredArgsConstructor
|
||||
@Transactional(readOnly = true)
|
||||
public class StatisticsService {
|
||||
private static final DateTimeFormatter SEARCH_DATE_TIME_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
private static final DateTimeFormatter EDT_FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
|
||||
private final DataMapper dataMapper;
|
||||
|
||||
@Value("${kri.kfpa-comment-idkey-suffix:}")
|
||||
private String kfpaCommentIdkeySuffix;
|
||||
|
||||
public Map<String, List<CsiDataDto>> getCsiData() {
|
||||
List<CsiDataEntity> csiDataList = dataMapper.selectDivCsiData(KFPA_DASH_PKEY);
|
||||
public Map<String, List<CsiSummaryDto>> getCsiSummary(String searchDateTime) {
|
||||
Map<String, List<CsiSummaryDto>> mergedCsiSummary = new LinkedHashMap<>();
|
||||
|
||||
REAL_QIDS.keySet().forEach(pkey ->
|
||||
getCsiData(pkey, searchDateTime).forEach((div, data) ->
|
||||
mergedCsiSummary.put(
|
||||
pkey + "_" + div,
|
||||
data.stream().map(CsiSummaryDto::from).toList()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return mergedCsiSummary;
|
||||
}
|
||||
|
||||
public Map<String, List<CsiDataDto>> getCsiData(String pkey, String searchDateTime) {
|
||||
List<CsiDataEntity> csiDataList = dataMapper.selectDivCsiData(
|
||||
pkey,
|
||||
getQids(pkey),
|
||||
getWeights(pkey),
|
||||
getParsedSearchDateTime(searchDateTime)
|
||||
);
|
||||
|
||||
Map<String, CsiDataDto> csiData = csiDataList.stream()
|
||||
.collect(Collectors.toMap(
|
||||
@@ -43,7 +73,11 @@ public class StatisticsService {
|
||||
));
|
||||
|
||||
Map<String, List<CsiDataDto>> mergedCsiData = new LinkedHashMap<>();
|
||||
DATA_2025.forEach((div, data) -> mergedCsiData.put(div, new ArrayList<>(List.of(data))));
|
||||
|
||||
DATA_2025.get(pkey).forEach((div, data) ->
|
||||
mergedCsiData.put(div, new ArrayList<>(List.of(data)))
|
||||
);
|
||||
|
||||
csiData.forEach((div, data) -> mergedCsiData
|
||||
.computeIfAbsent(div, key -> new ArrayList<>())
|
||||
.add(data));
|
||||
@@ -51,42 +85,92 @@ public class StatisticsService {
|
||||
return mergedCsiData;
|
||||
}
|
||||
|
||||
public Map<String, DivDetailDataDto> getDivDetailData(String div) {
|
||||
public Map<String, DivDetailDataDto> getDivDetailData(String div, String pkey, String searchDateTime) {
|
||||
String idkey = IDKEY_MAP.get(div);
|
||||
if (idkey == null) {
|
||||
throw BusinessException.badRequest(
|
||||
"INVALID_DIVISION",
|
||||
"유효하지 않은 지역 본부입니다."
|
||||
"유효하지 않은 지점본부입니다."
|
||||
).with("div", div);
|
||||
}
|
||||
|
||||
String suffixedIdkey = idkey + kfpaCommentIdkeySuffix;
|
||||
|
||||
List<ObjectTypeCsiRankEntity> objectTypeCsiRankList =
|
||||
dataMapper.selectDivObjectTypeCsiRank(KFPA_DASH_PKEY).stream()
|
||||
dataMapper.selectDivObjectTypeCsiRank(
|
||||
pkey,
|
||||
getQids(pkey),
|
||||
getWeights(pkey),
|
||||
getParsedSearchDateTime(searchDateTime)
|
||||
).stream()
|
||||
.filter(entity -> entity.getDiv().equals(div))
|
||||
.toList();
|
||||
|
||||
DivCommentEntity selectedComment = dataMapper.selectDivComment(KFPA_COMMENT_PKEY, suffixedIdkey);
|
||||
DivCommentEntity divCommentEntity =
|
||||
selectedComment == null ? DivCommentEntity.empty() : selectedComment;
|
||||
|
||||
Map<String, DivDetailDataDto> divDetailData = new LinkedHashMap<>();
|
||||
Map<String, DivCommentEntity> divCommentCache = new LinkedHashMap<>();
|
||||
DivDetailDataDto detailData =
|
||||
DivDetailDataDto.of(new LinkedHashMap<>(), divCommentEntity.getCommentValues());
|
||||
divDetailData.put(div, detailData);
|
||||
|
||||
for (ObjectTypeCsiRankEntity entity : objectTypeCsiRankList) {
|
||||
DivCommentEntity divCommentEntity = divCommentCache.computeIfAbsent(
|
||||
div,
|
||||
key -> {
|
||||
DivCommentEntity selectedComment =
|
||||
dataMapper.selectDivComment(KFPA_COMMENT_PKEY, suffixedIdkey);
|
||||
return selectedComment == null ? DivCommentEntity.empty() : selectedComment;
|
||||
}
|
||||
);
|
||||
|
||||
DivDetailDataDto detailData = divDetailData.computeIfAbsent(
|
||||
div,
|
||||
key -> DivDetailDataDto.of(new LinkedHashMap<>(), divCommentEntity.getCommentValues())
|
||||
);
|
||||
detailData.getCsiRanks().put(entity.getObjectType(), CsiRankDto.from(entity));
|
||||
}
|
||||
|
||||
return divDetailData;
|
||||
}
|
||||
|
||||
private String getParsedSearchDateTime(String searchDateTime) {
|
||||
try {
|
||||
LocalDateTime parsedSearchDateTime =
|
||||
LocalDateTime.parse(searchDateTime, SEARCH_DATE_TIME_FORMATTER);
|
||||
return parsedSearchDateTime
|
||||
.withSecond(59)
|
||||
.withNano(999_000_000)
|
||||
.format(EDT_FORMATTER);
|
||||
} catch (DateTimeParseException e) {
|
||||
throw BusinessException.badRequest(
|
||||
"INVALID_SEARCH_DATE",
|
||||
"유효하지 않은 검색일시 형식입니다."
|
||||
).with("searchDateTime", searchDateTime);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Map<String, String>> getQids(String pkey) {
|
||||
List<String> realQids = REAL_QIDS.get(pkey);
|
||||
if (realQids == null) {
|
||||
throw BusinessException.badRequest(
|
||||
"INVALID_PKEY",
|
||||
"유효하지 않은 pkey입니다."
|
||||
).with("pkey", pkey);
|
||||
}
|
||||
if (realQids.size() != QUERY_QIDS.size()) {
|
||||
throw BusinessException.badRequest(
|
||||
"INVALID_QIDS",
|
||||
"문항 ID 설정이 올바르지 않습니다."
|
||||
).with("pkey", pkey);
|
||||
}
|
||||
|
||||
List<Map<String, String>> qids = new ArrayList<>();
|
||||
for (int i = 0; i < realQids.size(); i++) {
|
||||
qids.add(Map.of(
|
||||
"realQid", realQids.get(i),
|
||||
"queryQid", QUERY_QIDS.get(i)
|
||||
));
|
||||
}
|
||||
return qids;
|
||||
}
|
||||
|
||||
private Map<String, Double> getWeights(String pkey) {
|
||||
Map<String, Double> weights = WEIGHTS.get(pkey);
|
||||
if (weights == null) {
|
||||
throw BusinessException.badRequest(
|
||||
"INVALID_PKEY",
|
||||
"유효하지 않은 pkey입니다."
|
||||
).with("pkey", pkey);
|
||||
}
|
||||
return weights;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,12 @@
|
||||
<mapper namespace="com.kri.kfpa.dash.mapper.DataMapper">
|
||||
<resultMap id="DivCsiDataResultMap" type="com.kri.kfpa.dash.entity.CsiDataEntity">
|
||||
<result property="div" column="div"/>
|
||||
<result property="sampleCount" column="sample_count"/>
|
||||
<result property="csi" column="csi"/>
|
||||
<result property="safeHelp" column="safe_help"/>
|
||||
<result property="recHelp" column="rec_help"/>
|
||||
<result property="staffProf" column="staff_prof"/>
|
||||
<result property="staffAtt" column="staff_att"/>
|
||||
<result property="direct1" column="direct1"/>
|
||||
<result property="direct2" column="direct2"/>
|
||||
<result property="indirect1" column="indirect1"/>
|
||||
<result property="indirect2" column="indirect2"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="DivObjectTypeCsiRankResultMap" type="com.kri.kfpa.dash.entity.ObjectTypeCsiRankEntity">
|
||||
@@ -30,23 +31,46 @@
|
||||
<result property="performance26Capability" column="performance26_capability"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="CsiScoreExpression">
|
||||
q1 * #{weights.q1} + q2 * #{weights.q2} + q4 * #{weights.q4} + q5 * #{weights.q5}
|
||||
</sql>
|
||||
|
||||
<sql id="BaseDataSelect">
|
||||
SELECT
|
||||
IDKEY
|
||||
, TRY_CAST(JSON_VALUE(DATJSON, '$.Q1.Q1') AS DECIMAL(18, 4)) AS q1
|
||||
, TRY_CAST(JSON_VALUE(DATJSON, '$.Q2.Q2') AS DECIMAL(18, 4)) AS q2
|
||||
, TRY_CAST(JSON_VALUE(DATJSON, '$.Q7.Q7') AS DECIMAL(18, 4)) AS q4
|
||||
, TRY_CAST(JSON_VALUE(DATJSON, '$.Q10.Q10') AS DECIMAL(18, 4)) AS q5
|
||||
, CASE
|
||||
WHEN JSON_VALUE(DATJSON, '$.Q16.Q14') IS NOT NULL
|
||||
THEN JSON_VALUE(DATJSON, '$.Q16.Q14')
|
||||
ELSE JSON_VALUE(DATJSON, '$.Q14.Q14')
|
||||
END AS object_type_raw
|
||||
, JSON_VALUE(DATJSON, '$.Q16.Q16') AS div
|
||||
FROM Kon.dbo.DATA
|
||||
DA.IDKEY
|
||||
<foreach collection="qids" item="qid">
|
||||
, TRY_CAST(MAX(CASE WHEN DV.[KEY] = #{qid.realQid} THEN DV.[VALUE] END) AS DECIMAL(18, 4)) AS ${qid.queryQid}
|
||||
</foreach>
|
||||
<choose>
|
||||
<when test="pkey == '2601009_A'">
|
||||
, MAX(CASE WHEN DV.[KEY] = 'Q14' THEN DV.[VALUE] END) AS object_type_raw
|
||||
, MAX(CASE WHEN DV.[KEY] = 'Q16' THEN DV.[VALUE] END) AS div
|
||||
</when>
|
||||
<otherwise>
|
||||
, '0' AS object_type_raw
|
||||
, '0' AS div
|
||||
</otherwise>
|
||||
</choose>
|
||||
FROM Kon.dbo.DATA DA
|
||||
CROSS APPLY OPENJSON(DA.DATJSON) DJ
|
||||
CROSS APPLY OPENJSON(DJ.VALUE) DV
|
||||
WHERE SURVEY_TYPE != 'TEST'
|
||||
AND Status = 10
|
||||
AND PKEY = #{pkey} AND JSON_VALUE(DATJSON, '$.Q16.Q16') != '99'
|
||||
AND PKEY = #{pkey}
|
||||
AND dbo.FN_LAST_TIME(survey_date) <= #{dt}
|
||||
AND (
|
||||
DV.[KEY] IN
|
||||
<foreach collection="qids" item="qid" open="(" separator="," close=")">
|
||||
#{qid.realQid}
|
||||
</foreach>
|
||||
<if test="pkey == '2601009_A'">
|
||||
OR DV.[KEY] IN ('Q14', 'Q16')
|
||||
</if>
|
||||
)
|
||||
<if test="pkey == '2601009_A'">
|
||||
AND JSON_VALUE(DATJSON, '$.Q16.Q16') != '99'
|
||||
</if>
|
||||
GROUP BY DA.IDKEY
|
||||
</sql>
|
||||
|
||||
<select id="selectDivCsiData" resultMap="DivCsiDataResultMap">
|
||||
@@ -68,22 +92,24 @@
|
||||
)
|
||||
SELECT
|
||||
div
|
||||
, AVG(q1 * 0.4 + q2 * 0.4 + q4 * 0.1 + q5 * 0.1) AS csi
|
||||
, AVG(q1) AS safe_help
|
||||
, AVG(q2) AS rec_help
|
||||
, AVG(q4) AS staff_prof
|
||||
, AVG(q5) AS staff_att
|
||||
, AVG(<include refid="CsiScoreExpression"/>) AS csi
|
||||
, COUNT(1) AS sample_count
|
||||
, AVG(q1) AS direct1
|
||||
, AVG(q2) AS direct2
|
||||
, AVG(q4) AS indirect1
|
||||
, AVG(q5) AS indirect2
|
||||
, 1 AS sort_order
|
||||
FROM Filtered
|
||||
GROUP BY div
|
||||
UNION ALL
|
||||
SELECT
|
||||
'-1' AS div
|
||||
, AVG(q1 * 0.4 + q2 * 0.4 + q4 * 0.1 + q5 * 0.1) AS csi
|
||||
, AVG(q1) AS safe_help
|
||||
, AVG(q2) AS rec_help
|
||||
, AVG(q4) AS staff_prof
|
||||
, AVG(q5) AS staff_att
|
||||
, AVG(<include refid="CsiScoreExpression"/>) AS csi
|
||||
, COUNT(1) AS sample_count
|
||||
, AVG(q1) AS direct1
|
||||
, AVG(q2) AS direct2
|
||||
, AVG(q4) AS indirect1
|
||||
, AVG(q5) AS indirect2
|
||||
, 0 AS sort_order
|
||||
FROM Filtered
|
||||
ORDER BY sort_order, div
|
||||
@@ -101,6 +127,7 @@
|
||||
, q4
|
||||
, q5
|
||||
, div
|
||||
, object_type_raw
|
||||
, CASE
|
||||
WHEN object_type_raw IN ('4', '12') THEN object_type_raw
|
||||
ELSE '90'
|
||||
@@ -111,20 +138,51 @@
|
||||
SELECT
|
||||
div
|
||||
, object_type
|
||||
, AVG(q1 * 0.4 + q2 * 0.4 + q4 * 0.1 + q5 * 0.1) AS csi
|
||||
, AVG(<include refid="CsiScoreExpression"/>) AS csi
|
||||
FROM Recode
|
||||
WHERE div IS NOT NULL
|
||||
AND div != '99'
|
||||
AND object_type_raw IS NOT NULL
|
||||
AND object_type_raw != '99'
|
||||
GROUP BY div, object_type
|
||||
),
|
||||
TotalCsiAgg AS (
|
||||
SELECT
|
||||
div
|
||||
, AVG(<include refid="CsiScoreExpression"/>) AS csi
|
||||
FROM Recode
|
||||
WHERE div IS NOT NULL
|
||||
AND div != '99'
|
||||
AND object_type_raw IS NOT NULL
|
||||
AND object_type_raw != '99'
|
||||
GROUP BY div
|
||||
),
|
||||
Ranked AS (
|
||||
SELECT
|
||||
div
|
||||
, object_type
|
||||
, csi
|
||||
, DENSE_RANK() OVER (
|
||||
PARTITION BY object_type
|
||||
ORDER BY csi DESC
|
||||
) AS div_rank
|
||||
FROM CsiAgg
|
||||
UNION ALL
|
||||
SELECT
|
||||
div
|
||||
, '-1' AS object_type
|
||||
, csi
|
||||
, DENSE_RANK() OVER (
|
||||
ORDER BY csi DESC
|
||||
) AS div_rank
|
||||
FROM TotalCsiAgg
|
||||
)
|
||||
SELECT
|
||||
div
|
||||
, object_type
|
||||
, CSI
|
||||
, DENSE_RANK() OVER (
|
||||
PARTITION BY object_type
|
||||
ORDER BY CSI DESC
|
||||
) AS div_rank
|
||||
FROM CsiAgg
|
||||
, csi
|
||||
, div_rank
|
||||
FROM Ranked
|
||||
ORDER BY div, object_type, div_rank
|
||||
</select>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user