|
@@ -3,30 +3,40 @@ package com.iden.bms.service;
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.face.monitor.FaceMonitor;
|
|
|
import com.face.monitor.model.FaceModel;
|
|
|
import com.iden.bms.face.FaceIdenTool;
|
|
|
+import com.iden.common.entity.IdenCamera;
|
|
|
import com.iden.common.entity.IdenCameraVideo;
|
|
|
+import com.iden.common.entity.IdenCommunity;
|
|
|
import com.iden.common.entity.IdenFaceImage;
|
|
|
import com.iden.common.exception.BDException;
|
|
|
|
|
|
+import com.iden.common.service.IdenCameraService;
|
|
|
import com.iden.common.service.IdenCameraVideoService;
|
|
|
+import com.iden.common.service.IdenCommunityService;
|
|
|
import com.iden.common.util.DateUtils;
|
|
|
import com.iden.common.util.FileUtil;
|
|
|
import com.iden.common.util.ImgUtil;
|
|
|
-import com.iden.common.vo.CameraVideoVO;
|
|
|
-import com.iden.common.vo.FaceRetrieveResultVO;
|
|
|
-import com.iden.common.vo.TraceVO;
|
|
|
-import com.iden.common.vo.UserLoginedConvertVO;
|
|
|
+import com.iden.common.vo.*;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -44,8 +54,10 @@ public class TraceService {
|
|
|
private FaceImageService faceImageService;
|
|
|
@Resource
|
|
|
private IdenCameraVideoService idenCameraVideoService;
|
|
|
-
|
|
|
-
|
|
|
+ @Resource
|
|
|
+ private IdenCommunityService idenCommunityService;
|
|
|
+ @Resource
|
|
|
+ private IdenCameraService idenCameraService;
|
|
|
|
|
|
@Value("${iden.root:#{null}}")
|
|
|
private String idenRoot;
|
|
@@ -133,6 +145,21 @@ public class TraceService {
|
|
|
if(idenFaceImage != null){
|
|
|
TraceVO vo = new TraceVO();
|
|
|
BeanUtil.copyProperties(idenFaceImage,vo);
|
|
|
+ if(vo.getCameraId() != null){
|
|
|
+ IdenCamera idenCamera = this.idenCameraService.getById(vo.getCameraId());
|
|
|
+ if(idenCamera != null) {
|
|
|
+ vo.setDistrict(idenCamera.getDistrict());
|
|
|
+ vo.setSubdistrict(idenCamera.getSubdistrict());
|
|
|
+
|
|
|
+ Long communityId = idenCamera.getCommunityId();
|
|
|
+ if(communityId != null ){
|
|
|
+ IdenCommunity idenCommunity = this.idenCommunityService.getById(communityId);
|
|
|
+ if(idenCommunity != null) {
|
|
|
+ vo.setCommunityName(idenCommunity.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
result.add(vo);
|
|
|
}
|
|
|
}
|
|
@@ -187,4 +214,44 @@ public class TraceService {
|
|
|
return vos;
|
|
|
}
|
|
|
|
|
|
+ public void exportToExcel(List<TraceVO> records, UserLoginedConvertVO loginUser, HttpServletResponse response) throws Exception {
|
|
|
+
|
|
|
+ InputStream excelTemplateIs = null;
|
|
|
+ try {
|
|
|
+ response.reset(); // 非常重要
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ final String fileName = URLEncoder.encode("轨迹表", "UTF-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName + System.currentTimeMillis() + ".xlsx");
|
|
|
+
|
|
|
+ // 模板注意 用{} 来表示你要用的变量 如果本来就有"{","}" 特殊字符 用"\{","\}"代替
|
|
|
+ // {} 代表普通变量 {.} 代表是list的变量
|
|
|
+
|
|
|
+ excelTemplateIs = this.getClass().getResourceAsStream("/static/template/export/IdenTraceTemplate.xlsx");
|
|
|
+
|
|
|
+ ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).withTemplate(excelTemplateIs).build();
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet("轨迹表").build();
|
|
|
+ // 这里注意 入参用了forceNewRow 代表在写入list的时候不管list下面有没有空行 都会创建一行,然后下面的数据往后移动。默认 是false,会直接使用下一行,如果没有则创建。
|
|
|
+ // forceNewRow 如果设置了true,有个缺点 就是他会把所有的数据都放到内存了,所以慎用
|
|
|
+ // 简单的说 如果你的模板有list,且list不是最后一行,下面还有数据需要填充 就必须设置 forceNewRow=true 但是这个就会把所有数据放到内存 会很耗内存
|
|
|
+ // 如果数据量大 list不是最后一行 参照另一个
|
|
|
+ FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.FALSE).build();
|
|
|
+ excelWriter.fill(records, fillConfig, writeSheet);
|
|
|
+
|
|
|
+ excelWriter.finish();
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if(excelTemplateIs != null){
|
|
|
+ try {
|
|
|
+ excelTemplateIs.close();
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ ioe.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|