zouyu
6 天以前 e50a43bb067adff10cd1dcc81349b1aafdfda882
ruoyi-common/src/main/java/com/ruoyi/common/utils/api/IfsApiUtils.java
@@ -6,13 +6,15 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.config.ifs.IfsConfig;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.config.IfsProperties;
import com.ruoyi.common.config.ifs.IfsProperties;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -25,27 +27,35 @@
@Component
public class IfsApiUtils {
    private IfsProperties ifsProperties;
    private IfsConfig ifsConfig;
    public IfsProperties getPropByContract(String contract){
        return ifsConfig.getProps().stream().filter(f-> StringUtils.equals(contract,f.getContract())).findFirst().orElse(new IfsProperties());
    }
    /**
     * 查询采购订单未检验
     */
    public List<Map<String, Object>> getInventory(String inAttr) {
        String procedureName = "QUERY_POL_RECEIPT_STD";
        JSONObject stockMap = getJsonObject(procedureName, inAttr);
        String body = HttpRequest.post(ifsProperties.getCustorderPort()).form(stockMap).execute().body();
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Map map = objectMapper.readValue(body, Map.class);
            List<Map<String, Object>> maps = objectMapper.readValue(JSONUtil.toJsonStr(map.get("LIST_INFO")), new TypeReference<List<Map<String, Object>>>() {
            });
            log.info("获取采购订单-->>" + maps);
            return maps;
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    public List<Map<String, Object>> getInventory(Map<String,Object> inAttrMap) {
        List<Map<String, Object>> maps = new ArrayList<>();
        ifsConfig.getProps().forEach(ifsProp->{
            String procedureName = "QUERY_POL_RECEIPT_STD";
            inAttrMap.put("LOCATION_NO",ifsProp.getTobeInspectedLocation());
            String inAttr = JSONUtil.toJsonStr(inAttrMap);
            JSONObject stockMap = getJsonObject(procedureName, inAttr,ifsProp.getContract(),ifsProp.getContractKeyPost());
            String body = HttpRequest.post(ifsProp.getCustorderPort()).form(stockMap).execute().body();
            ObjectMapper objectMapper = new ObjectMapper();
            try {
                Map map = objectMapper.readValue(body, Map.class);
                maps.addAll(objectMapper.readValue(JSONUtil.toJsonStr(map.get("LIST_INFO")), new TypeReference<List<Map<String, Object>>>() {
                }));
                log.info("获取采购订单-->>" + maps);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        });
        return maps;
    }
@@ -53,8 +63,8 @@
    /**
     * 登记采购检验结果STD
     */
    public Result getProcurementResults(String inAttr) {
        return getResult("REGIST_INSPECTION_RESULTS_STD", inAttr, ifsProperties.getCustorder(), "登记采购检验结果-->");
    public Result getProcurementResults(String contract,String inAttr) {
        return getResult(contract,"REGIST_INSPECTION_RESULTS_STD", inAttr, "GET", "登记采购检验结果-->");
    }
@@ -64,8 +74,8 @@
     * @param inAttr
     * @return
     */
    public Result moveReceipt(String inAttr) {
        return getResult("MOVE_RECEIPT_STD", inAttr, ifsProperties.getCustorder(), "检验后移库-->");
    public Result moveReceipt(String contract,String inAttr) {
        return getResult(contract,"MOVE_RECEIPT_STD", inAttr, "GET", "检验后移库-->");
    }
@@ -75,8 +85,8 @@
     * @param inAttr
     * @return
     */
    public Result updateMoveReceiptLot(String inAttr) {
        return getResult("MODIFY_PURCH_RECEIPT_LOT_STD", inAttr, ifsProperties.getCustorder(), "修改采购订单批次号-->");
    public Result updateMoveReceiptLot(String contract,String inAttr) {
        return getResult(contract,"MODIFY_PURCH_RECEIPT_LOT_STD", inAttr, "GET", "修改采购订单批次号-->");
    }
@@ -87,8 +97,8 @@
     * @param inAttr
     * @return
     */
    public Result getIfsStock(String inAttr) {
        return getResult("QUERY_INVENTORY_INFO_STD", inAttr, ifsProperties.getCustorderPort(), "查询库存信息-->");
    public Result getIfsStock(String contract,String inAttr) {
        return getResult(contract,"QUERY_INVENTORY_INFO_STD", inAttr, "POST", "查询库存信息-->");
    }
    /**
@@ -97,25 +107,28 @@
     * @param inAttr
     * @return
     */
    public Result importPartLotAttr(String inAttr) {
        return getResult("IMPORT_PART_LOT_ATTR_STD", inAttr, ifsProperties.getCustorder(), "库存物料批次属性新增修改接口-->");
    public Result importPartLotAttr(String contract,String inAttr) {
        return getResult(contract,"IMPORT_PART_LOT_ATTR_STD", inAttr, "GET", "库存物料批次属性新增修改接口-->");
    }
    /**
     * 通用接口
     * @param contract IFS域
     * @param procedureName 方法名
     * @param inAttr  传参
     * @param url 地址
     * @param urlType 请求类型(GET/POST)
     * @param image 消息
     * @return
     */
    private Result<?> getResult(String procedureName, String inAttr, String url, String image) {
    private Result<?> getResult(String contract,String procedureName, String inAttr, String urlType, String image) {
        IfsProperties ifsProperties = getPropByContract(contract);
        JSONObject stockMap = new JSONObject();
        stockMap.put("procedureName", procedureName);
        stockMap.put("contract", ifsProperties.getContract());
        stockMap.put("contractKey", ifsProperties.getContractKeyPost());
        stockMap.put("userId", "lims_user");
        stockMap.put("inAttr", inAttr);
        String url = StringUtils.equals("GET",urlType)?ifsProperties.getCustorder():ifsProperties.getCustorderPort();
        String body = HttpRequest.post(url).form(stockMap).execute().body();
        log.info(image + body);
        ObjectMapper objectMapper = new ObjectMapper();
@@ -139,11 +152,11 @@
     * @param inAttr             请求参数
     * @return
     */
    private JSONObject getJsonObject(String procedureName, String inAttr) {
    private JSONObject getJsonObject(String procedureName, String inAttr,String contract,String contractKeyPost) {
        JSONObject stockMap = new JSONObject();
        stockMap.put("procedureName", procedureName);
        stockMap.put("contract", ifsProperties.getContract());
        stockMap.put("contractKey", ifsProperties.getContractKeyPost());
        stockMap.put("contract", contract);
        stockMap.put("contractKey", contractKeyPost);
        stockMap.put("userId", "lims_user");
        stockMap.put("inAttr", inAttr);
        return stockMap;