commit
e80b37a25c
@ -0,0 +1,21 @@
|
||||
# Created by .ignore support plugin (hsz.mobi)
|
||||
### Example user template template
|
||||
### Example user template
|
||||
|
||||
# IntelliJ project files
|
||||
.idea
|
||||
*.iml
|
||||
out
|
||||
gen
|
||||
### Maven template
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.3.12.RELEASE</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
<groupId>com.mashibing</groupId>
|
||||
<artifactId>futuretask</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>5.1.47</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>2.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -0,0 +1,20 @@
|
||||
package com.mashibing;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@MapperScan(basePackages = "com.mashibing.mapper")
|
||||
public class FutureTaskStarterApp {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(FutureTaskStarterApp.class,args);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.mashibing.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Data
|
||||
public class Air implements Serializable {
|
||||
|
||||
private Long id;
|
||||
|
||||
private int pm25;
|
||||
|
||||
private String monitoringStation;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.mashibing.mapper;
|
||||
|
||||
import com.mashibing.entity.Air;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public interface AirMapper {
|
||||
|
||||
@Select("select * from air")
|
||||
List<Air> findAll();
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.mashibing.service;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
public interface PushService {
|
||||
|
||||
void pushData();
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package com.mashibing.service.impl;
|
||||
|
||||
import com.mashibing.entity.Air;
|
||||
import com.mashibing.mapper.AirMapper;
|
||||
import com.mashibing.service.PushService;
|
||||
import com.mashibing.util.PushUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class PushServiceImpl implements PushService {
|
||||
|
||||
@Autowired
|
||||
private PushUtil pushUtil;
|
||||
|
||||
@Resource
|
||||
private AirMapper airMapper;
|
||||
|
||||
@Override
|
||||
public void pushData() {
|
||||
long start = System.currentTimeMillis();
|
||||
List<Air> errorData = new ArrayList<>();
|
||||
List<Air> airList = airMapper.findAll();
|
||||
log.info("【推送数据】 推送air数据条数 = {}",airList.size());
|
||||
for (Air air : airList) {
|
||||
boolean success = pushUtil.push(air);
|
||||
if(!success){
|
||||
errorData.add(air);
|
||||
// 插入推送失败日志。
|
||||
}
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
log.info("【推送数据】 推送air数据条数 = {},花费时间 = {}",airList.size() - errorData.size(),(end - start) / 1000);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.mashibing.util;
|
||||
|
||||
import com.mashibing.entity.Air;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author zjw
|
||||
* @description
|
||||
*/
|
||||
@Component
|
||||
public class PushUtil {
|
||||
|
||||
|
||||
public boolean push(Air air){
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/air
|
||||
|
||||
mybatis:
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
@ -0,0 +1,22 @@
|
||||
package com.mashibing.service;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class PushServiceTest {
|
||||
|
||||
@Autowired
|
||||
private PushService pushService;
|
||||
|
||||
@Test
|
||||
public void pushData() {
|
||||
pushService.pushData();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue