From 6c01f422a03cad96592620ade35103e8d624d8f2 Mon Sep 17 00:00:00 2001 From: maolei Date: Mon, 12 May 2025 14:54:29 +0800 Subject: [PATCH] =?UTF-8?q?refactor(uapbd):=20=E9=87=8D=E6=9E=84=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8E=A5=E5=8F=A3=E5=B9=B6=E5=A2=9E=E5=8A=A0=E6=96=B0?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=B1=BB=E5=9E=8B=20-=20=E6=8A=BD=E5=8F=96?= =?UTF-8?q?=E5=85=AC=E5=85=B1=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91=E5=88=B0?= =?UTF-8?q?=20baseQuery=20=E6=96=B9=E6=B3=95=E4=B8=AD=20-=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=20queryDept=E3=80=81queryCustomer=20?= =?UTF-8?q?=E5=92=8C=20querySupplier=20=E4=B8=89=E7=A7=8D=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E6=9F=A5=E8=AF=A2=E7=B1=BB=E5=9E=8B=20-=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E4=BA=86=20query=20=E6=96=B9=E6=B3=95=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=9E=8B=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= =?UTF-8?q?=20-=20=E7=A7=BB=E9=99=A4=E4=BA=86=E6=9C=AA=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=20ApiDataVO=20=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/nccloud/api/uapbd/QuerySync.java | 94 +++++++++++-------- 1 file changed, 56 insertions(+), 38 deletions(-) diff --git a/uapbd/src/public/nccloud/api/uapbd/QuerySync.java b/uapbd/src/public/nccloud/api/uapbd/QuerySync.java index 8d07ca7..5b3f686 100644 --- a/uapbd/src/public/nccloud/api/uapbd/QuerySync.java +++ b/uapbd/src/public/nccloud/api/uapbd/QuerySync.java @@ -10,7 +10,6 @@ import nccloud.api.rest.utils.IJsonForAPI; import nccloud.api.rest.utils.JsonFactoryForAPI; import nccloud.api.rest.utils.OpenApiPageInfo; import nccloud.api.rest.utils.ResultMessageUtil; -import nccloud.api.rest.utils.vo.ApiDataVO; import nccloud.api.rest.utils.vo.ApiQueryParam; import nccloud.api.rest.utils.vo.ApiUfinterface; import nccloud.api.uapbd.common.utils.OpenApiPagenationUtils; @@ -30,49 +29,21 @@ import java.util.StringJoiner; public class QuerySync extends AbstractNCCRestResource { public static final BaseDAO BASE_DAO = new BaseDAO(); + @Override public String getModule() { return "uapbd"; } - @POST - @Path("query") - @Consumes({"application/json"}) - @Produces({"application/json"}) - public JSONString query(JSONString json) { - IJsonForAPI iJsonForAPI = JsonFactoryForAPI.create(); - ApiQueryParam apiQueryParam = iJsonForAPI.fromJson(json.toJSONString(), ApiQueryParam.class); - ApiDataVO apiDataVO = apiQueryParam.getUfinterface().getData(); - // 从中抓取接口枚举类型 - ApiUfinterface ufinterface = apiQueryParam.getUfinterface(); - if (ufinterface.getData().getParamdata().containsKey("type")) { - String type = (String) ufinterface.getData().getParamdata().get("type"); - try { - switch (type) { - case "queryStordoc": - return queryStordoc(ufinterface); - case "queryMaterial": - return queryMaterial(ufinterface); - default: - return ResultMessageUtil.exceptionToJSON(new Exception("不支持的接口类型: " + type)); - } - } catch (Exception e) { - // 捕获并返回异常信息 - return ResultMessageUtil.exceptionToJSON(e); - } - } else { - return ResultMessageUtil.exceptionToJSON(new Exception("缺失接口类型,请检查参数")); - } - } - - private JSONString queryStordoc(ApiUfinterface apiUfinterface) throws DAOException { + private JSONString baseQuery(ApiUfinterface apiUfinterface, String viewName, String pkColumnName) throws DAOException { Map data = apiUfinterface.getData().getParamdata(); JSONObject pageInfo = (JSONObject) JSONObject.toJSON(apiUfinterface.getPageInfo()); - data.remove("type"); + data.remove("type"); // 移除类型参数,因为它仅用于路由,向下传递会影响查询 String condition = QuerySyncSqlUtils.buildUniversalCondition(data); - String sql = "SELECT pk_stordoc FROM V_UAPBD_QUERYSYNC_STORDOC WHERE " + condition; - List allPks = (List) BASE_DAO.executeQuery(sql, new ColumnListProcessor()); + String countSql = "SELECT " + pkColumnName + " FROM " + viewName + " WHERE " + condition; + @SuppressWarnings("unchecked") + List allPks = (List) BASE_DAO.executeQuery(countSql, new ColumnListProcessor()); OpenApiPageInfo openApiPageInfo = new OpenApiPageInfo(); String[] currPks = OpenApiPagenationUtils.getCurrentPagePksAndPageInfo(allPks, pageInfo, openApiPageInfo); @@ -83,18 +54,65 @@ public class QuerySync extends AbstractNCCRestResource { for (String pk : currPks) { stringJoiner.add("'" + pk + "'"); } - String pks = "(" + stringJoiner + ")"; + String pksCondition = "(" + stringJoiner + ")"; - List> rows = (List>) BASE_DAO.executeQuery("select * from v_uapbd_querysync_stordoc where pk_stordoc in " + pks, new MapListProcessor()); + String dataSql = "SELECT * FROM " + viewName + " WHERE " + pkColumnName + " IN " + pksCondition; + @SuppressWarnings("unchecked") + List> rows = (List>) BASE_DAO.executeQuery(dataSql, new MapListProcessor()); return ResultMessageUtil.toJSONByPage(rows, openApiPageInfo, false); } + @POST + @Path("query") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString query(JSONString json) { + IJsonForAPI iJsonForAPI = JsonFactoryForAPI.create(); + ApiQueryParam apiQueryParam = iJsonForAPI.fromJson(json.toJSONString(), ApiQueryParam.class); + // 从中抓取接口枚举类型 + ApiUfinterface ufinterface = apiQueryParam.getUfinterface(); + if (ufinterface.getData().getParamdata().containsKey("type")) { + String type = (String) ufinterface.getData().getParamdata().get("type"); + try { + return switch (type) { + case "queryStordoc" -> queryStordoc(ufinterface); + case "queryMaterial" -> queryMaterial(ufinterface); + case "queryDept" -> queryDept(ufinterface); + case "queryCustomer" -> queryCustomer(ufinterface); + case "querySupplier" -> querySupplier(ufinterface); + default -> ResultMessageUtil.exceptionToJSON(new Exception("不支持的查询类型: " + type)); + }; + } catch (Exception e) { + // 捕获并返回异常信息 + return ResultMessageUtil.exceptionToJSON(e); + } + } else { + return ResultMessageUtil.exceptionToJSON(new Exception("缺失接口类型,请检查参数")); + } + } + + private JSONString queryCustomer(ApiUfinterface ufinterface) throws DAOException { + return baseQuery(ufinterface, "V_UAPBD_QUERYSYNC_CUSTOMER", "pk_customer"); + } + + private JSONString queryDept(ApiUfinterface apiUfinterface) throws DAOException { + return baseQuery(apiUfinterface, "V_UAPBD_QUERYSYNC_DEPT", "pk_defdoc"); + } + /** * 查询物料信息 */ private JSONString queryMaterial(ApiUfinterface apiUfinterface) { - return null; } + + private JSONString queryStordoc(ApiUfinterface apiUfinterface) throws DAOException { + return baseQuery(apiUfinterface, "V_UAPBD_QUERYSYNC_STORDOC", "pk_stordoc"); + } + + private JSONString querySupplier(ApiUfinterface ufinterface) throws DAOException { + return baseQuery(ufinterface, "V_UAPBD_QUERYSYNC_SUPPLIER", "pk_supplier"); + } + } \ No newline at end of file