数据贯通完成,规程重构
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.klp.framework.client;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.klp.framework.config.SqlServerApiProperties;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpMethod;
|
||||
@@ -73,7 +74,9 @@ public class SqlServerApiClient {
|
||||
}
|
||||
|
||||
public static class TableSchemaRequest {
|
||||
@JsonProperty("table_type")
|
||||
private String tableType;
|
||||
@JsonProperty("table_name")
|
||||
private String tableName;
|
||||
|
||||
public TableSchemaRequest() {
|
||||
@@ -102,6 +105,7 @@ public class SqlServerApiClient {
|
||||
}
|
||||
|
||||
public static class ExecuteSqlRequest {
|
||||
@JsonProperty("table_type")
|
||||
private String tableType;
|
||||
private String sql;
|
||||
private Map<String, Object> params;
|
||||
@@ -311,10 +315,23 @@ public class SqlServerApiClient {
|
||||
);
|
||||
}
|
||||
|
||||
public ExecuteSqlResponse queryPlanList() {
|
||||
public ExecuteSqlResponse queryPlanList(int page, int pageSize) {
|
||||
int endRow = page * pageSize;
|
||||
int startRow = endRow - pageSize;
|
||||
Map<String, Object> params = new java.util.HashMap<>();
|
||||
params.put("startRow", startRow);
|
||||
params.put("endRow", endRow);
|
||||
return executeSql(
|
||||
"oracle",
|
||||
"select * from JXPLTCM.PLTCM_PDI_PLAN order by INSDATE desc",
|
||||
"select * from (select t.*, ROWNUM rn from (select * from JXPLTCM.PLTCM_PDI_PLAN order by INSDATE desc) t where ROWNUM <= :endRow) where rn > :startRow",
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
public ExecuteSqlResponse queryPlanCount() {
|
||||
return executeSql(
|
||||
"oracle",
|
||||
"select count(*) as total from JXPLTCM.PLTCM_PDI_PLAN",
|
||||
emptyParams()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class SqlServerApiClientConfig {
|
||||
public RestTemplate sqlServerApiRestTemplate(RestTemplateBuilder builder) {
|
||||
return builder
|
||||
.setConnectTimeout(Duration.ofSeconds(5))
|
||||
.setReadTimeout(Duration.ofSeconds(30))
|
||||
.setReadTimeout(Duration.ofSeconds(60))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,12 +32,24 @@ public class SqlServerApiBusinessService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划列表:查询所有计划,按时间倒序。
|
||||
* <p>
|
||||
* 这是后续按 coilId 关联 SEG、实时数据的入口。
|
||||
* 计划列表(分页):按时间倒序,page 从 1 开始。
|
||||
*/
|
||||
public PlanListView getPlanList() {
|
||||
return PlanListView.fromExecuteSqlResponse(client.queryPlanList());
|
||||
public PlanListView getPlanList(int page, int pageSize) {
|
||||
return PlanListView.fromExecuteSqlResponse(client.queryPlanList(page, pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划总数。
|
||||
*/
|
||||
public long getPlanCount() {
|
||||
SqlServerApiClient.ExecuteSqlResponse resp = client.queryPlanCount();
|
||||
List<Map<String, Object>> rows = asRowList(resp);
|
||||
if (rows.isEmpty()) {
|
||||
return 0L;
|
||||
}
|
||||
Object total = rows.get(0).get("total");
|
||||
Number n = asNumber(total);
|
||||
return n == null ? 0L : n.longValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.klp.web.controller.sqlserver;
|
||||
package com.klp.framework.sqlserver;
|
||||
|
||||
import com.klp.common.core.domain.R;
|
||||
import com.klp.framework.service.SqlServerApiBusinessService;
|
||||
@@ -6,8 +6,12 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* sql-server-api 业务查询接口。
|
||||
* <p>
|
||||
@@ -21,11 +25,24 @@ public class SqlServerApiController {
|
||||
private final SqlServerApiBusinessService businessService;
|
||||
|
||||
/**
|
||||
* 计划列表。
|
||||
* 计划列表(分页)。
|
||||
* page 从 1 开始,默认第 1 页,每页 20 条。
|
||||
*/
|
||||
@GetMapping("/plans")
|
||||
public R<SqlServerApiBusinessService.PlanListView> planList() {
|
||||
return R.ok(businessService.getPlanList());
|
||||
public R<SqlServerApiBusinessService.PlanListView> planList(
|
||||
@RequestParam(defaultValue = "1") int page,
|
||||
@RequestParam(defaultValue = "20") int pageSize) {
|
||||
return R.ok(businessService.getPlanList(page, pageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 计划总数,用于前端分页器。
|
||||
*/
|
||||
@GetMapping("/plans/count")
|
||||
public R<Map<String, Long>> planCount() {
|
||||
Map<String, Long> result = new HashMap<>();
|
||||
result.put("total", businessService.getPlanCount());
|
||||
return R.ok(result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user