349 lines
16 KiB
C#
349 lines
16 KiB
C#
using FineUIPro;
|
||
using Model;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Concurrent;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace BLL
|
||
{
|
||
public static class PhtglContracttrackprogressService
|
||
{
|
||
#region 获取列表
|
||
|
||
/// <summary>
|
||
/// 记录数
|
||
/// </summary>
|
||
public static int Count { get; set; }
|
||
|
||
public static IQueryable<PHTGL_ContractTrackProgress> GetPHTGL_ContractTrackProgressByModle(PHTGL_ContractTrackProgress table)
|
||
{
|
||
var q = from x in Funs.DB.PHTGL_ContractTrackProgress
|
||
where
|
||
(string.IsNullOrEmpty(table.ContractTrackProgressId) ||
|
||
x.ContractTrackProgressId.Contains(table.ContractTrackProgressId)) &&
|
||
(string.IsNullOrEmpty(table.ContractTrackId) ||
|
||
x.ContractTrackId.Contains(table.ContractTrackId)) &&
|
||
(string.IsNullOrEmpty(table.Date) ||
|
||
x.Date.Contains(table.Date))
|
||
orderby x.Date
|
||
select x
|
||
;
|
||
return q;
|
||
}
|
||
public static PHTGL_ContractTrackProgress GetFirstOrDefaultByModle(PHTGL_ContractTrackProgress table)
|
||
{
|
||
var q = (from x in Funs.DB.PHTGL_ContractTrackProgress
|
||
where
|
||
(string.IsNullOrEmpty(table.ContractTrackProgressId) ||
|
||
x.ContractTrackProgressId.Contains(table.ContractTrackProgressId)) &&
|
||
(string.IsNullOrEmpty(table.ContractTrackId) ||
|
||
x.ContractTrackId.Contains(table.ContractTrackId)) &&
|
||
(string.IsNullOrEmpty(table.Date) ||
|
||
x.Date.Contains(table.Date))
|
||
orderby x.Date
|
||
select x).FirstOrDefault()
|
||
;
|
||
return q;
|
||
}
|
||
/// <summary>
|
||
/// 获取分页列表
|
||
/// </summary>
|
||
/// <param name="table"></param>
|
||
/// <param name="grid1"></param>
|
||
/// <returns></returns>
|
||
public static IEnumerable GetListData(PHTGL_ContractTrackProgress table, Grid grid1)
|
||
{
|
||
var q = GetPHTGL_ContractTrackProgressByModle(table);
|
||
Count = q.Count();
|
||
if (Count == 0) return null;
|
||
q = q.Skip(grid1.PageSize * grid1.PageIndex).Take(grid1.PageSize);
|
||
// q = SortConditionHelper.SortingAndPaging(q, Grid1.SortField, Grid1.SortDirection, Grid1.PageIndex, Grid1.PageSize);
|
||
return from x in q
|
||
select new
|
||
{
|
||
x.ContractTrackProgressId,
|
||
x.ContractTrackId,
|
||
x.BCWS_Quantity,
|
||
x.BCWS_OutputValue,
|
||
x.BCWS_Percentage,
|
||
x.ACWP_Quantity,
|
||
x.ACWP_OutputValue,
|
||
x.ACWP_Percentage,
|
||
x.Date
|
||
};
|
||
}
|
||
|
||
#endregion
|
||
|
||
public static PHTGL_ContractTrackProgress GetPHTGL_ContractTrackProgressById(string ContractTrackProgressId)
|
||
{
|
||
return Funs.DB.PHTGL_ContractTrackProgress.FirstOrDefault(x =>
|
||
x.ContractTrackProgressId == ContractTrackProgressId);
|
||
}
|
||
public static PHTGL_ContractTrackProgress GetPHTGL_ContractTrackProgressByTrackIdAndDate(string ContractTrackId, string date)
|
||
{
|
||
return Funs.DB.PHTGL_ContractTrackProgress.FirstOrDefault(x =>
|
||
x.ContractTrackId == ContractTrackId && x.Date == date);
|
||
}
|
||
/// <summary>
|
||
/// 根据合同价格信息主键创建进度日期数据
|
||
/// </summary>
|
||
/// <param name="ContractTrackId"></param>
|
||
public static void CreateTemplateByContractTrackId(string ContractTrackId)
|
||
{
|
||
var model = PhtglContractTrackService.GetPHTGL_ContractTrackById(ContractTrackId);
|
||
if (model == null) return;
|
||
var contractNum = model.ContractNum;
|
||
var contractmode = ContractService.GetContractByContractNum(contractNum);
|
||
if (contractmode.ContractStartDate != null && contractmode.ContractEndDate != null)
|
||
{
|
||
var startDate = (DateTime)contractmode.ContractStartDate;
|
||
var endDate = (DateTime)contractmode.ContractEndDate;
|
||
List<DateTime> months = GetMonthsBetween(startDate, endDate);//获取合同起止日期
|
||
|
||
foreach (DateTime month in months)
|
||
{
|
||
var querymodel = new Model.PHTGL_ContractTrackProgress
|
||
{
|
||
ContractTrackId = ContractTrackId,
|
||
Date = month.ToString("yyyy-MM")
|
||
};
|
||
|
||
if (!GetPHTGL_ContractTrackProgressByModle(querymodel).Any())
|
||
{
|
||
var newmodel = new Model.PHTGL_ContractTrackProgress();
|
||
newmodel.ContractTrackProgressId = SQLHelper.GetNewID(typeof(Model.PHTGL_ContractTrackProgress));
|
||
newmodel.ContractTrackId = ContractTrackId;
|
||
newmodel.Date = month.ToString("yyyy-MM");
|
||
AddPHTGL_ContractTrackProgress(newmodel);
|
||
}
|
||
//Console.WriteLine(month.ToString("yyyy-MM"));
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 根据导入合格价格信息数据来创建进度检测数据
|
||
/// </summary>
|
||
/// <param name="contractTrackList"></param>
|
||
/// <param name="projectid"></param>
|
||
public static void CreateTemplateByContractList(List<PHTGL_ContractTrack> contractTrackList, string projectid)
|
||
{
|
||
var dbcontractTrack = (from x in Funs.DB.PHTGL_ContractTrack where x.ProjectId == projectid select x).ToList();
|
||
var dbContractTrackProgress = (from x in Funs.DB.PHTGL_ContractTrackProgress
|
||
join y in Funs.DB.PHTGL_ContractTrack on x.ContractTrackId equals y.Id
|
||
where y.ProjectId == projectid
|
||
select x).ToList();
|
||
|
||
List<List<PHTGL_ContractTrack>> splitLists = new List<List<PHTGL_ContractTrack>>();
|
||
if (contractTrackList.Count > 10)
|
||
{
|
||
splitLists = Funs.SplitList(contractTrackList, 10);
|
||
}
|
||
else
|
||
{
|
||
splitLists = Funs.SplitList(contractTrackList, 1);
|
||
}
|
||
ConcurrentBag<PHTGL_ContractTrackProgress> contractTrackProgressList = new ConcurrentBag<PHTGL_ContractTrackProgress>();//用于批量新增的数据(无序集合)
|
||
|
||
ParallelOptions parallelOptions = new ParallelOptions();
|
||
parallelOptions.MaxDegreeOfParallelism = Environment.ProcessorCount;
|
||
|
||
///使用多线程开启并行任务,操作拆分后的list 同时进行数据处理
|
||
Parallel.ForEach(splitLists, parallelOptions, sublist =>
|
||
{
|
||
|
||
foreach (var item in sublist)
|
||
{
|
||
var model = (from x in dbcontractTrack where x.Id == item.Id select x).FirstOrDefault();
|
||
if (model == null) return;
|
||
var contractNum = model.ContractNum;
|
||
var contractmode = ContractService.GetContractByContractNum(contractNum);
|
||
if (contractmode.ContractStartDate != null && contractmode.ContractEndDate != null)
|
||
{
|
||
var startDate = (DateTime)contractmode.ContractStartDate;
|
||
var endDate = (DateTime)contractmode.ContractEndDate;
|
||
List<DateTime> months = GetMonthsBetween(startDate, endDate);//获取合同起止日期
|
||
|
||
foreach (DateTime month in months)
|
||
{
|
||
var querymodel = new Model.PHTGL_ContractTrackProgress
|
||
{
|
||
ContractTrackId = item.Id,
|
||
Date = month.ToString("yyyy-MM")
|
||
};
|
||
var q = (from x in dbContractTrackProgress
|
||
where
|
||
(string.IsNullOrEmpty(querymodel.ContractTrackId) ||
|
||
x.ContractTrackId.Contains(querymodel.ContractTrackId)) &&
|
||
(string.IsNullOrEmpty(querymodel.Date) ||
|
||
x.Date.Contains(querymodel.Date))
|
||
orderby x.Date
|
||
select x).ToList()
|
||
;
|
||
if (!q.Any())
|
||
{
|
||
var newmodel = new Model.PHTGL_ContractTrackProgress();
|
||
newmodel.ContractTrackProgressId = SQLHelper.GetNewID(typeof(Model.PHTGL_ContractTrackProgress));
|
||
newmodel.ContractTrackId = item.Id;
|
||
newmodel.Date = month.ToString("yyyy-MM");
|
||
contractTrackProgressList.Add(newmodel);
|
||
// AddPHTGL_ContractTrackProgress(newmodel);
|
||
}
|
||
}
|
||
}
|
||
} // 处理完成后,可以将结果保存到集合或其他地方
|
||
|
||
});
|
||
|
||
AddBulkPHTGL_ContractTrackProgress(contractTrackProgressList.ToList());
|
||
}
|
||
|
||
public static List<DateTime> GetMonthsBetween(DateTime startDate, DateTime endDate)
|
||
{
|
||
List<DateTime> months = new List<DateTime>();
|
||
|
||
DateTime currentMonth = new DateTime(startDate.Year, startDate.Month, 1);
|
||
DateTime lastMonth = new DateTime(endDate.Year, endDate.Month, 1);
|
||
|
||
while (currentMonth <= lastMonth)
|
||
{
|
||
months.Add(currentMonth);
|
||
currentMonth = currentMonth.AddMonths(1);
|
||
}
|
||
|
||
return months;
|
||
}
|
||
public static void AddPHTGL_ContractTrackProgress(PHTGL_ContractTrackProgress newtable)
|
||
{
|
||
var table = new PHTGL_ContractTrackProgress
|
||
{
|
||
ContractTrackProgressId = newtable.ContractTrackProgressId,
|
||
ContractTrackId = newtable.ContractTrackId,
|
||
BCWS_Quantity = newtable.BCWS_Quantity,
|
||
BCWS_OutputValue = newtable.BCWS_OutputValue,
|
||
BCWS_Percentage = newtable.BCWS_Percentage,
|
||
ACWP_Quantity = newtable.ACWP_Quantity,
|
||
ACWP_OutputValue = newtable.ACWP_OutputValue,
|
||
ACWP_Percentage = newtable.ACWP_Percentage,
|
||
Date = newtable.Date
|
||
|
||
};
|
||
Funs.DB.PHTGL_ContractTrackProgress.InsertOnSubmit(table);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
|
||
public static void AddBulkPHTGL_ContractTrackProgress(List<PHTGL_ContractTrackProgress> newtableList)
|
||
{
|
||
Funs.DB.PHTGL_ContractTrackProgress.InsertAllOnSubmit(newtableList);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
|
||
public static void UpdatePHTGL_ContractTrackProgress(PHTGL_ContractTrackProgress newtable)
|
||
{
|
||
var table = Funs.DB.PHTGL_ContractTrackProgress.FirstOrDefault(x =>
|
||
x.ContractTrackProgressId == newtable.ContractTrackProgressId);
|
||
if (table != null)
|
||
{
|
||
table.ContractTrackProgressId = newtable.ContractTrackProgressId;
|
||
table.ContractTrackId = newtable.ContractTrackId;
|
||
table.BCWS_Quantity = newtable.BCWS_Quantity;
|
||
table.BCWS_OutputValue = newtable.BCWS_OutputValue;
|
||
table.BCWS_Percentage = newtable.BCWS_Percentage;
|
||
table.ACWP_Quantity = newtable.ACWP_Quantity;
|
||
table.ACWP_OutputValue = newtable.ACWP_OutputValue;
|
||
table.ACWP_Percentage = newtable.ACWP_Percentage;
|
||
table.Date = newtable.Date;
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 重新校验计算进度数据
|
||
/// </summary>
|
||
/// <param name="contractTrackId"></param>
|
||
public static void CheckProgressByContractTrackId(string contractTrackId)
|
||
{
|
||
var modeContractTrack = PhtglContractTrackService.GetPHTGL_ContractTrackById(contractTrackId);
|
||
if (modeContractTrack != null)
|
||
{
|
||
var totalCostFixedComprehensiveUnitPrice = modeContractTrack.TotalCostFixedComprehensiveUnitPrice; //全费用综合单价
|
||
var settledAmount = modeContractTrack.SettledAmount ?? 0;//预算金额
|
||
var contractWeight = Funs.GetNewDecimalOrZero(modeContractTrack.ContractWeight) == 0 ? 0 : Funs.GetNewDecimalOrZero(modeContractTrack.ContractWeight) / 100;//合同权重
|
||
var quserytable = new Model.PHTGL_ContractTrackProgress();
|
||
quserytable.ContractTrackId = contractTrackId;
|
||
var list = GetPHTGL_ContractTrackProgressByModle(quserytable);
|
||
foreach (var item in list)
|
||
{
|
||
//产值=计划工程量*全费用综合单价(来源于“费用对比统计”),
|
||
// 百分比 =(产值 / 预算金额)*合同权重
|
||
item.ACWP_OutputValue = (item.ACWP_Quantity ?? 0) * totalCostFixedComprehensiveUnitPrice;
|
||
if (settledAmount == 0)
|
||
{
|
||
item.ACWP_Percentage = 0;
|
||
}
|
||
else
|
||
{
|
||
item.ACWP_Percentage = Math.Round(((item.ACWP_OutputValue ?? 0) / settledAmount) * contractWeight * 100, 2);
|
||
}
|
||
|
||
item.BCWS_OutputValue = (item.BCWS_Quantity ?? 0) * totalCostFixedComprehensiveUnitPrice;
|
||
if (settledAmount == 0)
|
||
{
|
||
item.BCWS_Percentage = 0;
|
||
}
|
||
else
|
||
{
|
||
item.BCWS_Percentage = Math.Round(((item.BCWS_OutputValue ?? 0) / settledAmount) * contractWeight * 100, 2);
|
||
}
|
||
UpdatePHTGL_ContractTrackProgress(item);
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 获取累计进程情况
|
||
/// </summary>
|
||
/// <param name="ContractTrackProgressId"></param>
|
||
/// <param name="date"></param>
|
||
public static PHTGL_ContractTrackProgress GetSumProgress(string contractTrackProgressId)
|
||
{
|
||
var result = new PHTGL_ContractTrackProgress();
|
||
var model = GetPHTGL_ContractTrackProgressById(contractTrackProgressId);
|
||
var q = (from x in Funs.DB.PHTGL_ContractTrackProgress
|
||
where x.ContractTrackId == model.ContractTrackId && string.Compare(x.Date, model.Date) <= 0
|
||
select x).ToList();
|
||
result.ACWP_Quantity = q.Sum(x => x.ACWP_Quantity ?? 0);
|
||
result.ACWP_OutputValue = q.Sum(x => x.ACWP_OutputValue ?? 0);
|
||
result.ACWP_Percentage = q.Sum(x => x.ACWP_Percentage ?? 0);
|
||
|
||
result.BCWS_Quantity = q.Sum(x => x.BCWS_Quantity ?? 0);
|
||
result.BCWS_OutputValue = q.Sum(x => x.BCWS_OutputValue ?? 0);
|
||
result.BCWS_Percentage = q.Sum(x => x.BCWS_Percentage ?? 0);
|
||
|
||
return result;
|
||
|
||
}
|
||
|
||
public static void DeleteModleById(string ContractTrackProgressId)
|
||
{
|
||
var table = Funs.DB.PHTGL_ContractTrackProgress.FirstOrDefault(x =>
|
||
x.ContractTrackProgressId == ContractTrackProgressId);
|
||
if (table != null)
|
||
{
|
||
Funs.DB.PHTGL_ContractTrackProgress.DeleteOnSubmit(table);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
}
|
||
public static void DeleteModleByContractTrackId(string ContractTrackId)
|
||
{
|
||
var table = Funs.DB.PHTGL_ContractTrackProgress.Where(x =>
|
||
x.ContractTrackId == ContractTrackId);
|
||
if (table != null)
|
||
{
|
||
Funs.DB.PHTGL_ContractTrackProgress.DeleteAllOnSubmit(table);
|
||
Funs.DB.SubmitChanges();
|
||
}
|
||
}
|
||
}
|
||
} |