123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- using Cksoft.Data;
- using DllEapEntity;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace DllEapDal
- {
- public class HsmsQueueDal
- {
- private IDatabase CurrDb;
- public HsmsQueueDal(IDatabase db)
- {
- CurrDb = db;
- }
- public IEnumerable<HsmsQueue> Get(int start, int length, string order, string sort, string filter, string errorinfo)
- {
- var pros = CurrDb.FindListForCondition<HsmsQueue>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo);
- if (pros != null && pros.Count() > 0)
- {
- foreach (var item in pros)
- {
- var events = CurrDb.FindListForCondition<HsmsQueueEvent>($" and a.HsmsQueueID='{item.ID}' order by a.id", ref errorinfo);
- item.Events = events;
- }
- }
- return pros;
- }
- public int GetCount(string filter)
- {
- string errorinfo = string.Empty;
- var entities = CurrDb.FindListForCondition<HsmsQueue>(filter, ref errorinfo);
- if (entities != null)
- {
- return entities.Count();
- }
- return 0;
- }
- public HsmsQueue Get(int id)
- {
- string errorinfo = string.Empty;
- var pro = CurrDb.FindEntityFor<HsmsQueue>(id);
- if (pro != null)
- {
- var events = CurrDb.FindListForCondition<HsmsQueueEvent>($" and a.HsmsQueueID='{pro.ID}' order by a.id", ref errorinfo);
- pro.Events = events;
- }
- return pro;
- }
- /// <summary>
- /// 添加角色并返回角色Id
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <returns></returns>
- public int Add(HsmsQueue pro, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<HsmsQueue>($" and a.FName='{pro.FName}' ", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "队列已存在,请确认";
- return -1;
- }
- if (CurrDb.InsertFor<HsmsQueue>(pro, userCode) < 0)
- {
- errorinfo = "插入队列主表失败";
- return -1;
- }
- var sql = "select @@identity;";
- var id = Convert.ToInt32(CurrDb.FindList<string>(sql).FirstOrDefault() ?? "-1");
- if (pro.Events != null && pro.Events.Count() > 0)
- {
- foreach (var item in pro.Events)
- {
- var temp = new HsmsQueueEvent();
- temp.HsmsQueueID = id;
- temp.SVal = item.SVal;
- temp.FVal = item.FVal;
- temp.remark = item.remark;
- temp.rectime = temp.modtime = DateTime.Now;
- if (CurrDb.InsertFor(temp, userCode) < 0)
- {
- errorinfo = "插入队列子表失败";
- return -1;
- }
- }
- }
- return id;
- }
- /// <summary>
- /// 待优化 存在删除后不能
- /// </summary>
- /// <param name="role"></param>
- /// <param name="userCode"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int Update(HsmsQueue role, string userCode, ref string errorinfo)
- {
- var entities = CurrDb.FindListForCondition<HsmsQueue>($" and a.FName='{role.FName}' " +
- $"and a.ID<>{role.ID}", ref errorinfo);
- if (entities != null && entities.Count() > 0)
- {
- errorinfo = "已存在相同的队列,请确认";
- return -1;
- }
- if (CurrDb.UpdateFor(role, userCode) < 0)
- {
- return -1;
- }
- var sql = $"delete from HsmsQueueEvent where HsmsQueueID={role.ID}";
- if (CurrDb.ExecuteBySql(sql) < 0)
- {
- return -1;
- }
- if (role.Events != null && role.Events.Count() > 0)
- {
- foreach (var item in role.Events)
- {
- var temp = new HsmsQueueEvent();
- temp.HsmsQueueID = role.ID;
- temp.SVal = item.SVal;
- temp.FVal = item.FVal;
- temp.remark = item.remark;
- temp.rectime = temp.modtime = DateTime.Now;
- if (CurrDb.InsertFor(temp, userCode) < 0)
- {
- errorinfo = "插入队列子表失败";
- return -1;
- }
- }
- }
- return role.ID;
- }
- public int Delete(int id, ref string msg)
- {
- if (CurrDb.DeleteFor<HsmsQueue>(id) < 0)
- {
- msg = "删除失败";
- return -1;
- }
- msg = string.Empty;
- return 1;
- }
- public IEnumerable<HsmsQueueEvent> GetQueueEvents(string filter, ref string errorinfo)
- {
- return CurrDb.FindListForCondition<HsmsQueueEvent>(filter + " order by a.id", ref errorinfo);
- }
- }
- }
|