change - SqlSugar异常报错问题处理测试StartCheckStatus

master
wenjy 6 months ago
parent 619a674cc0
commit 73bd807e31

@ -111,8 +111,8 @@ namespace SlnMesnac.WCS
private void StartCheckStatus()
{
//数据库里面的读写器集合,仅用来更新状态
List<BaseRfidInfo> rfidDbList = SqlSugarClient.Queryable<BaseRfidInfo>().ToList();
List<WcsBaseEquip> agvEquipList = SqlSugarClient.Queryable<WcsBaseEquip>().Where(it => it.EquipType == 1).ToList();
List<BaseRfidInfo> rfidDbList = SqlSugarClient.Ado.Context.CopyNew().Queryable<BaseRfidInfo>().ToList();
List<WcsBaseEquip> agvEquipList = SqlSugarClient.Ado.Context.CopyNew().Queryable<WcsBaseEquip>().Where(it => it.EquipType == 1).ToList();
Task.Run(async () =>
{
while (true)
@ -161,7 +161,17 @@ namespace SlnMesnac.WCS
rfidDb.IsOnline = status ? 1 : 0;
}
}
SqlSugarClient.Updateable(rfidDbList).UpdateColumns(it => new { it.IsOnline }).ExecuteCommand();
lock (string.Empty)
{
try
{
SqlSugarClient.Ado.Context.CopyNew().Updateable(rfidDbList).UpdateColumns(it => new { it.IsOnline }).ExecuteCommand();
}
catch (Exception ex)
{
_logger.Error($"更新RFID状态异常:{ex.Message}",ex);
}
}
#endregion RFID状态
//色粉库位有未取走色粉声光报警
@ -211,7 +221,7 @@ namespace SlnMesnac.WCS
{
PlcAbsractFactory? workShop3Plc = plcList.FirstOrDefault(x => x.ConfigKey == "workShop3Plc");
// 构建查询并执行 Any 方法
bool hasRecords = SqlSugarClient.Queryable<WcsBaseEquip>()
bool hasRecords = SqlSugarClient.Ado.Context.CopyNew().Queryable<WcsBaseEquip>()
.InnerJoin<WmsPalletInfo>((wbe, wpi) => wbe.ContainerCode == wpi.PalletInfoCode
&& !string.IsNullOrEmpty(wbe.ContainerCode)
&& wpi.TonerFlag == 1 && wbe.EquipType == 7).Any();
@ -240,7 +250,9 @@ namespace SlnMesnac.WCS
{
try
{
List<WcsAgvStatus> agvList = SqlSugarClient.Queryable<WcsAgvStatus>().ToList();
//List<WcsAgvStatus> agvList = SqlSugarClient.Queryable<WcsAgvStatus>().ToList();
List<WcsAgvStatus> agvList = SqlSugarClient.Ado.Context.CopyNew().Queryable<WcsAgvStatus>().ToList();
var data = new
{
reqCode = StaticData.SnowId.NextId(),
@ -274,7 +286,8 @@ namespace SlnMesnac.WCS
}
//TaskHandleByAgv(agvList);
SqlSugarClient.Updateable(agvList).ExecuteCommand();
//SqlSugarClient.Updateable(agvList).ExecuteCommand();
SqlSugarClient.Ado.Context.CopyNew().Updateable(agvList).ExecuteCommand();
}
}
catch (Exception ex)
@ -327,12 +340,13 @@ namespace SlnMesnac.WCS
{
Task.Run(() =>
{
List<WcsBaseEquip> agvEquipList = SqlSugarClient.Queryable<WcsBaseEquip>().Where(it => it.EquipType == 1).ToList();
var sqlClient = SqlSugarClient.Ado.Context.CopyNew();
List<WcsBaseEquip> agvEquipList = SqlSugarClient.Ado.Context.CopyNew().Queryable<WcsBaseEquip>().Where(it => it.EquipType == 1).ToList();
while (true)
{
try
{
List<WcsTask> wcsTasks = SqlSugarClient.Queryable<WcsTask>().Where(t => t.IsDelete == 1 || t.IsDelete == 2).ToList();
List<WcsTask> wcsTasks = SqlSugarClient.Ado.Context.CopyNew().Queryable<WcsTask>().Where(t => t.IsDelete == 1 || t.IsDelete == 2).ToList();
foreach (var item in wcsTasks)
{
WcsBaseEquip agvEquip = agvEquipList.First();
@ -353,30 +367,30 @@ namespace SlnMesnac.WCS
List<int> bigType = new List<int>() { 1, 3, 8, 10 };
if (bigType.Contains(item.TaskType))
{
List<WmsBaseLocation>? wmsBaseLocations = SqlSugarClient.Queryable<WmsBaseLocation>().Where(x => x.LocationCode == item.CurrPointNo || x.LocationCode == item.EndPointNo).ToList();
List<WmsBaseLocation>? wmsBaseLocations = SqlSugarClient.Ado.Context.CopyNew().Queryable<WmsBaseLocation>().Where(x => x.LocationCode == item.CurrPointNo || x.LocationCode == item.EndPointNo).ToList();
if (wmsBaseLocations != null && wmsBaseLocations.Count > 0)
{
wmsBaseLocations.ForEach(x => x.LocationStatus = 0);
SqlSugarClient.Updateable(wmsBaseLocations).ExecuteCommand();
SqlSugarClient.Ado.Context.CopyNew().Updateable(wmsBaseLocations).ExecuteCommand();
}
}
else //如果是小料箱解锁wcsbaseEquip
{
List<WcsBaseEquip> equips = SqlSugarClient.Queryable<WcsBaseEquip>().Where(x => x.AgvPositionCode == item.CurrPointNo || x.AgvPositionCode == item.EndPointNo).ToList();
List<WcsBaseEquip> equips = SqlSugarClient.Ado.Context.CopyNew().Queryable<WcsBaseEquip>().Where(x => x.AgvPositionCode == item.CurrPointNo || x.AgvPositionCode == item.EndPointNo).ToList();
if (equips != null && equips.Count > 0)
{
equips.ForEach(x => x.EquipStatus = 0);
SqlSugarClient.Updateable(equips).ExecuteCommand();
SqlSugarClient.Ado.Context.CopyNew().Updateable(equips).ExecuteCommand();
}
}
#endregion
SqlSugarClient.Deleteable<WcsTask>(item).ExecuteCommand();
SqlSugarClient.Ado.Context.CopyNew().Deleteable<WcsTask>(item).ExecuteCommand();
_logger.Agv($"任务id:{item.Id},任务名:{item.TaskName}已删除");
//
if (!string.IsNullOrEmpty(item.NextPointNo) && item.TaskStatus >= 2 && item.IsDelete == 2) //有执行任务的agv编号,并且需要去异常库位
{
WmsBaseLocation? endLocation = SqlSugarClient.Queryable<WmsBaseLocation>().First(x => x.LocationCode == "3066" && x.LocationStatus == 0 && string.IsNullOrEmpty(x.ContainerCode));
WmsBaseLocation? endLocation = SqlSugarClient.Ado.Context.CopyNew().Queryable<WmsBaseLocation>().First(x => x.LocationCode == "3066" && x.LocationStatus == 0 && string.IsNullOrEmpty(x.ContainerCode));
if (endLocation != null)
{
WcsTask task = new WcsTask();
@ -389,23 +403,23 @@ namespace SlnMesnac.WCS
task.CreatedBy = "wcs";
task.TaskName = "前往异常库位移库任务";
task.PalletInfoCode = item.PalletInfoCode;
SqlSugarClient.AsTenant().BeginTran();
sqlClient.AsTenant().BeginTran();
try
{
int id = SqlSugarClient.Insertable(task).ExecuteReturnIdentity();
int id = SqlSugarClient.Ado.Context.CopyNew().Insertable(task).ExecuteReturnIdentity();
WcsTaskLog wcsTaskLog = CoreMapper.Map<WcsTaskLog>(task);
wcsTaskLog.Id = id;
//锁定库位
endLocation.LocationStatus = 1;
SqlSugarClient.Updateable(endLocation).ExecuteCommand();
SqlSugarClient.Insertable(wcsTaskLog).ExecuteCommand();
SqlSugarClient.AsTenant().CommitTran();
SqlSugarClient.Ado.Context.CopyNew().Updateable(endLocation).ExecuteCommand();
SqlSugarClient.Ado.Context.CopyNew().Insertable(wcsTaskLog).ExecuteCommand();
sqlClient.AsTenant().CommitTran();
_logger.Agv($"生成{task.TaskName},起点:{task.CurrPointNo},终点:{task.EndPointNo}");
}
catch (Exception ex)
{
_logger.Error($"生成移库任务提交事务异常:{ex.Message}");
SqlSugarClient.AsTenant().RollbackTran();
sqlClient.AsTenant().RollbackTran();
}
}
else
@ -421,7 +435,7 @@ namespace SlnMesnac.WCS
}
else
{
SqlSugarClient.Deleteable<WcsTask>(item).ExecuteCommand();
sqlClient.Deleteable<WcsTask>(item).ExecuteCommand();
_logger.Agv($"任务id:{item.Id},任务名:{item.TaskName}已删除");
}
}

Loading…
Cancel
Save