自动化立体仓库 - WMS系统
1
zhang
2025-07-09 57c93e991d6a052f9f8467ba702b809f69126ebc
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package com.zy.asrs.task.handler;
 
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.task.core.ReturnT;
import com.zy.common.constant.OpenApiAddressConstant;
import com.zy.common.utils.HttpHandler;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @author pang.jiabao
 * @description 冠鸿龙南定时任务具体实现
 * @createDate 2024/7/10 9:28
 */
@Slf4j
@Service
public class GhlnHandler {
 
    @Resource
    private WrkMastService wrkMastService;
 
    @Resource
    private BasDevpService basDevpService;
 
    @Resource
    private WrkDetlService wrkDetlService;
 
    @Autowired
    private ApiLogService apiLogService;
 
    @Autowired
    private LoginAuthHandler loginAuthHandler;
 
    @Resource
    private MatService matService;
 
    @Autowired
    private LocDetlService locDetlService;
 
    @Autowired
    private ConfigService configService;
 
    /**
     * 调用金蝶同步物料接口,增量同步每小时产生的新物料
     */
    public void syncMat() {
 
        //登录金蝶
        ReturnT<String> start = loginAuthHandler.start();
 
        //条件和需要获得的结果拼接
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("FormId", "BD_MATERIAL");
        jsonObject.put("OrderString", "");
        jsonObject.put("TopRowCount", 0);
        jsonObject.put("Limit", 3000);
        jsonObject.put("StartRow", "0");
        jsonObject.put("SubSystemId", "");
        // 获取当前时间
        LocalDateTime currentDateTime = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        // 获取当前时间的前一小时整点时间
        LocalDateTime oneHourAgo = currentDateTime.minusHours(1).withMinute(0).withSecond(0).withNano(0);
        jsonObject.put("FilterString", "FCreateDate <= '2022-08-23 13:37:00'");
//        jsonObject.put("FilterString", "FCreateDate >= '"+oneHourAgo.format(formatter)+"' and FUseOrgId .FNumber='10004'");
//        jsonObject.put("FilterString","FNumber = '0101010003'");
        jsonObject.put("FieldKeys", "FNumber,FName,FCreateDate,FTypeID");
 
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("data", jsonObject);
        String add = jsonObject1.toJSONString();
 
        String response = "";
        boolean success = false;
        String url = "http://192.168.16.7";
        String address = "K3CLOUD/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc";
        try {
            //获取Cookie值
            HashMap<String, Object> headers = new HashMap<>();
            headers.put("Cookie", start.getContent());
            response = new HttpHandler.Builder()
                    .setHeaders(headers)
                    .setUri(url)
                    .setPath(address)
                    .setJson(add)
                    .build()
                    .doPost();
            String[] tempstr;
            if (!"[]".equals(response)) {
                String[] returnstr = response.split("],");
                int count = 0;
                log.info("--------调用金蝶同步物料信息开始--------");
                for (int i = 0; i < returnstr.length; i++) {
                    Mat mat = new Mat();
                    tempstr = returnstr[i].split(",");
                    if (i == 0) {
                        mat.setMatnr(tempstr[0].substring(2));  //物料编码
                    } else {
                        mat.setMatnr(tempstr[0].substring(1));  //物料编码
                    }
                    mat.setMaktx(tempstr[1]); //  物料名称
                    mat.setTagId(Long.valueOf(tempstr[3].substring(0, 1))); // 物料分类
                    mat.setCreateTime(new Date());//商品创建时间
                    mat.setUpdateTime(new Date());
                    mat.setStatus(1);
                    try {
                        matService.insert(mat);
                        count++;
                    } catch (Exception e) {
                        log.error("金蝶同步物料异常:{}", mat);
                    }
                }
                log.info("----调用金蝶同步物料信息结果:总{},成{}--------", returnstr.length, count);
                success = true;
            }
        } catch (Exception e) {
            log.error("fail", e);
        } finally {
            try {
                // 保存接口日志
                apiLogService.save(
                        "请求金蝶同步物料信息",
                        url + address,
                        null,
                        "127.0.0.1",
                        add,
                        response,
                        success
                );
            } catch (Exception e) {
                log.error("", e);
            }
        }
    }
 
