Commit 440ab2e414f4a6455153088b3b7195a68883a377
1 parent
96601d7c
Exists in
master
and in
1 other branch
自启监听
Showing
5 changed files
with
542 additions
and
526 deletions
Show diff stats
cloud/weigeng/src/main/java/com/sincere/weigeng/WatchServer.java
0 → 100644
| ... | ... | @@ -0,0 +1,530 @@ |
| 1 | +package com.sincere.weigeng; | |
| 2 | + | |
| 3 | + | |
| 4 | +import com.sincere.common.dto.smartCampus.UserDto; | |
| 5 | +import com.sincere.common.dto.xiaoan.CheckInDto; | |
| 6 | +import com.sincere.common.dto.xiaoan.CheckOutDto; | |
| 7 | +import com.sincere.common.dto.xiaoan.PassFailDto; | |
| 8 | +import com.sincere.common.dto.xiaoan.SendMessageDto; | |
| 9 | +import com.sincere.common.util.DateUtils; | |
| 10 | +import com.sincere.weigeng.feign.SmFeign; | |
| 11 | +import com.sincere.weigeng.feign.XaFeign; | |
| 12 | +import com.sincere.weigeng.logs.LogName; | |
| 13 | +import com.sincere.weigeng.logs.LoggerUtils; | |
| 14 | +import com.sincere.weigeng.utils.WGUtils; | |
| 15 | +import com.sincere.weigeng.utils.WatchingShortHandler; | |
| 16 | +import com.sincere.weigeng.utils.WgUdpCommShort; | |
| 17 | +import org.apache.commons.lang3.StringUtils; | |
| 18 | +import org.apache.mina.core.session.IoSession; | |
| 19 | +import org.apache.mina.transport.socket.DatagramSessionConfig; | |
| 20 | +import org.apache.mina.transport.socket.nio.NioDatagramAcceptor; | |
| 21 | +import org.slf4j.Logger; | |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 23 | +import org.springframework.boot.ApplicationArguments; | |
| 24 | +import org.springframework.boot.ApplicationRunner; | |
| 25 | +import org.springframework.stereotype.Component; | |
| 26 | + | |
| 27 | +import java.io.IOException; | |
| 28 | +import java.net.InetSocketAddress; | |
| 29 | +import java.util.*; | |
| 30 | +import java.util.concurrent.ConcurrentHashMap; | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * @author chen | |
| 34 | + * @version 1.0 | |
| 35 | + * @date 2019/10/12 0012 16:57 | |
| 36 | + */ | |
| 37 | + | |
| 38 | +@Component | |
| 39 | +public class WatchServer implements ApplicationRunner { | |
| 40 | + | |
| 41 | + private static final Logger Log_orderSuccess = LoggerUtils.Logger(LogName.orderSuccess); | |
| 42 | + private static final Logger Log_orderFail = LoggerUtils.Logger(LogName.orderFail); | |
| 43 | + private static final Logger Log_kaoInfo = LoggerUtils.Logger(LogName.kaoInfo); | |
| 44 | + private static final Logger Log_heartBeat = LoggerUtils.Logger(LogName.heartBeat); | |
| 45 | + private static final Logger Log_error = LoggerUtils.Logger(LogName.error); | |
| 46 | + | |
| 47 | + private static List<Long> snoList = new ArrayList<>(); | |
| 48 | + private static List<Long> indexList = new ArrayList<>(); | |
| 49 | + private static WatchingShortHandler watchingShortHandler ; | |
| 50 | + private static Queue<byte[]> queue = new LinkedList<>(); | |
| 51 | + private static Map<Long , IoSession> sessionMap = new ConcurrentHashMap<>(); | |
| 52 | + | |
| 53 | + @Autowired | |
| 54 | + SmFeign smFeign; | |
| 55 | + | |
| 56 | + @Autowired | |
| 57 | + XaFeign xaFeign; | |
| 58 | + | |
| 59 | + private static String ip = "172.16.3.175"; | |
| 60 | + private static int port = 1200; | |
| 61 | + | |
| 62 | + @Override | |
| 63 | + public void run(ApplicationArguments args) { | |
| 64 | + //启动服务监听 | |
| 65 | + this.WatchingServerRunning(ip,port); | |
| 66 | + } | |
| 67 | + | |
| 68 | + // 进入服务器监控状态 | |
| 69 | + public int WatchingServerRunning(String watchServerIP,int watchServerPort) { | |
| 70 | + watchingShortHandler = new WatchingShortHandler(queue,sessionMap); | |
| 71 | + // 创建UDP数据包NIO | |
| 72 | + NioDatagramAcceptor acceptor = new NioDatagramAcceptor(); | |
| 73 | + // NIO设置底层IOHandler | |
| 74 | + acceptor.setHandler(watchingShortHandler); | |
| 75 | + | |
| 76 | + // 设置是否重用地址? 也就是每个发过来的udp信息都是一个地址? | |
| 77 | + DatagramSessionConfig dcfg = acceptor.getSessionConfig(); | |
| 78 | + dcfg.setReuseAddress(false); | |
| 79 | + // 绑定端口地址 | |
| 80 | + try { | |
| 81 | + acceptor.bind(new InetSocketAddress(watchServerIP, watchServerPort)); | |
| 82 | + } catch (IOException e) { | |
| 83 | + Log_orderSuccess.info("绑定接收服务器失败...."); | |
| 84 | + e.printStackTrace(); | |
| 85 | + return 0; | |
| 86 | + } | |
| 87 | + Log_orderSuccess.info("绑定接收服务器成功...."); | |
| 88 | + long recordIndex = 0; | |
| 89 | + while(true) { | |
| 90 | + if (!queue.isEmpty()) { | |
| 91 | + byte[] recvBuff; | |
| 92 | + synchronized (queue) { | |
| 93 | + recvBuff= queue.poll(); | |
| 94 | + } | |
| 95 | + if (recvBuff[1]== 0x20) { | |
| 96 | + long sn = WgUdpCommShort.getLongByByte(recvBuff, 4, 4); | |
| 97 | + smFeign.updateLinkTime(sn+""); | |
| 98 | + Log_heartBeat.info("设备"+sn); | |
| 99 | + boolean isExist = true ; | |
| 100 | + long recordIndexGet = WgUdpCommShort.getLongByByte(recvBuff, 8, 4); | |
| 101 | + if(snoList.indexOf(sn) >= 0){ | |
| 102 | + int number = snoList.indexOf(sn); | |
| 103 | + recordIndex = indexList.get(number); | |
| 104 | + indexList.set(number,recordIndexGet); | |
| 105 | + }else { | |
| 106 | + snoList.add(sn); | |
| 107 | + recordIndex = 0 ; | |
| 108 | + indexList.add(recordIndexGet); | |
| 109 | + System.out.println("设备"+sn+"上线"); | |
| 110 | + isExist = false ; | |
| 111 | + } | |
| 112 | + if(isExist){ | |
| 113 | + if (recordIndex < recordIndexGet || (recordIndexGet - recordIndex) < -5) { | |
| 114 | + watching(recvBuff); | |
| 115 | + } | |
| 116 | + } | |
| 117 | + }else { | |
| 118 | + push(recvBuff); | |
| 119 | + } | |
| 120 | + } else { | |
| 121 | + long times = 100; | |
| 122 | + try { | |
| 123 | + Thread.sleep(times); | |
| 124 | + } catch (InterruptedException e) { | |
| 125 | + e.printStackTrace(); | |
| 126 | + } | |
| 127 | + } | |
| 128 | + } | |
| 129 | + } | |
| 130 | + | |
| 131 | + private void watching(byte[] recv){ | |
| 132 | + long res = 0; | |
| 133 | + //8-11 记录的索引号 | |
| 134 | + //(=0表示没有记录) 4 0x00000000 | |
| 135 | + int recordIndex = 0; | |
| 136 | + recordIndex = WGUtils.byteToInt(recv, 8, 4); | |
| 137 | + //12 记录类型********************************************** | |
| 138 | + //0=无记录 | |
| 139 | + //1=刷卡记录 | |
| 140 | + //2=门磁,按钮, 设备启动, 远程开门记录 | |
| 141 | + //3=报警记录 1 | |
| 142 | + //0xFF=表示指定索引位的记录已被覆盖掉了. 请使用索引0, 取回最早一条记录的索引值 | |
| 143 | + int recordType = recv[12]; | |
| 144 | + | |
| 145 | + //13 有效性(0 表示不通过, 1表示通过) 1 | |
| 146 | + int recordValid = recv[13]; | |
| 147 | + | |
| 148 | + //14 门号(1,2,3,4) 1 业务需要-->1出2进 | |
| 149 | + int recordDoorNO = recv[14]; | |
| 150 | + | |
| 151 | + //15 进门/出门(1表示进门, 2表示出门) 1 0x01 | |
| 152 | + //int recordInOrOut = recv[15]; | |
| 153 | + | |
| 154 | + //16-19 卡号(类型是刷卡记录时) | |
| 155 | + //或编号(其他类型记录) 4 | |
| 156 | + String cardNo = WGUtils.getCardNo(recv, 16, 4); | |
| 157 | + | |
| 158 | + //20-26 刷卡时间: | |
| 159 | + //年月日时分秒 (采用BCD码)见设置时间部分的说明 | |
| 160 | + String recordTime = "2000-01-01 00:00:00"; | |
| 161 | + recordTime = String.format("%02X%02X-%02X-%02X %02X:%02X:%02X", | |
| 162 | + recv[20], recv[21], recv[22], recv[23], recv[24], recv[25], recv[26]); | |
| 163 | + //2012.12.11 10:49:59 7 | |
| 164 | + //27 记录原因代码(可以查 “刷卡记录说明.xls”文件的ReasonNO) | |
| 165 | + //处理复杂信息才用 1 | |
| 166 | + int reason = recv[27]; | |
| 167 | + if (recordType == 0) { | |
| 168 | + Log_orderSuccess.info(String.format("索引位={0} 无记录", recordIndex)); | |
| 169 | + }else if (recordType == 0xff) { | |
| 170 | + Log_orderSuccess.info("指定索引位的记录已被覆盖掉了,请使用索引0, 取回最早一条记录的索引值"); | |
| 171 | + } else if (recordType == 1) { | |
| 172 | + long sno = 0; | |
| 173 | + sno = WgUdpCommShort.getLongByByte(recv, 4, 4);//解析设备号 | |
| 174 | + String msg = "索引位=" + recordIndex | |
| 175 | + + ",卡号=" + cardNo | |
| 176 | + +"进出=" + (recordDoorNO == 1 ? "出门" : "进门") | |
| 177 | + + ",有效=" + (recordValid == 1 ? "通过" : "禁止") | |
| 178 | + + ",时间=" + recordTime | |
| 179 | + + ",描述=" + WGUtils.getReasonDetailChinese(reason) + ""; | |
| 180 | + Log_orderSuccess.info("控制器:" + sno + msg); | |
| 181 | + if(recordValid == 1) { | |
| 182 | + //有效刷卡调考勤存储过程 | |
| 183 | + CheckInDto checkIn = new CheckInDto(); | |
| 184 | + checkIn.setDeviceId(sno+""); | |
| 185 | + checkIn.setCardNo(cardNo); | |
| 186 | + checkIn.setFunNo(8); | |
| 187 | + checkIn.setFlag(recordDoorNO == 1 ? 1 : 0); | |
| 188 | + checkIn.setCheckTime(recordTime); | |
| 189 | + CheckOutDto checkOutDto = xaFeign.checkIn(checkIn); | |
| 190 | + if(checkOutDto.getIsSuccess() == 1){ | |
| 191 | + //考勤成功 | |
| 192 | + String nowDate = DateUtils.date2String(new Date(),DateUtils.format2); | |
| 193 | + Log_kaoInfo.info("考勤成功!,设备:"+sno+"卡号:"+cardNo+"方向:"+(recordDoorNO == 1 ? "出门" : "进门")+"______刷卡时间"+ recordTime+";入库时间:"+nowDate); | |
| 194 | + }else { | |
| 195 | + //考勤失败 | |
| 196 | + Log_orderFail.error("考勤失败!,设备:"+sno+"卡号:"+cardNo + "---"+ checkOutDto.getOut()); | |
| 197 | + } | |
| 198 | + }else { | |
| 199 | + //判断是否请假 | |
| 200 | + String studentNum = smFeign.checkLeave(cardNo); | |
| 201 | + if (StringUtils.isNotBlank(studentNum)) { | |
| 202 | + int outOf = recordDoorNO == 1 ? 1 : 0; | |
| 203 | + //远程开门 | |
| 204 | + openDoor(sno,"64",recordDoorNO,cardNo); | |
| 205 | + Log_orderSuccess.info("请假开门成功"+cardNo); | |
| 206 | + } else { | |
| 207 | + //没有请假不做任何处理,则是刷卡异常,入库 | |
| 208 | + UserDto user = smFeign.selectUserByCardNum(cardNo); | |
| 209 | + PassFailDto passFail = new PassFailDto(); | |
| 210 | + passFail.setCardNum(cardNo); | |
| 211 | + passFail.setDeviceId(sno+""); | |
| 212 | + passFail.setDirection((recordDoorNO == 1 ? "出门" : "进门")); | |
| 213 | + passFail.setResultIntro(WGUtils.getReasonDetailChinese(reason)); | |
| 214 | + passFail.setInTime(DateUtils.string2Date(recordTime, DateUtils.format2)); | |
| 215 | + passFail.setCreateTime(new Date()); | |
| 216 | + passFail.setSchoolId(user.getSchoolId()); | |
| 217 | + xaFeign.insertPassFail(passFail); | |
| 218 | + } | |
| 219 | + } | |
| 220 | + } | |
| 221 | + } | |
| 222 | + | |
| 223 | + private void push(byte[] recv){ | |
| 224 | + long index = WgUdpCommShort.getXidOfCommand(recv); | |
| 225 | + long sno = WgUdpCommShort.getLongByByte(recv, 4, 4); | |
| 226 | + String functionId = WGUtils.byte2Hex(recv[1]); | |
| 227 | + SendMessageDto sendMessage = xaFeign.selectMessage(sno+"",index,functionId); | |
| 228 | + if(sendMessage != null){ | |
| 229 | + if(recv[8] == 1){ | |
| 230 | + sendMessage.setCorrect(1); | |
| 231 | + }else { | |
| 232 | + sendMessage.setCorrect(0); | |
| 233 | + } | |
| 234 | + StringBuffer result = new StringBuffer(); | |
| 235 | + for(byte b : recv){ | |
| 236 | + result.append(WGUtils.byte2Hex(b)).append("-"); | |
| 237 | + } | |
| 238 | + sendMessage.setResult(result.toString().substring(0,result.toString().length()-1)); | |
| 239 | + xaFeign.updateMessage(sendMessage.getId(),sendMessage.getResult(),sendMessage.getCorrect()); | |
| 240 | + } | |
| 241 | + } | |
| 242 | + | |
| 243 | + //远程开门 | |
| 244 | + public long openDoor(long sno , String outsideOrderId,int doorNo , String cardNo){ | |
| 245 | + WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 246 | + pkt.iDevSn = sno; | |
| 247 | + try{ | |
| 248 | + int doorNO =doorNo; | |
| 249 | + pkt.Reset(); | |
| 250 | + pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 251 | + pkt.data[0] =(byte) (doorNO & 0xff); | |
| 252 | + if(StringUtils.isNotBlank(cardNo)){ | |
| 253 | + pkt.data[20] = WGUtils.toHex(cardNo.substring(0,2)); | |
| 254 | + pkt.data[21] = WGUtils.toHex(cardNo.substring(2,4)); | |
| 255 | + pkt.data[22] = WGUtils.toHex(cardNo.substring(4,6)); | |
| 256 | + pkt.data[23] = WGUtils.toHex(cardNo.substring(6,8)); | |
| 257 | + } | |
| 258 | + byte[] bytes = pkt.toByte(); | |
| 259 | + long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 260 | + long result = insert(sno+"",outsideOrderId,cardNo,index,bytes); | |
| 261 | + pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 262 | + return result ; | |
| 263 | + }catch (Exception e){ | |
| 264 | + Log_error.error(e.toString()); | |
| 265 | + } | |
| 266 | + return 0L; | |
| 267 | + } | |
| 268 | + | |
| 269 | + //重置控制板时间 | |
| 270 | + public long setTime(long sno , String outsideOrderId){ | |
| 271 | + WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 272 | + pkt.iDevSn = sno; | |
| 273 | + try{ | |
| 274 | + pkt.Reset(); | |
| 275 | + pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 276 | + Calendar cal = (Calendar.getInstance()); | |
| 277 | + pkt.data[0] = WGUtils.toHex(String.valueOf(cal.get(Calendar.YEAR)).substring(0,2)); | |
| 278 | + pkt.data[1] = WGUtils.toHex(String.valueOf(cal.get(Calendar.YEAR)).substring(2,4)); | |
| 279 | + pkt.data[2] = WGUtils.toHex(String.valueOf(cal.get(Calendar.MONTH)+1)); | |
| 280 | + pkt.data[3] = WGUtils.toHex(String.valueOf(cal.get(Calendar.DATE))); | |
| 281 | + pkt.data[4] =WGUtils.toHex(String.valueOf(cal.get(Calendar.HOUR_OF_DAY))); | |
| 282 | + pkt.data[5] =WGUtils.toHex(String.valueOf(cal.get(Calendar.MINUTE))); | |
| 283 | + pkt.data[6] = WGUtils.toHex(String.valueOf(cal.get(Calendar.SECOND))); | |
| 284 | + byte[] bytes = pkt.toByte(); | |
| 285 | + long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 286 | + long result = insert(sno+"",outsideOrderId,null,index,bytes); | |
| 287 | + pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 288 | + return result ; | |
| 289 | + }catch (Exception e){ | |
| 290 | + Log_error.error(e.toString()); | |
| 291 | + } | |
| 292 | + return 0L; | |
| 293 | + } | |
| 294 | + | |
| 295 | + //设置考勤时段 | |
| 296 | + public List<Long> SetAttendanceTime(long sno ,String outsideOrderId, int shiduan , Date begin ,Date end , | |
| 297 | + int isMonDay ,int isTuesDay , int isWednesDay ,int isThursDay , int isFriday , | |
| 298 | + int isSaturDay , int isWeekend , String shiqu){ | |
| 299 | + List<Long> resultList = new ArrayList<>(); | |
| 300 | + WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 301 | + pkt.iDevSn = sno; | |
| 302 | + try{ | |
| 303 | + pkt.Reset(); | |
| 304 | + pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 305 | + String[] shiQuArray = shiqu.split(","); | |
| 306 | + int shiDuanCount = shiQuArray.length / 6 ; | |
| 307 | + for (int i = 0; i < shiDuanCount; i++){ | |
| 308 | + if (i == 0) { | |
| 309 | + pkt.data[0] = WGUtils.toHex(shiduan+""); | |
| 310 | + } else { | |
| 311 | + pkt.data[0] = WGUtils.toHex((shiduan+20*i)+""); | |
| 312 | + } | |
| 313 | + Calendar c = Calendar.getInstance(); | |
| 314 | + c.setTime(begin); | |
| 315 | + //开始时间 20 19 01 01 | |
| 316 | + pkt.data[1] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(0,2)); | |
| 317 | + pkt.data[2] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(2,4)); | |
| 318 | + pkt.data[3] = WGUtils.toHex(String.valueOf(c.get(Calendar.MONTH)+1)); | |
| 319 | + pkt.data[4] = WGUtils.toHex(String.valueOf(c.get(Calendar.DATE))); | |
| 320 | + //结束时间 | |
| 321 | + c.setTime(end); | |
| 322 | + pkt.data[5] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(0,2)); | |
| 323 | + pkt.data[6] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(2,4)); | |
| 324 | + pkt.data[7] = WGUtils.toHex(String.valueOf(c.get(Calendar.MONTH)+1)); | |
| 325 | + pkt.data[8] = WGUtils.toHex(String.valueOf(c.get(Calendar.DATE))); | |
| 326 | + //星期几 有效 | |
| 327 | + pkt.data[9] = WGUtils.toHex(String.valueOf(isMonDay)); | |
| 328 | + pkt.data[10] = WGUtils.toHex(String.valueOf(isTuesDay)); | |
| 329 | + pkt.data[11] = WGUtils.toHex(String.valueOf(isWednesDay)); | |
| 330 | + pkt.data[12] = WGUtils.toHex(String.valueOf(isThursDay)); | |
| 331 | + pkt.data[13] = WGUtils.toHex(String.valueOf(isFriday)); | |
| 332 | + pkt.data[14] = WGUtils.toHex(String.valueOf(isSaturDay)); | |
| 333 | + pkt.data[15] = WGUtils.toHex(String.valueOf(isWeekend)); | |
| 334 | + //有效时区 | |
| 335 | + pkt.data[16] = WGUtils.toHex(shiQuArray[i * 6 + 0].substring(0, 2)); | |
| 336 | + pkt.data[17] = WGUtils.toHex(shiQuArray[i * 6 + 0].substring(3, 5)); | |
| 337 | + | |
| 338 | + pkt.data[18] = WGUtils.toHex(shiQuArray[i * 6 + 1].substring(0, 2)); | |
| 339 | + pkt.data[19] = WGUtils.toHex(shiQuArray[i * 6 + 1].substring(3, 5)); | |
| 340 | + | |
| 341 | + pkt.data[20] = WGUtils.toHex(shiQuArray[i * 6 + 2].substring(0, 2)); | |
| 342 | + pkt.data[21] = WGUtils.toHex(shiQuArray[i * 6 + 2].substring(3, 5)); | |
| 343 | + | |
| 344 | + pkt.data[22] = WGUtils.toHex(shiQuArray[i * 6 + 3].substring(0, 2)); | |
| 345 | + pkt.data[23] = WGUtils.toHex(shiQuArray[i * 6 + 3].substring(3, 5)); | |
| 346 | + | |
| 347 | + pkt.data[24] = WGUtils.toHex(shiQuArray[i * 6 + 4].substring(0, 2)); | |
| 348 | + pkt.data[25] = WGUtils.toHex(shiQuArray[i * 6 + 4].substring(3, 5)); | |
| 349 | + | |
| 350 | + pkt.data[26] = WGUtils.toHex(shiQuArray[i * 6 + 5].substring(0, 2)); | |
| 351 | + pkt.data[27] = WGUtils.toHex(shiQuArray[i * 6 + 5].substring(3, 5)); | |
| 352 | + if (shiDuanCount != 1) { | |
| 353 | + //需要链接时段 | |
| 354 | + if (i != shiDuanCount - 1) { | |
| 355 | + //只要不是最后一个时段 | |
| 356 | + pkt.data[28] = WGUtils.toHex((shiduan+20*(i+1)+"")); | |
| 357 | + } else { | |
| 358 | + pkt.data[28] = 0; | |
| 359 | + } | |
| 360 | + } else { | |
| 361 | + pkt.data[28] = 0; | |
| 362 | + } | |
| 363 | + byte[] bytes = pkt.toByte(); | |
| 364 | + long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 365 | + long result = insert(sno+"",outsideOrderId,null,index,bytes); | |
| 366 | + pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 367 | + resultList.add(result); | |
| 368 | + } | |
| 369 | + return resultList ; | |
| 370 | + }catch (Exception e){ | |
| 371 | + Log_error.error(e.toString()); | |
| 372 | + } | |
| 373 | + return resultList; | |
| 374 | + } | |
| 375 | + | |
| 376 | + //设置权限 | |
| 377 | + public long SetSignalCardInfo(long sno , String outsideOrderId, String cardNo , int shiduan , Date begin , Date end){ | |
| 378 | + WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 379 | + pkt.iDevSn = sno; | |
| 380 | + try{ | |
| 381 | + pkt.Reset(); | |
| 382 | + pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 383 | + pkt.iDevSn = sno; | |
| 384 | + //0D D7 37 00 | |
| 385 | + pkt.data[0] = WGUtils.toHex(cardNo.substring(0,2)); | |
| 386 | + pkt.data[1] = WGUtils.toHex(cardNo.substring(2,4)); | |
| 387 | + pkt.data[2] = WGUtils.toHex(cardNo.substring(4,6)); | |
| 388 | + pkt.data[3] = WGUtils.toHex(cardNo.substring(6,8)); | |
| 389 | + | |
| 390 | + //20 10 01 01 起始日期: 2010年01月01日 (必须大于2001年) | |
| 391 | + Calendar c = Calendar.getInstance(); | |
| 392 | + c.setTime(begin); | |
| 393 | + pkt.data[4] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(0,2)); | |
| 394 | + pkt.data[5] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(2,4)); | |
| 395 | + pkt.data[6] = WGUtils.toHex(String.valueOf(c.get(Calendar.MONTH)+1)); | |
| 396 | + pkt.data[7] = WGUtils.toHex(String.valueOf(c.get(Calendar.DATE))); | |
| 397 | + //20 29 12 31 截止日期: 2029年12月31日 | |
| 398 | + c.setTime(end); | |
| 399 | + pkt.data[8] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(0,2)); | |
| 400 | + pkt.data[9] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(2,4)); | |
| 401 | + pkt.data[10] = WGUtils.toHex(String.valueOf(c.get(Calendar.MONTH)+1)); | |
| 402 | + pkt.data[11] = WGUtils.toHex(String.valueOf(c.get(Calendar.DATE))); | |
| 403 | + //01 允许通过 一号门 [对单门, 双门, 四门控制器有效] | |
| 404 | + pkt.data[12] = WGUtils.toHex(shiduan+""); | |
| 405 | + //01 允许通过 二号门 [对双门, 四门控制器有效] | |
| 406 | + pkt.data[13] = WGUtils.toHex(shiduan+""); | |
| 407 | + //01 允许通过 三号门 [对四门控制器有效] | |
| 408 | + pkt.data[14] = WGUtils.toHex(shiduan+""); | |
| 409 | + //01 允许通过 四号门 [对四门控制器有效] | |
| 410 | + pkt.data[15] = WGUtils.toHex(shiduan+""); | |
| 411 | + byte[] bytes = pkt.toByte(); | |
| 412 | + long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 413 | + long result = insert(sno+"",outsideOrderId,cardNo,index,bytes); | |
| 414 | + pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 415 | + return result ; | |
| 416 | + }catch (Exception e){ | |
| 417 | + Log_error.error(e.toString()); | |
| 418 | + } | |
| 419 | + return 0l; | |
| 420 | + } | |
| 421 | + | |
| 422 | + //删除单张卡权限 | |
| 423 | + public long clearSinglePower(long sno ,String outsideOrderId, String cardNo){ | |
| 424 | + WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 425 | + pkt.iDevSn = sno; | |
| 426 | + try{ | |
| 427 | + pkt.Reset(); | |
| 428 | + pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 429 | + pkt.iDevSn = sno; | |
| 430 | + pkt.data[0] = WGUtils.toHex(cardNo.substring(0,2)); | |
| 431 | + pkt.data[1] = WGUtils.toHex(cardNo.substring(2,4)); | |
| 432 | + pkt.data[2] = WGUtils.toHex(cardNo.substring(4,6)); | |
| 433 | + pkt.data[3] = WGUtils.toHex(cardNo.substring(6,8)); | |
| 434 | + byte[] bytes = pkt.toByte(); | |
| 435 | + long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 436 | + long result = insert(sno+"",outsideOrderId,cardNo,index,bytes); | |
| 437 | + pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 438 | + return result ; | |
| 439 | + }catch (Exception e){ | |
| 440 | + Log_error.error(e.toString()); | |
| 441 | + } | |
| 442 | + return 0l; | |
| 443 | + } | |
| 444 | + | |
| 445 | + //删除全部权限 | |
| 446 | + public long clearAllPower(long sno ,String outsideOrderId){ | |
| 447 | + WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 448 | + pkt.iDevSn = sno; | |
| 449 | + try{ | |
| 450 | + pkt.Reset(); | |
| 451 | + pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 452 | + pkt.iDevSn = sno; | |
| 453 | + pkt.data[0] = (byte) 0x55 ; | |
| 454 | + pkt.data[1] = (byte) 0xAA ; | |
| 455 | + pkt.data[2] = (byte) 0xAA ; | |
| 456 | + pkt.data[3] = (byte) 0x55 ; | |
| 457 | + byte[] bytes = pkt.toByte(); | |
| 458 | + long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 459 | + long result = insert(sno+"",outsideOrderId,null,index,bytes); | |
| 460 | + pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 461 | + return result ; | |
| 462 | + }catch (Exception e){ | |
| 463 | + Log_error.error(e.toString()); | |
| 464 | + } | |
| 465 | + return 0l; | |
| 466 | + } | |
| 467 | + | |
| 468 | + //查询卡权限 | |
| 469 | + public long searchPower(long sno ,String outsideOrderId, String cardNo){ | |
| 470 | + WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 471 | + pkt.iDevSn = sno; | |
| 472 | + try{ | |
| 473 | + pkt.Reset(); | |
| 474 | + pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 475 | + pkt.iDevSn = sno; | |
| 476 | + pkt.data[0] = WGUtils.toHex(cardNo.substring(0,2)); | |
| 477 | + pkt.data[1] = WGUtils.toHex(cardNo.substring(2,4)); | |
| 478 | + pkt.data[2] = WGUtils.toHex(cardNo.substring(4,6)); | |
| 479 | + pkt.data[3] = WGUtils.toHex(cardNo.substring(6,8)); | |
| 480 | + byte[] bytes = pkt.toByte(); | |
| 481 | + long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 482 | + long result = insert(sno+"",outsideOrderId,cardNo,index,bytes); | |
| 483 | + pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 484 | + return result ; | |
| 485 | + }catch (Exception e){ | |
| 486 | + Log_error.error(e.toString()); | |
| 487 | + } | |
| 488 | + return 0l; | |
| 489 | + } | |
| 490 | + | |
| 491 | + //删除时段 | |
| 492 | + public long clearShiDuan(long sno , String outsideOrderId){ | |
| 493 | + WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 494 | + pkt.iDevSn = sno; | |
| 495 | + try{ | |
| 496 | + pkt.Reset(); | |
| 497 | + pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 498 | + pkt.iDevSn = sno; | |
| 499 | + pkt.data[0] = (byte) 0x55 ; | |
| 500 | + pkt.data[1] = (byte) 0xAA ; | |
| 501 | + pkt.data[2] = (byte) 0xAA ; | |
| 502 | + pkt.data[3] = (byte) 0x55 ; | |
| 503 | + byte[] bytes = pkt.toByte(); | |
| 504 | + long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 505 | + long result = insert(sno+"",outsideOrderId,null,index,bytes); | |
| 506 | + pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 507 | + return result ; | |
| 508 | + }catch (Exception e){ | |
| 509 | + Log_error.error(e.toString()); | |
| 510 | + } | |
| 511 | + return 0l; | |
| 512 | + } | |
| 513 | + | |
| 514 | + private long insert(String sn ,String functionId , String cardNo , long index , byte[] recv){ | |
| 515 | + | |
| 516 | + StringBuffer send = new StringBuffer(); | |
| 517 | + for(byte b : recv){ | |
| 518 | + send.append(WGUtils.byte2Hex(b)).append("-"); | |
| 519 | + } | |
| 520 | + SendMessageDto sendMessage = new SendMessageDto(); | |
| 521 | + sendMessage.setDeviceId(sn); | |
| 522 | + sendMessage.setFunctionId(Integer.toHexString(Integer.valueOf(functionId))); | |
| 523 | + sendMessage.setIndex(index); | |
| 524 | + sendMessage.setCardNo(cardNo); | |
| 525 | + sendMessage.setCreateTime(new Date()); | |
| 526 | + sendMessage.setSend(send.toString().substring(0,send.toString().length()-1)); | |
| 527 | + xaFeign.insertMessage(sendMessage); | |
| 528 | + return sendMessage.getId(); | |
| 529 | + } | |
| 530 | +} | ... | ... |
cloud/weigeng/src/main/java/com/sincere/weigeng/WeigengApplication.java
cloud/weigeng/src/main/java/com/sincere/weigeng/controller/WgController.java
| ... | ... | @@ -11,7 +11,7 @@ import com.sincere.weigeng.feign.SmFeign; |
| 11 | 11 | import com.sincere.weigeng.feign.XaFeign; |
| 12 | 12 | import com.sincere.weigeng.logs.LogName; |
| 13 | 13 | import com.sincere.weigeng.logs.LoggerUtils; |
| 14 | -import com.sincere.weigeng.utils.WatchServer; | |
| 14 | +import com.sincere.weigeng.WatchServer; | |
| 15 | 15 | import com.sincere.weigeng.vo.*; |
| 16 | 16 | import io.swagger.annotations.Api; |
| 17 | 17 | import io.swagger.annotations.ApiOperation; |
| ... | ... | @@ -42,24 +42,20 @@ public class WgController { |
| 42 | 42 | @Autowired |
| 43 | 43 | XaFeign xaFeign; |
| 44 | 44 | |
| 45 | - private static String ip = "172.16.3.175"; | |
| 46 | - private static int port = 1200; | |
| 45 | + @Autowired | |
| 46 | + WatchServer watchServer; | |
| 47 | 47 | |
| 48 | - @RequestMapping(value = "watching" , method = RequestMethod.GET) | |
| 49 | - public void watching(){ | |
| 50 | - WatchServer.WatchingServerRunning(ip,port,smFeign,xaFeign); | |
| 51 | - } | |
| 52 | 48 | |
| 53 | 49 | @RequestMapping(value = "setTime" , method = RequestMethod.GET) |
| 54 | 50 | public void setTime(long sn){ |
| 55 | - WatchServer.setTime(xaFeign,sn,"48"); | |
| 51 | + watchServer.setTime(sn,"48"); | |
| 56 | 52 | } |
| 57 | 53 | |
| 58 | 54 | @ApiOperation("远程开门") |
| 59 | 55 | @RequestMapping(value = "openDoor" , method = RequestMethod.POST) |
| 60 | 56 | public boolean openDoor(@RequestBody OpenDoorVo openDoorVo) { |
| 61 | 57 | String functionId = smFeign.selectOutOrderId(openDoorVo.getType(),openDoorVo.getId()); |
| 62 | - long messageId = WatchServer.openDoor(xaFeign,openDoorVo.getSn(),functionId,openDoorVo.getDoorNo(),null); | |
| 58 | + long messageId = watchServer.openDoor(openDoorVo.getSn(),functionId,openDoorVo.getDoorNo(),null); | |
| 63 | 59 | SendMessageDto message = getResult(messageId); |
| 64 | 60 | if(message.getCorrect() == 1){ |
| 65 | 61 | Log_orderSuccess.info("web端远程开门成功!"); |
| ... | ... | @@ -74,7 +70,7 @@ public class WgController { |
| 74 | 70 | @RequestMapping(value = "setAttendanceTime" , method = RequestMethod.POST) |
| 75 | 71 | public boolean setAttendanceTime(@RequestBody AttendanceTimeVo attendanceTimeVo){ |
| 76 | 72 | String functionId = smFeign.selectOutOrderId(attendanceTimeVo.getType(),attendanceTimeVo.getId()); |
| 77 | - List<Long> result = WatchServer.SetAttendanceTime(xaFeign,attendanceTimeVo.getSn(),functionId,attendanceTimeVo.getShiduan(), | |
| 73 | + List<Long> result = watchServer.SetAttendanceTime(attendanceTimeVo.getSn(),functionId,attendanceTimeVo.getShiduan(), | |
| 78 | 74 | attendanceTimeVo.getStart(),attendanceTimeVo.getEnd(),attendanceTimeVo.getIsMonday(),attendanceTimeVo.getIsTuesday(), |
| 79 | 75 | attendanceTimeVo.getIsWednesday(),attendanceTimeVo.getIsThursday(),attendanceTimeVo.getIsFriday(), |
| 80 | 76 | attendanceTimeVo.getIsSaturday(),attendanceTimeVo.getIsWeekend(),attendanceTimeVo.getShiqu()); |
| ... | ... | @@ -97,7 +93,7 @@ public class WgController { |
| 97 | 93 | public boolean setSignalCardInfo(@RequestBody SignalCardInfoVo signalCardInfoVo){ |
| 98 | 94 | String functionId = smFeign.selectOutOrderId(signalCardInfoVo.getType(),signalCardInfoVo.getId()); |
| 99 | 95 | String cardNo = initCardNo(signalCardInfoVo.getCardNo()); |
| 100 | - long messageId = WatchServer.SetSignalCardInfo(xaFeign,signalCardInfoVo.getSn(),functionId,cardNo, | |
| 96 | + long messageId = watchServer.SetSignalCardInfo(signalCardInfoVo.getSn(),functionId,cardNo, | |
| 101 | 97 | signalCardInfoVo.getShiduan(),signalCardInfoVo.getStartTime(),signalCardInfoVo.getEndTime()); |
| 102 | 98 | SendMessageDto message = getResult(messageId); |
| 103 | 99 | UserDto user = smFeign.selectUserByCardNum(cardNo); |
| ... | ... | @@ -136,7 +132,7 @@ public class WgController { |
| 136 | 132 | public boolean clearSinglePower(@RequestBody CardInfo cardInfo){ |
| 137 | 133 | String functionId = smFeign.selectOutOrderId(cardInfo.getType(),cardInfo.getId()); |
| 138 | 134 | String cardNo = initCardNo(cardInfo.getCardNo()); |
| 139 | - long messageId = WatchServer.clearSinglePower(xaFeign,cardInfo.getSn(),functionId,cardNo); | |
| 135 | + long messageId = watchServer.clearSinglePower(cardInfo.getSn(),functionId,cardNo); | |
| 140 | 136 | SendMessageDto message = getResult(messageId); |
| 141 | 137 | if(message.getCorrect() == 1){ |
| 142 | 138 | Log_orderSuccess.info("卡号"+cardNo+"清除权限成功"); |
| ... | ... | @@ -154,7 +150,7 @@ public class WgController { |
| 154 | 150 | @RequestMapping(value = "clearAllPower" , method = RequestMethod.POST) |
| 155 | 151 | public boolean clearAllPower(@RequestBody CleanShiDuanVo cleanShiDuanVo){ |
| 156 | 152 | String functionId = smFeign.selectOutOrderId(cleanShiDuanVo.getType(),cleanShiDuanVo.getId()); |
| 157 | - long messageId = WatchServer.clearAllPower(xaFeign,cleanShiDuanVo.getSn(),functionId); | |
| 153 | + long messageId = watchServer.clearAllPower(cleanShiDuanVo.getSn(),functionId); | |
| 158 | 154 | SendMessageDto message = getResult(messageId); |
| 159 | 155 | if(message.getCorrect() == 1){ |
| 160 | 156 | Log_orderSuccess.info("设备"+cleanShiDuanVo.getSn()+"清除权限成功"); |
| ... | ... | @@ -172,7 +168,7 @@ public class WgController { |
| 172 | 168 | @RequestMapping(value = "clearShiDuan" , method = RequestMethod.POST) |
| 173 | 169 | public boolean clearShiDuan(@RequestBody CleanShiDuanVo cleanShiDuanVo){ |
| 174 | 170 | String functionId = smFeign.selectOutOrderId(cleanShiDuanVo.getType(),cleanShiDuanVo.getId()); |
| 175 | - long messageId = WatchServer.clearShiDuan(xaFeign,cleanShiDuanVo.getSn(),functionId); | |
| 171 | + long messageId = watchServer.clearShiDuan(cleanShiDuanVo.getSn(),functionId); | |
| 176 | 172 | SendMessageDto sendMessage = getResult(messageId); |
| 177 | 173 | if(sendMessage.getCorrect() == 1){ |
| 178 | 174 | Log_orderSuccess.info("设备"+cleanShiDuanVo.getSn()+"时段清除成功"); |
| ... | ... | @@ -187,7 +183,7 @@ public class WgController { |
| 187 | 183 | public boolean searchPower(@RequestBody CardInfo cardInfo){ |
| 188 | 184 | String functionId = smFeign.selectOutOrderId(cardInfo.getType(),cardInfo.getId()); |
| 189 | 185 | String cardNo = initCardNo(cardInfo.getCardNo()); |
| 190 | - long messageId = WatchServer.searchPower(xaFeign,cardInfo.getSn(),functionId,cardNo); | |
| 186 | + long messageId = watchServer.searchPower(cardInfo.getSn(),functionId,cardNo); | |
| 191 | 187 | SendMessageDto sendMessage = getResult(messageId); |
| 192 | 188 | if(sendMessage.getCorrect() == 1){ |
| 193 | 189 | Log_orderSuccess.info("设备"+cardInfo.getSn()+"卡号"+cardNo+"查询权限成功"); | ... | ... |
cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WatchServer.java
| ... | ... | @@ -1,509 +0,0 @@ |
| 1 | -package com.sincere.weigeng.utils; | |
| 2 | - | |
| 3 | - | |
| 4 | -import com.sincere.common.dto.smartCampus.UserDto; | |
| 5 | -import com.sincere.common.dto.xiaoan.CheckInDto; | |
| 6 | -import com.sincere.common.dto.xiaoan.CheckOutDto; | |
| 7 | -import com.sincere.common.dto.xiaoan.PassFailDto; | |
| 8 | -import com.sincere.common.dto.xiaoan.SendMessageDto; | |
| 9 | -import com.sincere.common.util.DateUtils; | |
| 10 | -import com.sincere.weigeng.feign.SmFeign; | |
| 11 | -import com.sincere.weigeng.feign.XaFeign; | |
| 12 | -import com.sincere.weigeng.logs.LogName; | |
| 13 | -import com.sincere.weigeng.logs.LoggerUtils; | |
| 14 | -import org.apache.commons.lang3.StringUtils; | |
| 15 | -import org.apache.mina.core.session.IoSession; | |
| 16 | -import org.apache.mina.transport.socket.DatagramSessionConfig; | |
| 17 | -import org.apache.mina.transport.socket.nio.NioDatagramAcceptor; | |
| 18 | -import org.slf4j.Logger; | |
| 19 | - | |
| 20 | -import java.io.IOException; | |
| 21 | -import java.net.InetSocketAddress; | |
| 22 | -import java.util.*; | |
| 23 | -import java.util.concurrent.ConcurrentHashMap; | |
| 24 | - | |
| 25 | -/** | |
| 26 | - * @author chen | |
| 27 | - * @version 1.0 | |
| 28 | - * @date 2019/10/12 0012 16:57 | |
| 29 | - */ | |
| 30 | -public class WatchServer { | |
| 31 | - | |
| 32 | - private static final Logger Log_orderSuccess = LoggerUtils.Logger(LogName.orderSuccess); | |
| 33 | - private static final Logger Log_orderFail = LoggerUtils.Logger(LogName.orderFail); | |
| 34 | - private static final Logger Log_kaoInfo = LoggerUtils.Logger(LogName.kaoInfo); | |
| 35 | - private static final Logger Log_heartBeat = LoggerUtils.Logger(LogName.heartBeat); | |
| 36 | - private static final Logger Log_error = LoggerUtils.Logger(LogName.error); | |
| 37 | - | |
| 38 | - private static List<Long> snoList = new ArrayList<>(); | |
| 39 | - private static List<Long> indexList = new ArrayList<>(); | |
| 40 | - private static WatchingShortHandler watchingShortHandler ; | |
| 41 | - private static Queue<byte[]> queue = new LinkedList<>(); | |
| 42 | - private static Map<Long , IoSession> sessionMap = new ConcurrentHashMap<>(); | |
| 43 | - | |
| 44 | - // 进入服务器监控状态 | |
| 45 | - public static int WatchingServerRunning(String watchServerIP,int watchServerPort, | |
| 46 | - SmFeign smFeign ,XaFeign xaFeign) { | |
| 47 | - watchingShortHandler = new WatchingShortHandler(queue,sessionMap); | |
| 48 | - // 创建UDP数据包NIO | |
| 49 | - NioDatagramAcceptor acceptor = new NioDatagramAcceptor(); | |
| 50 | - // NIO设置底层IOHandler | |
| 51 | - acceptor.setHandler(watchingShortHandler); | |
| 52 | - | |
| 53 | - // 设置是否重用地址? 也就是每个发过来的udp信息都是一个地址? | |
| 54 | - DatagramSessionConfig dcfg = acceptor.getSessionConfig(); | |
| 55 | - dcfg.setReuseAddress(false); | |
| 56 | - // 绑定端口地址 | |
| 57 | - try { | |
| 58 | - acceptor.bind(new InetSocketAddress(watchServerIP, watchServerPort)); | |
| 59 | - } catch (IOException e) { | |
| 60 | - Log_orderSuccess.info("绑定接收服务器失败...."); | |
| 61 | - e.printStackTrace(); | |
| 62 | - return 0; | |
| 63 | - } | |
| 64 | - Log_orderSuccess.info("绑定接收服务器成功...."); | |
| 65 | - long recordIndex = 0; | |
| 66 | - while(true) { | |
| 67 | - if (!queue.isEmpty()) { | |
| 68 | - byte[] recvBuff; | |
| 69 | - synchronized (queue) { | |
| 70 | - recvBuff= queue.poll(); | |
| 71 | - } | |
| 72 | - if (recvBuff[1]== 0x20) { | |
| 73 | - long sn = WgUdpCommShort.getLongByByte(recvBuff, 4, 4); | |
| 74 | - smFeign.updateLinkTime(sn+""); | |
| 75 | - Log_heartBeat.info("设备"+sn); | |
| 76 | - boolean isExist = true ; | |
| 77 | - long recordIndexGet = WgUdpCommShort.getLongByByte(recvBuff, 8, 4); | |
| 78 | - if(snoList.indexOf(sn) >= 0){ | |
| 79 | - int number = snoList.indexOf(sn); | |
| 80 | - recordIndex = indexList.get(number); | |
| 81 | - indexList.set(number,recordIndexGet); | |
| 82 | - }else { | |
| 83 | - snoList.add(sn); | |
| 84 | - recordIndex = 0 ; | |
| 85 | - indexList.add(recordIndexGet); | |
| 86 | - System.out.println("设备"+sn+"上线"); | |
| 87 | - isExist = false ; | |
| 88 | - } | |
| 89 | - if(isExist){ | |
| 90 | - if (recordIndex < recordIndexGet || (recordIndexGet - recordIndex) < -5) { | |
| 91 | - watching(recvBuff,smFeign,xaFeign); | |
| 92 | - } | |
| 93 | - } | |
| 94 | - }else { | |
| 95 | - push(recvBuff,xaFeign); | |
| 96 | - } | |
| 97 | - } else { | |
| 98 | - long times = 100; | |
| 99 | - try { | |
| 100 | - Thread.sleep(times); | |
| 101 | - } catch (InterruptedException e) { | |
| 102 | - e.printStackTrace(); | |
| 103 | - } | |
| 104 | - } | |
| 105 | - } | |
| 106 | - } | |
| 107 | - | |
| 108 | - private static void watching(byte[] recv,SmFeign smFeign ,XaFeign xaFeign){ | |
| 109 | - long res = 0; | |
| 110 | - //8-11 记录的索引号 | |
| 111 | - //(=0表示没有记录) 4 0x00000000 | |
| 112 | - int recordIndex = 0; | |
| 113 | - recordIndex = WGUtils.byteToInt(recv, 8, 4); | |
| 114 | - //12 记录类型********************************************** | |
| 115 | - //0=无记录 | |
| 116 | - //1=刷卡记录 | |
| 117 | - //2=门磁,按钮, 设备启动, 远程开门记录 | |
| 118 | - //3=报警记录 1 | |
| 119 | - //0xFF=表示指定索引位的记录已被覆盖掉了. 请使用索引0, 取回最早一条记录的索引值 | |
| 120 | - int recordType = recv[12]; | |
| 121 | - | |
| 122 | - //13 有效性(0 表示不通过, 1表示通过) 1 | |
| 123 | - int recordValid = recv[13]; | |
| 124 | - | |
| 125 | - //14 门号(1,2,3,4) 1 业务需要-->1出2进 | |
| 126 | - int recordDoorNO = recv[14]; | |
| 127 | - | |
| 128 | - //15 进门/出门(1表示进门, 2表示出门) 1 0x01 | |
| 129 | - //int recordInOrOut = recv[15]; | |
| 130 | - | |
| 131 | - //16-19 卡号(类型是刷卡记录时) | |
| 132 | - //或编号(其他类型记录) 4 | |
| 133 | - String cardNo = WGUtils.getCardNo(recv, 16, 4); | |
| 134 | - | |
| 135 | - //20-26 刷卡时间: | |
| 136 | - //年月日时分秒 (采用BCD码)见设置时间部分的说明 | |
| 137 | - String recordTime = "2000-01-01 00:00:00"; | |
| 138 | - recordTime = String.format("%02X%02X-%02X-%02X %02X:%02X:%02X", | |
| 139 | - recv[20], recv[21], recv[22], recv[23], recv[24], recv[25], recv[26]); | |
| 140 | - //2012.12.11 10:49:59 7 | |
| 141 | - //27 记录原因代码(可以查 “刷卡记录说明.xls”文件的ReasonNO) | |
| 142 | - //处理复杂信息才用 1 | |
| 143 | - int reason = recv[27]; | |
| 144 | - if (recordType == 0) { | |
| 145 | - Log_orderSuccess.info(String.format("索引位={0} 无记录", recordIndex)); | |
| 146 | - }else if (recordType == 0xff) { | |
| 147 | - Log_orderSuccess.info("指定索引位的记录已被覆盖掉了,请使用索引0, 取回最早一条记录的索引值"); | |
| 148 | - } else if (recordType == 1) { | |
| 149 | - long sno = 0; | |
| 150 | - sno = WgUdpCommShort.getLongByByte(recv, 4, 4);//解析设备号 | |
| 151 | - String msg = "索引位=" + recordIndex | |
| 152 | - + ",卡号=" + cardNo | |
| 153 | - +"进出=" + (recordDoorNO == 1 ? "出门" : "进门") | |
| 154 | - + ",有效=" + (recordValid == 1 ? "通过" : "禁止") | |
| 155 | - + ",时间=" + recordTime | |
| 156 | - + ",描述=" + WGUtils.getReasonDetailChinese(reason) + ""; | |
| 157 | - Log_orderSuccess.info("控制器:" + sno + msg); | |
| 158 | - if(recordValid == 1) { | |
| 159 | - //有效刷卡调考勤存储过程 | |
| 160 | - CheckInDto checkIn = new CheckInDto(); | |
| 161 | - checkIn.setDeviceId(sno+""); | |
| 162 | - checkIn.setCardNo(cardNo); | |
| 163 | - checkIn.setFunNo(8); | |
| 164 | - checkIn.setFlag(recordDoorNO == 1 ? 1 : 0); | |
| 165 | - checkIn.setCheckTime(recordTime); | |
| 166 | - CheckOutDto checkOutDto = xaFeign.checkIn(checkIn); | |
| 167 | - if(checkOutDto.getIsSuccess() == 1){ | |
| 168 | - //考勤成功 | |
| 169 | - Log_kaoInfo.info("考勤成功!,设备:"+sno+"卡号:"+cardNo+"方向:"+(recordDoorNO == 1 ? "出门" : "进门")+"______"+ recordTime); | |
| 170 | - }else { | |
| 171 | - //考勤失败 | |
| 172 | - Log_orderFail.error("考勤失败!,设备:"+sno+"卡号:"+cardNo + "---"+ checkOutDto.getOut()); | |
| 173 | - } | |
| 174 | - }else { | |
| 175 | - //判断是否请假 | |
| 176 | - String studentNum = smFeign.checkLeave(cardNo); | |
| 177 | - if (StringUtils.isNotBlank(studentNum)) { | |
| 178 | - int outOf = recordDoorNO == 1 ? 1 : 0; | |
| 179 | - //远程开门 | |
| 180 | - openDoor(xaFeign,sno,"64",recordDoorNO,cardNo); | |
| 181 | - Log_orderSuccess.info("请假开门成功"+cardNo); | |
| 182 | - } else { | |
| 183 | - //没有请假不做任何处理,则是刷卡异常,入库 | |
| 184 | - UserDto user = smFeign.selectUserByCardNum(cardNo); | |
| 185 | - PassFailDto passFail = new PassFailDto(); | |
| 186 | - passFail.setCardNum(cardNo); | |
| 187 | - passFail.setDeviceId(sno+""); | |
| 188 | - passFail.setDirection((recordDoorNO == 1 ? "出门" : "进门")); | |
| 189 | - passFail.setResultIntro(WGUtils.getReasonDetailChinese(reason)); | |
| 190 | - passFail.setInTime(DateUtils.string2Date(recordTime, DateUtils.format2)); | |
| 191 | - passFail.setCreateTime(new Date()); | |
| 192 | - passFail.setSchoolId(user.getSchoolId()); | |
| 193 | - xaFeign.insertPassFail(passFail); | |
| 194 | - } | |
| 195 | - } | |
| 196 | - } | |
| 197 | - } | |
| 198 | - | |
| 199 | - private static void push(byte[] recv,XaFeign xaFeign){ | |
| 200 | - long index = WgUdpCommShort.getXidOfCommand(recv); | |
| 201 | - long sno = WgUdpCommShort.getLongByByte(recv, 4, 4); | |
| 202 | - String functionId = WGUtils.byte2Hex(recv[1]); | |
| 203 | - SendMessageDto sendMessage = xaFeign.selectMessage(sno+"",index,functionId); | |
| 204 | - if(sendMessage != null){ | |
| 205 | - if(recv[8] == 1){ | |
| 206 | - sendMessage.setCorrect(1); | |
| 207 | - }else { | |
| 208 | - sendMessage.setCorrect(0); | |
| 209 | - } | |
| 210 | - StringBuffer result = new StringBuffer(); | |
| 211 | - for(byte b : recv){ | |
| 212 | - result.append(WGUtils.byte2Hex(b)).append("-"); | |
| 213 | - } | |
| 214 | - sendMessage.setResult(result.toString().substring(0,result.toString().length()-1)); | |
| 215 | - xaFeign.updateMessage(sendMessage.getId(),sendMessage.getResult(),sendMessage.getCorrect()); | |
| 216 | - } | |
| 217 | - } | |
| 218 | - | |
| 219 | - //远程开门 | |
| 220 | - public static long openDoor(XaFeign xaFeign,long sno , String outsideOrderId,int doorNo , String cardNo){ | |
| 221 | - WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 222 | - pkt.iDevSn = sno; | |
| 223 | - try{ | |
| 224 | - int doorNO =doorNo; | |
| 225 | - pkt.Reset(); | |
| 226 | - pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 227 | - pkt.data[0] =(byte) (doorNO & 0xff); | |
| 228 | - if(StringUtils.isNotBlank(cardNo)){ | |
| 229 | - pkt.data[20] = WGUtils.toHex(cardNo.substring(0,2)); | |
| 230 | - pkt.data[21] = WGUtils.toHex(cardNo.substring(2,4)); | |
| 231 | - pkt.data[22] = WGUtils.toHex(cardNo.substring(4,6)); | |
| 232 | - pkt.data[23] = WGUtils.toHex(cardNo.substring(6,8)); | |
| 233 | - } | |
| 234 | - byte[] bytes = pkt.toByte(); | |
| 235 | - long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 236 | - long result = insert(xaFeign,sno+"",outsideOrderId,cardNo,index,bytes); | |
| 237 | - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 238 | - return result ; | |
| 239 | - }catch (Exception e){ | |
| 240 | - Log_error.error(e.toString()); | |
| 241 | - } | |
| 242 | - return 0L; | |
| 243 | - } | |
| 244 | - | |
| 245 | - //重置控制板时间 | |
| 246 | - public static long setTime(XaFeign xaFeign,long sno , String outsideOrderId){ | |
| 247 | - WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 248 | - pkt.iDevSn = sno; | |
| 249 | - try{ | |
| 250 | - pkt.Reset(); | |
| 251 | - pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 252 | - Calendar cal = (Calendar.getInstance()); | |
| 253 | - pkt.data[0] = WGUtils.toHex(String.valueOf(cal.get(Calendar.YEAR)).substring(0,2)); | |
| 254 | - pkt.data[1] = WGUtils.toHex(String.valueOf(cal.get(Calendar.YEAR)).substring(2,4)); | |
| 255 | - pkt.data[2] = WGUtils.toHex(String.valueOf(cal.get(Calendar.MONTH)+1)); | |
| 256 | - pkt.data[3] = WGUtils.toHex(String.valueOf(cal.get(Calendar.DATE))); | |
| 257 | - pkt.data[4] =WGUtils.toHex(String.valueOf(cal.get(Calendar.HOUR_OF_DAY))); | |
| 258 | - pkt.data[5] =WGUtils.toHex(String.valueOf(cal.get(Calendar.MINUTE))); | |
| 259 | - pkt.data[6] = WGUtils.toHex(String.valueOf(cal.get(Calendar.SECOND))); | |
| 260 | - byte[] bytes = pkt.toByte(); | |
| 261 | - long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 262 | - long result = insert(xaFeign,sno+"",outsideOrderId,null,index,bytes); | |
| 263 | - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 264 | - return result ; | |
| 265 | - }catch (Exception e){ | |
| 266 | - Log_error.error(e.toString()); | |
| 267 | - } | |
| 268 | - return 0L; | |
| 269 | - } | |
| 270 | - | |
| 271 | - | |
| 272 | - | |
| 273 | - //设置考勤时段 | |
| 274 | - public static List<Long> SetAttendanceTime(XaFeign xaFeign,long sno ,String outsideOrderId, int shiduan , Date begin ,Date end , | |
| 275 | - int isMonDay ,int isTuesDay , int isWednesDay ,int isThursDay , int isFriday , | |
| 276 | - int isSaturDay , int isWeekend , String shiqu){ | |
| 277 | - List<Long> resultList = new ArrayList<>(); | |
| 278 | - WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 279 | - pkt.iDevSn = sno; | |
| 280 | - try{ | |
| 281 | - pkt.Reset(); | |
| 282 | - pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 283 | - String[] shiQuArray = shiqu.split(","); | |
| 284 | - int shiDuanCount = shiQuArray.length / 6 ; | |
| 285 | - for (int i = 0; i < shiDuanCount; i++){ | |
| 286 | - if (i == 0) { | |
| 287 | - pkt.data[0] = WGUtils.toHex(shiduan+""); | |
| 288 | - } else { | |
| 289 | - pkt.data[0] = WGUtils.toHex((shiduan+20*i)+""); | |
| 290 | - } | |
| 291 | - Calendar c = Calendar.getInstance(); | |
| 292 | - c.setTime(begin); | |
| 293 | - //开始时间 20 19 01 01 | |
| 294 | - pkt.data[1] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(0,2)); | |
| 295 | - pkt.data[2] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(2,4)); | |
| 296 | - pkt.data[3] = WGUtils.toHex(String.valueOf(c.get(Calendar.MONTH)+1)); | |
| 297 | - pkt.data[4] = WGUtils.toHex(String.valueOf(c.get(Calendar.DATE))); | |
| 298 | - //结束时间 | |
| 299 | - c.setTime(end); | |
| 300 | - pkt.data[5] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(0,2)); | |
| 301 | - pkt.data[6] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(2,4)); | |
| 302 | - pkt.data[7] = WGUtils.toHex(String.valueOf(c.get(Calendar.MONTH)+1)); | |
| 303 | - pkt.data[8] = WGUtils.toHex(String.valueOf(c.get(Calendar.DATE))); | |
| 304 | - //星期几 有效 | |
| 305 | - pkt.data[9] = WGUtils.toHex(String.valueOf(isMonDay)); | |
| 306 | - pkt.data[10] = WGUtils.toHex(String.valueOf(isTuesDay)); | |
| 307 | - pkt.data[11] = WGUtils.toHex(String.valueOf(isWednesDay)); | |
| 308 | - pkt.data[12] = WGUtils.toHex(String.valueOf(isThursDay)); | |
| 309 | - pkt.data[13] = WGUtils.toHex(String.valueOf(isFriday)); | |
| 310 | - pkt.data[14] = WGUtils.toHex(String.valueOf(isSaturDay)); | |
| 311 | - pkt.data[15] = WGUtils.toHex(String.valueOf(isWeekend)); | |
| 312 | - //有效时区 | |
| 313 | - pkt.data[16] = WGUtils.toHex(shiQuArray[i * 6 + 0].substring(0, 2)); | |
| 314 | - pkt.data[17] = WGUtils.toHex(shiQuArray[i * 6 + 0].substring(3, 5)); | |
| 315 | - | |
| 316 | - pkt.data[18] = WGUtils.toHex(shiQuArray[i * 6 + 1].substring(0, 2)); | |
| 317 | - pkt.data[19] = WGUtils.toHex(shiQuArray[i * 6 + 1].substring(3, 5)); | |
| 318 | - | |
| 319 | - pkt.data[20] = WGUtils.toHex(shiQuArray[i * 6 + 2].substring(0, 2)); | |
| 320 | - pkt.data[21] = WGUtils.toHex(shiQuArray[i * 6 + 2].substring(3, 5)); | |
| 321 | - | |
| 322 | - pkt.data[22] = WGUtils.toHex(shiQuArray[i * 6 + 3].substring(0, 2)); | |
| 323 | - pkt.data[23] = WGUtils.toHex(shiQuArray[i * 6 + 3].substring(3, 5)); | |
| 324 | - | |
| 325 | - pkt.data[24] = WGUtils.toHex(shiQuArray[i * 6 + 4].substring(0, 2)); | |
| 326 | - pkt.data[25] = WGUtils.toHex(shiQuArray[i * 6 + 4].substring(3, 5)); | |
| 327 | - | |
| 328 | - pkt.data[26] = WGUtils.toHex(shiQuArray[i * 6 + 5].substring(0, 2)); | |
| 329 | - pkt.data[27] = WGUtils.toHex(shiQuArray[i * 6 + 5].substring(3, 5)); | |
| 330 | - if (shiDuanCount != 1) { | |
| 331 | - //需要链接时段 | |
| 332 | - if (i != shiDuanCount - 1) { | |
| 333 | - //只要不是最后一个时段 | |
| 334 | - pkt.data[28] = WGUtils.toHex((shiduan+20*(i+1)+"")); | |
| 335 | - } else { | |
| 336 | - pkt.data[28] = 0; | |
| 337 | - } | |
| 338 | - } else { | |
| 339 | - pkt.data[28] = 0; | |
| 340 | - } | |
| 341 | - byte[] bytes = pkt.toByte(); | |
| 342 | - long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 343 | - long result = insert(xaFeign,sno+"",outsideOrderId,null,index,bytes); | |
| 344 | - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 345 | - resultList.add(result); | |
| 346 | - } | |
| 347 | - return resultList ; | |
| 348 | - }catch (Exception e){ | |
| 349 | - Log_error.error(e.toString()); | |
| 350 | - } | |
| 351 | - return resultList; | |
| 352 | - } | |
| 353 | - | |
| 354 | - | |
| 355 | - //设置权限 | |
| 356 | - public static long SetSignalCardInfo(XaFeign xaFeign,long sno , String outsideOrderId, String cardNo , int shiduan , Date begin , Date end){ | |
| 357 | - WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 358 | - pkt.iDevSn = sno; | |
| 359 | - try{ | |
| 360 | - pkt.Reset(); | |
| 361 | - pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 362 | - pkt.iDevSn = sno; | |
| 363 | - //0D D7 37 00 | |
| 364 | - pkt.data[0] = WGUtils.toHex(cardNo.substring(0,2)); | |
| 365 | - pkt.data[1] = WGUtils.toHex(cardNo.substring(2,4)); | |
| 366 | - pkt.data[2] = WGUtils.toHex(cardNo.substring(4,6)); | |
| 367 | - pkt.data[3] = WGUtils.toHex(cardNo.substring(6,8)); | |
| 368 | - | |
| 369 | - //20 10 01 01 起始日期: 2010年01月01日 (必须大于2001年) | |
| 370 | - Calendar c = Calendar.getInstance(); | |
| 371 | - c.setTime(begin); | |
| 372 | - pkt.data[4] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(0,2)); | |
| 373 | - pkt.data[5] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(2,4)); | |
| 374 | - pkt.data[6] = WGUtils.toHex(String.valueOf(c.get(Calendar.MONTH)+1)); | |
| 375 | - pkt.data[7] = WGUtils.toHex(String.valueOf(c.get(Calendar.DATE))); | |
| 376 | - //20 29 12 31 截止日期: 2029年12月31日 | |
| 377 | - c.setTime(end); | |
| 378 | - pkt.data[8] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(0,2)); | |
| 379 | - pkt.data[9] = WGUtils.toHex(String.valueOf(c.get(Calendar.YEAR)).substring(2,4)); | |
| 380 | - pkt.data[10] = WGUtils.toHex(String.valueOf(c.get(Calendar.MONTH)+1)); | |
| 381 | - pkt.data[11] = WGUtils.toHex(String.valueOf(c.get(Calendar.DATE))); | |
| 382 | - //01 允许通过 一号门 [对单门, 双门, 四门控制器有效] | |
| 383 | - pkt.data[12] = WGUtils.toHex(shiduan+""); | |
| 384 | - //01 允许通过 二号门 [对双门, 四门控制器有效] | |
| 385 | - pkt.data[13] = WGUtils.toHex(shiduan+""); | |
| 386 | - //01 允许通过 三号门 [对四门控制器有效] | |
| 387 | - pkt.data[14] = WGUtils.toHex(shiduan+""); | |
| 388 | - //01 允许通过 四号门 [对四门控制器有效] | |
| 389 | - pkt.data[15] = WGUtils.toHex(shiduan+""); | |
| 390 | - byte[] bytes = pkt.toByte(); | |
| 391 | - long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 392 | - long result = insert(xaFeign,sno+"",outsideOrderId,cardNo,index,bytes); | |
| 393 | - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 394 | - return result ; | |
| 395 | - }catch (Exception e){ | |
| 396 | - Log_error.error(e.toString()); | |
| 397 | - } | |
| 398 | - return 0l; | |
| 399 | - } | |
| 400 | - | |
| 401 | - //删除单张卡权限 | |
| 402 | - public static long clearSinglePower(XaFeign xaFeign,long sno ,String outsideOrderId, String cardNo){ | |
| 403 | - WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 404 | - pkt.iDevSn = sno; | |
| 405 | - try{ | |
| 406 | - pkt.Reset(); | |
| 407 | - pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 408 | - pkt.iDevSn = sno; | |
| 409 | - pkt.data[0] = WGUtils.toHex(cardNo.substring(0,2)); | |
| 410 | - pkt.data[1] = WGUtils.toHex(cardNo.substring(2,4)); | |
| 411 | - pkt.data[2] = WGUtils.toHex(cardNo.substring(4,6)); | |
| 412 | - pkt.data[3] = WGUtils.toHex(cardNo.substring(6,8)); | |
| 413 | - byte[] bytes = pkt.toByte(); | |
| 414 | - long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 415 | - long result = insert(xaFeign,sno+"",outsideOrderId,cardNo,index,bytes); | |
| 416 | - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 417 | - return result ; | |
| 418 | - }catch (Exception e){ | |
| 419 | - Log_error.error(e.toString()); | |
| 420 | - } | |
| 421 | - return 0l; | |
| 422 | - } | |
| 423 | - | |
| 424 | - //删除全部权限 | |
| 425 | - public static long clearAllPower(XaFeign xaFeign,long sno ,String outsideOrderId){ | |
| 426 | - WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 427 | - pkt.iDevSn = sno; | |
| 428 | - try{ | |
| 429 | - pkt.Reset(); | |
| 430 | - pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 431 | - pkt.iDevSn = sno; | |
| 432 | - pkt.data[0] = (byte) 0x55 ; | |
| 433 | - pkt.data[1] = (byte) 0xAA ; | |
| 434 | - pkt.data[2] = (byte) 0xAA ; | |
| 435 | - pkt.data[3] = (byte) 0x55 ; | |
| 436 | - byte[] bytes = pkt.toByte(); | |
| 437 | - long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 438 | - long result = insert(xaFeign,sno+"",outsideOrderId,null,index,bytes); | |
| 439 | - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 440 | - return result ; | |
| 441 | - }catch (Exception e){ | |
| 442 | - Log_error.error(e.toString()); | |
| 443 | - } | |
| 444 | - return 0l; | |
| 445 | - } | |
| 446 | - | |
| 447 | - //查询卡权限 | |
| 448 | - public static long searchPower(XaFeign xaFeign,long sno ,String outsideOrderId, String cardNo){ | |
| 449 | - WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 450 | - pkt.iDevSn = sno; | |
| 451 | - try{ | |
| 452 | - pkt.Reset(); | |
| 453 | - pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 454 | - pkt.iDevSn = sno; | |
| 455 | - pkt.data[0] = WGUtils.toHex(cardNo.substring(0,2)); | |
| 456 | - pkt.data[1] = WGUtils.toHex(cardNo.substring(2,4)); | |
| 457 | - pkt.data[2] = WGUtils.toHex(cardNo.substring(4,6)); | |
| 458 | - pkt.data[3] = WGUtils.toHex(cardNo.substring(6,8)); | |
| 459 | - byte[] bytes = pkt.toByte(); | |
| 460 | - long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 461 | - long result = insert(xaFeign,sno+"",outsideOrderId,cardNo,index,bytes); | |
| 462 | - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 463 | - return result ; | |
| 464 | - }catch (Exception e){ | |
| 465 | - Log_error.error(e.toString()); | |
| 466 | - } | |
| 467 | - return 0l; | |
| 468 | - } | |
| 469 | - | |
| 470 | - //删除时段 | |
| 471 | - public static long clearShiDuan(XaFeign xaFeign,long sno , String outsideOrderId){ | |
| 472 | - WgUdpCommShort pkt = new WgUdpCommShort(); | |
| 473 | - pkt.iDevSn = sno; | |
| 474 | - try{ | |
| 475 | - pkt.Reset(); | |
| 476 | - pkt.functionID = WGUtils.toFunctionHex(outsideOrderId); | |
| 477 | - pkt.iDevSn = sno; | |
| 478 | - pkt.data[0] = (byte) 0x55 ; | |
| 479 | - pkt.data[1] = (byte) 0xAA ; | |
| 480 | - pkt.data[2] = (byte) 0xAA ; | |
| 481 | - pkt.data[3] = (byte) 0x55 ; | |
| 482 | - byte[] bytes = pkt.toByte(); | |
| 483 | - long index = WgUdpCommShort.getXidOfCommand(bytes); | |
| 484 | - long result = insert(xaFeign,sno+"",outsideOrderId,null,index,bytes); | |
| 485 | - pkt.run(watchingShortHandler.getSessionMap().get(sno),bytes); | |
| 486 | - return result ; | |
| 487 | - }catch (Exception e){ | |
| 488 | - Log_error.error(e.toString()); | |
| 489 | - } | |
| 490 | - return 0l; | |
| 491 | - } | |
| 492 | - | |
| 493 | - private static long insert(XaFeign xaFeign ,String sn ,String functionId , String cardNo , long index , byte[] recv){ | |
| 494 | - | |
| 495 | - StringBuffer send = new StringBuffer(); | |
| 496 | - for(byte b : recv){ | |
| 497 | - send.append(WGUtils.byte2Hex(b)).append("-"); | |
| 498 | - } | |
| 499 | - SendMessageDto sendMessage = new SendMessageDto(); | |
| 500 | - sendMessage.setDeviceId(sn); | |
| 501 | - sendMessage.setFunctionId(Integer.toHexString(Integer.valueOf(functionId))); | |
| 502 | - sendMessage.setIndex(index); | |
| 503 | - sendMessage.setCardNo(cardNo); | |
| 504 | - sendMessage.setCreateTime(new Date()); | |
| 505 | - sendMessage.setSend(send.toString().substring(0,send.toString().length()-1)); | |
| 506 | - xaFeign.insertMessage(sendMessage); | |
| 507 | - return sendMessage.getId(); | |
| 508 | - } | |
| 509 | -} |
cloud/weigeng/src/main/java/com/sincere/weigeng/utils/WgUdpCommShort.java
| ... | ... | @@ -61,7 +61,7 @@ public class WgUdpCommShort { //短报文协议 |
| 61 | 61 | _Global_xid++; |
| 62 | 62 | _xid = _Global_xid; //新的值 |
| 63 | 63 | } |
| 64 | - static long getXidOfCommand(byte[] cmd) //获取指令中的xid | |
| 64 | + public static long getXidOfCommand(byte[] cmd) //获取指令中的xid | |
| 65 | 65 | { |
| 66 | 66 | long ret = -1; |
| 67 | 67 | if (cmd.length >= WGPacketSize) | ... | ... |