|
|
@@ -1,4 +1,6 @@ |
|
|
|
using Furion.EventBus; |
|
|
|
using BPA.MES.Base.Application.Entitys.Base; |
|
|
|
using Furion.EventBus; |
|
|
|
using System.Security.Cryptography; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
@@ -29,20 +31,36 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
{ |
|
|
|
bool result = false; |
|
|
|
Pztj_WorkInfoEntity entity = input.Adapt<Pztj_WorkInfoEntity>(); |
|
|
|
List<WorkDeviceRecordEntity> workDeviceRecordEntities = new(); |
|
|
|
foreach (var item in input.WorkDevices) |
|
|
|
{ |
|
|
|
WorkDeviceRecordEntity workDeviceRecordEntity = new() |
|
|
|
{ |
|
|
|
DeviceId = item.DeviceId, |
|
|
|
WorkId = entity.Id, |
|
|
|
ProcessId = item.ProcessId, |
|
|
|
LineId = input.LineId, |
|
|
|
}; |
|
|
|
workDeviceRecordEntities.Add(workDeviceRecordEntity); |
|
|
|
} |
|
|
|
Pztj_WorkInfoStatusEntity pztj_WorkInfoStatusEntity = new() |
|
|
|
{ |
|
|
|
Status = WorkOrderStatusEnum.Draft, |
|
|
|
WorkId = entity.Id |
|
|
|
}; |
|
|
|
try |
|
|
|
{ |
|
|
|
_dbContext.Ado.BeginTran(); |
|
|
|
await _dbContext.Insertable(entity).IgnoreColumns(ignoreNullColumn: true).ExecuteCommandAsync(); |
|
|
|
Pztj_WorkInfoStatusEntity pztj_WorkInfoStatusEntity = new() |
|
|
|
if (workDeviceRecordEntities.Count>1) |
|
|
|
{ |
|
|
|
Status = WorkOrderStatusEnum.Draft, |
|
|
|
WorkId = entity.Id |
|
|
|
}; |
|
|
|
await _dbContext.Insertable(workDeviceRecordEntities).ExecuteCommandAsync(); |
|
|
|
} |
|
|
|
await _dbContext.Insertable(pztj_WorkInfoStatusEntity).IgnoreColumns(true).ExecuteCommandAsync(); |
|
|
|
_dbContext.Ado.CommitTran(); |
|
|
|
result = true; |
|
|
|
} |
|
|
|
catch |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
_dbContext.Ado.RollbackTran(); |
|
|
|
throw Oops.Bah("添加失败!"); |
|
|
@@ -74,7 +92,7 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
.LeftJoin<Pztj_FinalsInfoEntity>((a, b) => a.FinalId == b.Id) |
|
|
|
.LeftJoin<ProductLineEntity>((a, b, c) => a.LineId == c.Id) |
|
|
|
.LeftJoin<Pztj_WorkInfoStatusEntity>((a, b, c, d) => d.Id == SqlFunc.Subqueryable<Pztj_WorkInfoStatusEntity>().Where(s => s.WorkId == a.Id).OrderByDesc(s => s.CreateTime).Select(s => s.Id)) |
|
|
|
.LeftJoin<Pztj_DevicesInfoEntity>((a,b,c,d,e)=>a.DeviceId==e.Id) |
|
|
|
.LeftJoin<Pztj_DevicesInfoEntity>((a, b, c, d, e) => a.DeviceId==e.Id) |
|
|
|
.Where((a, b, c, d) => a.Id == Id) |
|
|
|
.Select((a, b, c, d, e) => new WorkInfoDetailOutput |
|
|
|
{ |
|
|
@@ -100,10 +118,10 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
var craftlist = await _dbContext.Queryable<WorkInfoCraftstepRecordEntity>().Where(x => x.WorkId == Id).ToListAsync(); |
|
|
|
//获取物料信息 |
|
|
|
var materiallist = await _dbContext.Queryable<WorkInfoMaterialsRecordEntity>() |
|
|
|
.LeftJoin<Pztj_MaterialsInfoEntity>((a,b)=>a.MaterialId==b.Id) |
|
|
|
.LeftJoin<DictDataEntity>((a,b,c) => b.Type == c.Id) |
|
|
|
.LeftJoin<Pztj_MaterialsInfoEntity>((a, b) => a.MaterialId==b.Id) |
|
|
|
.LeftJoin<DictDataEntity>((a, b, c) => b.Type == c.Id) |
|
|
|
.Where((a, b) => a.WorkId == Id) |
|
|
|
.Select((a, b,c) => |
|
|
|
.Select((a, b, c) => |
|
|
|
new WorkInfoMaterialsRecordOutput |
|
|
|
{ |
|
|
|
Id = a.Id.SelectAll(), |
|
|
@@ -154,7 +172,7 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
var entity = await _dbContext.Queryable<Pztj_WorkInfoEntity>() |
|
|
|
.LeftJoin<Pztj_FinalsInfoEntity>((a, b) => a.FinalId == b.Id) |
|
|
|
.LeftJoin<ProductLineEntity>((a, b, c) => a.LineId == c.Id) |
|
|
|
.LeftJoin<Pztj_DevicesInfoEntity>((a, b, c, d) =>a.DeviceId==d.Id) |
|
|
|
.LeftJoin<Pztj_DevicesInfoEntity>((a, b, c, d) => a.DeviceId==d.Id) |
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.Name), (a, b, c, d) => b.Name.Contains(input.Name)) |
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.Id), (a, b, c, d) => a.Id.Contains(input.Id)) |
|
|
|
.WhereIF(!string.IsNullOrEmpty(input.BatchId), (a, b, c, d) => a.BatchId == input.BatchId) |
|
|
@@ -247,7 +265,7 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
string userId = App.User?.FindFirst(ClaimConst.CLAINM_USERID)?.Value; |
|
|
|
string userName = App.User?.FindFirst(ClaimConst.CLAINM_NAME)?.Value; |
|
|
|
var workentitys = await _dbContext.Queryable<Pztj_WorkInfoEntity>().Where(x => x.BatchId == input.BatchId).ToListAsync(); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var item in workentitys) |
|
|
|
{ |
|
|
|
var res = await UpdateStatus( |
|
|
@@ -283,7 +301,7 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
var materiallist = await _dbContext.Queryable<RecipeMaterialEntity>() |
|
|
|
.LeftJoin<Pztj_MaterialsInfoEntity>((a, b) => a.MaterialId == b.Id) |
|
|
|
.LeftJoin<RecipesInfoEntity>((a, b, c) => a.RecipesId == c.Id) |
|
|
|
//.Where((a, b, c) => a.RecipesId == finainfo.RecipeId) |
|
|
|
//.Where((a, b, c) => a.RecipesId == finainfo.RecipeId) |
|
|
|
.Select((a, b, c) => new WorkInfoMaterialsRecordEntity |
|
|
|
{ |
|
|
|
MaterialId = a.MaterialId, |
|
|
@@ -397,9 +415,9 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
Remark = $"[{userId}]{userName}" |
|
|
|
}); |
|
|
|
var workentity = await _dbContext.Queryable<Pztj_WorkInfoEntity>() |
|
|
|
.LeftJoin<Pztj_DevicesInfoEntity>((a,b)=>a.DeviceId==b.Id) |
|
|
|
.LeftJoin<Pztj_DevicesInfoEntity>((a, b) => a.DeviceId==b.Id) |
|
|
|
.Where((a, b) => a.Id == input.WorkId) |
|
|
|
.Select((a,b)=>new WorkInfoOutput |
|
|
|
.Select((a, b) => new WorkInfoOutput |
|
|
|
{ |
|
|
|
Id=a.Id.SelectAll(), |
|
|
|
DeviceCode = b.Code, |
|
|
@@ -421,8 +439,8 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
|
|
|
|
var materiallist = await _dbContext.Queryable<RecipeMaterialEntity>() |
|
|
|
.LeftJoin<Pztj_MaterialsInfoEntity>((a, b) => a.MaterialId == b.Id) |
|
|
|
.LeftJoin<RecipesInfoEntity>((a,b,c)=>a.RecipesId==c.Id) |
|
|
|
//.Where((a, b, c) => a.RecipesId == finainfo.RecipeId) |
|
|
|
.LeftJoin<RecipesInfoEntity>((a, b, c) => a.RecipesId==c.Id) |
|
|
|
//.Where((a, b, c) => a.RecipesId == finainfo.RecipeId) |
|
|
|
.Select((a, b, c) => new WorkInfoMaterialsRecordEntity |
|
|
|
{ |
|
|
|
MaterialId = a.MaterialId, |
|
|
@@ -498,7 +516,7 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
_dbContext.Ado.BeginTran(); |
|
|
|
await _dbContext.Deleteable<WorkInfoCraftstepRecordEntity>().Where(x => x.WorkId == input.WorkId).ExecuteCommandAsync(); |
|
|
|
await _dbContext.Deleteable<WorkInfoMaterialsRecordEntity>().Where(x => x.WorkId == input.WorkId).ExecuteCommandAsync(); |
|
|
|
|
|
|
|
|
|
|
|
await _dbContext.Insertable(newcraftslist).ExecuteCommandAsync(); |
|
|
|
await _dbContext.Insertable(newmateriallist).ExecuteCommandAsync(); |
|
|
|
_dbContext.Ado.CommitTran(); |
|
|
@@ -536,10 +554,43 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
[HttpPost] |
|
|
|
public async Task<bool> Update(WorkInfoUpdateInput input) |
|
|
|
{ |
|
|
|
bool result = false; |
|
|
|
Pztj_WorkInfoEntity entity = input.Adapt<Pztj_WorkInfoEntity>(); |
|
|
|
entity.CreateTime = DateTime.Now; |
|
|
|
var res = await _dbContext.Updateable(entity).IgnoreColumns(true).ExecuteCommandHasChangeAsync(); |
|
|
|
return res; |
|
|
|
List<WorkDeviceRecordEntity> workDeviceRecordEntities = new(); |
|
|
|
foreach (var item in input.WorkDevices) |
|
|
|
{ |
|
|
|
WorkDeviceRecordEntity workDeviceRecordEntity = new() |
|
|
|
{ |
|
|
|
DeviceId = item.DeviceId, |
|
|
|
WorkId = entity.Id, |
|
|
|
ProcessId = item.ProcessId, |
|
|
|
LineId = input.LineId, |
|
|
|
}; |
|
|
|
workDeviceRecordEntities.Add(workDeviceRecordEntity); |
|
|
|
} |
|
|
|
Pztj_WorkInfoStatusEntity pztj_WorkInfoStatusEntity = new() |
|
|
|
{ |
|
|
|
Status = WorkOrderStatusEnum.Draft, |
|
|
|
WorkId = entity.Id |
|
|
|
}; |
|
|
|
try |
|
|
|
{ |
|
|
|
_dbContext.Ado.BeginTran(); |
|
|
|
await _dbContext.Updateable(entity).Where(x=>x.Id==input.Id).IgnoreColumns(true).ExecuteCommandAsync(); |
|
|
|
await _dbContext.Deleteable<WorkDeviceRecordEntity>().Where(x => x.WorkId==input.Id).ExecuteCommandAsync(); |
|
|
|
if (workDeviceRecordEntities.Count>1) |
|
|
|
{ |
|
|
|
await _dbContext.Insertable(workDeviceRecordEntities).ExecuteCommandAsync(); |
|
|
|
} |
|
|
|
_dbContext.Ado.CommitTran(); |
|
|
|
result = true; |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
_dbContext.Ado.RollbackTran(); |
|
|
|
throw Oops.Bah("添加失败!"); |
|
|
|
} |
|
|
|
return result; |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 修改工单状态 |
|
|
@@ -661,10 +712,39 @@ namespace BPA.MES.Base.Application.Services.WorkInfoService.Services |
|
|
|
[HttpGet] |
|
|
|
public async Task<List<WorkInfoStatusOutput>> StatusList(string workId) |
|
|
|
{ |
|
|
|
var entitys = await _dbContext.Queryable<Pztj_WorkInfoStatusEntity>().Where(x => x.WorkId == workId).OrderByDescending(x=>x.CreateTime).ToListAsync(); |
|
|
|
var entitys = await _dbContext.Queryable<Pztj_WorkInfoStatusEntity>().Where(x => x.WorkId == workId).OrderByDescending(x => x.CreateTime).ToListAsync(); |
|
|
|
List<WorkInfoStatusOutput> list = entitys.Adapt<List<WorkInfoStatusOutput>>(); |
|
|
|
|
|
|
|
|
|
|
|
return list; |
|
|
|
} |
|
|
|
/// <summary> |
|
|
|
/// 获取编辑详情 |
|
|
|
/// </summary> |
|
|
|
/// <param name="Id"></param> |
|
|
|
/// <returns></returns> |
|
|
|
[HttpGet] |
|
|
|
public async Task<WorkInfoEditDetailOutput> EditDetail(string Id) |
|
|
|
{ |
|
|
|
var entity = await _dbContext.Queryable<Pztj_WorkInfoEntity>() |
|
|
|
.LeftJoin<WorkPlanEntity>((a, b) => a.PlanId == b.Id) |
|
|
|
.LeftJoin<Pztj_FinalsInfoEntity>((a, b, c) => a.FinalId == c.Id) |
|
|
|
.Where((a, b, c) => a.Id == Id) |
|
|
|
.Select((a, b, c) => new WorkInfoEditDetailOutput |
|
|
|
{ |
|
|
|
PlanId = a.PlanId, |
|
|
|
FinalName = c.Name, |
|
|
|
LineId = a.LineId, |
|
|
|
Quantity = b.Quantity |
|
|
|
}).FirstAsync(); |
|
|
|
var devicelist = await _dbContext.Queryable<WorkDeviceRecordEntity>().Where(x => x.WorkId==Id) |
|
|
|
.Select(x => new WorkDeviceAddInput |
|
|
|
{ |
|
|
|
DeviceId = x.DeviceId, |
|
|
|
ProcessId = x.ProcessId, |
|
|
|
}) |
|
|
|
.ToListAsync(); |
|
|
|
entity.WorkDevices = devicelist; |
|
|
|
return entity; |
|
|
|
} |
|
|
|
} |
|
|
|
} |