123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using Cksoft.Data;
- using DllEapEntity;
- using SharpCifs.Util.Sharpen;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal.OFILM
- {
- public class EapAppServerDal
- {
- private IDatabase CurrDb = null;
- public EapAppServerDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<EapAppserver> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<EapAppserver>($" {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<EapAppserver>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public EapAppserver Get(int id)
- {
- var pro = CurrDb.FindEntityFor<EapAppserver>(id);
- return pro;
- }
- /// <summary>
- /// 添加角色并返回角色Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(EapAppserver pro, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<EapAppserver>($" and a.FCode='{pro.FCode}' ", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "已存在相同编号的APP服务器,请确认";
- return -1;
- }
- CurrDb.InsertFor(pro, userCode);
- var sql = "select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- return id;
- }
- /// <summary>
- /// 待优化 存在删除后不能
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int Update(EapAppserver role, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<EapAppserver>($" and a.FCode='{role.FCode}' " +
- $"and a.ID<>{role.ID}", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "已存在相同编号的APP服务器,请确认";
- return -1;
- }
- if (CurrDb.UpdateFor(role, userCode) < 0)
- {
- return -1;
- }
- return role.ID;
- }
- public IEnumerable<EapAppserverMac> geteapappservermac(int id)
- {
- var sql = $"select * from eapappservermac where EapAppserverID={id}";
- return CurrDb.FindList<EapAppserverMac>(sql);
- }
- public int Delete(int id, ref string msg)
- {
- var sql = $"delete from eapappservermac where EapAppserverID={id}";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- msg = "删除该APP服务器下的机台失败";
- return -1;
- }
- if (CurrDb.DeleteFor<EapAppserver>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- /// <summary>
- /// 获取机台下挂数量最少的AP服务器
- /// </summary>
- /// <param name="factoryId"></param>
- /// <returns></returns>
- public EapAppserver GetMacLeastServer(Machine mac)
- {
- if (mac.FCode.StartsWith("AA") && mac.FactoryId == 8)
- {
- return this.Get(8);
- }
- var sql = $@"select EapAppserverID from eapappservermac a
- inner join EapAppserver b on a.EapAppserverID=b.id
- where factoryid={mac.FactoryId} and b.id<>8
- group by EapAppserverID order by count(1) asc limit 0,1";
- var serverId = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- if (serverId > 0)
- {
- return this.Get(serverId);
- }
- return null;
- }
- }
- }
|