diff --git a/api/src/main/java/com/NettyWeiXinApplication.java b/api/src/main/java/com/WeiXinApplication.java similarity index 71% rename from api/src/main/java/com/NettyWeiXinApplication.java rename to api/src/main/java/com/WeiXinApplication.java index 275f3c0..66df0b9 100644 --- a/api/src/main/java/com/NettyWeiXinApplication.java +++ b/api/src/main/java/com/WeiXinApplication.java @@ -1,10 +1,8 @@ package com; import com.sv.netty.config.SpringContextHolder; -import com.sv.netty.netty.BootService; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.scheduling.annotation.EnableAsync; @@ -17,7 +15,7 @@ import org.springframework.scheduling.annotation.EnableScheduling; @EnableScheduling @EnableAsync @MapperScan(value = {"com.sv.mapper"}) -public class NettyWeiXinApplication { +public class WeiXinApplication { /** * 启动项目 @@ -25,11 +23,8 @@ public class NettyWeiXinApplication { * @param args 启动参数 */ public static void main(String[] args) { - ConfigurableApplicationContext context = SpringApplication.run(NettyWeiXinApplication.class, args); + ConfigurableApplicationContext context = SpringApplication.run(WeiXinApplication.class, args); SpringContextHolder.setContext(context); - //启动netty - BootService bootService = (BootService) context.getBean("bootService"); - bootService.run(); } } diff --git a/api/src/main/java/com/sv/netty/controller/AppVenueLessonController.java b/api/src/main/java/com/sv/netty/controller/AppVenueLessonController.java index 75ea6b7..d0cd6d9 100644 --- a/api/src/main/java/com/sv/netty/controller/AppVenueLessonController.java +++ b/api/src/main/java/com/sv/netty/controller/AppVenueLessonController.java @@ -108,12 +108,4 @@ public class AppVenueLessonController { return venueItems; } - /** - * 查询远程配置项目,可以让APP联网可配置 - */ - @RequestMapping(value = "/getRemoteConfig", method = {RequestMethod.GET,RequestMethod.POST}) - public Map getRemoteConfig() { - return new HashMap<>(); - } - } diff --git a/api/src/main/java/com/sv/netty/controller/QREnterController.java b/api/src/main/java/com/sv/netty/controller/QREnterController.java index a15f4a3..3a5afc4 100644 --- a/api/src/main/java/com/sv/netty/controller/QREnterController.java +++ b/api/src/main/java/com/sv/netty/controller/QREnterController.java @@ -20,56 +20,56 @@ import javax.annotation.Resource; /** * 小程序二维码进场Controller */ -@RestController +//@RestController public class QREnterController extends BaseApiController { private final Logger logger = LoggerFactory.getLogger(QREnterController.class); - @Resource +// @Resource private QRCodeService qrCodeService; - @Resource +// @Resource private MessageService messageService; /** * 进场指令发布 */ - @RequestMapping(value = "/qrCode/enter", method = RequestMethod.GET) - public ResponseDTO enter(@RequestParam("deviceId") String deviceId) { - Integer memberId = getMemberIdByAccessToken(); - Integer venueId = getVenueId(deviceId); - String deviceName = getDeviceName(deviceId); - DeviceType enterOrOut = getEnterOrOut(deviceId); - Venue venue = qrCodeService.initEnter(venueId, deviceName,enterOrOut,memberId); - qrCodeService.unBindMember(venueId, deviceName, enterOrOut); - if (venue!=null){ - if (DeviceType.OUT == enterOrOut){ - // 出场 - messageService.outVenue(deviceName,venueId,memberId,venue); - }else{ - // 进场 - messageService.enterVenue(deviceName,venueId,memberId,venue); - } - } - return ResponseDTO.ok(); - } +// @RequestMapping(value = "/qrCode/enter", method = RequestMethod.GET) +// public ResponseDTO enter(@RequestParam("deviceId") String deviceId) { +// Integer memberId = getMemberIdByAccessToken(); +// Integer venueId = getVenueId(deviceId); +// String deviceName = getDeviceName(deviceId); +// DeviceType enterOrOut = getEnterOrOut(deviceId); +// Venue venue = qrCodeService.initEnter(venueId, deviceName,enterOrOut,memberId); +// qrCodeService.unBindMember(venueId, deviceName, enterOrOut); +// if (venue!=null){ +// if (DeviceType.OUT == enterOrOut){ +// // 出场 +// messageService.outVenue(deviceName,venueId,memberId,venue); +// }else{ +// // 进场 +// messageService.enterVenue(deviceName,venueId,memberId,venue); +// } +// } +// return ResponseDTO.ok(); +// } /** * 扫码结果页初始化 * 需要进场的场馆信息 */ - @RequestMapping(value = "/qrCode/init", method = RequestMethod.GET) - public ResponseDTO initEnter(@RequestParam("deviceId")String deviceId) { - try { - Integer memberId = getMemberIdByAccessToken(); - Integer venueId = getVenueId(deviceId); - String deviceName = getDeviceName(deviceId); - DeviceType enterOrOut = getEnterOrOut(deviceId); - Venue venue = qrCodeService.initEnter(venueId, deviceName, enterOrOut,memberId); - qrCodeService.bindMember(venueId, deviceName, enterOrOut,memberId); - messageService.sendLoading(deviceName, venueId, enterOrOut, memberId); - return ResponseDTO.ok().addAttribute("venueInit", venue); - }catch(ServiceException e){ - return ResponseDTO.ok().addAttribute("InitError",e.getMessage()); - } - } +// @RequestMapping(value = "/qrCode/init", method = RequestMethod.GET) +// public ResponseDTO initEnter(@RequestParam("deviceId")String deviceId) { +// try { +// Integer memberId = getMemberIdByAccessToken(); +// Integer venueId = getVenueId(deviceId); +// String deviceName = getDeviceName(deviceId); +// DeviceType enterOrOut = getEnterOrOut(deviceId); +// Venue venue = qrCodeService.initEnter(venueId, deviceName, enterOrOut,memberId); +// qrCodeService.bindMember(venueId, deviceName, enterOrOut,memberId); +// messageService.sendLoading(deviceName, venueId, enterOrOut, memberId); +// return ResponseDTO.ok().addAttribute("venueInit", venue); +// }catch(ServiceException e){ +// return ResponseDTO.ok().addAttribute("InitError",e.getMessage()); +// } +// } /** @@ -77,58 +77,58 @@ public class QREnterController extends BaseApiController { * @param deviceId * @return */ - private Integer getVenueId(String deviceId){ - String venueId = "0"; - if (deviceId!=null && deviceId.contains(Constant.SPIT_WORD)){ - venueId = deviceId.split(Constant.SPIT_WORD)[1]; - } - try { - return Integer.parseInt(venueId); - }catch (Exception e){ - return 0; - } - } +// private Integer getVenueId(String deviceId){ +// String venueId = "0"; +// if (deviceId!=null && deviceId.contains(Constant.SPIT_WORD)){ +// venueId = deviceId.split(Constant.SPIT_WORD)[1]; +// } +// try { +// return Integer.parseInt(venueId); +// }catch (Exception e){ +// return 0; +// } +// } /** * 根据字符串获取设备号 * @param deviceId * @return */ - private String getDeviceName(String deviceId){ - if (deviceId!=null){ - return deviceId.split(Constant.SPIT_WORD)[0]; - } - return null; - } +// private String getDeviceName(String deviceId){ +// if (deviceId!=null){ +// return deviceId.split(Constant.SPIT_WORD)[0]; +// } +// return null; +// } /** * 根据字符串获取门禁类型 * @param deviceId * @return */ - private DeviceType getEnterOrOut(String deviceId){ - DeviceType returnType = DeviceType.ENTER; - if (deviceId!=null && deviceId.contains(Constant.SPIT_WORD)){ - String temp = deviceId.split(Constant.SPIT_WORD)[1]; - if (temp!=null && temp.contains(Constant.SPIT_WORD)){ - returnType = DeviceType.valueOf(temp.split(Constant.SPIT_WORD)[1]); - } - } - return returnType; - } +// private DeviceType getEnterOrOut(String deviceId){ +// DeviceType returnType = DeviceType.ENTER; +// if (deviceId!=null && deviceId.contains(Constant.SPIT_WORD)){ +// String temp = deviceId.split(Constant.SPIT_WORD)[1]; +// if (temp!=null && temp.contains(Constant.SPIT_WORD)){ +// returnType = DeviceType.valueOf(temp.split(Constant.SPIT_WORD)[1]); +// } +// } +// return returnType; +// } /** * 检验客户端读取能力 * @return */ - @RequestMapping("/checkAlive") - public ResponseDTO checkAlive(@RequestParam String id) { - Integer venueId = getVenueId(id); - String deviceName = getDeviceName(id); - DeviceType enterOrOut = getEnterOrOut(id); - logger.info("验证设备"+ id + "通讯情况"); - messageService.testLoad(deviceName,venueId,enterOrOut); - return ResponseDTO.ok(); - } +// @RequestMapping("/checkAlive") +// public ResponseDTO checkAlive(@RequestParam String id) { +// Integer venueId = getVenueId(id); +// String deviceName = getDeviceName(id); +// DeviceType enterOrOut = getEnterOrOut(id); +// logger.info("验证设备"+ id + "通讯情况"); +// messageService.testLoad(deviceName,venueId,enterOrOut); +// return ResponseDTO.ok(); +// } } diff --git a/api/src/main/java/com/sv/netty/netty/BootService.java b/api/src/main/java/com/sv/netty/netty/BootService.java index 234827e..88b1a83 100644 --- a/api/src/main/java/com/sv/netty/netty/BootService.java +++ b/api/src/main/java/com/sv/netty/netty/BootService.java @@ -22,7 +22,7 @@ import java.util.concurrent.Executors; * @Author peakren * @Date 03/05/2017 6:18 PM */ -@Component +//@Component public class BootService { private Logger logger = LoggerFactory.getLogger(BootService.class); @@ -40,25 +40,25 @@ public class BootService { /** * 下面几个是由spring注入 */ - @Value("${netty.port}") +// @Value("${netty.port}") private int port; - @Value("${so.keepalive}") +// @Value("${so.keepalive}") private Boolean keepalive; - @Value("${so.backlog}") +// @Value("${so.backlog}") private int backlog; - @Value("${tcp_nodelay}") +// @Value("${tcp_nodelay}") private boolean nodelay; - @Value("${so.reuseaddr}") +// @Value("${so.reuseaddr}") private boolean reuseaddr; - @Value("${boss.thread.count}") +// @Value("${boss.thread.count}") private int bossCount; - @Value("${worker.thread.count}") +// @Value("${worker.thread.count}") private int workerCount; private Map channelOptions; @@ -108,7 +108,6 @@ public class BootService { * 开启单独的线程运行netty服务,避免和spring mvc冲突 */ public void run() { -// messageExecutor = Executors.newFixedThreadPool(1); messageExecutor = Executors.newSingleThreadExecutor(); messageExecutor.execute(() -> init()); } diff --git a/api/src/main/java/com/sv/netty/netty/ServerHandler.java b/api/src/main/java/com/sv/netty/netty/ServerHandler.java index be82b3a..3663d55 100644 --- a/api/src/main/java/com/sv/netty/netty/ServerHandler.java +++ b/api/src/main/java/com/sv/netty/netty/ServerHandler.java @@ -20,7 +20,7 @@ import java.util.Set; * @author ranfi */ -@ChannelHandler.Sharable +//@ChannelHandler.Sharable public class ServerHandler extends SimpleChannelInboundHandler { private static Logger logger = LoggerFactory.getLogger(ServerHandler.class); diff --git a/api/src/main/java/com/sv/netty/netty/ServerProtocolInitializer.java b/api/src/main/java/com/sv/netty/netty/ServerProtocolInitializer.java index 2fbe780..bbe8622 100644 --- a/api/src/main/java/com/sv/netty/netty/ServerProtocolInitializer.java +++ b/api/src/main/java/com/sv/netty/netty/ServerProtocolInitializer.java @@ -17,7 +17,7 @@ import org.springframework.stereotype.Component; * @Author peakren * @Date 09/05/2017 5:19 PM */ -@Component +//@Component public class ServerProtocolInitializer extends ChannelInitializer { private final int IDLE_TIME = 120; //连接检测空闲时间 diff --git a/api/src/main/java/com/sv/netty/netty/service/impl/AppMessageHandlerAdapter.java b/api/src/main/java/com/sv/netty/netty/service/impl/AppMessageHandlerAdapter.java index 2d2ac18..63a379f 100644 --- a/api/src/main/java/com/sv/netty/netty/service/impl/AppMessageHandlerAdapter.java +++ b/api/src/main/java/com/sv/netty/netty/service/impl/AppMessageHandlerAdapter.java @@ -37,7 +37,7 @@ import java.util.concurrent.TimeUnit; * @Author peakren * @Date 08/05/2017 10:43 PM */ -@Service("messageService") +//@Service("messageService") public class AppMessageHandlerAdapter implements MessageService { private Logger logger = LoggerFactory.getLogger(AppMessageHandlerAdapter.class); @@ -49,25 +49,25 @@ public class AppMessageHandlerAdapter implements MessageService { */ private ConcurrentMap links = PlatformDependent.newConcurrentHashMap(); - @Resource +// @Resource private MemberService memberService; - @Resource +// @Resource private VenueService venueService; - @Resource +// @Resource private DeviceService deviceService; - @Resource +// @Resource private ConfigService configService; - @Resource(name = "scheduledExecutorService") +// @Resource(name = "scheduledExecutorService") private ScheduledExecutorService scheduledExecutorService; - @Resource +// @Resource private MemberEnterVenueLogService memberEnterVenueLogService; - @Resource +// @Resource private RestTemplate restTemplate; /** diff --git a/service/src/main/java/com/sv/service/api/QRCodeService.java b/service/src/main/java/com/sv/service/api/QRCodeService.java index a579478..60c319f 100644 --- a/service/src/main/java/com/sv/service/api/QRCodeService.java +++ b/service/src/main/java/com/sv/service/api/QRCodeService.java @@ -20,14 +20,14 @@ import java.util.Date; /** * 小程序扫二维码处理 */ -@Service("qrCodeService") -@Transactional(readOnly = true) +//@Service("qrCodeService") +//@Transactional(readOnly = true) public class QRCodeService { private final Logger logger = LoggerFactory.getLogger(ProtocolService.class); - @Resource +// @Resource private VenueMapper venueMapper; - @Resource +// @Resource private DeviceMapper deviceMapper; public Venue initEnter(Integer venueId,String deviceName,DeviceType deviceType,Integer memberId) throws ServiceException{