    /**
     * 到达出库口,呼叫agv
     */
    public void OutboundCallAGV() {
        BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().setSqlSelect("wrk_no as wrkNo", "loading", "autoing", "out_enable as outEnable").eq("dev_no", 210));
        if (basDevp.getWrkNo() > 6000 && basDevp.getWrkNo() <= 9000 && basDevp.getLoading().equals("Y") && basDevp.getAutoing().equals("Y")) { // 出库工作档
            WrkMast wrkMast = wrkMastService.selectById(basDevp.getWrkNo());
            if (wrkMast.getWhsType() == null) {
                WrkDetl wrkDetl = wrkDetlService.selectOne(new EntityWrapper<WrkDetl>().eq("wrk_no", basDevp.getWrkNo()));
                // 调用结果
                boolean success = false;
                // 构造请求头
                Map<String, Object> headers = new HashMap<>();
                headers.put("Content-Type", "application/json;charset=UTF-8");
                // 构造请求体
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("matnr", wrkDetl.getMatnr()); // 物料编码
                jsonObject.put("model", wrkDetl.getModel()); // 型号
                jsonObject.put("batch", wrkDetl.getBatch()); // 批次
                jsonObject.put("specs", wrkDetl.getSpecs()); // 膜类型
                jsonObject.put("manuDate", wrkDetl.getManuDate()); // 生产日期
                jsonObject.put("length", wrkDetl.getLength() + ""); // 长
                jsonObject.put("weight", wrkDetl.getWeight() + ""); // 宽
                jsonObject.put("volume", wrkDetl.getVolume() + ""); // 面积
                String body = jsonObject.toString();
                String response = "";
                try {
                    response = new HttpHandler.Builder()
                            .setUri(OpenApiAddressConstant.AGV_IP)
                            .setPath(OpenApiAddressConstant.CALL_AGV_URL)
                            .setHeaders(headers)
                            .setJson(body)
                            .build()
                            .doPost();
                    if (!Cools.isEmpty(response)) {
                        JSONObject jsonObject1 = JSONObject.parseObject(response);
                        if ((Integer) jsonObject1.get("code") == 200) {
                            success = true;
                            wrkMast.setWhsType(1);
                            wrkMastService.updateById(wrkMast);
                        }
                    } else {
                        log.error("出库呼叫agv接口异常接口失败!!!url:{};request:{};response:{}", OpenApiAddressConstant.AGV_IP + OpenApiAddressConstant.CALL_AGV_URL, body, response);
                    }
                } catch (Exception e) {
                    log.error("出库呼叫agv接口异常:{}", e.getMessage());
                } finally {
                    try {
                        // 保存接口日志
                        apiLogService.save(
                                "出库请求agv",
                                OpenApiAddressConstant.AGV_IP + OpenApiAddressConstant.CALL_AGV_URL,
                                null,
                                "127.0.0.1",
                                jsonObject.toJSONString(),
                                response,
                                success
                        );
                    } catch (Exception e) {
                        log.error("出库呼叫agv接口日志异常", e);
                    }
                }
            }
        }
    }
 
    public void start() {
        long time = System.currentTimeMillis();
        Config config = configService.selectConfigByCode("EXPIREDDAY");
        long day = 180;
        if (config != null) {
            day = Long.parseLong(config.getValue());
        }
        Config config2 = configService.selectConfigByCode("durationOfFilmRollControl");
        long day2 = Long.parseLong(config2.getValue());
        Page<LocDetl> frozen = locDetlService.selectPage(new Page<>(0, 10000), new EntityWrapper<LocDetl>().isNull("sku").orderBy("manu_date"));
        for (LocDetl locDetl : frozen.getRecords()) {
            String manuDate = locDetl.getManuDate();
            Date yyyyMMdd = DateUtils.convert(manuDate, "yyyyMMdd");
            if ((time - yyyyMMdd.getTime()) > day * 24 * 60 * 60 * 1000) {
                locDetl.setFrozen(1);
                locDetlService.update(locDetl, new EntityWrapper<LocDetl>().eq("loc_no", locDetl.getLocNo()).eq("matnr", locDetl.getMatnr()).eq("batch", locDetl.getBatch()));
            } else if ((time - yyyyMMdd.getTime()) > day2 * 24 * 60 * 60 * 1000) {
                locDetl.setFrozen(2);
                locDetlService.update(locDetl, new EntityWrapper<LocDetl>().eq("loc_no", locDetl.getLocNo()).eq("matnr", locDetl.getMatnr()).eq("batch", locDetl.getBatch()));
            }
        }
    }
 
    @PostConstruct
    public void start2() {
        long time = System.currentTimeMillis();
        Config config = configService.selectConfigByCode("EXPIREDDAY");
        long day = 180;
        if (config != null) {
            day = Long.parseLong(config.getValue());
        }
        Config config2 = configService.selectConfigByCode("durationOfFilmRollControl");
        long day2 = Long.parseLong(config2.getValue());
        Page<LocDetl> frozen = locDetlService.selectPage(new Page<>(0, 10000), new EntityWrapper<LocDetl>().isNull("sku").orderBy("manu_date"));
        for (LocDetl locDetl : frozen.getRecords()) {
            String manuDate = locDetl.getManuDate();
            Date yyyyMMdd = DateUtils.convert(manuDate, "yyyyMMdd");
            if ((time - yyyyMMdd.getTime()) > day * 24 * 60 * 60 * 1000) {
                locDetl.setFrozen(1);
                locDetlService.update(locDetl, new EntityWrapper<LocDetl>().eq("loc_no", locDetl.getLocNo()).eq("matnr", locDetl.getMatnr()).eq("batch", locDetl.getBatch()));
            } else if ((time - yyyyMMdd.getTime()) > day2 * 24 * 60 * 60 * 1000) {
                locDetl.setFrozen(2);
                locDetlService.update(locDetl, new EntityWrapper<LocDetl>().eq("loc_no", locDetl.getLocNo()).eq("matnr", locDetl.getMatnr()).eq("batch", locDetl.getBatch()));
            }
        }
    }
}