From f8cf8c9859c66d79f350d1008546b13ed375c129 Mon Sep 17 00:00:00 2001 From: maolei Date: Sat, 10 May 2025 13:53:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(uapbd):=20=E6=B7=BB=E5=8A=A0openapi?= =?UTF-8?q?=E4=BB=93=E5=BA=93=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加查询仓库信息的 POST 接口 queryStordoc - 实现根据条件查询仓库信息并分页返回结果 --- .gitignore | 3 + uapbd/META-INF/stordocManageResource.rest | 6 + .../storedoc/StordocManageResource.java | 252 ++++++++++++++++++ 3 files changed, 261 insertions(+) create mode 100644 uapbd/META-INF/stordocManageResource.rest create mode 100644 uapbd/src/public/nccloud/api/uapbd/stordocmanage/storedoc/StordocManageResource.java diff --git a/.gitignore b/.gitignore index 6dcd014..c11d6f9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ /out/ /.idea/ /taikai2312.iml +.project +.classpath +.settings \ No newline at end of file diff --git a/uapbd/META-INF/stordocManageResource.rest b/uapbd/META-INF/stordocManageResource.rest new file mode 100644 index 0000000..e28a0b7 --- /dev/null +++ b/uapbd/META-INF/stordocManageResource.rest @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/uapbd/src/public/nccloud/api/uapbd/stordocmanage/storedoc/StordocManageResource.java b/uapbd/src/public/nccloud/api/uapbd/stordocmanage/storedoc/StordocManageResource.java new file mode 100644 index 0000000..bf366db --- /dev/null +++ b/uapbd/src/public/nccloud/api/uapbd/stordocmanage/storedoc/StordocManageResource.java @@ -0,0 +1,252 @@ +package nccloud.api.uapbd.stordocmanage.storedoc; + + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import nc.bs.dao.BaseDAO; +import nc.impl.pubapp.pattern.database.SqlBuilderUtil; +import nc.jdbc.framework.processor.ColumnListProcessor; +import nc.vo.bd.stordoc.StordocVO; +import nccloud.api.rest.utils.OpenApiPageInfo; +import nccloud.api.rest.utils.ResultMessageUtil; +import nccloud.api.uapbd.common.utils.OpenApiPagenationUtils; +import nccloud.commons.lang.StringUtils; +import nccloud.ws.rest.resource.AbstractNCCRestResource; +import org.json.JSONString; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import java.util.*; + +/** + * ֿӿ + */ +@Path("uapbd/stordoc/stordoc") +public class StordocManageResource extends AbstractNCCRestResource { + + public static final BaseDAO BASE_DAO = new BaseDAO(); + + @Override + public String getModule() { + return "uapbd"; + } + + /** + * ֶSQL + * + * @param paramMap Map + * @return SQLַ + */ + private String buildCondition(Map paramMap) { + List conditions = new ArrayList<>(); + + // code - ʹIN + if (paramMap.containsKey("code")) { + String[] codes = (String[]) paramMap.get("code"); + if (codes != null && codes.length > 0) { + StringBuilder codeCondition = new StringBuilder("code in ("); + for (int i = 0; i < codes.length; i++) { + if (i > 0) { + codeCondition.append(","); + } + codeCondition.append("'").append(escapeSql(codes[i])).append("'"); + } + codeCondition.append(")"); + conditions.add(codeCondition.toString()); + } + } + // pk_group - ʹIN + if (paramMap.containsKey("pk_group")) { + String[] pk_groups = (String[]) paramMap.get("pk_group"); + if (pk_groups != null && pk_groups.length > 0) { + StringBuilder codeCondition = new StringBuilder("pk_group in ("); + for (int i = 0; i < pk_groups.length; i++) { + if (i > 0) { + codeCondition.append(","); + } + codeCondition.append("'").append(escapeSql(pk_groups[i])).append("'"); + } + codeCondition.append(")"); + conditions.add(codeCondition.toString()); + } + } + // pk_org - ʹIN + if (paramMap.containsKey("pk_org")) { + String[] pk_orgs = (String[]) paramMap.get("pk_org"); + if (pk_orgs != null && pk_orgs.length > 0) { + StringBuilder codeCondition = new StringBuilder("pk_org in ("); + for (int i = 0; i < pk_orgs.length; i++) { + if (i > 0) { + codeCondition.append(","); + } + codeCondition.append("'").append(escapeSql(pk_orgs[i])).append("'"); + } + codeCondition.append(")"); + conditions.add(codeCondition.toString()); + } + } + + // name - ʹIN + if (paramMap.containsKey("name")) { + String[] names = (String[]) paramMap.get("name"); + if (names != null && names.length > 0) { + StringBuilder nameCondition = new StringBuilder("name in ("); + for (int i = 0; i < names.length; i++) { + if (i > 0) { + nameCondition.append(","); + } + nameCondition.append("'").append(escapeSql(names[i])).append("'"); + } + nameCondition.append(")"); + conditions.add(nameCondition.toString()); + } + } + + return conditions.isEmpty() ? "" : String.join(" and ", conditions); + } + + /** + * SQLע - ת嵥 + * + * @param input ַ + * @return תַ + */ + private String escapeSql(String input) { + return input == null ? null : input.replace("'", "''"); + } + + /** + * ѯֿϢ + * ʾ: + * JSONʾ: + * { + * "ufinterface": { + * "data": { + * "code": ["ֿcode", "ST002"], + * "name": ["ֿname", "ֿB"], + * "org_code": ["ORG01", "ORG02"], + * "group_codes": ["GROUP001", "GROUP002"] + * }, + * "pageInfo": { + * "pageNo": 1, + * "pageSize": 10 + * } + * } + * } + * + * @param json JSONַ + * @return JSONString ѯϢ + */ + @POST + @Path("queryStordoc") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public JSONString queryStordoc(JSONString json) { + JSONObject jObject = JSON.parseObject(json.toJSONString()); + if (jObject == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONΪnull")); + } + JSONObject ufinterfaceObj = jObject.getJSONObject("ufinterface"); + if (ufinterfaceObj == null) { + return ResultMessageUtil.exceptionToJSON(new NullPointerException("ufinterfaceڵΪnull")); + } + JSONObject data = ufinterfaceObj.getJSONObject("data"); // ѯ + JSONObject pageInfoJson = ufinterfaceObj.getJSONObject("pageInfo"); // ҳϢ + if (data == null) { + data = new JSONObject(); + } + Map paramMap = new HashMap<>(); + JSONArray code_json = data.getJSONArray("code"); + JSONArray name_json = data.getJSONArray("name"); + JSONArray orgCodeArr = data.getJSONArray("org_code"); + JSONArray groupCodeArr = data.getJSONArray("group_codes"); + + // ͵IJ + if (code_json != null && !code_json.isEmpty()) { + paramMap.put("code", code_json.toArray(new String[0])); + } + if (name_json != null && !name_json.isEmpty()) { + paramMap.put("name", name_json.toArray(new String[0])); + } + + try { + // org_code תΪ浽 paramMap + if (orgCodeArr != null && !orgCodeArr.isEmpty()) { + List pkOrgList = new ArrayList<>(); + StringBuilder cond = new StringBuilder("code in ("); + for (int i = 0; i < orgCodeArr.size(); i++) { + if (i > 0) { + cond.append(","); + } + cond.append("'").append(escapeSql(orgCodeArr.getString(i))).append("'"); + } + cond.append(")"); + Collection stockOrgs = BASE_DAO.retrieveByClause(nc.vo.org.StockOrgVO.class, cond.toString(), new String[]{"pk_stockorg"}); + if (stockOrgs != null) { + for (Object obj : stockOrgs) { + nc.vo.org.StockOrgVO vo = (nc.vo.org.StockOrgVO) obj; + pkOrgList.add(vo.getPk_stockorg()); + } + } + if (!pkOrgList.isEmpty()) { + paramMap.put("pk_org", pkOrgList.toArray(new String[0])); + } + } + + // group_codes תΪ浽 paramMap + if (groupCodeArr != null && !groupCodeArr.isEmpty()) { + List pkGroupList = new ArrayList<>(); + StringBuilder cond = new StringBuilder("code in ("); + for (int i = 0; i < groupCodeArr.size(); i++) { + if (i > 0) { + cond.append(","); + } + cond.append("'").append(escapeSql(groupCodeArr.getString(i))).append("'"); + } + cond.append(")"); + Collection groups = BASE_DAO.retrieveByClause(nc.vo.org.GroupVO.class, cond.toString(), new String[]{"pk_group"}); + if (groups != null) { + for (Object obj : groups) { + nc.vo.org.GroupVO vo = (nc.vo.org.GroupVO) obj; + pkGroupList.add(vo.getPk_group()); + } + } + if (!pkGroupList.isEmpty()) { + paramMap.put("pk_group", pkGroupList.toArray(new String[0])); + } + } + + // ʹԶ巽 + String condition = buildCondition(paramMap); + if (StringUtils.isNotBlank(condition)) { + condition = "dr = 0 and " + condition; + } else { + condition = "dr=0"; + } + + String sql = "SELECT pk_stordoc FROM bd_stordoc WHERE " + condition; + List allPks = (List) BASE_DAO.executeQuery(sql, new ColumnListProcessor()); + OpenApiPageInfo openApiPageInfo = new OpenApiPageInfo(); + String[] currPks = OpenApiPagenationUtils.getCurrentPagePksAndPageInfo(allPks, pageInfoJson, openApiPageInfo); + + if (currPks == null || currPks.length == 0) { + return ResultMessageUtil.toJSONByPage(new StordocVO[0], openApiPageInfo, false); + } + + SqlBuilderUtil sqlBuilderUtil = new SqlBuilderUtil(); + String wherePartForRetrieve = sqlBuilderUtil.buildSQL("pk_stordoc", currPks, null); + + StordocVO[] vos = (StordocVO[]) BASE_DAO.retrieveByClause(StordocVO.class, wherePartForRetrieve) + .toArray(new StordocVO[0]); + + return ResultMessageUtil.toJSONByPage(vos, openApiPageInfo, false); + + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + +}