Commit 08acc1e4 by liimin

修改一些BUG

1 parent f97c7129
...@@ -11,3 +11,5 @@ SOCKET_PORT= 8080 ...@@ -11,3 +11,5 @@ SOCKET_PORT= 8080
APP_PORT= 3000 APP_PORT= 3000
STATIC_PATH = "public" STATIC_PATH = "public"
JWT_SECRET = 'secretKey' JWT_SECRET = 'secretKey'
SERVER = 'app-admin-server.test.glsx.com.cn'
LOG_SAVED_DAYS = 30
\ No newline at end of file \ No newline at end of file
...@@ -112,7 +112,11 @@ export class DeviceService implements OnModuleInit { ...@@ -112,7 +112,11 @@ export class DeviceService implements OnModuleInit {
} }
async addDevice(device: Omit<DeviceTypes.IDeviceSaves, 'device_id'>): Promise<CommonTypes.IResData> { async addDevice(device: Omit<DeviceTypes.IDeviceSaves, 'device_id'>): Promise<CommonTypes.IResData> {
const { device_info, log_config, user_fields, sn } = device const { device_info, log_config = {}, user_fields, sn } = device
const dv = await this.prisma.device.findFirst({ where: { sn } })
if (dv) {
return { code: RESPONSE_CODE.NOSUCCESS, message: '设备已存在' }
}
await this.prisma.$transaction(async prisma => { await this.prisma.$transaction(async prisma => {
const now = new Date() const now = new Date()
const { id } = await prisma.device.create({ data: { sn, created_at: now }, select: { id: true } }) const { id } = await prisma.device.create({ data: { sn, created_at: now }, select: { id: true } })
...@@ -120,9 +124,9 @@ export class DeviceService implements OnModuleInit { ...@@ -120,9 +124,9 @@ export class DeviceService implements OnModuleInit {
if (device_info) { if (device_info) {
await prisma.device_info.create({ data: { device_id, user: device_info.user, mobile: device_info.mobile, merchant_name: device_info.merchant_name, updated_at: now, created_at: now } }) await prisma.device_info.create({ data: { device_id, user: device_info.user, mobile: device_info.mobile, merchant_name: device_info.merchant_name, updated_at: now, created_at: now } })
} }
if (log_config) { // if (log_config) {
await prisma.log_config.create({ data: { log_saved_days: log_config.log_saved_days, device_id, created_at: now, updated_at: now } }) await prisma.log_config.create({ data: { log_saved_days: log_config.log_saved_days || +process.env.LOG_SAVED_DAYS, device_id, created_at: now, updated_at: now } })
} // }
if (user_fields) { if (user_fields) {
await prisma.field_relation.deleteMany({ where: { device_id } }) await prisma.field_relation.deleteMany({ where: { device_id } })
await prisma.field_relation.createMany({ await prisma.field_relation.createMany({
...@@ -138,7 +142,7 @@ export class DeviceService implements OnModuleInit { ...@@ -138,7 +142,7 @@ export class DeviceService implements OnModuleInit {
async addDeviceInfo(deviceInfo: DeviceTypes.IDeviceSaves): Promise<CommonTypes.IResData> { async addDeviceInfo(deviceInfo: DeviceTypes.IDeviceSaves): Promise<CommonTypes.IResData> {
const now = new Date() const now = new Date()
const { device_id, ...data } = deviceInfo const { device_id, ...data } = deviceInfo
const { device_info, log_config, user_fields, sn } = data const { device_info, log_config = {}, user_fields, sn } = data
await this.prisma.$transaction(async prisma => { await this.prisma.$transaction(async prisma => {
if (sn) { if (sn) {
await prisma.device.update({ where: { id: device_id }, data: { sn } }) await prisma.device.update({ where: { id: device_id }, data: { sn } })
...@@ -146,9 +150,7 @@ export class DeviceService implements OnModuleInit { ...@@ -146,9 +150,7 @@ export class DeviceService implements OnModuleInit {
if (device_info) { if (device_info) {
await prisma.device_info.create({ data: { device_id, user: device_info.user, mobile: device_info.mobile, merchant_name: device_info.merchant_name, updated_at: now, created_at: now } }) await prisma.device_info.create({ data: { device_id, user: device_info.user, mobile: device_info.mobile, merchant_name: device_info.merchant_name, updated_at: now, created_at: now } })
} }
if (log_config) { await prisma.log_config.create({ data: { log_saved_days: log_config.log_saved_days || +process.env.LOG_SAVED_DAYS, device_id, created_at: now, updated_at: now } })
await prisma.log_config.create({ data: { log_saved_days: log_config.log_saved_days, device_id, created_at: now, updated_at: now } })
}
if (user_fields) { if (user_fields) {
await prisma.field_relation.deleteMany({ where: { device_id } }) await prisma.field_relation.deleteMany({ where: { device_id } })
await prisma.field_relation.createMany({ await prisma.field_relation.createMany({
...@@ -165,23 +167,24 @@ export class DeviceService implements OnModuleInit { ...@@ -165,23 +167,24 @@ export class DeviceService implements OnModuleInit {
const where = { device_id } const where = { device_id }
await this.prisma.$transaction(async prisma => { await this.prisma.$transaction(async prisma => {
const now = new Date() const now = new Date()
const { device_info, log_config, user_fields, sn } = data const { device_info, log_config = {}, user_fields, sn } = data
if (sn) { if (sn) {
await prisma.device.update({ where: { id: device_id }, data: { sn } }) await prisma.device.update({ where: { id: device_id }, data: { sn } })
} }
if (device_info) { if (device_info) {
device_info.updated_at = now device_info.updated_at = now
await prisma.device_info.update({ await prisma.device_info.upsert({
where, where,
data: { user: device_info.user, mobile: device_info.mobile, merchant_name: device_info.merchant_name, updated_at: now } update: { user: device_info.user, mobile: device_info.mobile, merchant_name: device_info.merchant_name, updated_at: now },
create: { device_id, user: device_info.user, mobile: device_info.mobile, merchant_name: device_info.merchant_name, created_at: now, updated_at: now }
}) })
} }
if (log_config) { const config = { log_saved_days: log_config.log_saved_days || +process.env.LOG_SAVED_DAYS, updated_at: now }
await prisma.log_config.update({ await prisma.log_config.upsert({
where, where,
data: { log_saved_days: log_config.log_saved_days, updated_at: now } update: config,
create: Object.assign({ created_at: now,device_id }, config)
}) })
}
if (user_fields) { if (user_fields) {
await prisma.field_relation.deleteMany({ where }) await prisma.field_relation.deleteMany({ where })
await prisma.field_relation.createMany({ await prisma.field_relation.createMany({
......
...@@ -34,7 +34,7 @@ export class FileController { ...@@ -34,7 +34,7 @@ export class FileController {
async upload(@UploadedFile() file: Express.Multer.File, @Req() req: Request): Promise<CommonTypes.IResData<FileTypes.FileUpload<DocTypes>>> { async upload(@UploadedFile() file: Express.Multer.File, @Req() req: Request): Promise<CommonTypes.IResData<FileTypes.FileUpload<DocTypes>>> {
const { fieldname, encoding, stream, buffer, path: origin_path, ...o } = file const { fieldname, encoding, stream, buffer, path: origin_path, ...o } = file
const bodyData: Pick<FileTypes.FileUpload<DocTypes>, 'device_id' | 'type'> = { device_id: Number(req.body.deviceId), type: req.body.type } const bodyData: Pick<FileTypes.FileUpload<DocTypes>, 'device_id' | 'type'> = { device_id: Number(req.body.deviceId), type: req.body.type }
const f: FileTypes.FileUpload<DocTypes> = Object.assign({ created_at: new Date(), path: `${req.protocol}://${req.get('Host')}${origin_path}` }, bodyData, o) const f: FileTypes.FileUpload<DocTypes> = Object.assign({ created_at: new Date(), path: `${req.protocol}://${process.env.SERVER}${origin_path}` }, bodyData, o)
return await this.fileService.save(f) return await this.fileService.save(f)
} }
......
...@@ -19,7 +19,8 @@ import { OnEvent } from '@nestjs/event-emitter' ...@@ -19,7 +19,8 @@ import { OnEvent } from '@nestjs/event-emitter'
* @implements OnGatewayInit * @implements OnGatewayInit
*/ */
@WebSocketGateway(+process.env.SOCKET_PORT, { @WebSocketGateway(+process.env.SOCKET_PORT, {
cors: true // 允许跨域 cors: true, // 允许跨域
path:'/websocket/'
}) })
@UseInterceptors(TransformInterceptor) @UseInterceptors(TransformInterceptor)
export class WsGateway implements WsTypes.WebSocketGateway<Server, Observable<WsResponse<string>>, any>, OnGatewayConnection, OnGatewayDisconnect, OnGatewayInit { export class WsGateway implements WsTypes.WebSocketGateway<Server, Observable<WsResponse<string>>, any>, OnGatewayConnection, OnGatewayDisconnect, OnGatewayInit {
......
# http://localhost:3000/device?user=尹 # http://localhost:3000/device?user=尹
http://localhost:3000/device/addAll # http://localhost:3000/device/addAll
# http://localhost:3000/device/task # http://localhost:3000/device/task
...@@ -34,19 +34,25 @@ http://localhost:3000/device/addAll ...@@ -34,19 +34,25 @@ http://localhost:3000/device/addAll
# POST http://localhost:3000/broadcast/cmd HTTP/1.1 POST http://localhost:3000/broadcast/cmd HTTP/1.1
# content-type: application/json content-type: application/json
# { {
# "event":"private", "event":"private",
# "device_id":"1000068", "device_id":"1000001",
# "data":{ "data":{
# "command":"getLog", # "command":"setPollingInterval",
# "days":20, # "command":"getLog",
# "interval":1000, # "command":"stopPolling",
# "force":true # "command":"startPolling",
# } # "command":"removeLog",
# } "command":"getLogList",
"interval":20,
"beginDate": "2024-11-07",
"endDate": "2024-11-07",
"force":true
}
}
# http://localhost:3000/file/list?device_id=1000000 # http://localhost:3000/file/list?device_id=1000000
# http://localhost:3000/config?device_id=1000000 # http://localhost:3000/config?device_id=1000000
...@@ -55,7 +61,7 @@ http://localhost:3000/device/addAll ...@@ -55,7 +61,7 @@ http://localhost:3000/device/addAll
# content-type: application/json # content-type: application/json
# { # {
# "device_id":1000002, # "device_id":1000086,
# "log_saved_days":7, # "log_saved_days":7,
# "user_fields":[1,2,3] # "user_fields":[1,2,3]
# } # }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!