|
@@ -1,7 +1,11 @@
|
|
|
package com.yx.face.service.impl;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
+import com.yx.face.boot.core.Constants;
|
|
|
import com.yx.face.boot.restful.RestDTO;
|
|
|
import com.yx.face.boot.restful.RestResponse;
|
|
|
import com.yx.face.boot.restful.RestResult;
|
|
@@ -11,6 +15,7 @@ import com.yx.face.dao.UserControlEarlyWarningListDao;
|
|
|
import com.yx.face.dao.UserControlEarlyWarningListLogDao;
|
|
|
import com.yx.face.model.dto.UserControlEarlyWarningDTO;
|
|
|
import com.yx.face.model.dto.UserWhitelistDTO;
|
|
|
+import com.yx.face.model.entity.Admin;
|
|
|
import com.yx.face.model.entity.UserControlEarlyWarningList;
|
|
|
import com.yx.face.model.entity.UserControlEarlyWarningListLog;
|
|
|
import com.yx.face.model.excel.UserControlEarlyWarningExcel;
|
|
@@ -26,10 +31,14 @@ import com.yx.face.service.UserControlEarlyWarningListService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -50,6 +59,8 @@ public class UserControlEarlyWarningListServiceImpl implements UserControlEarlyW
|
|
|
|
|
|
@Autowired
|
|
|
private AdminService adminService;
|
|
|
+ @Value("${web.address}")
|
|
|
+ private String address;
|
|
|
|
|
|
@Override
|
|
|
public Integer addOrUpdate(UserControlEarlyWarningDTO userControlEarlyWarningDTO) {
|
|
@@ -80,10 +91,11 @@ public class UserControlEarlyWarningListServiceImpl implements UserControlEarlyW
|
|
|
|
|
|
@Override
|
|
|
public RestResult<List<String>> userControlEarlyWarningListExcel(List<Object> datas, Integer adminId) {
|
|
|
- List<String> list = new ArrayList<>();
|
|
|
+ List<String> list = new ArrayList<>(datas.size());
|
|
|
+ List<UserControlEarlyWarningExcel> errList = new ArrayList<>(datas.size());
|
|
|
for (int i = 0; i < datas.size(); i++) {
|
|
|
+ UserControlEarlyWarningExcel ucewe = (UserControlEarlyWarningExcel) datas.get(i);
|
|
|
try {
|
|
|
- UserControlEarlyWarningExcel ucewe = (UserControlEarlyWarningExcel) datas.get(i);
|
|
|
if (ucewe.getEarlyWarningIdNumber() == null)
|
|
|
throw new ServiceException("第" + (i + 2) + "行,预警人员身份证号不能为空");
|
|
|
|
|
@@ -97,9 +109,36 @@ public class UserControlEarlyWarningListServiceImpl implements UserControlEarlyW
|
|
|
}
|
|
|
} catch (ServiceException e) {
|
|
|
list.add(e.getMessage());
|
|
|
+ ucewe.setMessage(e.getMessage());
|
|
|
+ errList.add(ucewe);
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
+ if (errList.size() > 0) {
|
|
|
+ String uploadExcel = Constants.UPLOAD_EXCEL;
|
|
|
+ String fileName = uploadExcel + "/错误记录-" + System.currentTimeMillis() + ".xlsx";
|
|
|
+
|
|
|
+ // 这里 需要指定写用哪个class去写
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
+ try {
|
|
|
+ Path directory = Paths.get(uploadExcel);
|
|
|
+ if (!Files.exists(directory)) {
|
|
|
+ Files.createDirectories(directory);
|
|
|
+ }
|
|
|
+ excelWriter = EasyExcel.write(fileName, UserControlEarlyWarningExcel.class).build();
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet("错误记录").build();
|
|
|
+ excelWriter.write(errList, writeSheet);
|
|
|
+ } catch (Exception ed) {
|
|
|
+ ed.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ // 千万别忘记finish 会帮忙关闭流
|
|
|
+ if (excelWriter != null) {
|
|
|
+ excelWriter.finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String filePath = address.concat(fileName);
|
|
|
+ list.add(filePath);
|
|
|
+ }
|
|
|
datas.clear();//结束后销毁不用的资源
|
|
|
return RestResponse.ok(list);
|
|
|
}
|
|
@@ -124,15 +163,16 @@ public class UserControlEarlyWarningListServiceImpl implements UserControlEarlyW
|
|
|
/**
|
|
|
* 插入匹配人员预警信息
|
|
|
*
|
|
|
- * @param deviceSn 设备编号
|
|
|
+ * @param admin 账号信息
|
|
|
* @param idNumber 身份证
|
|
|
* @param faceLogId 进出记录id
|
|
|
*/
|
|
|
@Async
|
|
|
@Override
|
|
|
- public void addWarningInformation(String deviceSn, String idNumber, Long faceLogId) {
|
|
|
+ public void addWarningInformation(Admin admin, String idNumber, Long faceLogId) {
|
|
|
// null 代表未查到
|
|
|
- AdminAndUserEarlyWarningVO adminAndUserEarlyWarningVO = userControlEarlyWarningListDao.getAdminWarningInformation(deviceSn, idNumber, 1);
|
|
|
+ //查询上级账号信息 且开启布控的账号
|
|
|
+ AdminAndUserEarlyWarningVO adminAndUserEarlyWarningVO = userControlEarlyWarningListDao.getAdminWarningInformation(admin, idNumber, 1);
|
|
|
if (adminAndUserEarlyWarningVO != null) {
|
|
|
System.out.println(adminAndUserEarlyWarningVO);
|
|
|
UserControlEarlyWarningListLog userControlEarlyWarningListLog = new UserControlEarlyWarningListLog();
|
|
@@ -142,7 +182,7 @@ public class UserControlEarlyWarningListServiceImpl implements UserControlEarlyW
|
|
|
userControlEarlyWarningListLog.setControlUnit(adminAndUserEarlyWarningVO.getControlUnit());
|
|
|
userControlEarlyWarningListLog.setControlPhone(adminAndUserEarlyWarningVO.getControlPhone());
|
|
|
userControlEarlyWarningListLog.setControlName(adminAndUserEarlyWarningVO.getControlName());
|
|
|
- userControlEarlyWarningListLog.setAdminId(adminAndUserEarlyWarningVO.getAdminId());
|
|
|
+ userControlEarlyWarningListLog.setAdminId(admin.getId());
|
|
|
userControlEarlyWarningListLog.setStatus(1);
|
|
|
userControlEarlyWarningListLog.setFaceLogId(faceLogId);
|
|
|
System.out.println(userControlEarlyWarningListLog);
|