From 17898b3e6e94fd4fb530727811fc21222dbedafa Mon Sep 17 00:00:00 2001 From: mzr Date: Fri, 18 Jul 2025 17:53:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=8E=B0=E5=AD=98=E9=87=8F?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=9A=84api-EIP-v0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/ic/onhand/APIOnhandQueryIpml.java | 37 ++++- .../api/ic/onhand/IAPIOnhandQuery.java | 15 +- .../openapi/ic/onhand/OnhandResource.java | 143 ++++++++++++++---- 3 files changed, 161 insertions(+), 34 deletions(-) diff --git a/ic/src/private/nccloud/api/impl/ic/onhand/APIOnhandQueryIpml.java b/ic/src/private/nccloud/api/impl/ic/onhand/APIOnhandQueryIpml.java index 2319f05..0f049c8 100644 --- a/ic/src/private/nccloud/api/impl/ic/onhand/APIOnhandQueryIpml.java +++ b/ic/src/private/nccloud/api/impl/ic/onhand/APIOnhandQueryIpml.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.StrUtil; import nc.bs.framework.common.NCLocator; import nc.itf.ic.onhand.OnhandResService; import nc.vo.ic.onhand.entity.OnhandDimVO; @@ -36,7 +38,7 @@ public class APIOnhandQueryIpml implements IAPIOnhandQuery { public OnhandVO[] queryOnhandVOByDims(Map paramMap) throws BusinessException { - //必输项检查 + // 必输项检查 this.requiredFieldCheck(requiredField, paramMap); // 翻译 paramMap = TransferCodeToPKTool.doTranslateFields(jsonParamMapping, paramMap); @@ -57,7 +59,7 @@ public class APIOnhandQueryIpml implements IAPIOnhandQuery { @Override public OnhandVO[] queryOnhandVOByDims(List> paramMapList) throws Exception { - //必输项检查 + // 必输项检查 try { List onhandDimVOS = new ArrayList<>(); for (Map paramMap : paramMapList) { @@ -78,6 +80,25 @@ public class APIOnhandQueryIpml implements IAPIOnhandQuery { } } + + @Override + public OnhandVO[] queryOnhandVOByCondition(Map paramMap) throws Exception { + this.requiredFieldCheck1(paramMap); + // 翻译 + paramMap = TransferCodeToPKTool.doTranslateFields(jsonParamMapping, paramMap); + OnhandDataSupplement dataSupplement = new OnhandDataSupplement(); + OnhandDimVO onhandDimVO = new OnhandDimVO(); + try { + onhandDimVO = dataSupplement.process(paramMap); + } catch (Exception e) { + ExceptionUtils.marsh(e); + } + OnhandVO[] onhandVOs = NCLocator.getInstance().lookup(OnhandResService.class) + .queryOnhandVOByDims(new OnhandDimVO[]{onhandDimVO}); + return onhandVOs; + } + + // 必输项校验 private void requiredFieldCheck(String[] requiredField, Map paramMap) { for (String field : requiredField) { @@ -88,4 +109,16 @@ public class APIOnhandQueryIpml implements IAPIOnhandQuery { } } + private void requiredFieldCheck1(Map paramMap) { + Object orgValue = paramMap.get("pk_org"); + if (ObjectUtil.isEmpty(orgValue)) { + ExceptionUtils.wrappBusinessException("组织字段为必输项!"); + } + Object cmaterialoid = paramMap.get("cmaterialoid"); + Object cwarehouseid = paramMap.get("cwarehouseid"); + if (ObjectUtil.isEmpty(cmaterialoid) && ObjectUtil.isEmpty(cwarehouseid)) { + ExceptionUtils.wrappBusinessException("仓库和物料字段不能都为空!"); + } + } + } diff --git a/ic/src/public/nccloud/api/ic/onhand/IAPIOnhandQuery.java b/ic/src/public/nccloud/api/ic/onhand/IAPIOnhandQuery.java index c5c935e..3f82295 100644 --- a/ic/src/public/nccloud/api/ic/onhand/IAPIOnhandQuery.java +++ b/ic/src/public/nccloud/api/ic/onhand/IAPIOnhandQuery.java @@ -8,11 +8,11 @@ import nc.vo.pub.BusinessException; /** * 现存量查询操作接口 - * @Description: * - * @author: shijkb - * @date: 2019年11月8日 下午2:49:51 * @version NCC1909 + * @Description: + * @author: shijkb + * @date: 2019年11月8日 下午2:49:51 */ public interface IAPIOnhandQuery { @@ -35,4 +35,13 @@ public interface IAPIOnhandQuery { * @throws Exception 当查询操作失败时抛出的异常 */ OnhandVO[] queryOnhandVOByDims(List> paramMap) throws Exception; + + /** + * 根据查询条件查询现存量信息 + * + * @param paramMap 参数映射列表,每个映射包含一组查询条件 + * @return OnhandVO[] 查询到的现存量信息数组 + * @throws Exception 当查询操作失败时抛出的异常 + */ + OnhandVO[] queryOnhandVOByCondition(Map paramMap) throws Exception; } diff --git a/ic/src/public/nccloud/openapi/ic/onhand/OnhandResource.java b/ic/src/public/nccloud/openapi/ic/onhand/OnhandResource.java index 2d4cd80..d51a033 100644 --- a/ic/src/public/nccloud/openapi/ic/onhand/OnhandResource.java +++ b/ic/src/public/nccloud/openapi/ic/onhand/OnhandResource.java @@ -12,9 +12,12 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import nc.bs.dao.BaseDAO; import nc.bs.dao.DAOException; +import nc.bs.uapbd.util.MyHelper; import nc.impl.pubapp.pattern.database.SqlBuilderUtil; +import nc.jdbc.framework.processor.MapProcessor; import nc.vo.bd.material.MaterialVO; import nc.vo.bd.stordoc.StordocVO; +import nc.vo.cmp.util.StringUtils; import nc.vo.pub.BusinessException; import nc.vo.pubapp.pattern.pub.SqlBuilder; import org.json.JSONString; @@ -28,11 +31,11 @@ import nccloud.api.rest.utils.ResultMessageUtil; /** * 现存量信息查询资源类 - * @Description: * - * @author: shijkb - * @date: 2019年11月8日 下午2:42:47 * @version NCC1909 + * @Description: + * @author: shijkb + * @date: 2019年11月8日 下午2:42:47 */ @Path("ic/onhand") public class OnhandResource { @@ -45,22 +48,22 @@ public class OnhandResource { @Path("onhandQuery") @Consumes("application/json") @Produces("application/json") - public JSONString onhandQuery(Map paramMap){ + public JSONString onhandQuery(Map paramMap) { if (paramMap == null) { return ResultMessageUtil.exceptionToJSON("传入参数错误,组织、单据日期条件必输", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); } try { OnhandVO[] onhandVOs = NCLocator.getInstance().lookup(IAPIOnhandQuery.class) - .queryOnhandVOByDims(paramMap) ; - //对数据进行整合组装,返回数量 + .queryOnhandVOByDims(paramMap); + // 对数据进行整合组装,返回数量 UFDouble onhandNum = UFDouble.ZERO_DBL; - if(null != onhandVOs && onhandVOs.length > 0){ + if (null != onhandVOs && onhandVOs.length > 0) { for (OnhandVO onhandVO : onhandVOs) { onhandNum = onhandNum.add(onhandVO.getNonhandnum()); } } return ResultMessageUtil.toJSON(onhandNum, "现存量查询成功!"); - }catch(Exception e){ + } catch (Exception e) { return ResultMessageUtil.exceptionToJSON(e); } } @@ -72,66 +75,118 @@ public class OnhandResource { @Path("onhandsQuery") @Consumes("application/json") @Produces("application/json") - public JSONString onhandsQuery(List> paramMapList){ + public JSONString onhandsQuery(List> paramMapList) { if (paramMapList == null) { return ResultMessageUtil.exceptionToJSON("传入参数错误,组织、单据日期条件必输", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); } try { OnhandVO[] onhandVOs = NCLocator.getInstance().lookup(IAPIOnhandQuery.class) - .queryOnhandVOByDims(paramMapList) ; - //对数据进行整合组装,返回物料+仓库+数量 + .queryOnhandVOByDims(paramMapList); + // 对数据进行整合组装,返回物料+仓库+数量 - if(null != onhandVOs && onhandVOs.length > 0){ - //提炼出onhandVOs里的物料和仓库 + if (null != onhandVOs && onhandVOs.length > 0) { + // 提炼出onhandVOs里的物料和仓库 Set materialPkSet = Arrays.stream(onhandVOs) .map(onhandVO -> onhandVO.getCmaterialvid()) .collect(Collectors.toSet()); Set warehousePkSet = Arrays.stream(onhandVOs) .map(onhandVO -> onhandVO.getCwarehouseid()) .collect(Collectors.toSet()); - Map materialPKCodeMap=queryPK2CodeMap("pk_material",materialPkSet,"bd_material"); - Map warehousePKCodeMap=queryPK2CodeMap("pk_stordoc",warehousePkSet,"bd_stordoc"); - if(materialPKCodeMap==null ||materialPKCodeMap.isEmpty()){ + Map materialPKCodeMap = queryPK2CodeMap("pk_material", materialPkSet, "bd_material"); + Map warehousePKCodeMap = queryPK2CodeMap("pk_stordoc", warehousePkSet, "bd_stordoc"); + if (materialPKCodeMap == null || materialPKCodeMap.isEmpty()) { throw new BusinessException("queryOnhand end : materialPKCodeMap is null"); } - if(warehousePKCodeMap==null ||warehousePKCodeMap.isEmpty()){ + if (warehousePKCodeMap == null || warehousePKCodeMap.isEmpty()) { throw new BusinessException("queryOnhand end : warehousePKCodeMap is null"); } // 根据物料和仓库分组 Map> groupedOnhand = Arrays.stream(onhandVOs) - .collect(Collectors.groupingBy(onhandVO -> onhandVO.getPk_org()+"_"+onhandVO.getCmaterialvid() + "_" + onhandVO.getCwarehouseid())); + .collect(Collectors.groupingBy(onhandVO -> onhandVO.getPk_org() + "_" + onhandVO.getCmaterialvid() + "_" + onhandVO.getCwarehouseid())); Set keys = groupedOnhand.keySet(); JSONArray reArray = new JSONArray(); - for (String dimkey : keys){ + for (String dimkey : keys) { List onhandVOList = groupedOnhand.get(dimkey); JSONObject jsonObject = new JSONObject(); UFDouble onhandNum = UFDouble.ZERO_DBL; jsonObject.put("materialpk", onhandVOList.get(0).getCmaterialvid()); jsonObject.put("materialCode", materialPKCodeMap.getOrDefault(onhandVOList.get(0).getCmaterialvid(), "")); - jsonObject.put("warehousepk", onhandVOList.get(0).getCwarehouseid()); - jsonObject.put("warehouseCOde", warehousePKCodeMap.getOrDefault(onhandVOList.get(0).getCwarehouseid(), "")); - for(OnhandVO onhandVO:onhandVOList){ + jsonObject.put("warehousepk", onhandVOList.get(0).getCwarehouseid()); + jsonObject.put("warehouseCOde", warehousePKCodeMap.getOrDefault(onhandVOList.get(0).getCwarehouseid(), "")); + for (OnhandVO onhandVO : onhandVOList) { onhandNum = onhandNum.add(onhandVO.getNonhandnum()); } - jsonObject.put("onhandnum", onhandNum); + jsonObject.put("onhandnum", onhandNum); reArray.add(jsonObject); } return ResultMessageUtil.toJSON(reArray, "现存量查询成功!"); - }else{ + } else { return ResultMessageUtil.toJSON(null, "现存量查询成功,无数据!"); } - }catch(Exception e){ + } catch (Exception e) { return ResultMessageUtil.exceptionToJSON(e); } } - private Map queryPK2CodeMap(String pkname, Set pks,String tablename) throws DAOException { + /** + * 根据条件批量查询现存量 + * + * @author mzr + * @date 2025/7/16 + */ + @POST + @Path("onhandQueryByCondition") + @Consumes("application/json") + @Produces("application/json") + public JSONString onhandQueryByCondition(Map paramMap) { + if (paramMap == null) { + return ResultMessageUtil.exceptionToJSON("传入参数错误,组织条件必输", APIErrCodeEnum.BUSINESSEXCCODE.getCode()); + } + try { + OnhandVO[] onhandVOs = NCLocator.getInstance().lookup(IAPIOnhandQuery.class) + .queryOnhandVOByCondition(paramMap); + // 对数据进行整合组装 + if (null != onhandVOs && onhandVOs.length > 0) { + JSONArray resArr = new JSONArray(); + for (OnhandVO onhandVO : onhandVOs) { + String cmaterialvid = onhandVO.getCmaterialvid(); + String cwarehouseid = onhandVO.getCwarehouseid(); + Map goodsMap = this.getMaterialInfo(cmaterialvid); + String selectFields = StordocVO.CODE + "," + StordocVO.NAME; + Map stordocMap = this.transferFields(StordocVO.getDefaultTableName(), selectFields, StordocVO.PK_STORDOC, cwarehouseid); + JSONObject oneJson = new JSONObject(); + oneJson.put("pk_material", cmaterialvid); + oneJson.put("materialCode", goodsMap.getOrDefault(MaterialVO.CODE, ""));// 物料编码 + oneJson.put("materialName", goodsMap.getOrDefault(MaterialVO.NAME, ""));// 物料名称 + oneJson.put("materialtype", goodsMap.getOrDefault(MaterialVO.MATERIALTYPE, "")); // 型号 + oneJson.put("materialspec", goodsMap.getOrDefault(MaterialVO.MATERIALSPEC, "")); // // 规格 + oneJson.put("unitcode", goodsMap.getOrDefault("unitcode", "")); // // 计量单位编码 + oneJson.put("unitname", goodsMap.getOrDefault("unitname", "")); // // 计量单位名称 + oneJson.put("warehousePk", onhandVO.getCwarehouseid()); + oneJson.put("warehouseCode", stordocMap.getOrDefault(StordocVO.CODE, ""));// 仓库编码 + oneJson.put("warehouseName", stordocMap.getOrDefault(StordocVO.NAME, ""));// 仓库名称 + oneJson.put("vbatchcode", onhandVO.getVbatchcode());// 批次号 + oneJson.put("onhandnum", onhandVO.getNonhandnum()); + resArr.add(oneJson); + } + return ResultMessageUtil.toJSON(resArr, "现存量查询成功!"); + + } else { + return ResultMessageUtil.toJSON(null, "现存量查询成功,无数据!"); + } + } catch (Exception e) { + return ResultMessageUtil.exceptionToJSON(e); + } + } + + + private Map queryPK2CodeMap(String pkname, Set pks, String tablename) throws DAOException { SqlBuilderUtil SqlBuilderUtil = new SqlBuilderUtil(); - SqlBuilder sql =new SqlBuilder(); - sql.append(" select code,"+pkname +" from "+tablename+" where "); - sql.append(pkname,pks.toArray(new String[0])); + SqlBuilder sql = new SqlBuilder(); + sql.append(" select code," + pkname + " from " + tablename + " where "); + sql.append(pkname, pks.toArray(new String[0])); List> remain = (List>) new BaseDAO().executeQuery(sql.toString(), new nc.jdbc.framework.processor.MapListProcessor()); if (remain == null || remain.isEmpty()) { return null; @@ -149,4 +204,34 @@ public class OnhandResource { } return pkCodeMap; } + + public Map transferFields(String tableName, String selectFields, String pkField, String pk) throws Exception { + if (StringUtils.isEmpty(pk)) { + return null; + } + SqlBuilder sqlBuilder = new SqlBuilder(); + sqlBuilder.append(" select " + selectFields); + sqlBuilder.append(" from " + tableName); + sqlBuilder.append(" where dr = 0 "); + sqlBuilder.append(" and "); + sqlBuilder.append(pkField, pk); + + Map result = (Map) new BaseDAO().executeQuery(sqlBuilder.toString(), new MapProcessor()); + + if (result == null || result.isEmpty()) { + result = new HashMap<>(); + } + + return result; + } + + private Map getMaterialInfo(String pkMaterial) throws BusinessException { + String sql = " select a.code, a.name, a.materialtype, a.materialspec, a.pk_measdoc, c.code unitcode, c.name unitname " + + "from bd_material a " + + "left join bd_materialconvert b on a.pk_material = b.pk_material " + + "left join bd_measdoc c on a.pk_measdoc = c.pk_measdoc " + + "where a.pk_material = '" + pkMaterial + "' "; + Map map = (Map) new BaseDAO().executeQuery(sql, new MapProcessor()); + return map; + } }