using SlnMesnac.Model.domain;
using SlnMesnac.Repository.service.@base;
using System;
using System.Collections.Generic;
using System.Text;

#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* 版权所有 (c) 2024 WenJY 保留所有权利。
* CLR版本：4.0.30319.42000
* 机器名称：LAPTOP-E0N2L34V
* 命名空间：SlnMesnac.Repository.service.Impl
* 唯一标识：2ef6cbc3-f5ce-4d6a-9750-06aac8227b6f
*
* 创建者：WenJY
* 电子邮箱：wenjy@mesnac.com
* 创建时间：2024-04-07 16:57:02
* 版本：V1.0.0
* 描述：
*
*--------------------------------------------------------------------
* 修改人：
* 时间：
* 修改说明：
*
* 版本：V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace SlnMesnac.Repository.service.Impl
{
    public class BasePalletInfoServiceImpl : BaseServiceImpl<BasePalletInfo>, IBasePalletInfoService
    {

        public BasePalletInfoServiceImpl(Repository<BasePalletInfo> rep):base(rep)
        {

        }

        /// <summary>
        /// 根据托盘编码获取托盘信息
        /// </summary>
        /// <param name="palleCode"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public BasePalletInfo GetPalletInfoByPalletCode(string palleCode)
        {
            try
            {
                return base._rep.GetFirst(x => x.PalletInfoCode == palleCode);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException($"根据托盘编码获取托盘信息异常:{e.Message}");
            }
        }

        /// <summary>
        /// 更新托盘信息
        /// </summary>
        /// <param name="palletInfo"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public bool UpdatePalletInfo(BasePalletInfo palletInfo)
        {
            try
            {
                return base._rep.Update(palletInfo);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException($"更新托盘信息异常:{e.Message}");
            }
        }

        /// <summary>
        /// 解绑托盘信息
        /// </summary>
        /// <param name="palletInfo"></param>
        /// <returns></returns>
        /// <exception cref="InvalidOperationException"></exception>
        public bool UnBindPalletInfo(BasePalletInfo palletInfo)
        {
            try
            {
                palletInfo.MaterialId = null;
                palletInfo.MaterialCode = string.Empty;
                palletInfo.MaterialName = string.Empty;
                palletInfo.MaterialBarcode = string.Empty;
                palletInfo.UpdateTime = DateTime.Now;
                return base._rep.Update(palletInfo);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException($"解绑托盘信息异常:{e.Message}");
            }
        }
    }
}