public static bool UploadWaybill_HuaDong(Model_Waybill_Postback_Pic huadongPostback, DateTime postbackTime, List <object> picList) { bool result = false; int picIndex = 0;//成功上传的图片数量 if (picList.Count == 0) { return(false); } if (string.IsNullOrEmpty(huadongPostback.PicName)) { return(false); } string[] picNameArr = huadongPostback.PicName.Split('|'); if (picNameArr.Length != picList.Count) { return(false); } //配置文件中的路径 string filePath = string.Empty; string tempPath = System.Configuration.ConfigurationManager.AppSettings["PostbackPath"]; if (string.IsNullOrEmpty(tempPath)) { return(false); } string timePath = DateTime.Now.ToString("yyyyMM"); filePath = tempPath + "\\" + timePath; try { List <Model_Huadong_Tmsorder_Waybillbase> waybillbase = GetHuadongWaybillbase(new List <string> { huadongPostback.BaseId }); if (waybillbase.Count() == 0) { return(true); } List <Model_Waybill_Base> numberList = GetExistWaybills(waybillbase[0].number).Distinct().ToList(); if (numberList.Count == 0) { return(true);//运单还未上传,无法上传签收图片 } if (!System.IO.Directory.Exists(filePath)) { System.IO.Directory.CreateDirectory(filePath); } StringBuilder sql = new StringBuilder("insert into waybill_postback_pic (baseId,picName) values "); for (int i = 0; i < picList.Count; i++) { string fileName = numberList[0].Number + "_" + System.IO.Path.GetFileName(huadongPostback.PicName.Split('|')[i]); MyTool.SaveImage(MyTool.GetGzipPicBytes(picList[i] as byte[]), filePath + "\\" + fileName); sql.AppendFormat("('{0}','{1}'),", numberList[0].Id, timePath + "/" + fileName); picIndex++; } sql.Length -= 1; List <string> sqlList = new List <string>(); sqlList.Add(sql.ToString()); sqlList.Add(string.Format("update waybill_base set picPostbackAt='{0}' where number='{1}'", postbackTime.ToString("yyyy-MM-dd HH:mm:ss"), numberList[0].Number)); result = _SqlHelp.ExecuteTranstration(sqlList); } catch (Exception ex) { throw ex; } finally { if (result == false && picIndex > 0) { //失败时删除图片 for (int i = picIndex; i > 0; i--) { string fileName = huadongPostback.BaseId + "_" + System.IO.Path.GetFileName(huadongPostback.PicName.Split('|')[i - 1]); System.IO.File.Delete(filePath + "\\" + fileName); } } } return(result); }
///// <summary> ///// 查询运单以前是否存在节点信息,没有超过一个月的节点信息保存到节点表中,超过时间的节点信息删除。 ///// </summary> ///// <param name="waybillList"></param> ///// <returns></returns> //public static int GetNode(List<Model_Waybill_Base> waybillList) //{ // int result = 0; // try // { // //是否存在运单信息 // List<Model_Waybill_Base> numberList = GetExistWaybills(waybillList.Select(l => l.Number).Distinct().ToList()); // foreach (Model_Waybill_Base item in waybillList) // { // //查询unnecessary_node是否存在节点信息 // string sql = string.Format("select * from unnecessary_node where baseId='{0}' ;", item.Number); // List<Model_Waybill_Node> waybillnode = _SqlHelp.ExecuteObjects<Model_Waybill_Node>(sql); // if (waybillnode.Count != 0) // { // //获取id // int baseId = numberList.Find(l => l.Number == item.Number).Id; // foreach (Model_Waybill_Node node in waybillnode) // { // //节点信息超过一个月就删除 // if (node.operateAt.AddMonths(1) > item.BeginAt) // { // sql = string.Format("insert into waybill_node (baseId,operateAt,storageId,storageName,content,arrived) values('{0}','{1}','{2}','{3}','{4}','{5}') ;", // baseId, node.operateAt, node.StorageId, node.StorageName, node.Content, (int)node.Arrived); // result = _SqlHelp.ExecuteNonQuery(sql); // //添加成功后删除节点 // if (result > 0) // { // sql = string.Format("delete from unnecessary_node where id={0} ", node.Id); // _SqlHelp.ExecuteNonQuery(sql); // } // } // else // { // sql = string.Format("delete from unnecessary_node where id={0} ", node.Id); // _SqlHelp.ExecuteNonQuery(sql); // } // } // } // } // } // catch (Exception ex) // { // throw ex; // } // return result; //} /// <summary> /// 上传图片,插入签收拍照信息 /// </summary> /// <param name="postback">签收拍照信息</param> /// <param name="postbackTime">签收拍照时间</param> /// <param name="picList">图片列表</param> /// <returns></returns> public static bool UploadWaybill_Postbacks(Model_Waybill_Postback_Pic postback, DateTime postbackTime, List <object> picList, int customerId = 0) { LogServer.AddLogText(string.Format("开始进入保存图片逻辑{0},DateTime:{1}", postback.BaseId, postbackTime), postback.BaseId); bool result = false; int picIndex = 0;//成功上传的图片数量 if (picList.Count == 0) { LogServer.AddLogText(string.Format("图片列表{0}", picList.Count), postback.BaseId); return(false); } if (string.IsNullOrEmpty(postback.PicName)) { LogServer.AddLogText(string.Format("图片名称{0}", postback.PicName), postback.BaseId); return(false); } string[] picNameArr = postback.PicName.Split('|'); if (picNameArr.Length != picList.Count) { LogServer.AddLogText(string.Format("picNameArr:{0},picList:{1}", picNameArr.Length, picList.Count), postback.BaseId); return(false); } //配置文件中的路径 string filePath = string.Empty; string tempPath = System.Configuration.ConfigurationManager.AppSettings["PostbackPath"]; if (string.IsNullOrEmpty(tempPath)) { LogServer.AddLogText(string.Format("配置文件路径:{0}", tempPath), postback.BaseId); return(false); } string timePath = DateTime.Now.ToString("yyyyMM"); filePath = tempPath + "\\" + timePath; try { string sql = string.Empty; string number = postback.BaseId;//PDA传过来的BaseId就是运单号 //Customer=0为自运单,否则为第三方运单 if (customerId != 0) { //第三方运单需要查询关系表获取转换后的运单号 sql = "select number from huadong_tmsorder_waybillbase where relationid='" + number + "' and customerId=" + customerId; number = _SqlHelp.ExecuteScalar <string>(sql); LogServer.AddLogText(string.Format("查询关联表,huadong_tmsorder_waybillbase:{0},结果:{1}", sql, number), postback.BaseId); if (string.IsNullOrEmpty(number)) { string remark = "运单[" + (string.IsNullOrEmpty(number) ? postback.BaseId : number) + "]不存在"; remark += "传入的CustomerId=" + customerId; if (!System.IO.Directory.Exists(filePath)) { System.IO.Directory.CreateDirectory(filePath); } StringBuilder pic = new StringBuilder("insert into temporarypictures(baseId,operateAt,PicName,remarks,inserttime) values "); for (int i = 0; i < picList.Count; i++) { string fileName = postback.BaseId + "_" + System.IO.Path.GetFileName(postback.PicName.Split('|')[i]); MyTool.SaveImage(MyTool.GetGzipPicBytes(picList[i] as byte[]), filePath + "\\" + fileName); pic.AppendFormat("('{0}', '{1}', '{2}', '{3}', '{4}'),", postback.BaseId, postbackTime.ToString("yyyy-MM-dd HH:mm:ss"), timePath + "/" + fileName, remark, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //picIndex++; } pic.Length -= 1; List <string> sqlpicList = new List <string>(); sqlpicList.Add(pic.ToString()); bool pictures = _SqlHelp.ExecuteTranstration(sqlpicList); LogServer.AddLogText(string.Format("sql:{0},结果:{1}", sql, pictures), postback.BaseId); return(true); } } Model_Waybill_Base waybillBase = null;//根据运单号获取到BaseId sql = "select * from waybill_base where number = '" + number + "' order by id desc limit 1"; waybillBase = _SqlHelp.ExecuteObject <Model_Waybill_Base>(sql); if (waybillBase == null) { string remark = "运单[" + (string.IsNullOrEmpty(number) ? postback.BaseId : number) + "]不存在"; remark += "传入的CustomerId=" + customerId; if (!System.IO.Directory.Exists(filePath)) { System.IO.Directory.CreateDirectory(filePath); } StringBuilder pic = new StringBuilder("insert into temporarypictures(baseId,operateAt,PicName,remarks,inserttime) values "); for (int i = 0; i < picList.Count; i++) { string fileName = postback.BaseId + "_" + System.IO.Path.GetFileName(postback.PicName.Split('|')[i]); MyTool.SaveImage(MyTool.GetGzipPicBytes(picList[i] as byte[]), filePath + "\\" + fileName); pic.AppendFormat("('{0}', '{1}', '{2}', '{3}', '{4}'),", postback.BaseId, postbackTime.ToString("yyyy-MM-dd HH:mm:ss"), timePath + "/" + fileName, remark, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //picIndex++; } pic.Length -= 1; List <string> sqlpicList = new List <string>(); sqlpicList.Add(pic.ToString()); bool pictures = _SqlHelp.ExecuteTranstration(sqlpicList); LogServer.AddLogText(string.Format("查询运单,waybill_base:{0},结果:{1}", sql, waybillBase == null ? "未查询到信息" : waybillBase.Number), postback.BaseId); return(true);//运单还未上传,无法上传签收图片 } //List<Model_Waybill_Base> numberList = GetExistWaybills(new List<string> { postback.BaseId }).Distinct().ToList(); //if (numberList.Count == 0) // return true;//运单还未上传,无法上传签收图片 if (!System.IO.Directory.Exists(filePath)) { System.IO.Directory.CreateDirectory(filePath); } StringBuilder sb = new StringBuilder("insert into waybill_postback_pic (baseId,picName) values "); for (int i = 0; i < picList.Count; i++) { string fileName = postback.BaseId + "_" + System.IO.Path.GetFileName(postback.PicName.Split('|')[i]); MyTool.SaveImage(MyTool.GetGzipPicBytes(picList[i] as byte[]), filePath + "\\" + fileName); sb.AppendFormat("('{0}','{1}'),", waybillBase.Id, timePath + "/" + fileName); picIndex++; } sb.Length -= 1; List <string> sqlList = new List <string>(); sqlList.Add(sb.ToString()); sqlList.Add(string.Format("update waybill_base set picPostbackAt='{0}' where number='{1}'", postbackTime.ToString("yyyy-MM-dd HH:mm:ss"), waybillBase.Number)); result = _SqlHelp.ExecuteTranstration(sqlList); foreach (string item in sqlList) { LogServer.AddLogText(string.Format("sql:{0}", item), postback.BaseId); } LogServer.AddLogText(string.Format("保存结果:{0}", result), postback.BaseId); } catch (Exception ex) { LogServer.AddLogText("保存图片失败:" + ex.Message, postback.BaseId); throw ex; } finally { if (result == false && picIndex > 0) { //失败时删除图片 for (int i = picIndex; i > 0; i--) { string fileName = postback.BaseId + "_" + System.IO.Path.GetFileName(postback.PicName.Split('|')[i - 1]); System.IO.File.Delete(filePath + "\\" + fileName); LogServer.AddLogText(string.Format("失败时删除图片,路径:{0}", filePath + "\\" + fileName), postback.BaseId); } } } return(result); }