Commit cf5a051b by 陶然

新增部门收入分析接口

parent 5729c8c9
......@@ -392,4 +392,38 @@ namespace Kivii.Finances.Transforms
return rtns;
}
}
[Api(Description = "部门收入分析")]
[RequiresAnyRole(SystemRoles.Everyone)]
public class PaymentGroupYearAnalysis : RestfulExecution<Payment>
{
public string Year { get; set; }
public Guid OwnerKvid { get; set; }
public List<Guid> OwnerKvids { get; set; }
public override object OnExecution(IRequest req, IResponse res)
{
Year.ThrowIfNullOrEmpty("请传入收入年份");
if (OwnerKvids.IsNullOrEmpty()) OwnerKvids = new List<Guid>();
if (OwnerKvid != Guid.Empty) OwnerKvids.Add(OwnerKvid);
var conn = KiviiContext.GetOpenedDbConnection<Payment>();
var query = conn.From<Payment>();
query.Where(o => o.AuditorName == Year && o.OffsetKvid == Guid.Empty && o.Type == PaymentType.Split);
if (!OwnerKvids.IsNullOrEmpty()) query.And(o => Sql.In(o.OwnerKvid, OwnerKvids));
query.GroupBy(o => new { o.OwnerName, o.AuditorName });
query.Select(o => new
{
AuditorName = o.AuditorName,
OwnerName = o.OwnerName,
Amount=Sql.Sum(o.Amount)
});
var rtns = new RestfulQueryResponse<Payment>();
rtns.Results = conn.Select(query);
rtns.Total = rtns.Results.Count;
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