Bladeren bron

sz 单位人员管理,人员绑定设备判断

xiao547607 5 jaren geleden
bovenliggende
commit
1f11b7b5e6

+ 26 - 12
web/src/main/java/com/jpsoft/smart/modules/base/controller/DeviceInfoController.java

@@ -1,21 +1,14 @@
 package com.jpsoft.smart.modules.base.controller;
 
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
-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.LApiUtil;
 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;
@@ -24,9 +17,6 @@ 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.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -34,9 +24,7 @@ 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.math.BigDecimal;
-import java.text.SimpleDateFormat;
 import java.util.*;
 
 @RestController
@@ -544,4 +532,30 @@ public class DeviceInfoController {
     }
 
 
+
+    @ApiOperation(value = "查询")
+    @RequestMapping(value = "query", method = RequestMethod.POST)
+    public MessageResult<List> query(
+            String aliasName,
+            @RequestParam(value = "limit", defaultValue = "20") int limit,
+            @RequestAttribute String subject) {
+        MessageResult<List> msgResult = new MessageResult<>();
+
+        Map<String, Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("a.is_online","desc"));
+        sortList.add(new Sort("a.create_time","desc"));
+
+        if (StringUtils.isNotEmpty(aliasName)) {
+            searchParams.put("aliasName", "%" + aliasName + "%");
+        }
+        List<DeviceInfo> deviceList = deviceInfoService.pageSearch(searchParams,1, limit,false, sortList);
+
+        msgResult.setResult(true);
+        msgResult.setData(deviceList);
+
+        return msgResult;
+    }
+
 }

+ 54 - 56
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -95,7 +95,7 @@ public class PersonDeviceRelationController {
                 personDeviceRelation.setDelFlag(false);
                 personDeviceRelation.setCreateBy(subject);
                 personDeviceRelation.setCreateTime(new Date());
-                personDeviceRelation.setIsBound(true);//绑定设备默认true
+                personDeviceRelation.setIsBound(false);//绑定设备默认true
 
                 affectCount = personDeviceRelationService.insert(personDeviceRelation);
             }
@@ -105,24 +105,24 @@ public class PersonDeviceRelationController {
                 //往设备库传输人脸信息
                 PersonInfo personInfo = personInfoService.get(personDeviceRelation.getPersonId());
                 //如果人员照片不为空
-                //if(StringUtils.isNotEmpty(personInfo.getFaceImageUrl())){
-
-                DeviceInfo deviceInfo = deviceInfoService.get(personDeviceRelation.getDeviceId());
-                if(!deviceInfo.getIsOnline()){
-                    throw new Exception("无法绑定,设备不在线!" );
-                }
-                List<LapiResult> lapiResults = lapiService.addPersonForDeviceIds(personDeviceRelation.getPersonId(),personDeviceRelation.getDeviceId());
-                for (int i = 0; i < lapiResults.size(); i++) {
-                    LapiResult lapiMsgResult = lapiResults.get(i);
-                    if (lapiMsgResult.isSuccess()) {
-                        msgResult.setResult(true);
-                    }else{
-                        throw new Exception("添加失败:" + lapiMsgResult.getMsg());
+                if(StringUtils.isNotEmpty(personInfo.getFaceImageUrl())){
+                    DeviceInfo deviceInfo = deviceInfoService.get(personDeviceRelation.getDeviceId());
+                    if(!deviceInfo.getIsOnline()){
+                        throw new Exception("无法绑定,设备不在线!" );
                     }
-                }
-                //}else{
+                    List<LapiResult> lapiResults = lapiService.addPersonForDeviceIds(personDeviceRelation.getPersonId(),personDeviceRelation.getDeviceId());
+                    for (int i = 0; i < lapiResults.size(); i++) {
+                        LapiResult lapiMsgResult = lapiResults.get(i);
+                        if (lapiMsgResult.isSuccess()) {
+                            msgResult.setResult(true);
+                        }else{
+                            throw new Exception("添加失败:" + lapiMsgResult.getMsg());
+                        }
+                    }
+                }else{
                     //throw new Exception("添加失败:人员没有上传照片" );
-                //}
+                    //没有照片 可以只进行数据绑定 不进行设备操作
+                }
                 msgResult.setResult(true);
                 msgResult.setData(personDeviceRelation);
             } else {
@@ -169,7 +169,7 @@ public class PersonDeviceRelationController {
                        item.setDelFlag(false);
                        item.setCreateBy(subject);
                        item.setCreateTime(new Date());
-                       item.setIsBound(true);//绑定设备默认true
+                       item.setIsBound(false);//绑定设备默认false
 
                        affectCount += personDeviceRelationService.insert(item);
                    }
@@ -183,43 +183,41 @@ public class PersonDeviceRelationController {
                 //往设备库传输人脸信息
                 PersonInfo personInfo = personInfoService.get(personId);
                 //如果人员照片不为空
-                //if(StringUtils.isNotEmpty(personInfo.getFaceImageUrl())) {
-                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 {
-                        String personName = "";
-                        if (personInfo != null) {
-                            personName = personInfo.getName();
+                if(StringUtils.isNotEmpty(personInfo.getFaceImageUrl())) {
+                    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 {
+                            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());
+                            personDeviceRelation.setIsBound(false);
+
+                            personDeviceRelationService.update(personDeviceRelation);
+                            addCount++;
                         }
-                        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());
-                        personDeviceRelation.setIsBound(false);
-
-                        personDeviceRelationService.update(personDeviceRelation);
-                        addCount++;
                     }
                 }
-                //}
 //
-
-
                 if(addCount > 0){
                     //异常数量大于0,表示有部分数据同步失败
                     msgResult.setResult(false);
@@ -288,15 +286,15 @@ public class PersonDeviceRelationController {
                         item.setDelFlag(false);
                         item.setCreateBy(subject);
                         item.setCreateTime(new Date());
-                        item.setIsBound(true);//绑定设备默认true
+                        item.setIsBound(false);//绑定设备默认false
 
                         affectCount += personDeviceRelationService.insert(item);
                         //往设备库传输人脸信息
                         //批量操作
 
-//                        PersonInfo personInfo = personInfoService.get(personId);
+                        PersonInfo personInfo = personInfoService.get(personId);
 //                        //如果人员照片为空
-//                        if(StringUtils.isEmpty(personInfo.getFaceImageUrl())){
+                        if(StringUtils.isEmpty(personInfo.getFaceImageUrl())){
 //                            HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
 //                            HSSFCell cell1 = row.createCell(0);
 //                            cell1.setCellValue(personInfo.getName());
@@ -312,8 +310,8 @@ public class PersonDeviceRelationController {
 //                            item.setUpdateBy(subject);
 //                            item.setUpdateTime(new Date());
 //                            personDeviceRelationService.update(item);
-//                            continue;
-//                        }
+                            continue;
+                        }
 
                         List<LapiResult> lapiResults = lapiService.addPersonForDeviceIds(personId,deviceId);
 

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

@@ -1103,7 +1103,7 @@ public class PersonInfoController {
 //            }
 //            else{
 //                searchParams.put("companyId",user.getCompanyId());
-//            }
+//
             if (StringUtils.isNotEmpty(position1)) {
                 searchParams.put("position1","%" + position1 + "%");
             }