Commit Graph

28 Commits (ec6aaac0fa61df190f9e2af63735e01a83e2e10c)

Author SHA1 Message Date
SYED MUSTUFA AHMED NAQVI ec6aaac0fa feat: require location-site filter and add departmental sync summaries
Initial department sync now requires InitialSyncLocationSiteId and can
run across all active departments when department IDs are empty. Employee
selection filters by location site, reports inactive/missing departments,
and writes per-department outcomes to a dedicated DepartmentalSync biz log.
2026-08-25 10:30:59 +05:00
SYED MUSTUFA AHMED NAQVI e202923a69 test: add manual harnesses for employee photo preprocessing
Add PowerShell harnesses to exercise EmployeePhotoFaceProcessor against
real HRMS portal photos without touching a device: run_photo_processor
processes given employee ids and writes source/processed JPEGs, and
run_photo_soak repeatedly processes real and synthetic images in one
process to check stability and memory. Both target 32-bit PowerShell to
match the service's x86 build.
2026-08-15 15:58:56 +05:00
SYED MUSTUFA AHMED NAQVI 3ce91f4d76 feat: apply photo preprocessing, employee allow-list, and user-sync logging to initial sync
Wire the initial department sync to the new photo processor: downloaded
JPEGs are face-cropped/normalized before FaceDataRecord, and photos with
no detectable face are skipped and logged as FACE_NOT_DETECTED.

Add an optional InitialSyncEmployeeIds allow-list so only selected
employees within the chosen departments are enrolled (empty = whole
department), filtered directly in the SQL query with parameters.

Emit business entries to logs/user_sync_logs for provisioned users
("added successfully", "face enrolled successfully", readable failure
reasons) so onboarded users appear alongside the existing deletion
entries instead of only in internal_logs.
2026-08-15 15:58:30 +05:00
SYED MUSTUFA AHMED NAQVI 0ef986e71a feat: add HRMS employee photo face preprocessing engine
Add EmployeePhotoFaceProcessor: a managed pipeline that detects the
largest face in an HRMS portal photo, crops it with margin in a 3:4
frame, normalizes to Hikvision's 480x640 enrollment size (capped
upscale), applies percentile contrast/gamma correction plus an unsharp
mask, and encodes JPEG within a size budget.

Face detection uses Accord.Vision's managed Haar cascade (added as a
package reference) so it works on the existing net48/x86 target with no
native binaries. Returns an explicit NoFace status so callers can skip
enrollment for photos without a detectable face.
2026-08-15 15:57:51 +05:00
SYED MUSTUFA AHMED NAQVI 8ae1749dac feat: add configuration for department-based device onboarding
Add initial department-sync and employee-photo source settings, plus department-based user-sync filters. Load, normalize, and apply the new configuration values.
2026-08-15 15:52:25 +05:00
SYED MUSTUFA AHMED NAQVI 9d1e361099 feat: add department-based initial user and face provisioning
Add a configurable initial-sync flow that creates department employees on target Hikvision devices and uploads portal JPEG photos.

Support department-based employee filtering for existing user/template sync.

Discover and retry available Hikvision face libraries, then verify face enrollment after upload.

Extend service configuration and scheduled sync handling for the new onboarding flow.
2026-08-15 15:50:58 +05:00
SYED MUSTUFA AHMED NAQVI 7b66f9319a Log face-template saves only for new inserts and pass updatedBy
Business-log “Saved successfully” only when a template is newly inserted; skip already-present templates in biz logs. Pass hikvision-service as updatedBy on user upserts.

Show machine context in user-sync logs and clear is_deleted after device add

