public ActionResult ExportCheckLists(DateTime date)
        {
            using (IRepository repo = new Repository())
            {
                var list = repo.Query <CheckList>(x => x.OperateDate >= date.AddDays(-2) && x.OperateDate <= date.AddDays(2))
                           .FindAll(x => x.OperateDate.Date == date.Date && x.IsActive);

                if (list.Count > 0)
                {
                    var mapper     = CheckListDto.ConfigMapper().CreateMapper();
                    var checklists = mapper.Map <IEnumerable <CheckListDto> >(list.AsEnumerable()).ToList();

                    var book = ExcelManager.BuildCheckListWorkbook(checklists, date);

                    byte[] file;
                    using (var ms = new MemoryStream())
                    {
                        book.Write(ms);
                        file = ms.GetBuffer();
                    }

                    return(File(file, "application/vnd.ms-excel", $@"今日安全检查表-{date:yyyyMMdd}.xls"));
                }
            }

            return(RedirectToAction("CheckListManagement", "SecureNode", new { date }));
        }
        // GET: SecureNode/CheckListManagement
        public ActionResult CheckListManagement(string date)
        {
            var model = new SecureNodeModels.CheckListManagementDto();

            using (IRepository repo = new Repository())
            {
                List <CheckList> list;

                if (!string.IsNullOrEmpty(date) && DateTime.TryParse(date, out var operateDate))
                {
                    list = repo.Query <CheckList>(x => x.OperateDate >= operateDate.AddDays(-2) && x.OperateDate <= operateDate.AddDays(2))
                           .FindAll(x => x.OperateDate.Date == operateDate.Date && x.IsActive);

                    model.OperateDate = operateDate;
                }
                else
                {
                    // 为避免数据量过大,只显示7天内的检查记录
                    list = repo.Query <CheckList>(x => x.OperateDate >= DateTime.Now.AddDays(-7)).FindAll(x => x.IsActive);

                    model.OperateDate = null;
                }

                if (list.Count > 0)
                {
                    var mapper = CheckListDto.ConfigMapper().CreateMapper();

                    model.CheckLists = mapper.Map <IEnumerable <CheckListDto> >(list.AsEnumerable()).ToList();
                }
            }

            return(View(model));
        }
        // GET: SecureNode/History
        public ActionResult History(string date)
        {
            var model = new SecureNodeModels.HistoryDto();

            using (IRepository repo = new Repository())
            {
                var list = repo.Query <CheckList>(x => x.UserGuid == _authorizedUser.ID).FindAll(x => x.IsActive);

                if (!string.IsNullOrEmpty(date) && DateTime.TryParse(date, out var operateDate))
                {
                    list = list.FindAll(x => x.OperateDate.Date == operateDate.Date);

                    model.OperateDate = operateDate;
                }
                else
                {
                    list = list.FindAll(x => x.OperateDate.Date == DateTime.Today.Date);

                    model.OperateDate = DateTime.Today;
                }

                if (list.Count > 0)
                {
                    var mapper = CheckListDto.ConfigMapper().CreateMapper();

                    model.MyCheckLists = mapper.Map <IEnumerable <CheckListDto> >(list.AsEnumerable()).ToList();
                }
            }

            return(View(model));
        }
        // GET: SecureNode
        public ActionResult Index(string date)
        {
            var model = new SecureNodeModels.IndexDto();

            using (IRepository repo = new Repository())
            {
                var relations = repo.Query <RelationUserOperationStandard>(x => x.UserGuid == _authorizedUser.ID);

                if (relations.Count > 0)
                {
                    var secureNodes = OperationStandard.Cache.OperationStandardList
                                      .FindAll(x => relations.Exists(rela => rela.OperationStandardId.Equals(x.ID)));

                    var mapper = OperationStandardDto.ConfigMapper().CreateMapper();

                    model.SecureNodes = mapper.Map <IEnumerable <OperationStandardDto> >(secureNodes.AsEnumerable())
                                        .ToList();
                }

                var list = repo.Query <CheckList>(x => x.UserGuid == _authorizedUser.ID).FindAll(x => x.IsActive);

                if (!string.IsNullOrEmpty(date) && DateTime.TryParse(date, out var operateDate))
                {
                    list = list.FindAll(x => x.OperateDate.Date == operateDate.Date);

                    model.OperateDate = operateDate;
                }
                else
                {
                    list = list.FindAll(x => x.OperateDate.Date == DateTime.Today.Date);

                    model.OperateDate = DateTime.Today;
                }

                if (list.Count > 0)
                {
                    var mapper = CheckListDto.ConfigMapper().CreateMapper();

                    model.MyCheckLists = mapper.Map <IEnumerable <CheckListDto> >(list.AsEnumerable()).ToList();
                }
            }

            return(View(model));
        }