|  | @ -6,14 +6,19 @@ async function record (ctx) { | 
			
		
	
		
		
			
				
					|  |  |       const { models } = ctx.fs.dc; |  |  |       const { models } = ctx.fs.dc; | 
			
		
	
		
		
			
				
					|  |  |       const { statusCode, description = '', platform = 'yingshi', serialNo, channelNo } = ctx.request.body; |  |  |       const { statusCode, description = '', platform = 'yingshi', serialNo, channelNo } = ctx.request.body; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       let statusRes = await models.CameraStatus.findOne({ |  |  |       // statusCode == 0 是自动恢复
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       const isRestore = statusCode == 0 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |       let statusRes = isRestore ? null : | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          await models.CameraStatus.findOne({ | 
			
		
	
		
		
			
				
					|  |  |             where: { |  |  |             where: { | 
			
		
	
		
		
			
				
					|  |  |                status: statusCode, |  |  |                status: statusCode, | 
			
		
	
		
		
			
				
					|  |  |                platform, |  |  |                platform, | 
			
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |          }) |  |  |          }) | 
			
		
	
		
		
			
				
					|  |  |       let alarmRes = null; |  |  |       let alarmRes = null; | 
			
		
	
		
		
			
				
					
					|  |  |       if (!statusRes) { |  |  |       if (!statusRes && !isRestore) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |          // 没有这种告警状态就新建一个
 | 
			
		
	
		
		
			
				
					|  |  |          statusRes = await models.CameraStatus.create({ |  |  |          statusRes = await models.CameraStatus.create({ | 
			
		
	
		
		
			
				
					|  |  |             platform: platform, |  |  |             platform: platform, | 
			
		
	
		
		
			
				
					|  |  |             status: statusCode, |  |  |             status: statusCode, | 
			
		
	
	
		
		
			
				
					|  | @ -21,30 +26,47 @@ async function record (ctx) { | 
			
		
	
		
		
			
				
					|  |  |             forbidden: false, |  |  |             forbidden: false, | 
			
		
	
		
		
			
				
					|  |  |          }) |  |  |          }) | 
			
		
	
		
		
			
				
					|  |  |       } else { |  |  |       } else { | 
			
		
	
		
		
			
				
					
					|  |  |          alarmRes = await models.CameraStatusAlarm.findOne({ |  |  |          let findWhere = { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             where: { |  |  |             confirmTime: null, | 
			
				
				
			
		
	
		
		
			
				
					|  |  |                statusId: statusRes.id, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |                description, |  |  |  | 
			
		
	
		
		
			
				
					|  |  |                confirm: null, |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |             serialNo, |  |  |             serialNo, | 
			
		
	
		
		
			
				
					|  |  |             channelNo, |  |  |             channelNo, | 
			
		
	
		
		
			
				
					|  |  |             platform, |  |  |             platform, | 
			
		
	
		
		
			
				
					|  |  |          } |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          if (isRestore) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          } else { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             findWhere.description = description | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          if (statusRes) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             findWhere.statusId = statusRes.id | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          alarmRes = await models.CameraStatusAlarm[isRestore ? 'findAll' : 'findOne']({ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             where: findWhere | 
			
		
	
		
		
			
				
					|  |  |          }) |  |  |          }) | 
			
		
	
		
		
			
				
					|  |  |       } |  |  |       } | 
			
		
	
		
		
			
				
					
					|  |  |       if (alarmRes) { |  |  |       if ( | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          await models.CameraStatusAlarm.update({ |  |  |          (!isRestore && alarmRes) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             updateTime: moment().format() |  |  |          || (isRestore && alarmRes && alarmRes.length) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |          }, { |  |  |       ) { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |          let updateD = { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             updateTime: moment().format('YYYY-MM-DD HH:mm:ss'), | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          if (isRestore) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             updateD.autoRestore = true | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             updateD.confirmTime = moment().format('YYYY-MM-DD HH:mm:ss') | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |          await models.CameraStatusAlarm.update(updateD, { | 
			
		
	
		
		
			
				
					|  |  |             where: { |  |  |             where: { | 
			
		
	
		
		
			
				
					
					|  |  |                id: alarmRes.id |  |  |                id: { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |                   $in: isRestore ? alarmRes.map(a => a.id) : [alarmRes.id] | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                } | 
			
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |          }) |  |  |          }) | 
			
		
	
		
		
			
				
					
					|  |  |       } else { |  |  |       } else if (!isRestore) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |          alarmRes = await models.CameraStatusAlarm.create({ |  |  |          alarmRes = await models.CameraStatusAlarm.create({ | 
			
		
	
		
		
			
				
					|  |  |             statusId: statusRes.id, |  |  |             statusId: statusRes.id, | 
			
		
	
		
		
			
				
					|  |  |             description, |  |  |             description, | 
			
		
	
		
		
			
				
					
					|  |  |             createTime: moment().format(), |  |  |             createTime: moment().format('YYYY-MM-DD HH:mm:ss'), | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             serialNo, |  |  |             serialNo, | 
			
		
	
		
		
			
				
					|  |  |             channelNo, |  |  |             channelNo, | 
			
		
	
		
		
			
				
					|  |  |             platform, |  |  |             platform, | 
			
		
	
	
		
		
			
				
					|  | @ -53,7 +75,7 @@ async function record (ctx) { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |       ctx.status = 204; |  |  |       ctx.status = 204; | 
			
		
	
		
		
			
				
					|  |  |    } catch (error) { |  |  |    } catch (error) { | 
			
		
	
		
		
			
				
					
					|  |  |       ctx.fs.logger.error(`path: ${ctx.path}, error: error`); |  |  |       ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |       ctx.status = 400; |  |  |       ctx.status = 400; | 
			
		
	
		
		
			
				
					|  |  |       ctx.body = { |  |  |       ctx.body = { | 
			
		
	
		
		
			
				
					|  |  |          message: typeof error == 'string' ? error : undefined |  |  |          message: typeof error == 'string' ? error : undefined | 
			
		
	
	
		
		
			
				
					|  | @ -66,7 +88,7 @@ async function confirm (ctx) { | 
			
		
	
		
		
			
				
					|  |  |       const { models } = ctx.fs.dc; |  |  |       const { models } = ctx.fs.dc; | 
			
		
	
		
		
			
				
					|  |  |       const { alarmId, content } = ctx.request.body; |  |  |       const { alarmId, content } = ctx.request.body; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |       await models.CameraStatusAlarm.findOne({ |  |  |       await models.CameraStatusAlarm.update({ | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |          confirm: content, |  |  |          confirm: content, | 
			
		
	
		
		
			
				
					|  |  |          confirmTime: moment().format(), |  |  |          confirmTime: moment().format(), | 
			
		
	
		
		
			
				
					|  |  |       }, { |  |  |       }, { | 
			
		
	
	
		
		
			
				
					|  | 
 |