using Cksoft.Data; using DllEapEntity; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DllEapDal.OFILM { public class EapAppServerMacDal { private IDatabase CurrDb = null; public EapAppServerMacDal(IDatabase db) { CurrDb = db; } public IEnumerable Get(int start, int length, string order, string sort, string filter, string errorinfo) { var pros = CurrDb.FindListForCondition($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo); return pros; } public int GetCount(string filter) { string errorinfo = string.Empty; var entities = CurrDb.FindListForCondition(filter, ref errorinfo); if (entities != null) { return entities.Count(); } return 0; } public EapAppserverMac Get(int id) { var pro = CurrDb.FindEntityFor(id); return pro; } public int Delete(int id, ref string msg) { if (CurrDb.DeleteFor(id) < 0) { msg = "删除失败"; return -1; } msg = string.Empty; return 1; } /// /// 添加机台到EAP服务器 /// /// /// /// /// /// public int AddMacToEapServer(int eapServerId, IEnumerable macIds, string userCode, ref string errorinfo) { //var sql = $"delete from eapappservermac where EapAppserverID={eapServerId}"; //if (CurrDb.ExecuteBySql(sql) < 0) //{ // errorinfo = "删除原数据失败"; // return -1; //} if (macIds != null && macIds.Count() > 0) { foreach (var item in macIds) { var temp = new EapAppserverMac { EapAppserverID = eapServerId, MacID = item }; if (CurrDb.InsertFor(temp, userCode) < 0) { errorinfo = "插入数据库失败"; return -1; } } } return 1; } /// /// 更新机台所在的APPServer /// /// /// /// /// /// public int Update(int macId, int appServerId, string userCode, ref string errorinfo) { var tmp = CurrDb.FindListForCondition($" and a.macid={macId}", ref errorinfo).FirstOrDefault(); if (tmp == null) { return this.AddMacToEapServer(appServerId, new int[] { macId }, userCode, ref errorinfo); } tmp.EapAppserverID = appServerId; return CurrDb.UpdateFor(tmp, userCode); } public bool MoveMacToAppServer(int macId, string oldFactoryCode, string newFactoryCode, ref string errInfo) { bool result = false; List list = new List(); list.Add(new FactoryAppServer { FactoryCode = "Factory02", AppServeCode = "AppServer001", AppServerId = 1 }); list.Add(new FactoryAppServer { FactoryCode = "Factory02", AppServeCode = "AppServer002", AppServerId = 2 }); list.Add(new FactoryAppServer { FactoryCode = "Factory03", AppServeCode = "AppServer003", AppServerId = 3 }); list.Add(new FactoryAppServer { FactoryCode = "Factory03", AppServeCode = "AppServer004", AppServerId = 4 }); list.Add(new FactoryAppServer { FactoryCode = "Factory04", AppServeCode = "AppServer005", AppServerId = 5 }); list.Add(new FactoryAppServer { FactoryCode = "Factory04", AppServeCode = "AppServer006", AppServerId = 6 }); var serverList = list.Where(s => s.FactoryCode == newFactoryCode); var mac = CurrDb.FindList($"select * from eapappservermac where MacID={macId}").FirstOrDefault(); foreach (var server in serverList) { int count = Convert.ToInt32(CurrDb.FindList($"select count(1) from eapappservermac where EapAppserverID={server.AppServerId}").FirstOrDefault()); if (count < 200) { if (mac == null) { mac = new EapAppserverMac { EapAppserverID = server.AppServerId, MacID = macId }; CurrDb.InsertFor(mac, "系统"); } else { mac.EapAppserverID = server.AppServerId; CurrDb.UpdateFor(mac, "系统"); } result = true; break; } } errInfo = result ? "" : $"园区{newFactoryCode}的服务器对应的机台都已达到200台,无法新增"; return result; } } }