【牛尾】培训计划达成率查询优化

master
Tiobon 3 weeks ago
parent c964aec330
commit 5ccffdf7e3
  1. 2
      Tiobon.Core.Model/ViewModels/Extend/UshioPlanReport.cs
  2. 24
      Tiobon.Core.Services/Ghre/Ghre_PlanServices.cs

@ -33,7 +33,7 @@ public class UshioPlanReport : Ghre_PlanDto
public class Ushio_ExternalTrainApply public class Ushio_ExternalTrainApply
{ {
public int TrainDays { get; set; } = 0; public int? TrainDays { get; set; } = 0;
public DateTime BeginDate { get; set; } public DateTime BeginDate { get; set; }
public DateTime EndDate { get; set; } public DateTime EndDate { get; set; }
} }

@ -237,7 +237,7 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr
var inPlanIds = result.result.DT_TableDataT1.Where(x => x.InOrOut == "In").Select(x => x.Id).ToList(); var inPlanIds = result.result.DT_TableDataT1.Where(x => x.InOrOut == "In").Select(x => x.Id).ToList();
var outPlanIds = result.result.DT_TableDataT1.Where(x => x.InOrOut == "Out").Select(x => x.Id).ToList(); var outPlanIds = result.result.DT_TableDataT1.Where(x => x.InOrOut == "Out").Select(x => x.Id).ToList();
int? year = null; int? year1 = null;
if (filter.jsonParam != null) if (filter.jsonParam != null)
foreach (JProperty jProperty in filter.jsonParam.Properties()) foreach (JProperty jProperty in filter.jsonParam.Properties())
{ {
@ -247,7 +247,7 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr
{ {
var jsonParam = JsonHelper.JsonToObj<JsonParam>(value); var jsonParam = JsonHelper.JsonToObj<JsonParam>(value);
year = jsonParam.columnValue.ObjToInt(); year1 = jsonParam.columnValue.ObjToInt();
} }
} }
@ -264,12 +264,13 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr
.GroupBy(q => new { q.Id, q.PlanId, q.ExamDate }) .GroupBy(q => new { q.Id, q.PlanId, q.ExamDate })
.Select(m => new { m.PlanId, ExamDate = m.ExamDate.Value, Count = SqlFunc.AggregateCount(m.Id) }) .Select(m => new { m.PlanId, ExamDate = m.ExamDate.Value, Count = SqlFunc.AggregateCount(m.Id) })
.ToListAsync(); .ToListAsync();
studyRecordGroup1 = studyRecordGroup1.Where(x => x.ExamDate.Year == year).ToList(); studyRecordGroup1 = studyRecordGroup1.Where(x => x.ExamDate.Year == year1).ToList();
var data = Mapper.Map(result.result.DT_TableDataT1).ToANew<List<UshioPlanReport>>(); var data = Mapper.Map(result.result.DT_TableDataT1).ToANew<List<UshioPlanReport>>();
for (int i = 0; i < data.Count; i++)
data.ForEach(async d =>
{ {
var d = data[i];
int year = d.Year.Value; int year = d.Year.Value;
if (d.InOrOut == "In") if (d.InOrOut == "In")
{ {
@ -291,9 +292,10 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr
if (await QueryCompanyCode() == "Ushio") if (await QueryCompanyCode() == "Ushio")
{ {
var sql = $"select TrainDays,BeginDate,EndDate from [120.26.205.42].[GhrUshio].[dbo].Ushio_ExternalTrainApply where TrainNeeds like '%{d.Id}%'"; var sql = $"select CAST( TrainDays as int) TrainDays, CAST( BeginDate as datetime) BeginDate, CAST( EndDate as datetime) EndDate from [120.26.205.42].[GhrUshio].[dbo].Ushio_ExternalTrainApply where TrainNeeds like '%{d.Id}%' and TrainDays is not null and TrainDays !=''";
var applys = await DbAccess.QueryListAsync<Ushio_ExternalTrainApply>(sql); //var applys = await DbAccess.QueryListAsync<Ushio_ExternalTrainApply>(sql);
var applys = await Db.Ado.SqlQueryAsync<Ushio_ExternalTrainApply>(sql);
d.M1_Count = applys.Where(x => x.BeginDate.Year == year && x.BeginDate.Month == 1).Sum(x => x.TrainDays); d.M1_Count = applys.Where(x => x.BeginDate.Year == year && x.BeginDate.Month == 1).Sum(x => x.TrainDays);
d.M2_Count = applys.Where(x => x.BeginDate.Year == year && x.BeginDate.Month == 2).Sum(x => x.TrainDays); d.M2_Count = applys.Where(x => x.BeginDate.Year == year && x.BeginDate.Month == 2).Sum(x => x.TrainDays);
@ -349,7 +351,7 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr
d.M12_CompletionRate = d.M12_Count / d.TrainNum; d.M12_CompletionRate = d.M12_Count / d.TrainNum;
}); }
ModuleParam param = new ModuleParam() ModuleParam param = new ModuleParam()
{ {
@ -361,7 +363,7 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr
result1.result.JM_TableColumnT1 = module.Data.JM_TableColumnT1; result1.result.JM_TableColumnT1 = module.Data.JM_TableColumnT1;
var yearField = module.Data.JM_TableColumnT1.TableColumn.Where(x => x.field == "Year").SingleOrDefault(); var yearField = module.Data.JM_TableColumnT1.TableColumn.Where(x => x.field == "Year").SingleOrDefault();
if (year != yearField?.searchColumnDefaultValue.ObjToInt()) if (year1 != yearField?.searchColumnDefaultValue.ObjToInt())
{ {
result1.result.JM_TableColumnT1.TableColumn?.ForEach(x => result1.result.JM_TableColumnT1.TableColumn?.ForEach(x =>
@ -370,9 +372,9 @@ public class Ghre_PlanServices : BaseServices<Ghre_Plan, Ghre_PlanDto, InsertGhr
{ {
int month = x.field.Replace("M", null).Replace("_F", null).ObjToInt(); int month = x.field.Replace("M", null).Replace("_F", null).ObjToInt();
x.label = year + "-" + (month < 10 ? "0" + month : month); x.label = year1 + "-" + (month < 10 ? "0" + month : month);
if (month == 12) if (month == 12)
year++; year1++;
} }
}); });
} }

Loading…
Cancel
Save