Browse Source

健康码授权

cuimengchao 3 years ago
parent
commit
13f20cfc7f

+ 19 - 17
src/main/java/com/yx/face/controller/TBFaceController.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.google.common.collect.Maps;
 import com.yx.face.boot.core.SnowflakeIdWorker;
 import com.yx.face.boot.uitls.JsonUtils;
+import com.yx.face.boot.uitls.RedisUtil;
 import com.yx.face.service.FaceTBService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -15,6 +16,7 @@ import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.persistence.Id;
 import javax.servlet.http.HttpServletRequest;
 import java.io.BufferedInputStream;
 import java.io.IOException;
@@ -150,23 +152,23 @@ public class TBFaceController {
     @ApiOperation("获取设备人员列表")
     @PostMapping("pushUsersOnline")
     public Map<String, Object> pushUsersOnline(HttpServletRequest request) {
-        List<Map<String, String>> list = new ArrayList<>();
-        try {
-            JSONObject paramJson = getParamJson(request);
-            JSONArray data = paramJson.getJSONArray("data");
-            System.out.println(data);
-            for (Object datum : data) {
-                Map<String, String> map = new HashMap<>();
-                map.put(JSONObject.parseObject(datum.toString()).getString("cardid"), paramJson.getString("SN"));
-                map.put("SN", paramJson.getString("SN"));
-                list.add(map);
-            }
-            if (!list.isEmpty()){
-                faceTBService.pushUsersOnline(list);
-            }
-        } catch (Exception e) {
-            log.info("推送刷脸刷卡记录 异常={}", e.getMessage());
-        }
+//        List<Map<String, String>> list = new ArrayList<>();
+//        try {
+//            JSONObject paramJson = getParamJson(request);
+//            JSONArray data = paramJson.getJSONArray("data");
+//            for (Object datum : data) {
+//                Map<String, String> map = new HashMap<>();
+//                map.put(JSONObject.parseObject(datum.toString()).getString("cardid"), paramJson.getString("SN"));
+//                map.put("SN", paramJson.getString("SN"));
+//                map.put("taskId", paramJson.getString("taskId"));
+//                    list.add(map);
+//            }
+//            if (!list.isEmpty()){
+//                faceTBService.pushUsersOnline(list);
+//            }
+//        } catch (Exception e) {
+//            log.info("推送刷脸刷卡记录 异常={}", e.getMessage());
+//        }
         Map<String, Object> result = Maps.newHashMapWithExpectedSize(1);
         result.put("errCode", "00");
         return result;

+ 16 - 0
src/main/java/com/yx/face/service/TbDeviceWhiteListService.java

@@ -0,0 +1,16 @@
+package com.yx.face.service;
+
+/**
+ * @ProjectName: face-server
+ * @Package: com.yx.face.service
+ * @ClassName: TbDeviceWhiteListService
+ * @Author: 崔哥
+ * @Description:
+ * @Date: 2021/12/7 15:34
+ * @Version: 1.0
+ */
+public interface TbDeviceWhiteListService {
+
+    Boolean addOrDeleteTbDeviceWhiteList(String sn, String type);
+
+}

+ 21 - 5
src/main/java/com/yx/face/service/impl/FaceServiceImpl.java

@@ -21,6 +21,7 @@ import com.yx.face.model.search.FaceServerLogSearch;
 import com.yx.face.model.vo.*;
 import com.yx.face.service.AdminService;
 import com.yx.face.service.FaceService;
+import com.yx.face.service.TbDeviceWhiteListService;
 import com.yx.face.service.feign.TBDeviceFaceService;
 import lombok.SneakyThrows;
 import lombok.extern.slf4j.Slf4j;
@@ -68,29 +69,40 @@ public class FaceServiceImpl implements FaceService {
     private FaceDeviceLogoDao faceDeviceLogoDao;
     @Resource
     private SystemConfigDao systemConfigDao;
-
+    @Resource
+    private TbDeviceWhiteListService tbDeviceWhiteListService;
     @Override
     public Boolean authFaceDevice(Integer deviceId) {
-        if (faceDeviceDao.selectByPrimaryKey(deviceId) == null) {
+        FaceDevice faceDevice = faceDeviceDao.selectByPrimaryKey(deviceId);
+        if (faceDevice == null) {
             throw new ServiceException("无此设备");
         }
         FaceDevice device = new FaceDevice();
         device.setId(deviceId);
         device.setAuth(1);
         device.setUpdateTime(new Date());
-        return faceDeviceDao.updateByPrimaryKeySelective(device) == 1;
+        Boolean aBoolean = tbDeviceWhiteListService.addOrDeleteTbDeviceWhiteList(faceDevice.getSn(), "00");
+        if (aBoolean) {
+            return faceDeviceDao.updateByPrimaryKeySelective(device) == 1;
+        }
+        return aBoolean;
     }
 
     @Override
     public Boolean stopFaceDevice(Integer deviceId) {
-        if (faceDeviceDao.selectByPrimaryKey(deviceId) == null) {
+        FaceDevice faceDevice = faceDeviceDao.selectByPrimaryKey(deviceId);
+        if (faceDevice == null) {
             throw new ServiceException("无此设备");
         }
         FaceDevice device = new FaceDevice();
         device.setId(deviceId);
         device.setAuth(0);
         device.setUpdateTime(new Date());
-        return faceDeviceDao.updateByPrimaryKeySelective(device) == 1;
+        Boolean aBoolean = tbDeviceWhiteListService.addOrDeleteTbDeviceWhiteList(faceDevice.getSn(), "01");
+        if (aBoolean) {
+            return faceDeviceDao.updateByPrimaryKeySelective(device) == 1;
+        }
+        return aBoolean;
     }
 
     @Override
@@ -159,6 +171,10 @@ public class FaceServiceImpl implements FaceService {
         if (device == null) {
             throw new ServiceException("无此数据");
         }
+        Boolean aBoolean = tbDeviceWhiteListService.addOrDeleteTbDeviceWhiteList(device.getSn(), "01");
+        if (!aBoolean) {
+            throw new ServiceException("删除失败");
+        }
         FaceRequestLog requestLog = new FaceRequestLog();
         requestLog.setName("删除人员人脸信息");
         requestLog.setContext("/delUser");

+ 44 - 34
src/main/java/com/yx/face/service/impl/FaceTBServiceImpl.java

@@ -746,40 +746,50 @@ public class FaceTBServiceImpl implements FaceTBService {
 
     @Override
     public void pushUsersOnline(List<Map<String, String>> list) {
-        //获取员工通道
-        List<FaceDevice> faceDeviceList = faceDeviceDao.selectTypeFaceDev(2);
-        if (faceDeviceList.isEmpty()) {
-            log.info("设备为空===========");
-            return;
-        }
-        //获取员工列表
-        List<SystemLongTermDocumentsVO> systemLongTermDocumentsDaoList = systemLongTermDocumentsDao.getList(42, null);
-        if (faceDeviceList.isEmpty()) {
-            log.info("获取员工列表===========");
-            return;
-        }
-        List<SystemLongTermDocumentsVO> mapList = new ArrayList<>();
-        for (SystemLongTermDocumentsVO vo : systemLongTermDocumentsDaoList) {
-            for (Map<String, String> map : list) {
-                String s = map.get(vo.getIdNumber());
-                if (StringUtils.hasText(s)) {
-                    mapList.add(vo);
-                    break;
-                }
-            }
-        }
-        //取差集
-        List<SystemLongTermDocumentsVO> differenceList = systemLongTermDocumentsDaoList.stream()
-                .filter(item -> !mapList.stream()
-                        .map(e -> e.getIdNumber())
-                        .collect(Collectors.toList())
-                        .contains(item.getIdNumber()))
-                .collect(Collectors.toList());
-        String sn = list.get(0).get("SN");
-        FaceDevice faceDeviceBySn = faceDeviceDao.getFaceDeviceBySn(sn);
-        for (SystemLongTermDocumentsVO vo : differenceList) {
-            faceDeviceList(faceDeviceBySn, vo);
-        }
+//        for (Map<String, String> map : list) {
+//            String taskId = (String) redisUtil.get(map.get("taskId"));
+//            if (StringUtils)
+//            redisUtil.get()
+//            redisUtil.get(map.get("taskId"));
+//        }
+//
+//
+//
+//
+//        //获取员工通道
+//        List<FaceDevice> faceDeviceList = faceDeviceDao.selectTypeFaceDev(2);
+//        if (faceDeviceList.isEmpty()) {
+//            log.info("设备为空===========");
+//            return;
+//        }
+//        //获取员工列表
+//        List<SystemLongTermDocumentsVO> systemLongTermDocumentsDaoList = systemLongTermDocumentsDao.getList(42, null);
+//        if (faceDeviceList.isEmpty()) {
+//            log.info("获取员工列表===========");
+//            return;
+//        }
+//        List<SystemLongTermDocumentsVO> mapList = new ArrayList<>();
+//        for (SystemLongTermDocumentsVO vo : systemLongTermDocumentsDaoList) {
+//            for (Map<String, String> map : list) {
+//                String s = map.get(vo.getIdNumber());
+//                if (StringUtils.hasText(s)) {
+//                    mapList.add(vo);
+//                    break;
+//                }
+//            }
+//        }
+//        //取差集
+//        List<SystemLongTermDocumentsVO> differenceList = systemLongTermDocumentsDaoList.stream()
+//                .filter(item -> !mapList.stream()
+//                        .map(e -> e.getIdNumber())
+//                        .collect(Collectors.toList())
+//                        .contains(item.getIdNumber()))
+//                .collect(Collectors.toList());
+//        String sn = list.get(0).get("SN");
+//        FaceDevice faceDeviceBySn = faceDeviceDao.getFaceDeviceBySn(sn);
+//        for (SystemLongTermDocumentsVO vo : differenceList) {
+//            faceDeviceList(faceDeviceBySn, vo);
+//        }
     }
 
 

+ 78 - 0
src/main/java/com/yx/face/service/impl/TbDeviceWhiteListServiceImpl.java

@@ -0,0 +1,78 @@
+package com.yx.face.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.yx.face.boot.uitls.OkHttpUtils;
+import com.yx.face.service.TbDeviceWhiteListService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+/**
+ * @ProjectName: face-server
+ * @Package: com.yx.face.service
+ * @ClassName: TbDeviceWhiteListService
+ * @Author: 崔哥
+ * @Description:
+ * @Date: 2021/12/7 15:34
+ * @Version: 1.0
+ */
+@Slf4j
+@Service
+public class TbDeviceWhiteListServiceImpl implements TbDeviceWhiteListService {
+
+    @Value("${tb.jkm.device.white.list.url}")
+    private String tbDeviceWhiteListUrl;
+
+
+    @Override
+    public Boolean addOrDeleteTbDeviceWhiteList(String sn, String type) {
+        JSONObject json = new JSONObject();
+        json.put("sn", sn);
+        OkHttpUtils sync = OkHttpUtils.builder().url(tbDeviceWhiteListUrl);
+        json.put("type", type);
+        String addOrDelete = "";
+        //type	操作类型	是	00:新增;01:删除;10:查询
+        if (StringUtils.equals("00", type)) {
+            //status	int	Fou	白名单状态00:禁用;01:启用
+            json.put("status", "01");
+            log.info("添加 {}", json.toJSONString());
+            addOrDelete = sync.localPost(json.toJSONString()).sync();
+        }
+        if (StringUtils.equals("01", type)) {
+            json.put("status", "00");
+            log.info("删除白名单 {}", json.toJSONString());
+            addOrDelete = sync.localPost(json.toJSONString()).sync();
+        }
+        if (StringUtils.isBlank(addOrDelete)) {
+            log.info("天波健康码启用停用接口返回值为addOrDelete为空{}", sn, addOrDelete);
+            return true;
+        }
+        JSONObject addOrDeleteJsonObject = JSONObject.parseObject(addOrDelete);
+        log.info("返回值;{}", addOrDelete);
+        if (addOrDeleteJsonObject == null) {
+            return true;
+        }
+        Integer code = addOrDeleteJsonObject.getInteger("code");
+        if (code == null) {
+            return false;
+        }
+        if (code == 200) {
+            return true;
+        }
+        return false;
+    }
+
+    public static void main(String[] args) {
+        String s = selectDeviceWhiteList("111", "11");
+        System.out.println(s);
+    }
+
+    public static String selectDeviceWhiteList(String sn, String type) {
+        JSONObject json = new JSONObject();
+        json.put("sn", "611F010T00100124");
+        json.put("type", "10");
+        String sync = OkHttpUtils.builder().url("http://183.237.179.218:1891/Hanghui/deviceWhiteList").localPost(json.toJSONString()).sync();
+        return sync;
+    }
+}

+ 1 - 1
src/main/java/com/yx/face/service/impl/UserWhitelistServiceImpl.java

@@ -173,6 +173,7 @@ public class UserWhitelistServiceImpl implements UserWhitelistService {
             requestLog.setUsedTime(0L);
             requestLog.setUpdateTime(now);
             requestLog.setCreateTime(now);
+            faceRequestLogDao.insertSelective(requestLog);
             params.put("taskId", requestLog.getId());
 //            try {
 //                result = tbDeviceFaceService.delUser(params);
@@ -200,7 +201,6 @@ public class UserWhitelistServiceImpl implements UserWhitelistService {
                     //异步下发三次
                     asyncTriggerRetryImpl.delUserRetry(params);
                 } else {
-                    faceRequestLogDao.insertSelective(requestLog);
                     faceTaskDao.updateFaceTaskStatus(sn, userIds);
                 }
                 log.info("删除结果={}", result);

+ 4 - 0
src/main/resources/application-prod.yml

@@ -106,6 +106,10 @@ file.upload.path: file/
 file.upload.path.relative: /file/**
 web.address: https://ldb-airport.hz-hanghui.com:9100/ldb-airport/
 
+##---------------------------------------健康码是否开启白名单地址------------------------------------------------------##
+
+tb.jkm.device.white.list.url: http://192.168.99.11:1821/Hanghui/deviceWhiteList
+
 
 ##``````````````````````````````````` 人脸服务 配置``````````````````````````````````````````````````````````````###
 face.service.tb: http://192.168.99.11:1820