调拨入库 备品备件
This commit is contained in:
@@ -63,5 +63,14 @@ public partial class EqpSpareParts : BaseEntity<string>
|
||||
/// 备注
|
||||
/// </summary>
|
||||
public string? remark { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 安全库存
|
||||
/// </summary>
|
||||
public decimal? safety_stock { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 保质期(天)
|
||||
/// </summary>
|
||||
public int quality_guarantee_period { get; set; }
|
||||
}
|
||||
@@ -48,5 +48,10 @@ public partial class EqpSparePartsInstockD : BaseEntity<string>
|
||||
/// 已领数量
|
||||
/// </summary>
|
||||
public int use_quantity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 批号
|
||||
/// </summary>
|
||||
public string batch { get; set; }
|
||||
|
||||
}
|
||||
100
EquipMgr/Tnb.EquipMgr/EqpEquipSparePartsInstockService.cs
Normal file
100
EquipMgr/Tnb.EquipMgr/EqpEquipSparePartsInstockService.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System.CodeDom.Compiler;
|
||||
using JNPF.Common.Core.Manager;
|
||||
using JNPF.Common.Dtos.VisualDev;
|
||||
using JNPF.Common.Filter;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.DependencyInjection;
|
||||
using JNPF.DynamicApiController;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Systems.Entitys.Permission;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.VisualDev;
|
||||
using JNPF.VisualDev.Entitys;
|
||||
using JNPF.VisualDev.Interfaces;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using NPOI.SS.Formula.Functions;
|
||||
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 EqpEquipSparePartsInstockService : IOverideVisualDevService, IDynamicApiController, ITransient
|
||||
{
|
||||
private const string ModuleId = "27338626725397";
|
||||
private readonly ISqlSugarRepository<EqpEquipSpareParts> _repository;
|
||||
private readonly IUserManager _userManager;
|
||||
private readonly IVisualDevService _visualDevService;
|
||||
private readonly IRunService _runService;
|
||||
|
||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||
|
||||
public EqpEquipSparePartsInstockService(ISqlSugarRepository<EqpEquipSpareParts> repository,
|
||||
IVisualDevService visualDevService,
|
||||
IRunService runService,
|
||||
IUserManager userManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_visualDevService = visualDevService;
|
||||
_runService = runService;
|
||||
_repository = repository;
|
||||
OverideFuncs.CreateAsync = Create;
|
||||
}
|
||||
|
||||
private async Task<dynamic> Create(VisualDevModelDataCrInput input)
|
||||
{
|
||||
ISqlSugarClient db = _repository.AsSugarClient();
|
||||
DbResult<bool> result = await db.Ado.UseTranAsync(async () =>
|
||||
{
|
||||
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
|
||||
await _runService.Create(templateEntity, input);
|
||||
|
||||
string id = input.data["ReturnIdentity"].ToString();
|
||||
string nowStr = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
string nowStr2 = DateTime.Now.ToString("yyyyMMdd");
|
||||
EqpSparePartsInstockH eqpSparePartsInstockH = await db.Queryable<EqpSparePartsInstockH>()
|
||||
.Where(x => x.id!=id && x.create_time.Value.ToString("yyyy-MM-dd") == nowStr)
|
||||
.OrderByDescending(x => x.create_time)
|
||||
.FirstAsync();
|
||||
string batch = "";
|
||||
if (eqpSparePartsInstockH != null)
|
||||
{
|
||||
EqpSparePartsInstockD eqpSparePartsInstockD = await db.Queryable<EqpSparePartsInstockD>()
|
||||
.Where(x => x.instock_id == eqpSparePartsInstockH.id)
|
||||
.FirstAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(eqpSparePartsInstockD.batch))
|
||||
{
|
||||
string batchNum = eqpSparePartsInstockD.batch.Substring(eqpSparePartsInstockD.batch.Length - 3);
|
||||
int num = int.Parse(batchNum) + 1;
|
||||
batch = nowStr2 + num.ToString().PadLeft(3,'0');
|
||||
}
|
||||
else
|
||||
{
|
||||
batch = nowStr2 + "1".PadLeft(3,'0');
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
batch = nowStr2 + "1".PadLeft(3,'0');
|
||||
}
|
||||
await db.Updateable<EqpSparePartsInstockD>()
|
||||
.SetColumns(x => x.batch == batch)
|
||||
.Where(x => x.instock_id == id)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
});
|
||||
|
||||
return !result.IsSuccess ? throw Oops.Bah(result.ErrorMessage) : (dynamic)(result.IsSuccess ? "保存成功" : result.ErrorMessage);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -846,26 +846,66 @@ namespace Tnb.ProductionMgr
|
||||
{
|
||||
string result = "";
|
||||
BasFactoryConfig config = await _repository.AsSugarClient().Queryable<BasFactoryConfig>().FirstAsync(x => x.enabled == 1 && x.key == FactoryConfigConst.DOMAIN);
|
||||
|
||||
try
|
||||
{
|
||||
string response1 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-unit");
|
||||
AuthResponse authResponse1 = JsonConvert.DeserializeObject<AuthResponse>(response1);
|
||||
result += authResponse1.data.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message,e);
|
||||
result += e.Message;
|
||||
}
|
||||
|
||||
string response1 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-unit");
|
||||
AuthResponse authResponse1 = JsonConvert.DeserializeObject<AuthResponse>(response1);
|
||||
result += authResponse1.data.ToString();
|
||||
try
|
||||
{
|
||||
string response2 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-material");
|
||||
AuthResponse authResponse2 = JsonConvert.DeserializeObject<AuthResponse>(response2);
|
||||
result += ","+authResponse2.data.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message,e);
|
||||
result += e.Message;
|
||||
}
|
||||
|
||||
string response2 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-material");
|
||||
AuthResponse authResponse2 = JsonConvert.DeserializeObject<AuthResponse>(response2);
|
||||
result += ","+authResponse2.data.ToString();
|
||||
try
|
||||
{
|
||||
string response3 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-customer");
|
||||
AuthResponse authResponse3 = JsonConvert.DeserializeObject<AuthResponse>(response3);
|
||||
result += ","+authResponse3.data.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message,e);
|
||||
result += e.Message;
|
||||
}
|
||||
|
||||
string response3 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-customer");
|
||||
AuthResponse authResponse3 = JsonConvert.DeserializeObject<AuthResponse>(response3);
|
||||
result += ","+authResponse3.data.ToString();
|
||||
try
|
||||
{
|
||||
string response4 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-supplier");
|
||||
AuthResponse authResponse4 = JsonConvert.DeserializeObject<AuthResponse>(response4);
|
||||
result += ","+authResponse4.data.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message,e);
|
||||
result += e.Message;
|
||||
}
|
||||
|
||||
string response4 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-supplier");
|
||||
AuthResponse authResponse4 = JsonConvert.DeserializeObject<AuthResponse>(response4);
|
||||
result += ","+authResponse4.data.ToString();
|
||||
|
||||
string response5 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-user");
|
||||
AuthResponse authResponse5 = JsonConvert.DeserializeObject<AuthResponse>(response5);
|
||||
result += ","+authResponse5.data.ToString();
|
||||
try
|
||||
{
|
||||
string response5 = HttpUtils.RequestGet($"{config.value}/api/production/time-work/sync-user");
|
||||
AuthResponse authResponse5 = JsonConvert.DeserializeObject<AuthResponse>(response5);
|
||||
result += ","+authResponse5.data.ToString();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(e.Message,e);
|
||||
result += e.Message;
|
||||
}
|
||||
|
||||
Log.Information($"基础数据同步结果:{result}");
|
||||
return result;
|
||||
|
||||
@@ -593,5 +593,9 @@
|
||||
/// </summary>
|
||||
public const string POINT_Elevator3 = "29307999693333";
|
||||
|
||||
/// <summary>
|
||||
/// 天益供应商id
|
||||
/// </summary>
|
||||
public const string TIANYIGONGYINGSHANG_ID = "35770039572253";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using JNPF.Common.Filter;
|
||||
using JNPF.Common.Security;
|
||||
using JNPF.EventBus;
|
||||
using JNPF.FriendlyException;
|
||||
using JNPF.Systems.Entitys.Permission;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using JNPF.Systems.Interfaces.System;
|
||||
using Mapster;
|
||||
@@ -439,11 +440,112 @@ namespace Tnb.WarehouseMgr
|
||||
// 调拨入库
|
||||
else if (instock.bill_type == WmsWareHouseConst.BILLTYPE_RAWMATTRANSFERINSTOCK_ID)
|
||||
{
|
||||
List<WmsInstockD> allInstockDetails = await _db.Queryable<WmsInstockD>().Where(it => it.bill_id == input.requireId).ToListAsync();
|
||||
|
||||
WmsTempCode wmsTempCode = await _db.Queryable<WmsCarryCode>()
|
||||
.LeftJoin<WmsTempCode>((a, b) => a.barcode == b.barcode)
|
||||
.Where((a, b) => a.carry_id == input.wmsDistaskH.carry_id)
|
||||
.Select((a, b) => b)
|
||||
.FirstAsync();
|
||||
|
||||
string rawmatTransferinstockDId = wmsTempCode?.require_id ?? "";
|
||||
WmsRawmatTransferinstockD wmsRawmatTransferinstockD = await _db.Queryable<WmsRawmatTransferinstockD>().SingleAsync(x => x.id == rawmatTransferinstockDId);
|
||||
string rawmatTransferinstockHId = wmsRawmatTransferinstockD?.bill_id ?? "";
|
||||
WmsRawmatTransferinstockH wmsRawmatTransferinstockH = await _db.Queryable<WmsRawmatTransferinstockH>().SingleAsync(x => x.id == rawmatTransferinstockHId);
|
||||
|
||||
List<String> materialIds = allInstockDetails.Select(x => x.material_id).Distinct().ToList();
|
||||
List<String> unitCodes = allInstockDetails.Select(x => x.unit_id).Distinct().ToList();
|
||||
List<DictionaryDataEntity> unitDatas = await _db.Queryable<DictionaryTypeEntity>()
|
||||
.LeftJoin<DictionaryDataEntity>((x, y) => x.Id == y.DictionaryTypeId)
|
||||
.Where((x, y) => x.EnCode == DictConst.MeasurementUnit && unitCodes.Contains(y.EnCode))
|
||||
.Select((x, y) => y)
|
||||
.ToListAsync();
|
||||
|
||||
string supplierId = WmsWareHouseConst.TIANYIGONGYINGSHANG_ID;
|
||||
List<string> tableIds = new List<string>();
|
||||
tableIds.Add(_userManager.UserId);
|
||||
tableIds.Add(WmsWareHouseConst.AdministratorOrgId);
|
||||
tableIds.Add(instock.warehouse_id);
|
||||
tableIds.AddRange(materialIds);
|
||||
tableIds.Add(supplierId);
|
||||
tableIds.AddRange(unitDatas.Select(x => x.Id).ToList());
|
||||
|
||||
List<ErpExtendField> erpExtendFields = await _db.Queryable<ErpExtendField>().Where(x => tableIds.Contains(x.table_id)).ToListAsync();
|
||||
string userAccount = wmsRawmatTransferinstockH?.biller ?? "";
|
||||
string deptCode = wmsRawmatTransferinstockH?.dept_code ?? "";
|
||||
UserEntity userEntity = await _db.Queryable<UserEntity>().Where(x=>x.Account==userAccount).FirstAsync();
|
||||
string userId = userEntity?.Id ?? "";
|
||||
string erpCreateId = erpExtendFields.Find(x => x.table_id == userId)?.user_id ?? "";
|
||||
ErpExtendField erpOrg = erpExtendFields.Find(x => x.table_id == (WmsWareHouseConst.AdministratorOrgId));
|
||||
string nowStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
List<Dictionary<string, object>> requestData = new List<Dictionary<string, object>>();
|
||||
Dictionary<string, object> erpRequestData = new Dictionary<string, object>();
|
||||
erpRequestData.Add("billmaker", erpCreateId);
|
||||
erpRequestData.Add("cbiztype", "");
|
||||
erpRequestData.Add("cdptid","1001A1100000000JRLI1");//部门先写死
|
||||
erpRequestData.Add("cdptvid","0001A11000000007GGO8");//部门先写死
|
||||
erpRequestData.Add("corpoid", erpOrg.corpoid);
|
||||
erpRequestData.Add("corpvid", erpOrg.corpvid);
|
||||
erpRequestData.Add("creationtime", nowStr);
|
||||
erpRequestData.Add("creator", erpCreateId);
|
||||
erpRequestData.Add("cwarehouseid", erpExtendFields.Find(x => x.table_id == instock.warehouse_id)?.cotherwhid ?? "");//类型视图里取
|
||||
erpRequestData.Add("dbilldate", nowStr);
|
||||
erpRequestData.Add("dmakedate", nowStr);
|
||||
erpRequestData.Add("fbillflag", 1);
|
||||
erpRequestData.Add("ntotalnum", allInstockDetails.Sum(x => x.qty));
|
||||
erpRequestData.Add("pk_org", erpOrg.pk_org);
|
||||
erpRequestData.Add("pk_org_v", erpOrg.pk_org_v);
|
||||
erpRequestData.Add("pk_group", erpOrg.pk_group);
|
||||
erpRequestData.Add("vdef1", null);
|
||||
erpRequestData.Add("vbillcode", instock.bill_code);
|
||||
erpRequestData.Add("ctrantypeid", "0001H11000000000D31E");//先写死
|
||||
erpRequestData.Add("vtrantypecode", "4E-01");//先写死
|
||||
erpRequestData.Add("csourcebillhid", wmsRawmatTransferinstockH?.erp_pk ?? "");
|
||||
|
||||
|
||||
List<Dictionary<string, object>> erpRequestDataDetails = new List<Dictionary<string, object>>();
|
||||
foreach (WmsInstockD item in allInstockDetails)
|
||||
{
|
||||
erpRequestDataDetails.Add(new Dictionary<string, object>()
|
||||
{
|
||||
["cbodytranstypecode"] = "4E-01",
|
||||
["cbodywarehouseid"] = erpExtendFields.Find(x => x.table_id == instock.warehouse_id)?.cotherwhid ?? "",
|
||||
["cmaterialoid"] = erpExtendFields.Find(x => x.table_id == item.material_id)?.cmaterialoid ?? "",
|
||||
["cmaterialvid"] = erpExtendFields.Find(x => x.table_id == item.material_id)?.cmaterialvid ?? "",
|
||||
["corpoid"] = erpOrg.corpoid,
|
||||
["corpvid"] = erpOrg.corpvid,
|
||||
["crowno"] = (allInstockDetails.FindIndex(x => x.id == item.id) + 1) * 10,
|
||||
["csourcebillhid"] = wmsRawmatTransferinstockH?.erp_pk ?? "",
|
||||
["csourcebillbid"] = wmsRawmatTransferinstockD?.erp_line_pk ?? "",
|
||||
["cunitid"] = erpExtendFields.Find(x => x.table_id == (unitDatas.Find(x => x.EnCode == item.unit_id)?.Id ?? ""))?.cunitid ?? "",
|
||||
["cvendorid"] = erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_id ?? "",
|
||||
["cvendorvid"] = erpExtendFields.Find(x => x.table_id == supplierId)?.supplier_vid ?? "",
|
||||
["dbizdate"] = instock.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
["dplanarrivedate"] = instock.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
["dplanoutdate"] = instock.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
|
||||
["nnum"] = item.qty,
|
||||
["nshouldnum"] = item.pr_qty,
|
||||
["pk_group"] = erpOrg.pk_group,
|
||||
["pk_org"] = erpOrg.pk_org,
|
||||
["pk_org_v"] = erpOrg.pk_org_v,
|
||||
["vbatchcode"] = item.code_batch,
|
||||
});
|
||||
}
|
||||
erpRequestData.Add("dtls", erpRequestDataDetails);
|
||||
requestData.Add(erpRequestData);
|
||||
|
||||
ThirdWebapiRecord thirdWebapiRecord = new ThirdWebapiRecord();
|
||||
thirdWebapiRecord.id = SnowflakeIdHelper.NextId();
|
||||
thirdWebapiRecord.third_name = WmsWareHouseConst.BIP;
|
||||
thirdWebapiRecord.name = "调拨入库";
|
||||
thirdWebapiRecord.method = "POST";
|
||||
thirdWebapiRecord.url = WmsWareHouseConst.BIP_DOMAIN + "uapws/rest/transIn/save";
|
||||
thirdWebapiRecord.request_data = JsonConvert.SerializeObject(requestData);
|
||||
thirdWebapiRecord.create_time = DateTime.Now;
|
||||
await _db.Insertable(thirdWebapiRecord).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
await _db.Ado.CommitTranAsync();
|
||||
|
||||
Reference in New Issue
Block a user