排班优化
This commit is contained in:
parent
2cc3ef3edc
commit
a99df420ac
@ -67,9 +67,13 @@ namespace APT.FM.WebApi.Controllers.Api.FM
|
||||
var baseConfig = this.GetEntityByRedis<T_FM_BASE_CONFIG>(filter.GetOrgId().ToString(), filter.GetOrgId());
|
||||
if (baseConfig == null)
|
||||
this.ThrowError("010002");
|
||||
List<T_FM_DEPARTMENT_SCHEDULING> updateShiftData = new List<T_FM_DEPARTMENT_SCHEDULING>();//删除上一个周期的几条
|
||||
List<T_FM_DEPARTMENT_SCHEDULING_DETAIL> updateShiftDataDetail = new List<T_FM_DEPARTMENT_SCHEDULING_DETAIL>();//删除上一个周期的几条
|
||||
//清除数据后重新生成
|
||||
if (!string.IsNullOrWhiteSpace(filter.Keyword))
|
||||
{
|
||||
var deleteShiftPersonIds = new List<Guid>();
|
||||
var deleteShiftDataIds = new List<Guid>();
|
||||
var configIds = filter.Parameter1?.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(i => Guid.Parse(i));
|
||||
Expression<Func<T_FM_DEPARTMENT_CALENDAR_CONFIG, bool>> express = i => i.DEPARTMENT_ID == new Guid(filter.Keyword)
|
||||
&& i.ENABLE_STATUS == (int)FMEnableStatusEnum.启用 && i.END_TIME > DateTime.Now;
|
||||
@ -80,18 +84,48 @@ namespace APT.FM.WebApi.Controllers.Api.FM
|
||||
var departmentConfig = this.GetEntities<T_FM_DEPARTMENT_CALENDAR_CONFIG>(express, new BaseFilter(filter.GetOrgId()));
|
||||
if (departmentConfig != null && departmentConfig.Any())
|
||||
{
|
||||
departmentConfig.ForEach(x => x.CURR_TIME = DateTime.Now.Date.AddDays(1));
|
||||
var configId = departmentConfig.FirstOrDefault().ID;
|
||||
var cycle = departmentConfig.FirstOrDefault().CYCLE;
|
||||
var currTime = departmentConfig.FirstOrDefault().CURR_TIME;
|
||||
var departIds = departmentConfig.Select(t => t.DEPARTMENT_ID).Distinct().ToList();
|
||||
deleteShiftDataIds = this.GetEntities<T_FM_DEPARTMENT_SCHEDULING>(s => s.DATE_TIME.Date >= currTime && departIds.Contains(s.DEPARTMENT_ID), new BaseFilter(filter.OrgId)).Select(m => m.ID).ToList();
|
||||
deleteShiftPersonIds = this.GetEntities<T_FM_DEPARTMENT_SCHEDULING_DETAIL>(s => deleteShiftDataIds.Contains(s.DEPARTMENT_SCHEDULING_ID), new BaseFilter(filter.OrgId)).Select(m => m.ID).ToList();
|
||||
//departmentConfig.ForEach(x => x.CURR_TIME = DateTime.Now.Date.AddDays(1));
|
||||
//排序排班的最后几条记录
|
||||
BasePageFilter pageFilter = new BasePageFilter(1, cycle);
|
||||
pageFilter.OrgId = filter.OrgId;
|
||||
pageFilter.Order = DbOrder.DESC;
|
||||
pageFilter.Sort = "DATE_TIME";
|
||||
var shiftDataTemp = this.GetEntities<T_FM_DEPARTMENT_SCHEDULING>(s => s.DEPARTMENT_CALENDAR_CONFIG_ID == configId
|
||||
&& s.DATE_TIME < currTime && s.DATE_TIME >= currTime.AddDays(-cycle) && departIds.Contains(s.DEPARTMENT_ID)&& s.IS_DELETED == false, new BaseFilter(filter.OrgId)).ToList();
|
||||
updateShiftData.AddRange(shiftDataTemp);
|
||||
updateShiftData.ForEach(x => x.IS_DELETED = true);
|
||||
//var updateShiftIds = updateShiftData.Select(m => m.ID).ToList();
|
||||
//updateShiftDataDetail = this.GetEntities<T_FM_DEPARTMENT_SCHEDULING_DETAIL>(s => updateShiftIds.Contains(s.DEPARTMENT_SCHEDULING_ID) && s.IS_DELETED == false, new BaseFilter(filter.OrgId)).ToList();
|
||||
//updateShiftDataDetail.ForEach(m => m.IS_DELETED = true);
|
||||
}
|
||||
this.UnifiedCommit(() =>
|
||||
{
|
||||
this.DeleteEntityNoCommit<T_FM_DEPARTMENT_SCHEDULING_DETAIL>(i => i.Nav_DepartmentScheduling.DEPARTMENT_ID == new Guid(filter.Keyword)
|
||||
&& configIds.Contains(i.Nav_DepartmentScheduling.DEPARTMENT_CALENDAR_CONFIG_ID.Value) && i.Nav_DepartmentScheduling.DATE_TIME > DateTime.Now);
|
||||
this.DeleteEntityNoCommit<T_FM_DEPARTMENT_SCHEDULING>(i => i.DEPARTMENT_ID == new Guid(filter.Keyword)
|
||||
&& configIds.Contains(i.DEPARTMENT_CALENDAR_CONFIG_ID.Value) && i.DATE_TIME > DateTime.Now);
|
||||
if (departmentConfig != null && departmentConfig.Any())
|
||||
if (deleteShiftPersonIds != null && deleteShiftPersonIds.Any())
|
||||
this.BantchDeleteEntityNoCommit<T_FM_DEPARTMENT_SCHEDULING_DETAIL>(deleteShiftPersonIds);
|
||||
if (deleteShiftDataIds != null && deleteShiftDataIds.Any())
|
||||
this.BantchDeleteEntityNoCommit<T_FM_DEPARTMENT_SCHEDULING>(deleteShiftDataIds);
|
||||
//if (updateShiftDataDetail != null && updateShiftDataDetail.Any())
|
||||
//{
|
||||
// this.BantchUpdateEntity_noneBase(updateShiftDataDetail);
|
||||
//}
|
||||
if (updateShiftData != null && updateShiftData.Any())
|
||||
{
|
||||
this.BantchUpdateEntityNoCommit(departmentConfig);
|
||||
this.BantchUpdateEntity_noneBase(updateShiftData);
|
||||
}
|
||||
// this.DeleteEntityNoCommit<T_FM_DEPARTMENT_SCHEDULING_DETAIL>(i => i.Nav_DepartmentScheduling.DEPARTMENT_ID == new Guid(filter.Keyword)
|
||||
//&& configIds.Contains(i.Nav_DepartmentScheduling.DEPARTMENT_CALENDAR_CONFIG_ID.Value) && i.Nav_DepartmentScheduling.DATE_TIME > DateTime.Now);
|
||||
// this.DeleteEntityNoCommit<T_FM_DEPARTMENT_SCHEDULING>(i => i.DEPARTMENT_ID == new Guid(filter.Keyword)
|
||||
// && configIds.Contains(i.DEPARTMENT_CALENDAR_CONFIG_ID.Value) && i.DATE_TIME > DateTime.Now);
|
||||
//if (departmentConfig != null && departmentConfig.Any())
|
||||
//{
|
||||
// this.BantchUpdateEntityNoCommit(departmentConfig);
|
||||
//}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace APT.PP.WebApi.Controllers
|
||||
{
|
||||
@ -47,6 +48,8 @@ namespace APT.PP.WebApi.Controllers
|
||||
var allTeamPersons = this.GetEntities<T_FM_TEAM_PERSON>(i => teamIds.Contains(i.TEAM_ID), filter);
|
||||
List<T_FM_DEPARTMENT_SCHEDULING> shiftList = new List<T_FM_DEPARTMENT_SCHEDULING>();//排版表
|
||||
List<T_FM_DEPARTMENT_SCHEDULING_DETAIL> shiftDetailList = new List<T_FM_DEPARTMENT_SCHEDULING_DETAIL>();//排版明细表
|
||||
List<T_FM_DEPARTMENT_SCHEDULING> updateShiftData = new List<T_FM_DEPARTMENT_SCHEDULING>();//还原被删除的几条
|
||||
List<T_FM_DEPARTMENT_SCHEDULING_DETAIL> updateShiftDataDetail = new List<T_FM_DEPARTMENT_SCHEDULING_DETAIL>();//还原被删除的几条
|
||||
var nodelModels = new List<ControlNodelModel>();//所有生产单元
|
||||
var baseFilter = new BaseFilter(filter.OrgId);
|
||||
baseFilter.Order = DbOrder.ASC;
|
||||
@ -74,7 +77,7 @@ namespace APT.PP.WebApi.Controllers
|
||||
pageFilter.Order = DbOrder.DESC;
|
||||
pageFilter.Sort = "DATE_TIME";
|
||||
var shiftData = this.GetOrderPageEntities<T_FM_DEPARTMENT_SCHEDULING>(s => s.DEPARTMENT_CALENDAR_CONFIG_ID == sh.ID
|
||||
&& s.DATE_TIME < sh.CURR_TIME && s.TEAM_ID == fristTeam.TEAM_ID, pageFilter);
|
||||
&& s.DATE_TIME < sh.CURR_TIME && s.DATE_TIME >= sh.CURR_TIME.AddDays(-sh.CYCLE) && s.TEAM_ID == fristTeam.TEAM_ID, pageFilter);
|
||||
var curPerEndDay = perEndDay > sh.END_TIME ? sh.END_TIME : perEndDay;
|
||||
var dayIndex = 0;
|
||||
var classIndex = 0;
|
||||
@ -109,6 +112,7 @@ namespace APT.PP.WebApi.Controllers
|
||||
|
||||
var totalCurrentIndex = classIndex * sh.CYCLE + dayIndex;//总的顺序
|
||||
var totalIndex = orderClass.Count * sh.CYCLE;
|
||||
var oldCurrTime = sh.CURR_TIME.Date;
|
||||
for (var starTime = sh.CURR_TIME.Date; starTime <= curPerEndDay; starTime = starTime.AddDays(1))
|
||||
{
|
||||
|
||||
@ -217,31 +221,38 @@ namespace APT.PP.WebApi.Controllers
|
||||
dayIndex++;
|
||||
sh.CURR_TIME = curPerEndDay.AddDays(1);
|
||||
}
|
||||
var shiftDataTemp = this.GetEntities_noneBase<T_FM_DEPARTMENT_SCHEDULING>(s => s.DEPARTMENT_CALENDAR_CONFIG_ID == sh.ID
|
||||
&& s.DATE_TIME < oldCurrTime && s.DATE_TIME >= oldCurrTime.AddDays(-sh.CYCLE) && s.DEPARTMENT_ID == sh.DEPARTMENT_ID && s.IS_DELETED == true).ToList();
|
||||
updateShiftData.AddRange(shiftDataTemp);
|
||||
updateShiftData.ForEach(x => x.IS_DELETED = false);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
//判断开始时间=当前时间的,为重新排班,删除该班组已有的排班
|
||||
var deleteConfigs = configData.Where(t => t.START_TIME.Date == t.CURR_TIME.Date && t.CURR_TIME.Date == DateTime.Now.Date).ToList();
|
||||
var deleteTeamIds = deleteConfigs.SelectMany(i => i.Nav_DepartmentCalendarConfigTeam).Select(i => i.TEAM_ID).ToArray();
|
||||
var deleteShiftDataIds = this.GetEntities<T_FM_DEPARTMENT_SCHEDULING>(s => s.DATE_TIME.Date >= DateTime.Now.Date && deleteTeamIds.Contains(s.TEAM_ID), new BaseFilter(filter.OrgId)).Select(m=>m.ID).ToList();
|
||||
var deleteShiftPersonIds = this.GetEntities<T_FM_DEPARTMENT_SCHEDULING_DETAIL>(s => deleteShiftDataIds.Contains(s.DEPARTMENT_SCHEDULING_ID), new BaseFilter(filter.OrgId)).Select(m => m.ID).ToList();
|
||||
//var updateShiftIds = updateShiftData.Select(m => m.ID).ToList();
|
||||
//updateShiftDataDetail = this.GetEntities<T_FM_DEPARTMENT_SCHEDULING_DETAIL>(s => updateShiftIds.Contains(s.DEPARTMENT_SCHEDULING_ID) && s.IS_DELETED == true, new BaseFilter(filter.OrgId)).ToList();
|
||||
//updateShiftDataDetail.ForEach(m => m.IS_DELETED = false);
|
||||
//统一提交数据
|
||||
this.UnifiedCommit(() =>
|
||||
{
|
||||
if (deleteShiftPersonIds != null && deleteShiftPersonIds.Any())
|
||||
this.BantchDeleteEntityNoCommit<T_FM_DEPARTMENT_SCHEDULING_DETAIL>(deleteShiftPersonIds);
|
||||
if (deleteShiftDataIds != null && deleteShiftDataIds.Any())
|
||||
this.BantchDeleteEntityNoCommit<T_FM_DEPARTMENT_SCHEDULING>(deleteShiftDataIds);
|
||||
if (shiftList.Any())
|
||||
this.BantchAddEntityNoCommit(shiftList);
|
||||
if (shiftDetailList.Any())
|
||||
this.BantchAddEntityNoCommit(shiftDetailList);
|
||||
this.BantchUpdateEntityNoCommit(configData, "CURR_TIME");
|
||||
|
||||
if (updateShiftData != null && updateShiftData.Any())
|
||||
{
|
||||
this.BantchUpdateEntity_noneBase(updateShiftData);
|
||||
}
|
||||
//if (updateShiftDataDetail != null && updateShiftDataDetail.Any())
|
||||
//{
|
||||
// this.BantchUpdateEntity_noneBase(updateShiftDataDetail);
|
||||
//}
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user