using WmsMobileServe.Annotation;
using WmsMobileServe.DataBase.Base.Po;

namespace WmsMobileServe.DataBase.Base.Dao;

/// <summary>
/// 出库任务表操作类
/// </summary>
/// <param name="client"></param>
[Component]
public class TPickingGoodsDao(DataBaseClient client)
{

    public List<TPickGoods>? SelectPickTask(string? vehicleNo)
    {
        try
        {
            var sqlFuc = client.Instance().Queryable<TPickGoods>()
                .Where(w => w.VehicleNo == vehicleNo && w.Status == "2");
            return sqlFuc.ToList();
        }
        catch (Exception ex)
        {
            _ = ex;
            return null;
        }
    }


    public bool PickComplete(List<(string? vehicleNo, string? goodsId, decimal? pickingNum)> pickData)
    {
        try
        {
            var sqlFuc = client.Instance().UseTran(() =>
            {
                foreach ((string? vehicleNo, string? goodsId, decimal? pickingNum) in pickData)
                {
                    client.Instance().Updateable<TPickGoods>()
                    .SetColumns(s => s.Status == "3")
                    .SetColumns(s => s.GoodsNumSj == pickingNum)
                    .Where(w => w.VehicleNo == vehicleNo && w.GoodsId == goodsId).ExecuteCommand();
                }
            });
            return sqlFuc.IsSuccess;
        }
        catch (Exception ex)
        {
            _ = ex;
            return false;
        }
    }





}
