src/main/java/org/springblade/modules/Netty/controller/nettyController.java
New file @@ -0,0 +1,186 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.Netty.controller; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.util.CharsetUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.modules.Netty.entitly.Netty; import org.springblade.modules.Netty.vo.nettyVO; import org.springblade.modules.catalog.service.catalogService; import org.springblade.modules.nettyServer.ChannelMap; import org.springblade.modules.nettyServer.ServerHandler; import org.springframework.web.bind.annotation.*; import org.springblade.modules.Netty.wrapper.nettyWrapper; import org.springblade.modules.Netty.service.nettyService; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; /** * 控制器 * * @author BladeX * @since 2020-07-06 */ @RestController @AllArgsConstructor @RequestMapping("netty/netty") @Api(value = "", tags = "接口") public class nettyController extends BladeController { private final nettyService nettyService ; private final org.springblade.modules.catalog.service.catalogService catalogService; /** * 详情 */ @GetMapping("/detail") @ApiOperationSupport(order = 1) @ApiOperation(value = "详情", notes = "传入deploy") public R<nettyVO> detail(Netty netty, HttpServletResponse response) { response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Allow-Credentials","true"); Netty detail = nettyService.getOne(Condition.getQueryWrapper(netty)); return R.data(nettyWrapper.build().entityVO(detail)); } /** * 分页 */ @GetMapping("/list") @ApiOperationSupport(order = 2) @ApiOperation(value = "分页", notes = "传入deploy") public R<IPage<nettyVO>> list(Netty netty, Query query) { IPage<Netty> pages = nettyService.page(Condition.getPage(query), Condition.getQueryWrapper(netty)); return R.data(nettyWrapper.build().pageVO(pages)); } /** * 新增 */ @PostMapping("/save") @ApiOperationSupport(order = 4) @ApiOperation(value = "新增", notes = "传入deploy") public R save(@Valid @RequestBody Netty netty) { return R.status(nettyService.save(netty)); } /** * 修改 */ @PostMapping("/update") @ApiOperationSupport(order = 5) @ApiOperation(value = "修改", notes = "传入deploy") public R update(@Valid @RequestBody Netty netty) { return R.status(nettyService.updateById(netty)); } /** * 新增或修改 */ @PostMapping("/submit") @ApiOperationSupport(order = 6) @ApiOperation(value = "新增或修改", notes = "传入deploy") public R submit(@Valid @RequestBody Netty netty) { return R.status(nettyService.saveOrUpdate(netty)); } /** * 删除 */ @PostMapping("/remove") @ApiOperationSupport(order = 8) @ApiOperation(value = "删除", notes = "传入ids") public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) { return R.status(nettyService.removeByIds(Func.toLongList(ids))); } /** * 布防 */ @PostMapping("/selectNettyChannelb") @ApiOperationSupport(order = 8) public R selectNettyChannel(String pid,HttpServletResponse response) { response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Allow-Credentials","true"); ConcurrentHashMap<String, Channel> channelHashMap = ChannelMap.getChannelHashMap(); System.out.println(channelHashMap); String s = catalogService.selectCatalogEqNUmber(pid); if (s==null){ return R.success("暂无设备布防"); } else { String[] split = s.split(","); for (int i = 0; i < split.length; i++) { List<String> outData = new ArrayList<>(); outData.add("LC8109085B#@"); Channel channel = channelHashMap.get(split[i]); channel.writeAndFlush(Unpooled.copiedBuffer(outData.get(0), CharsetUtil.UTF_8)); } return R.success("设备布防"); } } /** * 撤防 */ @PostMapping("/selectNettyChannelc") @ApiOperationSupport(order = 9) public R selectNettyChannelc(String pid,HttpServletResponse response) { response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); response.setHeader("Access-Control-Allow-Credentials","true"); ConcurrentHashMap<String, Channel> channelHashMap = ChannelMap.getChannelHashMap(); System.out.println(channelHashMap); String s = catalogService.selectCatalogEqNUmber(pid); if (s==null){ return R.success("暂无设备撤防"); } else { String[] split = s.split(","); for (int i = 0; i < split.length; i++) { List<String> outData = new ArrayList<>(); outData.add("LC8109085C#@"); Channel channel = channelHashMap.get(split[i]); channel.writeAndFlush(Unpooled.copiedBuffer(outData.get(0), CharsetUtil.UTF_8)); } return R.success("设备撤防"); } } } src/main/java/org/springblade/modules/Netty/dto/nettyDTO.java
New file @@ -0,0 +1,35 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.Netty.dto; import lombok.Data; import lombok.EqualsAndHashCode; import org.springblade.modules.Netty.entitly.Netty; import org.springblade.modules.catalog.entitly.catalog; /** * 数据传输对象实体类 * * @author BladeX * @since 2020-07-06 */ @Data @EqualsAndHashCode(callSuper = true) public class nettyDTO extends Netty { private static final long serialVersionUID = 1L; } src/main/java/org/springblade/modules/Netty/entitly/Netty.java
New file @@ -0,0 +1,51 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.Netty.entitly; import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; import io.swagger.annotations.ApiModel; import lombok.Data; import java.io.Serializable; /** * 实体类 * * @author BladeX * @since 2020-07-06 */ @Data @TableName("sys_netty") @ApiModel(value = "netty对象", description = "netty对象") public class Netty implements Serializable { private static final long serialVersionUID = 1L; @JsonSerialize(using = ToStringSerializer.class) @TableId(value = "id", type = IdType.AUTO) private Integer id; @TableField("nettyName") private String nettyName; @TableField("nettyChannel") private String nettyChannel; } src/main/java/org/springblade/modules/Netty/mapper/nettyMapper.java
New file @@ -0,0 +1,37 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.Netty.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import io.netty.channel.Channel; import org.springblade.modules.Netty.entitly.Netty; import org.springblade.modules.catalog.entitly.catalog; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * Mapper 接口 * * @author BladeX * @since 2020-07-06 */ public interface nettyMapper extends BaseMapper<Netty> { ConcurrentHashMap<String, Channel> selectNettyChannel(String nettyName); } src/main/java/org/springblade/modules/Netty/mapper/nettyMapper.xml
New file @@ -0,0 +1,16 @@ <?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.modules.Netty.mapper.nettyMapper"> <!-- 通用查询映射结果 --> <resultMap id="nettyResultMap" type="org.springblade.modules.Netty.entitly.Netty"> <id column="id" property="id"/> <result column="nettyName" property="nettyName"/> <result column="nettyChannel" property="nettyChannel"/> </resultMap> <select id="selectNettyChannel" resultType="java.util.HashMap"> SELECT nettyName,nettyChannel FROM sys_netty WHERE nettyName=#{nettyName} </select> </mapper> src/main/java/org/springblade/modules/Netty/service/impl/nettyServiceImpl.java
New file @@ -0,0 +1,48 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.Netty.service.impl; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import io.netty.channel.Channel; import org.springblade.modules.Netty.entitly.Netty; import org.springblade.modules.Netty.mapper.nettyMapper; import org.springblade.modules.Netty.service.nettyService; import org.springblade.modules.catalog.entitly.catalog; import org.springblade.modules.catalog.mapper.catalogMapper; import org.springblade.modules.catalog.service.catalogService; import org.springframework.stereotype.Service; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * 服务实现类 * * @author BladeX * @since 2020-07-06 */ @Service @DS("slaves") public class nettyServiceImpl extends ServiceImpl<nettyMapper, Netty> implements nettyService { @Override public ConcurrentHashMap<String, Channel> selectNettyChannel(String nettyName) { return baseMapper.selectNettyChannel(nettyName); } } src/main/java/org/springblade/modules/Netty/service/nettyService.java
New file @@ -0,0 +1,35 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.Netty.service; import com.baomidou.mybatisplus.extension.service.IService; import io.netty.channel.Channel; import org.springblade.modules.Netty.entitly.Netty; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; /** * 服务类 * * @author BladeX * @since 2020-07-06 */ public interface nettyService extends IService<Netty> { ConcurrentHashMap<String, Channel> selectNettyChannel(String nettyName); } src/main/java/org/springblade/modules/Netty/vo/nettyVO.java
New file @@ -0,0 +1,37 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.Netty.vo; import io.swagger.annotations.ApiModel; import lombok.Data; import lombok.EqualsAndHashCode; import org.springblade.modules.Netty.entitly.Netty; import org.springblade.modules.catalog.entitly.catalog; /** * 视图实体类 * * @author BladeX * @since 2020-07-06 */ @Data @EqualsAndHashCode(callSuper = true) @ApiModel(value = "nettyVO对象", description = "nettyVO对象") public class nettyVO extends Netty { private static final long serialVersionUID = 1L; } src/main/java/org/springblade/modules/Netty/wrapper/nettyWrapper.java
New file @@ -0,0 +1,52 @@ /* * Copyright (c) 2018-2028, Chill Zhuang All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * Neither the name of the dreamlu.net developer nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * Author: Chill 庄骞 (smallchill@163.com) */ package org.springblade.modules.Netty.wrapper; import org.springblade.core.mp.support.BaseEntityWrapper; import org.springblade.core.tool.utils.BeanUtil; import org.springblade.modules.Netty.entitly.Netty; import org.springblade.modules.Netty.vo.nettyVO; import org.springblade.modules.catalog.entitly.catalog; import org.springblade.modules.catalog.vo.catalogVO; import java.util.Objects; /** * 包装类,返回视图层所需的字段 * * @author BladeX * @since 2020-07-06 */ public class nettyWrapper extends BaseEntityWrapper<Netty, nettyVO> { public static nettyWrapper build() { return new nettyWrapper(); } @Override public nettyVO entityVO(Netty netty) { nettyVO nettyVO = Objects.requireNonNull(BeanUtil.copy(netty, nettyVO.class)); //User createUser = UserCache.getUser(deploy.getCreateUser()); //User updateUser = UserCache.getUser(deploy.getUpdateUser()); //deployVO.setCreateUserName(createUser.getName()); //deployVO.setUpdateUserName(updateUser.getName()); return nettyVO; } } src/main/java/org/springblade/modules/alarm/controller/AlarmController.java
@@ -192,4 +192,5 @@ return R.success("删除成功"); } } src/main/java/org/springblade/modules/alarm/mapper/AlarmMapper.xml
@@ -24,6 +24,9 @@ <result column="wd" property="wd"/> <result column="jtype" property="jtype"/> <result column="rname" property="rname"/> <result column="serialNumber" property="serialNumber"/> <result column="stype" property="stype"/> <result column="channelNumber" property="channelNumber"/> </resultMap> @@ -69,9 +72,12 @@ a.wd, a.jtype, a.rname, d.addvnm d.addvnm, e.serialNumber, e.stype, e.channelNumber FROM sys_alarm a LEFT JOIN sys_district d on d.addvcds=a.addvcd where 1=1 sys_alarm a LEFT JOIN sys_district d on d.addvcds=a.addvcd LEFT JOIN sys_equipment e on e.deviceNumber=a.deviceNumber where 1=1 <if test="jtype!=null and jtype!=''"> and a.jtype=#{jtype} </if> @@ -143,9 +149,12 @@ a.jd, a.wd, a.jtype, d.addvnm d.addvnm, e.serialNumber, e.stype, e.channelNumber FROM sys_alarm a LEFT JOIN sys_district d on d.addvcds=a.addvcd where 1=1 sys_alarm a LEFT JOIN sys_district d on d.addvcds=a.addvcd LEFT JOIN sys_equipment e on e.deviceNumber=a.deviceNumber where 1=1 <if test="id!=null and id!=''"> and a.id >#{id} </if> src/main/java/org/springblade/modules/alarm/vo/AlarmVO.java
@@ -33,5 +33,8 @@ public class AlarmVO extends Alarm { private static final long serialVersionUID = 1L; private String addvnm; private String serialNumber; private String stype; private String channelNumber; } src/main/java/org/springblade/modules/catalog/controller/catalogController.java
@@ -30,18 +30,14 @@ import org.springblade.modules.catalog.entitly.catalog; import org.springblade.modules.catalog.service.catalogService; import org.springblade.modules.catalog.vo.catalogVO; import org.springblade.modules.deploy.entity.Deploy; import org.springblade.modules.deploy.service.IDeployService; import org.springblade.modules.deploy.vo.DeployVO; import org.springblade.modules.catalog.wrapper.catalogWrapper; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; /** * 控制器 @@ -147,6 +143,5 @@ return R.data(list); } } src/main/java/org/springblade/modules/nettyServer/ChannelMap.java
New file @@ -0,0 +1,36 @@ package org.springblade.modules.nettyServer; import io.netty.channel.Channel; import java.util.concurrent.ConcurrentHashMap; public class ChannelMap { public static int channelNum=0; private static ConcurrentHashMap<String, Channel> channelHashMap=null;//concurrentHashmap以解决多线程冲突 public static ConcurrentHashMap<String, Channel> getChannelHashMap() { return channelHashMap; } public static Channel getChannelByName(String name){ if(channelHashMap==null||channelHashMap.isEmpty()){ return null; } return channelHashMap.get(name); } public static void addChannel(String name,Channel channel){ if(channelHashMap==null){ channelHashMap=new ConcurrentHashMap<String,Channel>(10); } channelHashMap.put(name,channel); channelNum++; } public static int removeChannelByName(String name){ if(channelHashMap.containsKey(name)){ channelHashMap.remove(name); return 0; }else{ return 1; } } } src/main/java/org/springblade/modules/nettyServer/ServerHandler.java
@@ -4,28 +4,54 @@ import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelId; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.channel.group.ChannelGroup; import io.netty.channel.group.ChannelMatcher; import io.netty.channel.group.DefaultChannelGroup; import io.netty.util.CharsetUtil; import io.netty.util.concurrent.GlobalEventExecutor; import org.springblade.modules.Netty.entitly.Netty; import org.springblade.modules.Netty.service.nettyService; import org.springblade.modules.alarm.entity.Alarm; import org.springblade.modules.alarm.service.IAlarmService; import org.springblade.modules.alarm.vo.AlarmVO; import org.springblade.modules.catalog.service.catalogService; import org.springblade.modules.equipment.entity.Equipment; import org.springblade.modules.equipment.service.IEquipmentService; import org.springblade.modules.equipment.vo.EquipmentVOS; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.PostMapping; import javax.annotation.PostConstruct; import java.util.Iterator; import java.util.List; import java.util.Map; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; @Component public class ServerHandler 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 catalogService catalogService; @Autowired private nettyService nettyService; @Autowired private IEquipmentService equipmentService; @Autowired private IAlarmService alarmService; private static ServerHandler serverHandler; @@ -38,9 +64,11 @@ */ @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { System.out.println("CTX:"+ctx.channel()); System.out.println("客户端与服务端连接开始..."); System.out.println("Channel:"+ctx.channel()); NettyConfig.group.add(ctx.channel()); // ChannelId id = ctx.channel().id(); // String s = id.toString(); //NettyConfig.group.add(ctx.channel()); } /** @@ -80,27 +108,155 @@ byte[] req = new byte[buf.readableBytes()]; buf.readBytes(req); String body = new String(req, "UTF-8"); String content = body; System.out.println("接收客户端数据:" + body); channelHandlerContext.writeAndFlush(Unpooled.copiedBuffer("LEOK#@!", CharsetUtil.UTF_8)); List<Map<String, Object>> list = serverHandler.catalogService.selectCatalogList(); System.out.println(list); // ByteBuf pingMessage = Unpooled.buffer(); // pingMessage.writeBytes(req); // channelHandlerContext.writeAndFlush(pingMessage); String ChannelName = content.substring(10, 22);//设备编码 String sub = content.substring(23, 27); ConcurrentHashMap<String, Channel> channelHashMap = ChannelMap.getChannelHashMap(); if (channelHashMap==null){ if (!sub.equals("VIMO")){ // 保存当前连接 ChannelMap.addChannel(ChannelName,channelHandlerContext.channel()); } } else { Channel channel = ChannelMap.getChannelByName(ChannelName); if (channel!=channelHandlerContext.channel()|| channel==null){ if (!sub.equals("VIMO")){ // 保存当前连接 ChannelMap.addChannel(ChannelName,channelHandlerContext.channel()); } } } List<String> outData = new ArrayList<>(); 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 alarm= new Alarm(); alarm.setAlarmType("一键报警"); Date day = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); alarm.setAlarmTime(df.format(day)); alarm.setPlace((String) list.get(0).get("streeName"));//事发地址 alarm.setDeviceNumber((String) list.get(0).get("deviceNumber"));//设备编号 alarm.setAddvcd((String) list.get(0).get("addvcd"));//行政区编码 alarm.setJd((String) list.get(0).get("jd"));//经度 alarm.setWd((String) list.get(0).get("wd"));//纬度 alarm.setJtype("0"); if (fqbm.equals("00")){ alarm.setWaringType("旁路"); } else if(fqbm.equals("01")){ alarm.setWaringType("火警"); } else if(fqbm.equals("02")){ alarm.setWaringType("挟持"); } else if(fqbm.equals("03")){ alarm.setWaringType("紧急"); } else if(fqbm.equals("04")){ alarm.setWaringType("救护"); } else if(fqbm.equals("05")){ alarm.setWaringType("内部"); } else if(fqbm.equals("06")){ alarm.setWaringType("出入"); } else if(fqbm.equals("07")){ alarm.setWaringType("周边"); } else { alarm.setWaringType("防拆"); } serverHandler.alarmService.s(alarm); outData.add("LEOK#@"); break; } case "LD": { // if (Pattern.matches(content, reg_LD)) String keyword = content.substring(23, 27); System.out.println(keyword); switch(keyword) { case "IMEI": { System.out.println("IMEI------------------"); Date d = new Date(); SimpleDateFormat sbf = new SimpleDateFormat("MMddHHmm"); outData.add("LC8C0470" + sbf.format(d) + "#@" + "LEOK#@"); outData.add("LEOK#@"); break; } case "SRTC": { Date d = new Date(); SimpleDateFormat sbf = new SimpleDateFormat("yyyyMMddHHmmss"); outData.add("LEOK#@"); outData.add("LC8C0700" + sbf.format(d) + "#@"); break; } case "STAS": { outData.add("LEOK#@"); outData.add("LC8100001E"+ "#@"); break; } case "TEST": { outData.add("LEOK#@"); outData.add("LEON#@"); break; } case "COMM": { outData.add("LEOK#@"); break; } default: { outData.add("LEOK#@"); break; } } break; } case "LB": { outData.add("LEOK#@"); break; } } if(outData.size() == 0) { outData.add("LERR#@"); } 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)); //服务端使用这个就能向 每个连接上来的客户端群发消息 //NettyConfig.group.writeAndFlush(info); Iterator<Channel> iterator = NettyConfig.group.iterator(); System.out.println("iterator:"+iterator); while(iterator.hasNext()){ //打印出所有客户端的远程地址 System.out.println((iterator.next()).remoteAddress()); } // Iterator<Channel> iterator = NettyConfig.group.iterator(); // System.out.println("iterator:"+iterator); // while(iterator.hasNext()){ // //打印出所有客户端的远程地址 // System.out.println((iterator.next()).remoteAddress()); // // } } }