using BLL; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; namespace FineUIPro.Web { public partial class mainMenu_HJGL : PageBase { protected void Page_Load(object sender, EventArgs e) { string projectId = this.CurrUser.LoginProjectId; this.getWeld(projectId, this.CurrUser.UnitId); getecharts04(projectId); getecharts05(projectId); getecharts06(projectId); this.divWelderEfficacyNum.InnerText = HJGL_WeldingReportService.GetWelderEfficacy(projectId).ToString(); var pipeStats = (from x in Funs.DB.HJGL_WeldJoint where x.ProjectId == projectId group x by x.ProjectId into g select new { TotalDin = g.Sum(x => x.Size ?? 0m), FinishedDin = g.Sum(x => x.WeldingDailyId != null && x.JointAttribute == "预制口" ? x.Size ?? 0m : 0m) }).SingleOrDefault(); this.echarts02Value.InnerText = pipeStats == null || pipeStats.TotalDin == 0 ? "0" : Math.Floor(Math.Round(decimal.Parse((pipeStats.FinishedDin / pipeStats.TotalDin).ToString("0.000")), 2) * 100).ToString(); } #region 焊工现场统计 /// /// 焊工现场统计 /// private void getWeld(string projectId, string unitId) { var getWelders = from x in Funs.DB.SitePerson_Person where x.ProjectId == projectId && x.WorkPostId == Const.WorkPost_Welder select x; if (!string.IsNullOrEmpty(this.CurrUser.UnitId) && unitId != CommonService.GetThisUnitId()) { getWelders = getWelders.Where(x => x.UnitId == unitId); } this.divWelderNum.InnerText = getWelders.Count().ToString(); string strSql = @"SELECT SUM(TotalFilm) AS TotalFilm, SUM(PassFilm) AS PassFilm from HJGL_Batch_NDEItem item left join HJGL_Batch_NDE nde on nde.NDEID = item.NDEID where ProjectId = @ProjectId"; List listStr = new List { new SqlParameter("@ProjectId", this.CurrUser.LoginProjectId) }; if (!string.IsNullOrEmpty(this.CurrUser.UnitId) && unitId != CommonService.GetThisUnitId()) { strSql += " AND UnitId=@unitId"; listStr.Add(new SqlParameter("@unitId", unitId)); } SqlParameter[] parameter = listStr.ToArray(); DataTable tb = SQLHelper.GetDataTableRunText(strSql, parameter); if (tb != null && tb.Rows.Count > 0) { try { var rate = 100 * double.Parse(tb.Rows[0]["PassFilm"].ToString()) / double.Parse(tb.Rows[0]["TotalFilm"].ToString()); this.divPassRate.InnerText = "" + ((int)rate) + "%"; } catch (Exception ex) { this.divPassRate.InnerText = "0%"; } } } #endregion #region 焊接一次合格率 protected string E04_Type01; protected string E04_Values01; protected string E04_Type02; protected string E04_Values02; protected string E04_Type03; protected string E04_Values03; protected string E04_Type04; protected string E04_Values04; protected string E04_Type05; protected string E04_Values05; protected string E04_Type06; protected string E04_Values06; private void getecharts04(string projectId) { E04_Type01 = "[]"; E04_Values01 = "[]"; E04_Type02 = "[]"; E04_Values02 = "[]"; E04_Type03 = "[]"; E04_Values03 = "[]"; E04_Type04 = "[]"; E04_Values04 = "[]"; E04_Type05 = "[]"; E04_Values05 = "[]"; E04_Type06 = "[]"; E04_Values06 = "[]"; var inspectionItems = (from x in Funs.DB.HJGL_Batch_NDEItem join y in Funs.DB.HJGL_Batch_BatchTrustItem on x.TrustBatchItemId equals y.TrustBatchItemId join z in Funs.DB.View_HJGL_WeldJoint on y.WeldJointId equals z.WeldJointId join line in Funs.DB.HJGL_Pipeline on z.PipelineId equals line.PipelineId where z.ProjectId == projectId select new { x.TotalFilm, x.PassFilm, z.UnitName, z.UnitWorkName, z.MaterialCode, z.Specification, z.WeldTypeCode, z.JointAttribute }).ToList(); double PassRate = 0; int current_pass_film = 0; int cht_totalfilm = 0; //// 按单位 List type01List = new List(); List count011List = new List(); var tb_type01 = inspectionItems.GroupBy(x => x.UnitName).Select(x => new { UnitName = x.Key, Current_pass_film = x.Sum(m => m.PassFilm) ?? 0, Cht_totalfilm = x.Sum(m => m.TotalFilm) ?? 0 }); foreach (var item in tb_type01) { type01List.Add(item.UnitName); PassRate = 0; current_pass_film = item.Current_pass_film; cht_totalfilm = item.Cht_totalfilm; if (cht_totalfilm > 0) { PassRate = Math.Round((100 * current_pass_film * 1.0) / cht_totalfilm, 1); } count011List.Add(PassRate); } if (type01List.Count() > 0) { E04_Type01 = JsonConvert.SerializeObject(type01List); E04_Values01 = JsonConvert.SerializeObject(count011List); } ///按单位工程 List type02List = new List(); List count021List = new List(); var tb_type02 = inspectionItems.GroupBy(x => x.UnitWorkName).Select(x => new { UnitWorkName = x.Key, Current_pass_film = x.Sum(m => m.PassFilm) ?? 0, Cht_totalfilm = x.Sum(m => m.TotalFilm) ?? 0 }); foreach (var item in tb_type02) { type02List.Add(item.UnitWorkName); PassRate = 0; current_pass_film = item.Current_pass_film; cht_totalfilm = item.Cht_totalfilm; if (cht_totalfilm > 0) { PassRate = Math.Round((100 * current_pass_film * 1.0) / cht_totalfilm, 1); } count021List.Add(PassRate); } if (type02List.Count() > 0) { E04_Type02 = JsonConvert.SerializeObject(type02List); E04_Values02 = JsonConvert.SerializeObject(count021List); } ///按材质类别 List type03List = new List(); List count031List = new List(); var tb_type03 = inspectionItems.GroupBy(x => x.MaterialCode).Select(x => new { MaterialCode = x.Key, Current_pass_film = x.Sum(m => m.PassFilm) ?? 0, Cht_totalfilm = x.Sum(m => m.TotalFilm) ?? 0 }); foreach (var item in tb_type03) { type03List.Add(item.MaterialCode); PassRate = 0; current_pass_film = item.Current_pass_film; cht_totalfilm = item.Cht_totalfilm; if (cht_totalfilm > 0) { PassRate = Math.Round((100 * current_pass_film * 1.0) / cht_totalfilm, 1); } count031List.Add(PassRate); } if (type03List.Count() > 0) { E04_Type03 = JsonConvert.SerializeObject(type03List); E04_Values03 = JsonConvert.SerializeObject(count031List); } //焊缝规格 List type04List = new List(); List count041List = new List(); var tb_type04 = inspectionItems.GroupBy(x => x.Specification).Select(x => new { Specification = x.Key, Current_pass_film = x.Sum(m => m.PassFilm) ?? 0, Cht_totalfilm = x.Sum(m => m.TotalFilm) ?? 0 }); foreach (var item in tb_type04) { type04List.Add(item.Specification); PassRate = 0; current_pass_film = item.Current_pass_film; cht_totalfilm = item.Cht_totalfilm; if (cht_totalfilm > 0) { PassRate = Math.Round((100 * current_pass_film * 1.0) / cht_totalfilm, 1); } count041List.Add(PassRate); } if (type04List.Count() > 0) { E04_Type04 = JsonConvert.SerializeObject(type04List); E04_Values04 = JsonConvert.SerializeObject(count041List); } //焊缝类型 List type05List = new List(); List count051List = new List(); var tb_type05 = inspectionItems.GroupBy(x => x.WeldTypeCode).Select(x => new { WeldTypeCode = x.Key, Current_pass_film = x.Sum(m => m.PassFilm) ?? 0, Cht_totalfilm = x.Sum(m => m.TotalFilm) ?? 0 }); foreach (var item in tb_type05) { type05List.Add(item.WeldTypeCode); PassRate = 0; current_pass_film = item.Current_pass_film; cht_totalfilm = item.Cht_totalfilm; if (cht_totalfilm > 0) { PassRate = Math.Round((100 * current_pass_film * 1.0) / cht_totalfilm, 1); } count051List.Add(PassRate); } if (type05List.Count() > 0) { E04_Type05 = JsonConvert.SerializeObject(type05List); E04_Values05 = JsonConvert.SerializeObject(count051List); } //焊缝属性 List type06List = new List(); List count061List = new List(); var tb_type06 = inspectionItems.GroupBy(x => x.JointAttribute).Select(x => new { JointAttribute = x.Key, Current_pass_film = x.Sum(m => m.PassFilm) ?? 0, Cht_totalfilm = x.Sum(m => m.TotalFilm) ?? 0 }); foreach (var item in tb_type06) { type06List.Add(item.JointAttribute); PassRate = 0; current_pass_film = item.Current_pass_film; cht_totalfilm = item.Cht_totalfilm; if (cht_totalfilm > 0) { PassRate = Math.Round((100 * current_pass_film * 1.0) / cht_totalfilm, 1); } count061List.Add(PassRate); } if (type06List.Count() > 0) { E04_Type06 = JsonConvert.SerializeObject(type06List); E04_Values06 = JsonConvert.SerializeObject(count061List); } } #endregion #region 焊接缺陷分析 protected string E05_Type01; protected string E05_Values01; protected string E05_Type02; protected string E05_Values02; protected string E05_Type03; protected string E05_Values03; protected string E05_Type04; protected string E05_Values04; private sealed class DefectChartPoint { public int Series { get; set; } public string Category { get; set; } public int DefectCount { get; set; } } private void getecharts05(string projectId) { // 同一报告下的缺陷明细先计数,再按原关联口径汇总四个维度。 const string sql = @" WITH DefectsByReport AS ( SELECT item.NDEID, COUNT(*) AS DefectCount FROM dbo.HJGL_Batch_NDEItem item INNER JOIN dbo.HJGL_Batch_NDE report ON report.NDEID = item.NDEID WHERE report.ProjectId = {0} AND item.CheckDefects IS NOT NULL AND item.CheckDefects <> '' GROUP BY item.NDEID ) SELECT CASE WHEN GROUPING(pipe.MaterialCode) = 0 THEN 1 WHEN GROUPING(weld.Specification) = 0 THEN 2 WHEN GROUPING(weld.WeldTypeCode) = 0 THEN 3 ELSE 4 END AS Series, CASE WHEN GROUPING(pipe.MaterialCode) = 0 THEN pipe.MaterialCode WHEN GROUPING(weld.Specification) = 0 THEN weld.Specification WHEN GROUPING(weld.WeldTypeCode) = 0 THEN weld.WeldTypeCode ELSE weld.JointAttribute END AS Category, SUM(defects.DefectCount) AS DefectCount FROM DefectsByReport defects INNER JOIN dbo.View_Batch_NDEItem item ON item.NDEID = defects.NDEID INNER JOIN dbo.View_HJGL_Pipeline pipe ON pipe.PipelineCode = item.PipelineCode INNER JOIN dbo.View_HJGL_WeldJoint weld ON weld.WeldJointId = item.WeldJointId GROUP BY GROUPING SETS ((pipe.MaterialCode), (weld.Specification), (weld.WeldTypeCode), (weld.JointAttribute))"; var series = Funs.DB.ExecuteQuery(sql, projectId).ToLookup(x => x.Series); E05_Type01 = JsonConvert.SerializeObject(series[1].Select(x => x.Category)); E05_Values01 = JsonConvert.SerializeObject(series[1].Select(x => x.DefectCount)); E05_Type02 = JsonConvert.SerializeObject(series[2].Select(x => x.Category)); E05_Values02 = JsonConvert.SerializeObject(series[2].Select(x => x.DefectCount)); E05_Type03 = JsonConvert.SerializeObject(series[3].Select(x => x.Category)); E05_Values03 = JsonConvert.SerializeObject(series[3].Select(x => x.DefectCount)); E05_Type04 = JsonConvert.SerializeObject(series[4].Select(x => x.Category)); E05_Values04 = JsonConvert.SerializeObject(series[4].Select(x => x.DefectCount)); } #endregion #region 焊工业绩分析 protected string E06_Type01; protected string E06_Values01; private void getecharts06(string projectId) { var projectUnits = Funs.DB.Project_ProjectUnit.Where(x => x.ProjectId == projectId && (x.UnitType == Const.ProjectUnitType_1 || x.UnitType == Const.ProjectUnitType_2)); var welderTotals = from person in Funs.DB.SitePerson_Person join weld in Funs.DB.HJGL_WeldJoint on person.PersonId equals weld.CoverWelderId join daily in Funs.DB.HJGL_WeldingDaily on weld.WeldingDailyId equals daily.WeldingDailyId join pipe in Funs.DB.HJGL_Pipeline on weld.PipelineId equals pipe.PipelineId where person.WorkPostId == Const.WorkPost_Welder && projectUnits.Any(x => x.UnitId == person.UnitId) group weld by person.UnitId into g select new { UnitId = g.Key, TotalDin = g.Sum(x => x.Size) }; var rows = (from projectUnit in projectUnits join baseUnit in Funs.DB.Base_Unit on projectUnit.UnitId equals baseUnit.UnitId into units from unit in units.DefaultIfEmpty() join welderTotal in welderTotals on projectUnit.UnitId equals welderTotal.UnitId into totals from total in totals.DefaultIfEmpty() select new { UnitName = unit == null ? string.Empty : unit.UnitName, TotalDin = total.TotalDin ?? 0m }).ToList(); E06_Type01 = JsonConvert.SerializeObject(rows.Select(x => x.UnitName)); E06_Values01 = JsonConvert.SerializeObject(rows.Select(x => x.TotalDin)); } #endregion } }