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-07
    /// </summary>
    [AppService(ServiceType = typeof(IBasRegionService), ServiceLifetime = LifeTime.Transient)]
    public class BasRegionService : BaseService<BasRegion>, IBasRegionService
    {
        #region 业务逻辑代码

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

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

            return response;
        }


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

        /// <summary>
        /// 修改基础资料/库区信息表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int UpdateBasRegion(BasRegion model)
        {
            //var response = Update(w => w.RegionId == model.RegionId, it => new BasRegion()
            //{
            //    RegionCode = model.RegionCode,
            //    RegionName = model.RegionName,
            //    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 TruncateBasRegion()
        {
            Truncate();
        }
        #endregion
    }
}