增加数据库框架与单测框架

This commit is contained in:
HuangXin 2023-08-08 19:41:41 +08:00
parent e8b84aedb7
commit 7fb827d1ca
17 changed files with 193 additions and 14 deletions

View File

@ -1,18 +1,24 @@
server.port=9276 server.port=9276
# 多个项目放在nginx下同个端口通过该配置区分
server.servlet.context-path=/tunnel server.servlet.context-path=/tunnel
# mysql 配置 # mysql
# 配置数据源
spring.datasource.url=jdbc:mysql://101.35.234.160:32306/beidou?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\ spring.datasource.url=jdbc:mysql://101.35.234.160:32306/beidou?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior\
=convertToNull&useUnicode=true =convertToNull&useUnicode=true
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=cmhi spring.datasource.username=cmhi
spring.datasource.password=cmHi10086! spring.datasource.password=cmHi10086!
#mybatis 配置 #spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource
# 下划线转驼峰 将带有下划线的表字段映射为驼峰格式的实体类属性 spring.datasource.dbcp2.max-total=128
spring.datasource.dbcp2.max-wait-millis=10000
spring.datasource.dbcp2.max-idle=32
spring.datasource.dbcp2.min-idle=8
spring.datasource.dbcp2.initial-size=8
spring.datasource.dbcp2.validation-query=SELECT 1
spring.datasource.dbcp2.test-while-idle=true
spring.datasource.dbcp2.connection-properties=characterEncoding=utf8
#mybatis
#mybatis.configuration.map-underscore-to-camel-case: true #mybatis.configuration.map-underscore-to-camel-case: true
mybatis.mapper-locations=classpath*:mappers/*.xml mybatis.mapper-locations=classpath*:mappers/*.xml
mybatis.type-aliases-package=com.zjyr.beidouservice.pojo.entry mybatis.type-aliases-package=com.zjyr.beidouservice.pojo.entry

10
pom.xml
View File

@ -60,6 +60,16 @@
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
<version>2.20.0</version> <version>2.20.0</version>
</dependency> </dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.96.Final</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>4.2.3</version>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,9 +1,11 @@
package com.zjyr.beidouservice; package com.zjyr.beidouservice;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication @SpringBootApplication
@MapperScan(basePackages = {"com.zjyr.beidouservice.mapper"})
public class TunnelServiceApplication { public class TunnelServiceApplication {
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -0,0 +1,4 @@
package com.zjyr.beidouservice.adapter;
public interface ControlAdapter {
}

View File

@ -0,0 +1,5 @@
package com.zjyr.beidouservice.adapter.impl;
import com.zjyr.beidouservice.adapter.ControlAdapter;
public class TcpSocketAdapter implements ControlAdapter {
}

View File

@ -1,7 +1,7 @@
package com.zjyr.beidouservice.controller; package com.zjyr.beidouservice.controller;
import com.zjyr.beidouservice.pojo.entry.BaseProtocolDTO; import com.zjyr.beidouservice.pojo.dto.BaseProtocolDTO;
import com.zjyr.beidouservice.pojo.entry.GetUserConfig; import com.zjyr.beidouservice.pojo.dto.GetUserConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;

View File

@ -0,0 +1,12 @@
package com.zjyr.beidouservice.mapper;
import com.zjyr.beidouservice.pojo.entry.ControlDeviceType;
import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ControlDeviceTypeMapper {
List<ControlDeviceType> selectAll();
int addDeviceTypes(@Param("typeLists") List<ControlDeviceType> typeLists);
}

View File

@ -1,4 +1,4 @@
package com.zjyr.beidouservice.pojo.entry; package com.zjyr.beidouservice.pojo.dto;
import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonPropertyOrder;

View File

@ -1,4 +1,4 @@
package com.zjyr.beidouservice.pojo.entry; package com.zjyr.beidouservice.pojo.dto;
import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;

View File

@ -0,0 +1,4 @@
package com.zjyr.beidouservice.pojo.dto;
public class User {
}

View File

@ -0,0 +1,29 @@
package com.zjyr.beidouservice.pojo.entry;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import tk.mybatis.mapper.annotation.KeySql;
import tk.mybatis.mapper.annotation.NameStyle;
import tk.mybatis.mapper.code.Style;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder(alphabetic = true)
@Table(name = "control_device")
@NameStyle(Style.normal)
public class ControlDevice {
@Id
@KeySql(useGeneratedKeys = true)
private Long id;
private Long deviceType;
}

View File

@ -0,0 +1,29 @@
package com.zjyr.beidouservice.pojo.entry;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import tk.mybatis.mapper.annotation.KeySql;
import tk.mybatis.mapper.annotation.NameStyle;
import tk.mybatis.mapper.code.Style;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder(alphabetic = true)
@Table(name = "sonsor_data")
@NameStyle(Style.normal)
public class ControlDeviceType {
@Id
@KeySql(useGeneratedKeys = true)
private Long id;
private Long type;
}

View File

@ -0,0 +1,29 @@
package com.zjyr.beidouservice.pojo.entry;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import tk.mybatis.mapper.annotation.KeySql;
import tk.mybatis.mapper.annotation.NameStyle;
import tk.mybatis.mapper.code.Style;
import javax.persistence.Id;
import javax.persistence.Table;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder(alphabetic = true)
@Table(name = "sonsor_data")
@NameStyle(Style.normal)
public class SensorData {
@Id
@KeySql(useGeneratedKeys = true)
private Long id;
private Long deviceId;
}

View File

@ -1,4 +0,0 @@
package com.zjyr.beidouservice.pojo.entry;
public class User {
}

View File

@ -0,0 +1,22 @@
<?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="com.zjyr.beidouservice.mapper.ControlDeviceTypeMapper">
<resultMap id="device_type" type="com.zjyr.beidouservice.pojo.entry.ControlDeviceType">
<id column="id" property="id"/>
<result column="type" property="type"/>
</resultMap>
<select id="selectAll" resultMap="device_type">
SELECT *
FROM control_dev_type
</select>
<insert id="addDeviceTypes" useGeneratedKeys="true" keyProperty="id"
parameterType="com.zjyr.beidouservice.pojo.entry.ControlDeviceType">
INSERT IGNORE INTO control_device_type(type)
VALUES
<foreach collection="typeLists" item="itme" separator=",">
(#{itme.type})
</foreach>
</insert>
</mapper>

View File

@ -8,6 +8,7 @@ class TunnelServiceApplicationTests {
@Test @Test
void contextLoads() { void contextLoads() {
} }
} }

View File

@ -0,0 +1,30 @@
package com.zjyr.beidouservice.mapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.zjyr.beidouservice.pojo.entry.ControlDeviceType;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.Rollback;
import org.springframework.transaction.annotation.Transactional;
import org.junit.jupiter.api.Test;
import java.util.List;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Slf4j
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@Transactional
@Rollback
public class ControlDeviceTypeMapperTest {
@Resource
private ControlDeviceTypeMapper mapper;
@Test
public void a5_getTaskInfo() {
List<ControlDeviceType> typeList = mapper.selectAll();
Assertions.assertNotEquals(typeList.size(), 0);
}
}