|
@@ -1,8 +1,10 @@
|
|
|
package com.metro.service.impl;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.metro.entity.WarningExcel;
|
|
|
import com.metro.entity.po.Company;
|
|
|
import com.metro.entity.po.JDevices;
|
|
|
import com.metro.entity.po.JDevicesMetro;
|
|
@@ -30,10 +32,9 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -68,6 +69,13 @@ public class PassreCordsServiceImpl extends BaseService implements PassreCordsSe
|
|
|
*/
|
|
|
@Override
|
|
|
public IPage<SelectPassreCordsPageListResp> page(SelectPassreCordsPageListReq req) {
|
|
|
+ JPersonVO userInfo = jPersonsService.getUserInfo();
|
|
|
+ if(userInfo.getType() == 3){
|
|
|
+ req.setBranchId(userInfo.getBranchId());
|
|
|
+ req.setCompanyId(userInfo.getCompanyId());
|
|
|
+ } else if (userInfo.getType() == 2) {
|
|
|
+ req.setCompanyId(userInfo.getCompanyId());
|
|
|
+ }
|
|
|
/*分页查询sql*/
|
|
|
IPage<SelectPassreCordsPageListResp> respPage = new Page<>(req.getPageNum(), req.getPageSize());
|
|
|
Page<PassreCords> selectPage = passreCordsMapper.selectPage(new Page<>(req.getPageNum(), req.getPageSize()), pageWrapper(req,1));
|
|
@@ -108,26 +116,42 @@ public class PassreCordsServiceImpl extends BaseService implements PassreCordsSe
|
|
|
|
|
|
@Override
|
|
|
public IPage<WarningVO> warningPageList(WarningSearch warningSearch) {
|
|
|
+ JPersonVO userInfo = jPersonsService.getUserInfo();
|
|
|
+ if(userInfo.getType() == 3){
|
|
|
+ warningSearch.setBranchId(userInfo.getBranchId());
|
|
|
+ warningSearch.setCompanyId(userInfo.getCompanyId());
|
|
|
+ } else if (userInfo.getType() == 2) {
|
|
|
+ warningSearch.setCompanyId(userInfo.getCompanyId());
|
|
|
+ }
|
|
|
Page<WarningVO> page = new Page<>(warningSearch.getPageNum(),warningSearch.getPageSize());
|
|
|
IPage<WarningVO> pageList =passreCordsMapper.warningPageList(page,warningSearch);
|
|
|
List<WarningVO> records = pageList.getRecords();
|
|
|
|
|
|
/*获取id列表 并根据idList获取数据列表*/
|
|
|
List<Integer> idList = records.stream().map(WarningVO::getId).collect(Collectors.toList());
|
|
|
+ if(idList.size() == 0)return page;
|
|
|
LambdaQueryWrapper<PassreCords> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
lambdaQueryWrapper.in(PassreCords::getId, idList);
|
|
|
lambdaQueryWrapper.orderByDesc(PassreCords::getId);
|
|
|
List<PassreCords> passreCords = passreCordsMapper.selectList(lambdaQueryWrapper);
|
|
|
Map<Integer, PassreCords> map = passreCords.stream().collect(Collectors.toMap(PassreCords::getId, Function.identity()));
|
|
|
-// /*获取数据中companyMap 和barnchMap*/
|
|
|
-// Map<String, Company> companyMap = companyService.getCompanyMapByList(passreCords,PassreCords::getCompanyId);
|
|
|
-// Map<String, Company> barnchMap = companyService.getBranchMapByList(passreCords,PassreCords::getBranchId);
|
|
|
- /*数据填入*/
|
|
|
+ List<Integer> list = new ArrayList<>();
|
|
|
+ Collections.addAll(list,0,1);//去掉了健康码异常的实时预警
|
|
|
for (WarningVO record : records) {
|
|
|
- BeanUtils.copyProperties(map.get(record.getId()),record);
|
|
|
-// record.setCompanyName(companyMap.get(record.getCompanyId()) == null?"" : companyMap.get(record.getCompanyId()).getCompanyName());
|
|
|
-// record.setBranchName(barnchMap.get(record.getCompanyId()+record.getBranchId()) == null ?
|
|
|
-// "" : barnchMap.get(record.getCompanyId()+record.getBranchId()).getBranchName()).getBranchName();
|
|
|
+ PassreCords passreCords1 = map.get(record.getId());
|
|
|
+ BeanUtils.copyProperties(passreCords1,record);
|
|
|
+ LambdaQueryWrapper<PassreCords> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if(StringUtils.isEmpty(passreCords1.getCardId()))continue;
|
|
|
+ wrapper.eq(StringUtils.isNotEmpty(warningSearch.getCompanyId()),PassreCords::getCompanyId,warningSearch.getCompanyId());
|
|
|
+ wrapper.eq(StringUtils.isNotEmpty(warningSearch.getBranchId()),PassreCords::getBranchId,warningSearch.getBranchId());
|
|
|
+ wrapper.eq(PassreCords::getCardId,passreCords1.getCardId());
|
|
|
+ wrapper.ne(PassreCords::getId,passreCords1.getId());
|
|
|
+ wrapper.in(PassreCords::getPass,list);
|
|
|
+ wrapper.orderByDesc(PassreCords::getId);
|
|
|
+ wrapper.last("limit 1");
|
|
|
+ PassreCords passreCord = passreCordsMapper.selectOne(wrapper);
|
|
|
+ if(passreCord != null)
|
|
|
+ record.setLastTime(passreCord.getPassTime()!=null?passreCord.getPassTime():null);
|
|
|
}
|
|
|
|
|
|
return pageList;
|
|
@@ -139,6 +163,7 @@ public class PassreCordsServiceImpl extends BaseService implements PassreCordsSe
|
|
|
|
|
|
Map<String,String> map = new HashMap<>();
|
|
|
List<String> collect = records.stream().map(p -> p.getMsgId().substring(0, 8)).collect(Collectors.toSet()).stream().collect(Collectors.toList());
|
|
|
+ if(collect.size() == 0)return new ArrayList<>();
|
|
|
List<Map<String, String>> maps = metroMapper.selectMetroNameByDeviceId(collect);
|
|
|
if(maps != null) {
|
|
|
for (Map<String, String> stringStringMap : maps) {
|
|
@@ -192,6 +217,74 @@ public class PassreCordsServiceImpl extends BaseService implements PassreCordsSe
|
|
|
return warningDetailOneVO;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void excelWarningPageList(WarningSearch warningSearch, HttpServletResponse response) {
|
|
|
+ warningSearch.setPageSize(50000);
|
|
|
+ warningSearch.setPageNum(0);
|
|
|
+ JPersonVO userInfo = jPersonsService.getUserInfo();
|
|
|
+ if(userInfo.getType() == 3){
|
|
|
+ warningSearch.setBranchId(userInfo.getBranchId());
|
|
|
+ warningSearch.setCompanyId(userInfo.getCompanyId());
|
|
|
+ } else if (userInfo.getType() == 2) {
|
|
|
+ warningSearch.setCompanyId(userInfo.getCompanyId());
|
|
|
+ }
|
|
|
+ Page<WarningVO> page = new Page<>(warningSearch.getPageNum(),warningSearch.getPageSize());
|
|
|
+ IPage<WarningVO> pageList =passreCordsMapper.warningPageList(page,warningSearch);
|
|
|
+ List<WarningVO> records = pageList.getRecords();
|
|
|
+
|
|
|
+ /*获取id列表 并根据idList获取数据列表*/
|
|
|
+ List<Integer> idList = records.stream().map(WarningVO::getId).collect(Collectors.toList());
|
|
|
+ List<WarningExcel> list = new ArrayList<>();
|
|
|
+ if(idList.size() != 0){
|
|
|
+ List<PassreCords> passreCords = passreCordsMapper.selectByIdList(idList);
|
|
|
+ Map<Integer, PassreCords> map = passreCords.stream().collect(Collectors.toMap(PassreCords::getId, Function.identity()));
|
|
|
+ List<Integer> passlist = new ArrayList<>();
|
|
|
+ Collections.addAll(passlist,0,1);//去掉了健康码异常的实时预警
|
|
|
+ for (WarningVO record : records) {
|
|
|
+ WarningExcel warningExcel = new WarningExcel();
|
|
|
+ PassreCords passreCords1 = map.get(record.getId());
|
|
|
+ BeanUtils.copyProperties(passreCords1,warningExcel);
|
|
|
+ LambdaQueryWrapper<PassreCords> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ if(StringUtils.isEmpty(passreCords1.getCardId()))continue;
|
|
|
+ wrapper.eq(StringUtils.isNotEmpty(warningSearch.getCompanyId()),PassreCords::getCompanyId,warningSearch.getCompanyId());
|
|
|
+ wrapper.eq(StringUtils.isNotEmpty(warningSearch.getBranchId()),PassreCords::getBranchId,warningSearch.getBranchId());
|
|
|
+ wrapper.eq(PassreCords::getCardId,passreCords1.getCardId());
|
|
|
+ wrapper.ne(PassreCords::getId,passreCords1.getId());
|
|
|
+ wrapper.in(PassreCords::getPass,passlist);
|
|
|
+ wrapper.orderByDesc(PassreCords::getId);
|
|
|
+ wrapper.last("limit 1");
|
|
|
+ PassreCords passreCord = passreCordsMapper.selectOne(wrapper);
|
|
|
+ if(passreCord != null){
|
|
|
+ warningExcel.setLastTime(passreCord.getPassTime()!=null?passreCord.getPassTime():null);
|
|
|
+ }
|
|
|
+ list.add(warningExcel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String fileName = "预警人员-" + System.currentTimeMillis() + ".xlsx";
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
|
|
|
+ response.addHeader("Access-Control-Expose-Headers", "Content-Disposition");
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=UTF-8");
|
|
|
+// response.setContentType("application/vnd.ms-excel");
|
|
|
+// response.setCharacterEncoding("utf-8");
|
|
|
+// // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
|
|
|
+// String fileName = "预警人员";
|
|
|
+// try {
|
|
|
+// fileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
|
|
|
+// } catch (UnsupportedEncodingException e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
|
|
+
|
|
|
+ EasyExcel.write(response.getOutputStream(), WarningExcel.class)
|
|
|
+ // 导出文件名
|
|
|
+ .autoCloseStream(Boolean.TRUE).sheet("预警人员")
|
|
|
+ .doWrite(list);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// page Wrapper
|
|
|
private LambdaQueryWrapper<PassreCords> pageWrapper(SelectPassreCordsPageListReq req , Integer type) {
|
|
@@ -225,12 +318,15 @@ public class PassreCordsServiceImpl extends BaseService implements PassreCordsSe
|
|
|
}
|
|
|
}
|
|
|
wrapper.like(StringUtils.isNotEmpty(req.getXm()), PassreCords::getXm, req.getXm());
|
|
|
+ wrapper.eq(StringUtils.isNotEmpty(req.getCompanyId()), PassreCords::getCompanyId, req.getCompanyId());
|
|
|
+ wrapper.eq(StringUtils.isNotEmpty(req.getBranchId()), PassreCords::getBranchId, req.getBranchId());
|
|
|
wrapper.eq(StringUtils.isNotEmpty(req.getCardId()), PassreCords::getCardId, req.getCardId());
|
|
|
wrapper.eq(StringUtils.isNotEmpty(req.getPhone()), PassreCords::getPhone, req.getPhone());
|
|
|
wrapper.eq(req.getPass() != null, PassreCords::getPass, req.getPass());
|
|
|
wrapper.gt(StringUtils.isNotEmpty(req.getStartTime()), PassreCords::getPassTime, req.getStartTime());
|
|
|
wrapper.lt(StringUtils.isNotEmpty(req.getEndTime()), PassreCords::getPassTime, req.getEndTime());
|
|
|
wrapper.orderByDesc(PassreCords::getPassTime);
|
|
|
+ if(type == 2)wrapper.last("limit 50");
|
|
|
return wrapper;
|
|
|
}
|
|
|
}
|