593 lines
28 KiB
C#
593 lines
28 KiB
C#
using JNPF;
|
|
using JNPF.Common.Core.Manager;
|
|
using JNPF.Common.Dtos.VisualDev;
|
|
using JNPF.Common.Extension;
|
|
using JNPF.Common.Filter;
|
|
using JNPF.Common.Security;
|
|
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.FriendlyException;
|
|
using JNPF.Logging;
|
|
using JNPF.Systems.Entitys.System;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using JNPF.VisualDev;
|
|
using JNPF.VisualDev.Entitys;
|
|
using JNPF.VisualDev.Entitys.Dto.VisualDevModelData;
|
|
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;
|
|
using Tnb.Common.Redis;
|
|
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
|
|
|
namespace Tnb.ProductionMgr
|
|
{
|
|
/// <summary>
|
|
/// 料仓原料条码服务
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConst.Tag, Area = ModuleConst.Area, Order = 700)]
|
|
[Route("api/[area]/[controller]/[action]")]
|
|
[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;
|
|
private readonly RedisData _redisData;
|
|
|
|
public PrdRawMaterialBarcodeService(ISqlSugarRepository<PrdRawMaterialBarcode> repository,
|
|
IUserManager userManager,
|
|
IBillRullService billRuleService,
|
|
IVisualDevService visualDevService,
|
|
RedisData redisData,
|
|
IRunService runService,
|
|
IDictionaryDataService dictionaryDataService)
|
|
{
|
|
_db = repository.AsSugarClient();
|
|
_userManager = userManager;
|
|
_billRuleService = billRuleService;
|
|
_dictionaryDataService = dictionaryDataService;
|
|
_visualDevService = visualDevService;
|
|
_runService = runService;
|
|
_redisData = redisData;
|
|
OverideFuncs.UpdateAsync = Update;
|
|
OverideFuncs.GetListAsync = GetList;
|
|
}
|
|
|
|
private async Task<dynamic> GetList(VisualDevModelListQueryInput input)
|
|
{
|
|
Dictionary<string, object>? queryJson = !string.IsNullOrEmpty(input.queryJson) ? Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, object>>(input.queryJson) : new Dictionary<string, object>();
|
|
string billCode = queryJson.ContainsKey("bill_code") ? queryJson["bill_code"].ToString() : "";
|
|
string equipTypeId = queryJson.ContainsKey("f_flowid") ? queryJson["f_flowid"].ToString() : "";
|
|
string isUpdate = queryJson.ContainsKey("is_update") ? queryJson["is_update"].ToString() : "";
|
|
|
|
SqlSugarPagedList<PrdRawMaterialBarcodeListDto> result = await _db.Queryable<PrdRawMaterialBarcode>()
|
|
.LeftJoin<BasMaterial>((a, b) => a.material_id == b.id)
|
|
.LeftJoin<EqpEquipment>((a, b,c) => a.equip_id == c.id)
|
|
.LeftJoin<EqpEquipType>((a,b,c,d)=>c.equip_type_id==d.id)
|
|
.WhereIF(!string.IsNullOrEmpty(billCode),(a,b,c)=>a.bill_code.Contains(billCode))
|
|
.WhereIF(!string.IsNullOrEmpty(equipTypeId),(a,b,c)=>c.equip_type_id==equipTypeId)
|
|
.WhereIF(!string.IsNullOrEmpty(isUpdate),(a,b,c)=>a.is_update.ToString()==isUpdate)
|
|
.Where((a,b,c)=>a.type=="1")
|
|
.Select((a, b, c,d) => new PrdRawMaterialBarcodeListDto
|
|
{
|
|
id = a.id,
|
|
bill_code = a.bill_code,
|
|
equip_id = c.name,
|
|
material_id = b.name,
|
|
absorb_material_finish = a.absorb_material_finish==1 ? "是" : "否",
|
|
is_update = a.is_update==1 ? "是" : "否",
|
|
start_time = a.start_time!=null ? a.start_time.Value.ToString(DbTimeFormat.SS) : "",
|
|
end_time = a.end_time!=null ? a.end_time.Value.ToString(DbTimeFormat.SS) : "",
|
|
remark = a.remark,
|
|
f_flowid = d.name,
|
|
equip_id_id = c.id,
|
|
material_id_id = b.id
|
|
}).ToPagedListAsync(input.currentPage, int.MaxValue);
|
|
return PageResult<PrdRawMaterialBarcodeListDto>.SqlSugarPageResult(result);
|
|
}
|
|
|
|
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}");
|
|
|
|
Dictionary<string, string> dicCommand4 = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["DevName"] = "挤出集中供料",
|
|
["token"] = _eleCtlCfg.token,
|
|
["TagName"] = "开关1",
|
|
["Value"] = "true",
|
|
};
|
|
|
|
string responseresult4 = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand4, false);
|
|
Log.Information($"挤出集中供料开关1开启返回结果:{responseresult4}");
|
|
|
|
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}未设置原料条码数据采集项");
|
|
}
|
|
|
|
BasMaterial basMaterial = await _db.Queryable<BasMaterial>().SingleAsync(x => x.id == item.material_id);
|
|
|
|
Dictionary<string, string> dicCommand3 = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["DevName"] = eqpDaq.equip_code,
|
|
["token"] = _eleCtlCfg.token,
|
|
["TagName"] = eqpDaq.label_name,
|
|
["Value"] = basMaterial?.code ?? "",
|
|
};
|
|
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}");
|
|
|
|
Dictionary<string, string> dicCommand4 = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["DevName"] = "挤出集中供料",
|
|
["token"] = _eleCtlCfg.token,
|
|
["TagName"] = "开关1",
|
|
["Value"] = "false",
|
|
};
|
|
|
|
string responseresult4 = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand4, false);
|
|
Log.Information($"挤出集中供料开关1关闭返回结果:{responseresult4}");
|
|
}
|
|
|
|
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("JZGL")).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 == "")
|
|
.SetColumns(x=>x.absorb_material_finish==0)
|
|
.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 "成功";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新截料阀
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> UpdateStopValve(List<string> ids)
|
|
{
|
|
try
|
|
{
|
|
await _db.Ado.BeginTranAsync();
|
|
|
|
List<PrdRawMaterialBarcode> prdRawMaterialBarcodeList = await _db.Queryable<PrdRawMaterialBarcode>()
|
|
.Where(x => ids.Contains(x.id)).ToListAsync();
|
|
foreach (var item in prdRawMaterialBarcodeList)
|
|
{
|
|
if (string.IsNullOrEmpty(item.stop_valve))
|
|
{
|
|
throw Oops.Bah($"{item.bill_code}未设置截料阀");
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(item.equip_ids))
|
|
{
|
|
throw Oops.Bah($"{item.bill_code}未设置机台");
|
|
}
|
|
|
|
List<string> equipIdList = JsonConvert.DeserializeObject<List<string>>(item.equip_ids);
|
|
List<EqpEquipment> eqpEquipments = await _db.Queryable<EqpEquipment>().Where(x => equipIdList.Contains(x.id)).ToListAsync();
|
|
foreach (var equipment in eqpEquipments)
|
|
{
|
|
EqpDaq eqpDaq = await _db.Queryable<EqpDaq>().Where(x => x.equip_id == equipment.id && x.label_name.Contains("原料选择")).FirstAsync();
|
|
|
|
if (eqpDaq == null)
|
|
{
|
|
throw Oops.Bah($"{equipment.name}未设置原料选择数据采集项");
|
|
}
|
|
|
|
Dictionary<string, string> dicCommand3 = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["DevName"] = eqpDaq.equip_code,
|
|
["token"] = _eleCtlCfg.token,
|
|
["TagName"] = eqpDaq.label_name,
|
|
["Value"] = item.stop_valve,
|
|
};
|
|
Log.Information($"{eqpDaq.equip_code}{eqpDaq.label_name}更新参数:{JsonConvert.SerializeObject(dicCommand3)}");
|
|
string responseresult3 = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand3, false);
|
|
Log.Information($"{eqpDaq.equip_code}{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);
|
|
}
|
|
|
|
return "成功";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 管道状态
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> GetPipingStatus(List<string> ids)
|
|
{
|
|
try
|
|
{
|
|
await _db.Ado.BeginTranAsync();
|
|
|
|
List<PrdRawMaterialBarcode> prdRawMaterialBarcodeList = await _db.Queryable<PrdRawMaterialBarcode>()
|
|
.Where(x => ids.Contains(x.id)).ToListAsync();
|
|
foreach (var item in prdRawMaterialBarcodeList)
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(item.equip_ids))
|
|
{
|
|
throw Oops.Bah($"{item.bill_code}未设置机台");
|
|
}
|
|
|
|
List<string> equipIdList = JsonConvert.DeserializeObject<List<string>>(item.equip_ids);
|
|
List<EqpEquipment> eqpEquipments = await _db.Queryable<EqpEquipment>().Where(x => equipIdList.Contains(x.id)).ToListAsync();
|
|
foreach (var equipment in eqpEquipments)
|
|
{
|
|
EqpDaq eqpDaq = await _db.Queryable<EqpDaq>().Where(x => x.equip_id == equipment.id && x.label_name.Contains("配管状态")).FirstAsync();
|
|
|
|
if (eqpDaq == null)
|
|
{
|
|
throw Oops.Bah($"{equipment.name}未设置配管状态数据采集项");
|
|
}
|
|
|
|
bool data = await _redisData.TryGetValueByKeyField<bool>(eqpDaq.equip_code, eqpDaq.label_name);
|
|
|
|
int pipingStatus = data ? 1 : 0;
|
|
await _db.Updateable<PrdRawMaterialBarcode>()
|
|
.SetColumns(x => x.piping_status == pipingStatus)
|
|
.Where(x => x.id == item.id)
|
|
.ExecuteCommandAsync();
|
|
}
|
|
|
|
}
|
|
|
|
await _db.Ado.CommitTranAsync();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
await _db.Ado.RollbackTranAsync();
|
|
throw Oops.Bah(e.Message);
|
|
}
|
|
|
|
return "成功";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 机台原料设定吸料完成
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
public async Task<dynamic> MaterialSuctionCompleted2(List<string> ids)
|
|
{
|
|
try
|
|
{
|
|
await _db.Ado.BeginTranAsync();
|
|
|
|
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)
|
|
{
|
|
List<string> equipIdList = JsonConvert.DeserializeObject<List<string>>(item.equip_ids);
|
|
List<EqpEquipment> eqpEquipments = await _db.Queryable<EqpEquipment>().Where(x => equipIdList.Contains(x.id)).ToListAsync();
|
|
foreach (var equipment in eqpEquipments)
|
|
{
|
|
EqpDaq eqpDaq = await _db.Queryable<EqpDaq>().Where(x => x.equip_id == equipment.id && x.label_name.Contains("原料选择")).FirstAsync();
|
|
|
|
if (eqpDaq == null)
|
|
{
|
|
throw Oops.Bah($"{equipment.name}未设置原料选择数据采集项");
|
|
}
|
|
|
|
Dictionary<string, string> dicCommand3 = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
["DevName"] = eqpDaq.equip_code,
|
|
["token"] = _eleCtlCfg.token,
|
|
["TagName"] = eqpDaq.label_name,
|
|
["Value"] = "",
|
|
};
|
|
Log.Information($"{eqpDaq.equip_code}{eqpDaq.label_name}吸料完成参数:{JsonConvert.SerializeObject(dicCommand3)}");
|
|
string responseresult3 = await HttpClientHelper.GetRequestAsync(_eleCtlCfg.WriteTagUrl, dicCommand3, false);
|
|
Log.Information($"{eqpDaq.equip_code}{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.piping_status == 0)
|
|
.SetColumns(x=>x.absorb_material_finish==0)
|
|
.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);
|
|
}
|
|
return "成功";
|
|
}
|
|
}
|
|
} |