This commit is contained in:
FanLian
2023-07-11 16:26:22 +08:00
15 changed files with 942 additions and 484 deletions

View File

@@ -19,5 +19,10 @@ namespace Tnb.BasicData
/// 生产任务单号单据模板编码 /// 生产任务单号单据模板编码
/// </summary> /// </summary>
public const string PRDMOTASK_CODE = "ProductionPlanAndSchedule"; public const string PRDMOTASK_CODE = "ProductionPlanAndSchedule";
/// <summary>
/// 备件领用
/// </summary>
public const string SPAREPARTSREQUISITION_CODE = "SparePartsRequisition";
} }
} }

View File

@@ -237,280 +237,281 @@ namespace Tnb.BasicData
}) })
.ToListAsync(); .ToListAsync();
} }
/// <summary>
/// 保存生产bom
/// </summary>
/// <param name="mbomSaveDataInput"></param>
/// <returns></returns>
[HttpPost]
public async Task<string> SaveData(MbomSaveDataInput mbomSaveDataInput)
{
ErrorCode errorCode = ErrorCode.COM1008;
DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
{
//新增
if (string.IsNullOrEmpty(mbomSaveDataInput.id))
{
string mbomId = SnowflakeIdHelper.NextId();
string orgId = _userManager.GetUserInfo().Result.organizeId;
BasMbom mbom = new BasMbom()
{
id = mbomId,
org_id = orgId,
material_id = mbomSaveDataInput.material_id,
num = mbomSaveDataInput.num,
unit_id = mbomSaveDataInput.unit_id,
version = mbomSaveDataInput.version,
start_time = mbomSaveDataInput.start_time,
end_time = mbomSaveDataInput.end_time,
ebom_id = mbomSaveDataInput.ebom_id,
route_id = mbomSaveDataInput.route_id,
is_first = mbomSaveDataInput.is_first,
remark = mbomSaveDataInput.remark,
create_id = _userManager.UserId,
create_time = DateTime.Now,
}; // /// <summary>
// /// 保存生产bom
if (await _repository.IsAnyAsync(x => // /// </summary>
x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version)) // /// <param name="mbomSaveDataInput"></param>
{ // /// <returns></returns>
errorCode = ErrorCode.COM1004; // [HttpPost]
throw Oops.Oh(ErrorCode.COM1004); // public async Task<string> SaveData(MbomSaveDataInput mbomSaveDataInput)
} // {
await _repository.InsertAsync(mbom); // ErrorCode errorCode = ErrorCode.COM1008;
List<BasMbomProcess> processes = new List<BasMbomProcess>(); // DbResult<bool> result = await _repository.AsSugarClient().Ado.UseTranAsync(async () =>
List<BasMbomInput> inputs = new List<BasMbomInput>(); // {
List<BasMbomOutput> outputs = new List<BasMbomOutput>(); // //新增
// if (string.IsNullOrEmpty(mbomSaveDataInput.id))
if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null) // {
{ // string mbomId = SnowflakeIdHelper.NextId();
int index = 0; // string orgId = _userManager.GetUserInfo().Result.organizeId;
foreach (var process in mbomSaveDataInput.processes) // BasMbom mbom = new BasMbom()
{ // {
string mbomProcessId = SnowflakeIdHelper.NextId(); // id = mbomId,
processes.Add(new BasMbomProcess()
{
id = mbomProcessId,
org_id = orgId,
mbom_id = mbomId,
process_id = process?.process_id ?? "",
preparation_time = process?.preparation_time ?? 0,
station = process?.station ?? "",
byproduct_status = process?.byproduct_status ?? 0,
production_method = process?.production_method,
route_detail_id = process?.route_detail_id ?? "",
ordinal = ++index,
is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0,
});
if (process!.inputs != null)
{
foreach (var input in process.inputs)
{
string inputId = SnowflakeIdHelper.NextId();
inputs.Add(new BasMbomInput()
{
id = inputId,
mbom_id = mbomId,
mbom_process_id = mbomProcessId,
process_id = process?.process_id ?? "",
material_id = input.material_id,
num = input.num,
org_id = orgId,
});
}
}
if (process.outputs != null)
{
foreach (var output in process.outputs)
{
string outputId = SnowflakeIdHelper.NextId();
outputs.Add(new BasMbomOutput()
{
id = outputId,
mbom_id = mbomId,
mbom_process_id = mbomProcessId,
process_id = process?.process_id ?? "",
material_id = output.material_id,
num = output.num,
org_id = orgId,
});
}
}
}
}
if (processes.Count > 0)
{
await _repository.AsSugarClient().Insertable<BasMbomProcess>(processes).ExecuteCommandAsync();
}
if (inputs.Count > 0)
{
await _repository.AsSugarClient().Insertable<BasMbomInput>(inputs).ExecuteCommandAsync();
}
if (outputs.Count > 0)
{
await _repository.AsSugarClient().Insertable<BasMbomOutput>(outputs).ExecuteCommandAsync();
}
}
else//修改
{
if (await _repository.IsAnyAsync(x =>
x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version && x.id != mbomSaveDataInput.id))
{
errorCode = ErrorCode.COM1004;
throw Oops.Oh(ErrorCode.COM1004);
}
string orgId = _userManager.GetUserInfo().Result.organizeId;
if (mbomSaveDataInput != null)
{
await _repository.UpdateAsync(x => new BasMbom()
{
// org_id = orgId, // org_id = orgId,
material_id = mbomSaveDataInput.material_id, // material_id = mbomSaveDataInput.material_id,
num = mbomSaveDataInput.num, // num = mbomSaveDataInput.num,
unit_id = mbomSaveDataInput.unit_id, // unit_id = mbomSaveDataInput.unit_id,
version = mbomSaveDataInput.version, // version = mbomSaveDataInput.version,
start_time = mbomSaveDataInput.start_time, // start_time = mbomSaveDataInput.start_time,
end_time = mbomSaveDataInput.end_time, // end_time = mbomSaveDataInput.end_time,
ebom_id = mbomSaveDataInput.ebom_id, // ebom_id = mbomSaveDataInput.ebom_id,
route_id = mbomSaveDataInput.route_id, // route_id = mbomSaveDataInput.route_id,
is_first = mbomSaveDataInput.is_first, // is_first = mbomSaveDataInput.is_first,
remark = mbomSaveDataInput.remark, // remark = mbomSaveDataInput.remark,
modify_id = _userManager.UserId, // create_id = _userManager.UserId,
modify_time = DateTime.Now, // create_time = DateTime.Now,
//
}, x => x.id == mbomSaveDataInput.id); // };
} //
// if (await _repository.IsAnyAsync(x =>
// x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version))
// {
// errorCode = ErrorCode.COM1004;
// throw Oops.Oh(ErrorCode.COM1004);
// }
// await _repository.InsertAsync(mbom);
// List<BasMbomProcess> processes = new List<BasMbomProcess>(); // List<BasMbomProcess> processes = new List<BasMbomProcess>();
List<BasMbomInput> inputs = new List<BasMbomInput>(); // List<BasMbomInput> inputs = new List<BasMbomInput>();
List<BasMbomOutput> outputs = new List<BasMbomOutput>(); // List<BasMbomOutput> outputs = new List<BasMbomOutput>();
//
if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null) // if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
{ // {
foreach (var process in mbomSaveDataInput.processes) // int index = 0;
{ // foreach (var process in mbomSaveDataInput.processes)
string mbomProcessId = process.id; // {
// string mbomProcessId = SnowflakeIdHelper.NextId(); // string mbomProcessId = SnowflakeIdHelper.NextId();
// processes.Add(new BasMbomProcess() // processes.Add(new BasMbomProcess()
// { // {
// id = mbomProcessId, // id = mbomProcessId,
// org_id = orgId ?? "", // org_id = orgId,
// mbom_id = mbomSaveDataInput?.id ?? "", // mbom_id = mbomId,
// process_id = process?.process_id ?? "", // process_id = process?.process_id ?? "",
// preparation_time = process?.preparation_time ?? 0, // preparation_time = process?.preparation_time ?? 0,
// station = process.station, // station = process?.station ?? "",
// byproduct_status = process.byproduct_status, // byproduct_status = process?.byproduct_status ?? 0,
// production_method = process.production_method, // production_method = process?.production_method,
// route_detail_id = process.route_detail_id, // route_detail_id = process?.route_detail_id ?? "",
// ordinal = ++index,
// is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0,
// //
// }); // });
//
decimal preparation_time = process?.preparation_time ?? 0; // if (process!.inputs != null)
await _repository.AsSugarClient().Updateable<BasMbomProcess>() // {
.SetColumns(x => x.preparation_time == preparation_time) // foreach (var input in process.inputs)
.SetColumns(x => x.station == process!.station) // {
.SetColumns(x => x.byproduct_status == process!.byproduct_status) // string inputId = SnowflakeIdHelper.NextId();
.SetColumns(x => x.production_method == process!.production_method) // inputs.Add(new BasMbomInput()
.Where(x => x.id == process!.id).ExecuteCommandAsync(); // {
// id = inputId,
if (process!.inputs != null) // mbom_id = mbomId,
{ // mbom_process_id = mbomProcessId,
foreach (var input in process.inputs) // process_id = process?.process_id ?? "",
{ // material_id = input.material_id,
string inputId = SnowflakeIdHelper.NextId(); // num = input.num,
inputs.Add(new BasMbomInput() // org_id = orgId,
{ // });
id = inputId, // }
mbom_id = mbomSaveDataInput?.id ?? "", // }
mbom_process_id = mbomProcessId, //
process_id = process?.process_id ?? "", // if (process.outputs != null)
material_id = input.material_id, // {
num = input.num, // foreach (var output in process.outputs)
org_id = orgId, // {
}); // string outputId = SnowflakeIdHelper.NextId();
} // outputs.Add(new BasMbomOutput()
} // {
// id = outputId,
if (process.outputs != null) // mbom_id = mbomId,
{ // mbom_process_id = mbomProcessId,
foreach (var output in process.outputs) // process_id = process?.process_id ?? "",
{ // material_id = output.material_id,
string outputId = SnowflakeIdHelper.NextId(); // num = output.num,
outputs.Add(new BasMbomOutput() // org_id = orgId,
{ // });
id = outputId, // }
mbom_id = mbomSaveDataInput?.id ?? "", // }
mbom_process_id = mbomProcessId, // }
process_id = process?.process_id ?? "", // }
material_id = output.material_id, //
num = output.num,
org_id = orgId,
});
}
}
}
}
if (mbomSaveDataInput != null && !string.IsNullOrEmpty(mbomSaveDataInput.id))
{
// await _repository.AsSugarClient().Deleteable<BasMbomProcess>().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
await _repository.AsSugarClient().Deleteable<BasMbomInput>().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
await _repository.AsSugarClient().Deleteable<BasMbomOutput>().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
}
// if (processes.Count > 0) // if (processes.Count > 0)
// { // {
// await _repository.AsSugarClient().Insertable<BasMbomProcess>(processes).ExecuteCommandAsync(); // await _repository.AsSugarClient().Insertable<BasMbomProcess>(processes).ExecuteCommandAsync();
// } // }
//
if (inputs.Count > 0) // if (inputs.Count > 0)
{ // {
await _repository.AsSugarClient().Insertable<BasMbomInput>(inputs).ExecuteCommandAsync(); // await _repository.AsSugarClient().Insertable<BasMbomInput>(inputs).ExecuteCommandAsync();
} // }
//
if (outputs.Count > 0) // if (outputs.Count > 0)
{ // {
await _repository.AsSugarClient().Insertable<BasMbomOutput>(outputs).ExecuteCommandAsync(); // await _repository.AsSugarClient().Insertable<BasMbomOutput>(outputs).ExecuteCommandAsync();
} // }
} // }
// else//修改
}); // {
// if (await _repository.IsAnyAsync(x =>
if (!result.IsSuccess) // x.material_id == mbomSaveDataInput.material_id && x.version == mbomSaveDataInput.version && x.id != mbomSaveDataInput.id))
{ // {
if (!string.IsNullOrEmpty(mbomSaveDataInput.id)) // errorCode = ErrorCode.COM1004;
{ // throw Oops.Oh(ErrorCode.COM1004);
if (errorCode != ErrorCode.COM1004) // }
{ //
throw Oops.Oh(ErrorCode.COM1001); // string orgId = _userManager.GetUserInfo().Result.organizeId;
} // if (mbomSaveDataInput != null)
else // {
{ // await _repository.UpdateAsync(x => new BasMbom()
throw Oops.Oh(errorCode); // {
} // // org_id = orgId,
} // material_id = mbomSaveDataInput.material_id,
else // num = mbomSaveDataInput.num,
{ // unit_id = mbomSaveDataInput.unit_id,
if (errorCode != ErrorCode.COM1004) // version = mbomSaveDataInput.version,
{ // start_time = mbomSaveDataInput.start_time,
throw Oops.Oh(ErrorCode.COM1000); // end_time = mbomSaveDataInput.end_time,
} // ebom_id = mbomSaveDataInput.ebom_id,
else // route_id = mbomSaveDataInput.route_id,
{ // is_first = mbomSaveDataInput.is_first,
throw Oops.Oh(errorCode); // remark = mbomSaveDataInput.remark,
} // modify_id = _userManager.UserId,
} // modify_time = DateTime.Now,
//
} // }, x => x.id == mbomSaveDataInput.id);
return result.IsSuccess ? "保存成功" : result.ErrorMessage; // }
} // // List<BasMbomProcess> processes = new List<BasMbomProcess>();
// List<BasMbomInput> inputs = new List<BasMbomInput>();
// List<BasMbomOutput> outputs = new List<BasMbomOutput>();
//
// if (mbomSaveDataInput != null && mbomSaveDataInput.processes != null)
// {
// foreach (var process in mbomSaveDataInput.processes)
// {
// string mbomProcessId = process.id;
// // string mbomProcessId = SnowflakeIdHelper.NextId();
// // processes.Add(new BasMbomProcess()
// // {
// // id = mbomProcessId,
// // org_id = orgId ?? "",
// // mbom_id = mbomSaveDataInput?.id ?? "",
// // process_id = process?.process_id ?? "",
// // preparation_time = process?.preparation_time ?? 0,
// // station = process.station,
// // byproduct_status = process.byproduct_status,
// // production_method = process.production_method,
// // route_detail_id = process.route_detail_id,
// //
// // });
//
// decimal preparation_time = process?.preparation_time ?? 0;
// await _repository.AsSugarClient().Updateable<BasMbomProcess>()
// .SetColumns(x => x.preparation_time == preparation_time)
// .SetColumns(x => x.station == process!.station)
// .SetColumns(x => x.byproduct_status == process!.byproduct_status)
// .SetColumns(x => x.production_method == process!.production_method)
// .Where(x => x.id == process!.id).ExecuteCommandAsync();
//
// if (process!.inputs != null)
// {
// foreach (var input in process.inputs)
// {
// string inputId = SnowflakeIdHelper.NextId();
// inputs.Add(new BasMbomInput()
// {
// id = inputId,
// mbom_id = mbomSaveDataInput?.id ?? "",
// mbom_process_id = mbomProcessId,
// process_id = process?.process_id ?? "",
// material_id = input.material_id,
// num = input.num,
// org_id = orgId,
// });
// }
// }
//
// if (process.outputs != null)
// {
// foreach (var output in process.outputs)
// {
// string outputId = SnowflakeIdHelper.NextId();
// outputs.Add(new BasMbomOutput()
// {
// id = outputId,
// mbom_id = mbomSaveDataInput?.id ?? "",
// mbom_process_id = mbomProcessId,
// process_id = process?.process_id ?? "",
// material_id = output.material_id,
// num = output.num,
// org_id = orgId,
// });
// }
// }
//
// }
// }
//
// if (mbomSaveDataInput != null && !string.IsNullOrEmpty(mbomSaveDataInput.id))
// {
// // await _repository.AsSugarClient().Deleteable<BasMbomProcess>().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
// await _repository.AsSugarClient().Deleteable<BasMbomInput>().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
// await _repository.AsSugarClient().Deleteable<BasMbomOutput>().Where(x => x.mbom_id == mbomSaveDataInput.id).ExecuteCommandAsync();
// }
// // if (processes.Count > 0)
// // {
// // await _repository.AsSugarClient().Insertable<BasMbomProcess>(processes).ExecuteCommandAsync();
// // }
//
// if (inputs.Count > 0)
// {
// await _repository.AsSugarClient().Insertable<BasMbomInput>(inputs).ExecuteCommandAsync();
// }
//
// if (outputs.Count > 0)
// {
// await _repository.AsSugarClient().Insertable<BasMbomOutput>(outputs).ExecuteCommandAsync();
// }
// }
//
// });
//
// if (!result.IsSuccess)
// {
// if (!string.IsNullOrEmpty(mbomSaveDataInput.id))
// {
// if (errorCode != ErrorCode.COM1004)
// {
// throw Oops.Oh(ErrorCode.COM1001);
// }
// else
// {
// throw Oops.Oh(errorCode);
// }
// }
// else
// {
// if (errorCode != ErrorCode.COM1004)
// {
// throw Oops.Oh(ErrorCode.COM1000);
// }
// else
// {
// throw Oops.Oh(errorCode);
// }
// }
//
// }
// return result.IsSuccess ? "保存成功" : result.ErrorMessage;
// }
/// <summary> /// <summary>
/// 保存生产bom /// 保存生产bom
@@ -573,13 +574,13 @@ namespace Tnb.BasicData
preparation_time = process?.preparation_time ?? 0, preparation_time = process?.preparation_time ?? 0,
station = process?.station ?? "", station = process?.station ?? "",
byproduct_status = process!.byproduct_status, byproduct_status = process!.byproduct_status,
production_method = process!.production_method, production_method = process.production_method,
route_detail_id = process!.route_detail_id, route_detail_id = process.route_detail_id,
ordinal = ++index, ordinal = ++index,
is_last = index==mbomSaveDataInput.processes.Count ? 1 : 0, is_last = string.IsNullOrEmpty(process.next_process_no) ? 1 : 0,
no = process!.no, no = process!.no,
last_process_no = process!.last_process_no, last_process_no = process.last_process_no,
next_process_no = process!.next_process_no, next_process_no = process.next_process_no,
}); });

