严智鑫
2025-11-13 945bc394f40d8af1072a53da9a94f24207124e6d
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
package com.northglass.service.message;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import com.northglass.constants.FunctionNumber;
import com.northglass.constants.FunctionNumber.CountMachineFunctionNumber;
import com.northglass.constants.StateConstants.ConnectState;
import com.northglass.constants.StateConstants.CountMachineTaskState;
import com.northglass.constants.StateConstants.GlassState;
import com.northglass.constants.StateConstants.ShelfTaskState;
import com.northglass.entity.CountMachine;
import com.northglass.entity.CountMachineTask;
import com.northglass.entity.Glass;
import com.northglass.entity.GlassOrder;
import com.northglass.entity.RawPackageTxt;
import com.northglass.entity.ShelfStatu;
import com.northglass.entity.ShelfTask;
import com.northglass.entity.TransferMachineTask;
import com.northglass.listener.GMMSPrinter;
import com.northglass.repository.CountMachineTaskDao;
import com.northglass.repository.GlassDao;
import com.northglass.repository.GlassOrderDao;
import com.northglass.repository.ManufactureBatchDao;
import com.northglass.repository.RawPackageTxtDao;
import com.northglass.repository.ShelfStatuDao;
import com.northglass.service.countmachine.CountMachineService;
import com.northglass.util.HexUtil;
 
@Component
@Transactional
public class CountMachineMessageProcessor extends AbstractMessageProcessor {
 
    // 请求信号
    private static final int TASK_ASK_START = 18;
    private static final int TASK_ASK_END = 21;
    // 请求ID
    private static final int TASK_ASK_TD_START = 22;
    private static final int TASK_ASK_ID_END = 25;
 
    // 任务汇报字
    private static final int TASK_FINISH_PLC_START = 38;
    private static final int TASK_FINISH_PLC_END = 41;
 
    // 任务汇报ID
    private static final int TASK_FINISH_PLC_ID_START = 42;
    private static final int TASK_FINISH_PLC_ID_END = 45;
    
    // 手工任务汇报
    private static final int PEOPLE_TASK_FINISH_PLC_ID_START = 46;
    private static final int PEOPLE_TASK_FINISH_PLC_ID_END = 49;
 
    // 任务发送字
    private static final int TASK_MES_START = 58;
    private static final int TASK_MES_END = 61;
 
    // 任务确认字
    private static final int TASK_SURE_START = 118;
    private static final int TASK_SURE_END = 121;
    
    // 手工任务确认字
    private static final int PEOPLE_TASK_SURE_START = 126;
    private static final int PEOPLE_TASK_SURE_END = 129;
 
    // 任务报警字
    private static final int TASK_WARN_START = 138;
    private static final int TASK_WARN_END = 141;
 
    @Autowired
    private CountMachineService countMachineService;
 
    @Autowired
    private CountMachineTaskDao countMachineTaskDao;
    
    @Autowired
    private RawPackageTxtDao rawPackageTxtDao;
    
    @Autowired
    private GlassOrderDao glassOrderDao;
    
    @Autowired
    private GlassDao glassDao;
 
    @Autowired
    private ShelfStatuDao shelfStatuDao;
 
    private static final Logger LOGGER = LoggerFactory.getLogger(CountMachineMessageProcessor.class);
 
    public String generateReturnMessage(String sendMessageHex, CountMachine countMachine) {
        // 请求信号
        LOGGER.debug("收到下片机信息:" + sendMessageHex);
        if (sendMessageHex.length() == 24) {
            String string = sendMessageHex.substring(8, 16);
            if (string.equals("00060110")) {
                LOGGER.debug("消息发送成功!");
                return "";
            } else {
                LOGGER.debug("消息发送失败!");
                return "";
            }
        } else if (sendMessageHex.length() == 198) {
            try {
                
                ShelfStatu statu=shelfStatuDao.findByMachine("count");
                String message=sendMessageHex.substring(18);
                statu.setMessage(message);
                statu.setSetTime(new Date());
                String result[]=ResultTexts(message);
//                String Length=result[10];     //长
//                String Width=result[10];      //宽        
//                String Thickness=result[10];  //厚
//                RawPackageTxt rawPackageTxt=rawPackageTxtDao.findAcceptedByGroup("1");
//                String Begin=statu.getPoint();      //开始字
//                //下发任务
//                if("1".equals(Begin)){
//                        //长+宽+厚+空空+开始+结束
//                        String data="";
//                        data+=HexUtil.intTo2ByteHex(new Double(rawPackageTxt.getWidth()).intValue());
//                        data+=HexUtil.intTo2ByteHex(new Double(rawPackageTxt.getHeight()).intValue());
//                        data+=HexUtil.intTo2ByteHex(new Double(rawPackageTxt.getThiness()).intValue());
//                        data+="0000"+"0000";
//                        data+="0001";
//                        statu.setPoint("3");
//                        shelfStatuDao.save(statu);
//                        return message(data,"0000");
//                }else if("2".equals(Begin)){
//                    String data="0000"+"0000"+"0000"+"0000"+"0000"+"0000"+"0001";
//                    return message(data,"0000");
//                }
            } catch (Exception e) {
                System.out.println("请检查CountMachineMessageProcessor.generateReturnMessage");
            }
            
        }
        return "";
    }
    //得到所有的45个字
    private String[] ResultTexts(String Str) {
        String []InfoTex =new String[45];
        Str=Str.substring(18);
        for(int i=0;i<45;i++){
            InfoTex[i]=Str.substring(0,4);
            Str=Str.substring(4);
        }
        return InfoTex;
    }
    private String message(String senddate, String address) {
        String Herd = "0010" + address;
        int length = senddate.length() / 4;
        String dates = Herd + HexUtil.intTo2ByteHex(length) + HexUtil.intTo1ByteHex(length * 2) + senddate;
        int lengths = dates.length() / 2;
        String date = "00000000" + HexUtil.intTo2ByteHex(lengths) + dates;
        LOGGER.debug("发送信息内容:" + date);
        return date;
    }
 
}