博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
netty
阅读量:5332 次
发布时间:2019-06-15

本文共 5085 字,大约阅读时间需要 16 分钟。

 

 

package com.hikvision.cloud.iep.network.task; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import io.netty.channel.ChannelHandlerContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import com.google.protobuf.ByteString; import com.hikvision.cloud.fastdfs.service.IUploadService; import com.hikvision.cloud.iep.network.ResultCodeType; import com.hikvision.cloud.iep.network.constant.Constants; import com.hikvision.cloud.iep.network.entity.PasscarInfo; import com.hikvision.cloud.iep.network.netty.cache.CacheService; import com.hikvision.cloud.iep.network.netty.handle.TcpServerHandler; import com.hikvision.cloud.iep.network.pb.CommunicationProto.CommandType; import com.hikvision.cloud.iep.network.pb.CommunicationProto.PassCarMsg; import com.hikvision.cloud.iep.network.pb.CommunicationProto.PassCarRecord; import com.hikvision.cloud.iep.network.pb.CommunicationProto.ProtocolMessage; import com.hikvision.cloud.iep.network.service.IDbOperService; @Component("passcarTask") @Scope("prototype") public class PasscarTask implements Runnable {
private static Logger logger = LoggerFactory.getLogger(PasscarTask.class); private ChannelHandlerContext ctx; private PassCarMsg passCarMsg; private long seqId; @Resource TcpServerHandler tcpServerHandler; @Resource IUploadService uploadService; @Resource IDbOperService dbOperServiceImpl; @Resource CacheService cacheService; public PasscarTask setPassCarMsg(PassCarMsg passCarMsg) {
this.passCarMsg = passCarMsg; return this; } public PasscarTask setCtx(ChannelHandlerContext ctx) {
this.ctx = ctx; return this; } public PasscarTask setSeqId(long seqId) {
this.seqId = seqId; return this; } @Override public void run() {
String gatewayNO = passCarMsg.getGatewayNO(); logger.info("过车消息请求, 网关的编号:" + gatewayNO + " 消息的序号:" + seqId); int msgstatus = ResultCodeType.SUCCESS.value(); List
passCarRecordList = passCarMsg.getPassCarRecordList(); try {
if (passCarRecordList != null && passCarRecordList.size() > 0) {
PasscarInfo passcarInfo = null; List
passcarInfoList = new ArrayList
(); String group = cacheService.findGroupByType(Constants.PASSCAR_TYPE); for (PassCarRecord passCarRecord : passCarRecordList) {
passcarInfo = new PasscarInfo(); ByteString imgcardData = passCarRecord.getCardNumPicData(); // 车牌图片 if (imgcardData != null && imgcardData.size() > 0) {
byte[] imgcardBuf = imgcardData.toByteArray(); String imgcardName = passCarRecord.getClientId() + ".jpg"; String imgcardURL = uploadService.upLoad(group,imgcardBuf, imgcardName); passcarInfo.setImgcardURL(imgcardURL); } ByteString imgCarData = passCarRecord.getCarPicData(); //车辆图片 if (imgCarData != null && imgCarData.size() > 0) {
byte[] imgCarBuf = imgCarData.toByteArray(); String imgCarName = passCarRecord.getClientId() + ".jpg"; String imgCarURL = uploadService.upLoad(group,imgCarBuf, imgCarName); passcarInfo.setImgURL(imgCarURL); } passcarInfo.setClientId(passCarRecord.getClientId()); passcarInfo.setCardNum(passCarRecord.getCardNum()); passcarInfo.setCardNo(passCarRecord.getCardNo()); passcarInfo.setPasstime(new Timestamp(passCarRecord.getCrossTime()/1000*1000)); passcarInfo.setParkNo(passCarRecord.getParkNo()); passcarInfo.setCarColor(passCarRecord.getCarColor().getNumber()); passcarInfo.setCarType(passCarRecord.getCarType().getNumber()); passcarInfo.setDirection(passCarRecord.getCarDirection().getNumber()); passcarInfo.setUserName(passCarRecord.getUserName()); passcarInfo.setParkingType(passCarRecord.getParkingType()); passcarInfoList.add(passcarInfo); } int size = dbOperServiceImpl.savePasscarList(passcarInfoList, gatewayNO, Constants.PASSCARTABLENAME); logger.info("过车消息存储成功, 网关的编号:" + gatewayNO + " 消息的序号:" + seqId + " size:" + size+",收到条数:"+passCarRecordList.size()); } } catch (Exception e) {
msgstatus = ResultCodeType.FAIL.value(); logger.info("过车消息存储失败, 网关的编号:" + gatewayNO + " 消息的序号:" + seqId + " 异常原因: " + e ); } ProtocolMessage protoMsg = tcpServerHandler.buildResponse(CommandType.PASSCAR_RESP, msgstatus, seqId); logger.info("过车消息响应序号:" + seqId + ",网关编号: " + gatewayNO +",状态:"+msgstatus); ctx.writeAndFlush(protoMsg); } }

转载于:https://www.cnblogs.com/xjatj/p/9828927.html

你可能感兴趣的文章
Data Structure 基本概念
查看>>
Ubuntu改坏sudoers后无法使用sudo的解决办法
查看>>
NEYC 2017 游记
查看>>
【BZOJ 3669】 [Noi2014]魔法森林 LCT维护动态最小生成树
查看>>
[搬运] 写给 C# 开发人员的函数式编程
查看>>
vsftpd虚拟用户【公司系统部分享】
查看>>
Python之旅Day14 JQuery部分
查看>>
core--线程池
查看>>
redux-effect
查看>>
Swift和OC混编
查看>>
Android轻量级的开源缓存框架ASimpleCache
查看>>
他山之石:加载图片的一个小问题
查看>>
shell - 常识
查看>>
mssql sqlserver 使用sql脚本 清空所有数据库表数据的方法分享
查看>>
分层图最短路【bzoj2763】: [JLOI2011]飞行路线
查看>>
linux下编译复数类型引发的错误:expected unqualified-id before '(' token
查看>>
codeforces 1041A Heist
查看>>
字典常用方法
查看>>
Spring Cloud Stream消费失败后的处理策略(三):使用DLQ队列(RabbitMQ)
查看>>
python的猴子补丁monkey patch
查看>>