123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- using GDNXFD.Data.Model;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace GDNXFD.Data.Repositories
- {
- public class AdviceHistoryModelRepository
- {
- /// <summary>
- /// 查询计算结果历史数据
- /// </summary>
- /// <param name="filter">查询条件,长度为6的数组,数组索引1=开始时间,2=结束时间,3=风场编号,4=风机编号,5=建议操作类型,6=实际操作类型</param>
- /// <param name="pageIndex">页码</param>
- /// <param name="pageSize">分页尺寸</param>
- /// <param name="total">总数量</param>
- /// <returns></returns>
- public static IList<AdviceHistoryModel> GetHistoryList(string filter, int pageIndex, int pageSize, ref int total)
- {
- string[] conditionArr = filter.Split(',');
- DateTime? startTime = null;
- DateTime? endTime = null;
- string stationId = "";
- string windturbineId = "";
- OperateStyle? adviceSendType = null;
- OperateStyle? executeSendType = null;
- if (!string.IsNullOrEmpty(conditionArr[0]))
- startTime = DateTime.Parse(conditionArr[0]);
- if (!string.IsNullOrEmpty(conditionArr[1]))
- endTime = DateTime.Parse(conditionArr[1]);
- if (!string.IsNullOrEmpty(conditionArr[2]))
- stationId = conditionArr[2];
- if (!string.IsNullOrEmpty(conditionArr[3]))
- windturbineId = conditionArr[3];
- if (!string.IsNullOrEmpty(conditionArr[4]))
- adviceSendType = (OperateStyle)Convert.ToInt32(conditionArr[4]);
- if (!string.IsNullOrEmpty(conditionArr[5]))
- executeSendType = (OperateStyle)Convert.ToInt32(conditionArr[5]);
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- // IList<AdviceHistoryModel> lst = ctx.AdviceHistoryModel.Select(s => s).ToList();
- var r1 = ctx.AdviceHistoryModel.AsQueryable();
- if (startTime.HasValue && endTime.HasValue)
- r1 = r1.Where(s => s.LastUpdateTime > startTime && s.LastUpdateTime < endTime.Value);
- if (!string.IsNullOrEmpty(stationId))
- r1 = r1.Where(s => s.StationId == stationId);
- if (!string.IsNullOrEmpty(windturbineId))
- r1 = r1.Where(s => s.WindturbineId == windturbineId);
- if (adviceSendType.HasValue)
- r1 = r1.Where(s => s.AdviseOperation == adviceSendType.Value);
- if (executeSendType.HasValue)
- r1 = r1.Where(s => s.ExecuteOperation == executeSendType.Value);
- total = r1.Count();
- var results = r1.OrderByDescending(q => q.LastUpdateTime)
- .Skip(--pageIndex * pageSize)
- .Take(pageSize)
- .ToList();
- return results.ToList();
- }
- }
- public static void InsertHistory(IList<AdviceHistoryModel> list)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- for (int i = 0; i < list.Count; i++)
- {
- ctx.AdviceHistoryModel.Add(list[i]);
- ctx.SaveChanges();
- }
- }
- }
- /// <summary>
- /// 更新计算结果
- /// </summary>
- /// <param name="windturbineId">风机编号</param>
- /// <param name="userId">更新人,0为系统</param>
- /// <param name="userId">更新人姓名,0为系统</param>
- /// <param name="userActive">动作类型,2用户执行,3用户取消,4系统取消</param>
- public static void UpdateHistory(string windturbineId, string userId, string userName, int userActive)
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- //查找流水表中,风机编号,状态为未执行,实际执行时间为空的数据(理论上只有一条)
- AdviceHistoryModel m = ctx.AdviceHistoryModel.Where(s => s.WindturbineId == windturbineId && s.Status == 1 && s.ExecuteTime == null).FirstOrDefault();
- if (m == null)
- {
- return;
- }
- m.Status = userActive;
- m.ExecuteTime = DateTime.Now;
- m.Operater = userId;
- m.OperaterName = userName;
- if (userActive == 2)//如果是用户执行推荐动作
- {
- m.ExecuteOperation = m.AdviseOperation;
- }
- else // 系统取消,用户取消
- {
- m.ExecuteOperation = OperateStyle.Unknow;
- }
- ctx.Entry(m).State = System.Data.Entity.EntityState.Modified;
- ctx.SaveChanges();
- }
- }
- /// <summary>
- /// 将上次所有未执行的计算结果全部更新未系统取消
- /// </summary>
- public static void UpdateAllCalcResult()
- {
- try
- {
- using (GDNXFDDbContext ctx = new GDNXFDDbContext())
- {
- string sql = String.Format("update wisdom_calc_history set status=4,executetime=sysdate,operater=0,operatername='系统' where status=1");
- ctx.Database.ExecuteSqlCommand(sql, new object[] { });
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("123");
- }
-
- }
- }
- }
|