2026-01-28 17:54:15 +08:00
|
|
|
using DOAN.Model.MES.product;
|
|
|
|
|
using DOAN.Model.MES.product.Dto;
|
|
|
|
|
using DOAN.Service.MES.product.IService;
|
|
|
|
|
using Infrastructure;
|
|
|
|
|
using Infrastructure.Attribute;
|
|
|
|
|
|
|
|
|
|
namespace DOAN.Service.MES.product
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 工单工具服务
|
|
|
|
|
/// </summary>
|
2026-01-28 18:44:44 +08:00
|
|
|
[AppService(
|
|
|
|
|
ServiceType = typeof(IProWorkorderUtilityService),
|
|
|
|
|
ServiceLifetime = LifeTime.Transient
|
|
|
|
|
)]
|
2026-01-28 17:54:15 +08:00
|
|
|
public class ProWorkorderUtilityService : BaseService<ProWorkorder>, IProWorkorderUtilityService
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成工单号
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="parm"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int Generate_workorder(ProWorkorderQueryDto2 parm)
|
|
|
|
|
{
|
|
|
|
|
DateTime update_time = parm.WorkorderDate.ToLocalTime().Date;
|
|
|
|
|
|
|
|
|
|
List<ProWorkorder> proWorkorderList = Context
|
|
|
|
|
.Queryable<ProWorkorder>()
|
|
|
|
|
.Where(it => it.WorkorderDate == update_time)
|
|
|
|
|
.Where(it => it.Status == 1)
|
|
|
|
|
.OrderBy(it => it.Sort)
|
|
|
|
|
.ToList();
|
|
|
|
|
string maxs = Context
|
|
|
|
|
.Queryable<ProWorkorder>()
|
|
|
|
|
.Where(it => it.WorkorderDate == update_time)
|
|
|
|
|
.Where(it => it.Status == 3)
|
|
|
|
|
.Max(it => it.Workorder);
|
|
|
|
|
|
|
|
|
|
if (proWorkorderList != null && proWorkorderList.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
string baseSort = update_time.ToString("yyyyMMdd");
|
|
|
|
|
int index = 1;
|
|
|
|
|
if (!string.IsNullOrEmpty(maxs))
|
|
|
|
|
{
|
|
|
|
|
index = Convert.ToInt32(maxs.Substring(maxs.Length - 3)) + 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (ProWorkorder item in proWorkorderList)
|
|
|
|
|
{
|
|
|
|
|
item.Workorder = baseSort + index.ToString("000");
|
|
|
|
|
item.Sort = index * 10;
|
|
|
|
|
index++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Context.Updateable(proWorkorderList).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 移动工单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="type"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int MoveWorkorder(string id, int type)
|
|
|
|
|
{
|
|
|
|
|
int result = 0;
|
|
|
|
|
ProWorkorder toMove = Context
|
|
|
|
|
.Queryable<ProWorkorder>()
|
|
|
|
|
.Where(it => it.Id == id)
|
|
|
|
|
.First();
|
|
|
|
|
var pervious = Context
|
|
|
|
|
.Queryable<ProWorkorder>()
|
|
|
|
|
.Where(it => it.WorkorderDate == toMove.WorkorderDate);
|
|
|
|
|
|
|
|
|
|
//上移动
|
|
|
|
|
if (type == 1)
|
|
|
|
|
{
|
|
|
|
|
pervious = pervious
|
|
|
|
|
.Where(it => it.Sort <= toMove.Sort)
|
|
|
|
|
.OrderByDescending(it => it.Sort);
|
|
|
|
|
}
|
|
|
|
|
//下移
|
|
|
|
|
else if (type == 2)
|
|
|
|
|
{
|
|
|
|
|
pervious = pervious.Where(it => it.Sort >= toMove.Sort).OrderBy(it => it.Sort);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ProWorkorder exchange = pervious.Skip(1).Take(1).First();
|
|
|
|
|
if (exchange != null)
|
|
|
|
|
{
|
|
|
|
|
int temp = toMove.Sort.Value;
|
|
|
|
|
toMove.Sort = exchange.Sort;
|
|
|
|
|
exchange.Sort = temp;
|
|
|
|
|
result += Context.Updateable(toMove).ExecuteCommand();
|
|
|
|
|
result += Context.Updateable(exchange).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 查询BOM及其所需数量
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="workorder_num"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public List<WorkOrderBom> SearchBOMNum(string workorder_num)
|
|
|
|
|
{
|
|
|
|
|
// 这里需要实现BOM查询逻辑
|
|
|
|
|
// 暂时返回空列表
|
|
|
|
|
return new List<WorkOrderBom>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-01-28 18:44:44 +08:00
|
|
|
/// 工单变更日志
|
2026-01-28 17:54:15 +08:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="workorder"></param>
|
|
|
|
|
/// <param name="log"></param>
|
|
|
|
|
/// <param name="Operator"></param>
|
|
|
|
|
/// <returns></returns>
|
2026-01-28 18:44:44 +08:00
|
|
|
public List<ProWorkorderUpdateLog> WorkOrderLog(string workorder)
|
2026-01-28 17:54:15 +08:00
|
|
|
{
|
2026-01-28 18:44:44 +08:00
|
|
|
var result = Context
|
|
|
|
|
.Queryable<ProWorkorderUpdateLog>()
|
|
|
|
|
.Where(it => it.Workorder == workorder)
|
|
|
|
|
.OrderByDescending(it => it.ChangeTime)
|
|
|
|
|
.ToList();
|
|
|
|
|
return result;
|
2026-01-28 17:54:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 导出PDF
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="workorderArray"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Task<(string, Stream)> ExportPDFByQuestPDFDemo(string[] workorderArray)
|
|
|
|
|
{
|
|
|
|
|
// 这里需要实现PDF导出逻辑
|
|
|
|
|
// 暂时返回空结果
|
|
|
|
|
return Task.FromResult(("", (Stream)new MemoryStream()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打印工单
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="param"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public Task<CustomException> PrintTicketsByTemplate(ProWorkorderExportDto param)
|
|
|
|
|
{
|
|
|
|
|
// 这里需要实现工单打印逻辑
|
|
|
|
|
// 暂时返回成功
|
|
|
|
|
return Task.FromResult((CustomException)null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|