120 lines
3.5 KiB
Plaintext
120 lines
3.5 KiB
Plaintext
package com.surfbird.util;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import com.surfbird.business.bean.HeatAnalyze;
|
|
import com.surfbird.business.bean.Instrucation;
|
|
import com.surfbird.business.service.HeatAnalyzeService;
|
|
import com.surfbird.business.service.HeatCollectService;
|
|
import com.surfbird.business.service.InstrucationService;
|
|
import com.surfbird.socket.server.service.MultiSocket;
|
|
import com.surfbird.util.convert.DataHandle;
|
|
import com.surfbird.util.convert.Recordable;
|
|
|
|
@Component
|
|
public class DataCollect {
|
|
@Autowired
|
|
private HeatAnalyzeService analyze;
|
|
@Autowired
|
|
private HeatCollectService collect;
|
|
@Autowired
|
|
private InstrucationService instrucation;
|
|
|
|
/**
|
|
* 清除数据日志.
|
|
**/
|
|
@Scheduled(cron="0 0 0 * * ?")
|
|
public void clear() {
|
|
Recordable.record("清楚数据采集日志(TQL_DATACOLLECT).");
|
|
//清楚采集数据日志.
|
|
analyze.clear(new HeatAnalyze());
|
|
}
|
|
|
|
/**
|
|
* 数据采集指令下发定时器.
|
|
**/
|
|
@Scheduled(cron="0 * * * * ?")
|
|
public void instructions() {
|
|
Map<String, MultiSocket> client = ClientCollect.instance().getClient();
|
|
Recordable.record("当前连接客户端:" + client.size() + "个.");
|
|
for(Map.Entry<String, MultiSocket> object : client.entrySet()) {
|
|
MultiSocket socket = object.getValue();
|
|
try {
|
|
socket.getWriter().write(DataHandle.toStringByte(socket.getClient().getOrder()));
|
|
socket.getWriter().flush();
|
|
} catch(Exception e) {
|
|
socket.close();
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* SQL SERVER 数据采集程序数据转存定时器(已弃用).
|
|
**/
|
|
public void collect() {
|
|
StringBuffer buffer = new StringBuffer();
|
|
List<HeatAnalyze> list = collect.list();
|
|
buffer.append("采集数据:");
|
|
buffer.append(list.size());
|
|
buffer.append("条");
|
|
if(list.size() > 0 ) {
|
|
buffer.append(";数据内容:[");
|
|
for(HeatAnalyze heat : list) {
|
|
//通过SIM查询CODE数据.
|
|
HeatAnalyze heatObject = analyze.show(heat);
|
|
if(heatObject != null) {
|
|
//设置设备代码.
|
|
heat.setCode(heatObject.getCode());
|
|
//插入数据信息.
|
|
analyze.save(heat);
|
|
//清除处理的数据.
|
|
collect.clear(heat);
|
|
buffer.append("(");
|
|
buffer.append(heat.getCode()).append(",");
|
|
buffer.append(heat.getSim()).append(",");
|
|
buffer.append(heat.getDatatime()).append(",");
|
|
buffer.append(heat.getView005()).append(",");
|
|
buffer.append(heat.getView006()).append(",");
|
|
buffer.append(heat.getView007()).append(",");
|
|
buffer.append(heat.getView008()).append(",");
|
|
buffer.append(heat.getView009()).append(",");
|
|
buffer.append(heat.getView010()).append(",");
|
|
buffer.append(heat.getView011()).append(",");
|
|
buffer.append(heat.getView012());
|
|
buffer.append(")");
|
|
} else {
|
|
System.out.println("[" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "] - 未注册设备手机卡:" + heat.getSim());
|
|
}
|
|
}
|
|
buffer.append("].");
|
|
} else {
|
|
buffer.append(".");
|
|
}
|
|
//记录数据采集日志
|
|
this.toInstrucation(buffer.toString(), "数据采集-转存数据");
|
|
}
|
|
|
|
/**
|
|
* 记录数据采集日志.
|
|
* @param content:日志内容.
|
|
* @param label:日志说明.
|
|
**/
|
|
private void toInstrucation(String content, String label) {
|
|
//日志对象.
|
|
Instrucation insObject = new Instrucation();
|
|
//设置日志内容.
|
|
insObject.setContent(content);
|
|
//设置日志描述.
|
|
insObject.setInstrucation(label);
|
|
//插入日志信息.
|
|
instrucation.save(insObject);
|
|
}
|
|
}
|