Bläddra i källkod

sz 设备同步方法

xiao547607 5 år sedan
förälder
incheckning
59b5696444

+ 34 - 2
web/src/main/java/com/jpsoft/smart/modules/base/controller/CompanyInfoController.java

@@ -485,6 +485,8 @@ public class CompanyInfoController {
                 cdr.setCreateBy(subject);
                 cdr.setCreateTime(new Date());
 
+                /**设备添加人脸库**/
+                /*
                 //设备添加人脸库
                 List<LapiResult> lapiResults= lapiService.addCompanyLib(companyId,deviceId);
                 for (int i = 0; i < lapiResults.size(); i++) {
@@ -498,6 +500,7 @@ public class CompanyInfoController {
                         System.out.println("LibraryId=============" + libraryId);
                     }
                 }
+                 */
 
                 cdr.setLibraryId(libraryId);
                 companyDeviceRelationService.insert(cdr);
@@ -525,16 +528,19 @@ public class CompanyInfoController {
             String[] arr = deviceIds.split(",");
 
             for (String deviceId : arr) {
-                //companyDeviceRelationService.deleteByCompanyIdAndDeviceId(companyId,deviceId);
+                companyDeviceRelationService.deleteByCompanyIdAndDeviceId(companyId,deviceId);
+                /** 删除人脸库操作**/
+                /*
                 CompanyDeviceRelation companyDeviceRelation = companyDeviceRelationService.findByCompanyIdAndDeviceId(companyId, deviceId);
                 if (companyDeviceRelation != null) {
-                    //设备添加人脸库
+                    //设备删除人脸库
                     LapiResult lapiResult = lapiService.deleteCompanyLib(deviceId, companyDeviceRelation.getLibraryId());
                     if (lapiResult.isSuccess()) {
                         //删除成功
                         companyDeviceRelationService.deleteByCompanyIdAndDeviceId(companyId, deviceId);
                     }
                 }
+                */
             }
             messageResult.setResult(true);
         }
@@ -548,4 +554,30 @@ public class CompanyInfoController {
 
         return messageResult;
     }
+
+    @ApiOperation(value="单位树")
+    @RequestMapping(value = "treeList",method = RequestMethod.POST)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name="subject",value = "当前用户编号(不传)",paramType = "form")
+    })
+    public MessageResult<List<CompanyInfo>> treeList(HttpServletRequest request){
+        String subject = (String)request.getAttribute("subject");
+
+        MessageResult<List<CompanyInfo>> msgResult = new MessageResult<>();
+        User user = userService.get(subject);
+        List<CompanyInfo> list = new ArrayList<>();
+
+        if (userService.hasRole(subject,"SYSADMIN")) {
+            list = companyInfoService.list();
+        }
+        else if(userService.hasRole(subject,"ADMIN")){
+            CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
+            list = companyInfoService.findByCompanyCode(companyInfo.getCode() + "%",null);
+        }
+
+        msgResult.setResult(true);
+        msgResult.setData(list);
+
+        return msgResult;
+    }
 }

+ 16 - 0
web/src/main/java/com/jpsoft/smart/modules/base/controller/DeviceInfoController.java

@@ -76,6 +76,7 @@ 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++) {
@@ -103,6 +104,21 @@ public class DeviceInfoController {
                         companyDeviceRelationService.insert(companyDeviceRelation);
                     }
                 }
