zhuangpei-mesbackend/DOAN.Service/MES/product/ProWorkorderScheduleService.cs

184 lines
6.9 KiB
C#
Raw Normal View History

2024-07-17 17:30:44 +08:00
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;
2024-07-18 09:16:01 +08:00
using DOAN.Model.MES.base_.Dto;
using Mapster;
2024-07-18 15:00:34 +08:00
using Microsoft.AspNetCore.Authentication;
2024-07-17 17:30:44 +08:00
namespace DOAN.Service.MES.product
{
/// <summary>
/// 生产工单Service业务层处理
/// </summary>
2024-07-18 10:17:02 +08:00
[AppService(ServiceType = typeof(IProWorkorderScheduleService), ServiceLifetime = LifeTime.Transient)]
public class ProWorkorderScheduleService : BaseService<ProWorkorder>, IProWorkorderScheduleService
2024-07-17 17:30:44 +08:00
{
/// <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))
2024-09-13 19:06:27 +08:00
2024-07-17 17:30:44 +08:00
.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])
2024-09-13 16:42:06 +08:00
2024-07-17 17:30:44 +08:00
;
var response = Queryable()
.Where(predicate.ToExpression())
.OrderBy(it => it.WorkorderDate)
.ToPage<ProWorkorder, ProWorkorderDto>(parm);
return response;
}
2024-07-18 09:16:01 +08:00
/// <summary>
/// 获取工序
/// </summary>
2024-09-04 16:43:29 +08:00
/// <param name="WorkFkRouteCode"></param>
2024-07-18 09:16:01 +08:00
/// <returns></returns>
2024-09-04 16:43:29 +08:00
public List<BaseWorkProcessesDto> GetworkProcess(int WorkFkRouteCode)
2024-07-18 09:16:01 +08:00
{
2024-09-04 16:43:29 +08:00
var query = Context.Queryable<BaseRelWorkRouteProcesses>().Where(it => it.FkWorkRoute == WorkFkRouteCode);
2024-07-18 09:16:01 +08:00
return Context.Queryable(query)
.LeftJoin<BaseWorkProcesses>((q, p) => q.FkWorkProcesses == p.Id)
.Select((q, p) => p)
.ToList()
.Adapt<List<BaseWorkProcessesDto>>();
}
/// <summary>
2024-07-18 15:00:34 +08:00
/// 获取工位列表 (选中为 1 未选中为0
2024-07-18 09:16:01 +08:00
/// </summary>
2024-07-18 15:00:34 +08:00
/// <param name="WorkorderId">工单号(不是工单id) </param>
2024-09-04 16:43:29 +08:00
/// <param name="WorkFkRouteCode">工序id</param>
2024-07-18 15:00:34 +08:00
/// <returns>工序绑定的工位列表</returns>
2024-07-18 15:41:21 +08:00
public List<BaseWorkStationDto3> GetworkStation(string WorkorderId, int WorkProcessID)
2024-07-18 09:16:01 +08:00
{
2024-07-18 15:00:34 +08:00
// 获取工序下可以选择的工位
2024-07-18 15:41:21 +08:00
List<BaseWorkStationDto3> Choices = Context.Queryable<BaseWorkStation>()
2024-07-18 15:00:34 +08:00
.Where(it => it.FkWorkProcesses == WorkProcessID)
.ToList().Adapt<List<BaseWorkStationDto3>>();
2024-07-19 08:51:16 +08:00
//被选中的工位
2024-07-18 15:41:21 +08:00
int Selected_id = Context.Queryable<ProRelWorkorderLineBody>()
.Where(it => it.FkWorkorderId == WorkorderId)
.Where(it => it.FkProcessId == WorkProcessID)
.Select(it => it.FkStationId)
.First();
2024-07-18 15:00:34 +08:00
2024-07-18 15:41:21 +08:00
if (Choices != null && Choices.Count() > 0)
2024-07-18 15:00:34 +08:00
{
2024-07-18 15:41:21 +08:00
foreach (BaseWorkStationDto3 choice in Choices)
2024-07-18 15:00:34 +08:00
{
if (choice.Id == Selected_id)
{
choice.flag = 1;
}
else
{
choice.flag = 0;
}
}
}
return Choices;
2024-07-18 09:16:01 +08:00
}
2024-07-18 15:00:34 +08:00
2024-07-18 09:16:01 +08:00
/// <summary>
2024-07-18 15:00:34 +08:00
/// 修改
2024-07-18 09:16:01 +08:00
/// </summary>
2024-07-18 15:00:34 +08:00
/// <param name="lineBodyDto"></param>
2024-07-18 09:16:01 +08:00
/// <returns></returns>
2024-07-18 15:00:34 +08:00
public int UpdateSelectedWorkstation(ProRelWorkorderLineBodyDto lineBodyDto)
2024-07-18 09:16:01 +08:00
{
2024-07-18 15:41:21 +08:00
int result = Context.Updateable<ProRelWorkorderLineBody>()
.SetColumns(it => new ProRelWorkorderLineBody() { FkStationId = lineBodyDto.FkStationId })
2024-07-18 15:00:34 +08:00
.Where(it => it.FkWorkorderId == lineBodyDto.FkWorkorderId)
.Where(it => it.FkProcessId == lineBodyDto.FkProcessId).ExecuteCommand();
2024-07-18 15:41:21 +08:00
if (result == 0)
{
ProRelWorkorderLineBody lineBody = new ProRelWorkorderLineBody();
lineBody.FkStationId = lineBodyDto.FkStationId;
lineBody.FkWorkorderId = lineBodyDto.FkWorkorderId;
lineBody.FkProcessId = lineBodyDto.FkProcessId;
2024-07-18 15:43:14 +08:00
lineBody.CreatedTime = DateTime.Now;
2024-07-18 15:41:21 +08:00
result = Context.Insertable(lineBody).ExecuteCommand();
}
return result;
2024-07-18 09:16:01 +08:00
}
2024-07-18 10:17:02 +08:00
/// <summary>
2024-07-18 15:00:34 +08:00
/// 传入工单号 默认选中
2024-07-18 10:17:02 +08:00
/// </summary>
2024-07-18 15:00:34 +08:00
/// <param name="WorkorderId"></param>
2024-07-18 10:17:02 +08:00
/// <returns></returns>
2024-07-18 15:00:34 +08:00
public int DefaultSelected(string WorkorderId)
2024-07-18 10:17:02 +08:00
{
2024-07-18 15:00:34 +08:00
int result = 0;
// 查询工单下单 工艺路线BaseRelWorkRouteProcesses
2024-09-13 16:42:06 +08:00
string RouteCode = Context.Queryable<ProWorkorder>().Where(it => it.Workorder == WorkorderId).Select(it => it.LineCode).First();
2024-07-18 15:41:21 +08:00
var query = Context.Queryable<BaseWorkRoute>().Where(it => it.Code == RouteCode);
int[] Processes_id = Context.Queryable(query).InnerJoin<BaseRelWorkRouteProcesses>((q, r) => q.Id == r.FkWorkRoute)
2024-07-18 15:00:34 +08:00
.Select((q, r) => r.FkWorkProcesses).ToArray();
var linqs = Context.Queryable<BaseWorkStation>();
2024-07-18 15:41:21 +08:00
List<ProRelWorkorderLineBody> inserts = new List<ProRelWorkorderLineBody>();
2024-07-18 15:00:34 +08:00
foreach (var process in Processes_id)
{
2024-07-18 15:41:21 +08:00
int station = linqs
.Where(it => it.FkWorkProcesses == process)
.Select(it => it.Id).First();
2024-07-18 15:00:34 +08:00
2024-07-18 15:41:21 +08:00
ProRelWorkorderLineBody lineBody = new ProRelWorkorderLineBody();
2024-07-18 15:00:34 +08:00
lineBody.FkWorkorderId = WorkorderId;
lineBody.FkProcessId = process;
2024-07-18 15:41:21 +08:00
lineBody.FkStationId = station;
lineBody.CreatedTime = DateTime.Now;
2024-07-18 15:00:34 +08:00
inserts.Add(lineBody);
}
2024-07-18 10:17:02 +08:00
2024-07-18 15:00:34 +08:00
UseTran2(() =>
{
2024-07-18 15:41:21 +08:00
Context.Deleteable<ProRelWorkorderLineBody>().Where(it => it.FkWorkorderId == WorkorderId);
result = Context.Insertable(inserts).ExecuteCommand();
2024-07-18 15:00:34 +08:00
});
return result;
}
2024-07-18 10:17:02 +08:00
2024-07-17 17:30:44 +08:00
}
}