winter il y a 1 mois
Parent
révision
6b9946ad40
10 fichiers modifiés avec 89 ajouts et 5 suppressions
  1. +4
    -0
      bjairAdmin/src/main/resources/application-dev.yml
  2. +4
    -0
      bjairAdmin/src/main/resources/application-prod.yml
  3. +8
    -0
      bjairCApi/src/main/java/com/iformall/CApplication.java
  4. +10
    -0
      bjairCApi/src/main/java/com/iformall/controller/HaiKangController.java
  5. +4
    -0
      bjairCApi/src/main/resources/application-dev.yml
  6. +4
    -0
      bjairCApi/src/main/resources/application-prod.yml
  7. +41
    -0
      bjairService/src/main/java/com/iformall/haikang/CarNumberFactory.java
  8. +5
    -2
      bjairService/src/main/java/com/iformall/haikang/netty/NioSocketHandler.java
  9. +5
    -2
      bjairService/src/main/java/com/iformall/haikang/netty/NioSocketInitializer.java
  10. +4
    -1
      bjairService/src/main/java/com/iformall/haikang/netty/NioSocketServer.java

+ 4
- 0
bjairAdmin/src/main/resources/application-dev.yml Voir le fichier

@@ -164,6 +164,10 @@ video:
tcp:
server:
port: 9010
air:
car:
file: /root/byjc


jasypt:


+ 4
- 0
bjairAdmin/src/main/resources/application-prod.yml Voir le fichier

@@ -151,6 +151,10 @@ video:
tcp:
server:
port: 9010
air:
car:
file: /root/byjc

fm:
exception: false


+ 8
- 0
bjairCApi/src/main/java/com/iformall/CApplication.java Voir le fichier

@@ -50,6 +50,9 @@ public class CApplication implements CommandLineRunner{
@Value("${tcp.server.port}")
private int tcpServerPort;
@Value("${air.car.file}")
private String airCarFile;
@Autowired
private NioSocketServer nioSocketServer;
@@ -93,6 +96,11 @@ public class CApplication implements CommandLineRunner{
public int tcpServerPort() {
return tcpServerPort;
}
@Bean
public String airCarFile() {
return airCarFile;
}

public static void main(String[] args) {
SpringApplication.run(CApplication.class, args);


+ 10
- 0
bjairCApi/src/main/java/com/iformall/controller/HaiKangController.java Voir le fichier

@@ -36,6 +36,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.iformall.annotation.AuthIgnore;
import com.iformall.common.ResultData;
import com.iformall.haikang.CarNumberFactory;
import com.iformall.haikang.HKHttpClientInstanceFactory;
import com.iformall.haikang.HKPeopleNumberFactory;

@@ -72,12 +73,21 @@ public class HaiKangController {
@Autowired
HKPeopleNumberFactory peopleNumberFactory;
@Autowired
CarNumberFactory carNumberFactory;
@AuthIgnore
@GetMapping("/getPeopleNumber")
public ResultData getPeopleNumber() {
return new ResultData(peopleNumberFactory.getPeopleNumber());
}
@AuthIgnore
@GetMapping("/getCarNumber")
public ResultData getCarNumber() {
return new ResultData(carNumberFactory.getCarNumber());
}
@AuthIgnore
@GetMapping("/setPeopleNumber")
public ResultData setPeopleNumber(String ip,Integer peopleNumber) {


+ 4
- 0
bjairCApi/src/main/resources/application-dev.yml Voir le fichier

@@ -161,6 +161,10 @@ video:
tcp:
server:
port: 9010
air:
car:
file: /root/byjc

jasypt:
encryptor:


+ 4
- 0
bjairCApi/src/main/resources/application-prod.yml Voir le fichier

@@ -132,6 +132,10 @@ video:
tcp:
server:
port: 9010
air:
car:
file: /root/byjc

fm:
exception: false


+ 41
- 0
bjairService/src/main/java/com/iformall/haikang/CarNumberFactory.java Voir le fichier

@@ -0,0 +1,41 @@
package com.iformall.haikang;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CarNumberFactory {
private final Logger log = LoggerFactory.getLogger(this.getClass());
@Autowired
private String airCarFile;

public Integer getCarNumber() {
int result = 0;
try (BufferedReader br = new BufferedReader(new FileReader(airCarFile))) {
String line;
while ((line = br.readLine()) != null) {
try {
result = Integer.parseInt(line);
break;
}catch(Exception e) {
log.error("getCarNumber error.",e);
}
}
} catch (FileNotFoundException e) {
log.error("getCarNumber error.",e);
} catch (IOException e) {
log.error("getCarNumber error.",e);
}
return result;
}
}

+ 5
- 2
bjairService/src/main/java/com/iformall/haikang/netty/NioSocketHandler.java Voir le fichier

@@ -15,6 +15,7 @@ import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iformall.haikang.CarNumberFactory;
import com.iformall.haikang.HKPeopleNumberFactory;

import io.netty.channel.ChannelHandlerContext;
@@ -28,11 +29,13 @@ public class NioSocketHandler extends SimpleChannelInboundHandler<String>{
private String hexData = "";
private HKPeopleNumberFactory peopleNumberFactory;
private CarNumberFactory carNumberFactory;
private final ThreadPoolTaskExecutor threadPoolTaskExecutor;

public NioSocketHandler(ThreadPoolTaskExecutor threadPoolTaskExecutor,HKPeopleNumberFactory peopleNumberFactory) {
public NioSocketHandler(ThreadPoolTaskExecutor threadPoolTaskExecutor,HKPeopleNumberFactory peopleNumberFactory,CarNumberFactory carNumberFactory) {
this.threadPoolTaskExecutor = threadPoolTaskExecutor;
this.peopleNumberFactory = peopleNumberFactory;
this.carNumberFactory = carNumberFactory;
}

@Override
@@ -123,7 +126,7 @@ public class NioSocketHandler extends SimpleChannelInboundHandler<String>{
value = peopleNumberFactory.getPeopleNumber();;//查询当前排队人数
break;
case 4:
value = 1;//查询场内出租车
value = carNumberFactory.getCarNumber();//查询场内出租车
break;
case 5:
value = 1;//查询在途出租车


+ 5
- 2
bjairService/src/main/java/com/iformall/haikang/netty/NioSocketInitializer.java Voir le fichier

@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import com.iformall.haikang.CarNumberFactory;
import com.iformall.haikang.HKPeopleNumberFactory;

import io.netty.channel.ChannelInitializer;
@@ -21,10 +22,12 @@ public class NioSocketInitializer extends ChannelInitializer<SocketChannel>{

private ThreadPoolTaskExecutor threadPoolTaskExecutor;
private HKPeopleNumberFactory peopleNumberFactory;
private CarNumberFactory carNumberFactory;

public NioSocketInitializer(ThreadPoolTaskExecutor threadPoolTaskExecutor,HKPeopleNumberFactory peopleNumberFactory) {
public NioSocketInitializer(ThreadPoolTaskExecutor threadPoolTaskExecutor,HKPeopleNumberFactory peopleNumberFactory,CarNumberFactory carNumberFactory) {
this.threadPoolTaskExecutor = threadPoolTaskExecutor;
this.peopleNumberFactory = peopleNumberFactory;
this.carNumberFactory = carNumberFactory;
}


@@ -46,7 +49,7 @@ public class NioSocketInitializer extends ChannelInitializer<SocketChannel>{

// 使用自定义线程池处理业务逻辑
log.info(">>>>peopleNumberFactory:"+peopleNumberFactory);
pipeline.addLast(new NioSocketHandler(threadPoolTaskExecutor,peopleNumberFactory));
pipeline.addLast(new NioSocketHandler(threadPoolTaskExecutor,peopleNumberFactory,carNumberFactory));
// 连接策略
pipeline.addLast(new IpRejectHandler());
}


+ 4
- 1
bjairService/src/main/java/com/iformall/haikang/netty/NioSocketServer.java Voir le fichier

@@ -6,6 +6,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import com.iformall.haikang.CarNumberFactory;
import com.iformall.haikang.HKPeopleNumberFactory;

import io.netty.bootstrap.ServerBootstrap;
@@ -23,6 +24,8 @@ public class NioSocketServer {
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
@Autowired
private HKPeopleNumberFactory peopleNumberFactory;
@Autowired
private CarNumberFactory carNumberFactory;

private EventLoopGroup bossGroup;
private EventLoopGroup workerGroup;
@@ -36,7 +39,7 @@ public class NioSocketServer {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new NioSocketInitializer(threadPoolTaskExecutor,peopleNumberFactory))
.childHandler(new NioSocketInitializer(threadPoolTaskExecutor,peopleNumberFactory,carNumberFactory))
.option(ChannelOption.SO_BACKLOG, 128)
.childOption(ChannelOption.SO_KEEPALIVE, true);



Chargement…
Annuler
Enregistrer