feat(api): 修改物料分类查询接口并优化仓库查询功能
- 修改物料分类查询接口,可以传入code和name数组 - 优化存储文档查询功能 StordocManageResource - 更新 .gitignore 文件,忽略 .project 文件 - 修复物料管理中空条件查询导致的 SQL 错误
This commit is contained in:
parent
40aa6dbe93
commit
756afff77e
|
@ -2,6 +2,7 @@
|
|||
/out/
|
||||
/.idea/
|
||||
/taikai2312.iml
|
||||
.project
|
||||
.classpath
|
||||
.settings
|
||||
# 忽略任意目录下的 .project
|
||||
**/.project
|
|
@ -0,0 +1,68 @@
|
|||
package nccloud.api.uapbd.material.materialclass;
|
||||
|
||||
|
||||
import nc.bs.framework.common.NCLocator;
|
||||
import nc.itf.bd.material.marbasclass.IMaterialBasClassQueryService;
|
||||
import nc.vo.bd.material.marbasclass.MarBasClassVO;
|
||||
import nccloud.api.rest.utils.ApiResourceParamUtils;
|
||||
import nccloud.api.rest.utils.IJsonForAPI;
|
||||
import nccloud.api.rest.utils.JsonFactoryForAPI;
|
||||
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.PageInfo;
|
||||
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.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Path("/uapbd/materialclass")
|
||||
public class MaterialClassQueryResources extends AbstractNCCRestResource {
|
||||
|
||||
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 = (ApiQueryParam) iJsonForAPI.fromJson(json.toJSONString(), ApiQueryParam.class);
|
||||
String sender = apiQueryParam.getUfinterface().getSender();
|
||||
ApiDataVO apiDataVO = apiQueryParam.getUfinterface().getData();
|
||||
PageInfo pageInfo = apiQueryParam.getUfinterface().getPageInfo();
|
||||
Map<String, Object> param = apiDataVO.getParamdata();
|
||||
if (param.containsKey("name") && param.get("name") != null) {
|
||||
List<String> names = (List<String>) param.get("name");
|
||||
if (!names.isEmpty()) {
|
||||
param.put("name", names.toArray(new String[0]));
|
||||
} else {
|
||||
param.remove("name");
|
||||
}
|
||||
}
|
||||
if (param.containsKey("code") && param.get("code") != null) {
|
||||
List<String> codes = (List<String>) param.get("code");
|
||||
if (!codes.isEmpty()) {
|
||||
param.put("code", codes.toArray(new String[0]));
|
||||
} else {
|
||||
param.remove("code");
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
String querycondition = (new ApiResourceParamUtils()).parseParmToSqlByCode(new MarBasClassVO(), param);
|
||||
MarBasClassVO[] vos = NCLocator.getInstance().lookup(IMaterialBasClassQueryService.class).queryMaterialClassByCondition(null, querycondition);
|
||||
return vos != null && vos.length > 0 ? ResultMessageUtil.toJSON(vos) : null;
|
||||
} catch (Exception ex) {
|
||||
return ResultMessageUtil.exceptionToJSON(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,28 +1,22 @@
|
|||
package nccloud.api.uapbd.materialmanage.material;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import nc.bs.dao.BaseDAO;
|
||||
import nc.ws.opm.pub.utils.result.APIErrCodeEnum;
|
||||
import nc.bs.dao.DAOException;
|
||||
import nc.bs.framework.common.NCLocator;
|
||||
import nc.bs.framework.core.util.ObjectCreator;
|
||||
import nc.impl.pubapp.pattern.database.SqlBuilderUtil;
|
||||
import nc.itf.bd.material.assign.IMaterialAssignService;
|
||||
import nc.jdbc.framework.processor.ColumnListProcessor;
|
||||
import nc.jdbc.framework.processor.MapListProcessor;
|
||||
import nc.vo.bd.material.MaterialVO;
|
||||
import nc.vo.bd.material.prod.MaterialProdVO;
|
||||
import nc.vo.bd.material.sale.MaterialSaleVO;
|
||||
import nc.vo.bd.material.stock.MaterialStockVO;
|
||||
import nc.ws.opm.pub.utils.result.APIErrCodeEnum;
|
||||
import nccloud.api.baseapp.exchange.convert.IOpenApiJsonConvertToExChangeXmlService;
|
||||
import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataObject;
|
||||
import nccloud.api.baseapp.exchange.convert.OpenApiConvertDataResult;
|
||||
|
@ -32,10 +26,18 @@ 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 nc.jdbc.framework.processor.MapListProcessor;
|
||||
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.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* ÎïÁϽӿÚÊÊÅä2312
|
||||
*/
|
||||
|
@ -171,6 +173,10 @@ public class MaterialManageMaterial extends AbstractNCCRestResource {
|
|||
ApiResourceParamUtils.addTranslatorMap("pk_org", IParamTranslator);
|
||||
String condition = ApiResourceParamUtils.parseParmToSqlByCode(new MaterialVO(), param);
|
||||
|
||||
if (condition.isBlank()) {
|
||||
condition = "1=1";// 没有条件就拼接个1=1,防止sql报错
|
||||
}
|
||||
|
||||
String sql = "select pk_material from bd_material where " + condition;
|
||||
List<String> allPks = (List) (new BaseDAO()).executeQuery(sql, new ColumnListProcessor());
|
||||
OpenApiPageInfo openApiPageInfo = new OpenApiPageInfo();
|
||||
|
|
|
@ -5,9 +5,8 @@ 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 nc.jdbc.framework.processor.MapListProcessor;
|
||||
import nccloud.api.rest.utils.OpenApiPageInfo;
|
||||
import nccloud.api.rest.utils.ResultMessageUtil;
|
||||
import nccloud.api.uapbd.common.utils.OpenApiPagenationUtils;
|
||||
|
@ -219,7 +218,6 @@ public class StordocManageResource extends AbstractNCCRestResource {
|
|||
}
|
||||
}
|
||||
|
||||
// 使用自定义方法替代工具类
|
||||
String condition = buildCondition(paramMap);
|
||||
if (StringUtils.isNotBlank(condition)) {
|
||||
condition = "dr = 0 and " + condition;
|
||||
|
@ -233,16 +231,71 @@ public class StordocManageResource extends AbstractNCCRestResource {
|
|||
String[] currPks = OpenApiPagenationUtils.getCurrentPagePksAndPageInfo(allPks, pageInfoJson, openApiPageInfo);
|
||||
|
||||
if (currPks == null || currPks.length == 0) {
|
||||
return ResultMessageUtil.toJSONByPage(new StordocVO[0], openApiPageInfo, false);
|
||||
return ResultMessageUtil.toJSONByPage(new JSONObject[0], openApiPageInfo, false);
|
||||
}
|
||||
StringJoiner stringJoiner = new StringJoiner(",");
|
||||
for (String pk : currPks) {
|
||||
stringJoiner.add("'" + pk + "'");
|
||||
}
|
||||
String pks = stringJoiner.toString();
|
||||
|
||||
String mainSql = "SELECT sd.*, " +
|
||||
"so.code AS org_code, so.name AS org_name, " +
|
||||
"og.code AS group_code, og.name AS group_name, " +
|
||||
"ad.code AS address_code, ad.name AS address_name, " +
|
||||
"ba.code AS storaddr_code " +
|
||||
"FROM bd_stordoc sd " +
|
||||
"LEFT JOIN org_stockorg so ON sd.pk_org = so.pk_stockorg " +
|
||||
"LEFT JOIN org_group og ON sd.pk_group = og.pk_group " +
|
||||
"LEFT JOIN bd_addressdoc ad ON sd.pk_address = ad.pk_addressdoc " +
|
||||
"LEFT JOIN bd_address ba ON sd.storaddr = ba.pk_address " +
|
||||
"WHERE sd.pk_stordoc IN (" + pks + ")";
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Map<String, Object>> rows = (List<Map<String, Object>>) BASE_DAO.executeQuery(mainSql, new MapListProcessor());
|
||||
|
||||
List<JSONObject> resultList = new ArrayList<>();
|
||||
for (Map<String, Object> row : rows) {
|
||||
JSONObject stordocJson = new JSONObject(true); // ʹÓÃÓÐÐòMap
|
||||
|
||||
for (Map.Entry<String, Object> entry : row.entrySet()) {
|
||||
String key = entry.getKey().toLowerCase();
|
||||
if ("org_code".equals(key) || "org_name".equals(key) ||
|
||||
"group_code".equals(key) || "group_name".equals(key) ||
|
||||
"address_code".equals(key) || "address_name".equals(key) ||
|
||||
"storaddr_code".equals(key)) {
|
||||
continue;
|
||||
}
|
||||
stordocJson.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
SqlBuilderUtil sqlBuilderUtil = new SqlBuilderUtil();
|
||||
String wherePartForRetrieve = sqlBuilderUtil.buildSQL("pk_stordoc", currPks, null);
|
||||
JSONObject pkOrgDetailsJson = new JSONObject(true);
|
||||
pkOrgDetailsJson.put("pk_org", row.get("pk_org"));
|
||||
pkOrgDetailsJson.put("code", row.get("org_code"));
|
||||
pkOrgDetailsJson.put("name", row.get("org_name"));
|
||||
stordocJson.put("pk_org", pkOrgDetailsJson);
|
||||
|
||||
StordocVO[] vos = (StordocVO[]) BASE_DAO.retrieveByClause(StordocVO.class, wherePartForRetrieve)
|
||||
.toArray(new StordocVO[0]);
|
||||
JSONObject pkGroupDetailsJson = new JSONObject(true);
|
||||
pkGroupDetailsJson.put("pk_group", row.get("pk_group"));
|
||||
pkGroupDetailsJson.put("code", row.get("group_code"));
|
||||
pkGroupDetailsJson.put("name", row.get("group_name"));
|
||||
stordocJson.put("pk_group", pkGroupDetailsJson);
|
||||
|
||||
return ResultMessageUtil.toJSONByPage(vos, openApiPageInfo, false);
|
||||
JSONObject pkAddressDetailsJson = new JSONObject(true);
|
||||
pkAddressDetailsJson.put("pk_address", row.get("pk_address"));
|
||||
pkAddressDetailsJson.put("code", row.get("address_code"));
|
||||
pkAddressDetailsJson.put("name", row.get("address_name"));
|
||||
stordocJson.put("pk_address", pkAddressDetailsJson);
|
||||
|
||||
JSONObject storaddrDetailsJson = new JSONObject(true);
|
||||
storaddrDetailsJson.put("pk_address", row.get("storaddr"));
|
||||
storaddrDetailsJson.put("code", row.get("storaddr_code"));
|
||||
stordocJson.put("storaddr", storaddrDetailsJson);
|
||||
|
||||
resultList.add(stordocJson);
|
||||
}
|
||||
|
||||
return ResultMessageUtil.toJSONByPage(resultList.toArray(new JSONObject[0]), openApiPageInfo, false);
|
||||
|
||||
} catch (Exception e) {
|
||||
return ResultMessageUtil.exceptionToJSON(e);
|
||||
|
|
Loading…
Reference in New Issue