示例#1
0
        public GiamSatThietBi2Cot GetListGiamSatThietBi(GiamSatInput input)
        {
            var lsThietBi = _repository.GetAll()
                            .WhereIf(input.iddonvi != 0, x => x.TRAM.IDDONVI == input.iddonvi)
                            .WhereIf(input.idtram != 0, x => x.IDTRAM == input.idtram)
                            .WhereIf(input.idthietbi != 0, x => x.Id == input.idtram)
                            .ToList().MapTo <List <DM_ThietBiDto> >();
            GiamSatThietBi2Cot    result = new GiamSatThietBi2Cot();
            List <GiamSatThietBi> cot1   = new List <GiamSatThietBi>();
            List <GiamSatThietBi> cot2   = new List <GiamSatThietBi>();

            if (lsThietBi.Count > 0)
            {
                for (var i = 0; i < lsThietBi.Count; i++)
                {
                    if (i % 2 == 0)
                    {
                        GiamSatThietBi giamsat = new GiamSatThietBi();
                        giamsat.thietbi    = lsThietBi[i];
                        giamsat.lsThongTin = _thongTin_ThietBiService.GetThongTinQuanLyByIdThietBi(lsThietBi[i].Id);
                        cot2.Add(giamsat);
                    }
                    else
                    {
                        GiamSatThietBi giamsat = new GiamSatThietBi();
                        giamsat.thietbi    = lsThietBi[i];
                        giamsat.lsThongTin = _thongTin_ThietBiService.GetThongTinQuanLyByIdThietBi(lsThietBi[i].Id);
                        cot1.Add(giamsat);
                    }
                }
            }
            result.cot1 = cot1;
            result.cot2 = cot2;
            return(result);
        }
