代码同步

This commit is contained in:
木鱼(iFish) 2015-07-30 16:01:49 +08:00
parent 11e68fab14
commit 50d3123bfa
5 changed files with 59 additions and 52 deletions

View File

@ -1,4 +1,4 @@
namespace Web12306.Servers.TrainSuggestion namespace Web12306.Servers.TrainSuggestion
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -16,9 +16,9 @@ namespace Web12306.Servers.TrainSuggestion
#region Implementation of IHttpHandler #region Implementation of IHttpHandler
/// <summary> /// <summary>
/// 通过实现 <see cref="T:System.Web.IHttpHandler"/> 接口的自定义 HttpHandler 启用 HTTP Web 请求的处理。 /// 通过实现 <see cref="T:System.Web.IHttpHandler"/> 接口的自定义 HttpHandler 启用 HTTP Web 请求的处理。
/// </summary> /// </summary>
/// <param name="context"><see cref="T:System.Web.HttpContext"/> 对象,它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session 和 Server的引用。</param> /// <param name="context"><see cref="T:System.Web.HttpContext"/> 对象,它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session 和 Server的引用。</param>
public void ProcessRequest(HttpContext context) public void ProcessRequest(HttpContext context)
{ {
var request = context.Request; var request = context.Request;
@ -49,7 +49,7 @@ namespace Web12306.Servers.TrainSuggestion
context.Response.AddHeader("Access-Control-Allow-Origin", origin); context.Response.AddHeader("Access-Control-Allow-Origin", origin);
else else
{ {
//非法提交 //非法提交
return; return;
} }
} }
@ -80,12 +80,12 @@ namespace Web12306.Servers.TrainSuggestion
{ {
//log error //log error
var sb = new StringBuilder(); var sb = new StringBuilder();
sb.AppendLine(string.Format("请求URL {0}", context.Request.Url)); sb.AppendLine(string.Format("请求URL {0}", context.Request.Url));
sb.AppendLine("数据:"); sb.AppendLine("数据:");
sb.AppendLine(data); sb.AppendLine(data);
sb.AppendLine(); sb.AppendLine();
sb.AppendLine("错误信息:"); sb.AppendLine("错误信息:");
sb.AppendLine(ex.ToString()); sb.AppendLine(ex.ToString());
var log = DateTime.Now.Ticks + ".log"; var log = DateTime.Now.Ticks + ".log";
@ -115,16 +115,16 @@ namespace Web12306.Servers.TrainSuggestion
} }
/// <summary> /// <summary>
/// 获取一个值,该值指示其他请求是否可以使用 <see cref="T:System.Web.IHttpHandler"/> 实例。 /// 获取一个值,该值指示其他请求是否可以使用 <see cref="T:System.Web.IHttpHandler"/> 实例。
/// </summary> /// </summary>
/// <returns> /// <returns>
/// 如果 <see cref="T:System.Web.IHttpHandler"/> 实例可再次使用,则为 true否则为 false。 /// 如果 <see cref="T:System.Web.IHttpHandler"/> 实例可再次使用,则为 true否则为 false。
/// </returns> /// </returns>
public bool IsReusable { get { return true; } } public bool IsReusable { get { return true; } }
#endregion #endregion
#region #region
static JsonSerializerSettings _camelJsonSetting = new JsonSerializerSettings static JsonSerializerSettings _camelJsonSetting = new JsonSerializerSettings
{ {
@ -141,13 +141,13 @@ namespace Web12306.Servers.TrainSuggestion
SuggestionResponse GetSuggestionResponseContentCore(RequestInfo ri) SuggestionResponse GetSuggestionResponseContentCore(RequestInfo ri)
{ {
//预处理 //预处理
PreProcessRequestData(ri); PreProcessRequestData(ri);
//获得所有的可替换站点 //获得所有的可替换站点
var alllines = ri.Stops.Values.SelectMany(s => GetAlternativeLines(s, ri.Date) ?? new List<AlternativeLine>()).Where(s => s != null).ToArray(); var alllines = ri.Stops.Values.SelectMany(s => GetAlternativeLines(s, ri.Date) ?? new List<AlternativeLine>()).Where(s => s != null).ToArray();
//对线路进行分组排序 //对线路进行分组排序
var lineGrouped = alllines.GroupBy(s => s.LineName).Select(s => var lineGrouped = alllines.GroupBy(s => s.LineName).Select(s =>
{ {
var list = s.ToList(); var list = s.ToList();
@ -155,18 +155,18 @@ namespace Web12306.Servers.TrainSuggestion
return new AlternativeLineGroup(f.From.Name, f.To.Name, f.Date, list, f.IsCrossDate); return new AlternativeLineGroup(f.From.Name, f.To.Name, f.Date, list, f.IsCrossDate);
}).ToList(); }).ToList();
//过滤 //过滤
FilteAlternativeLine(ri, lineGrouped); FilteAlternativeLine(ri, lineGrouped);
//填充数据 //填充数据
FillExtraInfo(ri, lineGrouped); FillExtraInfo(ri, lineGrouped);
//排序 //排序
SortLineRecommand(ri, lineGrouped); SortLineRecommand(ri, lineGrouped);
return new SuggestionResponse() return new SuggestionResponse()
{ {
Key = "盗用可耻鄙视无耻的各个国产IT同行", Key = "盗用可耻鄙视无耻的各个国产IT同行",
Accepted = true, Accepted = true,
Groups = lineGrouped Groups = lineGrouped
}; };
@ -187,10 +187,10 @@ namespace Web12306.Servers.TrainSuggestion
for (var j = line[i].Lines.Count - 1; j >= 0; j--) for (var j = line[i].Lines.Count - 1; j >= 0; j--)
{ {
var current = line[i].Lines[j]; var current = line[i].Lines[j];
//如果同时是发站和到站,则删除不推荐 //如果同时是发站和到站,则删除不推荐
if (current.From.IsOriginal && current.To.IsOriginal) if (current.From.IsOriginal && current.To.IsOriginal)
line[i].Lines.RemoveAt(j); line[i].Lines.RemoveAt(j);
//如果时间会超过原来最大的允许值,则排除 //如果时间会超过原来最大的允许值,则排除
else if (current.ElapsedTime > maxAllowElapsedTime) else if (current.ElapsedTime > maxAllowElapsedTime)
line[i].Lines.RemoveAt(j); line[i].Lines.RemoveAt(j);
} }
@ -202,7 +202,7 @@ namespace Web12306.Servers.TrainSuggestion
} }
/// <summary> /// <summary>
/// 根据停靠站获得权重 /// 根据停靠站获得权重
/// </summary> /// </summary>
/// <param name="lineList"></param> /// <param name="lineList"></param>
/// <returns></returns> /// <returns></returns>
@ -231,14 +231,14 @@ namespace Web12306.Servers.TrainSuggestion
if (x.Lines.Count != y.Lines.Count) if (x.Lines.Count != y.Lines.Count)
return y.Lines.Count - x.Lines.Count; return y.Lines.Count - x.Lines.Count;
//再看停靠时间 //再看停靠时间
var ep1 = (int)x.Lines.Min(s => s.From.StopTime + s.To.StopTime).TotalSeconds; var ep1 = (int)x.Lines.Min(s => s.From.StopTime + s.To.StopTime).TotalSeconds;
var ep2 = (int)y.Lines.Min(s => s.From.StopTime + s.To.StopTime).TotalSeconds; var ep2 = (int)y.Lines.Min(s => s.From.StopTime + s.To.StopTime).TotalSeconds;
if (ep1 != ep2) if (ep1 != ep2)
return ep2 - ep1; return ep2 - ep1;
//再看价格 //再看价格
var ap1 = x.Lines.Min(s => s.Radio); var ap1 = x.Lines.Min(s => s.Radio);
var ap2 = y.Lines.Min(s => s.Radio); var ap2 = y.Lines.Min(s => s.Radio);
if (ap1 != ap2) if (ap1 != ap2)
@ -246,22 +246,22 @@ namespace Web12306.Servers.TrainSuggestion
return 0; return 0;
}); });
//最多推荐5条线路 //最多推荐5条线路
if (line.Count > 5) if (line.Count > 5)
line.RemoveRange(5, line.Count - 5); line.RemoveRange(5, line.Count - 5);
//再对组内排序 //再对组内排序
foreach (var current in line) foreach (var current in line)
{ {
current.Lines.Sort((x, y) => current.Lines.Sort((x, y) =>
{ {
//再看停靠时间 //再看停靠时间
var ep1 = (int)(x.From.StopTime + x.To.StopTime).TotalSeconds; var ep1 = (int)(x.From.StopTime + x.To.StopTime).TotalSeconds;
var ep2 = (int)(y.From.StopTime + y.To.StopTime).TotalSeconds; var ep2 = (int)(y.From.StopTime + y.To.StopTime).TotalSeconds;
if (ep1 != ep2) if (ep1 != ep2)
return ep2 - ep1; return ep2 - ep1;
//再看价格 //再看价格
var ap1 = (int)x.ExtraPrice; var ap1 = (int)x.ExtraPrice;
var ap2 = (int)y.ExtraPrice; var ap2 = (int)y.ExtraPrice;
if (ap1 != ap2) if (ap1 != ap2)
@ -281,7 +281,7 @@ namespace Web12306.Servers.TrainSuggestion
var train = ri.Stops[line[i].Lines[j].TrainCode]; var train = ri.Stops[line[i].Lines[j].TrainCode];
var current = line[i].Lines[j]; var current = line[i].Lines[j];
var originalTime = train.TrainInfo.elapsedTime.Value; var originalTime = train.TrainInfo.elapsedTime.Value;
//如果时间会超过原来最大的允许值,则排除 //如果时间会超过原来最大的允许值,则排除
var priceExtraRadio = ((current.ElapsedTime - originalTime).TotalSeconds / (1.0 * originalTime.TotalSeconds)); var priceExtraRadio = ((current.ElapsedTime - originalTime).TotalSeconds / (1.0 * originalTime.TotalSeconds));
current.BasePriceSeat = Cn12306SuggestionUtility.BaseSeatCodes.First(s => train.TrainInfo.ticketMap.ContainsKey(s)); current.BasePriceSeat = Cn12306SuggestionUtility.BaseSeatCodes.First(s => train.TrainInfo.ticketMap.ContainsKey(s));
current.BasePrice = train.TrainInfo.ticketMap[current.BasePriceSeat].price / 10.0; current.BasePrice = train.TrainInfo.ticketMap[current.BasePriceSeat].price / 10.0;
@ -312,20 +312,20 @@ namespace Web12306.Servers.TrainSuggestion
var arriveTime = stops[indexFrom].ArriveTime; var arriveTime = stops[indexFrom].ArriveTime;
for (var i = 0; i < indexFrom; i++) for (var i = 0; i < indexFrom; i++)
{ {
//如果isEnabled为true则说明会停靠这个站点。不能推荐更短的。 //如果isEnabled为true则说明会停靠这个站点。不能推荐更短的。
//如果时间过久,则不做推荐 //如果时间过久,则不做推荐
if (stops[i].isEnabled || stops[i].StartTime - arriveTime > maxAddTime) if (stops[i].isEnabled || stops[i].StartTime - arriveTime > maxAddTime)
continue; continue;
var stopTime = i == 0 ? TimeSpan.Zero : stops[i].StopTime; var stopTime = i == 0 ? TimeSpan.Zero : stops[i].StopTime;
if (i != 0) if (i != 0)
{ {
//对于非始发站,停靠时间相同或更短,则不做推荐。 //对于非始发站,停靠时间相同或更短,则不做推荐。
if (stopTime < stopTimeFrom && i < indexFrom - 3) if (stopTime < stopTimeFrom && i < indexFrom - 3)
continue; continue;
} }
//添加到推荐列表中 //添加到推荐列表中
altFrom.Add(new AlternativeStation() altFrom.Add(new AlternativeStation()
{ {
ArriveTime = stops[i].StartTime, ArriveTime = stops[i].StartTime,
@ -340,7 +340,7 @@ namespace Web12306.Servers.TrainSuggestion
}); });
} }
//排序 //排序
altFrom.Sort(new AlternativeStationComparer()); altFrom.Sort(new AlternativeStationComparer());
if (altFrom.Count > 5) if (altFrom.Count > 5)
altFrom.RemoveRange(5, altFrom.Count - 5); altFrom.RemoveRange(5, altFrom.Count - 5);
@ -352,20 +352,20 @@ namespace Web12306.Servers.TrainSuggestion
for (var i = stops.Length - 1; i >= indexTo; i--) for (var i = stops.Length - 1; i >= indexTo; i--)
{ {
//如果isEnabled为true则说明会停靠这个站点。不能推荐更短的。 //如果isEnabled为true则说明会停靠这个站点。不能推荐更短的。
//如果时间过久,则不做推荐 //如果时间过久,则不做推荐
if (stops[i].isEnabled || stops[i].ArriveTime - startTime > maxAddTime) if (stops[i].isEnabled || stops[i].ArriveTime - startTime > maxAddTime)
continue; continue;
var stopTime = i == 0 ? TimeSpan.Zero : stops[i].StopTime; var stopTime = i == 0 ? TimeSpan.Zero : stops[i].StopTime;
if (i != stops.Length - 1) if (i != stops.Length - 1)
{ {
//对于非终到站,停靠时间相同或更短,则不做推荐。 //对于非终到站,停靠时间相同或更短,则不做推荐。
if (stopTime < stopTimeTo && i > indexTo + 3) if (stopTime < stopTimeTo && i > indexTo + 3)
continue; continue;
} }
//添加到推荐列表中 //添加到推荐列表中
altTo.Add(new AlternativeStation() altTo.Add(new AlternativeStation()
{ {
ArriveTime = stops[i].ArriveTime, ArriveTime = stops[i].ArriveTime,
@ -381,7 +381,7 @@ namespace Web12306.Servers.TrainSuggestion
if (altTo.Count > 5) if (altTo.Count > 5)
altTo.RemoveRange(5, altTo.Count - 5); altTo.RemoveRange(5, altTo.Count - 5);
} }
//plus 原始线路 //plus 原始线路
altFrom.Add(new AlternativeStation altFrom.Add(new AlternativeStation
{ {
ArriveTime = stops[indexFrom].StartTime, ArriveTime = stops[indexFrom].StartTime,

View File

@ -35,7 +35,7 @@
<add key="12306_trainsuggestion_maxradio" value="0.7" /> <add key="12306_trainsuggestion_maxradio" value="0.7" />
<add key="dataStoragePath" value="~/App_Data/12306" /> <add key="dataStoragePath" value="~/App_Data/12306" />
<add key="12306_keepaliveurl" value="http://test.fishlee.net/tt/keepalive" /> <add key="12306_keepaliveurl" value="http://test.fishlee.net/tt/keepalive" />
<add key="local_disable_train_provider" value="0" /> <add key="local_disable_train_provider" value="1" />
<add key="FSLib.MvcWeb.CsrfDefender.Disabled" value="1" /> <add key="FSLib.MvcWeb.CsrfDefender.Disabled" value="1" />
<add key="web_proxy" value="http://connect.fishlee.net:51100/" /> <add key="web_proxy" value="http://connect.fishlee.net:51100/" />

View File

@ -222,8 +222,8 @@
line-height: 20px; line-height: 20px;
margin-top: 16px;*/ margin-top: 16px;*/
position: absolute; position: absolute;
right: 0; right: 10px;
top: 0; top: 5px;
font-size: 14px; font-size: 14px;
color: #8d5000; color: #8d5000;
text-decoration: underline; text-decoration: underline;

View File

@ -13,19 +13,19 @@
return; return;
console.log.apply(console, arguments); console.log.apply(console, arguments);
}; };
exports.stationReportApi = "http://srv.12306.liebao.cn/tt/ls2"; exports.stationReportApi = "http://srv.12306.liebao.cn/st/ls2";
exports.trainSuggestApi = "http://srv.12306.liebao.cn/ts"; exports.trainSuggestApi = "http://srv.12306.liebao.cn/ets.axd";
exports.onceTransitApi = "http://srv.12306.liebao.cn/tt/tor"; exports.onceTransitApi = "http://srv.12306.liebao.cn/st/tor";
exports.chatServerGetAddressApi = "http://12306.liebao.cn/index.php?r=Api/GetRoomKey"; //exports.chatServerGetAddressApi = "http://12306.liebao.cn/index.php?r=Api/GetRoomKey";
exports.chatReportUrl = "http://12306.liebao.cn/index.php?r=Api/AbuseReport"; //exports.chatReportUrl = "http://12306.liebao.cn/index.php?r=Api/AbuseReport";
exports.sysNoticeUrl = "http://12306.liebao.cn/index.php?r=Api/GetNotificationList"; exports.sysNoticeUrl = "http://srv.12306.liebao.cn/announcement/list";
if (local) { //if (local) {
exports.trainSuggestApi = "/ts.axd"; // exports.trainSuggestApi = "/ts.axd";
exports.onceTransitApi = "/tt/tor"; // exports.onceTransitApi = "/tt/tor";
exports.sysNoticeUrl = "http://chatdev.fishlee.net/announcement/list"; // exports.sysNoticeUrl = "http://chatdev.fishlee.net/announcement/list";
exports.chatReportUrl = "http://chatdev.fishlee.net/api/users/report"; // exports.chatReportUrl = "http://chatdev.fishlee.net/api/users/report";
} //}
exports.sysNoticeLoadInterval = 30 * 60 * 1800; exports.sysNoticeLoadInterval = 30 * 60 * 1800;
exports.sysNoticeMaxShowCount = 3; exports.sysNoticeMaxShowCount = 3;

View File

@ -157,13 +157,20 @@
} }
if (media && media.length) { if (media && media.length) {
var tip = new mp.MessagePopup("loading", "正在上传图片,请稍等...");
tip.show();
//带有图片 //带有图片
$.post("http://12306.liebao.cn/index.php?r=UpdateImage/GetImageUrl", { data: media[0].data }) $.post("http://12306.liebao.cn/index.php?r=UpdateImage/GetImageUrl", { data: media[0].data })
.done(function (json) { .done(function (json) {
tip.close();
if (json.resCode === 0) { if (json.resCode === 0) {
data.images.push(json.data.img_url); data.images.push(json.data.img_url);
port.postMessage("chatRoomSendMsg", coder.encode(data)); port.postMessage("chatRoomSendMsg", coder.encode(data));
} }
}).fail(function () {
tip.setState("error", "图片上传失败:服务器开小差了....");
tip.delayClose();
}); });
} else { } else {
port.postMessage("chatRoomSendMsg", coder.encode(data)); port.postMessage("chatRoomSendMsg", coder.encode(data));