368 lines
12 KiB
C#
368 lines
12 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 DOAN.Model.MES.mm;
|
|
using Mapster;
|
|
using Microsoft.AspNetCore.Authentication;
|
|
using Org.BouncyCastle.Asn1;
|
|
using DOAN.Service.MES.mm.line;
|
|
using DOAN.Service.MES.mm.line.IService;
|
|
|
|
|
|
namespace DOAN.Service.MES.product
|
|
{
|
|
/// <summary>
|
|
/// 报工表Service业务层处理
|
|
/// </summary>
|
|
[AppService(ServiceType = typeof(IProReportworkService), ServiceLifetime = LifeTime.Transient)]
|
|
public class ProReportworkService : BaseService<ProReportwork>, IProReportworkService
|
|
{
|
|
/// <summary>
|
|
/// 查询报工表列表
|
|
/// </summary>
|
|
/// <param name="parm"></param>
|
|
/// <returns></returns>
|
|
public PagedInfo<ProReportworkDto> GetList(ProReportworkQueryDto parm)
|
|
{
|
|
if (parm.TimeRange != null && parm.TimeRange.Length == 2)
|
|
{
|
|
parm.TimeRange[0] = parm.TimeRange[0].Date;
|
|
// parm.TimeRange[1] = parm.TimeRange[1].Date.AddDays(1);
|
|
parm.TimeRange[1] = parm.TimeRange[1].Date;
|
|
}
|
|
|
|
var predicate = Expressionable.Create<ProWorkorder, ProReportwork>()
|
|
.AndIF(!string.IsNullOrEmpty(parm.FkWorkorder), (w, r) => w.Workorder.Contains(parm.FkWorkorder))
|
|
.AndIF(!string.IsNullOrEmpty(parm.GroupCode), (w, r) => w.GroupCode == parm.GroupCode)
|
|
.AndIF(!string.IsNullOrEmpty(parm.LineCode), (w, r) => w.LineCode == parm.LineCode)
|
|
.AndIF(parm.WarehouseconfirmationNum > 0, (w, r) => r.QualifiedNumber > 0)
|
|
.AndIF(
|
|
parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[0] > DateTime.MinValue,
|
|
(w, r) => w.WorkorderDate >= parm.TimeRange[0])
|
|
.AndIF(
|
|
parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[1] > DateTime.MinValue,
|
|
(w, r) => w.WorkorderDate <= parm.TimeRange[1])
|
|
.AndIF(parm.Status > 0, (w, r) => w.Status == parm.Status)
|
|
.AndIF(parm.UnfinishReportwork == 1, (w, r) => r.FinishedNum < r.DispatchNum)
|
|
;
|
|
|
|
|
|
var response = Context.Queryable<ProWorkorder>()
|
|
.LeftJoin<ProReportwork>((w, r) => w.Workorder == r.FkWorkorder)
|
|
.Where(predicate.ToExpression())
|
|
.Select((w, r) => new ProReportworkDto
|
|
{
|
|
Id = r.Id,
|
|
ProductionCode = w.ProductionCode,
|
|
ProductionName = w.ProductionName,
|
|
Specification = w.Specification,
|
|
QualifiedNumber = r.QualifiedNumber,
|
|
UnqualifiedNumber = r.UnqualifiedNumber,
|
|
ReworkNumber = r.ReworkNumber,
|
|
ScrapNumber = r.ScrapNumber,
|
|
UnfinishedReanson = r.UnfinishedReanson,
|
|
WorkorderRamark = w.Remark,
|
|
Remark = r.Remark,
|
|
Difference = r.QualifiedNumber - r.FinishedNum ?? 0,
|
|
FkWorkorder = w.Workorder,
|
|
GroupCode = w.GroupCode,
|
|
LineCode = w.LineCode,
|
|
DispatchNum = w.DeliveryNum ?? 0,
|
|
Priority = w.Priority,
|
|
Status = w.Status,
|
|
Beat = w.Beat,
|
|
IsProductPutIn = r.IsProductPutIn
|
|
}, true).ToPage_NO_Convert<ProReportworkDto>(parm);
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
public PagedInfo<ProReportworkDto> GetList_Print(ProReportworkQueryDto parm)
|
|
{
|
|
if (parm.TimeRange != null && parm.TimeRange.Length == 2)
|
|
{
|
|
parm.TimeRange[0] = parm.TimeRange[0].Date;
|
|
// parm.TimeRange[1] = parm.TimeRange[1].Date.AddDays(1);
|
|
parm.TimeRange[1] = parm.TimeRange[1].Date;
|
|
}
|
|
|
|
var predicate = Expressionable.Create<ProWorkorder, ProReportwork>()
|
|
.AndIF(!string.IsNullOrEmpty(parm.FkWorkorder), (w, r) => w.Workorder.Contains(parm.FkWorkorder))
|
|
.AndIF(!string.IsNullOrEmpty(parm.GroupCode), (w, r) => w.GroupCode == parm.GroupCode)
|
|
.AndIF(!string.IsNullOrEmpty(parm.LineCode), (w, r) => w.LineCode == parm.LineCode)
|
|
.AndIF(parm.WarehouseconfirmationNum > 0, (w, r) => r.QualifiedNumber > 0)
|
|
.AndIF(
|
|
parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[0] > DateTime.MinValue,
|
|
(w, r) => w.WorkorderDate >= parm.TimeRange[0])
|
|
.AndIF(
|
|
parm.TimeRange != null && parm.TimeRange.Length == 2 && parm.TimeRange[1] > DateTime.MinValue,
|
|
(w, r) => w.WorkorderDate <= parm.TimeRange[1])
|
|
.AndIF(parm.Status > 0, (w, r) => w.Status == parm.Status)
|
|
.AndIF(parm.UnfinishReportwork == 1, (w, r) => r.FinishedNum < r.DispatchNum)
|
|
;
|
|
|
|
|
|
var response = Context.Queryable<ProWorkorder>()
|
|
.LeftJoin<ProReportwork>((w, r) => w.Workorder == r.FkWorkorder)
|
|
.Where(predicate.ToExpression())
|
|
.Select((w, r) => new ProReportworkDto
|
|
{
|
|
Id = r.Id,
|
|
ProductionCode = w.ProductionCode,
|
|
ProductionName = w.ProductionName,
|
|
Specification = w.Specification,
|
|
QualifiedNumber = r.QualifiedNumber,
|
|
UnqualifiedNumber = r.UnqualifiedNumber,
|
|
ReworkNumber = r.ReworkNumber,
|
|
ScrapNumber = r.ScrapNumber,
|
|
UnfinishedReanson = r.UnfinishedReanson,
|
|
WorkorderRamark = w.Remark,
|
|
Remark = r.Remark,
|
|
Difference = r.QualifiedNumber - r.FinishedNum ?? 0,
|
|
FkWorkorder = w.Workorder,
|
|
GroupCode = w.GroupCode,
|
|
LineCode = w.LineCode,
|
|
DispatchNum = w.DeliveryNum ?? 0,
|
|
Priority = w.Priority,
|
|
Status = w.Status,
|
|
Beat = w.Beat,
|
|
IsProductPutIn = r.IsProductPutIn
|
|
}, true)
|
|
.MergeTable()
|
|
.OrderBy(t => new { t.GroupCode, t.ProductionCode })
|
|
//TODO 很奇怪 排序位置不对 差距那么大
|
|
.ToPage_NO_Convert<ProReportworkDto>(parm);
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 获取详情
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <returns></returns>
|
|
public ProReportwork GetInfo(string Id)
|
|
{
|
|
var response = Queryable()
|
|
.Where(x => x.Id == Id)
|
|
.First();
|
|
|
|
return response;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加报工表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public ProReportwork AddProReportwork(ProReportwork model)
|
|
{
|
|
model.Id = XueHua;
|
|
|
|
|
|
|
|
return Context.Insertable(model).ExecuteReturnEntity();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 修改报工表
|
|
/// </summary>
|
|
/// <param name="model"></param>
|
|
/// <returns></returns>
|
|
public int UpdateProReportwork(ProReportwork model)
|
|
{
|
|
|
|
|
|
|
|
//var response = Update(w => w.Id == model.Id, it => new ProReportwork()
|
|
//{
|
|
// FkWorkorder = model.FkWorkorder,
|
|
// DispatchNum = model.DispatchNum,
|
|
// FinishedNum = model.FinishedNum,
|
|
// GroupCode = model.GroupCode,
|
|
// LineCode = model.LineCode,
|
|
// CreatedBy = model.CreatedBy,
|
|
// CreatedTime = model.CreatedTime,
|
|
// UpdatedBy = model.UpdatedBy,
|
|
// UpdatedTime = model.UpdatedTime,
|
|
//});
|
|
//return response;
|
|
return Update(model, true);
|
|
}
|
|
|
|
public List<ProReportworkDto> UserExport(DateTime handleDate)
|
|
{
|
|
// DateTime AddhandleDate = handleDate.AddDays(1);
|
|
|
|
return Context.Queryable<ProWorkorder>()
|
|
.LeftJoin<ProReportwork>((w, r) => w.Workorder == r.FkWorkorder)
|
|
.Where((w, r) => w.WorkorderDate == handleDate)
|
|
.Select((w, r) => new ProReportworkDto()
|
|
{
|
|
Id = r.Id,
|
|
ProductionCode = w.ProductionCode,
|
|
ProductionName = w.ProductionName,
|
|
Specification = w.Specification,
|
|
QualifiedNumber = r.QualifiedNumber,
|
|
UnqualifiedNumber = r.UnqualifiedNumber,
|
|
ReworkNumber = r.ReworkNumber,
|
|
ScrapNumber = r.ScrapNumber,
|
|
WorkorderRamark = w.Remark,
|
|
Remark = r.Remark,
|
|
Difference = r.QualifiedNumber - r.FinishedNum ?? 0,
|
|
FkWorkorder = w.Workorder,
|
|
GroupCode = w.GroupCode,
|
|
LineCode = w.LineCode,
|
|
DispatchNum = w.DeliveryNum ?? 0,
|
|
Priority = w.Priority,
|
|
Status = w.Status,
|
|
Beat = w.Beat
|
|
}).ToList();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 如果没有id 传入工单 手动生成报工记录
|
|
/// </summary>
|
|
/// <param name="workorder"></param>
|
|
/// <returns></returns>
|
|
public string ManualGenerationOfReportWork(string workorder, string CreatedBy)
|
|
{
|
|
string ReportWork_Id = Context.Queryable<ProReportwork>().Where(it => it.FkWorkorder == workorder)
|
|
.Select(it => it.Id).First();
|
|
|
|
if (!string.IsNullOrEmpty(ReportWork_Id))
|
|
{
|
|
return ReportWork_Id;
|
|
}
|
|
|
|
ProWorkorder handleWorkorder =
|
|
Context.Queryable<ProWorkorder>().Where(it => it.Workorder == workorder).First();
|
|
ProReportwork proReportwork = new
|
|
ProReportwork();
|
|
proReportwork.Id = XueHua;
|
|
proReportwork.FkWorkorder = workorder;
|
|
proReportwork.DispatchNum = handleWorkorder.DeliveryNum;
|
|
proReportwork.FinishedNum = null;
|
|
proReportwork.GroupCode = handleWorkorder.GroupCode;
|
|
proReportwork.LineCode = handleWorkorder.LineCode;
|
|
proReportwork.CreatedBy = CreatedBy;
|
|
proReportwork.CreatedTime = DateTime.Now;
|
|
|
|
ProReportwork proReportwork1 = Context.Insertable(proReportwork).ExecuteReturnEntity();
|
|
|
|
return proReportwork1.Id;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 成品批量入库
|
|
/// </summary>
|
|
/// <param name="startTime"></param>
|
|
/// <param name="endTime"></param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public int batchPutInFinProduct(DateTime startTime, DateTime endTime)
|
|
{
|
|
MmLineInventoryService mmLineInventoryService = new MmLineInventoryService();
|
|
if (startTime <= DateTime.MinValue || endTime <= DateTime.MinValue)
|
|
{
|
|
throw new Exception("日期筛选条件不对");
|
|
}
|
|
List<ProReportworkDto> proReportworkDtos = Context.Queryable<ProWorkorder>()
|
|
.LeftJoin<ProReportwork>((w, r) => w.Workorder == r.FkWorkorder)
|
|
.Where((w, r) => r.CreatedTime >= startTime && r.CreatedTime <= endTime).Select((w, r) => new ProReportworkDto()
|
|
{
|
|
FkWorkorder=r.FkWorkorder,
|
|
LineCode=r.LineCode,
|
|
ProductionCode = w.ProductionCode,
|
|
ProductionName = w.ProductionName,
|
|
QualifiedNumber = r.QualifiedNumber,
|
|
}).Distinct().ToList();
|
|
|
|
foreach (var item in proReportworkDtos)
|
|
{
|
|
// 查看需要的子件
|
|
var bomList = Context.Queryable<BaseMaterialBom>().Where(it => it.InvCode == item.ProductionCode).ToList();
|
|
foreach (BaseMaterialBom bom in bomList)
|
|
{
|
|
decimal quantity = 0;
|
|
if (decimal.TryParse(bom.Iusequantity, out decimal res))
|
|
{
|
|
quantity = res* item.QualifiedNumber.Value;
|
|
}
|
|
|
|
|
|
mmLineInventoryService.outboundLineMaterial(3, item.LineCode, bom.SubInvCode, item.FkWorkorder, item.LineCode, quantity);
|
|
}
|
|
}
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 成品单个入库/驳回
|
|
/// </summary>
|
|
/// <param name="Id"></param>
|
|
/// <param name="type"> 1入库 2驳回</param>
|
|
/// <returns></returns>
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
public int putInAndReject(string Id, int type)
|
|
{
|
|
int result = 0;
|
|
MmLineInventoryService mmLineInventoryService = new MmLineInventoryService();
|
|
ProReportworkDto proReportworkDto = Context.Queryable<ProWorkorder>()
|
|
.LeftJoin<ProReportwork>((w, r) => w.Workorder == r.FkWorkorder)
|
|
.Where((w, r) => r.Id == Id).Select((w, r) => new ProReportworkDto()
|
|
{
|
|
FkWorkorder = r.FkWorkorder,
|
|
LineCode = r.LineCode,
|
|
ProductionCode = w.ProductionCode,
|
|
ProductionName = w.ProductionName,
|
|
QualifiedNumber = r.QualifiedNumber,
|
|
}).First();
|
|
// 查看需要的子件
|
|
var bomList = Context.Queryable<BaseMaterialBom>().Where(it => it.InvCode == proReportworkDto.ProductionCode).ToList();
|
|
if (type == 1)
|
|
{
|
|
foreach (BaseMaterialBom bom in bomList)
|
|
{
|
|
decimal quantity = 0;
|
|
if (decimal.TryParse(bom.Iusequantity, out decimal res))
|
|
{
|
|
quantity = res * proReportworkDto.QualifiedNumber.Value;
|
|
}
|
|
result=mmLineInventoryService.outboundLineMaterial(3, proReportworkDto.LineCode, bom.SubInvCode, proReportworkDto.FkWorkorder, proReportworkDto.LineCode, quantity);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (BaseMaterialBom bom in bomList)
|
|
{
|
|
decimal quantity = 0;
|
|
if (decimal.TryParse(bom.Iusequantity, out decimal res))
|
|
{
|
|
quantity = res * proReportworkDto.QualifiedNumber.Value;
|
|
}
|
|
result=mmLineInventoryService.putInLineMaterial(3, proReportworkDto.LineCode, bom.SubInvCode, "001", proReportworkDto.LineCode, quantity);
|
|
}
|
|
}
|
|
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |