Sfoglia il codice sorgente

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

# Conflicts:
#	common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonInfoDAO.java
#	common/src/main/java/com/jpsoft/smart/modules/base/service/PersonInfoService.java
#	common/src/main/resources/mapper/base/PersonInfo.xml
zhengqiang 5 anni fa
parent
commit
3ca07e56a4
17 ha cambiato i file con 394 aggiunte e 105 eliminazioni
  1. 2 0
      common/src/main/java/com/jpsoft/smart/modules/base/dao/DeviceInfoDAO.java
  2. 2 0
      common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonInfoDAO.java
  3. 1 0
      common/src/main/java/com/jpsoft/smart/modules/base/service/DeviceInfoService.java
  4. 1 0
      common/src/main/java/com/jpsoft/smart/modules/base/service/PersonInfoService.java
  5. 5 0
      common/src/main/java/com/jpsoft/smart/modules/base/service/impl/DeviceInfoServiceImpl.java
  6. 11 6
      common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonInfoServiceImpl.java
  7. 8 1
      common/src/main/java/com/jpsoft/smart/modules/lapi/service/ILapiService.java
  8. 93 28
      common/src/main/java/com/jpsoft/smart/modules/lapi/service/impl/LapiServiceImpl.java
  9. 3 0
      common/src/main/resources/mapper/base/DeviceInfo.xml
  10. 17 4
      common/src/main/resources/mapper/base/MessageNotice.xml
  11. 8 0
      common/src/main/resources/mapper/base/PersonInfo.xml
  12. 29 5
      lapi/src/main/java/com/jpsoft/smart/lapi/handler/PersonVerificationHandler.java
  13. 31 1
      web/src/main/java/com/jpsoft/smart/modules/base/controller/MessageNoticeController.java
  14. 136 41
      web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java
  15. 10 0
      web/src/main/java/com/jpsoft/smart/modules/mobile/controller/MessageNoticeApiController.java
  16. 24 19
      web/src/main/java/com/jpsoft/smart/schduled/HeartbeatDetectionTask.java
  17. 13 0
      web/src/test/java/com/jpsoft/smart/LApiTest.java

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/DeviceInfoDAO.java

@@ -20,4 +20,6 @@ public interface DeviceInfoDAO {
 	List<DeviceInfo> search(Map<String, Object> searchParams, List<Sort> sortList);
 
 	DeviceInfo findByDeviceNo(String deviceNo);
+
+	List<DeviceInfo> listOnline();
 }

+ 2 - 0
common/src/main/java/com/jpsoft/smart/modules/base/dao/PersonInfoDAO.java

@@ -19,5 +19,7 @@ public interface PersonInfoDAO {
 	PersonInfo findByOpenId(String openId);
     List<PersonInfo> findByCompanyId(String companyId);
     long countByCompanyCode(String code,Long personId);
+
+	PersonInfo getIgnoreDelFlag(Long id);
 	List<PersonInfo> findByCompanyCode(String code);
 }

+ 1 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/DeviceInfoService.java

@@ -19,4 +19,5 @@ public interface DeviceInfoService {
 	Page<DeviceInfo> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize,boolean count, List<Sort> sortList);
 	void updateByDeviceNo(String deviceNo, String ip);
 
+	List<DeviceInfo> listOnline();
 }

+ 1 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/PersonInfoService.java

@@ -20,6 +20,7 @@ public interface PersonInfoService {
 
     List<PersonInfo> findByCompanyId(String companyId);
 
+	PersonInfo getIgnoreDelFlag(Long id);
     long countByCompanyCode(String code,Long relatePersonId);
 
 	List<PersonInfo> findByCompanyCode(String code);

+ 5 - 0
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/DeviceInfoServiceImpl.java

@@ -111,4 +111,9 @@ public class DeviceInfoServiceImpl implements DeviceInfoService {
 		}
 
 	}
+
+	@Override
+	public List<DeviceInfo> listOnline() {
+		return deviceInfoDAO.listOnline();
+	}
 }

+ 11 - 6
common/src/main/java/com/jpsoft/smart/modules/base/service/impl/PersonInfoServiceImpl.java

