|
@@ -1,13 +1,19 @@
|
|
|
package com.jpsoft.smart.modules.base.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.github.pagehelper.Page;
|
|
|
import com.jpsoft.smart.modules.base.entity.AlarmInfo;
|
|
|
+import com.jpsoft.smart.modules.base.entity.CompanyDeviceRelation;
|
|
|
+import com.jpsoft.smart.modules.base.service.CompanyDeviceRelationService;
|
|
|
import com.jpsoft.smart.modules.common.utils.PojoUtils;
|
|
|
import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
import com.jpsoft.smart.modules.common.dto.MessageResult;
|
|
|
import com.jpsoft.smart.modules.base.entity.DeviceInfo;
|
|
|
import com.jpsoft.smart.modules.base.service.DeviceInfoService;
|
|
|
import com.jpsoft.smart.modules.lapi.service.ILapiService;
|
|
|
+import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
|
|
|
+import com.jpsoft.smart.modules.lapi.vo.LapiResult;
|
|
|
import com.jpsoft.smart.modules.sys.entity.User;
|
|
|
import com.jpsoft.smart.modules.sys.service.DataDictionaryService;
|
|
|
import com.jpsoft.smart.modules.sys.service.UserService;
|
|
@@ -16,9 +22,13 @@ import io.swagger.annotations.ApiImplicitParam;
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
+import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
@@ -43,7 +53,13 @@ public class DeviceInfoController {
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CompanyDeviceRelationService companyDeviceRelationService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@ApiOperation(value="添加设备")
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
@PostMapping("add")
|
|
|
public MessageResult<DeviceInfo> add(@RequestBody DeviceInfo deviceInfo,@RequestAttribute String subject){
|
|
|
MessageResult<DeviceInfo> msgResult = new MessageResult<>();
|
|
@@ -60,6 +76,34 @@ public class DeviceInfoController {
|
|
|
|
|
|
int affectCount = deviceInfoService.insert(deviceInfo);
|
|
|
|
|
|
+ //设备添加人脸库
|
|
|
+ List<LapiResult> lapiResults= lapiService.addCompanyLib(deviceInfo.getCompanyId(),deviceInfo.getId());
|
|
|
+ for (int i = 0; i < lapiResults.size(); i++) {
|
|
|
+ LapiResult lapiResult = lapiResults.get(i);
|
|
|
+
|
|
|
+ if (lapiResult.isSuccess()) {
|
|
|
+ //默认人脸库ID defaultFaceLibraryId
|
|
|
+ //LibraryId
|
|
|
+ //LibraryId -> 1585025356
|
|
|
+ HashMap dataMap = (HashMap) lapiResult.getData();
|
|
|
+ String libraryId = dataMap.get("LibraryId").toString();
|
|
|
+ System.out.println("LibraryId=============" + libraryId);
|
|
|
+
|
|
|
+ //添加信息到设备与公司关联表
|
|
|
+ //先查关联表是否存在数据
|
|
|
+ CompanyDeviceRelation companyDeviceRelation = companyDeviceRelationService.findByCompanyIdAndDeviceId(deviceInfo.getCompanyId(),deviceInfo.getId());
|
|
|
+ if(companyDeviceRelation == null ){
|
|
|
+ companyDeviceRelation = new CompanyDeviceRelation();
|
|
|
+ companyDeviceRelation.setId(UUID.randomUUID().toString());
|
|
|
+ }
|
|
|
+ companyDeviceRelation.setCompanyId(deviceInfo.getCompanyId());
|
|
|
+ companyDeviceRelation.setDeviceId(deviceInfo.getId());
|
|
|
+ //保存人脸库ID
|
|
|
+ companyDeviceRelation.setLibraryId(libraryId);
|
|
|
+ companyDeviceRelationService.insert(companyDeviceRelation);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if (affectCount > 0) {
|
|
|
msgResult.setResult(true);
|
|
|
msgResult.setData(deviceInfo);
|
|
@@ -74,6 +118,7 @@ public class DeviceInfoController {
|
|
|
}
|
|
|
}
|
|
|
catch(Exception ex){
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
logger.error(ex.getMessage(),ex);
|
|
|
msgResult.setResult(false);
|
|
|
msgResult.setMessage(ex.getMessage());
|
|
@@ -172,10 +217,30 @@ public class DeviceInfoController {
|
|
|
|
|
|
try {
|
|
|
DeviceInfo deviceInfo = deviceInfoService.get(id);
|
|
|
+// //删除所有设备人脸库
|
|
|
+ //清除人脸数据
|
|
|
+ //危险操作
|
|
|
+// List<LapiResult> lapiResults= lapiService.deleteDeviceAllCompanyLib(id);
|
|
|
+// for (int i = 0; i < lapiResults.size(); i++) {
|
|
|
+// LapiResult lapiResult = lapiResults.get(i);
|
|
|
+// if (lapiResult.isSuccess()) {
|
|
|
+// Object obj = lapiResult.getData();
|
|
|
+// //默认人脸库ID defaultFaceLibraryId
|
|
|
+// //LibraryId
|
|
|
+// //LibraryId -> 1585025356
|
|
|
+//
|
|
|
+// //设备上的人脸库删除成功后
|
|
|
+// //执行删除设备
|
|
|
+// deviceInfo.setDelFlag(true);
|
|
|
+// deviceInfo.setUpdateBy(subject);
|
|
|
+// deviceInfo.setUpdateTime(new Date());
|
|
|
+// affectCount = deviceInfoService.update(deviceInfo);
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
deviceInfo.setDelFlag(true);
|
|
|
deviceInfo.setUpdateBy(subject);
|
|
|
deviceInfo.setUpdateTime(new Date());
|
|
|
-
|
|
|
int affectCount = deviceInfoService.update(deviceInfo);
|
|
|
|
|
|
if (affectCount > 0) {
|