Commit f1f2026f authored by zhuangzhuang's avatar zhuangzhuang

12.18-线路历史数据下载接口

parent dec9362c
Pipeline #15 failed with stages
......@@ -550,6 +550,136 @@ public class DataController {
return gson.toJson(fb);
}
//下载数据
@ApiOperation(value = "abb下载线路数据", notes = "abb下载线路数据")
@PostMapping("/downLoadfForABB")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "header", name = "Account_token", value = "token", required = true, dataType = "String"),
@ApiImplicitParam(paramType = "header", name = "AccountLanguage", value = "language", required = true, dataType = "String"),
})
public String downLoadfForABB(@RequestBody TransportationNoVo transportationNo, HttpServletRequest request){
UserRedisVo user = gson.fromJson(tokenRedisService.get("TOKEN_" + request.getHeader("Account_token")), UserRedisVo.class);
ResultCircuitVo resultCircuitVo = circuitService.getByTransportationNo(transportationNo.getTransportationNo(), user.getCompanyNo());
if (resultCircuitVo == null) {
fb.setCode(0);
fb.setMessage(i18n.getMessage(request, "noCircuit"));
return gson.toJson(fb);
}
if(StringUtils.isEmpty(transportationNo.getOffset())){
transportationNo.setOffset("8");
}
if (resultCircuitVo.getStartTime() == null || resultCircuitVo.getStartTime() == 0) {
fb.setCode(0);
fb.setMessage(i18n.getMessage(request, "notStarted"));
return gson.toJson(fb);
}
Long startTime = resultCircuitVo.getStartTime() * 1000000l;
TDLLogVo gatewayVo = tdlLogService.getByTransportationNo(transportationNo.getTransportationNo());
if (gatewayVo == null) {
fb.setCode(0);
fb.setMessage(i18n.getMessage(request, "noCircuit"));
return gson.toJson(fb);
}
String device = gatewayVo.getgType() + "_" + gatewayVo.getgSN();
//获取tdl信息
List<String> devList = tdlLogService.getTdlSN(transportationNo.getTransportationNo());
if (devList.size() == 0) {
fb.setCode(0);
fb.setMessage(i18n.getMessage(request, "noCircuit"));
return gson.toJson(fb);
}
OSSClient ossClient = AliyunOSSClientUtil.getOSSClient();
String[] rowsName;
if("cn".equals(request.getHeader("AccountLanguage"))){
rowsName = new String[]{"时间","圧力(MPa)","海拔(m)","温度(℃)","湿度(%RH)","震动强度(g)","倾斜角度(°)","经度","纬度"};
}else if("jp".equals(request.getHeader("AccountLanguage"))){
rowsName = new String[]{"时间","圧力(MPa)","海抜(m)","温度(℃)","湿度(%RH)","振動(g)","回転(°)","経度","緯度"};
}else{
rowsName = new String[]{"Time","Pressure(MPa)","Altitude(m)","Temperature(℃)","Humidity(%RH)","Shock(g)","Tilt(°)","Longitude","Latitude"};
}
File file = new File("./export");
if(!file.exists()){
file.mkdir();
}
DecimalFormat df = new DecimalFormat("0.00");
df.getRoundingMode();
try {
String sqls = "";
if (resultCircuitVo.getEndTime() != null && resultCircuitVo.getEndTime() != 0) {
sqls = "SELECT \"tdl\",\"p\",\"T\",\"h\",\"a1\",\"ta\",\"bdlng\",\"bdlat\" FROM \"tdl_policy\".\""+device+"\" WHERE time >=" +startTime +" and time <=" +resultCircuitVo.getEndTime() * 1000000l+" ORDER BY time ";
} else {
sqls = "SELECT \"tdl\",\"p\",\"T\",\"h\",\"a1\",\"ta\",\"bdlng\",\"bdlat\" FROM \"tdl_policy\".\""+device+"\" WHERE time >=" +startTime +" and time <=" +System.currentTimeMillis() * 1000000l+" ORDER BY time ";
}
QueryResult queryResult = influxDBTemplate.query(new Query(sqls, database));
File[] srcFiles = new File[devList.size()];
File zipFile = new File("./export/" +transportationNo.getTransportationNo()+i18n.getMessage(request,"data")+".zip");
if (queryResult.getResults().get(0).getSeries().get(0) != null) {
for(int i = 0;i<devList.size();i++){
CsvWriter csvWriter = new CsvWriter("./export/"+devList.get(i).replace("TDL-", "").trim()+i18n.getMessage(request,"data")+".csv" , ',', Charset.forName("GBK"));
csvWriter.writeRecord(rowsName);
List<List<Object>> values = DataUtil.getValues(queryResult);
for(List<Object> value : values){
if(value.get(1) == null || value.get(1).toString().equals(devList.get(i))){
String[] objs = new String[rowsName.length];
for (int j = 0; j < objs.length; j++) {
if(j==0){
try {
objs[j] =timeStamp2Date(new Long(DataUtil.UTCToCST(String.valueOf(value.get(j)),transportationNo.getOffset())));
} catch (Exception e) {
e.printStackTrace();
logger.info(e.toString());
continue;
}
}else if(j ==1) {
String pressure = value.get(j+1) == null ? "-" :value.get(j+1).toString();
objs[j] =pressure;
Double altitude = value.get(j+1) == null ? null : 44300*(1-(Math.pow((Double.parseDouble(df.format(Float.valueOf(pressure)))/1013.25), (float)1/5.256)));
objs[j+1] =altitude == null ? "-" : altitude.toString();
}else{
objs[j] =value.get(j) == null ? "-" :value.get(j).toString();
}
}
csvWriter.writeRecord(objs);
csvWriter.flush();
}
}
csvWriter.close();
srcFiles[i]=new File("./export/"+devList.get(i).replace("TDL-", "").trim()+i18n.getMessage(request,"data")+".csv");
}
}
ZipCompressUtil.zipFiles(srcFiles,zipFile);
try {
String md5Key = AliyunOSSClientUtil.uploadObject2OSS(ossClient, zipFile);
if (md5Key != null) {
for(int a =0;a<srcFiles.length;a++){
srcFiles[a].delete();
}
zipFile.delete();
fb.setCode(1);
fb.setMessage("https://tdlcloud.oss-cn-shanghai.aliyuncs.com/circuit/"+transportationNo.getTransportationNo()+i18n.getMessage(request,"data")+".zip");
return gson.toJson(fb);
} else {
fb.setCode(0);
fb.setMessage(i18n.getMessage(request,"fileUpload"));
}
} catch (Exception e) {
e.printStackTrace();
logger.info(e.toString());
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.toString());
}
return gson.toJson(fb);
}
// @ApiOperation(value = "下载线路数据", notes = "下载线路数据")
// @PostMapping("/downLoad")
// @ApiImplicitParams({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment