559 lines
21 KiB
C#
559 lines
21 KiB
C#
using DOAN.Model.BZFM;
|
|
using DOAN.Model.BZFM.Dto;
|
|
using DOAN.Model.MES.base_;
|
|
using DOAN.Model.MES.base_.Dto;
|
|
using DOAN.Model.MES.order;
|
|
using DOAN.Model.MES.product;
|
|
using DOAN.Model.Mobile.ReportFlow.Dto;
|
|
using DOAN.Model.System;
|
|
using DOAN.Repository;
|
|
using DOAN.Service.BZFM;
|
|
using DOAN.Service.Mobile.IService;
|
|
using Infrastructure.Attribute;
|
|
using Mapster;
|
|
|
|
namespace DOAN.Service.Mobile;
|
|
|
|
/// <summary>
|
|
/// 广告管理Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IReportFlowService), ServiceLifetime = LifeTime.Transient)]
|
|
public class ReportFlowService : BaseService<ProReportwork01>, IReportFlowService
|
|
{
|
|
public ProWorkorder GetWorkOrderDetail(string workorder)
|
|
{
|
|
return Context.Queryable<ProWorkorder>().Where(x => x.Workorder == workorder).First();
|
|
}
|
|
|
|
public List<ProWorkorder> GetWorkOrdersByDate(DateTime startDate, DateTime endDate)
|
|
{
|
|
return Context
|
|
.Queryable<ProWorkorder>()
|
|
.Where(it => it.WorkorderDate >= startDate && it.WorkorderDate <= endDate)
|
|
.ToList();
|
|
}
|
|
|
|
public ProReportwork01 GetProcessReportWorkDetail(string workorder, int process)
|
|
{
|
|
return Context
|
|
.Queryable<ProReportwork01>()
|
|
.Where(x => x.Workorder == workorder && x.ProcessId == process)
|
|
.First();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 首工序报工(领料报工)
|
|
/// </summary>
|
|
/// <param name="workorder"></param>
|
|
/// <param name="processId"></param>
|
|
/// <param name="finish_num"></param>
|
|
/// <param name="stove_code"></param>
|
|
/// <param name="feed_order"></param>
|
|
/// <param name="Worker"></param>
|
|
/// <returns></returns>
|
|
public bool FeedProcessReportwork(
|
|
string workorder,
|
|
int processId,
|
|
int finish_num,
|
|
string stove_code,
|
|
string feed_order,
|
|
string Worker
|
|
)
|
|
{
|
|
try
|
|
{
|
|
int result = 0;
|
|
// 是否首次提交
|
|
bool Exist = Context
|
|
.Queryable<ProReportwork01>()
|
|
.Where(it => it.Workorder == workorder && it.ProcessId == processId)
|
|
.Any();
|
|
|
|
string NickName = Context
|
|
.Queryable<SysUser>()
|
|
.Where(it => it.UserName == Worker)
|
|
.Select(it => it.NickName)
|
|
.First();
|
|
Worker = string.IsNullOrEmpty(NickName) ? Worker + "|异常人员|" : NickName;
|
|
|
|
Context.Ado.BeginTran();
|
|
if (Exist)
|
|
{
|
|
result = Context
|
|
.Updateable<ProReportwork01>()
|
|
.Where(it => it.Workorder == workorder && it.ProcessId == processId)
|
|
.SetColumns(it => it.FinishNum == finish_num)
|
|
.SetColumns(it => it.Worker == Worker)
|
|
.SetColumns(it => it.JobDateTime == DateTime.Now)
|
|
.SetColumns(it => it.RouteId == 32)
|
|
.SetColumns(it => it.UpdatedBy == Worker)
|
|
.SetColumns(it => it.UpdatedTime == DateTime.Now)
|
|
.ExecuteCommand();
|
|
Context
|
|
.Updateable<ProWorkorder>()
|
|
.Where(it => it.Workorder == workorder)
|
|
.SetColumns(it => it.StoveCode == stove_code)
|
|
.SetColumns(it => it.FeedOrder == feed_order)
|
|
.ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
ProReportwork01 proReportwork01 = new ProReportwork01();
|
|
proReportwork01.Id = XueHua;
|
|
proReportwork01.Workorder = workorder;
|
|
proReportwork01.ProcessId = processId;
|
|
proReportwork01.FinishNum = finish_num;
|
|
proReportwork01.RouteId = 32;
|
|
proReportwork01.Worker = Worker;
|
|
proReportwork01.JobDateTime = DateTime.Now;
|
|
proReportwork01.CreatedBy = Worker;
|
|
proReportwork01.CreatedTime = DateTime.Now;
|
|
result = Context.Insertable(proReportwork01).ExecuteCommand();
|
|
Context
|
|
.Updateable<ProWorkorder>()
|
|
.Where(it => it.Workorder == workorder)
|
|
.SetColumns(it => it.StoveCode == stove_code)
|
|
.SetColumns(it => it.FeedOrder == feed_order)
|
|
.ExecuteCommand();
|
|
}
|
|
//XXX 领料出库操作(上边代码先不动)
|
|
MmRecordOutbound outRecordbound = Context
|
|
.Queryable<MmRecordOutbound>()
|
|
.Where(it => it.Workorder == workorder)
|
|
.Where(it => it.TransactionType == "领料出库")
|
|
.Where(it => it.Remarks != "已撤销")
|
|
.First();
|
|
ProWorkorder proWorkorder = Context
|
|
.Queryable<ProWorkorder>()
|
|
.Where(it => it.Workorder == workorder)
|
|
.First();
|
|
if (proWorkorder == null)
|
|
{
|
|
throw new Exception($"工单异常,原材料无法出库:{workorder}");
|
|
}
|
|
|
|
if (outRecordbound == null)
|
|
{
|
|
OutboundReceiptDto revokeRecepitDto = new()
|
|
{
|
|
ReceiptType = 1,
|
|
MaterialCode = proWorkorder.MaterialCode,
|
|
BatchNo = feed_order,
|
|
LocationCode = "YCL001",
|
|
WarehouseCode = "WH003",
|
|
OrderNo = proWorkorder.CustomerOrder,
|
|
Workorder = workorder,
|
|
Operator = Worker,
|
|
Quantity = finish_num,
|
|
TransactionType = "领料出库",
|
|
Remarks = $"生产领料,工单号:{workorder}",
|
|
};
|
|
MmInventoryService mmInventoryService = new();
|
|
string createReceiptresult = mmInventoryService.CreateOutboundReceipt(revokeRecepitDto);
|
|
if (createReceiptresult != "ok")
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception(createReceiptresult);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (outRecordbound.Quantity != finish_num)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception("修改领料数量前请先撤销已有领料出库记录!");
|
|
}
|
|
if (outRecordbound.BatchNo != feed_order)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception("修改领料号前请先撤销已有领料出库记录!");
|
|
}
|
|
}
|
|
Context.Ado.CommitTran();
|
|
return result > 0;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 普通工序报工
|
|
/// </summary>
|
|
/// <param name="workorder"></param>
|
|
/// <param name="process"></param>
|
|
/// <param name="finish_num"></param>
|
|
/// <param name="bad_num"></param>
|
|
/// <param name="Worker"></param>
|
|
/// <returns></returns>
|
|
public bool ProcessReportWork(
|
|
string workorder,
|
|
int process,
|
|
int finish_num,
|
|
int bad_num,
|
|
string Worker
|
|
)
|
|
{
|
|
try
|
|
{
|
|
int result = 0;
|
|
bool Exist = Context
|
|
.Queryable<ProReportwork01>()
|
|
.Where(it => it.Workorder == workorder && it.ProcessId == process)
|
|
.Any();
|
|
string NickName = Context
|
|
.Queryable<SysUser>()
|
|
.Where(it => it.UserName == Worker)
|
|
.Select(it => it.NickName)
|
|
.First();
|
|
Worker = string.IsNullOrEmpty(NickName) ? Worker + "|异常人员|" : NickName;
|
|
|
|
Context.Ado.BeginTran();
|
|
if (Exist)
|
|
{
|
|
result = Context
|
|
.Updateable<ProReportwork01>()
|
|
.Where(it => it.Workorder == workorder && it.ProcessId == process)
|
|
.SetColumns(it => it.FinishNum == finish_num)
|
|
.SetColumns(it => it.BadNum == bad_num)
|
|
.SetColumns(it => it.Worker == Worker)
|
|
.SetColumns(it => it.RouteId == 32)
|
|
.SetColumns(it => it.JobDateTime == DateTime.Now)
|
|
.SetColumns(it => it.UpdatedBy == Worker)
|
|
.SetColumns(it => it.UpdatedTime == DateTime.Now)
|
|
.ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
ProReportwork01 proReportwork01 = new ProReportwork01();
|
|
proReportwork01.Id = XueHua;
|
|
proReportwork01.Workorder = workorder;
|
|
proReportwork01.ProcessId = process;
|
|
proReportwork01.FinishNum = finish_num;
|
|
proReportwork01.BadNum = bad_num;
|
|
proReportwork01.Worker = Worker;
|
|
proReportwork01.RouteId = 32;
|
|
proReportwork01.JobDateTime = DateTime.Now;
|
|
proReportwork01.CreatedBy = Worker;
|
|
proReportwork01.CreatedTime = DateTime.Now;
|
|
result = Context.Insertable(proReportwork01).ExecuteCommand();
|
|
}
|
|
|
|
// XXX TODO 成品入库(临时使用)
|
|
|
|
if (process == 70)
|
|
{
|
|
// 成品入库
|
|
ProWorkorder proWorkorder = Context
|
|
.Queryable<ProWorkorder>()
|
|
.Where(it => it.Workorder == workorder)
|
|
.First();
|
|
if (proWorkorder == null)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception($"工单异常,无法成品入库:{workorder}");
|
|
}
|
|
MmRecordInbound inboundRecord = Context
|
|
.Queryable<MmRecordInbound>()
|
|
.Where(it => it.Workorder == workorder)
|
|
.Where(it => it.TransactionType == "生产入库")
|
|
.Where(it => it.Remarks != "已撤销")
|
|
.First();
|
|
MmMaterial mmMaterial = Context
|
|
.Queryable<MmMaterial>()
|
|
.Where(it => it.MaterialCode == proWorkorder.productionCode)
|
|
.First();
|
|
if (mmMaterial == null)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception($"物料档案不存在,无法成品入库:{proWorkorder.productionCode}");
|
|
}
|
|
if (inboundRecord == null)
|
|
{
|
|
//做生产入库单
|
|
InboundReceiptDto revokeRecepitDto = new()
|
|
{
|
|
ReceiptType = 1,
|
|
MaterialCode = proWorkorder.productionCode,
|
|
BatchNo = proWorkorder.FeedOrder,
|
|
LocationCode = "CP001",
|
|
WarehouseCode = "WH001",
|
|
SupplierCode = mmMaterial.SupplierCode,
|
|
StoveCode = proWorkorder.StoveCode,
|
|
Workorder = workorder,
|
|
Operator = Worker,
|
|
Quantity = finish_num,
|
|
TransactionType = "生产入库",
|
|
Remarks = $"成品入库,工单号:{workorder}",
|
|
};
|
|
MmInventoryService mmInventoryService = new();
|
|
string createReceiptresult = mmInventoryService.CreateInboundReceipt(
|
|
revokeRecepitDto
|
|
);
|
|
if (createReceiptresult != "ok")
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception(createReceiptresult);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (inboundRecord.Quantity != finish_num)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception("修改数量前请先撤销已有生产入库记录!");
|
|
}
|
|
}
|
|
}
|
|
Context.Ado.CommitTran();
|
|
return result > 0;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 出货工序报工
|
|
/// </summary>
|
|
/// <param name="workorder"></param>
|
|
/// <param name="processId"></param>
|
|
/// <param name="finish_num"></param>
|
|
/// <param name="bad_num"></param>
|
|
/// <param name="customer_order">客户订单号</param>
|
|
/// <param name="Worker"></param>
|
|
/// <returns></returns>
|
|
public int ShipmentProcessReportwork(
|
|
string workorder,
|
|
int processId,
|
|
int finish_num,
|
|
int bad_num,
|
|
string customer_order,
|
|
string Worker
|
|
)
|
|
{
|
|
try
|
|
{
|
|
//TODO 20250411 采购订单号和工单号是否匹配逻辑不适配实际情况,进行修改
|
|
|
|
// 判断订单号是否存在
|
|
OrderPurchase orderPurchase = Context
|
|
.Queryable<OrderPurchase>()
|
|
.Where(o => o.OrderNoMes == customer_order)
|
|
.First();
|
|
if (orderPurchase == null)
|
|
{
|
|
// 订单号不存在
|
|
return 2;
|
|
}
|
|
// 判断工单是否存在
|
|
ProWorkorder workorderInfo = Context
|
|
.Queryable<ProWorkorder>()
|
|
.Where(it => it.Workorder == workorder)
|
|
.First();
|
|
if (workorderInfo == null)
|
|
{
|
|
// 工单不存在
|
|
return 4;
|
|
}
|
|
// 判断工单主体型号和订单物料号是否匹配
|
|
if (workorderInfo.productionCode != orderPurchase.MaterialCode)
|
|
{
|
|
return 5;
|
|
}
|
|
|
|
string NickName = Context
|
|
.Queryable<SysUser>()
|
|
.Where(it => it.UserName == Worker)
|
|
.Select(it => it.NickName)
|
|
.First();
|
|
Worker = string.IsNullOrEmpty(NickName) ? Worker + "|异常人员|" : NickName;
|
|
|
|
int result = 0;
|
|
|
|
// 判断报工信息是否存在
|
|
Context.Ado.BeginTran();
|
|
// 更新报工信息
|
|
ProReportwork01 ReportWorkOrderDetail = Context
|
|
.Queryable<ProReportwork01>()
|
|
.Where(it => it.Workorder == workorder && it.ProcessId == processId)
|
|
.First();
|
|
if (ReportWorkOrderDetail == null)
|
|
{
|
|
// 新增
|
|
ProReportwork01 proReportwork01 = new()
|
|
{
|
|
Id = XueHua,
|
|
Workorder = workorder,
|
|
ProcessId = processId,
|
|
FinishNum = finish_num,
|
|
BadNum = bad_num,
|
|
Worker = Worker,
|
|
RouteId = 32,
|
|
JobDateTime = DateTime.Now,
|
|
CreatedBy = Worker,
|
|
CreatedTime = DateTime.Now,
|
|
};
|
|
result = Context.Insertable(proReportwork01).ExecuteCommand();
|
|
}
|
|
else
|
|
{
|
|
// 修改
|
|
ReportWorkOrderDetail.FinishNum = finish_num;
|
|
ReportWorkOrderDetail.BadNum = bad_num;
|
|
ReportWorkOrderDetail.Worker = Worker;
|
|
ReportWorkOrderDetail.UpdatedBy = Worker;
|
|
ReportWorkOrderDetail.UpdatedTime = DateTime.Now;
|
|
result = Context.Updateable(ReportWorkOrderDetail).ExecuteCommand();
|
|
}
|
|
|
|
// XXX 成品库出库
|
|
MmRecordOutbound outboundDto = Context
|
|
.Queryable<MmRecordOutbound>()
|
|
.Where(it => it.Workorder == workorder)
|
|
.Where(it => it.TransactionType == "出货出库")
|
|
.Where(it => it.Remarks != "已撤销")
|
|
.First();
|
|
if (outboundDto == null)
|
|
{
|
|
OutboundReceiptDto revokeRecepitDto = new()
|
|
{
|
|
ReceiptType = 1,
|
|
MaterialCode = workorderInfo.productionCode,
|
|
BatchNo = workorderInfo.FeedOrder,
|
|
LocationCode = "CP001",
|
|
WarehouseCode = "WH001",
|
|
OrderNo = customer_order,
|
|
Workorder = workorder,
|
|
Operator = Worker,
|
|
Quantity = finish_num,
|
|
TransactionType = "出货出库",
|
|
Remarks = $"出货出库,工单号:{workorder},订单号{customer_order}",
|
|
};
|
|
MmInventoryService mmInventoryService = new();
|
|
string createReceiptresult = mmInventoryService.CreateOutboundReceipt(
|
|
revokeRecepitDto
|
|
);
|
|
if(createReceiptresult != "ok")
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception(createReceiptresult);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (outboundDto.Quantity != finish_num)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw new Exception("修改数量前请先撤销出货出库记录");
|
|
}
|
|
}
|
|
|
|
// 修改工单信息
|
|
Context
|
|
.Updateable<ProWorkorder>()
|
|
.Where(it => it.Workorder == workorder)
|
|
.SetColumns(it => it.ShipmentNum == finish_num)
|
|
.SetColumns(it => it.CustomerOrder == customer_order)
|
|
.ExecuteCommand();
|
|
// 修改采购订单信息
|
|
int newQuantity =
|
|
Context
|
|
.Queryable<ProWorkorder>()
|
|
.Where(it => it.CustomerOrder == customer_order)
|
|
.Sum(it => it.ShipmentNum)
|
|
?? 0;
|
|
orderPurchase.DeliveryQuantity = newQuantity;
|
|
if (orderPurchase.DeliveryQuantity > orderPurchase.DemandQuantity)
|
|
{
|
|
// 订单超额了
|
|
Context.Ado.RollbackTran();
|
|
return 3;
|
|
}
|
|
if (orderPurchase.DeliveryQuantity == orderPurchase.DemandQuantity)
|
|
{
|
|
orderPurchase.Orderindicator = 1;
|
|
}
|
|
else
|
|
{
|
|
orderPurchase.Orderindicator = 0;
|
|
}
|
|
int res = Context.Updateable(orderPurchase).ExecuteCommand();
|
|
Context.Ado.CommitTran();
|
|
return result > 0 ? 1 : 0;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Context.Ado.RollbackTran();
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public List<ProReportWorkDetialDto> GetWorkOrderReportWorkList(string workorder)
|
|
{
|
|
return Context
|
|
.Queryable<ProReportwork01>()
|
|
.LeftJoin<BaseWorkProcesses>((rw, wp) => rw.ProcessId == wp.Id)
|
|
.Where((rw, wp) => rw.Workorder == workorder)
|
|
.OrderBy(rw => rw.ProcessId)
|
|
.Select((rw, wp) => new ProReportWorkDetialDto() { ProcessName = wp.Name }, true)
|
|
.ToList();
|
|
}
|
|
|
|
public PagedInfo<ProReportWorkDetialDto> GetReportInfoByName(ProReportWorkDto2 query)
|
|
{
|
|
string NickName = Context
|
|
.Queryable<SysUser>()
|
|
.Where(it => it.UserName == query.name)
|
|
.Select(it => it.NickName)
|
|
.First();
|
|
query.name = string.IsNullOrEmpty(NickName) ? query.name + "|异常人员|" : NickName;
|
|
|
|
return Context
|
|
.Queryable<ProReportwork01>()
|
|
.LeftJoin<BaseWorkProcesses>((rw, wp) => rw.ProcessId == wp.Id)
|
|
.Where(
|
|
(rw, wp) =>
|
|
rw.Worker == query.name
|
|
&& rw.JobDateTime >= DateTime.Today
|
|
&& rw.JobDateTime < DateTime.Today.AddDays(1)
|
|
)
|
|
.OrderBy(rw => rw.ProcessId)
|
|
.Select((rw, wp) => new ProReportWorkDetialDto() { ProcessName = wp.Name }, true)
|
|
.ToPage_NO_Convert(query);
|
|
}
|
|
|
|
public List<BaseWorkProcessesDto> GetProcessByRoute(int route_id)
|
|
{
|
|
return Context
|
|
.Queryable<BaseRelWorkRouteProcesses>()
|
|
.LeftJoin<BaseWorkProcesses>((rel, pro) => rel.FkWorkProcesses == pro.Id)
|
|
.Where((rel, pro) => rel.FkWorkRoute == route_id)
|
|
.Select((rel, pro) => pro)
|
|
.ToList()
|
|
.Adapt<List<BaseWorkProcesses>, List<BaseWorkProcessesDto>>();
|
|
}
|
|
|
|
public PagedInfo<ProReportWorkDetialDto> GetReportByProcessId(ProReportWorkDto3 query)
|
|
{
|
|
return Context
|
|
.Queryable<ProReportwork01>()
|
|
.LeftJoin<BaseWorkProcesses>((rw, wp) => rw.ProcessId == wp.Id)
|
|
.Where(
|
|
(rw, wp) =>
|
|
rw.ProcessId == query.processId
|
|
&& rw.JobDateTime >= DateTime.Today
|
|
&& rw.JobDateTime < DateTime.Today.AddDays(1)
|
|
)
|
|
.OrderBy(rw => rw.ProcessId)
|
|
.Select((rw, wp) => new ProReportWorkDetialDto() { ProcessName = wp.Name }, true)
|
|
.ToPage_NO_Convert(query);
|
|
}
|
|
}
|