|
|
@@ -2,6 +2,7 @@ import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
|
|
import PaginationService from 'App/Services/PaginationService'
|
|
|
import { schema } from '@ioc:Adonis/Core/Validator'
|
|
|
import OcrDevice from 'App/Models/OcrDevice'
|
|
|
+import OcrChannel from 'App/Models/OcrChannel'
|
|
|
|
|
|
export default class OcrDevicesController {
|
|
|
private paginationService = new PaginationService(OcrDevice)
|
|
|
@@ -19,9 +20,14 @@ export default class OcrDevicesController {
|
|
|
channel: schema.string(),
|
|
|
deviceInfo: schema.string.optional(),
|
|
|
total: schema.number(),
|
|
|
- scanned: schema.number()
|
|
|
+ scanned: schema.number(),
|
|
|
+ ipAddress: schema.string.optional()
|
|
|
})
|
|
|
})
|
|
|
+ const clientIp = request.ip()
|
|
|
+ if (!data.ipAddress) {
|
|
|
+ data.ipAddress = clientIp
|
|
|
+ }
|
|
|
const device = await OcrDevice.findBy('id', data.id)
|
|
|
if (device) {
|
|
|
device.merge(data)
|
|
|
@@ -34,4 +40,47 @@ export default class OcrDevicesController {
|
|
|
public async show({ params }: HttpContextContract) {
|
|
|
return await OcrDevice.findOrFail(params.id)
|
|
|
}
|
|
|
+
|
|
|
+ public async plusTotal({ request, response }: HttpContextContract) {
|
|
|
+ try {
|
|
|
+ const device = await OcrDevice.findBy('id', request.param('id'))
|
|
|
+ if (!device) {
|
|
|
+ return response.notFound({ message: `未找到ID为 ${request.param('id')} 的OCR设备` })
|
|
|
+ }
|
|
|
+ device.total += 1
|
|
|
+ await device.save()
|
|
|
+ return response.ok(device)
|
|
|
+ } catch (error) {
|
|
|
+ return response.internalServerError({
|
|
|
+ message: '更新设备记录数量时发生错误',
|
|
|
+ error: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public async plusScanned({ request, response }: HttpContextContract) {
|
|
|
+ const scanCount = Number(request.param('scanCount'))
|
|
|
+ if (isNaN(scanCount)) {
|
|
|
+ return response.badRequest({ message: 'scanCount 参数必须是有效数字' })
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ const device = await OcrDevice.findBy('id', request.param('id'))
|
|
|
+ if (!device) {
|
|
|
+ return response.notFound({
|
|
|
+ message: `未找到 ID 为 ${request.param('id')} 的 OCR 设备`
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ device.scanned += scanCount
|
|
|
+ await device.save()
|
|
|
+
|
|
|
+ return response.ok(device)
|
|
|
+ } catch (error) {
|
|
|
+ return response.internalServerError({
|
|
|
+ message: '更新设备扫描数量时发生错误',
|
|
|
+ error: error.message
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|