+                */
+
+                //添加信息到设备与公司关联表
+                //先查关联表是否存在数据
+                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("");
+                companyDeviceRelationService.insert(companyDeviceRelation);
+
 
                 if (affectCount > 0) {
                     msgResult.setResult(true);

+ 67 - 6
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -2,13 +2,16 @@ package com.jpsoft.smart.modules.base.controller;
 
 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.service.DeviceInfoService;
+import com.jpsoft.smart.modules.common.utils.OSSUtil;
 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.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.base.entity.PersonDeviceRelation;
 import com.jpsoft.smart.modules.base.service.PersonDeviceRelationService;
@@ -19,13 +22,20 @@ 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.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 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;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -50,8 +60,12 @@ public class PersonDeviceRelationController {
     @Autowired
     private ILapiService lapiService;
 
+    @Autowired
+    private OSSConfig ossConfig;
+
     
     @ApiOperation(value="添加设备和人员绑定")
+    @Transactional(rollbackFor = Exception.class)
     @PostMapping("add")
     public MessageResult<PersonDeviceRelation> add(@RequestBody PersonDeviceRelation personDeviceRelation,@RequestAttribute String subject){
         MessageResult<PersonDeviceRelation> msgResult = new MessageResult<>();
@@ -59,10 +73,9 @@ public class PersonDeviceRelationController {
         try {
             int affectCount = 0;
 
-            PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(personDeviceRelation.getDeviceId(),personDeviceRelation.getPersonId());
+            PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(personDeviceRelation.getDeviceId(), personDeviceRelation.getPersonId());
 
             if(item == null) {
-
                 personDeviceRelation.setId(UUID.randomUUID().toString());
                 personDeviceRelation.setDelFlag(false);
                 personDeviceRelation.setCreateBy(subject);
@@ -71,7 +84,18 @@ public class PersonDeviceRelationController {
                 affectCount = personDeviceRelationService.insert(personDeviceRelation);
             }
 
+
             if (affectCount > 0) {
+                //往设备库传输人脸信息
+                List<LapiMsgResult> lapiResults = lapiService.addPersonForDeviceIds(personDeviceRelation.getPersonId(),personDeviceRelation.getDeviceId());
+                for (int i = 0; i < lapiResults.size(); i++) {
+                    LapiMsgResult lapiMsgResult = lapiResults.get(i);
+                    if (lapiMsgResult.isSuccess()) {
+                        msgResult.setResult(true);
+                    }else{
+                        throw new Exception("添加失败:" + lapiMsgResult.getMsg());
+                    }
+                }
                 msgResult.setResult(true);
                 msgResult.setData(personDeviceRelation);
             } else {
@@ -80,8 +104,8 @@ public class PersonDeviceRelationController {
             }
         }
         catch(Exception ex){
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
             logger.error(ex.getMessage(),ex);
-
             msgResult.setResult(false);
             msgResult.setMessage(ex.getMessage());
         }
@@ -101,13 +125,15 @@ public class PersonDeviceRelationController {
         int affectCount = 0;
 
         try {
+            HSSFWorkbook workbook = new HSSFWorkbook();
+            HSSFSheet sheet = workbook.createSheet();
+
             if(StringUtil.isNotEmpty(devices)){
                String[] deviceArray = devices.split(",");
 
                for (String deviceId:deviceArray) {
 
                    PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(deviceId,personId);
-
                    if(item == null) {
                        item = new PersonDeviceRelation();
                        item.setId(UUID.randomUUID().toString());
@@ -123,6 +149,33 @@ 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);
+//
+//                msgResult.setMessage(downloadUrl);
                 msgResult.setResult(true);
                 msgResult.setData(affectCount);
             } else {
@@ -173,6 +226,9 @@ public class PersonDeviceRelationController {
                         item.setCreateTime(new Date());
 
                         affectCount += personDeviceRelationService.insert(item);
+                        //往设备库传输人脸信息
+                        //批量操作
+                        List<LapiMsgResult> lapiResults = lapiService.addPersonForDeviceIds(personId,deviceId);
                     }
                 }
             }
@@ -261,7 +317,9 @@ public class PersonDeviceRelationController {
             personDeviceRelation.setUpdateBy(subject);
             personDeviceRelation.setUpdateTime(new Date());
 
-            int affectCount = personDeviceRelationService.updateDevicePerson(personDeviceRelation);
+            /**删除同时删除设备**/
+            //int affectCount = personDeviceRelationService.updateDevicePerson(personDeviceRelation);
+            int affectCount = personDeviceRelationService.update(personDeviceRelation);
 
             if (affectCount > 0) {
                 msgResult.setResult(true);
@@ -295,7 +353,10 @@ public class PersonDeviceRelationController {
                 personDeviceRelation.setUpdateBy(subject);
                 personDeviceRelation.setUpdateTime(new Date());
 
-                affectCount = personDeviceRelationService.updateDevicePerson(personDeviceRelation);
+                /**删除同时删除设备**/
+                //affectCount = personDeviceRelationService.updateDevicePerson(personDeviceRelation);
+
+                affectCount = personDeviceRelationService.update(personDeviceRelation);
             }
 
             if (affectCount > 0) {