/// <summary> /// POST api/source /// 图片目录数据保存接口 /// </summary> public async Task <HttpResponseMessage> PostAsync() { string data = await Request.Content.ReadAsStringAsync(); JavaScriptSerializer js = new JavaScriptSerializer(); js.MaxJsonLength = int.MaxValue; Logger.Debug(data); SourceInputDto input = js.Deserialize <SourceInputDto>(data); srcOp.CreateBatchData(input.Images.Select(_ => new SourceEntity { SourceType = (int)SourceTypeEnum.Picture, DeviceNo = input.DeviceNo, SourceCameraNo = input.SourceCameraNo, SavePathDir = _.SavePathDir, SourceFiles = string.Join(";", _.SourceFiles), CoverImageName = _.SourceFiles[0], CreatedDate = DateTime.Parse(_.CreatedDate), CreatedTimestamp = Convert.ToInt64(Commoncs.GetTimestamp(DateTime.Parse(_.CreatedDate))), CurrentStatus = (int)RowStatusEnum.Enable })); return(new HttpResponseMessage { Content = new StringContent(Commoncs.SerializeJson(new ResponseViewModel { Status = (int)HttpStatusCode.OK, Msg = "保存成功!" }), Encoding.GetEncoding("UTF-8"), "application/json") }); }
public async Task CreateOrUpdateSource(SourceInputDto input) { if (input.Id != 0) { await UpdateSource(input); } else { await CreateSource(input); } }
/// <summary> /// 获取图片路径 /// </summary> /// <returns></returns> public JsonResult GetMonitorPics(SourceInputDto input) { var endDate = DateTime.Parse(input.BeginDate).AddMinutes(5).ToString("yyyy-MM-dd HH:mm:ss"); string andExpression = " and s.created_date >= '" + input.BeginDate + "' and s.created_date <= '" + endDate + "'"; string joinExpression = ""; joinExpression += " inner join bas_device d on d.device_no = s.device_no"; joinExpression += " inner join bas_loc l on l.loc_no = d.loc_no"; joinExpression += " inner join bas_line ln on ln.line_no = l.line_no"; if (!string.IsNullOrEmpty(input.LocNo)) { andExpression += " and d.loc_no = '" + input.LocNo + "'"; } if (!string.IsNullOrEmpty(input.ProcessNo)) { andExpression += " and l.process_no = '" + input.ProcessNo + "'"; } if (!string.IsNullOrEmpty(input.LineNo)) { andExpression += " and l.line_no = '" + input.LineNo + "'"; } if (!string.IsNullOrEmpty(input.WorkshopNo)) { andExpression += " and ln.workshop_no = '" + input.WorkshopNo + "'"; } string sql = $"select distinct s.* from biz_source s {joinExpression} where 1=1 {andExpression}"; sql += $" order by created_date limit {(input.PageIndex - 1) * 20}, {20}"; string countSql = $"select DISTINCT s.source_id from biz_source s {joinExpression} where 1=1 {andExpression}"; var total = srcOp.GetRowCount(countSql); var imgList = srcOp.GetDataByRawSql <SourceViewEntity>(sql); var list = new List <MonitorFile>(); string isCompressed = ConfigurationManager.AppSettings["IsCompressed"]; var isRealCompressed = true; // 不满足获取压缩图片的条件 if (isCompressed != "Yes" || !input.IsCompressed || imgList.Count(_ => _.CurrentStatus != (int)RowStatusEnum.Ready) > 0) { isRealCompressed = false; } GetImages(imgList, list, isRealCompressed); return(Json(new { Data = list, IsCompressed = isRealCompressed, Total = total % 20 == 0 ? total / 20 : total / 20 + 1 }, JsonRequestBehavior.AllowGet)); }
public async Task CreateSource(SourceInputDto input) { var src = input.MapTo <Source>(); var srcs = _sourceRepository .GetAll().Where(p => p.SourceName == input.SourceName || p.SourceCode == input.SourceName).FirstOrDefault(); if (srcs == null) { await _sourceRepository.InsertAsync(src); } else { throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in Source Name '" + input.SourceName + "' or Source Code '" + input.SourceCode + "'..."); } }
public async Task UpdateSource(SourceInputDto input) { var src = await _sourceRepository.GetAsync(input.Id); ObjectMapper.Map(input, src); var val = _sourceRepository .GetAll().Where(p => (p.SourceCode == input.SourceCode || p.SourceName == input.SourceName) && p.Id != input.Id).FirstOrDefault(); if (val == null) { await _sourceRepository.UpdateAsync(src); } else { throw new UserFriendlyException("Ooops!", "Duplicate Data Occured in source Name '" + input.SourceName + "' or source Code '" + input.SourceCode + "'..."); } }