Files
wcs/WCS.BLL/Services/Service/PDAMatBindService.cs
2025-02-23 14:46:12 +08:00

139 lines
5.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel.PDAMatBind;
namespace WCS.BLL.Services.Service
{
public class PDAMatBindService : IPDAMatBindService
{
public async Task<ResponseCommon> callEmptyShelf(BindMatDetailRequest request)
{
try
{
#region
//判断参数
if (request.LocationId == 0 || string.IsNullOrEmpty(request.LocationCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "工位或工位编码为空!\r\n请重新扫工位码",
Data = null,
};
}
#endregion
#region
//获取是否存在当前工位
var endLocation = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.Id == request.LocationId)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (endLocation == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"工位[{request.LocationCode}]不存在或已被禁用!\r\n请联系系统管理人员维护工位信息",
Data = null,
};
}
//获取当前工位的货架
var shelf = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.CurrentLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.
|| t.DestinationLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.)//解决产线人员 呼叫后货架未到的时候绑定的问题
.Where(t => t.IsEnable == true)
.FirstAsync();
if (shelf != null)
{
if (shelf.TransStatus == TransStatusEnum.)
{
return new ResponseCommon()
{
Code = 205,
Message = $"货架【{shelf.ShelfCode}】静止在工位上,请勿重复呼叫!",
Data = null,
};
}
//运输中
else
{
return new ResponseCommon()
{
Code = 205,
Message = $"货架【{shelf.ShelfCode}】运输中,请勿重复呼叫!\r\n货架到达后扫货架码即可继续绑定。",
Data = null,
};
}
}
#endregion
//获取空货架进行呼叫
shelf = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.TransStatus == TransStatusEnum. && t.CurrentLocationId != 0)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (shelf == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"不存在空货架!",
Data = null,
};
}
var startLocation = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.Id == shelf.CurrentLocationId)
.Where(t => t.IsEnable == true)
.FirstAsync();
var response = AGVManager.GenAgvSchedulingTask(startLocation, endLocation, shelf.ShelfCode, request.UserName);
if (response.code == "0" && response.message == "成功")
{
//更新货架位置信息
shelf.TransStatus = TransStatusEnum.;
shelf.DestinationLocationId = endLocation.Id;
shelf.DestinationLocaiotnCode = endLocation.LocationCode;
DbHelp.db.Updateable(shelf).ExecuteCommand();
return new ResponseCommon()
{
Code = 200,
Message = "success",
Data = null,
};
}
else
{
return new ResponseCommon()
{
Code = 201,
Message = $"海康RCS返回{response.message}",
Data = null,
};
}
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 201,
Message = ex.Message,
Data = null,
};
}
}
}
}