|
@@ -4,7 +4,9 @@ import com.github.pagehelper.Page;
|
|
|
import com.github.pagehelper.util.StringUtil;
|
|
|
import com.jpsoft.smart.config.OSSConfig;
|
|
|
import com.jpsoft.smart.modules.base.entity.DeviceInfo;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
import com.jpsoft.smart.modules.base.service.DeviceInfoService;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
|
import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
import com.jpsoft.smart.modules.common.utils.PojoUtils;
|
|
|
import com.jpsoft.smart.modules.common.dto.Sort;
|
|
@@ -63,6 +65,10 @@ public class PersonDeviceRelationController {
|
|
|
@Autowired
|
|
|
private OSSConfig ossConfig;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@ApiOperation(value="添加设备和人员绑定")
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -151,33 +157,59 @@ public class PersonDeviceRelationController {
|
|
|
if (affectCount > 0) {
|
|
|
//往设备库传输人脸信息
|
|
|
//批量操作
|
|
|
- List<LapiMsgResult> lapiResults = lapiService.addPerson(personId);
|
|
|
-// for (int i = 0; i < lapiResults.size(); i++) {
|
|
|
-// LapiMsgResult lapiMsgResult = lapiResults.get(i);
|
|
|
-// if (lapiMsgResult.isSuccess()) {
|
|
|
-// msgResult.setResult(true);
|
|
|
-// }else{
|
|
|
-// HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
|
-// HSSFCell cell1 = row.createCell(0);
|
|
|
-// cell1.setCellValue(personId);
|
|
|
-// HSSFCell cell2 = row.createCell(1);
|
|
|
-// cell2.setCellValue(lapiMsgResult.getAliasName());
|
|
|
-// HSSFCell cell3 = row.createCell(2);
|
|
|
-// cell3.setCellValue("添加失败:" + lapiMsgResult.getMsg());
|
|
|
-// HSSFCell cell4 = row.createCell(3);
|
|
|
-// cell4.setCellValue(lapiMsgResult.getMsg());
|
|
|
-// }
|
|
|
-// }
|
|
|
-//
|
|
|
-// ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
-// workbook.write(output);
|
|
|
-// byte[] buffer = output.toByteArray();
|
|
|
-// ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
-// String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
|
|
|
+ int addCount = 0;
|
|
|
+ List<LapiResult> lapiResults = lapiService.addPerson(personId);
|
|
|
+ for (int i = 0; i < lapiResults.size(); i++) {
|
|
|
+ LapiResult lapiResult = lapiResults.get(i);
|
|
|
+ if (lapiResult.isSuccess()) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ }else{
|
|
|
+
|
|
|
+ PersonInfo personInfo = personInfoService.get(personId);
|
|
|
+ String personName = "";
|
|
|
+ if(personInfo != null){
|
|
|
+ personName = personInfo.getName();
|
|
|
+ }
|
|
|
+ Map resultMap = (Map)lapiResult.getData();
|
|
|
+ HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
|
+ HSSFCell cell1 = row.createCell(0);
|
|
|
+ cell1.setCellValue(personName);
|
|
|
+ HSSFCell cell2 = row.createCell(1);
|
|
|
+ cell2.setCellValue(resultMap.get("deviceAliasName").toString());
|
|
|
+ HSSFCell cell3 = row.createCell(2);
|
|
|
+ cell3.setCellValue("添加失败:");
|
|
|
+ HSSFCell cell4 = row.createCell(3);
|
|
|
+ cell4.setCellValue(lapiResult.getMsg());
|
|
|
+
|
|
|
+ //删除绑定关系
|
|
|
+ PersonDeviceRelation personDeviceRelation = personDeviceRelationService.findByDeviceIdAndPersonId(resultMap.get("deviceId").toString(),personId);
|
|
|
+ personDeviceRelation.setDelFlag(true);
|
|
|
+ personDeviceRelation.setUpdateBy(subject);
|
|
|
+ personDeviceRelation.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ personDeviceRelationService.update(personDeviceRelation);
|
|
|
+ addCount ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
//
|
|
|
-// msgResult.setMessage(downloadUrl);
|
|
|
- msgResult.setResult(true);
|
|
|
- msgResult.setData(affectCount);
|
|
|
+
|
|
|
+
|
|
|
+ if(addCount > 0){
|
|
|
+ //异常数量大于0,表示有部分数据同步失败
|
|
|
+ msgResult.setResult(false);
|
|
|
+ //保存失败信息
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ workbook.write(output);
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
|
|
|
+ msgResult.setMessage(downloadUrl);
|
|
|
+ }else {
|
|
|
+ //异常数量为0,表示全部同步成功
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage("人员与0个设备绑定成功!");
|
|
@@ -206,6 +238,12 @@ public class PersonDeviceRelationController {
|
|
|
int affectCount = 0;
|
|
|
|
|
|
try {
|
|
|
+ HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
+ HSSFSheet sheet =workbook.createSheet();
|
|
|
+
|
|
|
+ //同步异常数量
|
|
|
+ int addCount = 0;
|
|
|
+
|
|
|
if(StringUtil.isNotEmpty(persons)){
|
|
|
|
|
|
String[] personArray = persons.split(",");
|
|
@@ -229,13 +267,51 @@ public class PersonDeviceRelationController {
|
|
|
//往设备库传输人脸信息
|
|
|
//批量操作
|
|
|
List<LapiMsgResult> lapiResults = lapiService.addPersonForDeviceIds(personId,deviceId);
|
|
|
+
|
|
|
+ for (int i = 0; i < lapiResults.size(); i++) {
|
|
|
+ LapiMsgResult lapiMsgResult = lapiResults.get(i);
|
|
|
+ if (lapiMsgResult.isSuccess()) {
|
|
|
+ msgResult.setResult(true);
|
|
|
+ }else{
|
|
|
+ HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
|
|
|
+ HSSFCell cell1 = row.createCell(0);
|
|
|
+ cell1.setCellValue(lapiMsgResult.getPersonName());
|
|
|
+ HSSFCell cell2 = row.createCell(1);
|
|
|
+ cell2.setCellValue(lapiMsgResult.getAliasName());
|
|
|
+ HSSFCell cell3 = row.createCell(2);
|
|
|
+ cell3.setCellValue("添加失败:" + lapiMsgResult.getMsg());
|
|
|
+ HSSFCell cell4 = row.createCell(3);
|
|
|
+ cell4.setCellValue(lapiMsgResult.getMsg());
|
|
|
+
|
|
|
+ //删除绑定关系
|
|
|
+ PersonDeviceRelation personDeviceRelation = personDeviceRelationService.findByDeviceIdAndPersonId(deviceId,personId);
|
|
|
+ personDeviceRelation.setDelFlag(true);
|
|
|
+ personDeviceRelation.setUpdateBy(subject);
|
|
|
+ personDeviceRelation.setUpdateTime(new Date());
|
|
|
+ personDeviceRelationService.update(personDeviceRelation);
|
|
|
+ addCount ++;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (affectCount > 0) {
|
|
|
- msgResult.setResult(true);
|
|
|
- msgResult.setData(affectCount);
|
|
|
+ if(addCount > 0){
|
|
|
+ //异常数量大于0,表示有部分数据同步失败
|
|
|
+ msgResult.setResult(false);
|
|
|
+ //保存失败信息
|
|
|
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
|
|
|
+ workbook.write(output);
|
|
|
+ byte[] buffer = output.toByteArray();
|
|
|
+ ByteArrayInputStream input = new ByteArrayInputStream(buffer);
|
|
|
+ String downloadUrl = OSSUtil.upload(ossConfig,"import","error.xls",input);
|
|
|
+ msgResult.setMessage(downloadUrl);
|
|
|
+ }else {
|
|
|
+ //异常数量为0,表示全部同步成功
|
|
|
+ msgResult.setResult(true);
|
|
|
+ msgResult.setData(affectCount);
|
|
|
+ }
|
|
|
} else {
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage("有0个人员与设备绑定成功!");
|