View File

@@ -0,0 +1,52 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.EquipMgr.Entities;
/// <summary>
/// 备件入库子表
/// </summary>
[SugarTable("eqp_spare_parts_instock_d")]
public partial class EqpSparePartsInstockD : BaseEntity<string>
{
public EqpSparePartsInstockD()
{
id = SnowflakeIdHelper.NextId();
}
/// <summary>
/// 备件入库单id
/// </summary>
public string? instock_id { get; set; }
/// <summary>
/// 备件id
/// </summary>
public string? spare_parts_id { get; set; }
/// <summary>
/// 入库数量
/// </summary>
public int quantity { get; set; }
/// <summary>
/// 库位id
/// </summary>
public string? location_id { get; set; }
/// <summary>
/// 质保开始时间
/// </summary>
public DateTime? warranty_start_time { get; set; }
/// <summary>
/// 质保结束时间
/// </summary>
public DateTime? warranty_end_time { get; set; }
/// <summary>
/// 已领数量
/// </summary>
public int use_quantity { get; set; }
}

View File

@@ -0,0 +1,82 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.EquipMgr.Entities;
/// <summary>
/// 备件入库
/// </summary>
[SugarTable("eqp_spare_parts_instock_h")]
public partial class EqpSparePartsInstockH : BaseEntity<string>
{
public EqpSparePartsInstockH()
{
id = SnowflakeIdHelper.NextId();
}
/// <summary>
/// 入库单编号
/// </summary>
public string? code { get; set; }
/// <summary>
/// 入库时间
/// </summary>
public string? instock_time { get; set; }
/// <summary>
/// 入库人员
/// </summary>
public string? instock_id { get; set; }
/// <summary>
/// 库位号
/// </summary>
public string? location_id { get; set; }
/// <summary>
/// 备件id
/// </summary>
public string? spare_parts_id { get; set; }
/// <summary>
/// 描述
/// </summary>
public string? descrip { get; set; }
/// <summary>
/// 创建用户
/// </summary>
public string? create_id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? create_time { get; set; }
/// <summary>
/// 修改用户
/// </summary>
public string? modify_id { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? modify_time { get; set; }
/// <summary>
/// 所属组织
/// </summary>
public string? org_id { get; set; }
/// <summary>
/// 流程任务Id
/// </summary>
public string? f_flowtaskid { get; set; }
/// <summary>
/// 流程引擎Id
/// </summary>
public string? f_flowid { get; set; }
}

View File

@@ -0,0 +1,47 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.EquipMgr.Entities;
/// <summary>
/// 备件领用子表
/// </summary>
[SugarTable("eqp_spare_parts_requisition_d")]
public partial class EqpSparePartsRequisitionD : BaseEntity<string>
{
public EqpSparePartsRequisitionD()
{
id = SnowflakeIdHelper.NextId();
}
/// <summary>
/// 备件id
/// </summary>
public string spare_parts_id { get; set; } = string.Empty;
/// <summary>
/// 批号
/// </summary>
public string? batch { get; set; }
/// <summary>
/// 数量
/// </summary>
public int quantity { get; set; }
/// <summary>
/// 备件领用主表id
/// </summary>
public string spare_parts_requisition_id { get; set; } = string.Empty;
/// <summary>
/// 设备id
/// </summary>
public string? equip_id { get; set; }
/// <summary>
/// 备件入库id
/// </summary>
public string? instock_detail_id { get; set; }
}

View File

@@ -0,0 +1,87 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.EquipMgr.Entities;
/// <summary>
/// 备件领用主表
/// </summary>
[SugarTable("eqp_spare_parts_requisition_h")]
public partial class EqpSparePartsRequisitionH : BaseEntity<string>
{
public EqpSparePartsRequisitionH()
{
id = SnowflakeIdHelper.NextId();
}
/// <summary>
/// 领用单编号
/// </summary>
public string? code { get; set; }
/// <summary>
/// 作用设备id
/// </summary>
public string? equip_id { get; set; }
/// <summary>
/// 使用部门
/// </summary>
public string? department { get; set; }
/// <summary>
/// 领用目的
/// </summary>
public string? requisition_purpose { get; set; }
/// <summary>
/// 库位号
/// </summary>
public string? location_id { get; set; }
/// <summary>
/// 备件id
/// </summary>
public string? spare_parts_id { get; set; }
/// <summary>
/// 领用人
/// </summary>
public string? recipient_id { get; set; }
/// <summary>
/// 创建用户
/// </summary>
public string? create_id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime? create_time { get; set; }
/// <summary>
/// 修改用户
/// </summary>
public string? modify_id { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public DateTime? modify_time { get; set; }
/// <summary>
/// 所属组织
/// </summary>
public string? org_id { get; set; }
/// <summary>
/// 流程任务Id
/// </summary>
public string? f_flowtaskid { get; set; }
/// <summary>
/// 流程引擎Id
/// </summary>
public string? f_flowid { get; set; }
}

View File

@@ -0,0 +1,10 @@
namespace Tnb.EquipMgr.Interfaces
{
/// <summary>
/// 备品备件领用服务
/// </summary>
public interface IEqpSparePartsRequisitionHService
{
}
}

View File

@@ -0,0 +1,134 @@
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Enums;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces;
using Microsoft.AspNetCore.Mvc;
using Microsoft.ClearScript.Util.Web;
using SqlSugar;
using Tnb.EquipMgr.Entities;
using Tnb.EquipMgr.Entities.Dto;
using Tnb.EquipMgr.Interfaces;
namespace Tnb.EquipMgr
{
/// <summary>
/// 备品备件领用服务
/// </summary>
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 700)]
[Route("api/[area]/[controller]/[action]")]
[OverideVisualDev(ModuleId)]
public class EqpSparePartsRequisitionHService : IEqpSparePartsRequisitionHService, IOverideVisualDevService,IDynamicApiController, ITransient
{
private const string ModuleId = "27338205223957";
private readonly ISqlSugarRepository<EqpSparePartsRequisitionH> _repository;
private readonly IVisualDevService _visualDevService;
private readonly IRunService _runService;
private readonly IUserManager _userManager;
private readonly IBillRullService _billRuleService;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
public EqpSparePartsRequisitionHService(ISqlSugarRepository<EqpSparePartsRequisitionH> repository,
IRunService runService,
IVisualDevService visualDevService,
IBillRullService billRuleService,
IUserManager userManager)
{
_repository = repository;
_visualDevService = visualDevService;
_runService = runService;
_userManager = userManager;
_billRuleService = billRuleService;
OverideFuncs.CreateAsync = Create;
}
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
{
var db = _repository.AsSugarClient();
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
{
// VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
// await _runService.Create(templateEntity, input);
var code = await _billRuleService.GetBillNumber(Tnb.BasicData.CodeTemplateConst.SPAREPARTSREQUISITION_CODE);
EqpSparePartsRequisitionH eqpSparePartsRequisitionH = new EqpSparePartsRequisitionH()
{
code = code,
equip_id = input.data.ContainsKey("equip_id") ? input.data["equip_id"].ToString() : "",
department = input.data.ContainsKey("department") ? input.data["department"].ToString() : "",
recipient_id = input.data.ContainsKey("recipient_id") ? input.data["recipient_id"].ToString() : "",
requisition_purpose = input.data.ContainsKey("requisition_purpose") ? input.data["requisition_purpose"].ToString() : "",
create_id = _userManager.UserId,
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId,
};
await db.Insertable<EqpSparePartsRequisitionH>(eqpSparePartsRequisitionH).ExecuteCommandAsync();
if (input.data.TryGetValue("tablefield120", out var value))
{
var details = value.ToObject<List<Dictionary<string,string>>>();
List<EqpEquipSpareParts> eqpSparePartsList = new List<EqpEquipSpareParts>();
List<EqpSparePartsRequisitionD> eqpSparePartsRequisitionDs = new List<EqpSparePartsRequisitionD>(){};
foreach (var detail in details)
{
string instockDetailId = detail.ContainsKey("instock_detail_id") ? detail["instock_detail_id"] : "";
string sparePartsId = detail.ContainsKey("spare_parts_id") ? detail["spare_parts_id"] : "";
int quantity = Convert.ToInt32(detail.ContainsKey("quantity") ? detail["quantity"] : "");
eqpSparePartsRequisitionDs.Add(new EqpSparePartsRequisitionD
{
instock_detail_id = instockDetailId,
spare_parts_id = sparePartsId,
quantity = quantity,
equip_id = eqpSparePartsRequisitionH.equip_id,
spare_parts_requisition_id = eqpSparePartsRequisitionH.id,
});
if (await db.Queryable<EqpSparePartsInstockD>()
.AnyAsync(x => x.id == instockDetailId && (x.quantity - x.use_quantity - quantity) >= 0))
{
eqpSparePartsList.Add(new EqpEquipSpareParts
{
equip_id = input.data["equip_id"]?.ToString() ?? "",
spare_parts_id = sparePartsId,
create_id = _userManager.UserId,
create_time = DateTime.Now,
org_id = _userManager.GetUserInfo().Result.organizeId
});
await db.Updateable<EqpSparePartsInstockD>()
.SetColumns(x => x.use_quantity == x.use_quantity + quantity)
.Where(x => x.id == instockDetailId).ExecuteCommandAsync();
}
else
{
throw new Exception("库存不够");
}
}
if (eqpSparePartsRequisitionDs.Count > 0)
{
await db.Insertable<EqpSparePartsRequisitionD>(eqpSparePartsRequisitionDs).ExecuteCommandAsync();
}
if (eqpSparePartsList.Count > 0)
{
await db.Insertable<EqpEquipSpareParts>(eqpSparePartsList).ExecuteCommandAsync();
}
}
});
if (!result.IsSuccess) throw Oops.Bah(result.ErrorMessage);
return result.IsSuccess ? "保存成功" : result.ErrorMessage;
}
}
}