Include Machine ID/IP on add/update/remove business logs. After a successful device user create, upsert the DB row so is_deleted returns to 0 with updated_by set.
2026-08-05 15:39:34 +05:00
SYED MUSTUFA AHMED NAQVI e5a3689434 Skip existing face templates and persist updated_by on user upsert
Do not rewrite active non-empty face templates already in DB. On machine-user upsert, set is_deleted=0 and write updated_by.
2026-08-05 15:37:58 +05:00
SYED MUSTUFA AHMED NAQVI 962a2470c2 Require updatedBy on attendance_machine_user upsert API
Extend UpsertMachineUser so callers must supply who updated the row, matching MarkDeleted.
2026-08-05 15:37:03 +05:00
SYED MUSTUFA AHMED NAQVI 920b8d1e0c Load DeviceSettings.config as an overlay on HikvisionServiceConfig
After loading serviceconfig.json, apply DeviceSettings.config values onto the existing config properties without changing runtime behavior or property names.
2026-08-05 15:36:09 +05:00
SYED MUSTUFA AHMED NAQVI 3bc691933a Copy DeviceSettings.config to the build output directory
Ensure DeviceSettings.config is deployed next to the service executable with serviceconfig.json.
2026-08-05 15:35:38 +05:00
SYED MUSTUFA AHMED NAQVI f8c6a060d8 Add DeviceSettings.config for machine scope and template sync direction
Introduce a dedicated device settings file for SITE/CENTRAL scope, scoped IPs, template sync direction flags, source/target IPs, and SyncEmployeeIds.
2026-08-05 15:35:08 +05:00
SYED MUSTUFA AHMED NAQVI dec8513d86 Add unit tests for ISAPI delete success confirmation rules
Cover confirmed-success parsing for statusCode/OK/ok variants and concise failure mapping (e.g. employee not found).
2026-07-30 13:20:39 +05:00
SYED MUSTUFA AHMED NAQVI 35ed884104 Fix USER_DELETE success parsing and Hikvision FaceImage upload multipart
Confirm deletes on HTTP 2xx + statusCode=1 + OK/ok (skip fallback after success); machine-scoped pending deletes; rebuild FaceDataRecord multipart with FaceImage (not img) and richer upload diagnostics.
2026-07-30 13:20:17 +05:00
SYED MUSTUFA AHMED NAQVI fb6f09188d Make attendance business logs an activity story and gate device→DB templates
Emit scope/DB startup once; per-machine CONNECTING/status/fetch/insert (or offline) story lines; keep technical counters in internal logs; require EnableTemplateDeviceToDbSync for device→DB template persistence/logging.
2026-07-30 13:19:46 +05:00
SYED MUSTUFA AHMED NAQVI 9ae838888a Fix attendance_log inserts and extend face-template/user deletion DB APIs
Replace REPLACE/empty ac_no inserts with guarded InsertAttendance (avoids generated ac_no_int cast failures); extend face-template upsert metadata and pending-deletion user queries for machine-scoped delete requests.
2026-07-30 13:19:28 +05:00
SYED MUSTUFA AHMED NAQVI a136fe587c Add console/debug host so F5 runs without Windows Service SCM
Support --console / debugger-attached interactive hosting with Ctrl+C shutdown, and launch profiles that pass --console.
2026-07-30 13:18:52 +05:00
SYED MUSTUFA AHMED NAQVI 672fa2a89d Wire two-tier FileLogger channels and template sync direction flags
Extend FileLogger with Biz/Ops/Diag writers and service start/stop blocks; add EnableTemplateDeviceToDbSync / EnableTemplateDbToDeviceSync so only the enabled template direction is logged and run.
2026-07-30 13:18:17 +05:00
SYED MUSTUFA AHMED NAQVI f783537917 Add ops markers and unreachable-device tracking for internal logs
Add structured [SERVICE] / [ATTENDANCE] / [USER_DELETE] / template markers and unreachable-device reporting used by internal diagnostic summaries
2026-07-30 13:17:55 +05:00
SYED MUSTUFA AHMED NAQVI e9438ac1dc Add business-log helpers for human-readable activity reports
Introduce shared session totals, time formatting, and friendly reason helpers used by operational attendance/user/template logs
2026-07-30 13:17:23 +05:00
SYED MUSTUFA AHMED NAQVI 803d645360 Update test mode for template export signature and discovered-user reporting. 2026-04-14 17:22:46 +05:00
SYED MUSTUFA AHMED NAQVI a5d0bc04c1 Populate machine-user assignments and template sync metadata from device discovery.
Upserts discovered users into attendance_machine_user
Updates attendance_machine.total_users
2026-04-14 17:21:42 +05:00
SYED MUSTUFA AHMED NAQVI 33c2dfabb3 Refactor attendance scheduler and move cursor/state handling to DB-driven flow.
1) Immediate startup attendance run
2) Shared real fetch cycle path with skip-reason logs
3) last_sync_date read/write from DB
4) Preserve cursor on status updates
5) IP-based machine matching
6) zero-record cursor advance to window end
7) CSV write lock/file-sharing fix
2026-04-14 17:17:05 +05:00
SYED MUSTUFA AHMED NAQVI 93b2bf9bd7 Add MySQL-backed HRMS repositories and DB integration configuration.
1) Introduces DB connectivity, repository abstractions, and new config flags/env overrides.

2) Keeps architecture clean and isolated.
2026-04-14 17:12:10 +05:00
SYED MUSTUFA AHMED NAQVI fbd4d1d313 Implement robust multi-job scheduling, ISAPI user/template sync, and production-grade logging for Hikvision attendance service.
This change set turns the service into a configurable, operations-friendly pipeline with independent jobs for attendance sync, template fetching, and user sync, while hardening data safety and observability for DS-K1T642MFW deployments.

What was implemented:

1) ISAPI-first user info + face URL handling
- Added direct HTTP ISAPI user search with Digest auth:
  - POST /ISAPI/AccessControl/UserInfo/Search?format=json
