|
@@ -0,0 +1,79 @@
|
|
|
+package com.jpsoft.smart.schduled;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateField;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.github.pagehelper.Page;
|
|
|
+import com.jpsoft.smart.modules.base.entity.DeviceInfo;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonDeviceRelation;
|
|
|
+import com.jpsoft.smart.modules.base.entity.PersonInfo;
|
|
|
+import com.jpsoft.smart.modules.base.service.DeviceInfoService;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonDeviceRelationService;
|
|
|
+import com.jpsoft.smart.modules.base.service.PersonInfoService;
|
|
|
+import com.jpsoft.smart.modules.common.dto.Sort;
|
|
|
+import com.jpsoft.smart.modules.lapi.service.ILapiService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author 墨鱼_mo
|
|
|
+ * @date 2020-4-8 14:27
|
|
|
+ */
|
|
|
+
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+@Transactional
|
|
|
+public class UpdatePersonDeviceBoundTask {
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonDeviceRelationService personDeviceRelationService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ILapiService lapiService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DeviceInfoService deviceInfoService;
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0/10 * * * ?")
|
|
|
+ public void run() {
|
|
|
+ log.warn("人员设备绑定关系更新定时任务开始");
|
|
|
+
|
|
|
+
|
|
|
+ List<PersonDeviceRelation> personDeviceRelationList = personDeviceRelationService.findByIsBoundAndUpdateTime(DateUtil.offset(new Date(),DateField.DAY_OF_MONTH, -1),500);
|
|
|
+ if (personDeviceRelationList.size()>0){
|
|
|
+ for (PersonDeviceRelation personDeviceRelation : personDeviceRelationList){
|
|
|
+ try{
|
|
|
+ lapiService.keepAlive(personDeviceRelation.getDeviceId());
|
|
|
+ PersonInfo personInfo = personInfoService.get(personDeviceRelation.getPersonId());
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.get(personDeviceRelation.getDeviceId());
|
|
|
+ String faceDbId = lapiService.getFaceDbId(deviceInfo,personInfo.getCompanyName());
|
|
|
+ Boolean isSuccessAdd = lapiService.isSuccessAddPerson(personInfo,deviceInfo,faceDbId);
|
|
|
+ if (isSuccessAdd){
|
|
|
+ personDeviceRelation.setIsBound(true);
|
|
|
+ personDeviceRelation.setUpdateTime(new Date());
|
|
|
+ }else {
|
|
|
+ personDeviceRelation.setIsBound(false);
|
|
|
+ personDeviceRelation.setUpdateTime(new Date());
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+ personDeviceRelation.setUpdateTime(new Date());
|
|
|
+ personDeviceRelation.setIsBound(null);
|
|
|
+ }
|
|
|
+
|
|
|
+ personDeviceRelationService.update(personDeviceRelation);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|