2023-11-09
This commit is contained in:
parent
540fbb97ee
commit
71dca3c416
|
|
@ -1467,6 +1467,37 @@ namespace BLL
|
|||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 将List 中的数据平均拆分为多个List
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="originalList">原始List</param>
|
||||
/// <param name="numberOfLists">拆分后的子列表数量</param>
|
||||
/// <returns></returns>
|
||||
/**们首先计算出每个子列表的大小chunkSize和余数remainder。然后,使用一个循环来创建并添加子列表到splitLists中。
|
||||
|
||||
在每次迭代中,我们根据当前索引是否小于余数来确定子列表的大小。如果小于余数,则将子列表大小加1,以确保最后一个子列表包含余数部分。
|
||||
|
||||
最后,我们更新startIndex以便正确获取下一个子列表的元素范围*/
|
||||
public static List<List<T>> SplitList<T>(List<T> originalList, int numberOfLists)
|
||||
{
|
||||
List<List<T>> splitLists = new List<List<T>>();
|
||||
int chunkSize = originalList.Count / numberOfLists;
|
||||
int remainder = originalList.Count % numberOfLists;
|
||||
|
||||
int startIndex = 0;
|
||||
for (int i = 0; i < numberOfLists; i++)
|
||||
{
|
||||
int sublistSize = chunkSize + (i < remainder ? 1 : 0);
|
||||
List<T> sublist = originalList.GetRange(startIndex, sublistSize);
|
||||
splitLists.Add(sublist);
|
||||
|
||||
startIndex += sublistSize;
|
||||
}
|
||||
|
||||
return splitLists;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using EmitMapper;
|
||||
using EmitMapper.MappingConfiguration;
|
||||
using FineUIPro;
|
||||
|
|
@ -358,7 +359,8 @@ namespace BLL
|
|||
{
|
||||
var responeData = new ResponeData();
|
||||
List<PHTGL_ContractTrackDtoIn> rows;
|
||||
List<PHTGL_ContractTrack> goingAddList =new List<PHTGL_ContractTrack>();
|
||||
List<PHTGL_ContractTrack> thisContractTracks =new List<PHTGL_ContractTrack>();
|
||||
|
||||
var sheetNames = MiniExcel.GetSheetNames(path);
|
||||
foreach (var sheet in sheetNames) ////多sheet导入
|
||||
{
|
||||
|
|
@ -376,6 +378,7 @@ namespace BLL
|
|||
ObjectMapperManager.DefaultInstance.GetMapper<List<PHTGL_ContractTrackDtoIn>, List<PHTGL_ContractTrack>>();
|
||||
var modeList = mapper.Map(rows);
|
||||
|
||||
List<PHTGL_ContractTrack> goingAddList = new List<PHTGL_ContractTrack>();
|
||||
if (modeList.Count == 0)
|
||||
{
|
||||
responeData.code = 0;
|
||||
|
|
@ -401,6 +404,7 @@ namespace BLL
|
|||
|
||||
item.ProjectCode = item.MainItemCode + "-" + item.ProjectCode;
|
||||
}
|
||||
|
||||
if (resultModel!=null)
|
||||
{
|
||||
item.Id = resultModel.Id;
|
||||
|
|
@ -409,10 +413,15 @@ namespace BLL
|
|||
else
|
||||
{
|
||||
item.Id = SQLHelper.GetNewID();
|
||||
AddPHTGL_ContractTrack(item);
|
||||
goingAddList.Add(item);
|
||||
//AddPHTGL_ContractTrack(item);
|
||||
}
|
||||
PhtglContracttrackprogressService.CreateTemplateByContractTrackId(item.Id);
|
||||
thisContractTracks.Add(item);
|
||||
//PhtglContracttrackprogressService.CreateTemplateByContractTrackId(item.Id);
|
||||
}
|
||||
|
||||
AddBulkPHTGL_ContractTrack(goingAddList);
|
||||
PhtglContracttrackprogressService.CreateTemplateByContractList(goingAddList,projectid);
|
||||
}
|
||||
|
||||
return responeData;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FineUIPro;
|
||||
using Model;
|
||||
|
||||
|
|
@ -110,6 +112,7 @@ namespace BLL
|
|||
ContractTrackId = ContractTrackId,
|
||||
Date= month.ToString("yyyy-MM")
|
||||
};
|
||||
|
||||
if (!GetPHTGL_ContractTrackProgressByModle(querymodel).Any())
|
||||
{
|
||||
var newmodel = new Model.PHTGL_ContractTrackProgress();
|
||||
|
|
@ -122,6 +125,75 @@ namespace BLL
|
|||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
@ -157,6 +229,12 @@ namespace BLL
|
|||
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 =>
|
||||
|
|
|
|||
Loading…
Reference in New Issue