| | |
| | | package com.zy.core.netty.handle; |
| | | |
| | | import com.core.common.Cools; |
| | | import com.zy.core.Slave; |
| | | import com.zy.core.cache.SlaveConnection; |
| | | import com.zy.core.enums.SlaveType; |
| | | import com.baomidou.mybatisplus.mapper.EntityWrapper; |
| | | import com.core.common.DateUtils; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.entity.FireLog; |
| | | import com.zy.asrs.entity.LocMast; |
| | | import com.zy.asrs.service.FireLogService; |
| | | import com.zy.asrs.service.LocMastService; |
| | | import com.zy.asrs.service.impl.MainServiceImpl; |
| | | import com.zy.asrs.utils.Utils; |
| | | import com.zy.core.netty.AbstractInboundHandler; |
| | | import com.zy.core.netty.cache.ChannelCache; |
| | | import com.zy.core.netty.constant.Constant; |
| | | import com.zy.core.netty.constant.FireDataType; |
| | | import com.zy.core.netty.domain.ChPackage; |
| | | import com.zy.core.netty.properties.TcpProperties; |
| | | import com.zy.core.properties.SlaveProperties; |
| | | import com.zy.core.thread.BarcodeThread; |
| | | import com.zy.core.netty.domain.fire.Fire_3030; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelHandler; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 国标业务处理handler |
| | |
| | | public class PackageServerHandler extends AbstractInboundHandler<ChPackage> { |
| | | |
| | | @Autowired |
| | | private SlaveProperties slaveProperties; |
| | | @Autowired |
| | | private TcpProperties tcpProperties; |
| | | private MainServiceImpl mainService; |
| | | |
| | | @Override |
| | | protected boolean channelRead0(ChannelHandlerContext ctx, ChPackage pac) { |
| | | // log.info("读码器【IP:{}】 上行数据 ===>> {}", pac.getIp(), pac.getAscii()); |
| | | // //扫码上传数据格式必须2个#开头,如:##12345678 |
| | | // String msg = pac.getAscii().replaceAll("#", ""); |
| | | // if(!Cools.isEmpty(msg) && msg.length()>=tcpProperties.getBarcodeLen()){ |
| | | // msg = msg.substring(0,tcpProperties.getBarcodeLen()); |
| | | // |
| | | // for (Slave slave : slaveProperties.getBarcode()) { |
| | | // if (slave.getIp().equals(pac.getIp())) { |
| | | // BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, slave.getId()); |
| | | // if (barcodeThread == null) { continue; } |
| | | // barcodeThread.setBarcode(msg); |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | FireDataType dataType = FireDataType.get(pac.getBytes()[1], pac.getBytes()[2]); |
| | | Fire_3030 fire3030 = new Fire_3030().readFromBytes(pac.getBytes()); |
| | | switch (dataType) { |
| | | case HEARTBEAT: |
| | | ChannelCache.setChannel(String.valueOf(fire3030.getNo()), ctx.channel()); |
| | | Constant.errorMap.remove(fire3030.getNo()); |
| | | break; |
| | | case FIRE_ALARM: |
| | | //消防IO点编号 |
| | | String fireNo = fire3030.getNo().toString() + fire3030.getLoop().toString() + fire3030.getPartNo().toString(); |
| | | String fireTime = "20" + fire3030.getYear() + "-" + fire3030.getMonth() + "-" + fire3030.getDay() |
| | | + " " + fire3030.getHour() + ":" + fire3030.getMinute() + ":" + fire3030.getSeconds(); |
| | | Date dt = DateUtils.convert(fireTime); |
| | | LocMastService locMastService = SpringUtils.getBean(LocMastService.class); |
| | | if(null != locMastService){ |
| | | //报警信号更新到库存主档 fire_status字段 |
| | | LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("fire_no",fireNo)); |
| | | if(null != locMast){ |
| | | if(locMast.getFireStatus() != 1) { |
| | | locMast.setFireStatus(1); |
| | | locMast.setModiTime(new Date()); |
| | | locMastService.update(locMast, new EntityWrapper<LocMast>().eq("fire_no", fireNo)); |
| | | } |
| | | |
| | | //插入报警日志记录,同一库位同一报警只插入一次 |
| | | FireLogService fireLogService = SpringUtils.getBean(FireLogService.class); |
| | | if(null != fireLogService){ |
| | | String ymd = "20" + fire3030.getYear() + "" + fire3030.getMonth() + "" + fire3030.getDay(); |
| | | FireLog one = fireLogService.selectOne(new EntityWrapper<FireLog>() |
| | | .eq("ymd",ymd) |
| | | .eq("fire_no",fireNo)); |
| | | if(null == one) { |
| | | FireLog fireLog = new FireLog(); |
| | | fireLog.setYmd(ymd); |
| | | fireLog.setFireNo(fireNo); |
| | | fireLog.setFireTime(dt); |
| | | fireLog.setLocNo(locMast.getLocNo()); |
| | | fireLog.setCreateTime(new Date()); |
| | | fireLogService.insert(fireLog); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | |
| | | } |
| | | channel.writeAndFlush(chPackage); |
| | | } |
| | | |
| | | /**************************************** 测试专用 *****************************************/ |
| | | public static void main(String[] args){ |
| | | byte[] bytes = new byte[]{(byte)0x82, 0x38, 0x30, 0x32, 0x34, 0x30, 0x38, 0x39, 0x3B, 0x30, 0x31, 0x31, 0x31, |
| | | 0x30, 0x33, 0x30, 0x38, 0x31, 0x30, 0x30, 0x34, 0x30, 0x38, 0x38, 0x30, (byte)0x83}; |
| | | Fire_3030 fire3030 = new Fire_3030().readFromBytes(bytes); |
| | | String now = "20" + fire3030.getYear() + "-" + fire3030.getMonth() + "-" + fire3030.getDay() |
| | | + " " + fire3030.getHour() + ":" + fire3030.getMinute() + ":" + fire3030.getSeconds(); |
| | | //消防IO点编号 |
| | | String fireNo = fire3030.getNo().toString() + fire3030.getLoop().toString() + fire3030.getPartNo().toString(); |
| | | System.out.println(fireNo); |
| | | String aa=""; |
| | | } |
| | | } |