using AutoMapper; using Model.ModelDto.SysDto; using System; using System.Collections.Generic; using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using SqlSugar; using WMS.DAL; using WMS.Entity.Context; using WMS.Entity.SysEntity; using WMS.IBLL.ISysServer; using WMS.IDAL.ISysInterface; namespace WMS.BLL.SysServer { public class FunSettingServer : DbHelper, IFunSettingServer { private static readonly SqlSugarScope Db = DataContext.Db; /// /// 依赖注入 /// private readonly IFunSettingRepository _setting; private readonly IMapper _mapper; /// /// 构造函数 /// /// 功能设定 /// automapper public FunSettingServer(IFunSettingRepository setting, IMapper mapper) : base(Db) { _setting = setting;//功能设定 _mapper = mapper;//automapper } /// /// 获取功能设定信息列表 /// /// 功能名称 /// 开启状态 /// 组号 /// public List GetFunSettingList(string FunSetName, string IsEnable, string GroupNo) { List settinglist = _setting.GetFunSettingList(FunSetName, IsEnable, GroupNo); return settinglist; } /// /// 根据id查询功能设定信息 /// /// 功能id /// public SysFunSetting GetFunSettingById(int id) { SysFunSetting settinglist = _setting.GetFunSettingById(id); return settinglist; } /// /// 根据编号查询功能设定消息 /// /// 功能编号 /// public SysFunSetting GetFunSettingByNo(string funSetNo) { try { var list = Db.Queryable().First(a => a.IsDel == "0" && a.FunSetNo == funSetNo); return list; } catch (Exception ex) { throw ex; } } ///// ///// 根据编号查询功能设定信息 ///// ///// 功能编号 ///// //public int GetFunSettingByNo(string FunSetNo) //{ // List funSettings = _setting.GetFunSettingByNo(FunSetNo); // return funSettings.Count; //} /// /// 新增功能信息 /// /// 功能设定dto /// /// 捕获异常 public async Task AddFunSettings(FunSettingDto settingdto) { //捕获异常 try { //映射模型 SysFunSetting setting = _mapper.Map(settingdto); //判断功能编号是否唯一 var set = GetFunSettingByNo(setting.FunSetNo); int i = 0; if (set != null) { i = 3; } else if (set == null) { var setData = Db.Queryable() .First(m => m.IsDel == "0" && m.GroupNo == settingdto.GroupNo && m.SetValue==settingdto.SetValue); if (setData!=null) { throw new Exception("同组内设定值重复"); } //新增 i = await _setting.AddFunSettings(setting); } return i; } catch (Exception ex) { //抛出异常 throw new Exception(ex.Message); } } /// /// 删除功能信息 /// /// 功能设定实体模型 /// /// 捕获异常 public async Task DelFunSettings(SysFunSetting funSetting) { //捕获异常 try { //删除 int i = await _setting.DelFunSettings(funSetting); return i; } catch (Exception ex) { //抛出异常 throw new Exception("删除功能异常", ex); } } /// /// 编辑功能信息 /// /// 功能设定实体 /// /// 捕获异常 public async Task ExitFunSettings(FunSettingDto settingdto) { //捕获异常 try { //映射模型 SysFunSetting setting = _mapper.Map(settingdto); var setData = Db.Queryable() .First(m => m.IsDel == "0" && m.GroupNo == settingdto.GroupNo && m.SetValue == settingdto.SetValue && m.Id!=settingdto.Id); if (setData != null) { throw new Exception("同组内设定值重复"); } //编辑 int i = await _setting.ExitFunSettings(setting); return i; } catch (Exception ex) { //抛出异常 throw new Exception(ex.Message); } } } }