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