You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/Areas/Dispatch/Helper/DispatchHelper.cs

141 lines
6.0 KiB
C#

3 years ago

using DSWeb.Areas.Dispatch.DB;
using DSWeb.Areas.Dispatch.Models;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Web;
namespace DSWeb.Areas.Dispatch.Helper
{
public static class DispatchHelper
{
private static string appid = ConfigurationManager.AppSettings["BeitongDispatchAppId"];
private static string dispatchServerUrl = ConfigurationManager.AppSettings["BeitongDispatchServerUrl"];
/// <summary>
/// 抢单
/// </summary>
/// <param name="leid"></param>
/// <returns></returns>
public static bool SendDispacthMessage(string leid, out string message)
{
DataContext dataContext = new DataContext();
var query = from i in dataContext.InfoClients
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<Tuple<string, string, string>> values = new List<Tuple<string, string, string>>();
// values.Add(new Tuple<string, string, string>("TITLE", "您有一条新的抢单通知", "#FF0000"));
// values.Add(new Tuple<string, string, string>("XX", truckInfo.CTNS, ""));
// values.Add(new Tuple<string, string, string>("DW", truckInfo.KGS, ""));
// values.Add(new Tuple<string, string, string>("ZHSJ", truckInfo.FACTRYTIME, ""));
// values.Add(new Tuple<string, string, string>("JGSJ", truckInfo.CLOSINGDATE.HasValue ? truckInfo.CLOSINGDATE.Value.ToString("yyyy-MM-dd") : "", ""));
// values.Add(new Tuple<string, string, string>("GCDZ", truckInfo.FACTRYADDR, ""));
// values.Add(new Tuple<string, string, string>("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;
}
/// <summary>
/// 派车
/// </summary>
/// <param name="leid"></param>
/// <returns></returns>
public static bool DispacthMessage(string leid, out string message)
{
var PcWxTemplateID = MsSysParamSetDAL.GetData("PARAMNAME='PcWxTemplateID'").PARAMVALUE;
DataContext dataContext = new DataContext();
var truckInfo = dataContext.OpLetterTrucks.FirstOrDefault(t => t.LE_ID == leid);
var driver = dataContext.Drivers.FirstOrDefault(d => d.InfoClient == truckInfo.TRUCK);
var opseae = dataContext.OpSeaes.FirstOrDefault(o => o.BSNO == truckInfo.BSNO);
if (driver == null)
{
message = "所选车队没有已注册的司机";
return false;
}
//todo:发送消息
List<Tuple<string, string, string>> values = new List<Tuple<string, string, string>>();
values.Add(new Tuple<string, string, string>("first", "您有一条新的派车通知\r\n", ""));
values.Add(new Tuple<string, string, string>("keyword1", opseae.MBLNO, ""));
values.Add(new Tuple<string, string, string>("keyword2", truckInfo.FACTRYADDR, ""));
values.Add(new Tuple<string, string, string>("keyword3", truckInfo.FACTRYTIME, ""));
values.Add(new Tuple<string, string, string>("keyword4", $"{truckInfo.CTNS} {truckInfo.KGS}", ""));
values.Add(new Tuple<string, string, string>("keyword5", DateTime.Today.ToString("yyyy-MM-dd"), ""));
if (truckInfo.CLOSINGDATE.HasValue)
{
values.Add(new Tuple<string, string, string>("remark", $"截港时间:{truckInfo.CLOSINGDATE.Value.ToString("yyyy-MM-dd")}\r\n\r\n请按时到场站拉货", ""));
}
else
{
values.Add(new Tuple<string, string, string>("remark", $"请按时到场站拉货", ""));
}
string mess = string.Empty;
bool success = TemplateMessageHelper.SendTemplateMessage(appid, PcWxTemplateID, values, driver.OpenId, $"{dispatchServerUrl}/Dispatch/Dispatch/DispatchDetail?leid={truckInfo.LE_ID}&openid={driver.OpenId}", out mess);
if (!success)
{
message = mess;
return false;
}
else
{
message = "";
return true;
}
}
}
}