SGGL_SHJ/SGGL/BLL/HJGL/WeldingManage/HJGL_WeldingReportService.cs

214 lines
7.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace BLL
{
public class HJGL_WeldingReportService
{
/// <summary>
/// 根据类型获取总达因数(0总达因1预制口总达因2安装口总达因)
/// </summary>
/// <param name="projectId"></param>
/// <param name="type">0总达因1预制口总达因2安装口总达因</param>
/// <returns></returns>
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;
}
/// <summary>
/// 工厂预制完成数
/// </summary>
/// <param name="projectId"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 工厂预制未完成数
/// </summary>
/// <param name="projectId"></param>
/// <returns></returns>
public static decimal GetGCRate_unfinished(string projectId)
{
decimal result = 0;
result = GetSumSize(projectId, 1) - GetGCRate_finished(projectId);
return result;
}
/// <summary>
/// 现场安装完成数
/// </summary>
/// <param name="projectId"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 现场安装未完成数
/// </summary>
/// <param name="projectId"></param>
/// <returns></returns>
public static decimal GetXCRate_unfinished(string projectId)
{
decimal result = 0;
result = GetSumSize(projectId, 2) - GetXCRate_finished(projectId);
return result;
}
/// <summary>
/// 管道完成预制数
/// </summary>
/// <param name="projectId"></param>
/// <returns></returns>
public static decimal GetPipeRate_finished(string projectId)
{
decimal result = 0;
result = GetGCRate_finished(projectId);
return result;
}
/// <summary>
/// 管道未完成预制数
/// </summary>
/// <param name="projectId"></param>
/// <returns></returns>
public static decimal GetPipeRate_unfinished(string projectId)
{
decimal result = 0;
result = GetSumSize(projectId, 0) - GetPipeRate_finished(projectId);
return result;
}
/// <summary>
/// 焊工功效
/// </summary>
/// <param name="projectId"></param>
/// <returns></returns>
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);
}
}
}