vince
2025-03-06 88763f2ae21e9d3771ba744577edcc2d344802a6
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
package com.fzzy.protocol.fzzy.service;
 
import com.fzzy.api.Constant;
import com.fzzy.api.data.ApiCommonDevice;
import com.fzzy.api.data.GatewayDeviceProtocol;
import com.fzzy.gateway.api.GatewaySyncGranService;
import com.fzzy.gateway.data.BaseReqData;
import com.fzzy.gateway.data.BaseResp;
import com.fzzy.gateway.entity.GatewayDevice;
import com.fzzy.protocol.ProtocolUtils;
import com.fzzy.protocol.fzzy.builder.GrainCommandBuilder;
import com.fzzy.protocol.fzzy.cmd.BaseRemoteImpl;
import com.fzzy.protocol.fzzy.data.SendMessage;
import com.fzzy.protocol.fzzy.server.ServerUtils;
import com.ld.io.api.InvokeResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
 
/**
 * 风正致远控制柜协议
 */
@Slf4j
@Component
public class FzzyGatewayGrainService extends BaseRemoteImpl implements GatewaySyncGranService {
 
    @Override
    public String getGrainProtocol() {
        return GatewayDeviceProtocol.TCP_FZZY_V3.getCode();
    }
 
    @Override
    public BaseResp syncGrain(BaseReqData reqData) {
 
        BaseResp resp = new BaseResp();
 
        GatewayDevice device = reqData.getDevice();
 
        //获取连接中的设备信息
        ApiCommonDevice apiCommonDevice = Constant.getCommonDeviceCacheBySn(device.getDeviceSn());
        if (null == apiCommonDevice) {
            resp.setCode(500);
            resp.setMsg("系统未获取到下行连接设备信息,无法执行");
            log.error("----------------系统未获取到下行连接设备信息,无法执行---------"+device.toString());
            return resp;
        }
 
        if (Constant.YN_N.equals(apiCommonDevice.getStatus())) {
            resp.setCode(500);
            resp.setMsg("下行设备不在线---无法执行----" + device.getDeviceName());
            log.error("下行设备不在线---无法执行----" + device.getDeviceName());
            return resp;
        }
 
        device.setIp(apiCommonDevice.getIp());
        device.setPort(apiCommonDevice.getPort());
 
        reqData.setDevice(device);
 
 
        try {
 
            //Step 请求信息放入内存
            ProtocolUtils.addSyncReq2Map(device.getDepotIdSys(), reqData);
 
            // Step1 生成粮情信息
            SendMessage message = GrainCommandBuilder.getInstance().buildMessage(device,apiCommonDevice);
            // 发送命令
            InvokeResult result = send(device.getIp(), device.getPort(), message.getByteMsg());
 
            log.error("平台------>>>>控制柜:发送粮情检测命令-{}", message);
 
            // 封装返回信息
            if (!InvokeResult.SUCCESS.getCode().equals(result.getCode())) {
                log.error("平台------>>>>控制柜:发送粮情检测命令-失败{}", result.getMessage());
                resp.setCode(500);
                resp.setMsg("平台------>>>>控制柜:发送粮情检测命令-失败:" + result.getMessage());
            }
 
        } catch (Exception e) {
            log.error("粮情检测异常:{}", e);
            resp.setCode(500);
            resp.setMsg("平台------>>>>控制柜:发送粮情检测命令:" + e.getMessage());
            return resp;
        }
        return resp;
    }
 
    @Override
    public BaseResp syncGrainTh(BaseReqData reqData) {
        return new BaseResp();
    }
 
    @Override
    public BaseResp syncConf(BaseReqData reqData) {
        return new BaseResp();
    }
 
    @Override
    public BaseResp writeConf(BaseReqData reqData) {
        return new BaseResp();
    }
 
    @Override
    public BaseResp initCable(BaseReqData reqData) {
        return new BaseResp();
    }
 
 
    @Override
    public BaseResp disconnect(BaseReqData reqData) {
        return new BaseResp();
    }
 
    @Override
    public BaseResp transparent(BaseReqData reqData) {
        return new BaseResp();
    }
}