290 lines
11 KiB
C#
290 lines
11 KiB
C#
using System;
|
|
using SqlSugar;
|
|
using Infrastructure.Attribute;
|
|
using Infrastructure.Extensions;
|
|
using DOAN.Model;
|
|
using DOAN.Model.Dto;
|
|
using DOAN.Model.MES.group;
|
|
using DOAN.Model.MES.group.Dto;
|
|
using DOAN.Repository;
|
|
using DOAN.Service.group.IService;
|
|
using System.Linq;
|
|
using DOAN.Model.MES.group.Dto;
|
|
using Aliyun.OSS;
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
|
using MimeKit.Tnef;
|
|
using System.Collections.Generic;
|
|
|
|
namespace DOAN.Service.Business
|
|
{
|
|
/// <summary>
|
|
/// 排班Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IGroupScheduleService), ServiceLifetime = LifeTime.Transient)]
|
|
public class GroupScheduleService : BaseService<GroupSchedule>, IGroupScheduleService
|
|
{
|
|
/// <summary>
|
|
/// 查询排班列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<GroupScheduleDto> GetList(GroupScheduleQueryDto parm)
|
|
{
|
|
var predicate = Expressionable.Create<GroupSchedule>();
|
|
var response = Queryable()
|
|
.Where(predicate.ToExpression())
|
|
.ToPage<GroupSchedule, GroupScheduleDto>(parm);
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
public GroupSchedule GetInfo(string Id)
|
|
{
|
|
var response = Queryable()
|
|
.Where(x => x.Id == Id)
|
|
.First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加排班
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public GroupSchedule AddGroupSchedule(GroupSchedule model)
|
|
{
|
|
model.Id = XueHua;
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改排班
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateGroupSchedule(GroupSchedule model)
|
|
{
|
|
//var response = Update(w => w.Id == model.Id, it => new GroupSchedule()
|
|
//{
|
|
// ScheduleDate = model.ScheduleDate,
|
|
// GroupName = model.GroupName,
|
|
// GrouoCode = model.GrouoCode,
|
|
// BelongRoute = model.BelongRoute,
|
|
// Remark = model.Remark,
|
|
// Status = model.Status,
|
|
// CreatedBy = model.CreatedBy,
|
|
// CreatedTime = model.CreatedTime,
|
|
// UpdatedBy = model.UpdatedBy,
|
|
// UpdatedTime = model.UpdatedTime,
|
|
//});
|
|
//return response;
|
|
return Update(model, true);
|
|
}
|
|
/// <summary>
|
|
/// 1 根据日期获取班组
|
|
/// </summary>
|
|
/// <param name="date"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<GroupScheduleDto> ListGroupByDate(GroupScheduleQueryDto2 query)
|
|
{
|
|
query.ScheduleDate = query.ScheduleDate.Date;
|
|
return Queryable().LeftJoin<GroupShift>((it, sh) => it.FkShift == sh.Id).Where((it, sh) => it.ScheduleDate == query.ScheduleDate)
|
|
.Select((it, sh) => new GroupScheduleDto { ShiftName = sh.Name }, true)
|
|
.ToPage<GroupScheduleDto, GroupScheduleDto>(query);
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// 查询班组绑定的人员
|
|
/// </summary>
|
|
/// <param name="group_schedule_id"></param>
|
|
/// <returns></returns>
|
|
public List<GroupPersonDto> SearchPerson_group_bind(string group_schedule_id)
|
|
{
|
|
var query = Context.Queryable<GroupRelPersonGroup>()
|
|
.LeftJoin<GroupPerson>((rel, p) => rel.FkPersonId == p.Id)
|
|
.Where((rel, p) => rel.FkGroupId == group_schedule_id)
|
|
.Where((rel, p) => p.Status == 1)
|
|
.Select((rel, p) => p);
|
|
|
|
|
|
return Context.Queryable(query)
|
|
.LeftJoin<GroupPost>((q, p) => q.FkPost == p.Id)
|
|
.Select((q, p) => new GroupPersonDto { PostName = p.PostName }, true)
|
|
.ToList();
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询班组未绑定的人员
|
|
/// </summary>
|
|
/// <param name="group_schedule_id"></param>
|
|
/// <param name="date"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<GroupPersonDto> SearchPerson_group_bind_No(GroupScheduleQueryDto3 parm)
|
|
{
|
|
// 查询日期内所有绑定人员
|
|
|
|
//查询指定日期排班
|
|
|
|
//查询排班所有绑定的人员
|
|
|
|
// 查询排班内所有未绑定人员
|
|
var query = Context.Queryable<GroupPerson>().Where(it => SqlFunc.Subqueryable<GroupRelPersonGroup>()
|
|
.LeftJoin<GroupPerson>((rel, p) => rel.FkPersonId == p.Id)
|
|
.Where((rel, p) => p.Status == 1)
|
|
.Where((rel, p) => SqlFunc.Subqueryable<GroupSchedule>().Where(it => it.ScheduleDate == SqlFunc.Subqueryable<GroupSchedule>()
|
|
.Where(it => it.Id == parm.group_schedule_id)
|
|
.Select(it => it.ScheduleDate)).Where(it => it.Id == rel.FkGroupId).Any()).Where((rel, p) => p.Id == it.Id).NotAny());
|
|
|
|
|
|
return Context.Queryable(query)
|
|
.LeftJoin<GroupPost>((q, p) => q.FkPost == p.Id)
|
|
.Where((q, p) => q.Status == 1)
|
|
.WhereIF(!string.IsNullOrEmpty(parm.WorkNum), (q, p) => q.WorkNum.Contains(parm.WorkNum))
|
|
.WhereIF(!string.IsNullOrEmpty(parm.Name), (q, p) => q.Name.Contains(parm.Name))
|
|
.WhereIF(!string.IsNullOrEmpty(parm.FkPost), (q, p) => q.FkPost == parm.FkPost)
|
|
.Select((q, p) => new GroupPersonDto { PostName = p.PostName }, true)
|
|
.ToPage<GroupPersonDto, GroupPersonDto>(parm);
|
|
|
|
|
|
}
|
|
|
|
public int GroupAddPerson(string group_schedule_id, string person_id, string CreatedBy)
|
|
{
|
|
GroupRelPersonGroup relPersonGroup = new GroupRelPersonGroup();
|
|
relPersonGroup.FkGroupId = group_schedule_id;
|
|
relPersonGroup.FkPersonId = person_id;
|
|
relPersonGroup.CreatedTime = DateTime.Now;
|
|
relPersonGroup.CreatedBy = CreatedBy;
|
|
return Context.Insertable(relPersonGroup).ExecuteCommand();
|
|
}
|
|
|
|
public int GroupRemovePerson(string group_schedule_id, string person_id)
|
|
{
|
|
return Context.Deleteable<GroupRelPersonGroup>()
|
|
.Where(it => it.FkGroupId == group_schedule_id)
|
|
.Where(it => it.FkPersonId == person_id)
|
|
.ExecuteCommand();
|
|
}
|
|
/// <summary>
|
|
/// 获取本月排班情况
|
|
/// </summary>
|
|
/// <param name="HandleMonth"></param>
|
|
/// <returns></returns>
|
|
public List<SchedulingSituation> GetMonthScheduleResult(int year, int HandleMonth)
|
|
{
|
|
List<SchedulingSituation> results = new List<SchedulingSituation>();
|
|
//获取月份所有日期
|
|
List<DateTime> GetDatesOfMonth(int year, int month)
|
|
{
|
|
|
|
List<DateTime> dates = new List<DateTime>();
|
|
|
|
DateTime firstDayOfMonth = new DateTime(year, month, 1);
|
|
DateTime lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1); // 获取下个月的第一天,然后减去一天得到本月的最后一天
|
|
|
|
for (DateTime date = firstDayOfMonth; date <= lastDayOfMonth; date = date.AddDays(1))
|
|
{
|
|
dates.Add(date);
|
|
}
|
|
|
|
return dates;
|
|
}
|
|
List<DateTime> All_Dates = GetDatesOfMonth(year, HandleMonth);
|
|
|
|
foreach (DateTime date in All_Dates)
|
|
{
|
|
int counts = Queryable().Where(it => it.ScheduleDate == date).Count();
|
|
SchedulingSituation situation = new SchedulingSituation();
|
|
situation.Date1 = date.ToString("yyyy-MM-dd");
|
|
situation.groupNum = counts;
|
|
results.Add(situation);
|
|
|
|
|
|
|
|
}
|
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
|
public int CopyPreDaySchedule(DateTime date, string CreatedBy)
|
|
{
|
|
int result = 0;
|
|
DateTime PreDate = date.AddDays(-1);
|
|
|
|
List<GroupSchedule> date_schedules = Queryable().Where(it => it.ScheduleDate == PreDate).ToList();
|
|
|
|
if (date_schedules == null || date_schedules.Count == 0) { return -1; }
|
|
bool isExist = Queryable().Where(it => it.ScheduleDate == date).Any();
|
|
if (isExist) { return -2; }
|
|
|
|
//TODO copy 班组人员
|
|
string[] collects = date_schedules.Select(it => it.Id).ToArray();
|
|
List<GroupRelPersonGroup> Copy_groups = Context.Queryable<GroupRelPersonGroup>().Where(it => collects.Contains(it.FkGroupId)).ToList();
|
|
|
|
List<GroupRelPersonGroup> inserts_GroupRelPersonGroup = new List<GroupRelPersonGroup>();
|
|
|
|
foreach (var group in date_schedules)
|
|
{
|
|
|
|
group.ScheduleDate = date;
|
|
group.CreatedBy = CreatedBy;
|
|
group.CreatedTime = DateTime.Now;
|
|
group.UpdatedBy = CreatedBy;
|
|
group.UpdatedTime = DateTime.Now;
|
|
//组绑定 的人员
|
|
List<GroupRelPersonGroup> Copy_group_presons = Copy_groups.Where(it => it.FkGroupId == group.Id).ToList();
|
|
if (Copy_group_presons.Count > 0)
|
|
{
|
|
group.Id = XueHua;
|
|
foreach (var person in Copy_group_presons)
|
|
{
|
|
person.FkGroupId = group.Id;
|
|
person.CreatedBy = group.CreatedBy;
|
|
person.CreatedTime = group.CreatedTime;
|
|
}
|
|
string[] person_id_array = Copy_group_presons.Select(it => it.FkPersonId).ToArray();
|
|
|
|
string[] Resigneds = Context.Queryable<GroupPerson>().Where(it => person_id_array.Contains(it.Id))
|
|
.Where(it => it.Status == 0)
|
|
.Select(it => it.Id)
|
|
.ToArray();
|
|
if (Resigneds.Length > 0)
|
|
{
|
|
Copy_group_presons = Copy_group_presons.Where(it => !Resigneds.Contains(it.FkPersonId)).ToList();
|
|
}
|
|
|
|
|
|
inserts_GroupRelPersonGroup.AddRange(Copy_group_presons);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
UseTran2(() =>
|
|
{
|
|
// 删除原有数据
|
|
// Context.Deleteable(date_schedules).ExecuteCommand();
|
|
// Context.Deleteable<GroupRelPersonGroup>().Where(it => collects.Contains(it.FkGroupId)).ExecuteCommand();
|
|
result = Context.Insertable(date_schedules).ExecuteCommand();
|
|
Context.Insertable(inserts_GroupRelPersonGroup).ExecuteCommand();
|
|
|
|
});
|
|
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |