料仓原料条码 更新 刷新 吸料完成

This commit is contained in:
2024-08-02 17:50:27 +08:00
parent 07d656a9d6
commit f043f3fafe
6 changed files with 423 additions and 26 deletions

View File

@@ -100,16 +100,16 @@ namespace Tnb.EquipMgr
.Mapper(a =>
{
a.status = a.status == "1" ? "待执行" : a.status == "2" ? "待复核" : "已完成";
a.create_time = a.date_create_time == null ? "" : a.date_create_time.Value.ToString(DbTimeFormat.SS);
a.execute_time = a.date_execute_time == null ? "" : a.date_execute_time.Value.ToString(DbTimeFormat.SS);
a.repeat_time = a.date_repeat_time == null ? "" : a.date_repeat_time.Value.ToString(DbTimeFormat.SS);
a.last_execute_time = a.date_last_execute_time == null ? "" : a.date_last_execute_time.Value.ToString(DbTimeFormat.SS);
a.create_time = a.date_create_time == null ? "" : a.date_create_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
a.execute_time = a.date_execute_time == null ? "" : a.date_execute_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
a.repeat_time = a.date_repeat_time == null ? "" : a.date_repeat_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
a.last_execute_time = a.date_last_execute_time == null ? "" : a.date_last_execute_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
})
.ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
var EqpMaintainRecordHs = await db.Queryable<EqpMaintainRecordH>().Where(p => list.list.Select(p => p.equip_id_id).ToList().Contains(p.equip_id)).ToListAsync();
foreach (var data in list.list)
{
data.last_execute_time = EqpMaintainRecordHs.Where(x => data.equip_id_id == x.equip_id && x.execute_time != null).Any() ? EqpMaintainRecordHs.Where(x => data.equip_id_id == x.equip_id && x.execute_time != null).OrderByDescending(x => x.execute_time).FirstOrDefault()!.execute_time!.Value.ToString(DbTimeFormat.SS) : "";
data.last_execute_time = EqpMaintainRecordHs.Where(x => data.equip_id_id == x.equip_id && x.execute_time != null).Any() ? EqpMaintainRecordHs.Where(x => data.equip_id_id == x.equip_id && x.execute_time != null).OrderByDescending(x => x.execute_time).FirstOrDefault()!.execute_time!.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
}
return PageResult<EqpMaintainRecordListOutput>.SqlSugarPageResult(list);
}
@@ -291,7 +291,7 @@ namespace Tnb.EquipMgr
a.equip_id,
equip_code = b.code,
equip_name = b.name,
create_time = a.create_time == null ? "" : a.create_time.Value.ToString(DbTimeFormat.SS),
create_time = a.create_time == null ? "" : a.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"),
a.result_remark,
a.result,
a.status,

View File

@@ -100,16 +100,16 @@ namespace Tnb.EquipMgr
.Mapper(a =>
{
a.status = a.status == "1" ? "待执行" : a.status == "2" ? "待复核" : "已完成";
a.create_time = a.date_create_time == null ? "" : a.date_create_time.Value.ToString(DbTimeFormat.SS);
a.execute_time = a.date_execute_time == null ? "" : a.date_execute_time.Value.ToString(DbTimeFormat.SS);
a.repeat_time = a.date_repeat_time == null ? "" : a.date_repeat_time.Value.ToString(DbTimeFormat.SS);
a.last_execute_time = a.date_last_execute_time == null ? "" : a.date_last_execute_time.Value.ToString(DbTimeFormat.SS);
a.create_time = a.date_create_time == null ? "" : a.date_create_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
a.execute_time = a.date_execute_time == null ? "" : a.date_execute_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
a.repeat_time = a.date_repeat_time == null ? "" : a.date_repeat_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
a.last_execute_time = a.date_last_execute_time == null ? "" : a.date_last_execute_time.Value.ToString("yyyy-MM-dd HH:mm:ss");
})
.ToPagedListAsync(input?.currentPage ?? 1, input?.pageSize ?? 50);
var ToolMoldMaintainRecordHs = await db.Queryable<ToolMoldMaintainRecordH>().Where(p => list.list.Select(p => p.mold_id_id).ToList().Contains(p.mold_id)).ToListAsync();
foreach (var data in list.list)
{
data.last_execute_time = ToolMoldMaintainRecordHs.Where(x => data.mold_id_id == x.mold_id && x.execute_time != null).Any() ? ToolMoldMaintainRecordHs.Where(x => data.mold_id_id == x.mold_id && x.execute_time != null).OrderByDescending(x => x.execute_time).FirstOrDefault()!.execute_time!.Value.ToString(DbTimeFormat.SS) : "";
data.last_execute_time = ToolMoldMaintainRecordHs.Where(x => data.mold_id_id == x.mold_id && x.execute_time != null).Any() ? ToolMoldMaintainRecordHs.Where(x => data.mold_id_id == x.mold_id && x.execute_time != null).OrderByDescending(x => x.execute_time).FirstOrDefault()!.execute_time!.Value.ToString("yyyy-MM-dd HH:mm:ss") : "";
}
return PageResult<ToolMoldMaintainRecordListOutput>.SqlSugarPageResult(list);
}
@@ -293,7 +293,7 @@ namespace Tnb.EquipMgr
a.mold_id,
mold_code = b.mold_code,
mold_name = b.mold_name,
create_time = a.create_time == null ? "" : a.create_time.Value.ToString(DbTimeFormat.SS),
create_time = a.create_time == null ? "" : a.create_time.Value.ToString("yyyy-MM-dd HH:mm:ss"),
a.result_remark,
a.result,
a.status,