- Added source switch to prefer HTTP user info while keeping SDK/STDXML fallback.
- Added face image download via ISAPI using configured device IP even when faceURL host differs.
- Preserved existing HCNetSDK functionality (no regression/removal).

2) Multi-device user sync orchestration
- Added sync config model and policies:
  - EnableUserSync, SyncIntervalMinutes, SourceDeviceId, TargetDeviceIds
  - UserSyncFaceCacheDirectory, SyncPolicies (update fields, upload policy, delete policy, retries, face lib settings)
- Implemented RunUserFaceSyncCycle with focused helpers:
  - user search (paged), compare, create/modify/delete users, upload faces, verify user existence
- Added retries with exponential backoff for transient HTTP failures.
- Added status tracking enum and cycle summaries.
- Added one-shot CLI/test mode trigger:
  - --user-sync-once
- Scheduler now runs first cycle immediately on startup, then at configured interval.

3) Scheduled template fetch job (independent)
- Added EnableTemplateFetch + TemplateFetchIntervalHours.
- Implemented periodic template export scheduler loop.
- Runs per device session and writes output under date/device directories.
- Scheduler now runs first cycle immediately on startup, then at configured interval.

4) Attendance job controls + dynamic historical fetch pagination
- Added EnableAttendanceSync + AttendanceSyncIntervalMinutes.
- Attendance scheduler now respects dedicated attendance flags/intervals.
- Refactored STDXML ISAPI ACS fetch to support pagination loop with:
  - responseStatusStrg handling (MORE/END)
  - dynamic batch size growth (30 -> 50 -> 100)
  - searchResultPosition advancement by actual returned rows
  - loop safety for empty-page anomalies

5) Safe cleanup of old device ACS records after confirmed DB insert
- Implemented device cleanup call:
  - PUT /ISAPI/AccessControl/AcsEvent/StorageCfg?format=json
  - mode=time, checkTime=last synced event time
- Cleanup executes only when:
  - historical fetch parsed records
  - DB persistence enabled
  - all parsed records inserted successfully
- If DB insert is incomplete/failed:
  - cleanup is skipped
  - last-sync is not advanced
  - next cycle retries same window
- Added explicit skip log:
  - “Cleanup skipped: DB insert not confirmed; delete not executed.”

6) Logging architecture overhaul
- Structured logs into daily files per concern:
  - internal deep logs
  - attendance_logs
  - template_fetching_logs
  - user_sync_logs
- Moved internal root to:
  - C:\Users\Public\HikvisionAttendanceService\internal_logs
  (no longer under logs/internal_logs)
- Added job cycle banners:
  - SERVICE STARTED / JOB / started at
  - SERVICE ENDED / finished at
- Added attendance-specific operational lines:
  - MACHINE <name> has <n> records !
  - [AttendanceInsert] machine_id= ip= emp_no= checktime= rows=
- Enhanced SDK failure logs to multi-line readable format with:
  - operation, device context, translated reason, original call+error code
  - preserved raw error context for troubleshooting

7) Template logging improvements (operational + internal split)
- Main template job log now includes full post-run summary:
  - totals, fetched vs not fetched, per-user lists for face and fingerprint
- Moved detailed per-user template status to internal debug location:
  - C:\Users\Public\HikvisionAttendanceService\internal_logs\template_internal_logs\face
  - C:\Users\Public\HikvisionAttendanceService\internal_logs\template_internal_logs\finger
- Added headings in internal files and “no templates to fetch” cases.

8) Config/path standardization for production
- Standardized runtime/log output root to:
  - C:\Users\Public\HikvisionAttendanceService
- Updated defaults and active serviceconfig fields accordingly
  (LogDirectory, AttendanceTextFilePath, HrExportPath, face cache path).
- Ensured last-sync markers and CSV/text outputs follow this root.

9) Test and build coverage
- Added/updated unit tests for:
  - user JSON parsing
  - retry helper/backoff behavior
  - dynamic historical batch thresholds
- Added integration placeholder test for hardware runs.
- Verified successful build/test runs after each major refactor.

Outcome:
- Service now supports independent, flag-driven operations for attendance, templates, and user sync.
- Logging is production-readable and audit-friendly.
- Historical sync is safer and more scalable.
- Device cleanup is guarded by DB-success semantics to prevent data loss.
2026-04-14 10:56:03 +05:00
SYED MUSTUFA AHMED NAQVI d2bb7ad566 Added a new path for logs to support exception loging 2026-04-14 10:48:47 +05:00
SYED MUSTUFA AHMED NAQVI 0100f4c5f1 face read support added 2026-04-09 18:14:54 +05:00
SYED MUSTUFA AHMED NAQVI 2455f71296 Initial Commit 2026-04-06 17:19:57 +05:00