liujie
2026-09-21 20051550f01227ecebbe0bf064e188dd242f58f2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/HikvisionAccessControlApi.java
@@ -33,6 +33,8 @@
    private static final String USER_INFO_SET_UP_PATH = "/ISAPI/AccessControl/UserInfo/SetUp?format=json";
    private static final String CARD_INFO_SET_UP_PATH = "/ISAPI/AccessControl/CardInfo/SetUp?format=json";
    private static final String FACE_DATA_RECORD_PATH = "/ISAPI/Intelligent/FDLib/FaceDataRecord?format=json";
    private static final String USER_INFO_DELETE_PATH = "/ISAPI/AccessControl/UserInfo/Delete?format=json";
    private static final String CARD_INFO_DELETE_PATH = "/ISAPI/AccessControl/CardInfo/Delete?format=json";
    private static final MediaType JSON_MEDIA_TYPE = MediaType.parse("application/json; charset=utf-8");
    private static final MediaType JPEG_MEDIA_TYPE = MediaType.parse("image/jpeg");
    private static final MediaType PNG_MEDIA_TYPE = MediaType.parse("image/png");
@@ -66,6 +68,25 @@
            result.setFace(face);
            ensureSuccess(face, "绑定员工人脸失败");
        }
        return result;
    }
    /**
     * 删除门禁人员,并尽量清理绑定卡和人脸凭据。
     */
    public static DeleteResult deleteEmployee(DeviceConfig device, EmployeeCredential employee) throws IOException {
        Objects.requireNonNull(employee, "employee");
        requireText(employee.getEmployeeNo(), "employeeNo");
        DeleteResult result = new DeleteResult();
        if (isNotBlank(employee.getCardNo())) {
            result.setCard(deleteCard(device, employee.getCardNo()));
        }
        result.setFace(deleteFace(device, employee.getEmployeeNo()));
        HikvisionResult userInfo = deleteUserInfo(device, employee.getEmployeeNo());
        result.setUserInfo(userInfo);
        ensureSuccess(userInfo, "delete user info failed");
        return result;
    }
@@ -152,6 +173,53 @@
    }
    /**
     * 删除设备端人员基础信息。
     */
    public static HikvisionResult deleteUserInfo(DeviceConfig device, String employeeNo) throws IOException {
        requireDevice(device);
        requireText(employeeNo, "employeeNo");
        JSONObject employeeNoItem = new JSONObject(true);
        employeeNoItem.put("employeeNo", employeeNo);
        JSONObject userInfoDelCond = new JSONObject(true);
        userInfoDelCond.put("EmployeeNoList", singletonList(employeeNoItem));
        JSONObject body = new JSONObject(true);
        body.put("UserInfoDelCond", userInfoDelCond);
        return executeJson(device, "DELETE", USER_INFO_DELETE_PATH, body);
    }
    public static HikvisionResult deleteCard(DeviceConfig device, String cardNo) throws IOException {
        requireDevice(device);
        requireText(cardNo, "cardNo");
        JSONObject cardNoItem = new JSONObject(true);
        cardNoItem.put("cardNo", cardNo);
        JSONObject cardInfoDelCond = new JSONObject(true);
        cardInfoDelCond.put("CardNoList", singletonList(cardNoItem));
        JSONObject body = new JSONObject(true);
        body.put("CardInfoDelCond", cardInfoDelCond);
        return executeJson(device, "DELETE", CARD_INFO_DELETE_PATH, body);
    }
    public static HikvisionResult deleteFace(DeviceConfig device, String employeeNo) throws IOException {
        requireDevice(device);
        requireText(employeeNo, "employeeNo");
        JSONObject faceData = new JSONObject(true);
        faceData.put("faceLibType", "blackFD");
        faceData.put("FDID", "1");
        faceData.put("FPID", employeeNo);
        JSONObject body = new JSONObject(true);
        body.put("FaceDataRecord", faceData);
        return executeJson(device, "DELETE", FACE_DATA_RECORD_PATH, body);
    }
    /**
     * 通过图片 URL 下载人脸并绑定到员工。
     */
    public static HikvisionResult bindFaceByUrl(DeviceConfig device, String employeeNo, String faceImageUrl) throws IOException {
@@ -179,6 +247,8 @@
                .header("Accept", "application/json");
        if ("POST".equals(method)) {
            builder.post(requestBody);
        } else if ("DELETE".equals(method)) {
            builder.delete(requestBody);
        } else {
            builder.put(requestBody);
        }
@@ -668,6 +738,36 @@
        }
    }
    public static final class DeleteResult {
        private HikvisionResult userInfo;
        private HikvisionResult card;
        private HikvisionResult face;
        public HikvisionResult getUserInfo() {
            return userInfo;
        }
        public void setUserInfo(HikvisionResult userInfo) {
            this.userInfo = userInfo;
        }
        public HikvisionResult getCard() {
            return card;
        }
        public void setCard(HikvisionResult card) {
            this.card = card;
        }
        public HikvisionResult getFace() {
            return face;
        }
        public void setFace(HikvisionResult face) {
            this.face = face;
        }
    }
    public static final class IssueResult {
        private HikvisionResult userInfo;
        private HikvisionResult card;