diff --git a/src/main/java/com/palnet/biz/api/anls/hstry/service/AnlsHstryService.java b/src/main/java/com/palnet/biz/api/anls/hstry/service/AnlsHstryService.java index 0742a67..bbd7572 100644 --- a/src/main/java/com/palnet/biz/api/anls/hstry/service/AnlsHstryService.java +++ b/src/main/java/com/palnet/biz/api/anls/hstry/service/AnlsHstryService.java @@ -2,6 +2,8 @@ package com.palnet.biz.api.anls.hstry.service; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.List; import java.util.Optional; @@ -28,12 +30,16 @@ import com.palnet.biz.jpa.entity.ComArcrftBas; import com.palnet.biz.jpa.entity.ComIdntfBas; import com.palnet.biz.jpa.entity.CtrCntrlBas; import com.palnet.biz.jpa.entity.CtrCntrlHstryArea; +import com.palnet.biz.jpa.entity.FltPlanBas; +import com.palnet.biz.jpa.entity.FltPlanPilot; import com.palnet.biz.jpa.entity.PtyCstmrGroup; import com.palnet.biz.jpa.repository.com.ComArcrftBasRepository; import com.palnet.biz.jpa.repository.com.ComIdntBasRepository; import com.palnet.biz.jpa.repository.ctr.CtrCntrlBasRepository; import com.palnet.biz.jpa.repository.ctr.CtrCntrlHstryAreaRepository; import com.palnet.biz.jpa.repository.ctr.CtrCntrlQueryRepository; +import com.palnet.biz.jpa.repository.flt.FltPlanBasRepository; +import com.palnet.biz.jpa.repository.flt.FltPlanPilotRepository; import com.palnet.biz.jpa.repository.pty.PtyCstmrGroupRepository; import com.palnet.comn.code.ErrorCode; import com.palnet.comn.exception.CustomException; @@ -59,6 +65,12 @@ public class AnlsHstryService { @Autowired private CtrCntrlHstryAreaRepository ctrCntrlHstryAreaRepository; + @Autowired + private FltPlanBasRepository fltPlanBasRepository; + + @Autowired + private FltPlanPilotRepository fltPlanPilotRepository; + @Autowired private CtrCntrlQueryRepository query; @@ -66,30 +78,58 @@ public class AnlsHstryService { private JwtTokenUtil jwtTokenUtil; //비행이력현황 list - public ComnPagingRs list(AnlsHstryGroupModel rq){ + public ComnPagingRs list(AnlsHstryGroupModel rq){ Integer cstmrSno = jwtTokenUtil.getCstmrSnoByToken(); - List groupAuth = jwtTokenUtil.getGroupAuthByToken(); String appAuth = jwtTokenUtil.getUserAuthByToken(); - ComnPagingRs response = new ComnPagingRs<>(); + ListresultList = new ArrayList<>(); + + ComnPagingRs response = new ComnPagingRs<>(); Pageable pageable = PageRequest.of(rq.getPage()-1, rq.getRecord()); if("USER".equals(appAuth) || "ROLE_USER".equals(appAuth)) { - - } - PageImpl result = query.listCntrlBasRs(rq, pageable); + if("NORMAL".equals(rq.getGroupId())) { + List idntfList = comIdntBasRepository.findIdntfNumber(cstmrSno); /* App 권한이 유저이면서 group 권한도 모두 NORMAL인 ID인 경우 본인이 생성한 기체만 조회 */ + if (idntfList.size() > 0) { + for (ComIdntfBas list : idntfList) { + List results = query.cntrlBasNormalHstryList(rq, list.getIdntfNum()); + if (results.size() > 0) { + resultList.addAll(results); + } + } + } + List basResult = fltPlanBasRepository.findByPlanSno(cstmrSno); /* App 권한이 유저이면서 group 권한도 모두 + NORMAL인 ID인 경우 cstmrSno로 비행계획서 조회 */ + for (FltPlanBas list : basResult) { + resultList.addAll(query.cntrlBasNormalPlanHstryList(rq, list.getPlanSno())); + } + List pilotResult = fltPlanPilotRepository.findByPlanSno(cstmrSno); /* App 권한이 유저이면서 group 권한도 + 모두 NORMAL인 ID인 경우 cstmrSno로 조종사 조회 */ + + for (FltPlanPilot list : pilotResult) { + resultList.addAll(query.cntrlBasNormalPlanHstryList(rq, list.getPlanSno())); + } + + Comparator comparator = (o1, o2) -> { + if (DateUtils.diffSecond(o1.getCntrlStDt(), o2.getCntrlStDt()) < 0) { + return 1; + } else if(DateUtils.diffSecond(o1.getCntrlStDt(), o2.getCntrlStDt()) > 0) { + return -1; + } + return 0; + }; + Collections.sort(resultList, comparator); + + } + }else { + PageImpl result = query.listCntrlBasRs(rq, pageable); long total = query.countCntrlBasRs(rq, cstmrSno); long totalPage = total % rq.getRecord() > 0 ? (total/rq.getRecord()) + 1 : total/rq.getRecord(); response.setItems(result.getContent()); response.setTotal(total); - response.setTotalPage(totalPage); - - - - - + response.setTotalPage(totalPage); response.setPage(rq.getPage()); - + } return response; } diff --git a/src/main/java/com/palnet/biz/api/bas/group/service/BasGroupAprvService.java b/src/main/java/com/palnet/biz/api/bas/group/service/BasGroupAprvService.java index 1a0d725..ad38caa 100644 --- a/src/main/java/com/palnet/biz/api/bas/group/service/BasGroupAprvService.java +++ b/src/main/java/com/palnet/biz/api/bas/group/service/BasGroupAprvService.java @@ -45,16 +45,16 @@ public class BasGroupAprvService { Pageable pageable = PageRequest.of(rq.getPage()-1, rq.getRecord()); - List result = query.aprvList(rq); + PageImpl result = query.aprvList(rq, pageable); long total = query.aprvCount(rq); long totalPage = total % rq.getRecord() > 0 ? (total/rq.getRecord()) + 1 : total/rq.getRecord(); -// response.setItems(result.getContent()); -// response.setTotal(total); -// response.setPage(rq.getPage()); -// response.setTotalPage(totalPage); + response.setItems(result.getContent()); + response.setTotal(total); + response.setPage(rq.getPage()); + response.setTotalPage(totalPage); return response;