#
Junjie
2025-11-12 885633a6a4da38c530c033796fcd3dead72349c0
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
package com.zy.core.network.fake;
 
import com.alibaba.fastjson.JSON;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.core.model.CommandResponse;
import com.zy.core.model.command.StationCommand;
import com.zy.core.network.api.ZyStationConnectApi;
import com.zy.core.network.entity.ZyStationStatusEntity;
import java.util.Collections;
import java.util.List;
 
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
 
/**
 * 输送站假连接(模拟)
 */
public class ZyStationFakeConnect implements ZyStationConnectApi {
 
    private ZyStationStatusEntity status;
    private final DeviceConfig deviceConfig;
    private final ExecutorService executor = Executors.newSingleThreadExecutor();
 
    public ZyStationFakeConnect(DeviceConfig deviceConfig) {
        this.deviceConfig = deviceConfig;
        this.status = JSON.parseObject(deviceConfig.getFakeInitStatus(), ZyStationStatusEntity.class);
        if (this.status == null) {
            this.status = new ZyStationStatusEntity();
            this.status.setStationId(deviceConfig.getDeviceNo());
        }
    }
 
    @Override
    public boolean connect() {
        return true;
    }
 
    @Override
    public boolean disconnect() {
        return true;
    }
 
    @Override
    public List<ZyStationStatusEntity> getStatus() {
        return Collections.singletonList(status);
    }
 
    @Override
    public CommandResponse sendCommand(StationCommand command) {
        CommandResponse response = new CommandResponse(false);
        executor.submit(() -> handleCommand(command));
        response.setResult(true);
        return response;
    }
 
    private void handleCommand(StationCommand command) {
        // 简单的模拟:设置工作号和目标站,并模拟有物/可入/可出状态切换
        this.status.setTaskNo(command.getTaskNo());
        this.status.setTargetStaNo(command.getTargetStaNo());
 
        // 模拟到站过程
        this.status.setAutoing(true);
        this.status.setLoading(true);
        sleep(1000);
 
        // 模拟放下托盘
        this.status.setInEnable(true);
        this.status.setOutEnable(false);
        sleep(1000);
 
        // 完成任务,复位状态
        this.status.setLoading(false);
        this.status.setAutoing(false);
        this.status.setTaskNo(0);
        this.status.setInEnable(false);
        this.status.setOutEnable(true);
    }
 
    private void sleep(long ms) {
        try {
            Thread.sleep(ms);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}