<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-base</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-web</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-annotation</artifactId>
<version>3.2.0</version>
</dependency>
public void exportWord(String projectId, HttpServletResponse response) throws Exception{
//获取项目根目录
File path = new File(ResourceUtils.getURL("classpath:").getPath());
//导出前的检查
beforeExportWord(path);
//业务代码
//根据项目id获取项目信息
ProjectEntity entity = projectRepository.getOne(projectId);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/x-download");
//把项目名称当作zip包的名字
String fileName = entity.getProjectName()+".zip";
fileName = URLEncoder.encode(fileName, "UTF-8");
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
//获取该项目下评测机构的list
List<PgzjEntity> pgzjList = pgzjRepository.findByProjectIdOrderByPgzjIdAsc(projectId);
List<PgzjCompanyEntity> companList = new ArrayList<>();
if(pgzjList.size()>0){
for(PgzjEntity pgzjItem: pgzjList){
PgjgInfoUserEntity pgjgInfoUser = pgjgInfoUserRepository.findByPgjgLoginIdAndProjectId(pgzjItem.getLoginId(), pgzjItem.getProjectId()).get(0);
PgjgInfoEntity pgjgInfo = pgjgInfoRepository.getOne(pgjgInfoUser.getPgjgInfoId());
//获取每个机构下评测的产品
companList = pgzjCompanyRepository.findByPgzjId(pgzjItem.getPgzjId());
if(companList.size()>0){
for(PgzjCompanyEntity companItem:companList){
//异步执行生成word方法
asyncService.caretWord(companItem,pgjgInfo,path,pgzjItem);
//生成的word文档放到word文件夹下
}
}
}
}
//业务代码结束
//超两分钟跳出循环,执行打,防止无限循环
Long startId = System.currentTimeMillis();
while (System.currentTimeMillis()-startId<120*1000){
int a = 0;
File word = new File(path.getAbsolutePath(), "/word");
System.out.println("开始:");
File[] arr = word.listFiles();
if(arr.length==(pgzjList.size()*companList.size())){
break;
}
System.out.println("等待:"+arr.length);
}
exportZip(path,response);
}
public void beforeExportWord(File path) throws Exception {
//获取临时存放生成word文件夹
File word = new File(path.getAbsolutePath(), "/word");
//判断文件夹是否存在,存在清空文件夹,不存在创建文件夹
if (word.exists()) {
for (File f : word.listFiles()) {
f.delete();
}
} else {
word.mkdir();
}
//获取临时存放生成zip文件夹
File zip = new File(path.getAbsolutePath(), "/zip");
//判断文件夹是否存在,存在清空文件夹,不存在创建文件夹
if (zip.exists()) {
for (File f : zip.listFiles()) {
f.delete();
}
} else {
zip.mkdir();
}
}
public void exportZip(File path,HttpServletResponse response) throws Exception{
FileOutputStream fos1 = new FileOutputStream(new File(path.getAbsolutePath()+"/zip/模板.zip"));
ZipUtils.toZip(path.getAbsolutePath()+"/word", fos1, true);
OutputStream fos = null;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
fos = response.getOutputStream();
bis = new BufferedInputStream(new FileInputStream(path.getAbsolutePath()+"/zip/模板.zip"));
bos = new BufferedOutputStream(fos);
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
fos.flush();
bis.close();
bos.close();
fos.close();
}
}
}
import java.io.*;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
import java.net.Socket;
public class Client {
public static void main(String[] args) throws IOException {
Socket socket = new Socket();
// 超时时间
socket.setSoTimeout(3000);
// 连接本地,端口2000;超时时间3000ms
socket.connect(new InetSocketAddress(Inet4Address.getLocalHost(), 8000), 3000);
System.out.println("已发起服务器连接,并进入后续流程~");
System.out.println("客户端信息:" + socket.getLocalAddress() + " P:" + socket.getLocalPort());
System.out.println("服务器信息:" + socket.getInetAddress() + " P:" + socket.getPort());
try {
// 发送接收数据
todo(socket);
} catch (Exception e) {
System.out.println("异常关闭");
}
// 释放资源
socket.close();
System.out.println("客户端已退出~");
}
private static void todo(Socket client) throws IOException {
// 构建键盘输入流
InputStream in = System.in;
BufferedReader input = new BufferedReader(new InputStreamReader(in));
// 得到Socket输出流,并转换为打印流
OutputStream outputStream = client.getOutputStream();
PrintStream socketPrintStream = new PrintStream(outputStream);
// 得到Socket输入流,并转换为BufferedReader
InputStream inputStream = client.getInputStream();
BufferedReader socketBufferedReader = new BufferedReader(new InputStreamReader(inputStream));
boolean flag = true;
do {
// 键盘读取一行
String str = input.readLine();
// 发送到服务器
socketPrintStream.println(str);
// 从服务器读取一行
String echo = socketBufferedReader.readLine();
if ("bye".equalsIgnoreCase(echo)) {
flag = false;
}else {
System.out.println(echo);
}
}while (flag);
// 资源释放
socketPrintStream.close();
socketBufferedReader.close();
}
}package com.flink;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.mortbay.util.ajax.JSON;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class sendTest {
private static CloseableHttpClient httpClient;
// private static HttpPost httpPost;
public static void main(String[] args) throws Exception {
int Total= 1000000;
int Num = 0;
httpClient = HttpClients.createDefault();
long Starttime = System.currentTimeMillis();
for(int i = 0; i< Total; i++){
List<Object> List = new ArrayList<>();
Map<String, Object> map1 = new HashMap<>();
Map<String, String> tags = new HashMap<>();
tags.put("operationValue", "HDFF88FFF");
tags.put("gateMac", "00E2690CDFFD");
map1.put("metric", 10);
map1.put("value", i);
map1.put("tags", tags);
// System.out.println(i + "条数据");
map1.put("timestamp", Starttime/1000 + i + 3000000);
List.add(map1);
Num += 1;
if (Num >= 200) {
long Starttime1 = System.currentTimeMillis();
sendPost("http://192.168.3.101:4242/api/put?async", List);
long Endtime1 = System.currentTimeMillis();
System.out.println("==============================opentsdb写入耗时=============================: " + (Endtime1-Starttime1));
Num = 0;
List.clear();
}
}
long EndTime = System.currentTimeMillis();
System.out.println(Starttime);
System.out.println(EndTime);
System.out.println("处理" + Total + "条数据, 消耗: " + (EndTime - Starttime));
}
public static void sendPost(final String url, List<Object> list) throws IOException {
final HttpPost httpPost = new HttpPost(url);
if (! list.isEmpty()) {
// System.out.println(list);
String string = JSON.toString(list);
StringEntity entity = new StringEntity(string, "utf-8");
entity.setContentEncoding("utf-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
httpClient.execute(httpPost);
}
}
}#coding:utf-8
import time
import requests
import uuid
import math
import random
import time, threading
start = time.time()
start_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
def get_value(num):
return math.sin(num)+1
def send_json(json, s, ip):
url = "http://%s:4242/api/put" % ip
r = s.post(url, json=json)
return r.text
def main(metric, ip, Num):
s = requests.Session()
a = int(time.time() + 2000000) - Num
# print(a)
ls = []
k = random.randint(0, 10000)
value = "转速"
# value = "转速".encode('unicode_escape')
# value = value.replace("\\u", "")
for i in range(1, Num):
print("%s: %s条数据" % (ip, i))
time.sleep(2)
json = {
"metric": metric,
"timestamp": a,
"value": "sdfasd",
"tags": {
"operationValue": "HDFF88FFF",
"gateMac": "00E2690CDFFD",
}
}
a += 1
k += 0.01
ls.append(json)
if len(ls) == 1:
send_json(ls, s, ip)
ls = []
send_json(ls, s, ip)
print("%s: %s条数据" % (ip, Num))
print("开始时间: %s" % start_time)
print("时间: %s" % time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())))
import json
def read_opentsdb():
queries = [{
"metric": 53,
"tags": {"operationValue": "WeldCurrent"},
"aggregator": "none",
}]
url = "http://192.168.3.101:4242/api/query"
post_dict = {
"start": 1551285963,
"end": 1551285965,
"queries": queries
}
ret = requests.post(url, data=json.dumps(post_dict))
data_ret = ret.json()
print(data_ret)
def start_opentsdb():
main("12", "192.168.3.101", 1000000)
if __name__ == "__main__":
start_opentsdb()
# read_opentsdb()