63 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C#
		
	
	
	
			
		
		
	
	
			63 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C#
		
	
	
	
| using BLL;
 | |
| using Model.APIItem;
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Configuration;
 | |
| using System.IO;
 | |
| using System.Linq;
 | |
| using System.Web;
 | |
| using System.Web.Http;
 | |
| 
 | |
| namespace WebAPI.Controllers
 | |
| {
 | |
| 
 | |
|     public class AIAlarmEventController : ApiController
 | |
|     {
 | |
|         [HttpPost]
 | |
|         public Model.ResponeData alarmEvent([FromBody] AIAlarmEventItem item)
 | |
|         {
 | |
|             var responeData = new Model.ResponeData();
 | |
|             try
 | |
|             {
 | |
|                 using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString))
 | |
|                 {
 | |
|                     Model.HSSE_AIAlarmEvent newInOut = new Model.HSSE_AIAlarmEvent
 | |
|                     {
 | |
|                         AIAlarmEventId = Guid.NewGuid().ToString(),
 | |
|                         DeviceId = item.device_id,
 | |
|                         DeviceVersion = item.device_version,
 | |
|                         Date = item.date,
 | |
|                         Label = item.label,
 | |
|                         Alias = item.alias,
 | |
|                         Count = item.count,
 | |
|                         Extend = item.extend.ToString(),
 | |
|                     };
 | |
|                     db.HSSE_AIAlarmEvent.InsertOnSubmit(newInOut);
 | |
|                     db.SubmitChanges();
 | |
|                     if (!string.IsNullOrEmpty(item.img_base64))
 | |
|                     {
 | |
|                         var image = Convert.FromBase64String(item.img_base64);
 | |
|                         string rootPath = ConfigurationManager.AppSettings["localRoot"];
 | |
|                         string path = "FileUpLoad/HSSE/AIAlarmEvent/" + DateTime.Now.ToString("yyyy-MM") + "/";
 | |
|                         string fileUrl = (rootPath + path).Replace('/', '\\');
 | |
|                         string flieName = Funs.GetNewFileName() + ".jpg";
 | |
|                         if (!Directory.Exists(fileUrl))
 | |
|                         {
 | |
|                             Directory.CreateDirectory(fileUrl);
 | |
|                         }
 | |
|                         System.IO.File.WriteAllBytes((fileUrl + flieName), image);
 | |
|                         UploadFileService.SaveAttachUrlForApi(UploadFileService.GetSourceByAttachUrl(path + flieName, 10, null), path + flieName, BLL.Const.AIAlarmEventMenuId, newInOut.AIAlarmEventId);
 | |
|                     }
 | |
|                 }
 | |
|             }
 | |
|             catch (Exception ex)
 | |
|             {
 | |
|                 responeData.code = 0;
 | |
|                 responeData.message = ex.Message;
 | |
|                 ErrLogInfo.WriteLog(ex, "接口-插入智能识别记录", "AIAlarmEventController.alarmEvent");
 | |
|             }
 | |
|             return responeData;
 | |
|         }
 | |
|     }
 | |
| }
 | |
|   |