Commit d85a8053 authored by chenying's avatar chenying

6.6修改分配公司接口,修改用户接口,添加仓库数据下载接口

parent ce7d2c94
package com.example.tdl.common;
import com.example.tdl.domain.vo.WarehouseDetailVo;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class WarehouseExcel {
private Logger logger = LoggerFactory.getLogger(WarehouseExcel.class);
//导出的文件名
private String fileName;
private String userName;
private HttpServletResponse response;
private WarehouseDetailVo warehouseDetailVo;
public WarehouseExcel(String fileName, WarehouseDetailVo warehouseDetailVo ,String userName, HttpServletResponse response) {
this.userName = userName;
this.fileName = fileName;
this.response = response;
this.warehouseDetailVo=warehouseDetailVo;
}
/*
* 导出数据
* */
public HSSFWorkbook downloadExcel() throws Exception {
// 创建工作簿对象
HSSFWorkbook workbook = new HSSFWorkbook();
try {
HSSFSheet sheet = workbook.createSheet("仓库温湿度观测记录表"); // 创建工作表
HSSFCellStyle style = getStyle(workbook);
/*
* 创建第一行(标题行)
* */
HSSFRow row1 = sheet.createRow((short) 0);
HSSFCell cell1 = null;
//设置单元格格式
HSSFCellStyle rowStyle1 = getTitleStyle(workbook);
//循环创建列
for (int n = 0; n < 6; n++) {
cell1 = row1.createCell(n);
//设置列的格式
cell1.setCellStyle(rowStyle1);
//将标题添加到列中
cell1.setCellValue(new HSSFRichTextString("仓库温湿度观测记录表"));
}
//设置行高
row1.setHeight((short) (30 * 20));
//合并单元格(参数1:起始行,参数2:截至行,参数3:起始列,参数4:截至列)
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 5));
/*
* 创建第二行
* */
HSSFRow row2 = sheet.createRow((short) 1);
HSSFCell cell2 = null;
HSSFCellStyle rowStyle2 = getStyle(workbook);
cell2 = row2.createCell(0);
cell2.setCellValue("年度");
cell2.setCellStyle(rowStyle2);
cell2 = row2.createCell(1);
cell2.setCellValue("");
cell2.setCellStyle(rowStyle2);
for (int n = 2; n < 6; n++) {
cell2 = row2.createCell(n);
//设置列的格式
cell2.setCellStyle(rowStyle2);
//将标题添加到列中
cell2.setCellValue("库房适宜温度为xx℃-xx℃,湿度保持xx%-xx%,超标要做必要调节。");
sheet.addMergedRegion(new CellRangeAddress(1, 1, 2, 4));
}
cell2 = row2.createCell(5);
cell2.setCellValue("记录人:"+userName);
cell2.setCellStyle(rowStyle2);
row2.setHeight((short) (26 * 20));
/*
* 创建第三行
* */
HSSFRow row3 = sheet.createRow((short) 2);
HSSFCell cell3 = null;
HSSFCellStyle rowStyle3 = getStyle(workbook);
for (int n = 0; n < 3; n++) {
cell3 = row3.createCell(n);
cell3.setCellStyle(rowStyle3);
//将标题添加到列中
cell3.setCellValue("测定时间");
sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 2));
}
cell3 = row3.createCell(3);
cell3.setCellValue("天气情况");
cell3.setCellStyle(rowStyle3);
cell3 = row3.createCell(4);
cell3.setCellValue("温度");
cell3.setCellStyle(rowStyle3);
cell3 = row3.createCell(5);
cell3.setCellValue("相对湿度");
cell3.setCellStyle(rowStyle3);
row3.setHeight((short) (26 * 20));
/** 创建第四行
* */
HSSFRow row4= sheet.createRow((short) 3);
HSSFCell cell4 = null;
HSSFCellStyle rowStyle4 = getStyle(workbook);
cell4 = row4.createCell(0);
cell4.setCellValue("月");
cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(1);
cell4.setCellValue("日");
cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(2);
cell4.setCellValue("时分");
cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(3);
cell4.setCellValue("天气情况");
cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(4);
cell4.setCellValue("温度");
cell4.setCellStyle(rowStyle4);
cell4 = row4.createCell(5);
cell4.setCellValue("相对湿度");
cell4.setCellStyle(rowStyle4);
sheet.addMergedRegion(new CellRangeAddress(2, 3, 3, 3));
sheet.addMergedRegion(new CellRangeAddress(2, 3, 4, 4));
sheet.addMergedRegion(new CellRangeAddress(2, 3, 5, 5));
row4.setHeight((short) (26 * 20));
/** 循环创建维修表的更换部件
* */
HSSFCellStyle rowStyle = getStyle(workbook);
int a=0;
for(int i = 0;i<warehouseDetailVo.getGatewayOnLineVos().size();i++) {
for (int j = 0; j < warehouseDetailVo.getGatewayOnLineVos().get(i).getTdlDeviceDetailVos().size(); j++) {
HSSFRow row = sheet.createRow((short) 4 + i);
HSSFCell cell = null;
Long time=Long.valueOf(warehouseDetailVo.getGatewayOnLineVos().get(i).getTdlDeviceDetailVos().get(j).getTime());
// SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date=new Date(time);
cell2 = row2.createCell(1);
cell2.setCellValue(date.getYear());
cell2.setCellStyle(rowStyle);
cell = row.createCell(0);
cell.setCellValue(date.getMonth());
cell.setCellStyle(rowStyle);
cell = row.createCell(1);
cell.setCellValue(date.getDay());
cell.setCellStyle(rowStyle);
cell = row.createCell(2);
cell.setCellValue(date.getHours()+":"+date.getMinutes());
cell.setCellStyle(rowStyle);
cell = row.createCell(3);
cell.setCellValue("-");
cell.setCellStyle(rowStyle);
cell = row.createCell(4);
cell.setCellValue(warehouseDetailVo.getGatewayOnLineVos().get(i).getTdlDeviceDetailVos().get(j).getTemperature());
cell.setCellStyle(rowStyle);
cell = row.createCell(5);
cell.setCellValue(warehouseDetailVo.getGatewayOnLineVos().get(i).getTdlDeviceDetailVos().get(j).getHumidity());
cell.setCellStyle(rowStyle);
row.setHeight((short) (26 * 20));
}
}
sheet.setColumnWidth(0, 10 * 256);
sheet.setColumnWidth(1, 10 * 256);
sheet.setColumnWidth(2, 10 * 256);
sheet.setColumnWidth(3, 27 * 256);
sheet.setColumnWidth(4, 27 * 256);
sheet.setColumnWidth(5, 27 * 256);
return workbook;
}catch (Exception e) {
e.printStackTrace();
logger.info(e.toString());
}
return workbook;
}
/*
* 标题单元格样式
*/
public static HSSFCellStyle getTitleStyle(HSSFWorkbook workbook) {
HSSFFont font = workbook.createFont();
font.setFontHeightInPoints((short)18);
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
font.setFontName("微软雅黑");
HSSFCellStyle style = workbook.createCellStyle();
style.setFont(font);
style.setWrapText(true);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
return style;
}
/*
* 列数据信息单元格样式
*/
public static HSSFCellStyle getStyle(HSSFWorkbook workbook){
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short)11);
font.setFontName("Arial");
//设置样式
HSSFCellStyle style = workbook.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFColor.BLACK.index);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setLeftBorderColor(HSSFColor.BLACK.index);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setRightBorderColor(HSSFColor.BLACK.index);
//设置顶边框;
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setTopBorderColor(HSSFColor.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
return style;
}
//文字左对齐
public static HSSFCellStyle getStageAlign(HSSFWorkbook workbook){
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short)11);
font.setFontName("Arial");
//设置样式
HSSFCellStyle style = workbook.createCellStyle();
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setLeftBorderColor(HSSFColor.BLACK.index);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setRightBorderColor(HSSFColor.BLACK.index);
//设置顶边框;
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setTopBorderColor(HSSFColor.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
return style;
}
//右对齐
public static HSSFCellStyle getJustifyRight(HSSFWorkbook workbook){
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short)11);
font.setFontName("Arial");
//设置样式
HSSFCellStyle style = workbook.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFColor.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为右对齐;
style.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
return style;
}
//左对齐
public static HSSFCellStyle getJustifyLeft(HSSFWorkbook workbook){
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short)11);
font.setFontName("Arial");
//设置样式
HSSFCellStyle style = workbook.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFColor.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为右对齐;
style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
return style;
}
//左对齐有右边框
public static HSSFCellStyle getAlignLeft(HSSFWorkbook workbook){
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short)11);
font.setFontName("Arial");
//设置样式
HSSFCellStyle style = workbook.createCellStyle();
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setRightBorderColor(HSSFColor.BLACK.index);
//设置顶边框;
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFColor.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
return style;
}
//左对齐,没有左右边框
public static HSSFCellStyle getJustifyCente(HSSFWorkbook workbook){
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short)11);
font.setFontName("Arial");
//设置样式
HSSFCellStyle style = workbook.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFColor.BLACK.index);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setRightBorderColor(HSSFColor.BLACK.index);
//设置顶边框;
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HSSFCellStyle.ALIGN_LEFT);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
return style;
}
public static HSSFCellStyle getBackGroundStyle(HSSFWorkbook workbook){
// 设置字体
HSSFFont font = workbook.createFont();
//设置字体大小
font.setFontHeightInPoints((short)11);
font.setFontName("Arial");
//设置样式
HSSFCellStyle style = workbook.createCellStyle();
style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
style.setBottomBorderColor(HSSFColor.BLACK.index);
style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
style.setLeftBorderColor(HSSFColor.BLACK.index);
style.setBorderRight(HSSFCellStyle.BORDER_THIN);
style.setRightBorderColor(HSSFColor.BLACK.index);
//设置顶边框;
style.setBorderTop(HSSFCellStyle.BORDER_THIN);
style.setTopBorderColor(HSSFColor.BLACK.index);
//在样式用应用设置的字体;
style.setFont(font);
//设置自动换行;
style.setWrapText(true);
//设置水平对齐的样式为居中对齐;
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
return style;
}
}
package com.example.tdl.domain.vo;
public class UpdateTDLCompanyVo {
private String TDLSN;
private String companyNo;
public String getTDLSN() {
return TDLSN;
}
public void setTDLSN(String TDLSN) {
this.TDLSN = TDLSN;
}
public String getCompanyNo() {
return companyNo;
}
public void setCompanyNo(String companyNo) {
this.companyNo = companyNo;
}
}
...@@ -8,13 +8,35 @@ public class UserNameVo { ...@@ -8,13 +8,35 @@ public class UserNameVo {
private String ipAddress; private String ipAddress;
private String companyImg;
private String companyAlias;
public UserNameVo() { public UserNameVo() {
} }
public UserNameVo(String userName, String time, String ipAddress) { public UserNameVo(String userName, String time, String ipAddress,String companyImg,String companyAlias) {
UserName = userName; UserName = userName;
this.time = time; this.time = time;
this.ipAddress = ipAddress; this.ipAddress = ipAddress;
this.companyImg = companyImg;
this.companyAlias = companyAlias;
}
public String getCompanyAlias() {
return companyAlias;
}
public void setCompanyAlias(String companyAlias) {
this.companyAlias = companyAlias;
}
public String getCompanyImg() {
return companyImg;
}
public void setCompanyImg(String companyImg) {
this.companyImg = companyImg;
} }
public String getUserName() { public String getUserName() {
......
...@@ -28,17 +28,17 @@ public class AliyunOSSClientUtil { ...@@ -28,17 +28,17 @@ public class AliyunOSSClientUtil {
private static String BACKET_NAME; private static String BACKET_NAME;
//阿里云API的文件夹名称 //阿里云API的文件夹名称
private static String FOLDER1; private static String FOLDER1;
private static String FOLDER2; private static String FOLDER2;
private static String FOLDER3; private static String FOLDER3;
private static String FOLDER4; private static String FOLDER4;
private static String FOLDER5;
private static CannedAccessControlList acl_pub_readwrite = CannedAccessControlList.PublicReadWrite; private static CannedAccessControlList acl_pub_readwrite = CannedAccessControlList.PublicReadWrite;
//初始化属性 //初始化属性
static { static {
...@@ -50,7 +50,7 @@ public class AliyunOSSClientUtil { ...@@ -50,7 +50,7 @@ public class AliyunOSSClientUtil {
FOLDER2 = OSSClientConstants.FOLDER2; FOLDER2 = OSSClientConstants.FOLDER2;
FOLDER3 = OSSClientConstants.FOLDER3; FOLDER3 = OSSClientConstants.FOLDER3;
FOLDER4 = OSSClientConstants.FOLDER4; FOLDER4 = OSSClientConstants.FOLDER4;
FOLDER5 = OSSClientConstants.FOLDER5;
} }
public static String getENDPOINT() { public static String getENDPOINT() {
...@@ -151,7 +151,6 @@ public class AliyunOSSClientUtil { ...@@ -151,7 +151,6 @@ public class AliyunOSSClientUtil {
logger.info("删除" + bucketName + "Bucket成功"); logger.info("删除" + bucketName + "Bucket成功");
} }
/** /**
* 上传图片 * 上传图片
* *
...@@ -170,7 +169,6 @@ public class AliyunOSSClientUtil { ...@@ -170,7 +169,6 @@ public class AliyunOSSClientUtil {
} }
} }
public static String uploadImg2Oss(OSSClient ossClient, MultipartFile file, String number,String imageType ) { public static String uploadImg2Oss(OSSClient ossClient, MultipartFile file, String number,String imageType ) {
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
...@@ -233,7 +231,6 @@ public class AliyunOSSClientUtil { ...@@ -233,7 +231,6 @@ public class AliyunOSSClientUtil {
return ret; return ret;
} }
public static String uploadFile2OSS(OSSClient ossClient,InputStream instream, String fileName,String imageType ) { public static String uploadFile2OSS(OSSClient ossClient,InputStream instream, String fileName,String imageType ) {
String ret = ""; String ret = "";
try { try {
...@@ -361,6 +358,8 @@ public class AliyunOSSClientUtil { ...@@ -361,6 +358,8 @@ public class AliyunOSSClientUtil {
putResult = ossClient.putObject(BACKET_NAME, FOLDER3+ fileName, is, metadata); putResult = ossClient.putObject(BACKET_NAME, FOLDER3+ fileName, is, metadata);
} else if(fileName.contains("CHN")){ } else if(fileName.contains("CHN")){
putResult = ossClient.putObject(BACKET_NAME, FOLDER4+ fileName, is, metadata); putResult = ossClient.putObject(BACKET_NAME, FOLDER4+ fileName, is, metadata);
} else if(fileName.contains("仓库温湿度观测记录表")){
putResult = ossClient.putObject(BACKET_NAME, FOLDER5+ fileName, is, metadata);
} else { } else {
putResult = ossClient.putObject(BACKET_NAME, FOLDER1+ fileName, is, metadata); putResult = ossClient.putObject(BACKET_NAME, FOLDER1+ fileName, is, metadata);
} }
......
...@@ -2,7 +2,7 @@ package com.example.tdl.util; ...@@ -2,7 +2,7 @@ package com.example.tdl.util;
import com.aliyun.oss.model.CannedAccessControlList; import com.aliyun.oss.model.CannedAccessControlList;
public class OSSClientConstants { public class OSSClientConstants {
//阿里云API的外网域名 //阿里云API的外网域名
public static final String ENDPOINT = "oss-cn-shanghai.aliyuncs.com"; public static final String ENDPOINT = "oss-cn-shanghai.aliyuncs.com";
...@@ -26,6 +26,8 @@ public class OSSClientConstants { ...@@ -26,6 +26,8 @@ public class OSSClientConstants {
public static final String FOLDER4="pic/wareHouseImage/";//仓库图片 public static final String FOLDER4="pic/wareHouseImage/";//仓库图片
public static final String FOLDER5="warehouse/";//仓库数据下载
//公共读写 //公共读写
private static final CannedAccessControlList acl_pub_readwrite = CannedAccessControlList.PublicReadWrite; private static final CannedAccessControlList acl_pub_readwrite = CannedAccessControlList.PublicReadWrite;
......
package com.example.tdl.web;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.OSSClient;
import com.example.tdl.common.WarehouseExcel;
import com.example.tdl.domain.dto.CommFeedback;
import com.example.tdl.domain.vo.*;
import com.example.tdl.service.*;
import com.example.tdl.service.redis.InfoRedisService;
import com.example.tdl.service.redis.TokenRedisService;
import com.example.tdl.util.AliyunOSSClientUtil;
import com.example.tdl.util.ZipCompressUtil;
import com.google.gson.Gson;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.influxdb.InfluxDBTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
@RestController
@RequestMapping("/download")
public class DownloadController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
Gson gson=new Gson();
CommFeedback fb=new CommFeedback();
@Autowired
private WarehouseService warehouseService;
@Autowired
private TokenRedisService tokenRedisService;
@Autowired
private InfluxDBTemplate influxDBTemplate;
@Autowired
private InfoRedisService infoRedisService;
@Autowired
private TDLDeviceService tdlDeviceService;
@Autowired
private I18nController i18n;
@Autowired
private TDLLogService tdlLogService;
private final static String database ="original";
@ApiOperation(value = "仓库数据下载",notes = "仓库数据下载")
@ApiImplicitParams({
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
})
@RequestMapping(value = "/download",method = RequestMethod.POST)
public String downLoad(HttpServletResponse response,HttpServletRequest request,@RequestBody String warehouseNo) {
String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
JSONObject jsonObject= JSON.parseObject(warehouseNo);
warehouseNo=(String)jsonObject.get("warehouseNo");
if (StringUtils.isEmpty(warehouseNo)){
fb.setCode(0);
fb.setMessage(i18n.getMessage(request,"warehouseNo"));
return gson.toJson(fb);
}
if(warehouseService.getWarehouseNo(warehouseNo) ==0){
fb.setCode(0);
fb.setMessage(i18n.getMessage(request,"Nonexistent"));
return gson.toJson(fb);
}
WarehouseDetailVo warehouseDetailVo=warehouseService.getWarehouseDetailByNo(warehouseNo);
//获取
List<WarehouseLogVo> list =tdlLogService.getByWarehouse(warehouseNo);
List<GatewayOnLineVo> gatewayOnLineVos=new ArrayList<>();
for (int a=0;a<list.size();a++){
if(list.get(a) == null){
continue;
}
if(list.get(a).getEndTime()!=null){
continue;
}
GatewayOnLineVo gatewayOnLineVo = new GatewayOnLineVo();
gatewayOnLineVo.setSN(list.get(a).getSN());
gatewayOnLineVo.setType(list.get(a).getType());
Object data = infoRedisService.getHash("DeviceOnline", list.get(a).getDevice() );
if(data !=null){
OnlineVo onlineVo = gson.fromJson(data.toString(),OnlineVo.class);
if(onlineVo.getOnline() == 1){
gatewayOnLineVo.setState(7);
}else {
gatewayOnLineVo.setState(6);
}
}else{
gatewayOnLineVo.setState(6);
}
String sql ="SELECT \"battery\" FROM \"tdl_policy\".\""+list.get(a).getDevice() +"\" ORDER BY time DESC LIMIT 1";
QueryResult queryResult = influxDBTemplate.query(new Query(sql, database));
if (queryResult.getResults().get(0).getSeries() != null) {
if(Double.valueOf(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString())>0){
gatewayOnLineVo.setBattery(queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1)==null ? "NA" :queryResult.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString());
}else{
gatewayOnLineVo.setBattery("NA");
}
}else {
gatewayOnLineVo.setBattery("NA");
}
List<String> tdls=tdlDeviceService.getByGatewaySN(list.get(a).getSN(),list.get(a).getType());
List<TDLDeviceDetailVo> tdlDeviceDetailVos=new ArrayList<>();
for (int b=0;b<tdls.size();b++){
TDLDeviceDetailVo tdlDeviceDetailVo=new TDLDeviceDetailVo();
tdlDeviceDetailVo.setGatewaySN(list.get(a).getSN());
String sqls ="SELECT \"b\", \"T\", \"h\" FROM \"tdl_policy\".\""+list.get(a).getDevice() +"\" WHERE (\"tdl\" = '"+tdls.get(b)+"') ORDER BY time DESC LIMIT 1";
QueryResult queryResults = influxDBTemplate.query(new Query(sqls, database));
if (queryResults.getResults().get(0).getSeries() != null) {
tdlDeviceDetailVo.setTime(parseTime(queryResults.getResults().get(0).getSeries().get(0).getValues().get(0).get(0).toString()));
tdlDeviceDetailVo.setPressure(queryResults.getResults().get(0).getSeries().get(0).getValues().get(0).get(1).toString());
tdlDeviceDetailVo.setTemperature(queryResults.getResults().get(0).getSeries().get(0).getValues().get(0).get(2).toString());
tdlDeviceDetailVo.setHumidity(queryResults.getResults().get(0).getSeries().get(0).getValues().get(0).get(3).toString());
}else{
tdlDeviceDetailVo.setTime("0");
tdlDeviceDetailVo.setPressure("0");
tdlDeviceDetailVo.setTemperature("0");
tdlDeviceDetailVo.setHumidity("0");
}
tdlDeviceDetailVo.setTDLSN(tdls.get(b).replace("TDL-","").trim());
tdlDeviceDetailVos.add(tdlDeviceDetailVo);
}
gatewayOnLineVo.setTdlDeviceDetailVos(tdlDeviceDetailVos);
gatewayOnLineVos.add(gatewayOnLineVo);
}
warehouseDetailVo.setGatewayOnLineVos(gatewayOnLineVos);
try {
String fileName = warehouseNo+"仓库温湿度观测记录表-" +System.currentTimeMillis();
WarehouseExcel warehouseExcel = new WarehouseExcel(fileName,warehouseDetailVo,user.getUserName(),response);
File file=new File("E:"+File.separator+fileName);
if(!file.exists()){
file.mkdir();
}
HSSFWorkbook wb = warehouseExcel.downloadExcel();
if(wb !=null){
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename="+fileName);
OutputStream os = new FileOutputStream(new File(file+".xls"));
wb.write(os);
os.flush();
os.close();
ZipCompressUtil zipCom = new ZipCompressUtil(file+".zip",file+".xls");
try{
zipCom.zip();
}catch(Exception e){
e.printStackTrace();
logger.info(e.toString());
}
try {
// OSSClient ossClient = AliyunOSSClientUtil.getOSSClient();
// AliyunOSSClientUtil.uploadObject2OSS(ossClient, new File(file +".zip"));
if (new File(file+".xls").delete()){
// new File(file+".zip").delete();
fb.setCode(1);
fb.setMessage("https://tdlcloud.oss-cn-shanghai.aliyuncs.com/warehouse/" +fileName+".zip");
return gson.toJson(fb);
}else{
fb.setCode(0);
fb.setMessage("下载失败");
}
} catch (Exception e) {
e.printStackTrace();
logger.info(e.toString());
fb.setCode(0);
fb.setMessage("上传失败");
}
}else{
fb.setCode(0);
fb.setMessage("上传失败");
}
}catch (Exception e){
e.printStackTrace();
logger.info(e.toString());
fb.setCode(0);
fb.setMessage("上传失败");
}
return gson.toJson(fb);
}
public String parseTime(String time){
String dateResult =null;
try {
dateResult = dateToStamp(time);
} catch (ParseException e) {
e.printStackTrace();
logger.info(e.toString());
fb.setCode(0);
fb.setMessage("解析时间异常");
}
return dateResult;
}
//将utc时间转换成时间戳
public static String dateToStamp(String s) throws ParseException {
Date date =null ;
if(s.length() !=20 ) {
date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").parse(s);
}else{
date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").parse(s);
}
return String.valueOf(date.getTime());
}
}
...@@ -225,18 +225,21 @@ public class TDLDeviceController { ...@@ -225,18 +225,21 @@ public class TDLDeviceController {
@ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"), @ApiImplicitParam(paramType="header", name = "Account_token", value = "token", required = true, dataType = "String"),
}) })
@RequestMapping(value = "/updateCompany",method = RequestMethod.POST) @RequestMapping(value = "/updateCompany",method = RequestMethod.POST)
public Object updateCompany(@RequestBody String TDLSN, HttpServletRequest request){ public Object updateCompany(@RequestBody UpdateTDLCompanyVo updateTDLCompanyVo, HttpServletRequest request){
String token = request.getHeader("Account_token"); String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" +token); String datum = tokenRedisService.get("TOKEN_" +token);
UserRedisVo user = gson.fromJson(datum,UserRedisVo.class); UserRedisVo user = gson.fromJson(datum,UserRedisVo.class);
JSONObject jsonObject=JSON.parseObject(TDLSN); if(StringUtils.isEmpty(updateTDLCompanyVo.getTDLSN())){
TDLSN=(String) jsonObject.get("TDLSN");
if(StringUtils.isEmpty(TDLSN)){
fb.setCode(0); fb.setCode(0);
fb.setMessage(i18n.getMessage(request,"TDLSN")); fb.setMessage(i18n.getMessage(request,"TDLSN"));
return gson.toJson(fb); return gson.toJson(fb);
} }
int a=tdlDeviceService.updateCompany(TDLSN,user.getCompanyNo()); if (StringUtils.isEmpty(updateTDLCompanyVo.getCompanyNo())){
fb.setCode(0);
fb.setMessage(i18n.getMessage(request,"companyNo"));
return gson.toJson(fb);
}
int a=tdlDeviceService.updateCompany(updateTDLCompanyVo.getTDLSN(),user.getCompanyNo());
if (a>=0){ if (a>=0){
fb.setCode(1); fb.setCode(1);
fb.setMessage(i18n.getMessage(request,"updateTDLCompanySuccess")); fb.setMessage(i18n.getMessage(request,"updateTDLCompanySuccess"));
......
...@@ -414,9 +414,11 @@ public class UserController { ...@@ -414,9 +414,11 @@ public class UserController {
String token = request.getHeader("Account_token"); String token = request.getHeader("Account_token");
String datum = tokenRedisService.get("TOKEN_" + token); String datum = tokenRedisService.get("TOKEN_" + token);
UserRedisVo userRedisVo = gson.fromJson(datum,UserRedisVo.class); UserRedisVo userRedisVo = gson.fromJson(datum,UserRedisVo.class);
//获取当前登录者的天气
String ip = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getRemoteAddr(); String ip = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getRemoteAddr();
return new UserNameVo(userRedisVo.getUserName(),System.currentTimeMillis() +"",ip); ResultCompanyVo resultCompanyVo=companyService.getByCompanyNo(userRedisVo.getCompanyNo());
String img=resultCompanyVo.getImg();
String companyAlias=resultCompanyVo.getAlias();
return new UserNameVo(userRedisVo.getUserName(),System.currentTimeMillis() +"",ip,img,companyAlias);
} }
} }
...@@ -67,6 +67,7 @@ public class WarehouseController { ...@@ -67,6 +67,7 @@ public class WarehouseController {
@Autowired @Autowired
private InfluxDBTemplate influxDBTemplate; private InfluxDBTemplate influxDBTemplate;
@Autowired
private TDLLogService tdlLogService; private TDLLogService tdlLogService;
private final static String database ="original"; private final static String database ="original";
......
spring.datasource.url=jdbc:mysql://192.168.1.53:3306/tdlcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false spring.datasource.url=jdbc:mysql://192.168.1.16:3306/tdlcloud?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root spring.datasource.username=root
spring.datasource.password=root spring.datasource.password=37774020
spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.driver-class-name=com.mysql.jdbc.Driver
threadpool.corepoolsize = 30 threadpool.corepoolsize = 30
threadpool.maxpoolsize = 50 threadpool.maxpoolsize = 50
server.port=8099 server.port=8092
management.security.enabled=false management.security.enabled=false
......
...@@ -44,8 +44,8 @@ ...@@ -44,8 +44,8 @@
<select id="getByWarehouse" parameterType="String" resultType="com.example.tdl.domain.vo.WarehouseLogVo"> <select id="getByWarehouse" parameterType="String" resultType="com.example.tdl.domain.vo.WarehouseLogVo">
select DISTINCT CONCAT( gatewaytype,"_",gatewaySN) device, tgl.gatewaySN SN,gatewaytype type, w.warehouseNo select DISTINCT CONCAT( gatewaytype,"_",gatewaySN) device, tgl.gatewaySN SN,gatewaytype type,w.warehouseNo
from tdl_gateway_log tgl,warehouse w from tdl_gateway_log tgl,warehouse w
where tgl.warehouseNo = w.warehouseNo where tgl.warehouseNo = w.warehouseNo
and w.warehouseNo=#{warehouseNo,jdbcType=VARCHAR} and w.warehouseNo=#{warehouseNo,jdbcType=VARCHAR}
and ISNULL(endTime) and ISNULL(endTime)
......
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