123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- 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<EapAppserverMac> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<EapAppserverMac>($" {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<EapAppserverMac>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public EapAppserverMac Get(int id)
- {
- var pro = CurrDb.FindEntityFor<EapAppserverMac>(id);
- return pro;
- }
- public int Delete(int id, ref string msg)
- {
- if (CurrDb.DeleteFor<EapAppserverMac>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- /// <summary>
- /// 添加机台到EAP服务器
- /// </summary>
- /// <param name="eapServerId"></param>
- /// <param name="macIds"></param>
- /// <param name="userCode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int AddMacToEapServer(int eapServerId, IEnumerable<int> 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;
- }
- /// <summary>
- /// 更新机台所在的APPServer
- /// </summary>
- /// <param name="macId"></param>
- /// <param name="appServerId"></param>
- /// <param name="userCode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int Update(int macId, int appServerId, string userCode, ref string errorinfo)
- {
- var tmp = CurrDb.FindListForCondition<EapAppserverMac>($" 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<FactoryAppServer> list = new List<FactoryAppServer>();
- 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<EapAppserverMac>($"select * from eapappservermac where MacID={macId}").FirstOrDefault();
- foreach (var server in serverList)
- {
- int count = Convert.ToInt32(CurrDb.FindList<string>($"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;
- }
- }
- }
|