|
@@ -14,6 +14,7 @@ import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
import com.jpsoft.smart.modules.common.utils.PojoUtils;
|
|
|
+import com.jpsoft.smart.modules.common.utils.TimeZonesUtil;
|
|
|
import com.jpsoft.smart.modules.sys.entity.Role;
|
|
|
import com.jpsoft.smart.modules.sys.entity.User;
|
|
|
import com.jpsoft.smart.modules.sys.service.RoleService;
|
|
@@ -27,18 +28,32 @@ import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.joda.time.DateTime;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.ValueOperations;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping("/personDeviceLog")
|
|
@@ -63,6 +78,10 @@ public class PersonDeviceLogController {
|
|
|
@Autowired
|
|
|
private CompanyPositionService companyPositionService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ValueOperations<String,Object> valueOperations;
|
|
|
+
|
|
|
+ private final String exportPrefix = "exportDeviceLog_";
|
|
|
|
|
|
@ApiOperation(value = "列表")
|
|
|
@RequestMapping(value = "pageList", method = RequestMethod.POST)
|
|
@@ -144,7 +163,7 @@ public class PersonDeviceLogController {
|
|
|
}
|
|
|
|
|
|
if (StringUtil.isNotEmpty(matchMsg)) {
|
|
|
- searchParams.put("matchMsg", "%" + matchMsg + "%");
|
|
|
+ searchParams.put("matchMsg", matchMsg);
|
|
|
}
|
|
|
|
|
|
if (StringUtil.isNotEmpty(timeRanges)) {
|
|
@@ -192,10 +211,28 @@ public class PersonDeviceLogController {
|
|
|
return msgResult;
|
|
|
}
|
|
|
|
|
|
+ @GetMapping("exportProgress")
|
|
|
+ public MessageResult<String> exportProgress(String timestamp){
|
|
|
+ MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
+ String exportProgress = (String)valueOperations.get(exportPrefix + timestamp);
|
|
|
+
|
|
|
+ if(StringUtils.isNotEmpty(exportProgress)){
|
|
|
+ msgResult.setMessage(exportProgress);
|
|
|
+ msgResult.setResult(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ return msgResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setExportProgress(String timestamp,String msg){
|
|
|
+ valueOperations.set(exportPrefix + timestamp , msg,5, TimeUnit.MINUTES);
|
|
|
+ }
|
|
|
|
|
|
@ApiOperation(value = "导出日志台账")
|
|
|
@PostMapping("exportXls")
|
|
|
@ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "timestamp", value = "时间戳", paramType = "query"),
|
|
|
@ApiImplicitParam(name = "companyId", value = "所属单位编号", paramType = "query"),
|
|
|
@ApiImplicitParam(name = "subordinate", value = "是否查询下级单位", required = false, paramType = "query", dataType = "String"),
|
|
|
@ApiImplicitParam(name = "deviceNo", value = "设备编号", paramType = "query"),
|
|
@@ -207,6 +244,7 @@ public class PersonDeviceLogController {
|
|
|
@ApiImplicitParam(name = "distinct", value = "是否去重", paramType = "query")
|
|
|
})
|
|
|
public MessageResult<String> exportXls(
|
|
|
+ String timestamp,
|
|
|
String companyId,
|
|
|
@RequestParam(value = "subordinate", defaultValue = "false") Boolean subordinate,
|
|
|
String deviceNo, String aliasName, String personName,
|
|
@@ -214,31 +252,33 @@ public class PersonDeviceLogController {
|
|
|
@RequestParam(value = "distinct", defaultValue = "false") Boolean distinct,
|
|
|
@RequestAttribute String subject) {
|
|
|
MessageResult<String> msgResult = new MessageResult<>();
|
|
|
+
|
|
|
try {
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+
|
|
|
User user = userService.get(subject);
|
|
|
String userCompanyId = user.getCompanyId();
|
|
|
|
|
|
- HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
- HSSFSheet sheet = workbook.createSheet();
|
|
|
+ Workbook workbook = new HSSFWorkbook();
|
|
|
+ Sheet sheet = workbook.createSheet();
|
|
|
|
|
|
//表头
|
|
|
- HSSFRow rowTitle = sheet.createRow(0);
|
|
|
- HSSFCell cellTitle1 = rowTitle.createCell(0);
|
|
|
+ Row rowTitle = sheet.createRow(0);
|
|
|
+ Cell cellTitle1 = rowTitle.createCell(0);
|
|
|
cellTitle1.setCellValue("序号");
|
|
|
- HSSFCell cellTitle2 = rowTitle.createCell(1);
|
|
|
+ Cell cellTitle2 = rowTitle.createCell(1);
|
|
|
cellTitle2.setCellValue("检测时间");
|
|
|
- HSSFCell cellTitle3 = rowTitle.createCell(2);
|
|
|
+ Cell cellTitle3 = rowTitle.createCell(2);
|
|
|
cellTitle3.setCellValue("人员姓名");
|
|
|
- HSSFCell cellTitle4 = rowTitle.createCell(3);
|
|
|
+ Cell cellTitle4 = rowTitle.createCell(3);
|
|
|
cellTitle4.setCellValue("测温度数");
|
|
|
- HSSFCell cellTitle5 = rowTitle.createCell(4);
|
|
|
+ Cell cellTitle5 = rowTitle.createCell(4);
|
|
|
cellTitle5.setCellValue("设备编号");
|
|
|
- HSSFCell cellTitle6 = rowTitle.createCell(5);
|
|
|
+ Cell cellTitle6 = rowTitle.createCell(5);
|
|
|
cellTitle6.setCellValue("设备别称");
|
|
|
- HSSFCell cellTitle7 = rowTitle.createCell(6);
|
|
|
+ Cell cellTitle7 = rowTitle.createCell(6);
|
|
|
cellTitle7.setCellValue("拍照图片");
|
|
|
|
|
|
-
|
|
|
//获取公司
|
|
|
//五级位置
|
|
|
//CompanyInfo companyInfo = companyInfoService.get(companyId);
|
|
@@ -246,15 +286,15 @@ public class PersonDeviceLogController {
|
|
|
CompanyPosition companyPosition = null;
|
|
|
if (companyPositionList.size() > 0) {
|
|
|
companyPosition = companyPositionList.get(0);
|
|
|
- HSSFCell cellTitle8 = rowTitle.createCell(7);
|
|
|
+ Cell cellTitle8 = rowTitle.createCell(7);
|
|
|
cellTitle8.setCellValue(companyPosition.getPosition1Name());
|
|
|
- HSSFCell cellTitle9 = rowTitle.createCell(8);
|
|
|
+ Cell cellTitle9 = rowTitle.createCell(8);
|
|
|
cellTitle9.setCellValue(companyPosition.getPosition2Name());
|
|
|
- HSSFCell cellTitle10 = rowTitle.createCell(9);
|
|
|
+ Cell cellTitle10 = rowTitle.createCell(9);
|
|
|
cellTitle10.setCellValue(companyPosition.getPosition3Name());
|
|
|
- HSSFCell cellTitle11 = rowTitle.createCell(10);
|
|
|
+ Cell cellTitle11 = rowTitle.createCell(10);
|
|
|
cellTitle11.setCellValue(companyPosition.getPosition4Name());
|
|
|
- HSSFCell cellTitle12 = rowTitle.createCell(11);
|
|
|
+ Cell cellTitle12 = rowTitle.createCell(11);
|
|
|
cellTitle12.setCellValue(companyPosition.getPosition5Name());
|
|
|
}
|
|
|
|
|
@@ -262,7 +302,7 @@ public class PersonDeviceLogController {
|
|
|
Map<String, Object> searchParams = new HashMap<>();
|
|
|
|
|
|
List<Sort> sortList = new ArrayList<>();
|
|
|
- sortList.add(new Sort("a.record_time", "desc"));
|
|
|
+ sortList.add(new Sort("a.record_time", "asc"));
|
|
|
|
|
|
//为公司管理员
|
|
|
boolean isSysAdmin = userService.hasRole(subject, "SYSADMIN");
|
|
@@ -307,6 +347,10 @@ public class PersonDeviceLogController {
|
|
|
searchParams.put("distinct", distinct);
|
|
|
}
|
|
|
|
|
|
+ if (StringUtil.isNotEmpty(matchMsg)) {
|
|
|
+ searchParams.put("matchMsg", matchMsg);
|
|
|
+ }
|
|
|
+
|
|
|
if (StringUtil.isNotEmpty(timeRanges)) {
|
|
|
String[] timeRangeArray = timeRanges.split(",");
|
|
|
String beginTime = "";
|
|
@@ -338,103 +382,141 @@ public class PersonDeviceLogController {
|
|
|
searchParams.put("maxTemperature", maxTemperature);
|
|
|
}
|
|
|
|
|
|
- //Page<PersonDeviceLog> page = personDeviceLogService.pageSearch(searchParams, 1, 10000, false, sortList);
|
|
|
- List<PersonDeviceLog> page = personDeviceLogService.pageList(searchParams,sortList);
|
|
|
+ int pageNum = 1;
|
|
|
+ boolean needCount = true;
|
|
|
+ int totalPages = 1;
|
|
|
+ int pageSize = 500;
|
|
|
+ long total = 0;
|
|
|
+ long exportNum = 0;
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
- for (int i = 0; i < page.size(); i++) {
|
|
|
+ while(pageNum<=totalPages){
|
|
|
+ Page<PersonDeviceLog> page = personDeviceLogService.pageSearch(searchParams, pageNum, pageSize, needCount, sortList);
|
|
|
|
|
|
- PersonDeviceLog personDeviceLog = page.get(i);
|
|
|
+ if(needCount){
|
|
|
+ totalPages = page.getPages();
|
|
|
+ total = page.getTotal();
|
|
|
+ setExportProgress(timestamp , "导出进度:0/" + page.getTotal() + "...");
|
|
|
+ }
|
|
|
|
|
|
- HSSFRow rowContent = sheet.createRow(i + 1);
|
|
|
+ for (int i = 0; i < page.size(); i++) {
|
|
|
+ PersonDeviceLog personDeviceLog = page.get(i);
|
|
|
|
|
|
- HSSFCell cellContent1 = rowContent.createCell(0);
|
|
|
- cellContent1.setCellValue(i + 1);
|
|
|
+ Row rowContent = sheet.createRow( (pageNum-1)*pageSize + i + 1);
|
|
|
|
|
|
- String recordTime = "";
|
|
|
- if (personDeviceLog.getRecordTime() != null) {
|
|
|
- recordTime = sdf.format(personDeviceLog.getRecordTime());
|
|
|
- }
|
|
|
+ Cell cellContent1 = rowContent.createCell(0);
|
|
|
+ cellContent1.setCellValue(i + 1);
|
|
|
|
|
|
- HSSFCell cellContent2 = rowContent.createCell(1);
|
|
|
- cellContent2.setCellValue(recordTime);
|
|
|
+ String recordTime = "";
|
|
|
+ if (personDeviceLog.getRecordTime() != null) {
|
|
|
+ recordTime = sdf.format(personDeviceLog.getRecordTime());
|
|
|
+ }
|
|
|
|
|
|
- String name = "";
|
|
|
- if (personDeviceLog.getPerson() != null) {
|
|
|
- name = personDeviceLog.getPerson().getName();
|
|
|
- } else {
|
|
|
- name = "匿名用户";
|
|
|
- }
|
|
|
- HSSFCell cellContent3 = rowContent.createCell(2);
|
|
|
- cellContent3.setCellValue(name);
|
|
|
- HSSFCell cellContent4 = rowContent.createCell(3);
|
|
|
- cellContent4.setCellValue(personDeviceLog.getTemperature().toString());
|
|
|
- HSSFCell cellContent5 = rowContent.createCell(4);
|
|
|
- cellContent5.setCellValue(personDeviceLog.getDeviceNo());
|
|
|
- HSSFCell cellContent6 = rowContent.createCell(5);
|
|
|
- if(personDeviceLog.getDevice() != null) {
|
|
|
- cellContent6.setCellValue(personDeviceLog.getDevice().getAliasName());
|
|
|
- }
|
|
|
- HSSFCell cellContent7 = rowContent.createCell(6);
|
|
|
- cellContent7.setCellValue(personDeviceLog.getFaceImage());
|
|
|
-
|
|
|
- //五级位置
|
|
|
- //判断 如果公司没有五级位置 就不做展示
|
|
|
- if (companyPositionList.size() > 0) {
|
|
|
- PersonInfo person = personDeviceLog.getPerson();
|
|
|
- if (person != null) {
|
|
|
- HSSFCell cellContent8 = rowContent.createCell(7);
|
|
|
- if (person.getPosition1() != null) {
|
|
|
- cellContent8.setCellValue(person.getPosition1());
|
|
|
- }
|
|
|
- HSSFCell cellContent9 = rowContent.createCell(8);
|
|
|
- if (person.getPosition1() != null) {
|
|
|
- cellContent9.setCellValue(person.getPosition2());
|
|
|
- }
|
|
|
- HSSFCell cellContent10 = rowContent.createCell(9);
|
|
|
- if (person.getPosition1() != null) {
|
|
|
- cellContent10.setCellValue(person.getPosition3());
|
|
|
- }
|
|
|
- HSSFCell cellContent11 = rowContent.createCell(10);
|
|
|
- if (person.getPosition1() != null) {
|
|
|
- cellContent11.setCellValue(person.getPosition4());
|
|
|
- }
|
|
|
- HSSFCell cellContent12 = rowContent.createCell(11);
|
|
|
- if (person.getPosition1() != null) {
|
|
|
- cellContent12.setCellValue(person.getPosition5());
|
|
|
+ Cell cellContent2 = rowContent.createCell(1);
|
|
|
+ cellContent2.setCellValue(recordTime);
|
|
|
+
|
|
|
+ String name = "";
|
|
|
+ if (personDeviceLog.getPerson() != null) {
|
|
|
+ name = personDeviceLog.getPerson().getName();
|
|
|
+ } else {
|
|
|
+ name = "匿名用户";
|
|
|
+ }
|
|
|
+ Cell cellContent3 = rowContent.createCell(2);
|
|
|
+ cellContent3.setCellValue(name);
|
|
|
+ Cell cellContent4 = rowContent.createCell(3);
|
|
|
+ cellContent4.setCellValue(personDeviceLog.getTemperature().toString());
|
|
|
+ Cell cellContent5 = rowContent.createCell(4);
|
|
|
+ cellContent5.setCellValue(personDeviceLog.getDeviceNo());
|
|
|
+ Cell cellContent6 = rowContent.createCell(5);
|
|
|
+ if(personDeviceLog.getDevice() != null) {
|
|
|
+ cellContent6.setCellValue(personDeviceLog.getDevice().getAliasName());
|
|
|
+ }
|
|
|
+ Cell cellContent7 = rowContent.createCell(6);
|
|
|
+ cellContent7.setCellValue(personDeviceLog.getFaceImage());
|
|
|
+
|
|
|
+ //五级位置
|
|
|
+ //判断 如果公司没有五级位置 就不做展示
|
|
|
+ if (companyPositionList.size() > 0) {
|
|
|
+ PersonInfo person = personDeviceLog.getPerson();
|
|
|
+ if (person != null) {
|
|
|
+ Cell cellContent8 = rowContent.createCell(7);
|
|
|
+ if (person.getPosition1() != null) {
|
|
|
+ cellContent8.setCellValue(person.getPosition1());
|
|
|
+ }
|
|
|
+ Cell cellContent9 = rowContent.createCell(8);
|
|
|
+ if (person.getPosition1() != null) {
|
|
|
+ cellContent9.setCellValue(person.getPosition2());
|
|
|
+ }
|
|
|
+ Cell cellContent10 = rowContent.createCell(9);
|
|
|
+ if (person.getPosition1() != null) {
|
|
|
+ cellContent10.setCellValue(person.getPosition3());
|
|
|
+ }
|
|
|
+ Cell cellContent11 = rowContent.createCell(10);
|
|
|
+ if (person.getPosition1() != null) {
|
|
|
+ cellContent11.setCellValue(person.getPosition4());
|
|
|
+ }
|
|
|
+ Cell cellContent12 = rowContent.createCell(11);
|
|
|
+ if (person.getPosition1() != null) {
|
|
|
+ cellContent12.setCellValue(person.getPosition5());
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
}
|
|
|
|
|
|
+ pageNum++;
|
|
|
+ needCount = false; //第二页就不用查总数
|
|
|
+ exportNum += page.size();
|
|
|
|
|
|
- sheet.autoSizeColumn(i);
|
|
|
+ setExportProgress(timestamp ,String.format("导出进度:%s/%s...", exportNum, total));
|
|
|
}
|
|
|
|
|
|
//todo 将wb保存到oss
|
|
|
ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
workbook.write(output);
|
|
|
-
|
|
|
byte[] buffer = output.toByteArray();
|
|
|
- ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+ output.close();
|
|
|
+
|
|
|
+ logger.warn("原文件大小:" + buffer.length);
|
|
|
+
|
|
|
+ String fileName = DateTime.now().toString("yyyyMMddHHmmss") + ".xls";
|
|
|
|
|
|
- String downloadUrl = OSSUtil.upload(ossConfig, "import", "error.xls", input);
|
|
|
+ InputStream input = new ByteArrayInputStream(buffer);
|
|
|
+
|
|
|
+ //todo 如果超过2M则压缩
|
|
|
+ if(buffer.length>2*1024*1024){
|
|
|
+ setExportProgress(timestamp ,"导出数据完毕,正在压缩...");
|
|
|
+
|
|
|
+ ByteArrayOutputStream zipOut = new ByteArrayOutputStream();
|
|
|
+
|
|
|
+ ZipOutputStream zos = new ZipOutputStream(zipOut);
|
|
|
+ ZipEntry zipEntry = new ZipEntry(fileName);
|
|
|
+ zos.putNextEntry(zipEntry);
|
|
|
+ zos.write(buffer, 0, buffer.length);
|
|
|
+ zos.close();
|
|
|
+
|
|
|
+ byte[] zipBuffer = zipOut.toByteArray();
|
|
|
+ logger.warn("压缩后文件大小:" + zipBuffer.length);
|
|
|
+
|
|
|
+ input = new ByteArrayInputStream(zipBuffer);
|
|
|
+ }
|
|
|
+
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+
|
|
|
+ setExportProgress(timestamp ,"导出数据完毕,正在保存...");
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig, "export", fileName, input);
|
|
|
|
|
|
- //todo 返回导入失败报表下载链接
|
|
|
msgResult.setData(downloadUrl);
|
|
|
- msgResult.setResult(true);
|
|
|
|
|
|
- //将exal输出到哪个文件夹中
|
|
|
-// ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
|
-// workbook.write(out);
|
|
|
-// workbook.close();
|
|
|
-//
|
|
|
-// String fileName = new String("导出数据".getBytes("UTF-8"), "iso-8859-1");
|
|
|
-// response.setContentType("application/x-msdownload");
|
|
|
-// response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".xls");
|
|
|
-// response.getOutputStream().write(out.toByteArray());
|
|
|
-// response.getOutputStream().flush();
|
|
|
+ long elapse = end - start;
|
|
|
|
|
|
+ msgResult.setMessage(String.format(
|
|
|
+ "导出完毕,请点击下载链接保存!耗时: %s",
|
|
|
+ TimeZonesUtil.friendlyTimeFormat(elapse)));
|
|
|
+
|
|
|
+ msgResult.setResult(true);
|
|
|
} catch (Exception ex) {
|
|
|
logger.error(ex.getMessage(), ex);
|
|
|
|