View File

@@ -1278,6 +1278,9 @@ namespace Tnb.ProductionMgr
.SetColumns(x => x.reported_work_qty == x.reported_work_qty + input.reported_qty) .SetColumns(x => x.reported_work_qty == x.reported_work_qty + input.reported_qty)
.Where(x => x.id == input.mo_task_id).ExecuteCommandAsync(); .Where(x => x.id == input.mo_task_id).ExecuteCommandAsync();
} }
if (prdMoTask.schedule_type == 2 && !string.IsNullOrEmpty(prdMoTask.mbom_process_id))
{
var mbomProcess = await db.Queryable<BasMbomProcess>().SingleAsync(x => x.id == prdMoTask.mbom_process_id); var mbomProcess = await db.Queryable<BasMbomProcess>().SingleAsync(x => x.id == prdMoTask.mbom_process_id);
if (mbomProcess.is_last==1 && prdMoTask != null && !string.IsNullOrEmpty(prdMoTask.parent_id)) if (mbomProcess.is_last==1 && prdMoTask != null && !string.IsNullOrEmpty(prdMoTask.parent_id))
{ {
@@ -1294,6 +1297,7 @@ namespace Tnb.ProductionMgr
.Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync(); .Where(x => x.id == prdMoTask.parent_id).ExecuteCommandAsync();
} }
} }
}
var master = await db.Queryable<PrdReportRecord>().FirstAsync(it => it.mo_task_id == input.mo_task_id); var master = await db.Queryable<PrdReportRecord>().FirstAsync(it => it.mo_task_id == input.mo_task_id);
if (master != null) if (master != null)

