备件领用
This commit is contained in:
@@ -19,5 +19,10 @@ namespace Tnb.BasicData
|
||||
/// 生产任务单号单据模板编码
|
||||
/// </summary>
|
||||
public const string PRDMOTASK_CODE = "ProductionPlanAndSchedule";
|
||||
|
||||
/// <summary>
|
||||
/// 备件领用
|
||||
/// </summary>
|
||||
public const string SPAREPARTSREQUISITION_CODE = "SparePartsRequisition";
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Tnb.EquipMgr.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// 备品备件领用服务
|
||||
/// </summary>
|
||||
public interface IEqpSparePartsRequisitionHService
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
134
EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs
Normal file
134
EquipMgr/Tnb.EquipMgr/EqpSparePartsRequisitionHService.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user