From bcfdfe52a9e876f199de2d555491705d84226179 Mon Sep 17 00:00:00 2001 From: sxxxxxb Date: Wed, 29 Jul 2026 17:19:42 +0900 Subject: [PATCH] =?UTF-8?q?chgrCurrState=20=EC=86=8C=EC=8A=A4=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/net/jwsi/jcms/vpp/api/ApiClient.java | 10 + .../jwsi/jcms/vpp/api/ExternalApiService.java | 3 +- .../jcms/vpp/chgrCurrState/ChgrCurrState.java | 74 +++++ .../ChgrCurrStateController.java | 63 ++++ .../vpp/chgrCurrState/ChgrCurrStateId.java | 19 ++ .../ChgrCurrStateRepository.java | 8 + .../chgrCurrState/ChgrCurrStateService.java | 87 +++++ .../jcms/vpp/chgrHist/ChgrHistService.java | 27 +- .../templates/system/chgrCurrState/list.html | 307 ++++++++++++++++++ 9 files changed, 588 insertions(+), 10 deletions(-) create mode 100644 src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrState.java create mode 100644 src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateController.java create mode 100644 src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateId.java create mode 100644 src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateRepository.java create mode 100644 src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateService.java create mode 100644 src/main/resources/templates/system/chgrCurrState/list.html diff --git a/src/main/java/net/jwsi/jcms/vpp/api/ApiClient.java b/src/main/java/net/jwsi/jcms/vpp/api/ApiClient.java index 8451d0d..5de7147 100644 --- a/src/main/java/net/jwsi/jcms/vpp/api/ApiClient.java +++ b/src/main/java/net/jwsi/jcms/vpp/api/ApiClient.java @@ -2,6 +2,7 @@ package net.jwsi.jcms.vpp.api; import lombok.RequiredArgsConstructor; import net.jwsi.jcms.vpp.chgr.ChgrResponseDto; +import net.jwsi.jcms.vpp.chgrCurrState.ChgrCurrState; import net.jwsi.jcms.vpp.chgrHist.ChgrHistResponseDto; import net.jwsi.jcms.vpp.provider.ProviderDto; import net.jwsi.jcms.vpp.station.StationDto; @@ -54,4 +55,13 @@ public class ApiClient { .retrieve() .body(new ParameterizedTypeReference>>() {}); } + + public ApiResponse> fetchChgrCurrState() { + + return externalApiClient.post() + .uri("/api/charge/stateInfo") + .body(Collections.emptyMap()) + .retrieve() + .body(new ParameterizedTypeReference>>() {}); + } } \ No newline at end of file diff --git a/src/main/java/net/jwsi/jcms/vpp/api/ExternalApiService.java b/src/main/java/net/jwsi/jcms/vpp/api/ExternalApiService.java index 6773d2c..1a4a523 100644 --- a/src/main/java/net/jwsi/jcms/vpp/api/ExternalApiService.java +++ b/src/main/java/net/jwsi/jcms/vpp/api/ExternalApiService.java @@ -20,7 +20,8 @@ public class ExternalApiService { private String baseUrl; @Value("${jcms.api.user-id}") - private String apiUserId; + private String + apiUserId; @Value("${jcms.api.user-pwd}") private String apiUserPwd; diff --git a/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrState.java b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrState.java new file mode 100644 index 0000000..b3c3ee4 --- /dev/null +++ b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrState.java @@ -0,0 +1,74 @@ +package net.jwsi.jcms.vpp.chgrCurrState; + +import jakarta.persistence.*; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; +import net.jwsi.jcms.base.BaseStEntity; + +@NoArgsConstructor +@Getter +@Setter +@ToString +@Entity(name = "vpp_chgr_curr_state") +@IdClass(ChgrCurrStateId.class) +public class ChgrCurrState extends BaseStEntity { + + @Transient + private ChgrCurrStateId oldId__; + + @Id + @Column(name = "provider_id") + private String providerId; // provider_id (PK) + + @Id + @Column(name = "st_id") + private String stId; // st_id (PK) + + @Id + @Column(name = "chgr_id") + private String chgrId; // chgr_id (PK) + + @Column(name = "state_dt") + private String stateDt; + + @Column(name = "op_mode") + private String opMode; + + @Column(name = "ch1_rechg_state_cd") + private String ch1RechgStateCd; + + @Column(name = "ch1_door_state_cd") + private String ch1DoorStateCd; + + @Column(name = "ch1_plug_state_cd") + private String ch1PlugStateCd; + + @Column(name = "ch2_rechg_state_cd") + private String ch2RechgStateCd; + + @Column(name = "ch2_door_state_cd") + private String ch2DoorStateCd; + + @Column(name = "ch2_plug_state_cd") + private String ch2PlugStateCd; + + @Column(name = "ch3_rechg_state_cd") + private String ch3RechgStateCd; + + @Column(name = "ch3_door_state_cd") + private String ch3DoorStateCd; + + @Column(name = "ch3_plug_state_cd") + private String ch3PlugStateCd; + + @Column(name = "integrated_kwh") + private Double integratedKwh; + + @Column(name = "dc_power_wh") + private Double dcPowerWh; + + @Column(name = "ac_power_wh") + private Double acPowerWh; +} \ No newline at end of file diff --git a/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateController.java b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateController.java new file mode 100644 index 0000000..7250442 --- /dev/null +++ b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateController.java @@ -0,0 +1,63 @@ +package net.jwsi.jcms.vpp.chgrCurrState; + +import net.jwsi.jcms.base.BaseController; +import net.jwsi.jcms.exception.JsonDataException; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.List; +import java.util.Map; + +@Controller +@RequestMapping("/cms/chgrCurrState") +public class ChgrCurrStateController extends BaseController { + + private final ChgrCurrStateService chgrCurrStateService; + private final String path = "/system/chgrCurrState/"; + + public ChgrCurrStateController(ChgrCurrStateService service, ChgrCurrStateService chgrCurrStateService) { + super(service); + this.chgrCurrStateService = chgrCurrStateService; + } + + @GetMapping("list") + public String list(){ + chgrCurrStateService.getChgrCurrState(); + return path+"list"; + } + @PostMapping("list.json") + @ResponseBody + public Map list(ChgrCurrState chgrCurrState){ + return svcSelectList(chgrCurrState); + } + @PostMapping("view.json") + @ResponseBody + public Map viewData(ChgrCurrState chgrCurrState) throws JsonDataException { + return svcSelectOne(chgrCurrState); + } + + @PostMapping("insert.json") + @ResponseBody + public Map insert(ChgrCurrState chgrCurrState) throws JsonDataException { + return svcInsert(chgrCurrState); + } + + @PostMapping("update.json") + @ResponseBody + public Map update(ChgrCurrState chgrCurrState) throws JsonDataException { + return svcUpdate(chgrCurrState); + } + + @Override + protected void chkSelectList(List list) throws JsonDataException { + + } + + @Override + protected void chkSelect(ChgrCurrState data) throws JsonDataException { + + } +} diff --git a/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateId.java b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateId.java new file mode 100644 index 0000000..1f4406b --- /dev/null +++ b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateId.java @@ -0,0 +1,19 @@ +package net.jwsi.jcms.vpp.chgrCurrState; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +@EqualsAndHashCode +public class ChgrCurrStateId implements Serializable { + + private String providerId; + private String stId; + private String chgrId; +} diff --git a/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateRepository.java b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateRepository.java new file mode 100644 index 0000000..b6e5f65 --- /dev/null +++ b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateRepository.java @@ -0,0 +1,8 @@ +package net.jwsi.jcms.vpp.chgrCurrState; + +import net.jwsi.jcms.base.BaseRecStRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface ChgrCurrStateRepository extends BaseRecStRepository { +} diff --git a/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateService.java b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateService.java new file mode 100644 index 0000000..9b5ca50 --- /dev/null +++ b/src/main/java/net/jwsi/jcms/vpp/chgrCurrState/ChgrCurrStateService.java @@ -0,0 +1,87 @@ +package net.jwsi.jcms.vpp.chgrCurrState; + +import jakarta.transaction.Transactional; +import lombok.extern.slf4j.Slf4j; +import net.jwsi.jcms.base.BaseService; +import net.jwsi.jcms.base.EnumSqlType; +import net.jwsi.jcms.utils.HttpUtil; +import net.jwsi.jcms.utils.LoginUtil; +import net.jwsi.jcms.vpp.api.ApiClient; +import net.jwsi.jcms.vpp.api.ApiResponse; +import org.springframework.data.domain.Page; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@Slf4j +public class ChgrCurrStateService extends BaseService { + + private final ApiClient apiClient; + + public ChgrCurrStateService(ChgrCurrStateRepository repository, ApiClient apiClient) { + super(repository); + this.apiClient = apiClient; + } + + @Transactional + @Scheduled(cron = "0 0 0 * * *") + public void getChgrCurrState() { + ApiResponse> response = apiClient.fetchChgrCurrState(); + + if (response == null || !Integer.valueOf(200).equals(response.getCode())) { + String msg = (response != null) ? response.getMessage() : "응답 없음"; + throw new RuntimeException("API 호출 실패: " + msg); + } + + List list = response.getData(); + if (list == null || list.isEmpty()) { + log.info("가져온 충전소 데이터가 없습니다."); + } + + List savedStations = super.repository.saveAll(list); + + log.info("총 {}건의 충전소 데이터가 DB에 동기화되었습니다.", savedStations.size()); + + } + + @Override + protected Integer getUserId() { + return HttpUtil.getUserId(); + } + + @Override + protected String getUserName(Integer id) { + return LoginUtil.getUserName(id); + } + + @Override + protected ChgrCurrState newSearchParam(ChgrCurrState chgrCurrState) { + if(chgrCurrState == null){ + chgrCurrState = new ChgrCurrState(); + } + return chgrCurrState; + } + + @Override + protected EnumSqlType useSqlTyp() { + return EnumSqlType.SPECIFICATION; + } + + @Override + protected Specification getSpecification(ChgrCurrState chgrCurrState) { + return null; + } + + @Override + protected Page _selectPage(ChgrCurrState chgrCurrState) { + return null; + } + + @Override + protected List _selectList(ChgrCurrState chgrCurrState) { + return null; + } +} diff --git a/src/main/java/net/jwsi/jcms/vpp/chgrHist/ChgrHistService.java b/src/main/java/net/jwsi/jcms/vpp/chgrHist/ChgrHistService.java index 4ef0b8c..97894d3 100644 --- a/src/main/java/net/jwsi/jcms/vpp/chgrHist/ChgrHistService.java +++ b/src/main/java/net/jwsi/jcms/vpp/chgrHist/ChgrHistService.java @@ -13,8 +13,7 @@ import org.springframework.data.jpa.domain.Specification; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; -import java.time.LocalDateTime; -import java.util.ArrayList; +import java.time.LocalDate; import java.util.List; @Slf4j @@ -33,7 +32,8 @@ public class ChgrHistService extends BaseService> response = apiClient.fetchChgrHist(LocalDateTime.now().toString(), "50"); + String startDt = LocalDate.now().toString(); + ApiResponse> response = apiClient.fetchChgrHist(startDt, "50"); if (response == null || !Integer.valueOf(200).equals(response.getCode())) { String msg = (response != null) ? response.getMessage() : "응답 없음"; @@ -42,21 +42,30 @@ public class ChgrHistService extends BaseService dtoList = response.getData(); if (dtoList == null || dtoList.isEmpty()) { - log.info("가져온 충전소 데이터가 없습니다."); + log.info("가져온 충전이력 데이터가 없습니다."); + return; } List entityList = dtoList.stream() .map(ChgrHistResponseDto::toEntity) .toList(); - List updateList = new ArrayList<>(); + int insertCount = 0; + int updateCount = 0; + for (ChgrHist h : entityList) { - update(h); - updateList.add(h); + Integer id = BaseService.getId(h); + + if (id != null && super.repository.existsById(id)) { + super.update(h); + updateCount++; + } else { + super.insert(h); + insertCount++; + } } - log.info("총 {}건의 충전소 데이터가 DB에 동기화되었습니다.", updateList.size()); - + log.info("충전이력 동기화 완료 (신규 추가: {}건 / 기존 업데이트: {}건)", insertCount, updateCount); } @Override diff --git a/src/main/resources/templates/system/chgrCurrState/list.html b/src/main/resources/templates/system/chgrCurrState/list.html new file mode 100644 index 0000000..83fd8fd --- /dev/null +++ b/src/main/resources/templates/system/chgrCurrState/list.html @@ -0,0 +1,307 @@ + + + +
+
+
+
+
+
+
+ provider_id + +
+
+
+
+ st_id + +
+
+
+
+ chgr_id + +
+
+
+
+ 상태 일시 + +
+
+
+
+ op_mode + +
+
+
+
+ ch1_rechg_state_cd + +
+
+
+
+ ch1_door_state_cd + +
+
+
+
+ ch1_plug_state_cd + +
+
+
+
+ +
+
+
+ + + + + +
+
+
+
+
+ +
+
+
+
+
+
+
+ + + + + +
+ + \ No newline at end of file