View File

@@ -0,0 +1,92 @@
using JNPF.Common.Contracts;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.ProductionMgr.Entities;
/// <summary>
/// 料仓原料条码记录表
/// </summary>
[SugarTable("prd_raw_material_barcode_record")]
public partial class PrdRawMaterialBarcodeRecord : BaseEntity<string>
{
public PrdRawMaterialBarcodeRecord()
{
id = SnowflakeIdHelper.NextId();
}
/// <summary>
/// 单据编号
/// </summary>
public string bill_code { get; set; } = string.Empty;
/// <summary>
/// 料仓id/机台id
/// </summary>
public string equip_id { get; set; } = string.Empty;
/// <summary>
/// 物料id
/// </summary>
public string? material_id { get; set; }
/// <summary>
/// 1 料仓原料条码 2 机台原料
/// </summary>
public string type { get; set; }
/// <summary>
/// 是否更新
/// </summary>
public int is_update { get; set; }
/// <summary>
/// 吸料完成
/// </summary>
public int absorb_material_finish { get; set; }
/// <summary>
/// 管道状态
/// </summary>
public int piping_status { get; set; }
/// <summary>
/// 开始时间
/// </summary>
public DateTime start_time { get; set; } = DateTime.Now;
/// <summary>
/// 结束时间
/// </summary>
public DateTime end_time { get; set; } = DateTime.Now;
/// <summary>
/// 备注
/// </summary>
public string? remark { 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; }
}

View File

