|
|
|
@ -7,11 +7,16 @@ import com.palnet.biz.jpa.repository.ctr.CtrCntrlBasRepository;
|
|
|
|
|
import com.palnet.biz.jpa.repository.ctr.CtrCntrlHstryAreaRepository; |
|
|
|
|
import com.palnet.biz.jpa.repository.ctr.CtrCntrlHstryRepository; |
|
|
|
|
import com.palnet.biz.api.comn.model.ControlGpsDataContext; |
|
|
|
|
import com.palnet.biz.api.ctr.cntrl.service.CtrCntrlService; |
|
|
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
|
|
import org.locationtech.jts.geom.Coordinate; |
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import com.palnet.biz.jpa.entity.CtrCntrlBas; |
|
|
|
|
import com.palnet.biz.jpa.entity.CtrCntrlHstry; |
|
|
|
|
import com.palnet.biz.jpa.entity.CtrCntrlHstryArea; |
|
|
|
|
import com.palnet.biz.jpa.repository.ctr.CtrCntrlQueryRepository; |
|
|
|
@ -21,6 +26,7 @@ import com.palnet.comn.utils.DateUtils;
|
|
|
|
|
|
|
|
|
|
@Service |
|
|
|
|
@RequiredArgsConstructor |
|
|
|
|
@Slf4j |
|
|
|
|
public class CtrSchedulerService { |
|
|
|
|
|
|
|
|
|
private final CtrCntrlJpaService service; |
|
|
|
@ -65,6 +71,18 @@ public class CtrSchedulerService {
|
|
|
|
|
|
|
|
|
|
ctrCntrlHstryAreaRepository.save(area); |
|
|
|
|
|
|
|
|
|
Double distance = getDistancSum(history.getCntrlId()); |
|
|
|
|
if(distance == null) log.error("No Search - CntrlId => {}", history.getCntrlId()); |
|
|
|
|
|
|
|
|
|
CtrCntrlBas ctrCntrlBas = ctrCntrlBasRepository.findById(history.getCntrlId()).orElse(null); |
|
|
|
|
|
|
|
|
|
if(ctrCntrlBas != null){ |
|
|
|
|
ctrCntrlBas.setTtlDstnc(distance); |
|
|
|
|
ctrCntrlBas.setTtlDstncType("M"); |
|
|
|
|
|
|
|
|
|
ctrCntrlBasRepository.save(ctrCntrlBas); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
gpsDataContext.removeIdntfKey(key); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -87,4 +105,32 @@ public class CtrSchedulerService {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* cntrlId의 총 비행거리 |
|
|
|
|
* @param cntrlId |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
private Double getDistancSum(String cntrlId){ |
|
|
|
|
List<CtrCntrlHstry> result = ctrCntrlHstryRepository.findAllByCntrlIdOrderBySrvrRcvDt(cntrlId); |
|
|
|
|
if(result.size() == 0) return null; |
|
|
|
|
|
|
|
|
|
List<Double> distanceList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
for(int i = 0; i < result.size(); i++){ |
|
|
|
|
if(i == 0) continue; |
|
|
|
|
|
|
|
|
|
CtrCntrlHstry prevNode = result.get(i-1); |
|
|
|
|
CtrCntrlHstry node = result.get(i); |
|
|
|
|
|
|
|
|
|
Coordinate prevCoord = new Coordinate(prevNode.getLat(), prevNode.getLon()); |
|
|
|
|
Coordinate coord = new Coordinate(node.getLat(), node.getLon()); |
|
|
|
|
|
|
|
|
|
Double distance = CtrCntrlService.calculateDistance(prevCoord, coord); |
|
|
|
|
|
|
|
|
|
distanceList.add(distance); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return distanceList.stream().mapToDouble(Double::doubleValue).sum(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|