6 files modified
1 files renamed
9 files added
8 files deleted
| | |
| | | |
| | | import org.springblade.core.cloud.feign.EnableBladeFeign; |
| | | import org.springblade.core.launch.BladeApplication; |
| | | import org.springblade.jfpt.nettyServer.Server; |
| | | import org.springblade.jfpt.nettyTcpServer.TcpServer; |
| | | import org.springblade.jfpt.nettyUdpServer.server.UdpServer; |
| | | import org.springframework.boot.CommandLineRunner; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | |
| | |
| | | @Override |
| | | public void run(String... args) throws Exception { |
| | | //Server server=new Server(8088); |
| | | TcpServer server=new TcpServer(8088); |
| | | TcpServer server=new TcpServer(8099); //测试用 |
| | | //UdpServer udpServer=new UdpServer(8099); |
| | | } |
| | | |
| New file |
| | |
| | | package org.springblade.jfpt.animalheat.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.jfpt.animalheat.entity.BladeAnimalHeat; |
| | | import org.springblade.jfpt.animalheat.service.AnimalHeatService; |
| | | import org.springblade.jfpt.animalheat.vo.AnimalHeatVo; |
| | | import org.springblade.jfpt.animalheat.vo.StatisVo; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 体温监测控制层 |
| | | * @time 2021-2-25 |
| | | */ |
| | | |
| | | @RestController |
| | | @RequestMapping("animalHeat/animalHeat") |
| | | @AllArgsConstructor |
| | | public class AnimalHeatController { |
| | | |
| | | private final AnimalHeatService animalHeatService; |
| | | |
| | | /** |
| | | * 获取体温数据统计 |
| | | * @param animalHeatVo 条件参数 开始时间,结束时间 |
| | | * @return |
| | | */ |
| | | @GetMapping("/getAnimalStatis") |
| | | public List<StatisVo> getAnimalStatis(AnimalHeatVo animalHeatVo){ |
| | | return animalHeatService.getAnimalStatis(animalHeatVo); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 体温数据的分页数据 |
| | | * @param animalHeatVo 查询条件 |
| | | * @param query 查询页码 |
| | | * @return |
| | | */ |
| | | @GetMapping("/page") |
| | | @ApiOperationSupport(order = 3) |
| | | public R<IPage<BladeAnimalHeat>> page(AnimalHeatVo animalHeatVo, Query query) { |
| | | return R.data(animalHeatService.selectAnimalHeatPage(Condition.getPage(query), animalHeatVo)); |
| | | } |
| | | |
| | | } |
| File was renamed from blade-service/blade-jfpts/src/main/java/org/springblade/jfpt/nettyUdpServer/entity/BladeAnimalHeat.java |
| | |
| | | package org.springblade.jfpt.nettyUdpServer.entity; |
| | | package org.springblade.jfpt.animalheat.entity; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Integer id;// bigint(20) NOT NULL COMMENT '主键', |
| | | |
| | | //private Integer method;// int(1) NOT NULL COMMENT '方法名: 0 表示 infrared_aiom_picture 图片数据, 1 表示 engine_echo 心跳包 ', |
| | | private Integer method;// int(1) NOT NULL COMMENT '方法名: 0 表示 infrared_aiom_picture 图片数据, 1 表示 engine_echo 心跳包 ', |
| | | |
| | | private String ip;// varchar(63) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '设备IP地址', |
| | | |
| | |
| | | @TableField("temp_red") |
| | | private Float tempRed;// float(4,2) DEFAULT NULL COMMENT '当前人员的温度', |
| | | |
| | | @TableField("person_rect") |
| | | private String[] personRect;// varchar(63) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '人脸位置二位数组,[left,top,right,bottom]', |
| | | @TableField(value = "person_rect") |
| | | private String personRect;// varchar(63) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '人脸位置二位数组,[left,top,right,bottom]', |
| | | |
| | | @TableField("person_rect_red") |
| | | private Integer[] personRectRed;// varchar(63) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '红外人脸位置二位数组,[left,top,right,bottom]', |
| | | private String personRectRed;// varchar(63) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '红外人脸位置二位数组,[left,top,right,bottom]', |
| | | |
| | | @TableField("create_time") |
| | | private Date createTime;// datetime DEFAULT NULL COMMENT '创建时间', |
| | | |
| | | private Integer status;//状态 1为高温 0为正常 ,以37度为标准,大于37度为高温 |
| | | |
| | | } |
| New file |
| | |
| | | package org.springblade.jfpt.animalheat.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import org.springblade.jfpt.animalheat.entity.BladeAnimalHeat; |
| | | import org.springblade.jfpt.animalheat.vo.AnimalHeatVo; |
| | | import org.springblade.jfpt.animalheat.vo.StatisVo; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * mapper 映射层 |
| | | * |
| | | */ |
| | | public interface AnimalHeatMapper extends BaseMapper<BladeAnimalHeat> { |
| | | /** |
| | | * 获取体温数据统计 --当天 |
| | | * @return |
| | | */ |
| | | List<StatisVo> getAnimalStatis(); |
| | | |
| | | /** |
| | | * 获取体温数据统计 --本周 |
| | | * @return |
| | | */ |
| | | List<StatisVo> getAnimalStatisWeek(); |
| | | |
| | | /** |
| | | * 体温数据的分页数据 |
| | | * @param animalHeatVo 查询条件 |
| | | * @param page 查询页码 |
| | | * @return |
| | | */ |
| | | List<BladeAnimalHeat> selectAnimalHeatPageList(IPage<BladeAnimalHeat> page, AnimalHeatVo animalHeatVo); |
| | | } |
| New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="org.springblade.jfpt.animalheat.mapper.AnimalHeatMapper"> |
| | | |
| | | <!--查询当天体温数据统计--> |
| | | <select id="getAnimalStatis" resultType="org.springblade.jfpt.animalheat.vo.StatisVo"> |
| | | SELECT 1 `status`,count(`status`) number FROM `blade_animal_heat` where |
| | | TO_DAYS(create_time)=TO_DAYS(now()) and `status`=1 |
| | | UNION |
| | | SELECT 0 `status`,count(`status`) number FROM `blade_animal_heat` where |
| | | TO_DAYS(create_time)=TO_DAYS(now()) and `status`=0 |
| | | </select> |
| | | |
| | | <!--获取本周的体温统计数据--> |
| | | <select id="getAnimalStatisWeek" resultType="org.springblade.jfpt.animalheat.vo.StatisVo"> |
| | | SELECT 1 `status`,count(`status`) number FROM `blade_animal_heat` where |
| | | YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now()) and `status`=1 |
| | | UNION |
| | | SELECT 0 `status`,count(`status`) number FROM `blade_animal_heat` where |
| | | YEARWEEK(date_format(create_time,'%Y-%m-%d')) = YEARWEEK(now()) and `status`=0 |
| | | </select> |
| | | |
| | | <select id="selectAnimalHeatPageList" resultType="org.springblade.jfpt.animalheat.entity.BladeAnimalHeat"> |
| | | SELECT * FROM blade_animal_heat |
| | | <if test="animalHeatVo.begTime!=null and animalHeatVo.begTime!=''"> |
| | | and create_time >=#{animalHeatVo.begTime} |
| | | </if> |
| | | <if test="animalHeatVo.endTime!=null and animalHeatVo.endTime!=''"> |
| | | and create_time <=#{animalHeatVo.endTime} |
| | | </if> |
| | | ORDER BY create_time asc |
| | | </select> |
| | | |
| | | </mapper> |
| New file |
| | |
| | | package org.springblade.jfpt.animalheat.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import org.springblade.jfpt.animalheat.entity.BladeAnimalHeat; |
| | | import org.springblade.jfpt.animalheat.vo.AnimalHeatVo; |
| | | import org.springblade.jfpt.animalheat.vo.StatisVo; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 体温监测服务层接口层 |
| | | */ |
| | | public interface AnimalHeatService extends IService<BladeAnimalHeat> { |
| | | /** |
| | | * 插入体温数据 |
| | | * @param body 温度数据 |
| | | */ |
| | | void save(String body); |
| | | |
| | | /** |
| | | * 获取体温数据统计 |
| | | * @param animalHeatVo 条件参数 开始时间,结束时间 |
| | | * @return |
| | | */ |
| | | List<StatisVo> getAnimalStatis(AnimalHeatVo animalHeatVo); |
| | | |
| | | /** |
| | | * 体温数据的分页数据 |
| | | * @param animalHeatVo 查询条件 |
| | | * @param page 查询页码 |
| | | * @return |
| | | */ |
| | | IPage<BladeAnimalHeat> selectAnimalHeatPage(IPage<BladeAnimalHeat> page, AnimalHeatVo animalHeatVo); |
| | | } |
| New file |
| | |
| | | package org.springblade.jfpt.animalheat.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springblade.jfpt.animalheat.entity.BladeAnimalHeat; |
| | | import org.springblade.jfpt.animalheat.mapper.AnimalHeatMapper; |
| | | import org.springblade.jfpt.animalheat.service.AnimalHeatService; |
| | | import org.springblade.jfpt.animalheat.util.ImageUtil; |
| | | import org.springblade.jfpt.animalheat.vo.AnimalHeatVo; |
| | | import org.springblade.jfpt.animalheat.vo.StatisVo; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.validation.Valid; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import static org.springblade.core.tool.utils.DateUtil.now; |
| | | |
| | | /** |
| | | * 体温数据服务层 |
| | | * |
| | | */ |
| | | @Service |
| | | public class AnimalHeatServiceImpl extends ServiceImpl<AnimalHeatMapper, BladeAnimalHeat> implements AnimalHeatService { |
| | | @Override |
| | | public boolean save(BladeAnimalHeat entity) { |
| | | return false; |
| | | } |
| | | |
| | | @Value("${picture.addUrl}") |
| | | private String picAddUrl; |
| | | |
| | | @Value("${picture.pre}") |
| | | private String picPre; |
| | | |
| | | |
| | | /** |
| | | * 新增体温数据 |
| | | * @param body 体温数据 |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public void save(String body) { |
| | | //1.截取信息 |
| | | int i = body.indexOf("{"); |
| | | //2.从 { 处开始截取 |
| | | int length = body.length(); |
| | | //3.截取,由于获取数据时,} 被去除,需要加上 |
| | | String dataBody = body.substring(i, length)+"}"; |
| | | System.out.println("dataBody = " + dataBody); |
| | | //4.数据转换 |
| | | Map<String,Object> data = (Map<String, Object>) JSONObject.parse(dataBody); |
| | | System.out.println("data = " + data); |
| | | //5.创建体温数据对象 |
| | | BladeAnimalHeat bladeAnimalHeat = new BladeAnimalHeat(); |
| | | //6.取出数据,封装数据到对象 |
| | | String picture = data.get("picture").toString(); |
| | | //将二进制原始图片转换成图片 |
| | | ImageUtil.base64StringToImage(picture); |
| | | //bladeAnimalHeat.setPicture(data.get("picture").toString()); //暂时不存入 |
| | | String temp_red =data.get("temp_red").toString(); |
| | | String[] temRedArr = temp_red.substring(1,temp_red.length()-1).split(","); |
| | | if (temRedArr.length>1){ |
| | | //比较两个温度的大小,取大的值 |
| | | float v = Float.parseFloat(temRedArr[0]); |
| | | float v1 = Float.parseFloat(temRedArr[1]); |
| | | int compare = Float.compare(v, v1); |
| | | bladeAnimalHeat.setTempRed(compare>=0 ? v:v1); |
| | | //和标志温度比较,大于37度为高温,标记为1,小于则为正常0 |
| | | int compare1 = Float.compare(37, compare >= 0 ? v : v1); |
| | | bladeAnimalHeat.setStatus(compare1>0 ?0:1); |
| | | }else { |
| | | bladeAnimalHeat.setTempRed(Float.parseFloat(temRedArr[0])); |
| | | int compare1 = Float.compare(37, Float.parseFloat(temRedArr[0])); |
| | | bladeAnimalHeat.setStatus(compare1>0 ?0:1); |
| | | } |
| | | String person_rects = data.get("person_rect").toString(); |
| | | bladeAnimalHeat.setPersonRect(person_rects.substring(2,person_rects.length()-2)); |
| | | bladeAnimalHeat.setCreateTime(now()); |
| | | //7.插入数据 |
| | | int idata = baseMapper.insert(bladeAnimalHeat); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取体温数据统计 |
| | | * @param animalHeatVo 条件参数 开始时间,结束时间 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<StatisVo> getAnimalStatis(AnimalHeatVo animalHeatVo) { |
| | | if(null!= animalHeatVo.getStatus()){ |
| | | //查询当天的统计数据 |
| | | if (animalHeatVo.getStatus()==0){ |
| | | return baseMapper.getAnimalStatis(); |
| | | } |
| | | //查询本周的统计数据 |
| | | if (animalHeatVo.getStatus()==1){ |
| | | return baseMapper.getAnimalStatisWeek(); |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 体温数据的分页数据 |
| | | * @param animalHeatVo 查询条件 |
| | | * @param page 查询页码 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public IPage<BladeAnimalHeat> selectAnimalHeatPage(IPage<BladeAnimalHeat> page, AnimalHeatVo animalHeatVo) { |
| | | return page.setRecords(baseMapper.selectAnimalHeatPageList(page, animalHeatVo)); |
| | | } |
| | | } |
| New file |
| | |
| | | package org.springblade.jfpt.animalheat.util; |
| | | |
| | | import jodd.util.StringPool; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.FileUtil; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import sun.misc.BASE64Decoder; |
| | | import sun.misc.BASE64Encoder; |
| | | |
| | | import javax.imageio.ImageIO; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.*; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | |
| | | import static java.time.LocalDate.now; |
| | | |
| | | /** |
| | | * 二进制原始数据转换为图片工具类 |
| | | */ |
| | | public class ImageUtil { |
| | | static BASE64Encoder encoder = new sun.misc.BASE64Encoder(); |
| | | static BASE64Decoder decoder = new sun.misc.BASE64Decoder(); |
| | | |
| | | @Value("${picture.addUrl}") |
| | | private String picAddUrl; |
| | | |
| | | @Value("${picture.pre}") |
| | | private static String picPre; |
| | | |
| | | /** |
| | | * 二进制原始数据转换为图片 |
| | | * @param base64String |
| | | */ |
| | | public static String base64StringToImage(String base64String){ |
| | | try { |
| | | byte[] bytes1 = decoder.decodeBuffer(base64String); |
| | | |
| | | ByteArrayInputStream bais = new ByteArrayInputStream(bytes1); |
| | | BufferedImage bi1 = ImageIO.read(bais); |
| | | String yyyyMMddHHmmss = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); |
| | | File w2 = new File("D://"+picPre+StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | +".jpg");//可以是jpg,png,gif格式 |
| | | |
| | | ImageIO.write(bi1, "jpg", w2);//不管输出什么格式图片,此处不需改动 |
| | | //返回图片路径 |
| | | return picPre+ StringPool.SLASH+ DateUtil.today()+StringPool.SLASH+ StringUtil.randomUUID() |
| | | +StringPool.DOT+ "jpg"; |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | } |
| New file |
| | |
| | | package org.springblade.jfpt.animalheat.vo; |
| | | |
| | | import lombok.Data; |
| | | import org.springblade.jfpt.animalheat.entity.BladeAnimalHeat; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 查询的条件属性 |
| | | */ |
| | | @Data |
| | | public class AnimalHeatVo extends BladeAnimalHeat implements Serializable { |
| | | /** |
| | | *开始时间 |
| | | */ |
| | | private Date begTime; |
| | | |
| | | /** |
| | | * 结束时间 |
| | | */ |
| | | private Date endTime; |
| | | |
| | | /** |
| | | * 状态 0: 当天时间统计数据 1: 本周内的数据统计 |
| | | */ |
| | | private Integer status; |
| | | } |
| New file |
| | |
| | | package org.springblade.jfpt.animalheat.vo; |
| | | |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 体温数据统计返回属性参数 |
| | | */ |
| | | @Data |
| | | public class StatisVo { |
| | | /** |
| | | * 体温状态 1为高于37度高温状态 0为正常 |
| | | */ |
| | | private Integer status; |
| | | |
| | | /** |
| | | * 数量 |
| | | */ |
| | | private Integer number; |
| | | } |
| | |
| | | <result column="handletype" property="handletype"/> |
| | | </resultMap> |
| | | |
| | | |
| | | <select id="selectJingdanPage" resultMap="jingdanResultMap"> |
| | | SELECT j.id,j.galarmPeople,j.phoneNumber,j.place,j.content,j.galarmTime,j.waringType,j.deviceNumber,j.type, |
| | | j.handleP,j.handleTime,j.handName,j.level,ST_ASTEXT(j.coordinate) as coordinate,j.jd,j.wd,j.addvcd,j.rName, |
| | |
| | | import org.springblade.jfpt.Netty.service.nettyService; |
| | | import org.springblade.jfpt.alarm.entity.Alarm; |
| | | import org.springblade.jfpt.alarm.service.IAlarmService; |
| | | import org.springblade.jfpt.animalheat.service.AnimalHeatService; |
| | | import org.springblade.jfpt.catalog.service.catalogService; |
| | | import org.springblade.jfpt.equipment.service.IEquipmentService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | |
| | | @Autowired |
| | | private IEquipmentService equipmentService; |
| | | |
| | | @Autowired |
| | | private AnimalHeatService animalHeatService; |
| | | |
| | | @Autowired |
| | | private IAlarmService alarmService; |
| | |
| | | String body = new String(req, "UTF-8"); |
| | | String content = body; |
| | | System.out.println("接收客户端数据:" + body); |
| | | //获取字符串的长度 |
| | | int length = content.length(); |
| | | //当字符串长度大于200时,采集体温数据,小于则采集报警数据 |
| | | if (length>200){ |
| | | //只有数据长度大于300时,采集体温数据 200-300 之间为心跳数据,当前不采集 |
| | | if (length>250){ |
| | | //插入数据 |
| | | serverHandler.animalHeatService.save(body); |
| | | } |
| | | }else { |
| | | String ChannelName = content.substring(10, 22);//设备编码 |
| | | String sub = content.substring(23, 27); |
| | | ConcurrentHashMap<String, Channel> channelHashMap = ChannelMap.getChannelHashMap(); |
| | |
| | | // 保存当前连接 |
| | | ChannelMap.addChannel(ChannelName,channelHandlerContext.channel()); |
| | | } |
| | | } |
| | | else { |
| | | } else { |
| | | Channel channel = ChannelMap.getChannelByName(ChannelName); |
| | | if (channel!=channelHandlerContext.channel()|| channel==null){ |
| | | if (!sub.equals("VIMO")){ |
| | |
| | | } |
| | | |
| | | List<String> outData = new ArrayList<>(); |
| | | switch (content.substring(0, 2)) |
| | | { |
| | | case "LA": |
| | | { |
| | | switch (content.substring(0, 2)) { |
| | | case "LA": { |
| | | String devId = content.substring(10, 22); |
| | | String fqbm = content.substring(24, 26); |
| | | List<Map<String, Object>> list = serverHandler.equipmentService.selectInfos(devId); |
| | |
| | | alarm.setJtype("0"); |
| | | if (fqbm.equals("00")){ |
| | | alarm.setWaringType("旁路"); |
| | | } |
| | | else if(fqbm.equals("01")){ |
| | | } else if (fqbm.equals("01")) { |
| | | alarm.setWaringType("火警"); |
| | | } |
| | | else if(fqbm.equals("02")){ |
| | | } else if (fqbm.equals("02")) { |
| | | alarm.setWaringType("挟持"); |
| | | } |
| | | else if(fqbm.equals("03")){ |
| | | } else if (fqbm.equals("03")) { |
| | | alarm.setWaringType("紧急"); |
| | | } |
| | | else if(fqbm.equals("04")){ |
| | | } else if (fqbm.equals("04")) { |
| | | alarm.setWaringType("救护"); |
| | | } |
| | | else if(fqbm.equals("05")){ |
| | | } else if (fqbm.equals("05")) { |
| | | alarm.setWaringType("内部"); |
| | | } |
| | | else if(fqbm.equals("06")){ |
| | | } else if (fqbm.equals("06")) { |
| | | alarm.setWaringType("出入"); |
| | | } |
| | | else if(fqbm.equals("07")){ |
| | | } else if (fqbm.equals("07")) { |
| | | alarm.setWaringType("周边"); |
| | | } |
| | | else { |
| | | } else { |
| | | alarm.setWaringType("防拆"); |
| | | } |
| | | serverHandler.alarmService.s(alarm); |
| | |
| | | |
| | | break; |
| | | } |
| | | case "LD": |
| | | { |
| | | case "LD": { |
| | | // if (Pattern.matches(content, reg_LD)) |
| | | String deviceNumber = content.substring(10, 22); |
| | | String keyword = content.substring(23, 27); |
| | | System.out.println(keyword); |
| | | switch(keyword) |
| | | { |
| | | case "IMEI": |
| | | { |
| | | switch (keyword) { |
| | | case "IMEI": { |
| | | Date d = new Date(); |
| | | SimpleDateFormat sbf = new SimpleDateFormat("MMddHHmm"); |
| | | outData.add("LC8C0470" + sbf.format(d) + "#@" + "LEOK#@"); |
| | | outData.add("LEOK#@"); |
| | | break; |
| | | } |
| | | case "SRTC": |
| | | { |
| | | case "SRTC": { |
| | | Date d = new Date(); |
| | | SimpleDateFormat sbf = new SimpleDateFormat("yyyyMMddHHmmss"); |
| | | outData.add("LEOK#@"); |
| | | outData.add("LC8C0700" + sbf.format(d) + "#@"); |
| | | break; |
| | | } |
| | | case "STAS": |
| | | { |
| | | case "STAS": { |
| | | outData.add("LEOK#@"); |
| | | outData.add("LC8100001E"+ "#@"); |
| | | break; |
| | | } |
| | | case "TEST": |
| | | { |
| | | case "TEST": { |
| | | Date d = new Date(); |
| | | SimpleDateFormat sbf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | String format = sbf.format(d); |
| | |
| | | outData.add("LEON#@"); |
| | | break; |
| | | } |
| | | case "COMM": |
| | | { |
| | | case "COMM": { |
| | | outData.add("LEOK#@"); |
| | | break; |
| | | } |
| | | default: |
| | | { |
| | | default: { |
| | | outData.add("LEOK#@"); |
| | | break; |
| | | } |
| | |
| | | |
| | | break; |
| | | } |
| | | case "LB": |
| | | { |
| | | case "LB": { |
| | | outData.add("LEOK#@"); |
| | | break; |
| | | } |
| | | } |
| | | if(outData.size() == 0) |
| | | { |
| | | if (outData.size() == 0) { |
| | | outData.add("LERR#@"); |
| | | } |
| | | for (int i = 0; i < outData.size(); i++) |
| | | { |
| | | for (int i = 0; i < outData.size(); i++) { |
| | | channelHandlerContext.writeAndFlush(Unpooled.copiedBuffer(outData.get(i), CharsetUtil.UTF_8)); |
| | | } |
| | | } |
| | | |
| | | |
| | | // channelHandlerContext.writeAndFlush(Unpooled.copiedBuffer("LEOK#@!", CharsetUtil.UTF_8)); |
| | |
| | | import io.netty.channel.socket.SocketChannel; |
| | | import io.netty.channel.socket.nio.NioServerSocketChannel; |
| | | import io.netty.handler.codec.DelimiterBasedFrameDecoder; |
| | | import io.netty.handler.codec.LengthFieldBasedFrameDecoder; |
| | | import io.netty.handler.codec.LengthFieldPrepender; |
| | | import io.netty.handler.codec.string.StringDecoder; |
| | | import io.netty.handler.logging.LoggingHandler; |
| | | |
| | | import java.nio.ByteOrder; |
| | | import java.nio.charset.Charset; |
| | | |
| | | |
| | | public class TcpServer { |
| | |
| | | // 绑定处理group |
| | | bootstrap.group(boss, worker).channel(NioServerSocketChannel.class) |
| | | //保持连接数 |
| | | .option(ChannelOption.SO_BACKLOG, 128) |
| | | .option(ChannelOption.SO_BACKLOG, 30) |
| | | //设置缓冲区大小 |
| | | .option(ChannelOption.SO_RCVBUF, 1024*1024) |
| | | .option(ChannelOption.SO_SNDBUF, 1024*1024) |
| | | //有数据立即发送 |
| | | .option(ChannelOption.TCP_NODELAY, true) |
| | | //保持连接 |
| | | .childOption(ChannelOption.SO_KEEPALIVE, true) |
| | | .childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(512*250)) |
| | | .childOption(ChannelOption.RCVBUF_ALLOCATOR, new FixedRecvByteBufAllocator(1024*1024)) |
| | | .childHandler(new NettyChannelHandler()); |
| | | |
| | | //绑定端口,同步等待成功 |
| | |
| | | @Override |
| | | protected void initChannel(SocketChannel socketChannel) |
| | | throws Exception { |
| | | //socketChannel.pipeline().addLast(new MyNettyDecode()); |
| | | //socketChannel.pipeline().addLast(new StringDecoder(Charset.forName("UTF-8"))); |
| | | //socketChannel.pipeline().addLast("decoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE,0,4,0,4)); |
| | | //socketChannel.pipeline().addLast("encoder", new LengthFieldPrepender(4, false)); |
| | | ByteBuf delimiter = Unpooled.copiedBuffer("}".getBytes()); |
| | | socketChannel.pipeline().addLast( new DelimiterBasedFrameDecoder(200000,delimiter)); |
| | | socketChannel.pipeline().addLast(new TcpServerHandler()); |
| | | } |
| | | } |
| | |
| | | import org.springblade.jfpt.alarm.service.IAlarmService; |
| | | import org.springblade.jfpt.equipment.service.IEquipmentService; |
| | | import org.springblade.jfpt.nettyServer.NettyConfig; |
| | | import org.springblade.jfpt.nettyUdpServer.service.AnimalHeatService; |
| | | import org.springblade.jfpt.animalheat.service.AnimalHeatService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import javax.annotation.PostConstruct; |
| | |
| | | |
| | | @Component |
| | | public class TcpServerHandler extends ChannelInboundHandlerAdapter { |
| | | |
| | | private String reg_LA ="LA[d]{8}[d|A-F]{12}[d|A-F]{8}[d|A-Z]{2}[d|A-F]{4}[x2A][d|A-F]{6}[#@]"; |
| | | private String reg_LB = "LB[\\d|A-F]{12}[\\x2A].*[#@]"; |
| | | private String reg_LB2 = "LB[\\d|A-F]{6}[\\x2A].*[#@]"; |
| | | private String reg_LD = "LD[d]{8}[d|A-F]{12}:[A-Z]{4}[\\x2A].*[#@]"; |
| | | |
| | | |
| | | private ConcurrentHashMap<String, Channel> sessionChannelMap = new ConcurrentHashMap<String, Channel>(); |
| | | |
| | | @Autowired |
| | | private org.springblade.jfpt.catalog.service.catalogService catalogService; |
| | | |
| | | @Autowired |
| | | private org.springblade.jfpt.Netty.service.nettyService nettyService; |
| | | |
| | | @Autowired |
| | | private IEquipmentService equipmentService; |
| | | |
| | | @Autowired |
| | | private IAlarmService alarmService; |
| | | |
| | | private static TcpServerHandler tcpServerHandler; |
| | | |
| | |
| | | String body = new String(req, "UTF-8"); |
| | | String content = body; |
| | | System.out.println("接收客户端数据:" + body); |
| | | System.out.println("content.length() = " + content.length()); |
| | | //获取字符串的长度 |
| | | int length = content.length(); |
| | | //当字符串长度大于200时,采集体温数据,小于则采集报警数据 |
| | | //只有数据长度大于300时,采集体温数据 200-300 之间为心跳数据,当前不采集 |
| | | if (length>250){ |
| | | //插入数据 |
| | | tcpServerHandler.animalHeatService.save(body); |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | url: jdbc:mysql://36.134.81.48:3306/jfpt?allowMultiQueries=true&useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true&useOldAliasMetadataBehavior=true |
| | | username: root |
| | | password: jfpt123 |
| | | |
| | | |
| New file |
| | |
| | | picture.addUrl= http://36.134.81.48:9000/ |
| | | picture.pre= software/minio/data/animalHeat/ |