@@ -1,10 +1,30 @@
using JNPF;
using JNPF.Common.Core.Manager;
using JNPF.Common.Dtos.VisualDev;
using JNPF.Common.Extension;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.DynamicApiController;
using JNPF.FriendlyException;
using JNPF.Logging;
using JNPF.Systems.Interfaces.System;
using JNPF.VisualDev;
using JNPF.VisualDev.Entitys;
using JNPF.VisualDev.Interfaces;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Senparc.CO2NET.HttpUtility;
using SqlSugar;
using Tnb.BasicData;
using Tnb.BasicData.Entities;
using Tnb.Common.Extension;
using Tnb.EquipMgr.Entities;
using Tnb.ProductionMgr.Entities;
using Tnb.WarehouseMgr.Entities.Configs;
using Tnb.Common.Utils;
using Tnb.WarehouseMgr.Entities.Consts;
using HttpClientHelper = Tnb.Common.Utils.HttpClientHelper;
namespace Tnb.ProductionMgr
{
@@ -13,31 +33,303 @@ namespace Tnb.ProductionMgr
/// </summary>
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
[Route("api/[area]/[controller]/[action]")]
public class PrdRawMaterialBarcodeService: IDynamicApiController, ITransient
[OverideVisualDev(ModuleId)]
public class PrdRawMaterialBarcodeService: IOverideVisualDevService,IDynamicApiController, ITransient
{
private const string ModuleId = "35925395676181";
private readonly ISqlSugarClient _db;
private readonly IDictionaryDataService _dictionaryDataService;
private readonly IUserManager _userManager;
private static Dictionary<string, Tuple<string, string>> _dicWorkLine = new();
private readonly ElevatorControlConfiguration _eleCtlCfg = App.Configuration.Build<ElevatorControlConfiguration>();
private readonly IBillRullService _billRuleService;
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
private readonly IVisualDevService _visualDevService;
private readonly IRunService _runService;
public PrdRawMaterialBarcodeService(ISqlSugarRepository<PrdRawMaterialBarcode> repository,
IUserManager userManager,
IBillRullService billRuleService,
IVisualDevService visualDevService,
IRunService runService,
IDictionaryDataService dictionaryDataService)
{
_db = repository.AsSugarClient();
_userManager = userManager;
_billRuleService = billRuleService;
_dictionaryDataService = dictionaryDataService;
_visualDevService = visualDevService;
_runService = runService;
OverideFuncs.UpdateAsync = Update;
}
// /// <summary>
// /// 上模校验
// /// </summary>
// /// <returns></returns>
// [HttpPost]
// public async Task<dynamic> CheckMold(string id)
// {
// // PrdRawMaterialBarcode prdRawMaterialBarcode = await _db.Queryable<PrdMoTask>().SingleAsync(x => x.id == input.mo_task_id);
// // BasQrcode basQrcode = await _db.Queryable<BasQrcode>().Where(x => x.source_name == "TOOL_MOLDS" && x.code == input.mold_qrcode).FirstAsync();
// // return prdMoTask != null && basQrcode != null ? prdMoTask.mold_id == basQrcode.source_id : (dynamic)false;
// }
private async Task<dynamic> Update(string id, VisualDevModelDataUpInput visualDevModelDataUpInput)
{
PrdRawMaterialBarcode prdRawMaterialBarcode = await _db.Queryable<PrdRawMaterialBarcode>().SingleAsync(x=>x.id==id);
string newMaterialId = visualDevModelDataUpInput.data.ContainsKey("material_id") ? visualDevModelDataUpInput.data["material_id"].ToString() : "";
VisualDevEntity? templateEntity = await _visualDevService.GetInfoById(ModuleId, true);
await _runService.Update(id, templateEntity, visualDevModelDataUpInput);
if (!string.IsNullOrEmpty(newMaterialId) && prdRawMaterialBarcode.material_id != newMaterialId)
{
string billCode = await _billRuleService.GetBillNumber(CodeTemplateConst.PRDRAWMATERIALBARCODE_CODE);
await _db.Updateable<PrdRawMaterialBarcode>()
.SetColumns(x => x.bill_code == billCode)
.Where(x => x.id == id)
.ExecuteCommandAsync();
}
return await Task.FromResult(true);
}
/// <summary>
/// 更新
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<dynamic> UpdateBarcode(List<string> ids)
{
try
{
await _db.Ado.BeginTranAsync();
Dictionary<string, string> dicCommand = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = "注塑主控柜",
["token"] = _eleCtlCfg.token,
["TagName"] = "开工1",
["Value"] = "true",
};
string responseresult =
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand, false);
Log.Information($"注塑主控柜开工1开启返回结果:{responseresult}");
Dictionary<string, string> dicCommand2 = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = "注塑主控柜",
["token"] = _eleCtlCfg.token,
["TagName"] = "开工2",
["Value"] = "true",
};
string responseresult2 =
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand2, false);
Log.Information($"注塑主控柜开工2开启返回结果:{responseresult2}");
List<PrdRawMaterialBarcode> prdRawMaterialBarcodeList = await _db.Queryable<PrdRawMaterialBarcode>()
.Where(x => ids.Contains(x.id)).ToListAsync();
foreach (var item in prdRawMaterialBarcodeList)
{
if (string.IsNullOrEmpty(item.material_id))
{
throw Oops.Bah($"{item.bill_code}未设置原材料");
}
EqpEquipment eqpEquipment =
await _db.Queryable<EqpEquipment>().SingleAsync(x => x.id == item.equip_id);
EqpDaq eqpDaq = await _db.Queryable<EqpDaq>()
.Where(x => x.equip_id == item.equip_id && x.label_name.Contains("原料条码")).FirstAsync();
if (eqpDaq == null)
{
throw Oops.Bah($"{eqpEquipment.name}未设置原料条码数据采集项");
}
Dictionary<string, string> dicCommand3 = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = eqpDaq.equip_code,
["token"] = _eleCtlCfg.token,
["TagName"] = eqpDaq.label_name,
["Value"] = item.material_id,
};
Log.Information($"注塑主控柜{eqpDaq.label_name}更新参数:{JsonConvert.SerializeObject(dicCommand3)}");
string responseresult3 =
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand3, false);
Log.Information($"注塑主控柜{eqpDaq.label_name}更新返回结果:{responseresult3}");
await _db.Updateable<PrdRawMaterialBarcode>()
.SetColumns(x => x.start_time == DateTime.Now)
.SetColumns(x => x.is_update == 1)
.Where(x => x.id == item.id)
.ExecuteCommandAsync();
}
await _db.Ado.CommitTranAsync();
}
catch (Exception e)
{
await _db.Ado.RollbackTranAsync();
throw Oops.Bah(e.Message);
}
finally
{
Dictionary<string, string> dicCommand = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = "注塑主控柜",
["token"] = _eleCtlCfg.token,
["TagName"] = "开工1",
["Value"] = "false",
};
string responseresult = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand, false);
Log.Information($"注塑主控柜开工1关闭返回结果:{responseresult}");
Dictionary<string, string> dicCommand2 = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = "注塑主控柜",
["token"] = _eleCtlCfg.token,
["TagName"] = "开工2",
["Value"] = "false",
};
string responseresult2 = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand2, false);
Log.Information($"注塑主控柜开工2关闭返回结果:{responseresult2}");
}
return "成功";
}
/// <summary>
/// 刷新 同步料仓
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<dynamic> AsyncMaterialWarhouse()
{
List<string> equipIds = await _db.Queryable<PrdRawMaterialBarcode>().Where(x=>x.type=="1").Select(x=>x.equip_id).ToListAsync();
List<EqpEquipment> equipments = await _db.Queryable<EqpEquipment>().Where(x=>!equipIds.Contains(x.id) && x.code.StartsWith("abc")).ToListAsync();
List<PrdRawMaterialBarcode> insertList = new List<PrdRawMaterialBarcode>();
if (equipments != null && !equipments.IsEmpty())
{
foreach (var item in equipments)
{
insertList.Add(new PrdRawMaterialBarcode()
{
id = SnowflakeIdHelper.NextId(),
bill_code = await _billRuleService.GetBillNumber(CodeTemplateConst.PRDRAWMATERIALBARCODE_CODE),
equip_id = item.id,
type = "1",
create_id = _userManager.UserId,
create_time = DateTime.Now,
org_id = WmsWareHouseConst.AdministratorOrgId,
});
}
}
if (!insertList.IsEmpty())
{
await _db.Insertable(insertList).ExecuteCommandAsync();
}
return "成功";
}
/// <summary>
/// 吸料完成
/// </summary>
/// <returns></returns>
[HttpPost]
public async Task<dynamic> MaterialSuctionCompleted(List<string> ids)
{
try
{
await _db.Ado.BeginTranAsync();
Dictionary<string, string> dicCommand = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = "注塑主控柜",
["token"] = _eleCtlCfg.token,
["TagName"] = "开工1",
["Value"] = "true",
};
string responseresult =
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand, false);
Log.Information($"注塑主控柜开工1开启返回结果:{responseresult}");
Dictionary<string, string> dicCommand2 = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = "注塑主控柜",
["token"] = _eleCtlCfg.token,
["TagName"] = "开工2",
["Value"] = "true",
};
string responseresult2 =
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand2, false);
Log.Information($"注塑主控柜开工2开启返回结果:{responseresult2}");
List<PrdRawMaterialBarcode> prdRawMaterialBarcodeList = await _db.Queryable<PrdRawMaterialBarcode>()
.Where(x => ids.Contains(x.id)).ToListAsync();
List<PrdRawMaterialBarcodeRecord> insertList = new List<PrdRawMaterialBarcodeRecord>();
foreach (var item in prdRawMaterialBarcodeList)
{
EqpEquipment eqpEquipment = await _db.Queryable<EqpEquipment>().SingleAsync(x => x.id == item.equip_id);
EqpDaq eqpDaq = await _db.Queryable<EqpDaq>().Where(x => x.equip_id == item.equip_id && x.label_name.Contains("原料条码")).FirstAsync();
if (eqpDaq == null)
{
throw Oops.Bah($"{eqpEquipment.name}未设置原料条码数据采集项");
}
Dictionary<string, string> dicCommand3 = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = eqpDaq.equip_code,
["token"] = _eleCtlCfg.token,
["TagName"] = eqpDaq.label_name,
["Value"] = "",
};
Log.Information($"注塑主控柜{eqpDaq.label_name}吸料完成参数:{JsonConvert.SerializeObject(dicCommand3)}");
string responseresult3 =
await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand3, false);
Log.Information($"注塑主控柜{eqpDaq.label_name}吸料完成返回结果:{responseresult3}");
PrdRawMaterialBarcodeRecord prdRawMaterialBarcodeRecord = item.Adapt<PrdRawMaterialBarcodeRecord>();
prdRawMaterialBarcodeRecord.id = SnowflakeIdHelper.NextId();
prdRawMaterialBarcodeRecord.end_time = DateTime.Now;
insertList.Add(prdRawMaterialBarcodeRecord);
await _db.Updateable<PrdRawMaterialBarcode>()
.SetColumns(x => x.bill_code == "")
.SetColumns(x => x.start_time == null)
.SetColumns(x => x.end_time == null)
.SetColumns(x => x.is_update == 0)
.SetColumns(x => x.material_id == "")
.Where(x => x.id == item.id)
.ExecuteCommandAsync();
}
if (!insertList.IsEmpty())
{
await _db.Insertable(insertList).ExecuteCommandAsync();
}
await _db.Ado.CommitTranAsync();
}
catch (Exception e)
{
await _db.Ado.RollbackTranAsync();
throw Oops.Bah(e.Message);
}
finally
{
Dictionary<string, string> dicCommand = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = "注塑主控柜",
["token"] = _eleCtlCfg.token,
["TagName"] = "开工1",
["Value"] = "false",
};
string responseresult = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand, false);
Log.Information($"注塑主控柜开工1关闭返回结果:{responseresult}");
Dictionary<string, string> dicCommand2 = new(StringComparer.OrdinalIgnoreCase)
{
["DevName"] = "注塑主控柜",
["token"] = _eleCtlCfg.token,
["TagName"] = "开工2",
["Value"] = "false",
};
string responseresult2 = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand2, false);
Log.Information($"注塑主控柜开工2关闭返回结果:{responseresult2}");
}
return "成功";
}
}
}

