Ejemplo n.º 1
0
        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="name"></param>
        /// <param name="type"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public IActionResult ExportPdf(string shipId, string name, int type, string startTime, string endTime)
        {
            int total = 0;
            SearchAlarmViewModel model = new SearchAlarmViewModel()
            {
                Name      = name,
                EndTime   = endTime,
                StartTime = startTime,
                Type      = type,
                ShipId    = shipId
            };

            shipId = string.IsNullOrEmpty(shipId) ? base.user.ShipId : shipId;
            if (!base.user.IsLandHome)
            {
                shipId       = base.user.ShipId;
                model.ShipId = base.user.ShipId;
            }
            var    ship    = _context.Ship.Where(c => c.Id == shipId).FirstOrDefault();
            var    list    = GetDate(model, 1, 1000000, out total);
            string time    = startTime + "~" + endTime;
            var    address = HttpContext.Request.Scheme + "://" + HttpContext.Request.Host;
            string html    = ManagerHelp.GetHtml(list, time, ship.Name, address);
            //生成PDF
            var pdfBytes = _PDFService.CreatePDF(html);

            return(File(pdfBytes, "application/pdf", "报警信息.pdf"));
        }
Ejemplo n.º 2
0
        private List <AlarmViewModel> GetDate(SearchAlarmViewModel model, int pageIndex, int pageSize, out int total)
        {
            List <AlarmViewModel> list = new List <AlarmViewModel>();

            total = 0;
            if (model == null)
            {
                model = new SearchAlarmViewModel();
            }
            //查询船信息
            List <Ship> shipList = new List <Ship>();
            string      shipName = "";
            string      shipIds  = "";

            if (!ManagerHelp.IsShipPort)
            {
                shipList = GetShips();
                if (!string.IsNullOrEmpty(model.ShipId))
                {
                    shipList = shipList.Where(c => c.Id == model.ShipId).ToList();
                }
                shipIds = string.Join(',', shipList.Select(c => c.Id));
            }
            else
            {
                shipName = _context.Ship.FirstOrDefault().Name;
            }

            var alarmData = _context.Alarm.Where(c => shipIds.Contains(c.ShipId) && (c.Type != Alarm.AlarmType.ATTENDANCE_IN && c.Type != Alarm.AlarmType.ATTENDANCE_OUT) && (model.Type == 0 ? 1 == 1 : c.Type == (Alarm.AlarmType)model.Type));

            if (!(string.IsNullOrEmpty(model.StartTime)) && !(string.IsNullOrEmpty(model.EndTime)))
            {
                DateTime dtStart = DateTime.Parse(model.StartTime);
                DateTime dtEnd   = DateTime.Parse(model.EndTime);
                alarmData = alarmData.Where(c => c.Time >= dtStart && c.Time <= dtEnd);
            }
            else if (!(string.IsNullOrEmpty(model.StartTime)))
            {
                DateTime dtStart = DateTime.Parse(model.StartTime);
                alarmData = alarmData.Where(c => c.Time >= dtStart);
            }
            else if (!(string.IsNullOrEmpty(model.EndTime)))
            {
                DateTime dtEnd = DateTime.Parse(model.EndTime);
                alarmData = alarmData.Where(c => c.Time <= dtEnd);
            }
            if (!string.IsNullOrEmpty(model.Name))
            {
                alarmData = alarmData.Where(c => c.Cname.Contains(model.Name));
            }
            var alarm = alarmData.OrderByDescending(c => c.CreatDate).ToList();
            //组合数据
            var data = from a in alarm
                       select new
            {
                a.Time,
                a.Id,
                NickName = a.Cname,
                a.Type,
                a.Picture
            };

            total = data.Count();
            var datapage = data.Skip((pageIndex - 1) * pageSize).Take(pageSize);
            var ids      = string.Join(',', datapage.Select(c => c.Id));
            //查询位置信息
            var pics = _context.AlarmPosition.Where(c => ids.Contains(c.AlarmId)).ToList();

            foreach (var item in datapage)
            {
                string picture = Convert.ToBase64String(item.Picture);
                if (!ManagerHelp.IsShipPort)
                {
                    var ship = shipList.FirstOrDefault(c => c.Id == item.Id);
                    shipName = ship != null ? ship.Name : "";
                }
                AlarmViewModel avm = new AlarmViewModel()
                {
                    Id       = item.Id,
                    Name     = shipName,
                    NickName = item.NickName,
                    Picture  = picture,
                    Type     = (int)item.Type,
                    Time     = item.Time.ToString("yyyy-MM-dd HH:mm:ss"),
                };
                if (pics != null && pics.Count > 0)
                {
                    if (pics.Where(c => c.AlarmId == item.Id).Any())
                    {
                        var pic = pics.FirstOrDefault(c => c.AlarmId == item.Id);
                        avm.H = pic.H;
                        avm.W = pic.W;
                        avm.X = pic.X;
                        avm.Y = pic.Y;
                    }
                }
                list.Add(avm);
            }
            return(list);
        }