@@ -29,14 +29,14 @@ public class PersonInfoServiceImpl implements PersonInfoService {
 	public int insert(PersonInfo model) {
 		// TODO Auto-generated method stub
 		//model.setId(UUID.randomUUID().toString());
-		
+
 		return personInfoDAO.insert(model);
 	}
 
 	@Override
 	public int update(PersonInfo model) {
 		// TODO Auto-generated method stub
-		return personInfoDAO.update(model);		
+		return personInfoDAO.update(model);
 	}
 
 	@Override
@@ -49,22 +49,22 @@ public class PersonInfoServiceImpl implements PersonInfoService {
 	public boolean exist(Long id) {
 		// TODO Auto-generated method stub
 		int count = personInfoDAO.exist(id);
-		
+
 		return count > 0 ? true : false;
 	}
-	
+
 	@Override
 	public List<PersonInfo> list() {
 		// TODO Auto-generated method stub
 		return personInfoDAO.list();
 	}
-		
+
 	@Override
 	public Page<PersonInfo> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize,boolean count,List<Sort> sortList) {
         Page<PersonInfo> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
             personInfoDAO.search(searchParams,sortList);
         });
-        
+
         return page;
 	}
 
@@ -92,4 +92,9 @@ public class PersonInfoServiceImpl implements PersonInfoService {
 	public List<PersonInfo> findByCompanyCode(String code) {
 		return personInfoDAO.findByCompanyCode(code);
 	}
+
+	@Override
+	public PersonInfo getIgnoreDelFlag(Long id) {
+		return personInfoDAO.getIgnoreDelFlag(id);
+	}
 }

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

@@ -1,6 +1,7 @@
 package com.jpsoft.smart.modules.lapi.service;
 
 import com.jpsoft.smart.modules.base.entity.DeviceInfo;
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
 import com.jpsoft.smart.modules.lapi.vo.LapiMsgResult;
 import com.jpsoft.smart.modules.lapi.vo.LapiResult;
 