View File

@@ -379,8 +379,8 @@ namespace Tnb.WarehouseMgr
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("vbillcode", null);
erpRequestData.Add("vtrantypecode", null);
erpRequestData.Add("vbillcode", instock.bill_code);
erpRequestData.Add("vtrantypecode", tranType?.EnCode ?? "");
List<Dictionary<string, object>> erpRequestDataDetails = new List<Dictionary<string, object>>();
foreach (WmsInstockD item in allInstockDetails)

View File

@@ -123,6 +123,19 @@ namespace Tnb.WarehouseMgr
await _db.Insertable(instockDs).ExecuteCommandAsync();
var purchase = await _db.Queryable<WmsPurchaseH>().FirstAsync(it => it.id == purchaseDs.First().bill_id);
if (string.IsNullOrEmpty(purchase.supplier_id))
{
BasSupplier basSupplier = await _db.Queryable<BasSupplier>().Where(x=>x.supplier_code==purchase.supplier_code).FirstAsync();
if (basSupplier != null)
{
await _db.Updateable<WmsPurchaseH>()
.SetColumns(x => x.supplier_id == basSupplier.id)
.Where(x => x.id == purchase.id)
.ExecuteCommandAsync();
purchase.supplier_id = basSupplier.id;
}
}
List<WmsPurchaseD> dList = await _db.Queryable<WmsPurchaseD>().Where(x=>x.bill_id==purchaseDs.First().bill_id).OrderBy(x=>x.id).ToListAsync();
List<String> materialIds = purchaseDs.Select(x=>x.material_id).Distinct().ToList();
List<String> unitCodes = purchaseDs.Select(x => x.unit_id).Distinct().ToList();