Selaa lähdekoodia

Merge remote-tracking branch 'origin/V1' into V1

zhengqiang 5 vuotta sitten
vanhempi
commit
6f1c93c5f4

+ 1 - 1
common/src/main/java/com/jpsoft/smart/modules/lapi/service/ILapiService.java

@@ -35,7 +35,7 @@ public interface ILapiService {
      * @return
      * @throws Exception
      */
-     List<LapiMsgResult> addPerson(Long id) throws Exception;
+     List<LapiResult> addPerson(Long id) throws Exception;
 
 
     /**

+ 25 - 17
common/src/main/java/com/jpsoft/smart/modules/lapi/service/impl/LapiServiceImpl.java

@@ -70,7 +70,7 @@ public class LapiServiceImpl implements ILapiService {
     }
 
     @Override
-    public List<LapiMsgResult> addPerson(Long id) throws Exception {
+    public List<LapiResult> addPerson(Long id) throws Exception {
 
         PersonInfo personInfo = personInfoService.get(id);
         if (personInfo == null) {
@@ -92,10 +92,8 @@ public class LapiServiceImpl implements ILapiService {
             throw new Exception("人员与设备绑定错误");
         }
         String base64Data = OSSUtil.downloadToBase64(personInfo.getFaceImageUrl());
-        if (base64Data.length() > 512 * 1024 || base64Data.length() < 10 * 1024) {
-            throw new Exception("人员照片大小限定为10k~512k");
-        }
-        List<LapiMsgResult> lapiMsgResults = new ArrayList<>();
+
+        List<LapiResult> lapiResultList = new ArrayList<>();
         for (DeviceInfo deviceInfo : deviceList) {
             HashMap<String, Object> map = new HashMap<>();
             map.put("Num", 1L);
@@ -132,6 +130,9 @@ public class LapiServiceImpl implements ILapiService {
             map.put("PersonInfoList", listMap1);
 
             try {
+                if (base64Data.length() > 512 * 1024 || base64Data.length() < 10 * 1024) {
+                    throw new Exception("人员照片大小限定为10k~512k");
+                }
                 //获取人员人脸库id
                 String faceDbId = getFaceDbId(deviceInfo, companyInfo.getName());
 
@@ -139,24 +140,31 @@ public class LapiServiceImpl implements ILapiService {
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
-                    LapiMsgResult lapiMsgResult = new LapiMsgResult();
-                    lapiMsgResult.setPersonName(personInfo.getName());
-                    lapiMsgResult.setSuccess(true);
-                    lapiMsgResult.setAliasName(deviceInfo.getAliasName());
-                    lapiMsgResults.add(lapiMsgResult);
+                    HashMap<String,Object> dataMap = new HashMap<>();
+                    dataMap.put("deviceId",deviceInfo.getId());
+                    dataMap.put("deviceAliasName",deviceInfo.getAliasName());
+                    dataMap.put("persoName",personInfo.getName());
+                    LapiResult lapiResult = new LapiResult();
+                    lapiResult.setMsg("绑定成功");
+                    lapiResult.setSuccess(true);
+                    lapiResult.setData(dataMap);
+                    lapiResultList.add(lapiResult);
                 }
             } catch (Exception e) {
                 log.error(e.getMessage());
-                LapiMsgResult lapiMsgResult = new LapiMsgResult();
-                lapiMsgResult.setPersonName(personInfo.getName());
-                lapiMsgResult.setSuccess(false);
-                lapiMsgResult.setMsg(e.getMessage());
-                lapiMsgResult.setAliasName(deviceInfo.getAliasName());
-                lapiMsgResults.add(lapiMsgResult);
+                HashMap<String,Object> dataMap = new HashMap<>();
+                dataMap.put("deviceId",deviceInfo.getId());
+                dataMap.put("deviceAliasName",deviceInfo.getAliasName());
+                dataMap.put("persoName",personInfo.getName());
+                LapiResult lapiResult = new LapiResult();
+                lapiResult.setSuccess(false);
+                lapiResult.setMsg(e.getMessage());
+                lapiResult.setData(dataMap);
+                lapiResultList.add(lapiResult);
             }
         }
 
-        return lapiMsgResults;
+        return lapiResultList;
     }
 
     @Override

+ 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

@@ -13,6 +13,7 @@ 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.sys.service.UserService;
 import io.swagger.annotations.Api;
@@ -1148,21 +1149,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();