ic_现存量批量查询接口
This commit is contained in:
		
							parent
							
								
									aee3473bbd
								
							
						
					
					
						commit
						206adc4443
					
				| 
						 | 
					@ -0,0 +1,91 @@
 | 
				
			||||||
 | 
					package nccloud.api.impl.ic.onhand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import nc.bs.framework.common.NCLocator;
 | 
				
			||||||
 | 
					import nc.itf.ic.onhand.OnhandResService;
 | 
				
			||||||
 | 
					import nc.vo.ic.onhand.entity.OnhandDimVO;
 | 
				
			||||||
 | 
					import nc.vo.ic.onhand.entity.OnhandVO;
 | 
				
			||||||
 | 
					import nc.vo.pub.BusinessException;
 | 
				
			||||||
 | 
					import nc.vo.pubapp.pattern.exception.ExceptionUtils;
 | 
				
			||||||
 | 
					import nccloud.api.ic.onhand.IAPIOnhandQuery;
 | 
				
			||||||
 | 
					import nccloud.api.ic.onhand.OnhandDataSupplement;
 | 
				
			||||||
 | 
					import nccloud.openapi.ic.onhand.mapping.OnhandMapping;
 | 
				
			||||||
 | 
					import nccloud.openapi.scmpub.pub.TransferCodeToPKTool;
 | 
				
			||||||
 | 
					import nccloud.openapi.scmpub.pubitf.IJsonParamMapping;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 现存量查询操作实现类
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @version NCC1909
 | 
				
			||||||
 | 
					 * @Description:
 | 
				
			||||||
 | 
					 * @author: shijkb
 | 
				
			||||||
 | 
					 * @date: 2019年11月14日 上午9:55:49
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public class APIOnhandQueryIpml implements IAPIOnhandQuery {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    String[] requiredField = new String[]{
 | 
				
			||||||
 | 
					            "pk_org", "cmaterialoid"
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private IJsonParamMapping jsonParamMapping = new OnhandMapping();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public OnhandVO[] queryOnhandVOByDims(Map<String, Object> paramMap) throws BusinessException {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //必输项检查
 | 
				
			||||||
 | 
					        this.requiredFieldCheck(requiredField, paramMap);
 | 
				
			||||||
 | 
					        // 翻译
 | 
				
			||||||
 | 
					        paramMap = TransferCodeToPKTool.doTranslateFields(jsonParamMapping, paramMap);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        OnhandDataSupplement dataSupplement = new OnhandDataSupplement();
 | 
				
			||||||
 | 
					        OnhandDimVO onhandDimVO = new OnhandDimVO();
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            onhandDimVO = dataSupplement.process(paramMap);
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            // TODO Auto-generated catch block
 | 
				
			||||||
 | 
					            ExceptionUtils.marsh(e);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        OnhandVO[] onhandVOs = NCLocator.getInstance().lookup(OnhandResService.class)
 | 
				
			||||||
 | 
					                .queryOnhandVOByDims(new OnhandDimVO[]{onhandDimVO});
 | 
				
			||||||
 | 
					        return onhandVOs;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public OnhandVO[] queryOnhandVOByDims(List<Map<String, Object>> paramMapList) throws Exception {
 | 
				
			||||||
 | 
					        //必输项检查
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            List<OnhandDimVO> onhandDimVOS = new ArrayList<>();
 | 
				
			||||||
 | 
					            for (Map<String, Object> paramMap : paramMapList) {
 | 
				
			||||||
 | 
					                this.requiredFieldCheck(requiredField, paramMap);
 | 
				
			||||||
 | 
					                // 翻译
 | 
				
			||||||
 | 
					                paramMap = TransferCodeToPKTool.doTranslateFields(jsonParamMapping, paramMap);
 | 
				
			||||||
 | 
					                OnhandDataSupplement dataSupplement = new OnhandDataSupplement();
 | 
				
			||||||
 | 
					                OnhandDimVO onhandDimVO = new OnhandDimVO();
 | 
				
			||||||
 | 
					                onhandDimVO = dataSupplement.process(paramMap);
 | 
				
			||||||
 | 
					                onhandDimVOS.add(onhandDimVO);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            OnhandVO[] onhandVOs = NCLocator.getInstance().lookup(OnhandResService.class)
 | 
				
			||||||
 | 
					                    .queryOnhandVOByDims(onhandDimVOS.toArray(new OnhandDimVO[0]));
 | 
				
			||||||
 | 
					            return onhandVOs;
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            ExceptionUtils.marsh(e);
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //必输项校验
 | 
				
			||||||
 | 
					    private void requiredFieldCheck(String[] requiredField, Map<String, Object> paramMap) {
 | 
				
			||||||
 | 
					        for (String field : requiredField) {
 | 
				
			||||||
 | 
					            Object keyValue = paramMap.get(field);
 | 
				
			||||||
 | 
					            if (null == keyValue) {
 | 
				
			||||||
 | 
					                ExceptionUtils.wrappBusinessException("字段:" + field + "为必输项!");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,22 @@
 | 
				
			||||||
 | 
					package nccloud.api.ic.onhand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import nc.vo.ic.onhand.entity.OnhandVO;
 | 
				
			||||||
 | 
					import nc.vo.pub.BusinessException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 现存量查询操作接口
 | 
				
			||||||
 | 
					 * @Description:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author: shijkb
 | 
				
			||||||
 | 
					 * @date:   2019年11月8日 下午2:49:51
 | 
				
			||||||
 | 
					 * @version NCC1909
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					public interface IAPIOnhandQuery {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    OnhandVO[] queryOnhandVOByDims(Map<String, Object> paramMap) throws BusinessException;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    OnhandVO[] queryOnhandVOByDims(List<Map<String, Object>> paramMap)throws Exception;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,152 @@
 | 
				
			||||||
 | 
					package nccloud.openapi.ic.onhand;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.ws.rs.Consumes;
 | 
				
			||||||
 | 
					import javax.ws.rs.POST;
 | 
				
			||||||
 | 
					import javax.ws.rs.Path;
 | 
				
			||||||
 | 
					import javax.ws.rs.Produces;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.alibaba.fastjson.JSONArray;
 | 
				
			||||||
 | 
					import com.alibaba.fastjson.JSONObject;
 | 
				
			||||||
 | 
					import nc.bs.dao.BaseDAO;
 | 
				
			||||||
 | 
					import nc.bs.dao.DAOException;
 | 
				
			||||||
 | 
					import nc.impl.pubapp.pattern.database.SqlBuilderUtil;
 | 
				
			||||||
 | 
					import nc.vo.bd.material.MaterialVO;
 | 
				
			||||||
 | 
					import nc.vo.bd.stordoc.StordocVO;
 | 
				
			||||||
 | 
					import nc.vo.pub.BusinessException;
 | 
				
			||||||
 | 
					import nc.vo.pubapp.pattern.pub.SqlBuilder;
 | 
				
			||||||
 | 
					import org.json.JSONString;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import nc.bs.framework.common.NCLocator;
 | 
				
			||||||
 | 
					import nc.vo.ic.onhand.entity.OnhandVO;
 | 
				
			||||||
 | 
					import nc.vo.pub.lang.UFDouble;
 | 
				
			||||||
 | 
					import nc.ws.opm.pub.utils.result.APIErrCodeEnum;
 | 
				
			||||||
 | 
					import nccloud.api.ic.onhand.IAPIOnhandQuery;
 | 
				
			||||||
 | 
					import nccloud.api.rest.utils.ResultMessageUtil;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 现存量信息查询资源类
 | 
				
			||||||
 | 
					 * @Description:
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author: shijkb
 | 
				
			||||||
 | 
					 * @date:   2019年11月8日 下午2:42:47
 | 
				
			||||||
 | 
					 * @version NCC1909
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Path("ic/onhand")
 | 
				
			||||||
 | 
					public class OnhandResource {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 现存量查询
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @POST
 | 
				
			||||||
 | 
					    @Path("onhandQuery")
 | 
				
			||||||
 | 
					    @Consumes("application/json")
 | 
				
			||||||
 | 
					    @Produces("application/json")
 | 
				
			||||||
 | 
					    public JSONString onhandQuery(Map<String, Object> paramMap){
 | 
				
			||||||
 | 
					        if (paramMap == null) {
 | 
				
			||||||
 | 
					            return ResultMessageUtil.exceptionToJSON("传入参数错误,组织、单据日期条件必输", APIErrCodeEnum.BUSINESSEXCCODE.getCode());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            OnhandVO[] onhandVOs = NCLocator.getInstance().lookup(IAPIOnhandQuery.class)
 | 
				
			||||||
 | 
					                    .queryOnhandVOByDims(paramMap) ;
 | 
				
			||||||
 | 
					            //对数据进行整合组装,返回数量
 | 
				
			||||||
 | 
					            UFDouble onhandNum = UFDouble.ZERO_DBL;
 | 
				
			||||||
 | 
					            if(null != onhandVOs && onhandVOs.length > 0){
 | 
				
			||||||
 | 
					                for (OnhandVO onhandVO : onhandVOs) {
 | 
				
			||||||
 | 
					                    onhandNum = onhandNum.add(onhandVO.getNonhandnum());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            return ResultMessageUtil.toJSON(onhandNum, "现存量查询成功!");
 | 
				
			||||||
 | 
					        }catch(Exception e){
 | 
				
			||||||
 | 
					            return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 现存量查询
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @POST
 | 
				
			||||||
 | 
					    @Path("onhandsQuery")
 | 
				
			||||||
 | 
					    @Consumes("application/json")
 | 
				
			||||||
 | 
					    @Produces("application/json")
 | 
				
			||||||
 | 
					    public JSONString onhandsQuery(List<Map<String, Object>> paramMapList){
 | 
				
			||||||
 | 
					        if (paramMapList == null) {
 | 
				
			||||||
 | 
					            return ResultMessageUtil.exceptionToJSON("传入参数错误,组织、单据日期条件必输", APIErrCodeEnum.BUSINESSEXCCODE.getCode());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            OnhandVO[] onhandVOs = NCLocator.getInstance().lookup(IAPIOnhandQuery.class)
 | 
				
			||||||
 | 
					                    .queryOnhandVOByDims(paramMapList) ;
 | 
				
			||||||
 | 
					            //对数据进行整合组装,返回物料+仓库+数量
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if(null != onhandVOs && onhandVOs.length > 0){
 | 
				
			||||||
 | 
					                //提炼出onhandVOs里的物料和仓库
 | 
				
			||||||
 | 
					                Set<String> materialPkSet = Arrays.stream(onhandVOs)
 | 
				
			||||||
 | 
					                        .map(onhandVO -> onhandVO.getCmaterialvid())
 | 
				
			||||||
 | 
					                        .collect(Collectors.toSet());
 | 
				
			||||||
 | 
					                Set<String> warehousePkSet = Arrays.stream(onhandVOs)
 | 
				
			||||||
 | 
					                        .map(onhandVO -> onhandVO.getCwarehouseid())
 | 
				
			||||||
 | 
					                        .collect(Collectors.toSet());
 | 
				
			||||||
 | 
					                Map<String, String> materialPKCodeMap=queryPK2CodeMap("pk_material",materialPkSet,"bd_material");
 | 
				
			||||||
 | 
					                Map<String, String> 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()){
 | 
				
			||||||
 | 
					                    throw new BusinessException("queryOnhand end : warehousePKCodeMap is null");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                // 根据物料和仓库分组
 | 
				
			||||||
 | 
					                Map<String, List<OnhandVO>> groupedOnhand = Arrays.stream(onhandVOs)
 | 
				
			||||||
 | 
					                        .collect(Collectors.groupingBy(onhandVO -> onhandVO.getPk_org()+"_"+onhandVO.getCmaterialvid() + "_" + onhandVO.getCwarehouseid()));
 | 
				
			||||||
 | 
					                Set<String> keys = groupedOnhand.keySet();
 | 
				
			||||||
 | 
					                JSONArray reArray = new JSONArray();
 | 
				
			||||||
 | 
					                for (String dimkey : keys){
 | 
				
			||||||
 | 
					                    List<OnhandVO> 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){
 | 
				
			||||||
 | 
					                        onhandNum = onhandNum.add(onhandVO.getNonhandnum());
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    jsonObject.put("onhandnum",  onhandNum);
 | 
				
			||||||
 | 
					                    reArray.add(jsonObject);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return ResultMessageUtil.toJSON(reArray, "现存量查询成功!");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            }else{
 | 
				
			||||||
 | 
					                return ResultMessageUtil.toJSON(null, "现存量查询成功,无数据!");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }catch(Exception e){
 | 
				
			||||||
 | 
					            return ResultMessageUtil.exceptionToJSON(e);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Map<String, String> queryPK2CodeMap(String pkname, Set<String> 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]));
 | 
				
			||||||
 | 
					        List<Map<String, Object>> remain = (List<Map<String, Object>>) new BaseDAO().executeQuery(sql.toString(), new nc.jdbc.framework.processor.MapListProcessor());
 | 
				
			||||||
 | 
					        if (remain == null || remain.isEmpty()) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // 转换为 pk 和 code 的映射
 | 
				
			||||||
 | 
					        Map<String, String> pkCodeMap = new HashMap<>();
 | 
				
			||||||
 | 
					        for (Map<String, Object> row : remain) {
 | 
				
			||||||
 | 
					            if (row != null) {
 | 
				
			||||||
 | 
					                String pk = row.get(pkname) != null ? row.get(pkname).toString() : null;
 | 
				
			||||||
 | 
					                String code = row.get("code") != null ? row.get("code").toString() : null;
 | 
				
			||||||
 | 
					                if (pk != null && code != null) {
 | 
				
			||||||
 | 
					                    pkCodeMap.put(pk, code);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return pkCodeMap;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue