From e074a057b0a9c11022c57185d6e559e45cea1b3a Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期一, 26 八月 2019 18:47:14 +0800
Subject: [PATCH] first commit
---
src/main/resources/generator/generatorConfig.xml | 52 ++++++++++
src/main/kotlin/com/flightfeather/obd/domain/MyMapper.kt | 8 +
src/main/kotlin/com/flightfeather/obd/lightshare/packgeinfo.kt | 2
pom.xml | 93 ++++++++++++++++++
src/main/kotlin/com/flightfeather/obd/ObdApplication.kt | 4
src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt | 39 +++++++
src/main/resources/application.yml | 0
src/main/kotlin/com/flightfeather/obd/socket/SocketServerClient.kt | 49 +++++++++
8 files changed, 247 insertions(+), 0 deletions(-)
diff --git a/pom.xml b/pom.xml
index 946f63e..7c168a5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,6 +18,9 @@
<properties>
<java.version>1.8</java.version>
<kotlin.version>1.2.71</kotlin.version>
+ <!-- tk.mybatis -->
+ <mapper.plugin>tk.mybatis.mapper.generator.MapperPlugin</mapper.plugin>
+ <mapper.Mapper>tk.mybatis.mapper.common.Mapper</mapper.Mapper>
</properties>
<dependencies>
@@ -59,6 +62,32 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
+ <!--mybatis-->
+ <dependency>
+ <groupId>org.mybatis.spring.boot</groupId>
+ <artifactId>mybatis-spring-boot-starter</artifactId>
+ <version>2.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mybatis.generator</groupId>
+ <artifactId>mybatis-generator-core</artifactId>
+ <version>1.3.7</version>
+ </dependency>
+
+ <!--tk.mybatis-->
+ <dependency>
+ <groupId>tk.mybatis</groupId>
+ <artifactId>mapper-spring-boot-starter</artifactId>
+ <version>2.1.5</version>
+ </dependency>
+
+ <!--Netty-->
+ <dependency>
+ <groupId>io.netty</groupId>
+ <artifactId>netty-all</artifactId>
+ <version>4.1.39.Final</version>
+ </dependency>
+
</dependencies>
<build>
@@ -88,7 +117,71 @@
</dependency>
</dependencies>
</plugin>
+ <!-- mybatis generator 鑷姩鐢熸垚浠g爜鎻掍欢 -->
+ <plugin>
+ <groupId>org.mybatis.generator</groupId>
+ <artifactId>mybatis-generator-maven-plugin</artifactId>
+ <version>1.3.7</version>
+ <configuration>
+ <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
+ <overwrite>true</overwrite>
+ <verbose>true</verbose>
+ </configuration>
+
+ <dependencies>
+ <!-- https://mvnrepository.com/artifact/tk.mybatis/mapper -->
+ <dependency>
+ <groupId>tk.mybatis</groupId>
+ <artifactId>mapper</artifactId>
+ <version>4.1.5</version>
+ </dependency>
+ </dependencies>
+ </plugin>
</plugins>
</build>
+ <!--渚濊禆涓嬭浇鍦板潃-->
+ <repositories>
+ <repository>
+ <id>alimaven</id>
+ <name>aliyun maven</name>
+ <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
+ </repository>
+ <repository>
+ <id>spring-snapshots</id>
+ <name>Spring Snapshots</name>
+ <url>https://repo.spring.io/snapshot</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>spring-milestones</id>
+ <name>Spring Milestones</name>
+ <url>https://repo.spring.io/milestone</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>spring-snapshots</id>
+ <name>Spring Snapshots</name>
+ <url>https://repo.spring.io/snapshot</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ <pluginRepository>
+ <id>spring-milestones</id>
+ <name>Spring Milestones</name>
+ <url>https://repo.spring.io/milestone</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+
</project>
diff --git a/src/main/kotlin/com/flightfeather/obd/ObdApplication.kt b/src/main/kotlin/com/flightfeather/obd/ObdApplication.kt
index 6d1d434..50ebef2 100644
--- a/src/main/kotlin/com/flightfeather/obd/ObdApplication.kt
+++ b/src/main/kotlin/com/flightfeather/obd/ObdApplication.kt
@@ -1,5 +1,6 @@
package com.flightfeather.obd
+import com.flightfeather.obd.socket.SocketServerClient
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
@@ -7,5 +8,8 @@
class ObdApplication
fun main(args: Array<String>) {
+
+ SocketServerClient().startServer(9000)
+
runApplication<ObdApplication>(*args)
}
diff --git a/src/main/kotlin/com/flightfeather/obd/domain/MyMapper.kt b/src/main/kotlin/com/flightfeather/obd/domain/MyMapper.kt
new file mode 100644
index 0000000..2c35bdc
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/domain/MyMapper.kt
@@ -0,0 +1,8 @@
+package com.flightfeather.obd.domain
+
+import tk.mybatis.mapper.common.Mapper
+import tk.mybatis.mapper.common.MySqlMapper
+
+interface MyMapper<T> : Mapper<T>, MySqlMapper<T> {
+
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/lightshare/packgeinfo.kt b/src/main/kotlin/com/flightfeather/obd/lightshare/packgeinfo.kt
new file mode 100644
index 0000000..05b7a70
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/lightshare/packgeinfo.kt
@@ -0,0 +1,2 @@
+package com.flightfeather.obd.lightshare
+
diff --git a/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt b/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt
new file mode 100644
index 0000000..e1480ee
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt
@@ -0,0 +1,39 @@
+package com.flightfeather.obd.socket
+
+import io.netty.channel.ChannelHandlerContext
+import io.netty.channel.ChannelInboundHandlerAdapter
+import io.netty.util.AttributeKey
+
+class ServerHandler : ChannelInboundHandlerAdapter() {
+
+ val attributeKey = AttributeKey.valueOf<String>("deviceCode")
+
+ override fun channelRegistered(ctx: ChannelHandlerContext?) {
+ super.channelRegistered(ctx)
+ }
+
+ override fun channelActive(ctx: ChannelHandlerContext?) {
+ super.channelActive(ctx)
+ }
+
+ override fun channelRead(ctx: ChannelHandlerContext?, msg: Any?) {
+ super.channelRead(ctx, msg)
+ val attribute = ctx?.channel()?.attr(attributeKey)?.apply {
+ if (get() == null) {
+// set()
+ }
+ }
+ }
+
+ override fun channelReadComplete(ctx: ChannelHandlerContext?) {
+ super.channelReadComplete(ctx)
+ }
+
+ override fun channelInactive(ctx: ChannelHandlerContext?) {
+ super.channelInactive(ctx)
+ }
+
+ override fun exceptionCaught(ctx: ChannelHandlerContext?, cause: Throwable?) {
+ super.exceptionCaught(ctx, cause)
+ }
+}
\ No newline at end of file
diff --git a/src/main/kotlin/com/flightfeather/obd/socket/SocketServerClient.kt b/src/main/kotlin/com/flightfeather/obd/socket/SocketServerClient.kt
new file mode 100644
index 0000000..bf89577
--- /dev/null
+++ b/src/main/kotlin/com/flightfeather/obd/socket/SocketServerClient.kt
@@ -0,0 +1,49 @@
+package com.flightfeather.obd.socket
+
+import io.netty.bootstrap.ServerBootstrap
+import io.netty.channel.ChannelInitializer
+import io.netty.channel.ChannelOption
+import io.netty.channel.nio.NioEventLoopGroup
+import io.netty.channel.socket.SocketChannel
+import io.netty.channel.socket.nio.NioServerSocketChannel
+import io.netty.channel.socket.nio.NioSocketChannel
+
+/**
+ * socket闀胯繛鎺ユ湇鍔$
+ * 2019.8.26
+ * @author riku
+ */
+class SocketServerClient {
+
+// val sessionMap = HashMap<String, IoSession>
+
+ fun startServer(port: Int) {
+ initialize()?.bind(port)?.sync()
+ ?.channel()?.closeFuture()?.sync()
+ }
+
+ private fun initialize(): ServerBootstrap? {
+ val bossGroup = NioEventLoopGroup()
+ val workerGroup = NioEventLoopGroup()
+
+ try {
+ return ServerBootstrap()
+ .group(bossGroup, workerGroup)
+ .channel(NioServerSocketChannel::class.java)
+ .childHandler(object : ChannelInitializer<NioSocketChannel>() {
+ override fun initChannel(p0: NioSocketChannel?) {
+ p0?.pipeline()?.addLast(ServerHandler())
+ }
+ })
+ .option(ChannelOption.SO_BACKLOG, 128)
+ .childOption(ChannelOption.SO_KEEPALIVE, true)
+ } catch (e: Throwable) {
+ e.printStackTrace()
+ } finally {
+ bossGroup.shutdownGracefully()
+ workerGroup.shutdownGracefully()
+ }
+
+ return null
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/application.properties b/src/main/resources/application.yml
similarity index 100%
rename from src/main/resources/application.properties
rename to src/main/resources/application.yml
diff --git a/src/main/resources/generator/generatorConfig.xml b/src/main/resources/generator/generatorConfig.xml
new file mode 100644
index 0000000..8039021
--- /dev/null
+++ b/src/main/resources/generator/generatorConfig.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE generatorConfiguration
+ PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
+ "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
+<generatorConfiguration>
+ <!-- 鏁版嵁搴撻┍鍔�:閫夋嫨浣犵殑鏈湴纭洏涓婇潰鐨勬暟鎹簱椹卞姩鍖�-->
+ <classPathEntry location="C:\Users\feiyu\.m2\repository\mysql\mysql-connector-java\5.1.46\mysql-connector-java-5.1.46.jar"/>
+ <!--defaultModelType{
+ conditional:杩欎釜妯″瀷涓巋ierarchical妯″瀷鐩镐技,闄や簡濡傛灉涓�涓疄浣撶被鍙寘鍚竴涓瓧娈�,鍒欎笉浼氬崟鐙敓鎴愭瀹炰綋绫汇�傚洜姝�,濡傛灉涓�涓〃鐨勪富閿彧鏈変竴涓瓧娈�,閭d箞涓嶄細涓鸿瀛楁鐢熸垚鍗曠嫭鐨勫疄浣撶被,浼氬皢璇ュ瓧娈靛悎骞跺埌鍩烘湰瀹炰綋绫讳腑銆�
+ flat:璇ユā鍨嬩负姣忎竴寮犺〃鍙敓鎴愪竴涓疄浣撶被銆傝繖涓疄浣撶被鍖呭惈琛ㄤ腑鐨勬墍鏈夊瓧娈点��
+ hierarchical:濡傛灉琛ㄦ湁涓婚敭,閭d箞璇ユā鍨嬩細浜х敓涓�涓崟鐙殑涓婚敭瀹炰綋绫�,濡傛灉琛ㄨ繕鏈塀LOB瀛楁锛屽垯浼氫负琛ㄧ敓鎴愪竴涓寘鍚墍鏈塀LOB瀛楁鐨勫崟鐙殑瀹炰綋绫�,鐒跺悗涓烘墍鏈夊叾浠栫殑瀛楁鐢熸垚涓�涓崟鐙殑瀹炰綋绫汇�侻BG浼氬湪鎵�鏈夌敓鎴愮殑瀹炰綋绫讳箣闂寸淮鎶や竴涓户鎵垮叧绯汇��
+ }-->
+ <context id="DB2Tables" defaultModelType="flat" targetRuntime="MyBatis3">
+ <!-- TKmybatis閰嶇疆 -->
+ <property name="javaFileEncoding" value="UTF-8"/>
+ <property name="beginningDelimiter" value="`"/>
+ <property name="endingDelimiter" value="`"/>
+ <plugin type="${mapper.plugin}">
+ <property name="mappers" value="${mapper.Mapper}"/>
+ </plugin>
+ <commentGenerator>
+ <property name="suppressDate" value="true"/>
+ <!-- 鏄惁鍘婚櫎鑷姩鐢熸垚鐨勬敞閲� true锛氭槸 锛� false:鍚� -->
+ <property name="suppressAllComments" value="true"/>
+ </commentGenerator>
+ <!--鏁版嵁搴撻摼鎺RL锛岀敤鎴峰悕銆佸瘑鐮� -->
+ <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://47.100.191.150:3306/obd"
+ userId="obd"
+ password="obd2019">
+ </jdbcConnection>
+ <javaTypeResolver>
+ <property name="forceBigDecimals" value="false"/>
+ </javaTypeResolver>
+ <!-- 鐢熸垚妯″瀷鐨勫寘鍚嶅拰浣嶇疆-->
+ <javaModelGenerator targetPackage="com.flightfeather.obd.domain.entity" targetProject="src/main/kotlin">
+ <property name="enableSubPackages" value="true"/>
+ <property name="trimStrings" value="true"/>
+ </javaModelGenerator>
+ <!-- 鐢熸垚鏄犲皠鏂囦欢鐨勫寘鍚嶅拰浣嶇疆-->
+ <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
+ <property name="enableSubPackages" value="true"/>
+ </sqlMapGenerator>
+ <!-- 鐢熸垚DAO鐨勫寘鍚嶅拰浣嶇疆-->
+ <javaClientGenerator type="XMLMAPPER" targetPackage="com.flightfeather.obd.domain.mapper" targetProject="src/main/kotlin">
+ <property name="enableSubPackages" value="true"/>
+ </javaClientGenerator>
+ <!-- 瑕佺敓鎴愮殑琛� tableName鏄暟鎹簱涓殑琛ㄥ悕鎴栬鍥惧悕 domainObjectName鏄疄浣撶被鍚�-->
+ <table tableName="obd_data" domainObjectName="ObdData" enableCountByExample="false"
+ enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false"
+ selectByExampleQueryId="false"/>
+ </context>
+</generatorConfiguration>
\ No newline at end of file
--
Gitblit v1.9.3