View File

@@ -171,7 +171,7 @@ namespace Tnb.WarehouseMgr
[HttpPost] [HttpPost]
public async Task<dynamic> MesEmptyCarryInStock(MESEmptyCarryInStockInput input) public async Task<dynamic> MesEmptyCarryInStock(MESEmptyCarryInStockInput input)
{ {
if(input.IsNull())throw new ArgumentNullException("input"); if (input.IsNull()) throw new ArgumentNullException("input");
try try
{ {
var carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.carry_code == input.carry_code); var carry = await _db.Queryable<WmsCarryH>().SingleAsync(it => it.carry_code == input.carry_code);
@@ -186,16 +186,16 @@ namespace Tnb.WarehouseMgr
var cols = new List<string>(); var cols = new List<string>();
var dic = new Dictionary<string, object>(); var dic = new Dictionary<string, object>();
dic[nameof(WmsEmptyInstock.id)] = SnowflakeIdHelper.NextId(); dic[nameof(WmsEmptyInstock.id)] = SnowflakeIdHelper.NextId();
dic[nameof(WmsEmptyInstock.org_id)] = input.org_id; dic[nameof(WmsEmptyInstock.org_id)] = input.org_id ?? _userManager.User.OrganizeId;
dic[nameof(WmsEmptyInstock.location_id)] = location.id; dic[nameof(WmsEmptyInstock.location_id)] = location.id;
dic[nameof(WmsEmptyInstock.bill_code)] = await _billRullService.GetBillNumber(WmsWareHouseConst.WMS_EMPTYINSTK_ENCODE); dic[nameof(WmsEmptyInstock.bill_code)] = await _billRullService.GetBillNumber(WmsWareHouseConst.WMS_EMPTYINSTK_ENCODE);
dic[nameof(WmsEmptyInstock.status)] = WmsWareHouseConst.BILLSTATUS_ADD_ID; dic[nameof(WmsEmptyInstock.status)] = WmsWareHouseConst.BILLSTATUS_ADD_ID;
dic[nameof(WmsEmptyInstock.carry_id)] = carry.id; dic[nameof(WmsEmptyInstock.carry_id)] = carry.id;
dic[nameof(WmsEmptyInstock.carry_code)] = input.carry_code; dic[nameof(WmsEmptyInstock.carry_code)] = input.carry_code!;
dic[nameof(WmsEmptyInstock.biz_type)] = WmsWareHouseConst.BIZTYPE_WMSEMPTYINSTOCK_ID; dic[nameof(WmsEmptyInstock.biz_type)] = WmsWareHouseConst.BIZTYPE_WMSEMPTYINSTOCK_ID;
dic[nameof(WmsEmptyInstock.create_id)] = input.create_id; dic[nameof(WmsEmptyInstock.create_id)] = input.create_id ?? _userManager.UserId;
dic[nameof(WmsEmptyInstock.create_time)] = DateTime.Now; dic[nameof(WmsEmptyInstock.create_time)] = DateTime.Now;
dic[nameof(WmsEmptyInstock.warehouse_id)] = input.warehouse_id; dic[nameof(WmsEmptyInstock.warehouse_id)] = input.warehouse_id!;
VisualDevModelDataCrInput visualDevModelDataCrInput = new() VisualDevModelDataCrInput visualDevModelDataCrInput = new()
{ {

View File

@@ -85,7 +85,7 @@ namespace Tnb.WarehouseMgr
[HttpPost] [HttpPost]
public async Task BarCodePrint(BarCodePrintInput input) public async Task BarCodePrint(BarCodePrintInput input)
{ {
if (input == null) throw new ArgumentNullException("input"); if (input == null) throw new ArgumentNullException(nameof(input));
if (input.BillIds == null || input.BillIds.Count == 0) throw new ArgumentException($"parameter {nameof(input.BillIds)} not be null or zero"); if (input.BillIds == null || input.BillIds.Count == 0) throw new ArgumentException($"parameter {nameof(input.BillIds)} not be null or zero");
try try
{ {
@@ -161,28 +161,30 @@ namespace Tnb.WarehouseMgr
private Task<WmsTempCode> CreateInstock(WmsInstockD detail, int no) private Task<WmsTempCode> CreateInstock(WmsInstockD detail, int no)
{ {
WmsTempCode barCode = new();
barCode.org_id = detail.org_id;
barCode.material_id = detail.material_id;
barCode.material_code = detail.material_code;
var code = $"{detail.material_code}{detail.code_batch}{no.ToString().PadLeft(4, '0')}"; var code = $"{detail.material_code}{detail.code_batch}{no.ToString().PadLeft(4, '0')}";
barCode.barcode = code; WmsTempCode barCode = new()
barCode.code_batch = detail.code_batch; {
barCode.codeqty = detail.pr_qty!.Value; org_id = detail.org_id,
barCode.unit_id = detail.unit_id; material_id = detail.material_id,
barCode.is_lock = 0; material_code = detail.material_code,
barCode.is_end = 0; barcode = code,
barCode.require_id = detail.bill_id; code_batch = detail.code_batch,
barCode.require_code = _dicBillCodes.ContainsKey(detail.bill_id) ? _dicBillCodes[detail.bill_id]?.ToString() : ""; codeqty = detail.pr_qty!.Value,
barCode.create_id = _userManager.UserId; unit_id = detail.unit_id,
barCode.create_time = DateTime.Now; is_lock = 0,
is_end = 0,
require_id = detail.bill_id,
require_code = _dicBillCodes.ContainsKey(detail.bill_id) ? _dicBillCodes[detail.bill_id]?.ToString() : "",
create_id = _userManager.UserId,
create_time = DateTime.Now
};
return Task.FromResult(barCode); return Task.FromResult(barCode);
} }
public override async Task ModifyAsync(WareHouseUpInput input) public override async Task ModifyAsync(WareHouseUpInput input)
{ {
if (input == null) throw new ArgumentNullException("input"); if (input == null) throw new ArgumentNullException(nameof(input));
//更具distaskCode的barcode 更新 instockcode 的 is_end 为 1 //更具distaskCode的barcode 更新 instockcode 的 is_end 为 1
try try
{ {
@@ -253,7 +255,7 @@ namespace Tnb.WarehouseMgr
//入库申请条码明细表 //入库申请条码明细表
List<WmsInstockCode> instockcodes = input.instockcodes; List<WmsInstockCode> instockcodes = input.instockcodes;
//如果数据不全, //如果数据不全,
if (instock.IsNull() || instock.carry_id.IsNullOrWhiteSpace() || instock.location_id.IsNullOrWhiteSpace() || instockds?.Count < 1 || instockcodes?.Count < 1) if ((instock?.carry_id.IsNullOrWhiteSpace() ?? true) || (instock?.location_id.IsNullOrWhiteSpace() ?? true) || instockds?.Count < 1 || instockcodes?.Count < 1)
{ {
//报错, 提示数据不全。 //报错, 提示数据不全。
throw new AppFriendlyException("数据不全!", 500); throw new AppFriendlyException("数据不全!", 500);
@@ -351,7 +353,7 @@ namespace Tnb.WarehouseMgr
List<WmsPretaskCode> pretaskCodes = new(); List<WmsPretaskCode> pretaskCodes = new();
foreach (var pt in preTasks) foreach (var pt in preTasks)
{ {
if (instockCOdes.Count() > 0) if (instockCOdes.Count > 0)
{ {
foreach (var jo in instockCOdes) foreach (var jo in instockCOdes)
{ {
@@ -377,9 +379,9 @@ namespace Tnb.WarehouseMgr
var preTaskUpInput = new GenPreTaskUpInput(); var preTaskUpInput = new GenPreTaskUpInput();
preTaskUpInput.RquireId = instock.id; preTaskUpInput.RquireId = instock.id;
preTaskUpInput.CarryId = instock.carry_id!; preTaskUpInput.CarryId = instock.carry_id!;
preTaskUpInput.CarryStartLocationId = points.FirstOrDefault()!.location_id!; preTaskUpInput.CarryStartLocationId = points.FirstOrDefault()?.location_id;
preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault()!.location_code!; preTaskUpInput.CarryStartLocationCode = points.FirstOrDefault()?.location_code;
preTaskUpInput.LocationIds = points.Select(x => x.location_id).ToList()!; preTaskUpInput.LocationIds = (points?.Select(x => x.location_id)?.ToList() ?? Enumerable.Empty<string?>().ToList()) as List<string>;
//创建预任务操作记录 //创建预任务操作记录
var operBillId = string.Empty; var operBillId = string.Empty;
@@ -393,7 +395,7 @@ namespace Tnb.WarehouseMgr
preTaskUpInput.PreTaskRecord = handleH; preTaskUpInput.PreTaskRecord = handleH;
} }
//创建预任务条码操作记录 //创建预任务条码操作记录
if (instockcodes != null && instockcodes.Count() > 0) if (instockcodes?.Count > 0)
{ {
foreach (var jo in instockcodes) foreach (var jo in instockcodes)
{ {

View File

@@ -216,7 +216,7 @@ namespace Tnb.WarehouseMgr
if (kittingOut != null) if (kittingOut != null)
{ {
var locaion = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == kittingOut.location_id); var locaion = await _db.Queryable<BasLocation>().SingleAsync(it => it.id == kittingOut.location_id);
if (locaion != null && locaion.is_type.ToEnum<EnumLocationType>() != EnumLocationType.) if (locaion?.is_type.ToEnum<EnumLocationType>() != EnumLocationType.)
{ {
kittingOut.status = WmsWareHouseConst.BILLSTATUS_TOBESHIPPED_ID; kittingOut.status = WmsWareHouseConst.BILLSTATUS_TOBESHIPPED_ID;

View File

@@ -293,11 +293,11 @@ namespace Tnb.WarehouseMgr
{ {
await _db.Ado.BeginTranAsync(); await _db.Ado.BeginTranAsync();
//出库申请主表 //出库申请主表
WmsOutstockH outstock = input.outstock!; WmsOutstockH? outstock = input.outstock;
//出库申请明细表 //出库申请明细表
List<WmsOutstockD> outstockDs = input.outstockDs!; List<WmsOutstockD>? outstockDs = input.outstockDs;
//如果数据不全, //如果数据不全,
if (outstock.IsNull() || outstock.location_id.IsNullOrWhiteSpace() || outstockDs?.Count < 1) if ((outstock?.location_id.IsNullOrWhiteSpace() ?? true) || outstockDs?.Count < 1)
{ {
//报错, 提示数据不全。 //报错, 提示数据不全。
throw new AppFriendlyException("数据不全!", 500); throw new AppFriendlyException("数据不全!", 500);
@@ -498,9 +498,7 @@ namespace Tnb.WarehouseMgr
public override async Task ModifyAsync(WareHouseUpInput input) public override async Task ModifyAsync(WareHouseUpInput input)
{ {
if (input == null) throw new ArgumentNullException("input"); if (input == null) throw new ArgumentNullException(nameof(input));
try try
{ {

View File

@@ -113,13 +113,12 @@ namespace Tnb.WarehouseMgr
carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch }) carryMats = carryMats.OrderBy(o => o.create_time).GroupBy(g => new { g.carry_id, g.material_id, g.code_batch })
.Select(x => .Select(x =>
{ {
WmsCarryMat? carryMat = x.FirstOrDefault()!; WmsCarryMat? carryMat = x.FirstOrDefault();
carryMat.need_qty = x.Sum(d => d.need_qty); carryMat.need_qty = x.Sum(d => d.need_qty);
return carryMat; return carryMat;
}) })
.ToList(); .ToList();
await _db.Insertable(carryMats).ExecuteCommandAsync(); await _db.Insertable(carryMats).ExecuteCommandAsync();
var dic = carryMats.DistinctBy(x => x.carry_id).ToDictionary(x => x.carry_id, x => x.need_qty);
carryIds = carryMats.Select(x => x.carry_id).Distinct().ToList(); carryIds = carryMats.Select(x => x.carry_id).Distinct().ToList();
await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.).ToString(), collocation_scheme_id = singleSorting.collocation_scheme_id, collocation_scheme_code = singleSorting.collocation_scheme_code }).Where(it => carryIds.Contains(it.id)).ExecuteCommandAsync(); await _db.Updateable<WmsCarryH>().SetColumns(it => new WmsCarryH { out_status = ((int)EnumOutStatus.).ToString(), collocation_scheme_id = singleSorting.collocation_scheme_id, collocation_scheme_code = singleSorting.collocation_scheme_code }).Where(it => carryIds.Contains(it.id)).ExecuteCommandAsync();
@@ -280,7 +279,7 @@ namespace Tnb.WarehouseMgr
} }
} }
await _db.Updateable(curSortingDetails).ExecuteCommandAsync(); await _db.Updateable(curSortingDetails).ExecuteCommandAsync();
if(curSortingDetails.All(it=>it.line_status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID)) if (curSortingDetails.All(it => it.line_status == WmsWareHouseConst.BILLSTATUS_COMPLETE_ID))
{ {
await _db.Updateable<WmsSetsortingH>().SetColumns(it => new WmsSetsortingH { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }).Where(it => it.id == input.requireId).ExecuteCommandAsync(); await _db.Updateable<WmsSetsortingH>().SetColumns(it => new WmsSetsortingH { status = WmsWareHouseConst.BILLSTATUS_COMPLETE_ID }).Where(it => it.id == input.requireId).ExecuteCommandAsync();

View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.SwaggerUI;
namespace Tnb.Common.Options
{
public class ConfigureSwaggerUIOptions : IConfigureOptions<SwaggerUIOptions>
{
private readonly IWebHostEnvironment _hostingEnvironment;
public ConfigureSwaggerUIOptions(IWebHostEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
public void Configure(SwaggerUIOptions options)
{
// Configure SwaggerUI options
options.DefaultModelExpandDepth(2);
options.DefaultModelRendering(ModelRendering.Example);
options.DocExpansion(DocExpansion.List);
options.EnableDeepLinking();
options.DisplayOperationId();
options.EnableFilter();
options.MaxDisplayedTags(5);
options.ShowExtensions();
}
}
}