Merge remote-tracking branch 'origin/main'

This commit is contained in:
maolei 2025-05-12 14:02:11 +08:00
commit 286a5d1c60
2 changed files with 88 additions and 66 deletions

View File

@ -55,33 +55,39 @@ public class SubcontractReceiptResource extends AbstractNCCRestResource {
if (jObject == null) { if (jObject == null) {
return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null")); return ResultMessageUtil.exceptionToJSON(new NullPointerException("JSONString:null"));
} }
JSONObject bject = jObject.getJSONObject("ufinterface"); JSONObject ufinterface = jObject.getJSONObject("ufinterface");
if (bject == null) { if (ufinterface == null) {
return ResultMessageUtil.exceptionToJSON(new NullPointerException("ufinterface:null")); return ResultMessageUtil.exceptionToJSON(new NullPointerException("ufinterface:null"));
} }
// 处理分页参数 // 处理分页参数设为必传
JSONObject pageInfo = bject.getJSONObject("pageInfo"); JSONObject pageInfo = ufinterface.getJSONObject("pageInfo");
if (pageInfo == null) {
return ResultMessageUtil.exceptionToJSON(new BusinessException("分页信息(pageInfo)为必填项"));
}
OpenApiPageInfo openApiPageInfo = new OpenApiPageInfo(); OpenApiPageInfo openApiPageInfo = new OpenApiPageInfo();
int pageIndex = 1, pageSize = 20; int pageIndex = pageInfo.getIntValue("pageIndex") > 0 ? pageInfo.getIntValue("pageIndex") : 1;
if (pageInfo != null) { int pageSize = pageInfo.getIntValue("pageSize") > 0 ? pageInfo.getIntValue("pageSize") : 20;
pageIndex = pageInfo.getIntValue("pageIndex") > 0 ? pageInfo.getIntValue("pageIndex") : 1; openApiPageInfo.setPageIndex(pageIndex);
pageSize = pageInfo.getIntValue("pageSize") > 0 ? pageInfo.getIntValue("pageSize") : 20; openApiPageInfo.setPageSize(pageSize);
openApiPageInfo.setPageIndex(pageIndex);
openApiPageInfo.setPageSize(pageSize);
}
// 提取查询参数 // 提取查询参数不再强制验证必填
Map<String, Object> param = extractAndValidateParams(jObject); Map<String, Object> param = new HashMap<>();
boolean hasConditions = extractParams(ufinterface, param);
// 使用ApiResourceParamUtils生成查询条件 // 查询条件若无条件则查询全部
ApiResourceParamUtils apiUtils = new ApiResourceParamUtils(); String condition = "1=1";
String condition = apiUtils.parseParmToSql(new SubcontInHeadVO(), param, ApiResourceParamUtils.BYCODE); if (hasConditions) {
if (condition.endsWith("and ")) { // 使用ApiResourceParamUtils生成查询条件
condition = condition.substring(0, condition.length() - 4); ApiResourceParamUtils apiUtils = new ApiResourceParamUtils();
} condition = apiUtils.parseParmToSql(new SubcontInHeadVO(), param, ApiResourceParamUtils.BYCODE);
if (condition.trim().isEmpty()) { if (condition.endsWith("and ")) {
condition = "1=1"; condition = condition.substring(0, condition.length() - 4);
}
if (condition.trim().isEmpty()) {
condition = "1=1";
}
} }
// 查询所有符合条件的主键 // 查询所有符合条件的主键
@ -131,63 +137,70 @@ public class SubcontractReceiptResource extends AbstractNCCRestResource {
} }
/** /**
* 提取并验证请求参数 * 提取请求参数不强制验证必填
* *
* @param jObject JSON请求对象 * @param ufinterface JSON请求对象
* @return 参数Map * @param param 要填充的参数Map
* @throws BusinessException 参数校验失败时抛出异常 * @return 是否有查询条件
*/ */
private Map<String, Object> extractAndValidateParams(JSONObject jObject) throws BusinessException { private boolean extractParams(JSONObject ufinterface, Map<String, Object> param) {
Map<String, Object> param = new HashMap<>(); boolean hasConditions = false;
jObject = (JSONObject) jObject.get("ufinterface");
// 获取参数 // 获取参数
String pk_group = jObject.getString("pk_group"); String pk_group = ufinterface.getString("pk_group");
String name = jObject.getString("name"); String name = ufinterface.getString("name");
String code = jObject.getString("code"); String code = ufinterface.getString("code");
String createdate = jObject.getString("createdate"); String createdate = ufinterface.getString("createdate");
String ncindustry = jObject.getString("ncindustry"); String ncindustry = ufinterface.getString("ncindustry");
String pk_currtype = jObject.getString("pk_currtype"); String pk_currtype = ufinterface.getString("pk_currtype");
String pk_exratescheme = jObject.getString("pk_exratescheme"); String pk_exratescheme = ufinterface.getString("pk_exratescheme");
String vbillcode = jObject.getString("vbillcode"); String vbillcode = ufinterface.getString("vbillcode");
String pk_org = jObject.getString("pk_org"); String pk_org = ufinterface.getString("pk_org");
String dbilldate = jObject.getString("dbilldate"); String dbilldate = ufinterface.getString("dbilldate");
// 必填字段校验 // 添加到参数Map - 只添加非空参数
if (pk_group == null || pk_group.trim().isEmpty()) { if (pk_group != null && !pk_group.trim().isEmpty()) {
throw new BusinessException("集团主键(pk_group)为必填项"); param.put("pk_group", pk_group);
hasConditions = true;
} }
if (name == null || name.trim().isEmpty()) { if (name != null && !name.trim().isEmpty()) {
throw new BusinessException("名称(name)为必填项"); param.put("name", name);
hasConditions = true;
} }
if (code == null || code.trim().isEmpty()) { if (code != null && !code.trim().isEmpty()) {
throw new BusinessException("编码(code)为必填项"); param.put("code", code);
hasConditions = true;
} }
if (createdate == null || createdate.trim().isEmpty()) { if (createdate != null && !createdate.trim().isEmpty()) {
throw new BusinessException("成立时间(createdate)为必填项"); param.put("createdate", createdate);
hasConditions = true;
} }
if (ncindustry == null || ncindustry.trim().isEmpty()) { if (ncindustry != null && !ncindustry.trim().isEmpty()) {
throw new BusinessException("所属UAP行业(ncindustry)为必填项"); param.put("ncindustry", ncindustry);
hasConditions = true;
} }
if (pk_currtype == null || pk_currtype.trim().isEmpty()) { if (pk_currtype != null && !pk_currtype.trim().isEmpty()) {
throw new BusinessException("本位币(pk_currtype)为必填项"); param.put("pk_currtype", pk_currtype);
hasConditions = true;
} }
if (pk_exratescheme == null || pk_exratescheme.trim().isEmpty()) { if (pk_exratescheme != null && !pk_exratescheme.trim().isEmpty()) {
throw new BusinessException("外币汇率方案(pk_exratescheme)为必填项"); param.put("pk_exratescheme", pk_exratescheme);
hasConditions = true;
}
if (vbillcode != null && !vbillcode.trim().isEmpty()) {
param.put("vbillcode", vbillcode);
hasConditions = true;
}
if (pk_org != null && !pk_org.trim().isEmpty()) {
param.put("pk_org", pk_org);
hasConditions = true;
}
if (dbilldate != null && !dbilldate.trim().isEmpty()) {
param.put("dbilldate", dbilldate);
hasConditions = true;
} }
// 添加到参数Map return hasConditions;
param.put("pk_group", pk_group);
param.put("name", name);
param.put("code", code);
param.put("createdate", createdate);
param.put("ncindustry", ncindustry);
param.put("pk_currtype", pk_currtype);
param.put("pk_exratescheme", pk_exratescheme);
if (vbillcode != null) param.put("vbillcode", vbillcode);
if (pk_org != null) param.put("pk_org", pk_org);
if (dbilldate != null) param.put("dbilldate", dbilldate);
return param;
} }
@Override @Override

View File

@ -51,6 +51,8 @@ public class QuerySync extends AbstractNCCRestResource {
switch (type) { switch (type) {
case "queryStordoc": case "queryStordoc":
return queryStordoc(ufinterface); return queryStordoc(ufinterface);
case "queryMaterial":
return queryMaterial(ufinterface);
default: default:
return ResultMessageUtil.exceptionToJSON(new Exception("不支持的接口类型: " + type)); return ResultMessageUtil.exceptionToJSON(new Exception("不支持的接口类型: " + type));
} }
@ -88,4 +90,11 @@ public class QuerySync extends AbstractNCCRestResource {
return ResultMessageUtil.toJSONByPage(rows, openApiPageInfo, false); return ResultMessageUtil.toJSONByPage(rows, openApiPageInfo, false);
} }
/**
* 查询物料信息
*/
private JSONString queryMaterial(ApiUfinterface apiUfinterface) {
return null;
}
} }