Commit a885acfd by 陶然

优化

parent f6b484f1
......@@ -37,5 +37,5 @@ using System.Runtime.InteropServices;
//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
//通过使用 "*",如下所示:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.2023.10080")]
[assembly: AssemblyFileVersion("5.4.2023.10080")]
[assembly: AssemblyVersion("5.4.2024.2280")]
[assembly: AssemblyFileVersion("5.4.2024.2280")]
......@@ -4,6 +4,7 @@ using Kivii.Web;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Policy;
......@@ -813,4 +814,80 @@ namespace Kivii.Samples.Transforms
}
}
[RequiresAnyRole(SystemRoles.Everyone)]
[Api(Description = "样品联合路由查询")]
public class SampleQueryEx : RestfulExecution<Sample>
{
#region QueryArgs
//public virtual int? Skip { get; set; }
//public virtual int? Take { get; set; }
public virtual string OrderBy { get; set; }
public string OrderByDesc { get; set; }
public virtual string Include { get; set; }
public virtual string Fields { get; set; }
public string QueryKeys { get; set; }
public string QueryValues { get; set; }
#endregion
public Guid LocationKvid { get; set; }
public string LocationInternalCode { get; set; }
public DateTime RouteBeginTime { get; set; }
public DateTime RouteEndTime { get; set; }
public override object OnExecution(IRequest req, IResponse res)
{
int monthDay = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
if (RouteBeginTime == DateTime.MinValue) RouteBeginTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
if (RouteEndTime == DateTime.MinValue) RouteEndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, monthDay);
var beginTime = DateTime.Parse(RouteBeginTime.ToString("yyyy-MM-dd"));
var endTime = DateTime.Parse(RouteEndTime.ToString("yyyy-MM-dd"));
if (endTime < beginTime) throw new Exception("查询结束日期不可小于开始日期!");
var conn = KiviiContext.GetOpenedDbConnection<Sample>();
Location location = null;
if (LocationKvid != Guid.Empty) location = conn.SingleById<Location>(LocationKvid);
if (location == null)
{
if (!LocationInternalCode.IsNullOrEmpty()) location = conn.Single<Location>(o => o.InternalCode == LocationInternalCode);
//location.ThrowIfNull("未找到指定的地点信息!");
}
var dynamicParams = Request.GetRequestParams();
var autoQuery = Request.TryResolve<IAutoQueryDb>();
autoQuery.IncludeTotal = true;
var request = new RestfulQuery<Sample>();
request = request.PopulateWith(this);
var sqlExpress = autoQuery.CreateQuery(Request, conn, request, dynamicParams);
sqlExpress.Rows = null;
sqlExpress.LeftJoin<Route>((s, r) => s.Kvid == r.SampleKvid);
if (location != null) sqlExpress.Where<Route>(o => o.CurrentLocationKvid == location.Kvid);
if (beginTime != DateTime.MinValue) sqlExpress.Where<Route>(o => o.OperateTime >= beginTime);
if (endTime != DateTime.MinValue) sqlExpress.Where<Route>(o => o.OperateTime < endTime);
sqlExpress.Select<Route, Sample>((r, s) => new
{
BizId = r.BizId,
s.DealTime,
s.DeadTime,
Name = r.SampleName,
PackageName=r.Title,
OperateTime=r.OperateTime,
Summary=r.Summary,
s.Kvid
});
var rtns = autoQuery.Execute(Request, conn, request, sqlExpress);
return rtns;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment