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 NPOI.SS.Formula.Functions;
using NPOI.XSSF.UserModel;
using Aliyun.OSS;
using DOAN.Model.MES.base_.Dto;
using DOAN.Model.MES.base_;
using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.Mvc;
namespace DOAN.Service.group
{
///
/// 人员技能Service业务层处理
///
[AppService(ServiceType = typeof(IGroupPersonSkillService), ServiceLifetime = LifeTime.Transient)]
public class GroupPersonSkillService : BaseService, IGroupPersonSkillService
{
///
/// 查询人员技能列表
///
///
///
public PagedInfo GetList(GroupPersonSkillQueryDto parm)
{
var predicate = Expressionable.Create()
.AndIF(!string.IsNullOrEmpty(parm.SkillName), it => it.SkillName.Contains(parm.SkillName))
.AndIF(parm.Status > 0, it => it.Status == parm.Status)
;
var response = Queryable()
.Where(predicate.ToExpression())
.ToPage(parm);
return response;
}
///
/// 获取详情
///
///
///
public GroupPersonSkill GetInfo(string Id)
{
var response = Queryable()
.Where(x => x.Id == Id)
.First();
return response;
}
///
/// 添加人员技能
///
///
///
public GroupPersonSkill AddGroupPersonSkill(GroupPersonSkill model)
{
if (string.IsNullOrEmpty(model.Id))
{
model.Id = XueHua;
}
return Context.Insertable(model).ExecuteReturnEntity();
}
///
/// 修改人员技能
///
///
///
public int UpdateGroupPersonSkill(GroupPersonSkill model)
{
//var response = Update(w => w.Id == model.Id, it => new GroupPersonSkill()
//{
// SkillName = model.SkillName,
// Image = model.Image,
// Vedio = model.Vedio,
// Remark = model.Remark,
// Status = model.Status,
// CreatedBy = model.CreatedBy,
// CreatedTime = model.CreatedTime,
// UpdatedBy = model.UpdatedBy,
// UpdatedTime = model.UpdatedTime,
//});
//return response;
return Update(model, true);
}
///
/// 人员技能评估
///
///
///
public int PersonskillAssessment(GroupRelPersonSkill relPersonSkill)
{
return Context.Storageable(relPersonSkill).ExecuteCommand();
}
//获取人员已经拥有的技能
public List GetPersonSkills(string person_id)
{
var query = Context.Queryable().Where(it => it.FkPersonId == person_id);
return Context.Queryable(query).LeftJoin((rel, s) => rel.FkSkillId == s.Id)
.Select((rel, s) => new GroupPersonSkillDto2() { score = rel.Score.Value }, true)
.ToList();
}
//获取人员没有拥有的技能
public PagedInfo GetPersonUnownSkills(GroupPersonSkillQueryDto2 parm)
{
var query = Context.Queryable().Where(it => it.FkPersonId == parm.person_id);
return Context.Queryable(query).RightJoin((rel, s) => rel.FkSkillId == s.Id)
.Where((rel, s) => rel.FkSkillId == null)
.WhereIF(!string.IsNullOrEmpty(parm.SkillName), (rel, s) => s.SkillName.Contains(parm.SkillName))
.Select((rel, s) => s)
.ToPage(parm);
}
///
/// 取消绑定
///
///
///
///
public int CancalPersonSkillBind(string person_id, string skill_id)
{
return Context.Deleteable()
.Where(it => it.FkPersonId == person_id && it.FkSkillId == skill_id)
.ExecuteCommand();
}
///
/// 获取工艺路线
///
///
///
public List GetWorkRouteList([FromBody] BaseWorkRouteQueryDto query)
{
List workRouteList = Context.Queryable()
.WhereIF(!string.IsNullOrEmpty(query.Name), it => it.Name.Contains(query.Name))
.WhereIF(!string.IsNullOrEmpty(query.Code), it => it.Code.Contains(query.Code))
.WhereIF(query.Status > 0, it => it.Status == query.Status)
.ToList();
return workRouteList;
}
///
/// 根据工艺路线查工位
///
///
///
public PagedInfo GetWorkstationbyRoute(BaseWorkStationQueryDto2 query)
{
var query1 = Context.Queryable()
.Where(it => it.FkWorkRoute == query.route_id);
List workProcesses = Context.Queryable(query1).LeftJoin((q, p) => q.FkWorkProcesses == p.Id)
.Select((q, p) => p)
.ToList();
int?[] filters= workProcesses.Select(it=>it.Id).ToArray();
return Context.Queryable()
.Where(it => filters.Contains(it.FkWorkProcesses))
.ToPage(query);
}
///
/// 获取工艺路线与工序父子表
///
///
///
public List RouteProcessParentSon(BaseWorkRouteQueryDto query)
{
List result = new List();
List workRouteList = Context.Queryable()
.WhereIF(!string.IsNullOrEmpty(query.Name), it => it.Name.Contains(query.Name))
.WhereIF(!string.IsNullOrEmpty(query.Code), it => it.Code.Contains(query.Code))
.WhereIF(query.Status > 0, it => it.Status == query.Status)
.ToList();
// int[] queryints = workRouteList.Select(it => it.Id).ToArray();
if (workRouteList != null && workRouteList.Count > 0)
{
foreach (var workRoute in workRouteList)
{
RouteANDprocess parent = new RouteANDprocess();
parent.Name = workRoute.Name;
parent.Id = workRoute.Id;
parent.parentId = 0;
result.Add(parent);
var query1 = Context.Queryable()
.Where(it => it.FkWorkRoute == workRoute.Id);
List workProcesses = Context.Queryable(query1).LeftJoin((q, p) => q.FkWorkProcesses == p.Id)
.Select((q, p) => p)
.ToList();
if (workProcesses != null && workProcesses.Count > 0)
{
foreach (var process in workProcesses)
{
RouteANDprocess son = new RouteANDprocess();
son.Name = process.Name;
son.Id = process.Id.Value;
son.parentId = parent.Id;
result.Add(son);
}
}
}
}
return result;
}
///
/// 根据工序查工位
///
///
///
public List GetWorkstationList_byProccess(int workProcess_id)
{
return Context.Queryable().Where(it => it.FkWorkProcesses == workProcess_id).ToList();
}
///
/// 获取工位绑定的技能
///
///
///
public List GetWorkstationBindSkillList(int workstation_id)
{
var query = Context.Queryable().Where(it => it.FkWorkstationId == workstation_id);
return Context.Queryable(query).LeftJoin((rel, s) => rel.FkSkillId == s.Id)
.Select((rel, s) => s)
.ToList();
}
///
/// 获取工位没有绑定的技能 分页
///
///
///
public PagedInfo GetWorkstationunBindSkillList(GroupPersonSkillQueryDto3 parm)
{
var query = Context.Queryable().Where(it => it.FkWorkstationId == parm.workstation_id);
return Context.Queryable(query).RightJoin((rel, s) => rel.FkSkillId == s.Id)
.Where((rel, s) => rel.FkSkillId == null)
.WhereIF(!string.IsNullOrEmpty(parm.SkillName),(rel, s) => s.SkillName.Contains(parm.SkillName))
.Select((rel, s) => s)
.ToPage(parm);
}
public int HandleWorkstationbindSkill(int workstation_id, string skill_id)
{
GroupRelWorkstationSkill relWorkstationSkill = new GroupRelWorkstationSkill();
relWorkstationSkill.FkSkillId = skill_id;
relWorkstationSkill.FkWorkstationId = workstation_id;
return Context.Insertable(relWorkstationSkill).ExecuteCommand();
}
public int LiftedWorkstationbindSkill(int workstation_id, string skill_id)
{
return Context.Deleteable()
.Where(it => it.FkWorkstationId == workstation_id)
.Where(it => it.FkSkillId == skill_id)
.ExecuteCommand();
}
}
}