Browse Source

refactor: RS 모델 작업

develop
lkd9125(이경도) 4 hours ago
parent
commit
98eb3d5f70
  1. 33
      pav-server/src/main/java/com/palnet/biz/api/bas/dos/model/AllStatDataRS.java
  2. 9
      pav-server/src/main/java/com/palnet/biz/api/bas/dos/service/StatisticsDosService.java
  3. 53
      pav-server/src/main/java/com/palnet/biz/jpa/repository/dos/DosFltPlanAreaQueryRepository.java

33
pav-server/src/main/java/com/palnet/biz/api/bas/dos/model/AllStatDataRS.java

@ -8,14 +8,15 @@ import java.util.List;
@Data
public class AllStatDataRS {
private List<GroupModel> fullApproval;
private List<GroupRSModel> fullApproval;
private List<GroupModel> controlApproval;
private List<GroupRSModel> controlApproval;
private List<GroupRSModel> nonControlApproval;
private List<GroupModel> nonControlApproval;
@Data
public static class GroupModel{
public static class GroupProccessModel{
private List<String> groupName;
@ -27,11 +28,33 @@ public class AllStatDataRS {
private Long day;
public GroupModel(){
public GroupProccessModel(){
this.groupName = new ArrayList<>();
}
public GroupRSModel convertRsModel(){
GroupRSModel model = new GroupRSModel();
model.setAll(this.all);
model.setYear(this.year);
model.setMonth(this.month);
model.setDay(this.day);
model.setGroupName(this.groupName != null ? this.groupName.get(0) : "");
return model;
}
}
@Data
public static class GroupRSModel{
private String groupName;
private Long all;
private Long year;
private Long month;
private Long day;
}
}

9
pav-server/src/main/java/com/palnet/biz/api/bas/dos/service/StatisticsDosService.java

@ -11,7 +11,9 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@Service
@Slf4j
@ -22,9 +24,9 @@ public class StatisticsDosService {
public AllStatDataRS allData() {
List<AllStatDataRS.GroupModel> fullApproval = dosFltPlanAreaQueryRepository.allApplyTopData();
List<AllStatDataRS.GroupModel> controlApproval = dosFltPlanAreaQueryRepository.controlApplyTopData(true);
List<AllStatDataRS.GroupModel> nonControlApproval = dosFltPlanAreaQueryRepository.controlApplyTopData(false);
List<AllStatDataRS.GroupRSModel> fullApproval = dosFltPlanAreaQueryRepository.allApplyTopData().stream().map(AllStatDataRS.GroupProccessModel::convertRsModel).collect(Collectors.toList());
List<AllStatDataRS.GroupRSModel> controlApproval = dosFltPlanAreaQueryRepository.controlApplyTopData(true).stream().map(AllStatDataRS.GroupProccessModel::convertRsModel).collect(Collectors.toList());
List<AllStatDataRS.GroupRSModel> nonControlApproval = dosFltPlanAreaQueryRepository.controlApplyTopData(false).stream().map(AllStatDataRS.GroupProccessModel::convertRsModel).collect(Collectors.toList());
AllStatDataRS result = new AllStatDataRS();
result.setFullApproval(fullApproval);
@ -37,7 +39,6 @@ public class StatisticsDosService {
public CptStatRS cptStatData(CptStatRQ rq) {
List<CptStatRS.CptStat> cptList = dosFltPlanAreaQueryRepository.cptStatData(rq);
CptStatRS result = new CptStatRS();

53
pav-server/src/main/java/com/palnet/biz/jpa/repository/dos/DosFltPlanAreaQueryRepository.java

@ -6,6 +6,7 @@ import com.palnet.biz.api.bas.dos.model.CptStatRS;
import com.palnet.biz.api.bas.dos.service.StatisticsDosService;
import com.palnet.biz.jpa.entity.QDosFltPlanArea;
import com.palnet.biz.jpa.entity.QDosFltPlanBas;
import com.palnet.biz.jpa.entity.QFltCptAuthBas;
import com.palnet.comn.code.ErrorCode;
import com.palnet.comn.exception.CustomException;
import com.querydsl.core.BooleanBuilder;
@ -33,7 +34,7 @@ public class DosFltPlanAreaQueryRepository {
* 데이터 조회
* @return
*/
public List<AllStatDataRS.GroupModel> allApplyTopData() {
public List<AllStatDataRS.GroupProccessModel> allApplyTopData() {
QDosFltPlanArea qDosFltPlanArea = QDosFltPlanArea.dosFltPlanArea;
QDosFltPlanBas qDosFltPlanBas = QDosFltPlanBas.dosFltPlanBas;
@ -48,10 +49,10 @@ public class DosFltPlanAreaQueryRepository {
BooleanBuilder builder = new BooleanBuilder();
builder.and(Expressions.booleanTemplate("{0} IS NOT NULL", qDosFltPlanArea.cptCd));
Map<String, AllStatDataRS.GroupModel> groupModel = query
Map<String, AllStatDataRS.GroupProccessModel> groupModel = query
.select(
Projections.bean(
AllStatDataRS.GroupModel.class,
AllStatDataRS.GroupProccessModel.class,
qDosFltPlanArea.cptCd.as("groupName"),
qDosFltPlanArea.count().as("all"),
yearTemplate.as("year"),
@ -93,7 +94,7 @@ public class DosFltPlanAreaQueryRepository {
* @param controlFlag TRUE : 관제권 조회, FALSE : 관제권 조회
* @return
*/
public List<AllStatDataRS.GroupModel> controlApplyTopData(Boolean controlFlag) {
public List<AllStatDataRS.GroupProccessModel> controlApplyTopData(Boolean controlFlag) {
QDosFltPlanArea qDosFltPlanArea = QDosFltPlanArea.dosFltPlanArea;
QDosFltPlanBas qDosFltPlanBas = QDosFltPlanBas.dosFltPlanBas;
@ -116,10 +117,10 @@ public class DosFltPlanAreaQueryRepository {
groupingColumn = qDosFltPlanArea.cptCd;
}
Map<String, AllStatDataRS.GroupModel> groupModel = query
Map<String, AllStatDataRS.GroupProccessModel> groupModel = query
.select(
Projections.bean(
AllStatDataRS.GroupModel.class,
AllStatDataRS.GroupProccessModel.class,
groupingColumn.as("groupName"),
qDosFltPlanArea.count().as("all"),
yearTemplate.as("year"),
@ -227,12 +228,23 @@ public class DosFltPlanAreaQueryRepository {
return cptStatList;
}
private String cptAuthNmByCptCd(String cptCd){
QFltCptAuthBas qFltCptAuthBas = QFltCptAuthBas.fltCptAuthBas;
private List<AllStatDataRS.GroupModel> topDataParsing(Map<String, AllStatDataRS.GroupModel> groupModel){
Map<String, AllStatDataRS.GroupModel> currentMap = new ConcurrentHashMap<>(groupModel);
return query
.select(
qFltCptAuthBas.cptAuthNm
)
.from(qFltCptAuthBas)
.where(qFltCptAuthBas.cptAuthCode.eq(cptCd))
.fetchOne();
}
private List<AllStatDataRS.GroupProccessModel> topDataParsing(Map<String, AllStatDataRS.GroupProccessModel> groupModel){
Map<String, AllStatDataRS.GroupProccessModel> currentMap = new ConcurrentHashMap<>(groupModel);
// CptCd가 한 개가 아닌 값들에 대한 로직
for(Map.Entry<String, AllStatDataRS.GroupModel> entry : currentMap.entrySet()){
for(Map.Entry<String, AllStatDataRS.GroupProccessModel> entry : currentMap.entrySet()){
String[] cptCdArray = entry.getKey().split(",");
@ -243,7 +255,7 @@ public class DosFltPlanAreaQueryRepository {
// 기존 Map에 없는 값일 경우 CptCd를 Key로 새로 만들어 put
if(currentMap.get(cptCd) == null){
AllStatDataRS.GroupModel node = new AllStatDataRS.GroupModel();
AllStatDataRS.GroupProccessModel node = new AllStatDataRS.GroupProccessModel();
node.setGroupName(Collections.singletonList(cptCd));
node.setAll(entry.getValue().getAll());
node.setYear(entry.getValue().getYear());
@ -255,7 +267,7 @@ public class DosFltPlanAreaQueryRepository {
}
// 기존 값이 있을 경우 객체를 새로운 메모리에 할당하여 put
AllStatDataRS.GroupModel node = new AllStatDataRS.GroupModel();
AllStatDataRS.GroupProccessModel node = new AllStatDataRS.GroupProccessModel();
node.setGroupName(Collections.singletonList(cptCd));
node.setAll(currentMap.get(cptCd).getAll() + entry.getValue().getAll());
node.setYear(currentMap.get(cptCd).getYear() + entry.getValue().getYear());
@ -275,20 +287,31 @@ public class DosFltPlanAreaQueryRepository {
// 총 카운트가 가장많은 값 추출
Long max = currentMap.values().stream()
.mapToLong(AllStatDataRS.GroupModel::getAll)
.mapToLong(AllStatDataRS.GroupProccessModel::getAll)
.max()
.orElse(0);
List<AllStatDataRS.GroupModel> result = new ArrayList<>();
List<AllStatDataRS.GroupProccessModel> result = new ArrayList<>();
// 가장 많은 값만 반환 리스트에 ADD
for(Map.Entry<String, AllStatDataRS.GroupModel> entry : currentMap.entrySet()){
for(Map.Entry<String, AllStatDataRS.GroupProccessModel> entry : currentMap.entrySet()){
if(entry.getValue().getAll().equals(max)){
result.add(entry.getValue());
}
}
if(result.isEmpty()) result.add(new AllStatDataRS.GroupModel());
result.forEach(node -> {
List<String> groupDesc = new ArrayList<>();
for(String groupName : node.getGroupName()){
groupDesc.add(this.cptAuthNmByCptCd(groupName));
}
node.setGroupName(groupDesc);
});
if(result.isEmpty()) result.add(new AllStatDataRS.GroupProccessModel());
return result;
}

Loading…
Cancel
Save