diff --git a/attendance_iot/controllers/kaoqin_test.py b/attendance_iot/controllers/kaoqin_test.py index b50e7cb47..db22b86fa 100644 --- a/attendance_iot/controllers/kaoqin_test.py +++ b/attendance_iot/controllers/kaoqin_test.py @@ -81,6 +81,10 @@ class BusController(Controller): # 同步到同公司的其他设备 self._sync_to_other_devices(employee, attendance_iot_id, data.get('photo')) _logger.info("-------------------------%s创建成功-------------------------------" % (employee.name)) + # 更新设备最后触发时间 & 写日志 + if attendance_iot_id: + attendance_iot_id.touch_last_update() + attendance_iot_id._log('人脸注册', f"员工 {employee.name} 注册到设备 {attendance_iot_id.name}") return {"Result": 0, "Msg": "添加成功"} @route('/api/v1/record/face', methods=['POST'], type='json', auth='none', csrf=False) @@ -117,6 +121,10 @@ class BusController(Controller): }) _logger.info(f"考勤机创建的数据:{details}") _logger.info(f"---考勤机名称-id:{attendance_iot_id.name}-{attendance_iot_id.id}-===okokokokokokokokokokok==----") + # 更新设备最后触发时间 & 写日志 + if attendance_iot_id: + attendance_iot_id.touch_last_update() + attendance_iot_id._log('打卡上报', f"员工 {employee_id.name} 在 {recog_time} 打卡") return {"Result": 0, "Msg": "添加成功"} @route('/api/v1/user/inf_photo', methods=['POST'], type='json', auth='none', csrf=False) @@ -149,6 +157,10 @@ class BusController(Controller): }) # 同步到同公司的其他设备 self._sync_to_other_devices(employee, iot_device, vl_photo) + # 更新设备最后触发时间 & 写日志 + if iot_device: + iot_device.touch_last_update() + iot_device._log('用户信息更新', f"员工 {employee.name} 照片更新/注册") return {"Result": 0, "Msg": "添加成功"} @route('/api/v1/uploadFaceInfo', methods=['POST'], type='json', auth='none', csrf=False) @@ -199,6 +211,10 @@ class BusController(Controller): # 同步到同公司的其他设备(uploadFaceInfo 是设备主动发起的数据同步,同样需要推给其他设备) self._sync_to_other_devices(employee, iot_device, u.get('photo')) + # 更新设备最后触发时间 & 写日志 + if iot_device: + iot_device.touch_last_update() + iot_device._log('人脸数据同步', f"设备 {iot_device.name} 上报 {len(user_list)} 条用户数据") return {"Result": 0, "Msg": "更新成功"} @http.route('/phone/attendance/list', type='http', auth="none", csrf=False, cors='*') diff --git a/attendance_iot/models/attendance_iot.py b/attendance_iot/models/attendance_iot.py index 1c6dba785..821ebf400 100644 --- a/attendance_iot/models/attendance_iot.py +++ b/attendance_iot/models/attendance_iot.py @@ -21,6 +21,7 @@ class AttendanceIot(models.Model): remake = fields.Text(string='备注') employee_ids = fields.Many2many('hr.employee', string="员工") is_connected = fields.Boolean(string="连接状态", default=False) + last_update_time = fields.Datetime(string="最后更新时间") def action_init_device(self): ''' @@ -114,9 +115,22 @@ class AttendanceIot(models.Model): return { 'name': '考勤机日志', 'type': 'ir.actions.act_window', - 'res_model': 'iot.message', + 'res_model': 'attendance.iot.log', 'view_mode': 'tree,form', - 'domain': [('device_sn', '=', self.name)], + 'domain': [('attendance_iot_id', '=', self.id)], } + def touch_last_update(self): + """更新最后触发时间(MQTT/API 每次触发时调用)""" + self.write({'last_update_time': fields.Datetime.now()}) + + def _log(self, event_type, content): + """写入设备操作日志""" + self.ensure_one() + self.env['attendance.iot.log'].create({ + 'attendance_iot_id': self.id, + 'event_type': event_type, + 'content': content, + }) + diff --git a/attendance_iot/models/attendance_iot_log.py b/attendance_iot/models/attendance_iot_log.py index 88ac63640..9e03c757f 100644 --- a/attendance_iot/models/attendance_iot_log.py +++ b/attendance_iot/models/attendance_iot_log.py @@ -7,4 +7,5 @@ class AttendanceIotLog(models.Model): _order = 'create_date desc' attendance_iot_id = fields.Many2one('attendance.iot', string="考勤机设备", required=True, ondelete='cascade') + event_type = fields.Char(string="事件类型") content = fields.Text(string="内容") diff --git a/attendance_iot/views/attendance_iot_log_views.xml b/attendance_iot/views/attendance_iot_log_views.xml index 4304efb73..83b27b594 100644 --- a/attendance_iot/views/attendance_iot_log_views.xml +++ b/attendance_iot/views/attendance_iot_log_views.xml @@ -7,6 +7,7 @@ + diff --git a/attendance_iot/views/attendance_iot_views.xml b/attendance_iot/views/attendance_iot_views.xml index ab3f989aa..149892e36 100644 --- a/attendance_iot/views/attendance_iot_views.xml +++ b/attendance_iot/views/attendance_iot_views.xml @@ -10,13 +10,12 @@ - - - + +