173 lines
6.6 KiB
C#
173 lines
6.6 KiB
C#
using DOAN.Model.MES.base_;
|
||
using DOAN.Model;
|
||
using DOAN.Model.MES.product;
|
||
using DOAN.Model.MES.product.Dto;
|
||
using DOAN.Service.MES.product.IService;
|
||
using Infrastructure.Attribute;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using DOAN.Repository;
|
||
using DOAN.Model.MES.base_.Dto;
|
||
using Mapster;
|
||
using Microsoft.AspNetCore.Authentication;
|
||
|
||
|
||
|
||
namespace DOAN.Service.MES.product
|
||
{
|
||
/// <summary>
|
||
/// 生产工单Service业务层处理
|
||
/// </summary>
|
||
[AppService(ServiceType = typeof(IProWorkorderScheduleService), ServiceLifetime = LifeTime.Transient)]
|
||
public class ProWorkorderScheduleService : BaseService<ProWorkorder>, IProWorkorderScheduleService
|
||
{
|
||
/// <summary>
|
||
/// 查询生产工单列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
public PagedInfo<ProWorkorderDto> GetList(ProWorkorderQueryDto parm)
|
||
{
|
||
if (parm.WorkorderDate != null && parm.WorkorderDate.Length > 0)
|
||
{
|
||
parm.WorkorderDate[0] = parm.WorkorderDate[0].Date;
|
||
parm.WorkorderDate[1] = parm.WorkorderDate[1].Date;
|
||
|
||
}
|
||
|
||
var predicate = Expressionable.Create<ProWorkorder>()
|
||
.AndIF(!string.IsNullOrEmpty(parm.ProductionName), it => it.ProductionName.Contains(parm.ProductionName))
|
||
.AndIF(!string.IsNullOrEmpty(parm.ProductionCode), it => it.ProductionCode.Contains(parm.ProductionCode))
|
||
.AndIF(!string.IsNullOrEmpty(parm.CustomCode), it => it.CustomCode.Contains(parm.CustomCode))
|
||
.AndIF(parm.WorkorderDate != null && parm.WorkorderDate[0] > DateTime.MinValue, it => it.WorkorderDate >= parm.WorkorderDate[0])
|
||
.AndIF(parm.WorkorderDate != null && parm.WorkorderDate[1] > DateTime.MinValue, it => it.WorkorderDate <= parm.WorkorderDate[1])
|
||
.AndIF(parm.Year > 0, it => it.Year == parm.Year)
|
||
.AndIF(parm.Week > 0, it => it.Week == parm.Week)
|
||
.AndIF(parm.Date > 0, it => it.Date == parm.Date)
|
||
;
|
||
|
||
var response = Queryable()
|
||
.Where(predicate.ToExpression())
|
||
.OrderBy(it => it.WorkorderDate)
|
||
.ToPage<ProWorkorder, ProWorkorderDto>(parm);
|
||
|
||
|
||
|
||
|
||
return response;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取工序
|
||
/// </summary>
|
||
/// <param name="WorkRouteId"></param>
|
||
/// <returns></returns>
|
||
public List<BaseWorkProcessesDto> GetworkProcess(int WorkRouteId)
|
||
{
|
||
var query = Context.Queryable<BaseRelWorkRouteProcesses>().Where(it => it.FkWorkRoute == WorkRouteId);
|
||
return Context.Queryable(query)
|
||
.LeftJoin<BaseWorkProcesses>((q, p) => q.FkWorkProcesses == p.Id)
|
||
.Select((q, p) => p)
|
||
.ToList()
|
||
.Adapt<List<BaseWorkProcessesDto>>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取工位列表 (选中为 1 未选中为0)
|
||
/// </summary>
|
||
/// <param name="WorkorderId">工单号(不是工单id) </param>
|
||
/// <param name="WorkRouteID">工序id</param>
|
||
/// <returns>工序绑定的工位列表</returns>
|
||
public List<BaseWorkStationDto3> GetworkStation(string WorkorderId, int WorkProcessID)
|
||
{
|
||
// 获取工序下可以选择的工位
|
||
List<BaseWorkStationDto3> Choices= Context.Queryable<BaseWorkStation>()
|
||
.Where(it => it.FkWorkProcesses == WorkProcessID)
|
||
.ToList().Adapt<List<BaseWorkStationDto3>>();
|
||
int Selected_id= Context.Queryable<ProRelWorkorderLineBody>()
|
||
.Where(it => it.FkWorkorderId == WorkorderId)
|
||
.Where(it => it.FkProcessId == WorkProcessID)
|
||
.Select(it => it.FkStationId)
|
||
.First();
|
||
|
||
if(Choices != null&& Choices.Count()>0)
|
||
{
|
||
foreach(BaseWorkStationDto3 choice in Choices)
|
||
{
|
||
if (choice.Id == Selected_id)
|
||
{
|
||
|
||
choice.flag = 1;
|
||
}
|
||
else
|
||
{
|
||
choice.flag = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
return Choices;
|
||
|
||
|
||
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 修改
|
||
/// </summary>
|
||
/// <param name="lineBodyDto"></param>
|
||
/// <returns></returns>
|
||
public int UpdateSelectedWorkstation(ProRelWorkorderLineBodyDto lineBodyDto)
|
||
{
|
||
return Context.Updateable<ProRelWorkorderLineBody>()
|
||
.SetColumns(it => it.FkStationId == lineBodyDto.FkStationId)
|
||
.Where(it => it.FkWorkorderId == lineBodyDto.FkWorkorderId)
|
||
.Where(it => it.FkProcessId == lineBodyDto.FkProcessId).ExecuteCommand();
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 传入工单号 默认选中
|
||
/// </summary>
|
||
/// <param name="WorkorderId"></param>
|
||
/// <returns></returns>
|
||
public int DefaultSelected(string WorkorderId)
|
||
{
|
||
int result = 0;
|
||
// 查询工单下单 工艺路线BaseRelWorkRouteProcesses
|
||
string RouteCode = Context.Queryable<ProWorkorder>().Where(it => it.Workorder == WorkorderId).Select(it => it.RouteId).First();
|
||
var query= Context.Queryable<BaseWorkRoute>().Where(it => it.Code == RouteCode);
|
||
int[] Processes_id= Context.Queryable(query).InnerJoin<BaseRelWorkRouteProcesses>((q, r) => q.Id == r.FkWorkRoute)
|
||
.Select((q, r) => r.FkWorkProcesses).ToArray();
|
||
var linqs = Context.Queryable<BaseWorkStation>();
|
||
List<ProRelWorkorderLineBody> inserts= new List<ProRelWorkorderLineBody>();
|
||
foreach (var process in Processes_id)
|
||
{
|
||
int station= linqs
|
||
.Where(it => it.FkWorkProcesses == process)
|
||
.Select(it=>it.Id).First();
|
||
|
||
ProRelWorkorderLineBody lineBody= new ProRelWorkorderLineBody();
|
||
lineBody.FkWorkorderId = WorkorderId;
|
||
lineBody.FkProcessId = process;
|
||
lineBody.FkStationId= station;
|
||
lineBody.CreatedTime= DateTime.Now;
|
||
inserts.Add(lineBody);
|
||
}
|
||
|
||
UseTran2(() =>
|
||
{
|
||
Context.Deleteable<ProRelWorkorderLineBody>().Where(it=>it.FkWorkorderId == WorkorderId);
|
||
result=Context.Insertable(inserts).ExecuteCommand();
|
||
|
||
});
|
||
|
||
return result;
|
||
}
|
||
|
||
}
|
||
} |