suntianwu 3 vuotta sitten
vanhempi
commit
afb26f981f

+ 31 - 1
src/main/java/com/iden/bms/controller/TraceController.java

@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.util.List;
 
 /**
@@ -104,5 +105,34 @@ public class TraceController {
         return  Result.success("查询成功!");
     }
 
-
+    /**
+     * 轨迹下载
+     * @param
+     * @return
+     */
+    @ApiOperation(value = "轨迹下载")
+    @ApiImplicitParams(value = {
+            @ApiImplicitParam(paramType = "query", name = "district", value = "所属区域"),
+            @ApiImplicitParam(paramType = "query", name = "subdistrict", value = "所属街道"),
+            @ApiImplicitParam(paramType = "query", name = "name", value = "小区名称")
+    })
+    @PostMapping({"/exportToExcel"})
+    @LogAnnotation(
+            type = OperateType.EXPORT,
+            moduleName = "轨迹下载",
+            description = "轨迹下载"
+    )
+    public void exportToExcel( @RequestHeader(name = "token", required = true) String token,
+                               HttpServletRequest request,
+                              HttpServletResponse response,
+                              @RequestBody List<TraceVO> traceVOS) {
+        try {
+            UserLoginedConvertVO loginUser = WebPageUtils.getCurrentLoginedUser(request);
+            this.traceService.exportToExcel(traceVOS,loginUser ,response);
+        } catch (BDException e) {
+            log.error("导出小区列表出现异常",e);
+        } catch (Exception e) {
+            log.error("小区管理: 导出小区列表出现异常",e);
+        }
+    }
 }

+ 73 - 6
src/main/java/com/iden/bms/service/TraceService.java

@@ -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();
+                }
+            }
+        }
+    }
+
+
 }

+ 19 - 1
src/main/java/com/iden/bms/service/WarningPersonService.java

@@ -43,8 +43,11 @@ public class WarningPersonService {
     @Resource
     private IdenCrowdService idenCrowdService;
     @Resource
+    private IdenCommunityService idenCommunityService;
+    @Resource
     private IdenWarningPersonTraceService idenWarningPersonTraceService;
-
+    @Resource
+    private IdenCameraService idenCameraService;
     /**
      * 根据小区查询预警人员列表分页
      * @return
@@ -145,6 +148,21 @@ public class WarningPersonService {
                 TraceVO vo = new TraceVO();
                 IdenWarningPersonTrace idenWarningPersonTrace = new IdenWarningPersonTrace();
                 BeanUtil.copyProperties(idenWarningPersonTrace,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());
+                            }
+                        }
+                    }
+                }
                 vos.add(vo);
             });
         }

+ 10 - 0
src/main/java/com/iden/common/vo/TraceVO.java

@@ -2,6 +2,7 @@ package com.iden.common.vo;
 
 
 import com.fasterxml.jackson.annotation.JsonFormat;
+import com.iden.common.exceltool.HeaderToColumn;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -35,6 +36,15 @@ public class TraceVO implements Serializable {
     @ApiModelProperty("小区ID")
     private Long communityId;
 
+    @ApiModelProperty("小区名")
+    private String communityName;
+
+    @ApiModelProperty("出现区域")
+    private String district;
+
+
+    @ApiModelProperty("出现街道")
+    private String subdistrict;
 
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
     @ApiModelProperty("抓拍时间")

BIN
src/main/resources/export/IdenTraceTemplate.xlsx