using System.Linq; namespace BLL { public class HJGL_WeldingReportService { /// /// 根据类型获取总达因数(0总达因,1预制口总达因,2安装口总达因) /// /// /// 0总达因,1预制口总达因,2安装口总达因 /// public static decimal GetSumSize(string projectId, int type) { decimal result = 0; var getWelds = Funs.DB.HJGL_WeldJoint.Where(x => x.ProjectId == projectId); if (getWelds.Count() > 0) { switch (type) { case 0: result = getWelds.Sum(x => x.Size ?? 0); //项目总达因数 break; case 1: if (getWelds.Where(x => x.JointAttribute == "预制口").Count() > 0) { result = getWelds.Where(x => x.JointAttribute == "预制口").Sum(x => x.Size ?? 0); } break; case 2: if (getWelds.Where(x => x.JointAttribute == "安装口").Count() > 0) { result = getWelds.Where(x => x.JointAttribute == "安装口").Sum(x => x.Size ?? 0); } break; } } return result; } /// /// 工厂预制完成数 /// /// /// public static decimal GetGCRate_finished(string projectId) { decimal result = 0; var getWelds = Funs.DB.HJGL_WeldJoint.Where(x => x.ProjectId == projectId); if (getWelds.Count() > 0) { var getWeldsOk = getWelds.Where(x => x.WeldingDailyId != null); if (getWeldsOk.Count() > 0) { var GCModel = getWeldsOk.Where(x => x.JointAttribute == "预制口"); if (GCModel.Count() > 0) { result = GCModel.Sum(x => x.Size ?? 0); } } } return result; } /// /// 工厂预制未完成数 /// /// /// public static decimal GetGCRate_unfinished(string projectId) { decimal result = 0; result = GetSumSize(projectId, 1) - GetGCRate_finished(projectId); return result; } /// /// 现场施工完成数 /// /// /// public static decimal GetXCRate_finished(string projectId) { decimal result = 0; var getWelds = Funs.DB.HJGL_WeldJoint.Where(x => x.ProjectId == projectId); if (getWelds.Count() > 0) { var getWeldsOk = getWelds.Where(x => x.WeldingDailyId != null); if (getWeldsOk.Count() > 0) { var GCModel = getWeldsOk.Where(x => x.JointAttribute == "安装口"); if (GCModel.Count() > 0) { result = GCModel.Sum(x => x.Size ?? 0); } } } return result; } /// /// 现场施工未完成数 /// /// /// public static decimal GetXCRate_unfinished(string projectId) { decimal result = 0; result = GetSumSize(projectId, 2) - GetXCRate_finished(projectId); return result; } /// /// 管道完成预制数 /// /// /// public static decimal GetPipeRate_finished(string projectId) { decimal result = 0; result = GetGCRate_finished(projectId); return result; } /// /// 管道未完成预制数 /// /// /// public static decimal GetPipeRate_unfinished(string projectId) { decimal result = 0; result = GetSumSize(projectId, 0) - GetPipeRate_finished(projectId); return result; } /// /// 焊工功效 /// /// /// public static decimal GetWelderEfficacy(string projectId) { decimal result = 0; var db = Funs.DB; var q = (from x in db.HJGL_WeldJoint join y in db.HJGL_WeldingDaily on x.WeldingDailyId equals y.WeldingDailyId where x.ProjectId == projectId group x by x.ProjectId into g select new { TotalDin = g.Sum(x => x.Size), worktime = g.Select(x => x.WeldingDailyId).Distinct().Count(), }); foreach (var item in q) { result = decimal.Divide((decimal)item.TotalDin, item.worktime); } return decimal.Truncate(result); } public static decimal GetWelderEfficacy_GC(string projectId) { decimal result = 0; var db = Funs.DB; var q = (from x in db.HJGL_WeldJoint join y in db.HJGL_WeldingDaily on x.WeldingDailyId equals y.WeldingDailyId where x.ProjectId == projectId && x.JointAttribute == "预制口" group x by x.ProjectId into g select new { TotalDin = g.Sum(x => x.Size), worktime = g.Select(x => x.WeldingDailyId).Distinct().Count(), }); foreach (var item in q) { result = decimal.Divide((decimal)item.TotalDin, item.worktime); } return decimal.Truncate(result); } public static decimal GetWelderEfficacy_XC(string projectId) { decimal result = 0; var db = Funs.DB; var q = (from x in db.HJGL_WeldJoint join y in db.HJGL_WeldingDaily on x.WeldingDailyId equals y.WeldingDailyId where x.ProjectId == projectId && x.JointAttribute == "安装口" group x by x.ProjectId into g select new { TotalDin = g.Sum(x => x.Size), worktime = g.Select(x => x.WeldingDailyId).Distinct().Count(), }); foreach (var item in q) { result = decimal.Divide((decimal)item.TotalDin, item.worktime); } return decimal.Truncate(result); } } }