示例#2
0
        private async Task AutoDieuHoa(DM_ThietBiDto thietbi, string ndtp, string ndmt)
        {
            if (float.Parse(ndtp) > thietbi.NGUONGNHIETDOCANHBAO)
            {
                if (_lichSuHoatDongThietBiAppService.CheckSaveLog(thietbi.Id, "NHIETDO", "1"))
                {
                    var canhbao = "NHIETDO@1@" + ndtp + "°C";
                    await SendMessageTrangThai(canhbao);
                }
            }
            else
            {
                if (_lichSuHoatDongThietBiAppService.CheckSaveLog(thietbi.Id, "NHIETDO", "0"))
                {
                    var canhbao = "NHIETDO@0@";
                    await SendMessageTrangThai(canhbao);
                }
            }
            var lsthongtin = _thongTin_ThietBiAppService.GetThongTinQuanLyByIdThietBi(thietbi.Id);

            if (thietbi.AUTODIEUHOA == "AUTO")
            {
                if (float.Parse(ndtp) > thietbi.NGUONGNHIETDOCAO)
                {
                    //Bật 2 điều hòa, Tắt quạt
                    foreach (var item in lsthongtin)
                    {
                        if (item.THONGTINQUANLY.CODE.Contains("DIEUHOA"))
                        {
                            if (item.TRANGTHAI != "1")
                            {
                                var dieuhoa = item.THONGTINQUANLY.CODE + "@1@" + "{\"cmd_type\":4,\"source\":" + item.THONGTINQUANLY.DESCRIPTION + ",\"brand\":0, \"power\":1, \"temp\":25, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                await SendMessagePrivate(thietbi.ConnectionID, dieuhoa);

                                Thread.Sleep(30000);
                            }
                        }
                        if (item.THONGTINQUANLY.CODE.Contains("QUATGIO"))
                        {
                            if (item.TRANGTHAI != "0")
                            {
                                var quatgio = "QUATGIO@0@";
                                await SendMessagePrivate(thietbi.ConnectionID, quatgio);

                                Thread.Sleep(30000);
                            }
                        }
                    }
                }
                else
                {
                    if (thietbi.NGUONGNHIETDOANTOAN < float.Parse(ndtp) && float.Parse(ndtp) <= thietbi.NGUONGNHIETDOCAO)
                    {
                        //Chạy luân phiên 1 điều hòa, Tắt quạt
                        var lasthoatdongDH1 = _lichSuHoatDongThietBiAppService.GetLastLichSuHoatDongByCode(thietbi.Id, "DIEUHOAIR1");
                        var lasthoatdongDH2 = _lichSuHoatDongThietBiAppService.GetLastLichSuHoatDongByCode(thietbi.Id, "DIEUHOAIR2");
                        if (lasthoatdongDH1 != null)
                        {
                            if (lasthoatdongDH1.SUSSES == 1)
                            {
                                var tnghi = (DateTime.Now - lasthoatdongDH1.ENDDATE).TotalMinutes;
                                if (tnghi < thietbi.THOIGIANCHAYLUANPHIEN)
                                {
                                    //Bật điều hòa 2
                                    var thongtindieuhoa2 = _thongTin_ThietBiAppService.GetThongTinThietBiByIdThietBiAndCode(thietbi.Id, "DIEUHOAIR2");
                                    if (thongtindieuhoa2.TRANGTHAI != "1")
                                    {
                                        var dieuhoa2 = "DIEUHOAIR2@1@" + "{\"cmd_type\":4,\"source\":" + thongtindieuhoa2.THONGTINQUANLY.DESCRIPTION + ",\"brand\":0, \"power\":1, \"temp\":25, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                        await SendMessagePrivate(thietbi.ConnectionID, dieuhoa2);

                                        Thread.Sleep(30000);
                                    }
                                }
                                else
                                {
                                    //Bật điều hòa 1
                                    var thongtindieuhoa1 = _thongTin_ThietBiAppService.GetThongTinThietBiByIdThietBiAndCode(thietbi.Id, "DIEUHOAIR1");
                                    if (thongtindieuhoa1.TRANGTHAI != "1")
                                    {
                                        var dieuhoa1 = "DIEUHOAIR1@1@" + "{\"cmd_type\":4,\"source\":0,\"brand\":0, \"power\":1, \"temp\":25, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                        await SendMessagePrivate(thietbi.ConnectionID, dieuhoa1);

                                        Thread.Sleep(30000);
                                    }

                                    //Tắt điều hòa 2
                                    var thongtindieuhoa2 = _thongTin_ThietBiAppService.GetThongTinThietBiByIdThietBiAndCode(thietbi.Id, "DIEUHOAIR2");
                                    if (thongtindieuhoa2.TRANGTHAI != "0" && (DateTime.Now - lasthoatdongDH2.STARTDATE).TotalMinutes > 10)
                                    {
                                        var dieuhoa2 = "DIEUHOAIR2@0@" + "{\"cmd_type\":4,\"source\":" + thongtindieuhoa2.THONGTINQUANLY.DESCRIPTION + ",\"brand\":0, \"power\":0, \"temp\":25, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                        await SendMessagePrivate(thietbi.ConnectionID, dieuhoa2);

                                        Thread.Sleep(30000);
                                    }
                                }
                            }
                            else
                            {
                                var tchay = (DateTime.Now - lasthoatdongDH1.STARTDATE).TotalMinutes;
                                if (tchay > thietbi.THOIGIANCHAYLUANPHIEN)
                                {
                                    //Bật điều hòa 2
                                    var thongtindieuhoa2 = _thongTin_ThietBiAppService.GetThongTinThietBiByIdThietBiAndCode(thietbi.Id, "DIEUHOAIR2");
                                    if (thongtindieuhoa2.TRANGTHAI != "1")
                                    {
                                        var dieuhoa2 = "DIEUHOAIR2@1@" + "{\"cmd_type\":4,\"source\":" + thongtindieuhoa2.THONGTINQUANLY.DESCRIPTION + ",\"brand\":0, \"power\":1, \"temp\":25, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                        await SendMessagePrivate(thietbi.ConnectionID, dieuhoa2);

                                        Thread.Sleep(30000);
                                    }
                                    var thongtindieuhoa1 = _thongTin_ThietBiAppService.GetThongTinThietBiByIdThietBiAndCode(thietbi.Id, "DIEUHOAIR1");
                                    if (tchay > 10 && thongtindieuhoa1.TRANGTHAI != "0")
                                    {
                                        //Tắt điều hòa 1
                                        var dieuhoa1 = "DIEUHOAIR1@0@" + "{\"cmd_type\":4,\"source\":0,\"brand\":0, \"power\":0, \"temp\":25, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                        await SendMessagePrivate(thietbi.ConnectionID, dieuhoa1);

                                        Thread.Sleep(30000);
                                    }
                                }
                                else
                                {
                                    //Tắt điều hòa 2
                                    var thongtindieuhoa2 = _thongTin_ThietBiAppService.GetThongTinThietBiByIdThietBiAndCode(thietbi.Id, "DIEUHOAIR2");
                                    if (thongtindieuhoa2.TRANGTHAI != "0" && (DateTime.Now - lasthoatdongDH2.STARTDATE).TotalMinutes > 10)
                                    {
                                        var dieuhoa2 = "DIEUHOAIR2@0@" + "{\"cmd_type\":4,\"source\":" + thongtindieuhoa2.THONGTINQUANLY.DESCRIPTION + ",\"brand\":0, \"power\":0, \"temp\":25, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                        await SendMessagePrivate(thietbi.ConnectionID, dieuhoa2);

                                        Thread.Sleep(30000);
                                    }
                                }
                            }
                        }

                        //Tắt quạt
                        var thongtinquat = _thongTin_ThietBiAppService.GetThongTinThietBiByIdThietBiAndCode(thietbi.Id, "QUATGIO");
                        if (thongtinquat != null)
                        {
                            if (thongtinquat.TRANGTHAI != "0")
                            {
                                var quatgio = "QUATGIO@0@";
                                await SendMessagePrivate(thietbi.ConnectionID, quatgio);

                                Thread.Sleep(30000);
                            }
                        }
                    }
                    else
                    {
                        if (thietbi.NGUONGNHIETDOTHAP < float.Parse(ndtp) && float.Parse(ndtp) <= thietbi.NGUONGNHIETDOANTOAN)
                        {
                            if (float.Parse(ndmt) < float.Parse(ndtp))
                            {
                                //Tắt 2 điều hòa, bật quạt
                                foreach (var item in lsthongtin)
                                {
                                    if (item.THONGTINQUANLY.CODE.Contains("DIEUHOA"))
                                    {
                                        var hoatdong = _lichSuHoatDongThietBiAppService.GetLastLichSuHoatDongByCode(thietbi.Id, item.THONGTINQUANLY.CODE);
                                        if (item.TRANGTHAI != "0" && (DateTime.Now - hoatdong.STARTDATE).TotalMinutes > 10)
                                        {
                                            var dieuhoa = item.THONGTINQUANLY.CODE + "@0@" + "{\"cmd_type\":4,\"source\":" + item.THONGTINQUANLY.DESCRIPTION + ",\"brand\":0, \"power\":0, \"temp\":20, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                            await SendMessagePrivate(thietbi.ConnectionID, dieuhoa);

                                            Thread.Sleep(30000);
                                        }
                                    }
                                    if (item.THONGTINQUANLY.CODE.Contains("QUATGIO"))
                                    {
                                        if (item.TRANGTHAI != "1")
                                        {
                                            var quatgio = "QUATGIO@1@";
                                            await SendMessagePrivate(thietbi.ConnectionID, quatgio);

                                            Thread.Sleep(30000);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                //Tắt 2 điều hòa, tắt quạt
                                foreach (var item in lsthongtin)
                                {
                                    if (item.THONGTINQUANLY.CODE.Contains("DIEUHOA"))
                                    {
                                        var hoatdong = _lichSuHoatDongThietBiAppService.GetLastLichSuHoatDongByCode(thietbi.Id, item.THONGTINQUANLY.CODE);
                                        if (item.TRANGTHAI != "0" && (DateTime.Now - hoatdong.STARTDATE).TotalMinutes > 10)
                                        {
                                            var dieuhoa = item.THONGTINQUANLY.CODE + "@0@" + "{\"cmd_type\":4,\"source\":" + item.THONGTINQUANLY.DESCRIPTION + ",\"brand\":0, \"power\":0, \"temp\":25, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                            await SendMessagePrivate(thietbi.ConnectionID, dieuhoa);

                                            Thread.Sleep(30000);
                                        }
                                    }
                                    if (item.THONGTINQUANLY.CODE.Contains("QUATGIO"))
                                    {
                                        if (item.TRANGTHAI != "0")
                                        {
                                            var quatgio = "QUATGIO@0@";
                                            await SendMessagePrivate(thietbi.ConnectionID, quatgio);

                                            Thread.Sleep(30000);
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            //Tắt 2 điều hòa, tắt quạt
                            foreach (var item in lsthongtin)
                            {
                                if (item.THONGTINQUANLY.CODE.Contains("DIEUHOA"))
                                {
                                    if (item.TRANGTHAI != "0")
                                    {
                                        var dieuhoa = item.THONGTINQUANLY.CODE + "@0@" + "{\"cmd_type\":4,\"source\":" + item.THONGTINQUANLY.DESCRIPTION + ",\"brand\":0, \"power\":0, \"temp\":20, \"mode\":1, \"fan\":4, \"swing\":1, \"model\":4}";
                                        SendMessagePrivate(thietbi.ConnectionID, dieuhoa);
                                        Thread.Sleep(60000);
                                    }
                                }
                                if (item.THONGTINQUANLY.CODE.Contains("QUATGIO"))
                                {
                                    if (item.TRANGTHAI != "0")
                                    {
                                        var quatgio = "QUATGIO@0@";
                                        SendMessagePrivate(thietbi.ConnectionID, quatgio);
                                        Thread.Sleep(60000);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }