using System;
using SqlSugar;
using Infrastructure.Attribute;
using ZR.Model;
using ZR.Model.Dto;
using ZR.Model.Models;
using ZR.Repository;
using ZR.Service.Business.IBusinessService;
using System.Linq;

namespace ZR.Service.Business
{
    /// <summary>
    /// 基础资料/库位信息表Service业务层处理
    ///
    /// @author admin
    /// @date 2023-04-10
    /// </summary>
    [AppService(ServiceType = typeof(IBasBinService), ServiceLifetime = LifeTime.Transient)]
    public class BasBinService : BaseService<BasBin>, IBasBinService
    {
        #region 业务逻辑代码

        /// <summary>
        /// 查询基础资料/库位信息表列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public PagedInfo<BasBinDto> GetList(BasBinQueryDto parm)
        {
            //开始拼装查询条件
            var predicate = Expressionable.Create<BasBin>();

            //搜索条件查询语法参考Sqlsugar
            var response = Queryable()
                .Where(predicate.ToExpression())
                .ToPage<BasBin, BasBinDto>(parm);

            return response;
        }


        /// <summary>
        /// 添加基础资料/库位信息表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int AddBasBin(BasBin model)
        {
            return Add(model, true);
        }

        /// <summary>
        /// 修改基础资料/库位信息表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateBasBin(BasBin model)
        {
            //var response = Update(w => w.BinId == model.BinId, it => new BasBin()
            //{
            //    BinCode = model.BinCode,
            //    BinName = model.BinName,
            //    BinType = model.BinType,
            //    RegionId = model.RegionId,
            //    BinRow = model.BinRow,
            //    BinColumn = model.BinColumn,
            //    BinLayer = model.BinLayer,
            //    Describe = model.Describe,
            //    Visible = model.Visible,
            //    Status = model.Status,
            //    UpdateBy = model.UpdateBy,
            //    UpdateTime = model.UpdateTime,
            //    Remark = model.Remark,
            //});
            //return response;
            return Update(model, true);
        }

        /// <summary>
        /// 清空基础资料/库位信息表
        /// </summary>
        /// <returns></returns>
        public void TruncateBasBin()
        {
            Truncate();
        }
        #endregion
    }
}