zhuo
2025-02-17 9733594dd881627b4c00665e6f9bfbf08c1cacec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package com.ruoyi.common.utils;
 
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.properties.IfsProperties;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
import java.util.List;
import java.util.Map;
 
/**
 * @Author zhuo
 * @Date 2024/9/29
 */
@Slf4j
@AllArgsConstructor
@Component
public class IfsApiUtils {
 
    private IfsProperties ifsProperties;
 
 
    /**
     * 查询采购订单未检验
     */
    private String getStock(String inAttr) {
        return ifsProperties.getCustorderPort() + "contract=" + ifsProperties.getContract() + "&contractKey=" + ifsProperties.getContractKeyGet() + "&procedureName=QUERY_POL_RECEIPT_STD&userId=lims_user&inAttr=" + inAttr;
    }
 
    public List<Map<String, Object>> getInventory(String inAttr) {
        String body = HttpRequest.get(getStock(inAttr)).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);
        }
    }
 
    /**
     * 登记采购检验结果STD
     */
    private String ProcurementResultsURL(String inAttr) {
        return ifsProperties.getCustorder() + "contract=" + ifsProperties.getContract() + "&contractKey=" + ifsProperties.getContractKeyGet() + "&procedureName=REGIST_INSPECTION_RESULTS_STD&userId=lims_user&inAttr=" + inAttr;
    }
 
    public Result getProcurementResults(String inAttr) {
        String body = HttpRequest.get(ProcurementResultsURL(inAttr)).execute().body();
        log.info("登记采购检验结果-->" + body);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Map map = objectMapper.readValue(body, Map.class);
            String successFlag = map.get("SuccessFlag").toString();
            if (Integer.valueOf(successFlag) == 1) {
                return Result.success(map);
            } else {
                return Result.fail(map.get("ErrorMsg").toString());
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return Result.fail(e.getMessage());
        }
    }
 
 
    /**
     * 检验后移库
     */
    private String getMoveReceiptApi(String inAttr) {
 
        return ifsProperties.getCustorder() + "contract=" + ifsProperties.getContract() + "&contractKey=" + ifsProperties.getContractKeyGet() + "&procedureName=MOVE_RECEIPT_STD&userId=lims_user&inAttr=" + inAttr;
    }
 
    /**
     * 原材料检验-检验后移库
     *
     * @param inAttr
     * @return
     */
    public Result moveReceipt(String inAttr) {
        String body = HttpRequest.get(getMoveReceiptApi(inAttr)).execute().body();
        log.info("检验后移库-->" + body);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Map map = objectMapper.readValue(body, Map.class);
            String successFlag = map.get("SuccessFlag").toString();
            if (Integer.valueOf(successFlag) == 1) {
                return Result.success(map);
            } else {
                return Result.fail(map.get("ErrorMsg").toString());
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return Result.fail(e.getMessage());
        }
    }
 
    /**
     * 采购接收更改批号
     */
    private String getMoveReceiptLotApi(String inAttr) {
 
        return ifsProperties.getCustorder() + "contract=" + ifsProperties.getContract() + "&contractKey=" + ifsProperties.getContractKeyGet() + "&procedureName=MODIFY_PURCH_RECEIPT_LOT_STD&userId=lims_user&inAttr=" + inAttr;
    }
 
    /**
     * 原材料检验-检验后移库
     *
     * @param inAttr
     * @return
     */
    public Result updateMoveReceiptLot(String inAttr) {
        String body = HttpRequest.get(getMoveReceiptLotApi(inAttr)).execute().body();
        log.info("修改采购订单批次号-->" + body);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Map map = objectMapper.readValue(body, Map.class);
            String successFlag = map.get("SuccessFlag").toString();
            if (Integer.valueOf(successFlag) == 1) {
                return Result.success(map);
            } else {
                return Result.fail(map.get("ErrorMsg").toString());
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return Result.fail(e.getMessage());
        }
    }
 
 
    /**
     * 查询库存数据
     */
    private String getIfsStockApi(String inAttr) {
 
        return ifsProperties.getCustorderPort() + "contract=" + ifsProperties.getContract() + "&contractKey=" + ifsProperties.getContractKeyGet() + "&procedureName=QUERY_INVENTORY_INFO_STD&userId=lims_user&inAttr=" + inAttr;
    }
 
    /**
     * 查询库存数据
     *
     * @param inAttr
     * @return
     */
    public Result getIfsStock(String inAttr) {
        JSONObject stockMap = new JSONObject();
        stockMap.put("procedureName", "QUERY_INVENTORY_INFO_STD");
        stockMap.put("contract", ifsProperties.getContract());
        stockMap.put("contractKey", ifsProperties.getContractKeyPost());
        stockMap.put("userId", "userId");
        stockMap.put("inAttr", inAttr);
        String body = HttpRequest.post(ifsProperties.getCustorderPort()).form(stockMap).execute().body();
        log.info("查询库存信息-->" + body);
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            Map map = objectMapper.readValue(body, Map.class);
            String successFlag = map.get("SuccessFlag").toString();
            if (Integer.valueOf(successFlag) == 1) {
                return Result.success(map);
            } else {
                return Result.fail(map.get("ErrorMsg").toString());
            }
        } catch (JsonProcessingException e) {
            e.printStackTrace();
            return Result.fail(e.getMessage());
        }
    }
}