refactor(uapbd): 重构查询接口并增加新查询类型
- 抽取公共查询逻辑到 baseQuery 方法中 -增加了 queryDept、queryCustomer 和 querySupplier 三种新的查询类型 - 优化了 query 方法中的类型判断逻辑 - 移除了未使用的 ApiDataVO 导入
This commit is contained in:
parent
286a5d1c60
commit
6c01f422a0
|
@ -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<String, Object> 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<String> allPks = (List<String>) BASE_DAO.executeQuery(sql, new ColumnListProcessor());
|
||||
String countSql = "SELECT " + pkColumnName + " FROM " + viewName + " WHERE " + condition;
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> allPks = (List<String>) 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<Map<String, Object>> rows = (List<Map<String, Object>>) 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<Map<String, Object>> rows = (List<Map<String, Object>>) 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");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue