using DSWeb.Areas.Storage.DB;
using DSWeb.Areas.Storage.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
namespace DSWeb.Areas.Storage.Helper
{
public class StorageHelper
{
private static string appid = ConfigurationManager.AppSettings["BeitongDispatchAppId"];
private static string dispatchServerUrl = ConfigurationManager.AppSettings["BeitongDispatchServerUrl"];
///
/// 抢单
///
///
///
//public static bool SendIndoMessage(string leid, out string message)
//{
// DataContext dataContext = new DataContext();
// var query = from i in dataContext.IndoInfo
// join d in dataContext.Drivers on i.SHORTNAME equals d.InfoClient
// where i.ISTRUCK
// select new
// {
// d.OpenId,
// d.InfoClient
// };
// var infoList = query.ToList();
// var truckInfo = dataContext.OpLetterTrucks.FirstOrDefault(t => t.LE_ID == leid);
// //如果重复发电,删除先前的
// dataContext.Grabs.RemoveRange(dataContext.Grabs.Where(g => g.LE_ID == leid));
// //插入发单信息
// foreach (var item in infoList)
// {
// GrabInfo grab = new GrabInfo();
// grab.GID = Guid.NewGuid().ToString();
// grab.InfoClient = item.InfoClient;
// grab.LE_ID = truckInfo.LE_ID;
// grab.SendTime = DateTime.Now;
// grab.IsGrab = false;
// dataContext.Grabs.Add(grab);
// }
// dataContext.SaveChanges();
// StringBuilder sbErr = new StringBuilder();
// bool allSuccess = true;
// #region 微信禁止板消息群发,暂注释
// //保存完数据后,再发送消息
// //foreach (var item in infoList)
// //{
// // List> values = new List>();
// // values.Add(new Tuple("TITLE", "您有一条新的抢单通知", "#FF0000"));
// // values.Add(new Tuple("XX", truckInfo.CTNS, ""));
// // values.Add(new Tuple("DW", truckInfo.KGS, ""));
// // values.Add(new Tuple("ZHSJ", truckInfo.FACTRYTIME, ""));
// // values.Add(new Tuple("JGSJ", truckInfo.CLOSINGDATE.HasValue ? truckInfo.CLOSINGDATE.Value.ToString("yyyy-MM-dd") : "", ""));
// // values.Add(new Tuple("GCDZ", truckInfo.FACTRYADDR, ""));
// // values.Add(new Tuple("FOOTTER", "点击查看详情", "#0000FF"));
// // string mess = string.Empty;
// // bool success = TemplateMessageHelper.SendTemplateMessage(appid, "5zWCiYhS44naUs1dolJuMtAhzqvrfpdHUK6JQJdtkLw", values, item.OpenId, $"{dispatchServerUrl}/Dispatch/Dispatch/GrabDetail?leid={truckInfo.LE_ID}&openid={item.OpenId}", out mess);
// // if (!success)
// // {
// // sbErr.AppendLine(mess);
// // allSuccess = false;
// // }
// //}
// #endregion
// message = sbErr.ToString();
// return allSuccess;
//}
///
/// 派车
///
///
///
public static bool SendOutdoMessage(string wmsid, out string message)
{
DataContext dataContext = new DataContext();
var opseae = dataContext.OutdoInfo.FirstOrDefault(o => o.WMSID == wmsid);
//todo:发送消息
List> values = new List>();
values.Add(new Tuple("first", "您有一条新的出库通知\r\n", ""));
values.Add(new Tuple("keyword1", opseae.MBLNO, ""));
values.Add(new Tuple("keyword2", opseae.GOODSNAME, ""));
values.Add(new Tuple("keyword3", opseae.DODATE, ""));
values.Add(new Tuple("keyword4", $"{opseae.PKGS}", ""));
values.Add(new Tuple("keyword4", $"{opseae.KGS}", ""));
//values.Add(new Tuple("keyword5", DateTime.Today.ToString("yyyy-MM-dd"), ""));
//if (truckInfo.CLOSINGDATE.HasValue)
//{
// values.Add(new Tuple("remark", $"截港时间:{truckInfo.CLOSINGDATE.Value.ToString("yyyy-MM-dd")}\r\n\r\n请按时到场站拉货", ""));
//}
//else
//{
// values.Add(new Tuple("remark", $"请按时到场站拉货", ""));
//}
string mess = string.Empty;
bool success = TemplateMessageHelper.SendTemplateMessage(appid, "hHh9N9xY1sVK6d8wxS-ObEV-0gWsPh_iCR13K447VXU", values, "", $"{dispatchServerUrl}/Storage/Storage/StorageDetail?wmsid={wmsid}&openid={""}", out mess);
if (!success)
{
message = mess;
return false;
}
else
{
message = "";
return true;
}
}
}
}