pnu cnt update 수동호출 추가

This commit is contained in:
2026-03-04 23:00:46 +09:00
parent 66b78022a9
commit f99144eccc
6 changed files with 132 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
package com.kamco.cd.kamcoback.postgres.core;
import com.kamco.cd.kamcoback.postgres.repository.gukyuin.GukYuinPnuCntUpdateJobRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class GukYuinPnuCntUpdateJobCoreService {
private final GukYuinPnuCntUpdateJobRepository gukYuinPnuCntUpdateRepository;
public GukYuinPnuCntUpdateJobCoreService(
GukYuinPnuCntUpdateJobRepository gukYuinPnuCntUpdateRepository) {
this.gukYuinPnuCntUpdateRepository = gukYuinPnuCntUpdateRepository;
}
@Transactional
public int updateGukYuinContListPnuUpdateCnt(String uid) {
return gukYuinPnuCntUpdateRepository.updateGukYuinContListPnuUpdateCnt(uid);
}
@Transactional
public void updateGukYuinApplyStatus(String uid, String status) {
gukYuinPnuCntUpdateRepository.updateGukYuinApplyStatus(uid, status);
}
}

View File

@@ -0,0 +1,7 @@
package com.kamco.cd.kamcoback.postgres.repository.gukyuin;
import com.kamco.cd.kamcoback.postgres.entity.MapSheetLearnEntity;
import org.springframework.data.jpa.repository.JpaRepository;
public interface GukYuinPnuCntUpdateJobRepository
extends JpaRepository<MapSheetLearnEntity, Long>, GukYuinPnuCntUpdateJobRepositoryCustom {}

View File

@@ -0,0 +1,8 @@
package com.kamco.cd.kamcoback.postgres.repository.gukyuin;
public interface GukYuinPnuCntUpdateJobRepositoryCustom {
int updateGukYuinContListPnuUpdateCnt(String uid);
void updateGukYuinApplyStatus(String uid, String status);
}

View File

@@ -0,0 +1,58 @@
package com.kamco.cd.kamcoback.postgres.repository.gukyuin;
import static com.kamco.cd.kamcoback.postgres.entity.QMapSheetLearnEntity.mapSheetLearnEntity;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import jakarta.persistence.PersistenceContext;
import java.time.ZonedDateTime;
import lombok.RequiredArgsConstructor;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
@Repository
@RequiredArgsConstructor
public class GukYuinPnuCntUpdateJobRepositoryImpl
implements GukYuinPnuCntUpdateJobRepositoryCustom {
private final JPAQueryFactory queryFactory;
private final JdbcTemplate jdbcTemplate;
@PersistenceContext private EntityManager em;
@Override
public int updateGukYuinContListPnuUpdateCnt(String uid) {
String sql =
"""
WITH target_geo AS (
SELECT DISTINCT g.geo_uid
FROM tb_map_sheet_anal_data_inference_geom g
JOIN tb_map_sheet_anal_data_inference d ON d.data_uid = g.data_uid
JOIN tb_map_sheet_anal_inference i ON i.anal_uid = d.anal_uid
JOIN tb_map_sheet_learn l ON l.id = i.learn_id
WHERE l.uid = ?
),
pnu_cnt AS (
SELECT p.geo_uid, COUNT(*)::int AS cnt
FROM tb_pnu p
JOIN target_geo t ON t.geo_uid = p.geo_uid
GROUP BY p.geo_uid
)
UPDATE tb_map_sheet_anal_data_inference_geom geo
SET pnu = pnu_cnt.cnt
FROM pnu_cnt
WHERE geo.geo_uid = pnu_cnt.geo_uid
""";
return jdbcTemplate.update(sql, uid);
}
@Override
public void updateGukYuinApplyStatus(String uid, String status) {
queryFactory
.update(mapSheetLearnEntity)
.set(mapSheetLearnEntity.applyStatus, status)
.set(mapSheetLearnEntity.applyStatusDttm, ZonedDateTime.now())
.where(mapSheetLearnEntity.uid.eq(uid))
.execute();
}
}

View File

@@ -6,6 +6,7 @@ import com.kamco.cd.kamcoback.gukyuin.service.GukYuinApiService;
import com.kamco.cd.kamcoback.inference.dto.InferenceResultShpDto;
import com.kamco.cd.kamcoback.inference.service.InferenceResultShpService;
import com.kamco.cd.kamcoback.scheduler.service.GukYuinApiLabelJobService;
import com.kamco.cd.kamcoback.scheduler.service.GukYuinApiPnuCntUpdateJobService;
import com.kamco.cd.kamcoback.scheduler.service.GukYuinApiPnuJobService;
import com.kamco.cd.kamcoback.scheduler.service.GukYuinApiStatusJobService;
import com.kamco.cd.kamcoback.scheduler.service.GukYuinApiStbltJobService;
@@ -49,6 +50,7 @@ public class SchedulerApiController {
private final MapSheetMngFileJobController mapSheetMngFileJobController;
private final InferenceResultShpService inferenceResultShpService;
private final GukYuinApiService gukYuinApiService;
private final GukYuinApiPnuCntUpdateJobService gukYuinApiPnuCntUpdateJobService;
@Operation(summary = "국유인 탐지객체 조회 PNU 업데이트 스케줄링", description = "국유인 탐지객체 조회 PNU 업데이트 스케줄링")
@GetMapping("/gukyuin/pnu")
@@ -184,4 +186,11 @@ public class SchedulerApiController {
@PathVariable String uid, @PathVariable int updateCnt) {
return ApiResponseDto.ok(gukYuinApiService.updateStbltRandomData(uid, updateCnt));
}
@Operation(summary = "pnu 연동 이후 pnu cnt, 상태 업데이트", description = "pnu 연동 이후 pnu cnt, 상태 업데이트")
@GetMapping("/gukyuin/pnu-cnt/{uid}")
public ApiResponseDto<Void> updateGukYuinContListPnuUpdateCnt(@PathVariable String uid) {
gukYuinApiPnuCntUpdateJobService.updateGukYuinContListPnuUpdateCnt(uid);
return ApiResponseDto.ok(null);
}
}

View File

@@ -0,0 +1,24 @@
package com.kamco.cd.kamcoback.scheduler.service;
import com.kamco.cd.kamcoback.gukyuin.dto.GukYuinStatus;
import com.kamco.cd.kamcoback.postgres.core.GukYuinPnuCntUpdateJobCoreService;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
@Log4j2
@Service
@RequiredArgsConstructor
public class GukYuinApiPnuCntUpdateJobService {
private final GukYuinPnuCntUpdateJobCoreService gukYuinPnuCntUpdateJobCoreService;
public void updateGukYuinContListPnuUpdateCnt(String uid) {
int execCnt = gukYuinPnuCntUpdateJobCoreService.updateGukYuinContListPnuUpdateCnt(uid);
if (execCnt > 0) {
gukYuinPnuCntUpdateJobCoreService.updateGukYuinApplyStatus(
uid, GukYuinStatus.PNU_COMPLETED.getId());
}
}
}