390 lines
15 KiB
C#
390 lines
15 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;
|
|
using DOAN.Model.MES.base_;
|
|
using Mapster;
|
|
|
|
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="schedule_date">排班日期</param>
|
|
/// <param name="group_code">排班线别</param>
|
|
/// <returns></returns>
|
|
public List<GroupPersonDto> SearchPerson_group_bind(DateTime schedule_date, string group_code)
|
|
{
|
|
//var query = Context.Queryable<GroupRelPersonGroup>()
|
|
// .LeftJoin<GroupPerson>((rel, p) => rel.FkPersonId == p.Id)
|
|
// .Where((rel, p) => rel.GroupCode == group_code)
|
|
// .Where((rel, p) => rel.ScheduleDate == schedule_date)
|
|
// .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();
|
|
|
|
return Context.Queryable<GroupRelPersonGroup>().LeftJoin<GroupPerson>((rel,p)=>rel.FkPersonId==p.Id)
|
|
.Where((rel, p) => rel.GroupCode == group_code)
|
|
.Where((rel, p) => rel.ScheduleDate == schedule_date)
|
|
.Select((rel, p) => p)
|
|
.ToList()
|
|
.Adapt<List<GroupPersonDto>>()
|
|
;
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询班组未绑定的人员
|
|
/// </summary>
|
|
/// <param name="group_code"></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_code)
|
|
// .Select(it => it.ScheduleDate))
|
|
// .Where(it => it.Id == rel.GroupCode)
|
|
// .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);
|
|
|
|
parm.ScheduleDate= parm.ScheduleDate.Date;
|
|
// 1. 查询已绑定的人员ID列表
|
|
var PersonList = Context.Queryable<GroupRelPersonGroup>()
|
|
.LeftJoin<GroupPerson>((rel, p) => rel.FkPersonId == p.Id)
|
|
.Where((rel, p) => rel.GroupCode == parm.group_code)
|
|
.Where((rel, p) => rel.ScheduleDate == parm.ScheduleDate)
|
|
.Select((rel, p) => p.Id)
|
|
.ToList();
|
|
|
|
// 2. 查询未绑定的人员列表
|
|
var unboundPersons = Context.Queryable<GroupPerson>()
|
|
.Where(x => !PersonList.Contains(x.Id))
|
|
.ToPage<GroupPerson, GroupPersonDto>(parm);
|
|
|
|
return unboundPersons;
|
|
}
|
|
|
|
|
|
public List<BaseGroup> GetALLGroup(string group_code, string group_name)
|
|
{
|
|
return Context.Queryable<BaseGroup>()
|
|
.WhereIF(!string.IsNullOrEmpty(group_code),it=>it.GroupCode.Contains(group_code))
|
|
.WhereIF(!string.IsNullOrEmpty(group_name),it=>it.GroupName.Contains(group_name))
|
|
.ToList();
|
|
}
|
|
|
|
public int GroupAddPerson(string group_code, string person_id,DateTime schedule_date, string CreatedBy)
|
|
{
|
|
GroupRelPersonGroup relPersonGroup = new GroupRelPersonGroup();
|
|
relPersonGroup.GroupCode = group_code;
|
|
relPersonGroup.FkPersonId = person_id;
|
|
relPersonGroup.CreatedTime = DateTime.Now;
|
|
relPersonGroup.CreatedBy = CreatedBy;
|
|
relPersonGroup.ScheduleDate = schedule_date.Date;
|
|
return Context.Insertable(relPersonGroup).ExecuteCommand();
|
|
}
|
|
|
|
public int GroupRemovePerson(string group_code, string person_id)
|
|
{
|
|
return Context.Deleteable<GroupRelPersonGroup>()
|
|
.Where(it => it.GroupCode == group_code)
|
|
.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.ToLocalTime().AddDays(-1).Date;
|
|
|
|
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.ToLocalTime()).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.GroupCode)).ToList();
|
|
|
|
List<GroupRelPersonGroup> inserts_GroupRelPersonGroup = new List<GroupRelPersonGroup>();
|
|
|
|
foreach (var group in date_schedules)
|
|
{
|
|
|
|
group.ScheduleDate = date.ToLocalTime();
|
|
group.CreatedBy = CreatedBy;
|
|
group.CreatedTime = DateTime.Now;
|
|
group.UpdatedBy = CreatedBy;
|
|
group.UpdatedTime = DateTime.Now;
|
|
//组绑定 的人员
|
|
List<GroupRelPersonGroup> Copy_group_presons = Copy_groups.Where(it => it.GroupCode == group.Id).ToList();
|
|
if (Copy_group_presons.Count > 0)
|
|
{
|
|
group.Id = XueHua;
|
|
foreach (var person in Copy_group_presons)
|
|
{
|
|
person.GroupCode = 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);
|
|
|
|
}else
|
|
{
|
|
group.Id = XueHua;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
UseTran2(() =>
|
|
{
|
|
// 删除原有数据
|
|
// Context.Deleteable(date_schedules).ExecuteCommand();
|
|
// Context.Deleteable<GroupRelPersonGroup>().Where(it => collects.Contains(it.GroupCode)).ExecuteCommand();
|
|
result = Context.Insertable(date_schedules).ExecuteCommand();
|
|
Context.Insertable(inserts_GroupRelPersonGroup).ExecuteCommand();
|
|
|
|
});
|
|
|
|
|
|
return result;
|
|
}
|
|
|
|
public List<BaseWorkRoute> GetAllRoutes()
|
|
{
|
|
return Context.Queryable<BaseWorkRoute>().Where(it=>it.Status==1).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取在这个工艺流程下人员的技能
|
|
/// </summary>
|
|
/// <param name="person_id"></param>
|
|
/// <param name="route_id"></param>
|
|
/// <returns></returns>
|
|
public List<GroupPersonOfSkillDto> GetSkillsOFperson(string person_id, int route_id)
|
|
{
|
|
//获取工艺流程下的工位的技能
|
|
var query= Context.Queryable<BaseRelWorkRouteProcesses>()
|
|
.Where(it => it.FkWorkRoute == route_id);
|
|
|
|
|
|
var query2 = Context.Queryable(query)
|
|
.LeftJoin<BaseWorkProcesses>((q, p) => q.FkWorkProcesses == p.Id)
|
|
.Where((q, p) => p.Status == 1).Select((q, p) => p);
|
|
//查到工位
|
|
var query3 = Context.Queryable(query2).LeftJoin<BaseWorkStation>((q, s) => q.Id == s.Id)
|
|
.Where((q, s) => s.Status == 1).Select((q, s) => s);
|
|
//工位技能要求
|
|
List<GroupRelWorkstationSkill> SkillList= Context.Queryable(query3).LeftJoin<GroupRelWorkstationSkill>((q,skill)=>q.Id==skill.FkWorkstationId)
|
|
.Select((q, skill) => skill).ToList();
|
|
string[] queryArray=SkillList.Select(it=>it.FkSkillId).ToArray();
|
|
var query4 = Context.Queryable<GroupRelPersonSkill>().Where(it => it.FkPersonId == person_id)
|
|
.Where(it => queryArray.Contains(it.FkSkillId));
|
|
|
|
|
|
List<GroupPersonOfSkillDto> result_List= Context.Queryable(query4).LeftJoin<GroupPersonSkill>((q,s)=>q.FkSkillId==s.Id)
|
|
.Select((q, s) => new GroupPersonOfSkillDto()
|
|
{
|
|
FkSkillId = q.FkSkillId,
|
|
SkillName=s.SkillName,
|
|
Score = q.Score,
|
|
}).ToList();
|
|
foreach (var item in result_List)
|
|
{
|
|
foreach (var item2 in SkillList)
|
|
{
|
|
if(item.FkSkillId == item2.FkSkillId)
|
|
{
|
|
item.WorkStationDescription = item.WorkStationDescription;
|
|
}
|
|
}
|
|
}
|
|
return result_List;
|
|
|
|
}
|
|
}
|
|
} |