12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622 |
- using Cksoft.Data;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using DllEapEntity.Dtos;
- using DllEapEntity.OFILM;
- using System.Linq;
- using System.Data;
- using DllEapEntity;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using ChartDto = DllEapEntity.OFILM.ChartDto;
- using Cksoft.Data.Repository;
- namespace DllEapDal.OFILM
- {
- public class MacRunDataDal
- {
- private readonly string timeFormat = "yyyy-MM-dd HH:mm:ss";
- private IDatabase CurrDb = null;
- public MacRunDataDal(IDatabase db)
- {
- CurrDb = db;
- }
-
- public DataTable GetMacRunDatas(DateTime startTime, DateTime endTime, string filter, int start, int length, ref string errorinfo,
- out IEnumerable<Machine> machines, out int total)
- {
- var hours = Convert.ToInt32(Math.Ceiling((endTime - startTime).TotalHours));
- var machineDal = new MachineDal(CurrDb);
- var list = new List<MacRunDataDto>();
- var dt = new DataTable();
- var macFilter = filter?.Replace("c.", "a.");
- total = machineDal.GetCount(macFilter);
- var macs = machineDal.Get(start, length, "asc", "a.FCode", macFilter,ref errorinfo);
- machines = macs;
- var timeSpan = (endTime - startTime).TotalSeconds;
- if (macs != null && macs.Count() > 0)
- {
- var macIdFilter = $" and b.macid in ({string.Join(",", macs.Select(c => c.ID))})";
- var alarmCodeFilter = $" and a.McaCode in ({string.Join(",", macs.Select(c => $"'{c.FCode}'"))})";
- var statusFilter = $" and a.MacCode in ({string.Join(",", macs.Select(c => $"'{c.FCode}'"))})";
- var sql = $@"SELECT
- IFNULL(sum(a.FCount),0) Count,IFNULL(sum(a.FCount),0) IntCount,Year(b.edate) year,Month(b.edate) month,DAY(b.edate) DAY,HOUR(b.EDate) Hour,
- b.MacID MacId
- FROM
- maccountdetail a
- LEFT JOIN maccountmst b ON a.mstid = b.id
- LEFT JOIN machine c on b.macid=c.id
- WHERE
- a.typeID = 0
- AND a.ParamCode = 'S00026'
- {macIdFilter}
- AND b.EDate BETWEEN '{startTime.ToString(timeFormat)}'
- AND '{endTime.ToString(timeFormat)}'
- GROUP BY b.MacID,Year(b.Edate),Month(b.EDate),DAY(b.Edate),HOUR(b.EDate);";
- var outputDtos = CurrDb.FindList<HourCount>(sql).ToList();
- #region
- // sql = $@"SELECT
- //count(1) IntCount, Year(a.stime) Year,Month(a.stime) Month,DAY(a.stime) DAY,HOUR(a.stime) Hour,
- // sum(flen) TimeLen,maccode MacCode,StatusID
- //FROM
- // macstatus a
- // LEFT JOIN machine c ON a.MacCode = c.fcode
- //WHERE
- // 1=1
- // AND a.stime>='{startTime.ToString(timeFormat)}'
- // AND a.stime<='{endTime.ToString(timeFormat)}'
- // {statusFilter}
- // AND StatusID = 6
- // GROUP BY maccode,Year(a.stime),Month(a.stime),DAY(a.stime),HOUR(a.stime),StatusID";
- // var alarmDtos = CurrDb.FindList<HourCount>(sql);
- // sql = $@"SELECT
- //count(1) IntCount, Year(a.stime) Year,Month(a.stime) Month,DAY(a.stime) DAY,HOUR(a.stime) Hour,
- // sum(flen) TimeLen,maccode MacCode,StatusID
- //FROM
- // macstatus a
- //WHERE
- // a.stime>='{startTime.ToString(timeFormat)}'
- // AND a.stime<='{endTime.ToString(timeFormat)}'
- // {statusFilter}
- // AND StatusID in (4,3,6)
- // GROUP BY maccode,Year(a.stime),Month(a.stime),DAY(a.stime),HOUR(a.stime),StatusID";
- #endregion
- sql = $@"SELECT
- count(1) IntCount, Year(a.stime) Year,Month(a.stime) Month,DAY(a.stime) DAY,HOUR(a.stime) Hour,
- sum(flen) TimeLen,maccode MacCode,StatusID
- FROM
- (select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime>='{startTime.ToString(timeFormat)}'
- AND t.stime<='{endTime.ToString(timeFormat)}' and StatusID=4
- union all
- select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime>='{startTime.ToString(timeFormat)}'
- AND t.stime<='{endTime.ToString(timeFormat)}' and StatusID=3
- union all
- select t.stime,t.statusid,t.maccode,if(flen=0,0.01,flen) flen from macstatus t
- where 1=1
- AND t.stime>='{startTime.ToString(timeFormat)}'
- AND t.stime<='{endTime.ToString(timeFormat)}' and StatusID=6 )
- a
- WHERE
- 1=1
- {statusFilter}
- GROUP BY maccode,Year(a.stime),Month(a.stime),DAY(a.stime),HOUR(a.stime),StatusID";
- var statusDtos = CurrDb.FindList<HourCount>(sql);
- #region
- ////var dic = new Dictionary<DateTime, DateTime>();
- ////for (var k = 0; k < hours; k++)
- ////{
- //// var date = startTime.AddHours(k);
- //// var endDate = date.AddHours(1);
- //// dic.Add(date, endDate);
- ////}
- ////StringBuilder firstSb = new StringBuilder();
- ////StringBuilder lastSb = new StringBuilder();
- //sql = $" ";
- //var baseSql = $"(select * from macstatus t where stime>='{startTime.AddMinutes(-10).ToString(timeFormat)}' " +
- // $" and t.etime<='{endTime.AddMinutes(10).ToString(timeFormat)}' and t.Flen>0)";
- //baseSql = $" macstatus ";
- //IList<string> allFirstsSqls = new List<string>();
- //var allLastsSqls = new List<string>();
- //if (dic != null && dic.Keys.Count > 0)
- //{
- // foreach (var item in dic)
- // {
- // //sql = $" select a.stime,a.etime,a.maccode,a.statusid,a.flen from {baseSql} a " +
- // // $"where a.stime<'{item.Key.ToString(timeFormat)}' and a.etime>'{item.Key.ToString(timeFormat)}' " +
- // // $"";
- // //allFirstsSqls.Add(sql);
- // //sql = $" select a.stime,a.etime,a.maccode,a.statusid,a.flen from {baseSql} a " +
- // // $"where a.stime<'{item.Value.ToString(timeFormat)}' and a.etime>'{item.Value.ToString(timeFormat)}' " +
- // // $"";
- // //allLastsSqls.Add(sql);
- // firstSb.Append($@" (a.stime<'{item.Key.ToString(timeFormat)}' and a.etime>'{item.Key.ToString(timeFormat)}') or ");
- // lastSb.Append($@" (a.stime<'{item.Value.ToString(timeFormat)}' and a.etime>'{item.Value.ToString(timeFormat)}') or ");
- // }
- // firstSb = firstSb.Remove(firstSb.Length - 3, 3);
- // lastSb = lastSb.Remove(lastSb.Length - 3, 3);
- //}
- //var allFirstSql = string.Join(" union all ", allFirstsSqls);
- //var allLastSql = string.Join(" union all ", allLastsSqls);
- //var allFirsts = CurrDb.FindList<MacStatus>($"select a.stime,a.etime,a.maccode,a.statusid,a.flen from ({allFirstSql}) a where 1=1 {statusFilter}");
- #endregion
- sql = $@"select * from macstatus a where
- a.etime>'{startTime.AddMinutes(-5).ToString(timeFormat)}'
- and a.stime<'{endTime.AddMinutes(5).ToString(timeFormat)}'
- and a.FLen>0
- and (day(a.stime)<>day(a.etime) or hour(a.stime)<>hour(a.etime))
- ";
- var macCodes = machines.Select(c => c.FCode).ToList();
- // var allFirsts = CurrDb.FindList<MacStatus>(sql);
- var allFirsts = CurrDb.FindList<MacStatus>(sql).Where(c => macCodes.Contains(c.MacCode)).ToList();
- // var allFirsts = CurrDb.FindList<MacStatus>($"select tt.stime,tt.etime,tt.maccode,tt.statusid,tt.flen from ({allFirstSql}) tt left join machine b on tt.maccode=b.fcode where 1=1 {macIdFilter}");
- // var allFirsts = CurrDb.FindListForCondition<MacStatus>($" {statusFilter} and ({firstSb.ToString()}) and a.flen>0", ref errorinfo);
- // var allLasts = CurrDb.FindList<MacStatus>($"select a.stime,a.etime,a.maccode,a.statusid,a.flen from ({allLastSql}) a where 1=1 ");
- //var alllasts = CurrDb.FindListForCondition<MacStatus>($" {statusFilter} and ({lastSb.ToString()}) and a.flen>0", ref errorinfo);
- #region 异步
- Parallel.For(0, hours, i =>
- {
- var date = startTime.AddHours(i);
- var endDate = date.AddHours(1);
- //var firsts = CurrDb.FindListForCondition<MacStatus>($" {statusFilter} and " +
- // $" a.stime<'{date.ToString(timeFormat)}' and a.etime>'{date.ToString(timeFormat)}'",
- // ref errorinfo);
- //var lasts = CurrDb.FindListForCondition<MacStatus>($" {statusFilter} and " +
- // $" a.stime<'{endDate.ToString(timeFormat)}' and a.etime>'{endDate.ToString(timeFormat)}'",
- // ref errorinfo);
- var firsts = allFirsts.Where(c => c.STime < date && c.ETime > date).ToList();
- var lasts = allFirsts.Where(c => c.STime < endDate && c.ETime > endDate).ToList();
- var hoursDtos = statusDtos.Where(c => c.Year == date.Year && c.Month == date.Month && c.Day == date.Day &&
- c.Hour == date.Hour);
- Parallel.For(0, hoursDtos.Count(), (j) =>
- {
- var dto = hoursDtos.ElementAt(j);
- var first = firsts.FirstOrDefault(c => c.MacCode == dto.MacCode && c.StatusID == dto.StatusId
- && c.STime < date && c.ETime > date);
- if (first != null)
- {
- dto.TimeLen += (first.ETime - date).TotalSeconds;
- }
- var last = lasts.FirstOrDefault(c => c.MacCode == dto.MacCode && c.StatusID == dto.StatusId
- && c.STime < endDate && c.ETime > endDate);
- if (last != null)
- {
- dto.TimeLen -= (last.ETime - endDate).TotalSeconds;
- }
- });
- });
- #endregion
- #region 同步
- //for (int i = 0; i < hours; i++)
- //{
- // var date = startTime.AddHours(i);
- // var endDate = date.AddHours(1);
- // //var firsts = CurrDb.FindListForCondition<MacStatus>($" {statusFilter} and " +
- // // $" a.stime<'{date.ToString(timeFormat)}' and a.etime>'{date.ToString(timeFormat)}'",
- // // ref errorinfo);
- // //var lasts = CurrDb.FindListForCondition<MacStatus>($" {statusFilter} and " +
- // // $" a.stime<'{endDate.ToString(timeFormat)}' and a.etime>'{endDate.ToString(timeFormat)}'",
- // // ref errorinfo);
- // var firsts = allFirsts.Where(c => c.STime < date && c.ETime > date).ToList();
- // var lasts = allFirsts.Where(c => c.STime < endDate && c.ETime > endDate).ToList();
- // var hoursDtos = statusDtos.Where(c => c.Year == date.Year && c.Month == date.Month && c.Day == date.Day &&
- // c.Hour == date.Hour);
- // var totalCount = hoursDtos.Count();
- // for (var j = 0; j < hoursDtos.Count(); j++)
- // {
- // var dto = hoursDtos.ElementAt(j);
- // var first = firsts.FirstOrDefault(c => c.MacCode == dto.MacCode && c.StatusID == dto.StatusId
- // && c.STime < date && c.ETime > date);
- // if (first != null)
- // {
- // dto.TimeLen += (first.ETime - date).TotalSeconds;
- // }
- // var last = lasts.FirstOrDefault(c => c.MacCode == dto.MacCode && c.StatusID == dto.StatusId
- // && c.STime < endDate && c.ETime > endDate);
- // if (last != null)
- // {
- // dto.TimeLen -= (last.ETime - endDate).TotalSeconds;
- // }
- // }
- //}
- #endregion
- var rowStrings = new string[] { "产量", "稼动率", "待机率", "故障率", "故障次数", "故障时长" };
- dt.Columns.Add("园区");
- dt.Columns.Add("楼层");
- dt.Columns.Add("制程代码");
- dt.Columns.Add("设备类型");
- dt.Columns.Add("设备ID");
- dt.Columns.Add("ModelRowSpan");
- dt.Columns.Add("MacRowSpan");
- //dt.Columns.Add("FactroyNameRowSpan");
- dt.Columns.Add("指标");
- dt.Columns.Add("汇总");
- for (int i = 0; i < hours; i++)
- {
- var currTime = startTime.AddHours(i);
- var date = currTime.ToString("yyyy-MM-dd HH:00:00");
- dt.Columns.Add(date);
- }
- foreach (var mac in macs)
- {
- AppendOutPutDataRow(outputDtos, mac, "产量", dt);
- AppendRunDataRow(statusDtos.Where(c => c.StatusId == 4), mac, "稼动率", 4, dt, timeSpan, startTime, endTime);
- AppendRunDataRow(statusDtos.Where(c => c.StatusId == 3), mac, "待机率", 3, dt, timeSpan, startTime, endTime);
- AppendAlarmRateDataRow(statusDtos.Where(c => c.StatusId == 6), mac, "故障率", dt, "RATE", timeSpan, startTime, endTime);
- AppendAlarmRateDataRow(statusDtos.Where(c => c.StatusId == 6), mac, "故障次数", dt, "COUNT", timeSpan, startTime, endTime);
- AppendAlarmRateDataRow(statusDtos.Where(c => c.StatusId == 6), mac, "故障时长", dt, "TIME", timeSpan, startTime, endTime);
- }
- var modelGroups = macs.GroupBy(c => c.MModeCode);
- IList<string> codes = new List<string>();
- foreach (var model in modelGroups)
- {
- for (var i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows[i]["设备类型"].ToString() == model.Key)
- {
- dt.Rows[i]["ModelRowSpan"] = model.Count() * 6;
- //dt.Rows[i]["FactroyNameRowSpan"] = model.Count() * 6;
- }
- dt.Rows[i]["MacRowSpan"] = 6;
- }
- }
- // else if (colName == "园区")
- //{
- // row[colName] = mac.FactoryName;
- //}
- //else if (colName == "楼层")
- //{
- // row[colName] = mac.FloorName;
- //}
- //else if (colName == "制程代码")
- //{
- // row[colName] = mac.PCode;
- //}
- }
- return dt;
- }
- public DataTable getDT(int hours, DateTime startTime )
- {
- DataTable dt = new DataTable();
- dt.Columns.Add("园区");
- dt.Columns.Add("楼层");
- dt.Columns.Add("制程代码");
- dt.Columns.Add("设备类型");
- dt.Columns.Add("设备ID");
- dt.Columns.Add("ModelRowSpan");
- dt.Columns.Add("MacRowSpan");
- //dt.Columns.Add("FactroyNameRowSpan");
- dt.Columns.Add("指标");
- dt.Columns.Add("汇总");
- for (int i = 0; i < hours; i++)
- {
- var currTime = startTime.AddHours(i);
- var date = currTime.ToString("yyyy-MM-dd HH:00:00");
- dt.Columns.Add(date);
- }
- return dt;
- }
- /* public LayuiModel<CountTotal> GetCountWeek(DateTime startTime, DateTime endTime, string filter, int pageIndex, int pageSize, out int total)
- {
- var time = Convert.ToDateTime("2022-03-03 14:00:00");
- if (endTime < time)
- {
- return GetWeekNew(startTime, endTime, filter, pageIndex, pageSize, out total);
- }
- else if (startTime >= time)
- {
- return GetWeekNew(startTime, endTime, filter, pageIndex, pageSize, out total);
- }
- else
- {
- return GetWeekMix(GetWeekOld(startTime, endTime, filter, pageIndex, pageSize, out total), GetWeekNew(startTime, endTime, filter, pageIndex, pageSize, out total), startTime, endTime);
- }
- }*/
- private LayuiModel<CountTotal> GetWeekMix(LayuiModel<CountTotal> layuiModel1, LayuiModel<CountTotal> layuiModel2, DateTime startTime, DateTime endTime)
- {
- throw new NotImplementedException();
- }
- public LayuiModel<CountTotal> GetCountWeek(DateTime startTime, DateTime endTime, string filter, int pageIndex, int pageSize, out int total)
- {
- ChartDto dto = new ChartDto();
- var data = new List<OutPutTimeInfo>();
- var time = Convert.ToDateTime("2022-03-03 14:00:00");
-
- var rowStrings = new string[] { "产量", "稼动率", "待机率", "故障率", "故障次数", "故障时长" };
- /* string condition = $@" and date_add(a.day,interval a.`Hour` hour)>='{startTime.ToString("yyyy-MM-dd HH:mm:ss")}' and date_add(a.day,interval a.`Hour` hour)<'{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' " + filter;
- */ int start = (pageIndex - 1) * pageSize + 1;
- int end = start + pageSize;
- var mac = GetMac(filter, out total);
-
- if (endTime < time)
- {
- data = GetDataDel(startTime, endTime, mac).ToList();
- }
- else if (startTime >= time)
- {
- data = GetDataDel(startTime, endTime, mac).ToList();
- }
- else
- {
- data = GetDataDel(startTime, time, mac).ToList();
- data.AddRange(GetDataDel(time, endTime, mac).ToList());
- }
- List<CountTotal> list = new List<CountTotal>();
- List<IndexDatas> count = new List<IndexDatas>();
- count = SetTotal(data, rowStrings);
- Parallel.Invoke(() => { dto = SetCharDto(count); }, () => {
- list.Add(new CountTotal()
- {
- Factory = "汇总",
- Datas = count
- });
- });
- for (int i = start-1; i < end&&i<total; i++)
- {
- var item = mac[i];
- var datas = data.Where(c => c.MacID == item.MacID).ToList();
- if (datas==null||datas.Count<1)
- {
- continue;
- }
- list.Add(new CountTotal()
- {
- Factory = item.Factory,
- Floor = item.Floor,
- PCode = item.PCode,
- Model = item.MModelCode,
- FCode = item.MacCode,
- Datas = SetTotal(datas, rowStrings)
- });
- }
- return new LayuiModel<CountTotal>()
- {
- code = 1,
- data = list,
- count = total,
- extraObject = dto
- };
- }
- private List<OutPutTimeInfo> GetMac(string filter, out int total)
- {
- string table = $@" machine c
- LEFT OUTER JOIN macmodel d ON c.MModeID = d.id
- LEFT OUTER JOIN factoryregion e ON c.FactoryId = e.id
- LEFT OUTER JOIN mactprocess f ON c.id = f.macid
- LEFT OUTER JOIN tprocess g ON f.PCode = g.FCode
- LEFT OUTER JOIN factoryregion j ON c.RegionId = j.id
- LEFT OUTER JOIN factoryregion k ON j.ParentId = k.id
- LEFT OUTER JOIN factoryregion l ON k.ParentId = l.id";
- string select = $@"e.FName Factory,k.FName Floor,g.FCode PCode,d.FCode MModelCode,c.FCode MacCode,c.ID MacID";
- total = Convert.ToInt32(CurrDb.FindObject($@"select count(*) from {table} where 1=1 {filter}"));
- return CurrDb.FindList<OutPutTimeInfo>($"select {select} from {table} where 1=1 {filter} order by c.Fcode").ToList();
- }
- private ChartDto SetCharDto(List<IndexDatas> count)
- {
- ChartDto dto = new ChartDto()
- {
- LegendData = new List<string>()
- {
- "产量","稼动率","待机率","故障率","故障次数","故障时长"
- },
- XData = new List<string>(),
- };
- List<decimal> y1 = new List<decimal>(), y2 = new List<decimal>(), y3 = new List<decimal>(), y4 = new List<decimal>(), y5 = new List<decimal>(), y6 = new List<decimal>();
- for (int i = 0; i < 24; i++)
- {
- dto.XData.Add(i.ToString("00") + ":00:00");
- y1.Add(Convert.ToDecimal(count[0].data[i]));
- y2.Add(Convert.ToDecimal(count[1].data[i].Replace("%","")));
- y3.Add(Convert.ToDecimal(count[2].data[i].Replace("%", "")));
- y4.Add(Convert.ToDecimal(count[3].data[i].Replace("%", "")));
- y5.Add(Convert.ToDecimal(count[4].data[i]));
- y6.Add(Convert.ToDecimal(count[5].data[i]));
- }
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "产量", YAxis = 0, Type = "line", Data = y1});
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "稼动率", YAxis = 1, Type = "line", Data = y2 });
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "待机率", YAxis = 1, Type = "line", Data = y3 });
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "故障率", YAxis = 1, Type = "line", Data = y4 });
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "故障次数", YAxis = 0, Type = "line", Data = y5 });
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "故障时长", YAxis = 0, Type = "line", Data = y6 });
- return dto;
- }
- /* private List<IndexDatas> SetData(List<OutPutTimeInfo> datas, string[] rowStrings)
- {
- var data = datas.GroupBy(c => c.Hour).OrderBy(a => a.Key);
- CountTotal count = new CountTotal()
- {
- Factory = datas[0].Factory,
- Floor=datas[0].Floor,
- PCode=datas[0].PCode,
- Model=datas[0].MModelCode,
- FCode=datas[0].MacCode
- };
- }*/
- private List<IndexDatas> SetTotal(IEnumerable<OutPutTimeInfo> datas, string[] rowStrings)
- {
- var data = datas.GroupBy(c => c.Hour).OrderBy(a => a.Key);
- /* List<string> str = new List<string>() { "稼动率", "待机率", "故障率" };*/
- List<IndexDatas> count = new List<IndexDatas>();
- foreach (var item in rowStrings)
- {
- count.Add(new IndexDatas()
- {
- Index = item
- });
- }
- foreach (var item in data)
- {
- var da = datas.Where(c => c.Hour == item.Key);
- var t1 = da.Sum(c => c.RunTime);
- var t2 = da.Sum(c => c.StandbyTime);
- var t3 = da.Sum(c => c.AlarmTime);
- foreach (var items in count)
- {
- if (items.Index==rowStrings[0])
- {
- items.data.Add(da.Sum(c => c.Count).ToString());
- }
- if (items.Index == rowStrings[1])
- {
- items.data.Add((Math.Round(t1/(t1+t2+t3),4)*100).ToString()+"%");
- }
- if (items.Index==rowStrings[2])
- {
- items.data.Add((Math.Round(t2 / (t1 + t2 + t3), 4) * 100).ToString() + "%");
- }
- if (items.Index == rowStrings[3])
- {
- items.data.Add((Math.Round(t3 / (t1 + t2 + t3), 4) * 100).ToString() + "%");
- }
- if (items.Index == rowStrings[4])
- {
- items.data.Add(da.Sum(c => c.AlarmCount).ToString());
- }
- if (items.Index == rowStrings[5])
- {
- items.data.Add(Math.Round(da.Sum(c => c.AlarmTime)/60,2).ToString());
- }
- }
- }
- return count;
- }
- private IEnumerable<OutPutTimeInfo> GetDataDel(DateTime startTime, DateTime endTime, List<OutPutTimeInfo> mac)
- {
- var time = Convert.ToDateTime("2022-03-03 14:00:00");
- if (startTime>=time)
- {
- string condition = $@" and date_add(day,interval `Hour` hour)>='{startTime.ToString("yyyy-MM-dd HH:mm:ss")}' and date_add(day,interval `Hour` hour)<'{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' ";
- condition += $" and macid in ({string.Join(",", mac.Select(c => c.MacID))})";
- string sql = $@" select macid MacID,`Hour` Hour,SUM(RunTime) RunTime,SUM(StandbyTime) StandbyTime,SUM(AlarmTime) AlarmTime,SUM(AlarmCount) AlarmCount,SUM(Count) Count
- from outputtime where 1=1 {condition} GROUP BY macid, hour HAVING RunTime+AlarmTime+StandbyTime>0 ";
- var data= CurrDb.FindList<OutPutTimeInfo>(sql);
- foreach (var item in data)
- {
- var machine = mac.Where(c => c.MacID == item.MacID).FirstOrDefault();
- item.MacCode = machine.MacCode;
- item.Factory = machine.Factory;
- item.Floor = machine.Floor;
- item.PCode = machine.PCode;
- item.MModelCode = machine.MModelCode;
- }
- return data;
- }
- else if (endTime<=time)
- {
- string str = $" and b.macid in ({string.Join(",", mac.Select(c => c.MacID))})";
- string str1 = $"and MacCode in ({string.Join(",", mac.Select(c => $"'{c.MacCode}'"))})";
- List<OutPutTimeInfo> data = new List<OutPutTimeInfo>();
- List<HourCount> Tstatus = new List<HourCount>();
- Parallel.Invoke(() =>
- {
- string sqql = $@" SELECT
- count(1) IntCount, HOUR(a.stime) Hour,StatusID,
- sum(flen) TimeLen,maccode MacCode
- FROM
- (select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=4 {str1}
- union all
- select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >='{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=3 {str1}
- union all
- select t.stime,t.statusid,t.maccode,if(flen=0,0.01,flen) flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=6 {str1})
- a
- WHERE
- 1=1
-
- GROUP BY HOUR(a.stime),StatusID,maccode ";
- Tstatus = CurrDb.FindList<HourCount>(sqql).ToList();
- }, () =>
- {
- using(IDatabase db = DbFactory.Base("eapslave")){
- string sql = $@"SELECT IFNULL( sum( a.FCount ), 0 ) Count,IFNULL( sum( a.FCount ), 0 ) IntCount,HOUR ( b.EDate ) HOUR,b.MacID MacID
- FROM
- maccountdetail a
- LEFT JOIN maccountmst b ON a.mstid = b.id
- LEFT JOIN machine c ON b.macid = c.id
- WHERE
- a.typeID = 0
- AND a.ParamCode = 'S00026'
- AND b.EDate BETWEEN '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' {str}
- GROUP BY HOUR ( b.EDate ),b.MacID ";
- data = db.FindList<OutPutTimeInfo>(sql).ToList();
- }
- });
- foreach (var item in data)
- {
- var machine = mac.Where(c => c.MacID == item.MacID).FirstOrDefault();
- item.MacCode = machine.MacCode;
- item.Factory = machine.Factory;
- item.Floor = machine.Floor;
- item.PCode = machine.PCode;
- item.MModelCode = machine.MModelCode;
- Parallel.Invoke(
- () => {
- var x = Tstatus.Where(c => c.MacCode == item.MacCode && c.Hour == item.Hour && c.StatusId == 4).FirstOrDefault();
- item.RunTime = x != null ? x.TimeLen : 0;
- },
- () => {
- var x = Tstatus.Where(c => c.MacCode == item.MacCode && c.Hour == item.Hour && c.StatusId == 3).FirstOrDefault();
- item.StandbyTime = x != null ? x.TimeLen : 0;
- },
- () => {
- var x = Tstatus.Where(c => c.MacCode == item.MacCode && c.Hour == item.Hour && c.StatusId == 6).FirstOrDefault();
- item.AlarmTime = x != null ? x.TimeLen : 0;
- item.AlarmCount = x!= null ?Convert.ToInt32( x.IntCount) : 0;
- }
- );
- }
- return data;
- }
- return new List<OutPutTimeInfo>();
- }
-
- /// <summary>
- /// 产量按24小时统计的时间段在2022-03-03 14:00:00之前的数据处理
- /// </summary>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="filter"></param>
- /// <param name="pageIndex"></param>
- /// <param name="pageSize"></param>
- /// <param name="total"></param>
- /// <returns></returns>
- public LayuiModel<CountTotal> GetWeekOld(DateTime startTime, DateTime endTime, string filter, int pageIndex, int pageSize, out int total)
- {
- int start = (pageIndex - 1) * pageSize + 1;
- int end = start + pageSize;
- total = 1;
- var machineDal = new MachineDal(CurrDb);
- var list = new List<MacRunDataDto>();
- string errorinfo = "";
- var macFilter = filter?.Replace("c.", "a.");
- total += machineDal.GetCount(macFilter);
- var macs = machineDal.Get(start, end, "asc", "a.FCode", macFilter, ref errorinfo);
- List<CountTotal> tests = new List<CountTotal>();
- ChartDto dto = new ChartDto();
- if (string.IsNullOrEmpty(filter))
- {
- tests.Add(GetTotal(startTime, endTime, "", "", out dto));
- }
- else
- {
- var mac = machineDal.Get(1, total, "asc", "a.FCode", macFilter, ref errorinfo);
- if (mac != null && mac.Count() > 0)
- {
- var macIdFilter = $" and b.macid in ({string.Join(",", mac.Select(c => c.ID))})";
- /*var alarmCodeFilter = $" and a.McaCode in ({string.Join(",", macs.Select(c => $"'{c.FCode}'"))})";*/
- var statusFilter = $" and a.MacCode in ({string.Join(",", mac.Select(c => $"'{c.FCode}'"))})";
- tests.Add(GetTotal(startTime, endTime, macIdFilter, statusFilter, out dto));
- }
- }
- if (macs != null && macs.Count() > 0)
- {
- var macIdFilter = $" and b.macid in ({string.Join(",", macs.Select(c => c.ID))})";
- /*var alarmCodeFilter = $" and a.McaCode in ({string.Join(",", macs.Select(c => $"'{c.FCode}'"))})";*/
- var statusFilter = $" and a.MacCode in ({string.Join(",", macs.Select(c => $"'{c.FCode}'"))})";
- tests.AddRange(GetDatas(macs, startTime, endTime, macIdFilter, statusFilter));
- }
- return new LayuiModel<CountTotal>()
- {
- code = 1,
- data = tests,
- count = total,
- extraObject = dto
- };
- }
- /// <summary>
- /// 产量按24小时统计的单机台数据处理
- /// </summary>
- /// <param name="macs"></param>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="macFilter"></param>
- /// <param name="statusFilter"></param>
- /// <returns></returns>
- private IEnumerable<CountTotal> GetDatas(IEnumerable<Machine> macs, DateTime startTime, DateTime endTime, string macFilter, string statusFilter)
- {
- string sql = $@" SELECT
- IFNULL(sum(a.FCount),0) Count,IFNULL(sum(a.FCount),0) IntCount,HOUR(b.EDate) Hour, b.MacID MacId
-
- FROM
- maccountdetail a
- LEFT JOIN maccountmst b ON a.mstid = b.id
- LEFT JOIN machine c on b.macid=c.id
- WHERE
- a.typeID = 0
- AND a.ParamCode = 'S00026'
- {macFilter}
- AND b.EDate BETWEEN '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- GROUP BY HOUR(b.EDate), b.MacID";
- var TCount = CurrDb.FindList<HourCount>(sql);
- sql = $@" SELECT
- count(1) IntCount, HOUR(a.stime) Hour,
- sum(flen) TimeLen,maccode MacCode
- FROM
- (select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=4
- union all
- select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=3
- union all
- select t.stime,t.statusid,t.maccode,if(flen=0,0.01,flen) flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=6 )
- a
- WHERE
- 1=1
- {statusFilter}
- GROUP BY HOUR(a.stime),maccode";
- var Time = CurrDb.FindList<HourCount>(sql);
- sql = $@" SELECT
- count(1) IntCount, HOUR(a.stime) Hour,StatusID,
- sum(flen) TimeLen,maccode MacCode
- FROM
- (select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=4
- union all
- select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >='{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=3
- union all
- select t.stime,t.statusid,t.maccode,if(flen=0,0.01,flen) flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=6 )
- a
- WHERE
- 1=1
- {statusFilter}
- GROUP BY HOUR(a.stime),StatusID,maccode";
- var TStatus = CurrDb.FindList<HourCount>(sql);
- List <CountTotal> data = new List<CountTotal>();
- foreach (var item in macs)
- {
- var Sam = new CountTotal()
- {
- Factory = item.FactoryName,
- Floor = item.FloorName,
- PCode = item.PCode,
- Model = item.MModeCode,
- FCode = item.FCode
- };
-
- var x1 = new IndexDatas()
- {
- Index = "产量"
- };
- var x2 = new IndexDatas()
- {
- Index = "稼动率"
- };
- var x3 = new IndexDatas()
- {
- Index = "待机率"
- };
- var x4 = new IndexDatas()
- {
- Index = "故障率"
- };
- var x5 = new IndexDatas()
- {
- Index = "故障次数"
- };
- var x6 = new IndexDatas()
- {
- Index = "故障时长"
- };
-
- for (int i = 0; i <24; i++)
- {
- var a = TCount.Where(c => c.Hour == i && c.MacId == item.ID)?.FirstOrDefault()?.Count;
- a = a != null ? a : "0";
- var b = TStatus.Where(c => c.MacCode == item.FCode && c.Hour == i && c.StatusId == 4)?.FirstOrDefault()?.TimeLen;
- b = b != null ? b : 0;
- var d = Time.Where(c => c.MacCode == item.FCode && c.Hour == i)?.FirstOrDefault()?.TimeLen;
- d = d != null ? d : 1;
- var e = TStatus.Where(c => c.MacCode == item.FCode && c.Hour == i && c.StatusId == 3)?.FirstOrDefault()?.TimeLen;
- e = e != null ? e : 0;
- var f = TStatus.Where(c => c.MacCode == item.FCode && c.Hour == i && c.StatusId == 6)?.FirstOrDefault()?.TimeLen;
- f = f != null ? f : 0;
- var g= TStatus.Where(c => c.MacCode == item.FCode && c.Hour == i && c.StatusId == 6)?.FirstOrDefault()?.IntCount;
- g = g != null ? g : 0;
- x1.data.Add(a);
- x2.data.Add(Math.Round(b.Value / d.Value * 100, 2).ToString()+"%");
- x3.data.Add(Math.Round(e.Value / d.Value * 100, 2).ToString()+"%");
- x4.data.Add(Math.Round(f.Value / d.Value * 100, 2).ToString()+"%");
- x5.data.Add(g.Value.ToString());
- x6.data.Add(Math.Round(f.Value / 60, 2).ToString());
-
- }
- Sam.Datas.Add(x1); Sam.Datas.Add(x2); Sam.Datas.Add(x3); Sam.Datas.Add(x4); Sam.Datas.Add(x5); Sam.Datas.Add(x6);
- data.Add(Sam);
- }
- return data;
- }
- /// <summary>
- /// 产量按24小时统计的汇总数据处理
- /// </summary>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="filter1"></param>
- /// <param name="filter"></param>
- /// <param name="dtos"></param>
- /// <returns></returns>
- public CountTotal GetTotal(DateTime startTime, DateTime endTime, string filter1,string filter,out ChartDto dtos)
- {
- try
- {
- #region 获取数据
- string sql = $@" SELECT
- IFNULL(sum(a.FCount),0) Count,IFNULL(sum(a.FCount),0) IntCount,HOUR(b.EDate) Hour
-
- FROM
- maccountdetail a
- LEFT JOIN maccountmst b ON a.mstid = b.id
- LEFT JOIN machine c on b.macid=c.id
- WHERE
- a.typeID = 0
- AND a.ParamCode = 'S00026'
- {filter1}
- AND b.EDate BETWEEN '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- GROUP BY HOUR(b.EDate)";
- var TCount = CurrDb.FindList<HourCount>(sql);
- sql = $@" SELECT
- count(1) IntCount, HOUR(a.stime) Hour,
- sum(flen) TimeLen
- FROM
- (select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=4
- union all
- select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=3
- union all
- select t.stime,t.statusid,t.maccode,if(flen=0,0.01,flen) flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=6 )
- a
- WHERE
- 1=1
- {filter}
- GROUP BY HOUR(a.stime)";
- var Time = CurrDb.FindList<HourCount>(sql);
- sql = $@" SELECT
- count(1) IntCount, HOUR(a.stime) Hour,StatusID,
- sum(flen) TimeLen
- FROM
- (select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=4
- union all
- select t.stime,t.statusid,t.maccode,t.flen from macstatus t
- where 1=1
- AND t.stime >='{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=3
- union all
- select t.stime,t.statusid,t.maccode,if(flen=0,0.01,flen) flen from macstatus t
- where 1=1
- AND t.stime >= '{startTime.ToString("yyyy-MM-dd HH:mm:ss")}'
- AND t.stime<= '{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' and StatusID=6 )
- a
- WHERE
- 1=1
- {filter}
- GROUP BY HOUR(a.stime),StatusID";
- var TStatus = CurrDb.FindList<HourCount>(sql);
- #endregion
- ChartDto dto = new ChartDto()
- {
- LegendData = new List<string>()
- {
- "产量","稼动率","待机率","故障率","故障次数","故障时长"
- },
- XData = new List<string>(),
- };
- #region 数据处理
- List<decimal> y1 = new List<decimal>(), y2 = new List<decimal>(), y3 = new List<decimal>(), y4 = new List<decimal>(), y5 = new List<decimal>(), y6 = new List<decimal>();
- var Sam = new CountTotal();
- Sam.Factory = "汇总";
- var x1 = new IndexDatas()
- {
- Index = "产量"
- };
- var x2 = new IndexDatas()
- {
- Index = "稼动率"
- };
- var x3 = new IndexDatas()
- {
- Index = "待机率"
- };
- var x4 = new IndexDatas()
- {
- Index = "故障率"
- };
- var x5 = new IndexDatas()
- {
- Index = "故障次数"
- };
- var x6 = new IndexDatas()
- {
- Index = "故障时长"
- };
- for (int i = 0; i < 24; i++)
- {
- dto.XData.Add(i.ToString("00") + ":00:00");
- var a = TCount.Where(c => c.Hour == i)?.FirstOrDefault()?.Count;
- a = a != null ? a : "0";
- var b = TStatus.Where(c => c.Hour == i && c.StatusId == 4)?.FirstOrDefault()?.TimeLen;
- b = b != null ? b : 0;
- var d = Time.Where(c => c.Hour == i)?.FirstOrDefault()?.TimeLen;
- d = d != null ? d : 1;
- var e = TStatus.Where(c => c.Hour == i && c.StatusId == 3)?.FirstOrDefault()?.TimeLen;
- e = e != null ? e : 0;
- var f = TStatus.Where(c => c.Hour == i && c.StatusId == 6)?.FirstOrDefault()?.TimeLen;
- f = f != null ? f : 0;
- var g = TStatus.Where(c => c.Hour == i && c.StatusId == 6)?.FirstOrDefault()?.IntCount;
- g = g != null ? g : 0;
- var t1 = Convert.ToDecimal(Math.Round(b.Value / d.Value * 100, 2));
- var t2 = Convert.ToDecimal(Math.Round(e.Value / d.Value * 100, 2));
- var t3 = Convert.ToDecimal(Math.Round(f.Value / d.Value * 100, 2));
- var t4 = Convert.ToInt32(g.Value);
- var t5 = Convert.ToDecimal(Math.Round(f.Value / 60, 2));
- x1.data.Add(a);
- x2.data.Add(t1.ToString() + "%");
- x3.data.Add(t2.ToString() + "%");
- x4.data.Add(t3.ToString() + "%");
- x5.data.Add(t4.ToString());
- x6.data.Add(t5.ToString());
- y1.Add(Convert.ToDecimal(a));
- y2.Add(t1);
- y3.Add(t2);
- y4.Add(t3);
- y5.Add(t4);
- y6.Add(t5);
- #endregion
- #region 没有用
- /*if (i < Time.Count())
- {
- x1.data.Add(Convert.ToInt32(TCount.Where(c => c.Hour == i).FirstOrDefault().Count));
- x2.data.Add(Convert.ToDouble(Math.Round((TStatus.Where(c => c.Hour == i && c.StatusId == 4).FirstOrDefault().TimeLen / Time.Where(c => c.Hour == i).FirstOrDefault().TimeLen) * 100, 2)));
- x3.data.Add(Convert.ToDouble(Math.Round((TStatus.Where(c => c.Hour == i && c.StatusId == 3).FirstOrDefault().TimeLen / Time.Where(c => c.Hour == i).FirstOrDefault().TimeLen) * 100, 2)));
- x4.data.Add(Convert.ToDouble(Math.Round((TStatus.Where(c => c.Hour == i && c.StatusId == 6).FirstOrDefault().TimeLen / Time.Where(c => c.Hour == i).FirstOrDefault().TimeLen) * 100, 4)));
- x5.data.Add(Convert.ToInt32(TStatus.Where(c => c.Hour == i && c.StatusId == 6).FirstOrDefault().IntCount));
- x6.data.Add(Convert.ToDouble(Math.Round((TStatus.Where(c => c.Hour == i && c.StatusId == 6).FirstOrDefault().TimeLen) / 3600, 2)));
- *//*indexDatas.Add(new IndexData()
- {
- hour = i.ToString("00") + ":00:00",
- count = Convert.ToInt32(TCount.Where(c => c.Hour == i).FirstOrDefault().Count),
- JDrate = Convert.ToDouble(Math.Round(TStatus.Where(c => c.Hour == i && c.StatusId == 4).FirstOrDefault().TimeLen / Time.Where(c => c.Hour == i).FirstOrDefault().TimeLen, 4) * 100),
- DJrate = Convert.ToDouble(Math.Round(TStatus.Where(c => c.Hour == i && c.StatusId == 3).FirstOrDefault().TimeLen / Time.Where(c => c.Hour == i).FirstOrDefault().TimeLen, 4) * 100),
- GZrate = Convert.ToDouble(Math.Round(TStatus.Where(c => c.Hour == i && c.StatusId == 6).FirstOrDefault().TimeLen / Time.Where(c => c.Hour == i).FirstOrDefault().TimeLen, 4) * 100),
- GZcount = Convert.ToInt32(TStatus.Where(c => c.Hour == i && c.StatusId == 6).FirstOrDefault().IntCount),
- GZtime = Convert.ToDouble(Math.Round((TStatus.Where(c => c.Hour == i && c.StatusId == 6).FirstOrDefault().TimeLen) / 3600, 2))
- });*//*
- }
- else
- {
- *//*indexDatas.Add(new IndexData()
- {
- hour = i.ToString("00") + ":00:00",
- count = 0,
- JDrate=0.00,
- DJrate=0.00,
- GZrate=0.00,
- GZcount=0,
- GZtime=0.00
- }); ;*//*
- x1.data.Add(0);
- x2.data.Add(0);
- x3.data.Add(0);
- x4.data.Add(0);
- x5.data.Add(0);
- x6.data.Add(0);
- }*/
- #endregion
- }
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "产量", YAxis = 0, Type = "line", Data = y1 });
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "稼动率", YAxis = 1, Type = "line", Data = y2 });
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "待机率", YAxis = 1, Type = "line", Data = y3 });
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "故障率", YAxis = 1, Type = "line", Data = y4 });
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "故障次数", YAxis = 0, Type = "line", Data = y5 });
- dto.SeriesData.Add(new DllEapEntity.OFILM.Series() { Name = "故障时长", YAxis = 0, Type = "line", Data = y6 });
- Sam.Datas.Add(x1); Sam.Datas.Add(x2); Sam.Datas.Add(x3); Sam.Datas.Add(x4); Sam.Datas.Add(x5); Sam.Datas.Add(x6);
- dtos = dto;
- return Sam;
- }
- catch (Exception ex)
- {
- throw;
- }
- }
- /// <summary>
- /// 时段产量时间在2022-03-03 14:00:00之前的数据处理方法
- /// </summary>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="filter"></param>
- /// <param name="start"></param>
- /// <param name="length"></param>
- /// <param name="errorinfo"></param>
- /// <param name="total"></param>
- /// <returns></returns>
- public AntdComplexTableDto GetOldData(DateTime startTime, DateTime endTime, string filter, int start,
- int length, ref string errorinfo, out int total)
- {
- IEnumerable<Machine> macs = null;
- var dt = this.GetMacRunDatas(startTime, endTime, filter, start, length, ref errorinfo, out macs, out total);
- var headers = new List<AntdColumn>();
- if (dt != null && dt.Columns.Count > 0)
- {
- foreach (DataColumn item in dt.Columns)
- {
- if (item.ColumnName == "MacCode" || item.ColumnName == "MacModel"
- || item.ColumnName == "ModelRowSpan" || item.ColumnName == "MacRowSpan")
- continue;
- headers.Add(new AntdColumn { ColName = item.ColumnName });
- }
- }
- var antdData = new AntdComplexTableDto();
- antdData.Columns = headers;
- var modelGroups = macs.GroupBy(c => c.MModeCode);
- IList<AntdComplexData> antdComplexDatas = new List<AntdComplexData>();
- foreach (var item in modelGroups)
- {
- var complexData = new AntdComplexData { MacModel = item.Key, RowSpan = item.Count() };
- var modelMacs = item;
- var macDatas = new List<AntdComplexMachineData>();
- complexData.Machines = macDatas;
- antdComplexDatas.Add(complexData);
- }
- antdData.Datas = dt;
- return antdData;
- }
- /// <summary>
- /// 时段产量数据获取
- /// </summary>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="filter"></param>
- /// <param name="start"></param>
- /// <param name="length"></param>
- /// <param name="errorinfo"></param>
- /// <param name="total"></param>
- /// <returns></returns>
- public AntdComplexTableDto GetComplexData(DateTime startTime, DateTime endTime, string filter, int start,
- int length, ref string errorinfo, out int total)
- {
-
- var time = Convert.ToDateTime("2022-03-03 14:00:00");
- if (endTime < time)
- {
- return GetOldData(startTime, endTime, filter, start, length, ref errorinfo, out total);
- }
- else if (startTime >= time)
- {
- return GetNewData(startTime, endTime, filter, start, length, ref errorinfo, out total);
- }
- else
- {
- return GetMixData(GetOldData(startTime, time, filter, start, length, ref errorinfo, out total).Datas, GetNewData(time, endTime, filter, start, length, ref errorinfo, out total).Datas, startTime,endTime);
- }
- }
- /// <summary>
- /// 时段产量时间包含2022-03-03 14:00:00的数据处理方法
- /// </summary>
- /// <param name="datas1"></param>
- /// <param name="datas2"></param>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <returns></returns>
- private AntdComplexTableDto GetMixData(DataTable datas1, DataTable datas2, DateTime startTime, DateTime endTime)
- {
- List<string> colList1 = new List<string>();
- List<string> colList2 = new List<string>();
- foreach (DataColumn col in datas1.Columns)
- {
- colList1.Add(col.ColumnName);
- }
- foreach (DataColumn col in datas2.Columns)
- {
- colList2.Add(col.ColumnName);
- }
- int hour = Convert.ToInt32(Math.Ceiling((endTime - startTime).TotalHours));
- var dt = getDT(hour, startTime);
- int i = 0;
- while (i<datas1.Rows.Count)
- {
- var row = dt.NewRow();
- foreach (DataColumn col in dt.Columns)
- {
- var colName = col.ColumnName;
- if (colName == "汇总")
- {
- if (i%6==1||i%6==2||i%6==3)
- {
- row[colName] = (Convert.ToDouble(datas1.Rows[i][colName]) + Convert.ToDouble(datas2.Rows[i][colName]))/2;
- }
- else
- {
- row[colName] = Convert.ToDouble(datas1.Rows[i][colName]) + Convert.ToDouble(datas2.Rows[i][colName]);
- }
-
- }
- else
- {
- if (colList1.Contains(colName))
- {
- row[colName] = datas1.Rows[i][colName];
- continue;
- }
- if (colList2.Contains(colName))
- {
- row[colName] = datas2.Rows[i][colName];
- continue;
- }
- }
- }
- dt.Rows.Add(row);
- i++;
- }
- var headers = new List<AntdColumn>();
- if (dt != null && dt.Columns.Count > 0)
- {
- foreach (DataColumn item in dt.Columns)
- {
- if (item.ColumnName == "MacCode" || item.ColumnName == "MacModel"
- || item.ColumnName == "ModelRowSpan" || item.ColumnName == "MacRowSpan")
- continue;
- headers.Add(new AntdColumn { ColName = item.ColumnName });
- }
- }
- return new AntdComplexTableDto()
- {
- Datas = dt,
- Columns = headers
- };
- }
- /// <summary>
- /// 时段产量时间在2022-03-03 14:00:00之后的数据处理方法
- /// </summary>
- /// <param name="startTime"></param>
- /// <param name="endTime"></param>
- /// <param name="filter"></param>
- /// <param name="start"></param>
- /// <param name="length"></param>
- /// <param name="errorinfo"></param>
- /// <param name="total"></param>
- /// <returns></returns>
- private AntdComplexTableDto GetNewData(DateTime startTime, DateTime endTime, string filter, int start, int length, ref string errorinfo, out int total)
- {
- int hour = Convert.ToInt32(Math.Ceiling((endTime - startTime).TotalHours));
- var rowStrings = new string[] { "产量", "稼动率", "待机率", "故障率", "故障次数", "故障时长" };
- var dt = getDT(hour, startTime);
- string condition = $@" and date_add(a.day,interval a.`Hour` hour)>='{startTime.ToString("yyyy-MM-dd HH:mm:ss")}' and date_add(a.day,interval a.`Hour` hour)<'{endTime.ToString("yyyy-MM-dd HH:mm:ss")}' " + filter;
- string table = new OutPutTimeInfo().GetQueryTabSql();
- total = Convert.ToInt32( CurrDb.FindObject($@"select count(DISTINCT(a.macid)) from {table} where 1=1 {condition}"));
- var mac = CurrDb.FindList<OutPutTimeInfo>($@"select DISTINCT (a.MacID ) MacID,c.FCode MacCode from {table} where 1=1 {condition} order by c.Fcode limit {start - 1},{length}");
- condition += $" and a.macid in ({string.Join(",", mac.Select(c => c.MacID))})";
- var data = CurrDb.FindListForCondition<OutPutTimeInfo>(condition, ref errorinfo);
- foreach (var item in mac)
- {
- var datas = data.Where(c => c.MacID == item.MacID).OrderBy(c => c.ID).ToList();
- var row1 = dt.NewRow();
- var row2 = dt.NewRow();
- var row3 = dt.NewRow();
- var row4 = dt.NewRow();
- var row5 = dt.NewRow();
- var row6 = dt.NewRow();
-
- foreach (DataColumn col in dt.Columns)
- {
- var colName = col.ColumnName;
- if (colName == "汇总")
- {
- row1[colName] = datas.Sum(c => c.Count);
- row2[colName] = Math.Round(datas.Sum(c => c.RunRate) / hour, 4);
- row3[colName] = Math.Round(datas.Sum(c => c.StandbyRate) / hour, 4);
- row4[colName] = Math.Round(datas.Sum(c => c.AlarmRate) / hour, 4);
- row5[colName] = datas.Sum(c => c.AlarmCount);
- row6[colName] = Math.Round(datas.Sum(c => c.AlarmTime) , 4);
- }
- else if (colName == "指标")
- {
- row1[colName] = rowStrings[0];
- row2[colName] = rowStrings[1];
- row3[colName] = rowStrings[2];
- row4[colName] = rowStrings[3];
- row5[colName] = rowStrings[4];
- row6[colName] = rowStrings[5];
- }
- else if (colName == "设备ID")
- {
- row1[colName] = datas[0].MacCode;
- row2[colName] = datas[0].MacCode;
- row3[colName] = datas[0].MacCode;
- row4[colName] = datas[0].MacCode;
- row5[colName] = datas[0].MacCode;
- row6[colName] = datas[0].MacCode;
- }
- else if (colName == "设备类型")
- {
- row1[colName] = datas[0].MModelCode;
- row2[colName] = datas[0].MModelCode;
- row3[colName] = datas[0].MModelCode;
- row4[colName] = datas[0].MModelCode;
- row5[colName] = datas[0].MModelCode;
- row6[colName] = datas[0].MModelCode;
- }
- else if (colName == "MacRowSpan" || colName == "ModelRowSpan")
- {
- continue;
- }
- else if (colName == "园区")
- {
- row1[colName] = datas[0].Factory;
- row2[colName] = datas[0].Factory;
- row3[colName] = datas[0].Factory;
- row4[colName] = datas[0].Factory;
- row5[colName] = datas[0].Factory;
- row6[colName] = datas[0].Factory;
- }
- else if (colName == "楼层")
- {
- row1[colName] = datas[0].Floor;
- row2[colName] = datas[0].Floor;
- row3[colName] = datas[0].Floor;
- row4[colName] = datas[0].Floor;
- row5[colName] = datas[0].Floor;
- row6[colName] = datas[0].Floor;
- }
- else if (colName == "制程代码")
- {
- row1[colName] = datas[0].PCode;
- row2[colName] = datas[0].PCode;
- row3[colName] = datas[0].PCode;
- row4[colName] = datas[0].PCode;
- row5[colName] = datas[0].PCode;
- row6[colName] = datas[0].PCode;
- }
- else
- {
- var da = new OutPutTimeInfo();
-
- var day = Convert.ToDateTime( Convert.ToDateTime(colName).ToString("yyyy-MM-dd"));
- var hou= Convert.ToDouble(Convert.ToDateTime(colName).ToString("HH"));
- da = datas.Where(c => c.Day == day && c.Hour == hou)?.FirstOrDefault();
- row1[colName] = da.Count;
- row2[colName] = da.RunRate;
- row3[colName] = da.StandbyRate;
- row4[colName] = da.AlarmRate;
- row5[colName] = da.AlarmCount;
- row6[colName] = da.AlarmTime / 60;
-
- }
- }
- dt.Rows.Add(row1); dt.Rows.Add(row2); dt.Rows.Add(row3); dt.Rows.Add(row4); dt.Rows.Add(row5); dt.Rows.Add(row6);
- }
- var modelGroups = data.GroupBy(c => c.MModelCode);
- foreach (var model in modelGroups)
- {
- for (var i = 0; i < dt.Rows.Count; i++)
- {
- if (dt.Rows[i]["设备类型"].ToString() == model.Key)
- {
- dt.Rows[i]["ModelRowSpan"] = model.Count() * 6;
- //dt.Rows[i]["FactroyNameRowSpan"] = model.Count() * 6;
- }
- dt.Rows[i]["MacRowSpan"] = 6;
- }
- }
- var headers = new List<AntdColumn>();
- if (dt != null && dt.Columns.Count > 0)
- {
- foreach (DataColumn item in dt.Columns)
- {
- if (item.ColumnName == "MacCode" || item.ColumnName == "MacModel"
- || item.ColumnName == "ModelRowSpan" || item.ColumnName == "MacRowSpan")
- continue;
- headers.Add(new AntdColumn { ColName = item.ColumnName });
- }
- }
- return new AntdComplexTableDto()
- {
- Datas = dt,
- Columns = headers,
-
- };
- }
- #region 拼接DataTable
- /// <summary>
- /// 添加产量行
- /// </summary>
- /// <param name="datas"></param>
- /// <param name="mac"></param>
- /// <param name="type"></param>
- /// <param name="dt"></param>
- private void AppendOutPutDataRow(IEnumerable<HourCount> datas, Machine mac, string type, DataTable dt)
- {
- DataRow row = dt.NewRow();
- Func<HourCount, bool> func = t => t.MacCode == mac.FCode;
- if (type == "产量")
- {
- func = t => t.MacId == mac.ID;
- }
- foreach (DataColumn col in dt.Columns)
- {
- var colName = col.ColumnName;
- if (colName == "汇总")
- {
- row[colName] = datas.Where(c => c.MacId == mac.ID).Sum(c => c.IntCount);
- }
- else if (colName == "指标")
- {
- row[colName] = type;
- }
- else if (colName == "设备ID")
- {
- row[colName] = mac.FCode;
- }
- else if (colName == "设备类型")
- {
- row[colName] = mac.MModeCode;
- }
- else if (colName == "MacRowSpan" || colName == "ModelRowSpan" )
- {
- continue;
- }
- else if (colName == "园区")
- {
- row[colName] = mac.FactoryName;
- }
- else if (colName == "楼层")
- {
- row[colName] = mac.FloorName;
- }
- else if (colName == "制程代码")
- {
- row[colName] = mac.PCode;
- }
- else
- {
- var currTime = Convert.ToDateTime(colName);
- var year = currTime.Year;
- var month = currTime.Month;
- var day = currTime.Day;
- var hour = currTime.Hour;
- var entity = datas.Where(func).FirstOrDefault(c => c.Year == year
- && c.Month == month && c.Day == day && c.Hour == hour);
- if (entity == null)
- {
- row[colName] = 0;
- }
- else
- {
- row[colName] = entity.Count;
- }
- }
- }
- dt.Rows.Add(row);
- }
- /// <summary>
- /// 添加稼动率及闲置率
- /// </summary>
- /// <param name="datas"></param>
- /// <param name="mac"></param>
- /// <param name="type"></param>
- /// <param name="dt"></param>
- private void AppendRunDataRow(IEnumerable<HourCount> datas, Machine mac, string type, int statusId, DataTable dt,
- double timeSpan, DateTime startTime, DateTime endTime)
- {
- //string errorinfo = string.Empty;
- //var hours = Math.Ceiling((endTime - startTime).TotalHours);
- //if (datas.Any(c => c.StatusId == statusId && c.MacCode == mac.FCode))
- //{
- // for (int i = 0; i < hours; i++)
- // {
- // var date = startTime.AddHours(i);
- // var endDate = date.AddHours(1);
- // var first = CurrDb.FindListForCondition<MacStatus>($" and statusId={statusId} and maccode='{mac.FCode}' " +
- // $"and etime>'{date.ToString(timeFormat)}' order by stime asc limit 0,1 ", ref errorinfo)
- // .FirstOrDefault();
- // if (first != null && first.STime < date)
- // {
- // datas.FirstOrDefault(c => c.Year == date.Year && c.Month == date.Month && c.Day == date.Day
- // && c.Hour == date.Hour && c.StatusId == statusId && c.MacCode == mac.FCode).TimeLen += (first.ETime - date).TotalSeconds;
- // }
- // var last = CurrDb.FindListForCondition<MacStatus>($" and statusId={statusId} and maccode='{mac.FCode}' " +
- // $"and stime<'{endDate.ToString(timeFormat)}' order by stime desc limit 0,1 ", ref errorinfo)
- // .FirstOrDefault();
- // if (last != null && last.ETime > endDate)
- // {
- // datas.FirstOrDefault(c => c.Year == date.Year && c.Month == date.Month && c.Day == date.Day
- // && c.Hour == date.Hour && c.StatusId == statusId && c.MacCode == mac.FCode).TimeLen -= (last.ETime - endDate).TotalSeconds;
- // }
- // }
- //}
- DataRow row = dt.NewRow();
- Func<HourCount, bool> func = t => t.MacCode == mac.FCode;
- foreach (DataColumn col in dt.Columns)
- {
- var colName = col.ColumnName;
- if (colName == "汇总")
- {
- double rate = 0;
- var totalTime = datas.Where(c => c.MacCode == mac.FCode && c.StatusId == statusId)?.Sum(c => c.TimeLen);
- if (totalTime != null)
- {
- rate = totalTime.Value / (timeSpan);
- }
- row[colName] = rate;
- }
- else if (colName == "指标")
- {
- row[colName] = type;
- }
- else if (colName == "设备ID")
- {
- row[colName] = mac.FCode;
- }
- else if (colName == "设备类型")
- {
- row[colName] = mac.MModeCode;
- }
- else if (colName == "MacRowSpan" || colName == "ModelRowSpan" )
- {
- continue;
- }
- else if (colName == "园区")
- {
- row[colName] = mac.FactoryName;
- }
- else if (colName == "楼层")
- {
- row[colName] = mac.FloorName;
- }
- else if (colName == "制程代码")
- {
- row[colName] = mac.PCode;
- }
- else
- {
- var currTime = Convert.ToDateTime(colName);
- var year = currTime.Year;
- var month = currTime.Month;
- var day = currTime.Day;
- var hour = currTime.Hour;
- var statuses = datas.Where(c => c.MacCode == mac.FCode && c.Year == year
- && c.Month == month && c.Day == day && c.Hour == hour && c.StatusId == statusId);
- if (statuses == null || statuses.Count() <= 0)
- {
- row[colName] = 0;
- }
- else
- {
- row[colName] = statuses.Sum(c => c.TimeLen) / 3600;
- }
- }
- }
- dt.Rows.Add(row);
- }
- /// <summary>
- /// 生成报警数据行
- /// </summary>
- /// <param name="datas"></param>
- /// <param name="mac"></param>
- /// <param name="type"></param>
- /// <param name="statusId"></param>
- /// <param name="dt"></param>
- private void AppendAlarmRateDataRow(IEnumerable<HourCount> datas, Machine mac, string type, DataTable dt, string alarmType, double timeSpan, DateTime startTime, DateTime endTime)
- {
- //string errorinfo = string.Empty;
- //var hours = Math.Ceiling((endTime - startTime).TotalHours);
- //if (datas.Any(c => c.StatusId == 6 && c.MacCode == mac.FCode))
- //{
- // for (int i = 0; i < hours; i++)
- // {
- // var date = startTime.AddHours(i);
- // var endDate = date.AddHours(1);
- // var first = CurrDb.FindListForCondition<MacStatus>($" and statusId={6} and maccode='{mac.FCode}' " +
- // $"and etime>'{date.ToString(timeFormat)}' order by stime asc limit 0,1 ", ref errorinfo)
- // .FirstOrDefault();
- // if (first != null && first.STime < date)
- // {
- // datas.FirstOrDefault(c => c.Year == date.Year && c.Month == date.Month && c.Day == date.Day
- // && c.Hour == date.Hour && c.StatusId == 6 && c.MacCode == mac.FCode).TimeLen += (first.ETime - date).TotalSeconds;
- // }
- // var last = CurrDb.FindListForCondition<MacStatus>($" and statusId={6} and maccode='{mac.FCode}' " +
- // $"and stime<'{endDate.ToString(timeFormat)}' order by stime desc limit 0,1 ", ref errorinfo)
- // .FirstOrDefault();
- // if (last != null && last.ETime > endDate)
- // {
- // datas.FirstOrDefault(c => c.Year == date.Year && c.Month == date.Month && c.Day == date.Day
- // && c.Hour == date.Hour && c.StatusId == 6 && c.MacCode == mac.FCode).TimeLen -= (last.ETime - endDate).TotalSeconds;
- // }
- // }
- //}
- DataRow row = dt.NewRow();
- Func<HourCount, bool> func = t => t.MacCode == mac.FCode;
- foreach (DataColumn col in dt.Columns)
- {
- var colName = col.ColumnName;
- if (colName == "汇总")
- {
- var totalTime = datas.Where(c => c.MacCode == mac.FCode);
- if (alarmType == "COUNT")
- {
- int count = 0;
- if (totalTime != null)
- {
- count = totalTime.Sum(c => c.IntCount);
- }
- row[colName] = count;
- }
- else if (alarmType == "TIME")
- {
- double time = 0;
- if (totalTime != null)
- {
- time = totalTime.Sum(c => c.TimeLen) / 60;
- }
- row[colName] = time;
- }
- else
- {
- double time = 0;
- if (totalTime != null)
- {
- time = totalTime.Sum(c => c.TimeLen) / (timeSpan);
- }
- row[colName] = time;
- }
- }
- else if (colName == "指标")
- {
- row[colName] = type;
- }
- else if (colName == "设备ID")
- {
- row[colName] = mac.FCode;
- }
- else if (colName == "设备类型")
- {
- row[colName] = mac.MModeCode;
- }
- else if (colName == "MacRowSpan" || colName == "ModelRowSpan")
- {
- continue;
- }
- else if (colName == "园区")
- {
- row[colName] = mac.FactoryName;
- }
- else if (colName == "楼层")
- {
- row[colName] = mac.FloorName;
- }
- else if (colName == "制程代码")
- {
- row[colName] = mac.PCode;
- }
- else
- {
- var currTime = Convert.ToDateTime(colName);
- var year = currTime.Year;
- var month = currTime.Month;
- var day = currTime.Day;
- var hour = currTime.Hour;
- var statuses = datas.Where(c => c.MacCode == mac.FCode && c.Year == year
- && c.Month == month && c.Day == day && c.Hour == hour);
- if (statuses == null || statuses.Count() <= 0)
- {
- row[colName] = 0;
- }
- else
- {
- switch (alarmType)
- {
- case "COUNT": row[colName] = statuses.Sum(c => c.IntCount); break;
- case "TIME": row[colName] = statuses.Sum(c => c.TimeLen) / 60; break;
- default: row[colName] = statuses.Sum(c => c.TimeLen) / 3600; break;
- }
- }
- }
- }
- dt.Rows.Add(row);
- }
- #endregion
- }
-
- }
|