@@ -45,7 +46,7 @@ public interface ILapiService {
      * @return
      * @throws Exception
      */
-     List<LapiMsgResult> addPersonForDeviceIds(Long id ,String deviceIds) throws Exception;
+     List<LapiResult> addPersonForDeviceIds(Long id ,String deviceIds) throws Exception;
 
     /**
      * 根据公司名称获取人脸库
@@ -127,6 +128,12 @@ public interface ILapiService {
     List<LapiResult> deleteDeviceAllCompanyLib(String deviceInfoId) throws Exception;
 
 
+    /**
+     * 人员是否成功写入设备
+     * @param
+     * @return
+     */
+    Boolean isSuccessAddPerson(PersonInfo personInfo, DeviceInfo deviceInfo, String faceDbId);
 
 
 

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

@@ -120,7 +120,9 @@ public class LapiServiceImpl implements ILapiService {
             map3.put("FaceID", personInfo.getId());
             map3.put("Name", personInfo.getId() + ".jpg");
 
-            map3.put("Size", base64Data.length());
+            //照片base64长度
+            Integer imageSize = base64Data.length();
+            map3.put("Size", imageSize);
             map3.put("Data", base64Data);
             List listMap3 = new ArrayList();
             listMap3.add(map3);
@@ -130,7 +132,9 @@ public class LapiServiceImpl implements ILapiService {
             map.put("PersonInfoList", listMap1);
 
             try {
-                if (base64Data.length() > 512 * 1024 || base64Data.length() < 10 * 1024) {
+                //照片字节大小
+                Integer fileSize = imageSize - (imageSize/8)*2;
+                if (fileSize > 512 * 1024 || fileSize < 10 * 1024) {
                     throw new Exception("人员照片大小限定为10k~512k");
                 }
                 //获取人员人脸库id
@@ -140,25 +144,34 @@ public class LapiServiceImpl implements ILapiService {
                 JSONObject dataJson = jsonObject.getJSONObject("Response");
                 JSONObject response = LApiUtil.getResponse(dataJson);
                 if (dataJson.getInteger("ResponseCode") == 0 && dataJson.getInteger("StatusCode") == 0) {
+                    Boolean success = isSuccessAddPerson(personInfo,deviceInfo,faceDbId);
                     HashMap<String,Object> dataMap = new HashMap<>();
                     dataMap.put("deviceId",deviceInfo.getId());
                     dataMap.put("deviceAliasName",deviceInfo.getAliasName());
-                    dataMap.put("persoName",personInfo.getName());
+                    dataMap.put("personName",personInfo.getName());
                     LapiResult lapiResult = new LapiResult();
-                    lapiResult.setMsg("绑定成功");
-                    lapiResult.setSuccess(true);
-                    lapiResult.setData(dataMap);
-                    lapiResultList.add(lapiResult);
+                    if (success){
+                        lapiResult.setMsg("绑定成功");
+                        lapiResult.setSuccess(true);
+                        lapiResult.setData(dataMap);
+                        lapiResultList.add(lapiResult);
+                    }else {
+                        lapiResult.setMsg("绑定失败");
+                        lapiResult.setSuccess(false);
+                        lapiResult.setData(dataMap);
+                        lapiResultList.add(lapiResult);
+                    }
+
                 }
             } catch (Exception e) {
                 log.error(e.getMessage());
                 HashMap<String,Object> dataMap = new HashMap<>();
                 dataMap.put("deviceId",deviceInfo.getId());
                 dataMap.put("deviceAliasName",deviceInfo.getAliasName());
-                dataMap.put("persoName",personInfo.getName());
+                dataMap.put("personName",personInfo.getName());
                 LapiResult lapiResult = new LapiResult();
                 lapiResult.setSuccess(false);
-                lapiResult.setMsg(e.getMessage());
+                lapiResult.setMsg(e.getMessage().contains("timed out")?"设备连接超时":e.getMessage());
                 lapiResult.setData(dataMap);
                 lapiResultList.add(lapiResult);
             }
@@ -168,7 +181,7 @@ public class LapiServiceImpl implements ILapiService {
     }
 
     @Override
-    public List<LapiMsgResult> addPersonForDeviceIds(Long id, String deviceIds) throws Exception {
+    public List<LapiResult> addPersonForDeviceIds(Long id, String deviceIds) throws Exception {
         if (StringUtils.isBlank(deviceIds)){
             throw new Exception("设备为空");
         }
@@ -177,7 +190,7 @@ public class LapiServiceImpl implements ILapiService {
         String base64Data = OSSUtil.downloadToBase64(personInfo.getFaceImageUrl());
 
         List<String> deviceIdList = Arrays.asList(deviceIds.split(","));
-        List<LapiMsgResult> lapiMsgResults = new ArrayList<>();
+        List<LapiResult> lapiResultList = new ArrayList<>();
 
             for (String deviceId : deviceIdList) {
                 DeviceInfo deviceInfo = deviceInfoService.get(deviceId);
@@ -207,7 +220,9 @@ public class LapiServiceImpl implements ILapiService {
                     map3.put("FaceID", personInfo.getId());
                     map3.put("Name", personInfo.getId() + ".jpg");
 
-                    map3.put("Size", base64Data.length());
+                    //照片base64长度
+                    Integer imageSize = base64Data.length();
+                    map3.put("Size", imageSize);
                     map3.put("Data", base64Data);
                     List listMap3 = new ArrayList();
                     listMap3.add(map3);
@@ -216,7 +231,10 @@ public class LapiServiceImpl implements ILapiService {
                     listMap1.add(map1);
                     map.put("PersonInfoList", listMap1);
 
-                    if (base64Data.length() > 512 * 1024 || base64Data.length() < 10 * 1024) {
+                    //照片字节大小
+                    Integer fileSize = imageSize - (imageSize/8)*2;
+
+                    if (fileSize > 512 * 1024 || fileSize < 10 * 1024) {
                         throw new Exception("人员照片大小限定为10k~512k");
                     }
                     //获取人员人脸库id
@@ -226,22 +244,39 @@ 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);
+                        Boolean success = isSuccessAddPerson(personInfo,deviceInfo,faceDbId);
+                        HashMap<String,Object> dataMap = new HashMap<>();
+                        dataMap.put("deviceId",deviceInfo.getId());
+                        dataMap.put("deviceAliasName",deviceInfo.getAliasName());
+                        dataMap.put("personName",personInfo.getName());
+                        LapiResult lapiResult = new LapiResult();
+                        if (success){
+                            lapiResult.setMsg("绑定成功");
+                            lapiResult.setSuccess(true);
+                            lapiResult.setData(dataMap);
+                            lapiResultList.add(lapiResult);
+                        }else {
+                            lapiResult.setMsg("绑定失败");
+                            lapiResult.setSuccess(false);
+                            lapiResult.setData(dataMap);
+                            lapiResultList.add(lapiResult);
+                        }
+
+
                     }
 
 
                 }catch (Exception e){
-                    log.error(e.getMessage(),e);
-                    LapiMsgResult lapiMsgResult = new LapiMsgResult();
-                    lapiMsgResult.setAliasName(deviceInfo.getAliasName());
-                    lapiMsgResult.setMsg(e.getMessage());
-                    lapiMsgResult.setPersonName("");
-                    lapiMsgResult.setSuccess(false);
-                    lapiMsgResults.add(lapiMsgResult);
+                    log.error(e.getMessage());
+                    HashMap<String,Object> dataMap = new HashMap<>();
+                    dataMap.put("deviceId",deviceInfo.getId());
+                    dataMap.put("deviceAliasName",deviceInfo.getAliasName());
+                    dataMap.put("personName",personInfo.getName());
+                    LapiResult lapiResult = new LapiResult();
+                    lapiResult.setSuccess(false);
+                    lapiResult.setMsg(e.getMessage().contains("timed out")?"设备连接超时":e.getMessage());
+                    lapiResult.setData(dataMap);
+                    lapiResultList.add(lapiResult);
                 }
 
 
@@ -249,7 +284,7 @@ public class LapiServiceImpl implements ILapiService {
 
 
 
-        return lapiMsgResults;
+        return lapiResultList;
     }
 
     @Override
@@ -324,7 +359,7 @@ public class LapiServiceImpl implements ILapiService {
     @Override
     public List<LapiMsgResult> deletePerson(Long id) throws Exception {
 
-        PersonInfo personInfo = personInfoService.get(id);
+        PersonInfo personInfo = personInfoService.getIgnoreDelFlag(id);
         if (personInfo == null) {
             throw new Exception("人员不存在");
         }
@@ -384,7 +419,7 @@ public class LapiServiceImpl implements ILapiService {
         if (StringUtils.isBlank(deviceIds)) {
             throw new Exception("相关设备不能为空");
         }
-        PersonInfo personInfo = personInfoService.get(id);
+        PersonInfo personInfo = personInfoService.getIgnoreDelFlag(id);
         if (personInfo == null) {
             throw new Exception("人员信息不存在");
         }
@@ -655,5 +690,35 @@ public class LapiServiceImpl implements ILapiService {
         return lapiResultList;
     }
 
+    @Override
+    public Boolean isSuccessAddPerson(PersonInfo personInfo,DeviceInfo deviceInfo,String faceDbId) {
+        HashMap map = new HashMap();
+        map.put("Num", 1);
+        map.put("Limit",3);
+        map.put("Offset",0);
+        List list = new ArrayList();
+        HashMap map1 = new HashMap();
+        map1.put("QryType", 27);
+        map1.put("QryCondition", 0);
+        map1.put("QryData", personInfo.getId().toString());
+        list.add(map1);
+        map.put("QueryInfos", list);
+        try{
+            JSONObject jsonObject = LApiUtil.PostRequest(deviceInfo.getIpAddress() + ":" + deviceInfo.getPort() + LApiConstant.ADDPERSON +faceDbId +"/People/Info", map);
+            JSONObject dataJson = jsonObject.getJSONObject("Response");
+            JSONObject response = LApiUtil.getResponse(dataJson);
+            Integer num = response.getInteger("Total");
+            if (num >0){
+                return true;
+            }
+        }catch (Exception e){
+
+            return false;
+        }
+
+
+        return false;
+    }
+
 
 }

+ 3 - 0
common/src/main/resources/mapper/base/DeviceInfo.xml

@@ -145,6 +145,9 @@ id_, header_,device_no,alias_name,address_,is_online,company_id,unlock_password,
 	<select id="list" resultMap="DeviceInfoMap">
 		select * from base_device_info where del_flag=false
 	</select>
+	<select id="listOnline" resultMap="DeviceInfoMap">
+		select * from base_device_info where is_online=true and del_flag=false
+	</select>
 	<select id="findByDeviceIdList"  resultMap="DeviceInfoMap">
 		select * from base_device_info where del_flag=false and id_ in
 		<foreach item="item" collection="list"  open="(" separator="," close=")">

+ 17 - 4
common/src/main/resources/mapper/base/MessageNotice.xml

@@ -92,12 +92,20 @@ id_,title_,content_,sender_id,recipient_id,status_,del_flag,create_by,create_tim
 	</select>
 	<select id="search" parameterType="hashmap" resultMap="MessageNoticeMap">
 		<![CDATA[
-			select * from base_message_notice
+			select * from base_message_notice a
+			LEFT JOIN base_message_notice_company b ON a.id_ = b.notice_id
+			LEFT JOIN base_company_info c ON b.company_id = c.id_
 		]]>
 		<where>
-			and del_flag = false
+			and a.del_flag = false
 			<if test="searchParams.title != null">
-				and title_ like #{searchParams.title}
+				and a.title_ like #{searchParams.title}
+			</if>
+			<if test="searchParams.companyId != null">
+				and b.company_id = #{searchParams.companyId}
+			</if>
+			<if test="searchParams.companyCode != null">
+				and c.code_ like #{searchParams.companyCode}
 			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">
@@ -106,7 +114,9 @@ id_,title_,content_,sender_id,recipient_id,status_,del_flag,create_by,create_tim
 	</select>
 	<select id="searchShort" parameterType="hashmap" resultMap="MessageNoticeMap">
 		<![CDATA[
-			select a.id_,a.title_,a.create_time from base_message_notice a LEFT JOIN base_message_notice_company b ON a.id_ = b.notice_id
+			select a.id_,a.title_,a.create_time from base_message_notice a
+			LEFT JOIN base_message_notice_company b ON a.id_ = b.notice_id
+			LEFT JOIN base_company_info c ON b.company_id = c.id_
 		]]>
 		<where>
 			and a.del_flag = false
@@ -116,6 +126,9 @@ id_,title_,content_,sender_id,recipient_id,status_,del_flag,create_by,create_tim
 			<if test="searchParams.companyId != null">
 				and b.company_id like #{searchParams.companyId}
 			</if>
+			<if test="searchParams.companyCode != null">
+				and c.code_ like #{searchParams.companyCode}
+			</if>
 		</where>
 		<foreach item="sort" collection="sortList"  open="order by" separator=",">
 			${sort.name} ${sort.order}

+ 8 - 0
common/src/main/resources/mapper/base/PersonInfo.xml

@@ -277,4 +277,12 @@
         where a.del_flag = 0
         and b.code_ like #{code}
     </select>
+
+    <select id="getIgnoreDelFlag" parameterType="long" resultMap="PersonInfoMap">
+        select
+        a.*,b.name_ as company_name
+        from base_person_info a
+        left join base_company_info b on a.company_id = b.id_
+        where a.id_=#{0}  limit 1
+    </select>
 </mapper>

+ 29 - 5
lapi/src/main/java/com/jpsoft/smart/lapi/handler/PersonVerificationHandler.java

@@ -11,7 +11,11 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
+import sun.misc.BASE64Encoder;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -97,12 +101,32 @@ public class PersonVerificationHandler extends SimpleChannelInboundHandler<Perso
 
 
 
+    }
 
-
-
-
-
-
+    public static void main(String[] args) {
+        String imgStr = "";
+        try {
+
+            File file = new File("C:\\Users\\Administrator\\Desktop\\异常照片\\3.jpg");
+            FileInputStream fis = new FileInputStream(file);
+            byte[] buffer = new byte[(int) file.length()];
+            int offset = 0;
+            int numRead = 0;
+            while (offset < buffer.length && (numRead = fis.read(buffer, offset, buffer.length - offset)) >= 0) {
+                offset += numRead;
+            }
+
+            if (offset != buffer.length) {
+                throw new IOException("Could not completely read file "
+                        + file.getName());
+            }
+            fis.close();
+            BASE64Encoder encoder = new BASE64Encoder();
+            imgStr = encoder.encode(buffer);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        System.out.print(imgStr.length());
 
     }
 }

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

@@ -1,14 +1,18 @@
 package com.jpsoft.smart.modules.base.controller;
 
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.jpsoft.smart.modules.base.entity.MessageNoticeCompany;
 import com.jpsoft.smart.modules.base.entity.PersonCompany;
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
 import com.jpsoft.smart.modules.base.service.MessageNoticeCompanyService;
 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.MessageNotice;
 import com.jpsoft.smart.modules.base.service.MessageNoticeService;
+import com.jpsoft.smart.modules.sys.entity.User;
+import com.jpsoft.smart.modules.sys.service.UserService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
@@ -33,6 +37,13 @@ public class MessageNoticeController {
     @Autowired
     private MessageNoticeCompanyService messageNoticeCompanyService;
 
+    @Autowired
+    private CompanyInfoService companyInfoService;
+
+    @Autowired
+    private UserService userService;
+
+
     @ApiOperation(value="创建空记录")
     @GetMapping("create")
     public MessageResult<MessageNotice> create(){
@@ -245,24 +256,43 @@ public class MessageNoticeController {
     @RequestMapping(value = "pageList",method = RequestMethod.POST)
     public MessageResult<Map> pageList(
             String title,
+            String companyId,
+            String companyCode,
             @RequestParam(value="pageIndex",defaultValue="1") int pageIndex,
             @RequestParam(value="pageSize",defaultValue="20") int pageSize,
             @RequestAttribute String subject){
 
         //当前用户ID
         System.out.println(subject);
+        //当前用户ID
+        User user = userService.get(subject);
+
+        CompanyInfo companyInfo = companyInfoService.get(user.getCompanyId());
 
         MessageResult<Map> msgResult = new MessageResult<>();
 
         Map<String,Object> searchParams = new HashMap<>();
 
         List<Sort> sortList = new ArrayList<>();
-        sortList.add(new Sort("create_time","desc"));
+        sortList.add(new Sort("a.create_time","desc"));
 
         if (StringUtils.isNotEmpty(title)) {
             searchParams.put("title","%" + title + "%");
         }
 
+        if (StringUtils.isNotEmpty(title)) {
+            searchParams.put("title","%" + title + "%");
+        }
+
+        if (StringUtils.isEmpty(companyCode)){
+            if (!userService.hasRole(subject,"SYSADMIN")) {
+                searchParams.put("companyCode", companyInfo.getCode() + "%");
+            }
+        }
+        else{
+            searchParams.put("companyCode", companyCode + "%");
+        }
+
         Page<MessageNotice> page = messageNoticeService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
 
         msgResult.setResult(true);

+ 136 - 41
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonDeviceRelationController.java

@@ -93,13 +93,17 @@ public class PersonDeviceRelationController {
 
             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());
+                PersonInfo personInfo = personInfoService.get(personDeviceRelation.getPersonId());
+                //如果人员照片不为空
+                if(StringUtils.isNotEmpty(personInfo.getFaceImageUrl())){
+                    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());
+                    }
                     }
                 }
                 msgResult.setResult(true);
@@ -158,37 +162,40 @@ public class PersonDeviceRelationController {
                 //往设备库传输人脸信息
                 //批量操作
                 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();
+                //往设备库传输人脸信息
+                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();
+                            }
+                            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++;
                         }
-                        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 ++;
                     }
                 }
 //
@@ -266,18 +273,27 @@ public class PersonDeviceRelationController {
                         affectCount += personDeviceRelationService.insert(item);
                         //往设备库传输人脸信息
                         //批量操作
-                        List<LapiMsgResult> lapiResults = lapiService.addPersonForDeviceIds(personId,deviceId);
+
+                        PersonInfo personInfo = personInfoService.get(personId);
+                        //如果人员照片为空
+                        if(StringUtils.isEmpty(personInfo.getFaceImageUrl())){
+                            continue;
+                        }
+
+                        List<LapiResult> lapiResults = lapiService.addPersonForDeviceIds(personId,deviceId);
 
                         for (int i = 0; i < lapiResults.size(); i++) {
-                            LapiMsgResult lapiMsgResult = lapiResults.get(i);
+                            LapiResult lapiMsgResult = lapiResults.get(i);
                             if (lapiMsgResult.isSuccess()) {
                                 msgResult.setResult(true);
                             }else{
+
+                                Map resultMap = (Map) lapiMsgResult.getData();
                                 HSSFRow row = sheet.createRow(sheet.getLastRowNum() + 1);
                                 HSSFCell cell1 = row.createCell(0);
-                                cell1.setCellValue(lapiMsgResult.getPersonName());
+                                cell1.setCellValue(resultMap.get("personName").toString());
                                 HSSFCell cell2 = row.createCell(1);
-                                cell2.setCellValue(lapiMsgResult.getAliasName());
+                                cell2.setCellValue(resultMap.get("deviceAliasName").toString());
                                 HSSFCell cell3 = row.createCell(2);
                                 cell3.setCellValue("添加失败:" + lapiMsgResult.getMsg());
                                 HSSFCell cell4 = row.createCell(3);
@@ -327,6 +343,63 @@ public class PersonDeviceRelationController {
         return msgResult;
     }
 
+    @ApiOperation(value="多个人员与设备批量解除绑定")
+    @PostMapping("batchUnBindPerson")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "persons",value = "人员ID(多个人员)", required = true,paramType = "query"),
+            @ApiImplicitParam(name = "deviceId",value = "设备ID", required = true, paramType = "query")
+    })
+    public MessageResult<Integer> batchUnBindPerson(String persons,String deviceId,@RequestAttribute String subject){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+        int affectCount = 0;
+
+        try {
+            if(StringUtil.isNotEmpty(persons)){
+
+                String[] personArray = persons.split(",");
+
+                for (String strPersonId:personArray) {
+
+                    long personId = Long.parseLong(strPersonId);
+
+                    PersonDeviceRelation item = personDeviceRelationService.findByDeviceIdAndPersonId(deviceId,personId);
+
+                    if(item != null) {
+                        item.setDelFlag(true);
+                        item.setUpdateBy(subject);
+                        item.setUpdateTime(new Date());
+                        affectCount += personDeviceRelationService.update(item);
+                        //删除设备上的信息
+                        new Thread(()->{
+                            try {
+                                lapiService.deleteDevicePerson(personId,deviceId);
+                            }
+                            catch (Exception ex){
+                                logger.error(ex.getMessage(),ex);
+                            }
+                        }).start();
+                    }
+                }
+            }
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(affectCount);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("解绑失败!");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
     @ApiOperation(value="获取人员和设备绑定信息")
     @GetMapping("edit/{id}")
     public MessageResult<PersonDeviceRelation> edit(@PathVariable("id") String id){
@@ -398,6 +471,16 @@ public class PersonDeviceRelationController {
             int affectCount = personDeviceRelationService.update(personDeviceRelation);
 
             if (affectCount > 0) {
+                //删除设备上的信息
+                new Thread(()->{
+                    try {
+                        lapiService.deleteDevicePerson(personDeviceRelation.getPersonId(),personDeviceRelation.getDeviceId());
+                    }
+                    catch (Exception ex){
+                        logger.error(ex.getMessage(),ex);
+                    }
+                }).start();
+
                 msgResult.setResult(true);
                 msgResult.setData(affectCount);
             } else {
@@ -435,6 +518,7 @@ public class PersonDeviceRelationController {
                 affectCount = personDeviceRelationService.update(personDeviceRelation);
             }
 
+
             if (affectCount > 0) {
                 msgResult.setResult(true);
                 msgResult.setData(affectCount);
@@ -549,6 +633,17 @@ public class PersonDeviceRelationController {
                 affectCount += personDeviceRelationService.update(personDeviceRelation);
             }
 
+
+            //删除所有设备上的信息
+            new Thread(()->{
+                try {
+                    lapiService.deletePerson(personId);
+                }
+                catch (Exception ex){
+                    logger.error(ex.getMessage(),ex);
+                }
+            }).start();
+
             if (affectCount > 0) {
                 msgResult.setResult(true);
                 msgResult.setData(affectCount);

+ 10 - 0
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/MessageNoticeApiController.java

@@ -1,9 +1,11 @@
 package com.jpsoft.smart.modules.mobile.controller;
 
 import com.github.pagehelper.Page;
+import com.jpsoft.smart.modules.base.entity.CompanyInfo;
 import com.jpsoft.smart.modules.base.entity.MessageNotice;
 import com.jpsoft.smart.modules.base.entity.MessageNoticeCompany;
 import com.jpsoft.smart.modules.base.entity.PersonInfo;
+import com.jpsoft.smart.modules.base.service.CompanyInfoService;
 import com.jpsoft.smart.modules.base.service.MessageNoticeService;
 import com.jpsoft.smart.modules.base.service.PersonInfoService;
 import com.jpsoft.smart.modules.common.dto.MessageResult;
@@ -31,6 +33,9 @@ public class MessageNoticeApiController {
     private MessageNoticeService messageNoticeService;
     @Autowired
     private PersonInfoService personInfoService;
+    @Autowired
+    private CompanyInfoService companyService;
+
 
     @ApiOperation(value="获取信息")
     @RequestMapping(value = "detail",method = RequestMethod.POST)
@@ -114,6 +119,11 @@ public class MessageNoticeApiController {
         List<Sort> sortList = new ArrayList<>();
         sortList.add(new Sort("create_time","desc"));
 
+        //获取公司CODE
+        CompanyInfo company = companyService.get(personInfo.getCompanyId());
+        //包含下级公司
+        searchParams.put("companyCode", company.getCode() + "%");
+
         Page<MessageNotice> page = messageNoticeService.pageSearchShort(searchParams,pageIndex,pageSize,true,sortList);
 
         msgResult.setResult(true);

+ 24 - 19
web/src/main/java/com/jpsoft/smart/schduled/HeartbeatDetectionTask.java

@@ -26,34 +26,39 @@ public class HeartbeatDetectionTask {
     private ILapiService lapiService;
 
     //每2分钟执行一次
-    @Scheduled(cron="0 0/1 * * * ?")
+    @Scheduled(cron = "0 0/2 * * * ?")
     public void run() {
 
-        List<DeviceInfo> deviceInfoList = deviceInfoService.list();
-
-        for (DeviceInfo deviceInfo : deviceInfoList){
-            if (deviceInfo.getIsOnline() && deviceInfo.getHeartbeatUpdateTime() != null){
-                Long heartbeatUpdateTime = deviceInfo.getHeartbeatUpdateTime().getTime();
-                if (new Date().getTime() - heartbeatUpdateTime >2*60*1000){
-                    deviceInfo.setIsOnline(false);
-                    try{
-                        Boolean isKeepAlive = lapiService.keepAlive(deviceInfo.getId());
-                        if (isKeepAlive){
-                            deviceInfo.setAbnormalReason("设备可正常访问,但无心跳返回,请查看设备服务器配置");
-                        }else {
+        log.warn("设备在线定时任务启动");
+        List<DeviceInfo> deviceInfoList = deviceInfoService.listOnline();
+
+        if (deviceInfoList.size() > 0) {
+
+            for (DeviceInfo deviceInfo : deviceInfoList) {
+                if (deviceInfo.getHeartbeatUpdateTime() != null) {
+                    Long heartbeatUpdateTime = deviceInfo.getHeartbeatUpdateTime().getTime();
+                    if (new Date().getTime() - heartbeatUpdateTime > 2 * 60 * 1000) {
+                        deviceInfo.setIsOnline(false);
+                        try {
+                            Boolean isKeepAlive = lapiService.keepAlive(deviceInfo.getId());
+                            if (isKeepAlive) {
+                                deviceInfo.setAbnormalReason("设备可正常访问,但无心跳返回,请查看设备服务器配置");
+                            } else {
+                                deviceInfo.setAbnormalReason("设备离线");
+                            }
+                            deviceInfoService.update(deviceInfo);
+                        } catch (Exception e) {
                             deviceInfo.setAbnormalReason("设备离线");
+                            deviceInfoService.update(deviceInfo);
                         }
-                        deviceInfoService.update(deviceInfo);
-                    }catch (Exception e){
-                        deviceInfo.setAbnormalReason("设备离线");
-                        deviceInfoService.update(deviceInfo);
-                    }
 
+                    }
                 }
             }
+
         }
 
+    }
 
-        }
 
 }

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

@@ -175,6 +175,7 @@ public class LApiTest {
             List<String> idList = Arrays.asList(ids.split(","));
 
             List<WarningPusher> list = warningPusherDAO.findByIdList(idList);
+
             System.out.println(list);
         } catch (Exception e) {
             e.printStackTrace();
@@ -183,5 +184,17 @@ public class LApiTest {
 
     }
 
+    @Test
+    public void testIsSuccessAddPerson(){
+        try {
+
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            String message = e.getMessage();
+        }
+
+    }
+
 
 }