xiao547607 %!s(int64=5) %!d(string=hai) anos
pai
achega
f975557238

+ 7 - 5
web/src/main/java/com/jpsoft/smart/listener/ImportImageListener.java

@@ -4,6 +4,7 @@ import com.jpsoft.smart.modules.base.entity.PersonInfo;
 import com.jpsoft.smart.modules.base.service.PersonInfoService;
 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 lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.rabbit.annotation.RabbitHandler;
 import org.springframework.amqp.rabbit.annotation.RabbitListener;
@@ -12,6 +13,7 @@ import org.springframework.stereotype.Component;
 
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * concurrency 表示并发数
@@ -31,19 +33,19 @@ public class ImportImageListener {
         System.out.println("收到用户编号:" + personId);
 
         try {
-            List<LapiMsgResult> msgResultList = lapiService.addPerson(personId);
+            List<LapiResult> msgResultList = lapiService.addPerson(personId);
 
             StringBuilder sb = new StringBuilder();
 
             boolean success = true;
 
             for (int i = 0; i < msgResultList.size(); i++) {
-                LapiMsgResult lapiMsgResult = msgResultList.get(i);
-
+                LapiResult lapiMsgResult = msgResultList.get(i);
+                Map lapiMsgMap = (Map)lapiMsgResult.getData();
                 if (lapiMsgResult.isSuccess()) {
-                    sb.append(lapiMsgResult.getAliasName() + "绑定人脸信息成功!");
+                    sb.append(lapiMsgMap.get("deviceAliasName") + "绑定人脸信息成功!");
                 } else {
-                    sb.append(lapiMsgResult.getAliasName() + "绑定人脸信息失败!" + lapiMsgResult.getMsg());
+                    sb.append(lapiMsgMap.get("deviceAliasName") + "绑定人脸信息失败!" + lapiMsgResult.getMsg());
                 }
 
                 if (i != msgResultList.size() - 1) {

+ 104 - 28
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -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个人员与设备绑定成功!");

+ 7 - 6
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -19,6 +19,7 @@ import com.jpsoft.smart.modules.base.entity.PersonInfo;
 import com.jpsoft.smart.modules.base.service.PersonInfoService;
 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.UserService;
 import io.swagger.annotations.Api;
@@ -1135,21 +1136,21 @@ public class PersonInfoController {
         boolean bl = true;
 
         try {
-            List<LapiMsgResult> msgResultList = lapiService.addPerson(personInfo.getId());
+            List<LapiResult> msgResultList = lapiService.addPerson(personInfo.getId());
 
             for (int i = 0; i < msgResultList.size(); i++) {
-                LapiMsgResult lapiMsgResult = msgResultList.get(i);
-
-                if (!lapiMsgResult.isSuccess()) {
+                LapiResult lapiResult = msgResultList.get(i);
+                if (!lapiResult.isSuccess()) {
+                    Map resultMap = (Map)lapiResult.getData();
                     HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
                     HSSFCell cell1 = row.createCell(0);
                     cell1.setCellValue(personInfo.getName());
                     HSSFCell cell2 = row.createCell(1);
-                    cell2.setCellValue(lapiMsgResult.getAliasName());
+                    cell2.setCellValue(resultMap.get("deviceAliasName").toString());
                     HSSFCell cell3 = row.createCell(2);
                     cell3.setCellValue("绑定人脸信息失败!");
                     HSSFCell cell4 = row.createCell(3);
-                    cell4.setCellValue(lapiMsgResult.getMsg());
+                    cell4.setCellValue(lapiResult.getMsg());
 
                     bl = false;
                 }

+ 2 - 2
web/src/test/java/com/jpsoft/smart/LApiTest.java

@@ -41,8 +41,8 @@ public class LApiTest {
     public void testAddPerson(){
         try {
 
-            List<LapiMsgResult> result = lapiService.addPerson(11838L);
-            System.out.println(result);
+            //List<LapiMsgResult> result = lapiService.addPerson(11838L);
+            //System.out.println(result);
         } catch (Exception e) {
             e.printStackTrace();
             String message = e.getMessage();