#region 存栏统计
/// <summary>
/// 存栏统计
/// </summary>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async Task<IEnumerable<InventoryStatisticsDto>> ShowInventoryStatistics(string? Generic,int Variety,DateTime? KDate, DateTime? JDate)
{
using (IDbConnection dbConnection = Connection)
{
try
{
dbConnection.Open();
var data = $"SELECT {Generic} aaa, COUNT(c.BuildingName) Beginning," +
$"COUNT(sr.ShiftToBuild)RuRoundup, " +
$"COUNT(dt.TransferDate) RuReplanting," +
$"COUNT(lrm.BirthDate) Ruborn," +
$"COUNT(sr.TurnOutBuild) ChuRoundup, " +
$"COUNT(dm.DeathType) Chudeath," +
$"COUNT(em.DepartureState) Chueliminate," +
$"COUNT(ss.SaleDate) Rureturn," +
$"COUNT(pf.DateOfPurchase) Ruprocurement," +
$"COUNT(c.BuildingName) Beginning ," +
$"COUNT(CASE WHEN sf.PresenceState = 3 THEN 1 ELSE NULL END) AS chusale " +
$"FROM " +
$"SheepFileModel sf full JOIN " +
$"MaternalMating mm ON sf.EarTag = mm.EarTag full JOIN " +
$"BreedMaleAndFemaleStart bms ON bms.EarTag = sf.EarTag full JOIN " +
$"MaternalWeaning mw ON sf.EarTag = mw.EarTag full JOIN " +
$"LambAblactation la ON sf.EarTag = la.EarTag full JOIN " +
$"BodyMeasureModel bm ON sf.EarTag = bm.EarTag full JOIN " +
$"AppearanceModel am ON sf.EarTag = am.EarTag full JOIN " +
$"DeathModel dm ON sf.EarTag = dm.EarTag full JOIN " +
$"SheepRescission sr ON sf.EarTag = sr.EarTag full JOIN " +
$"BreedingHistoryModel bh ON sf.EarTag = bh.EarTag full JOIN " +
$"PregnancytestModel pt ON sf.EarTag = pt.EarTag full JOIN " +
$"ParturitionModel p ON sf.EarTag = p.EarTag full JOIN " +
$"SheepSaleModels ss ON sf.EarTag = ss.EarTag full JOIN " +
$"EliminationModel em ON sf.EarTag = em.EarTag full JOIN " +
$"DescendantTransfer dt ON sf.EarTag = dt.EarTag full JOIN " +
$"MarkModel er ON sf.EarTag = er.EarTag full JOIN " +
$"LambRegistrationModel lrm on lrm.EarTag = sf.EarTag full JOIN " +
$"EarTagOrMarkModel eom ON er.MarkId = eom.MarkId full JOIN " +
$"PurchaseFormModels pf on sf.EarTag = pf.BatchEarHorns full JOIN " +
$"EarTagModel etm ON eom.EarTagId = etm.EarTagId full JOIN " +
$"SheepRescission b ON sf.EarTag = b.EarTag full JOIN " +
$"ColumnManagementModel c ON b.ShiftToBuildingManagementId = c.BuildingManagementId full JOIN " +
$"FieldModel d ON b.ShiftToColumnManagementId = d.ColumnManagementId full JOIN " +
$"ProductionGrading pr ON sf.EarTag = pr.RankEarTag WHERE 1=1 ";
if (Variety != 0)
{
data += $" AND sf.Variety = {Variety} ";
}
if (KDate.HasValue)
{
data += $" AND sf.AdmissionDate >= '{KDate?.ToString("yyyy-MM-dd HH:mm:ss")} ' ";
}
if (JDate.HasValue)
{
data += $" AND sf.AdmissionDate <= '{JDate?.ToString("yyyy-MM-dd HH:mm:ss")} ' ";
}
data += $" Group by {Generic} ";
int ps = 1;
return await dbConnection.QueryAsync<InventoryStatisticsDto>(data);
}
catch (Exception)
{
throw;
}
finally
{
dbConnection.Close();
}
}
}
#endregion