using FactorySystemCommon;
using FactorySystemModel.SqlSugarModel;
using SqlSugar;
using System.Collections.Generic;
using FactorySystemModel.EnumModel;
namespace FactorySystemBll
{
    public class FactoryBll
    {
        /// 
        /// 获取配置信息
        /// 
        public static List GetFactoryList()
        {
            int isDelete = (int)Constant.DeleteCode.已删除;
            return AppSettingsHelper.GetSqlSugar().Queryable().Where(s => s.FDeleted != isDelete).ToList();
        }
        /// 
        /// 验证工厂代码是否重复
        /// 
        public object CheckHasCode(Dictionary insertData)
        {
            SqlSugarClient db = AppSettingsHelper.GetSqlSugar();
            int isDelete = (int)Constant.DeleteCode.已删除;
            string code = insertData["FCode"].ToString();
            if (int.TryParse(insertData["FID"].ToString(), out int dataId) && dataId > 0)
            {
                return AppSettingsHelper.GetSqlSugar().Queryable().Where(s => s.FDeleted != isDelete 
                && s.FCode == code && s.FID != dataId).Count();
            }
            else
            {
                return AppSettingsHelper.GetSqlSugar().Queryable().Where(s => s.FDeleted != isDelete && s.FCode == code).Count();
            }
        }
    }
}