示例#1
0
        public JsonResult CheckReservation(string id, int status, string comment)
        {
            try {
                if (string.IsNullOrWhiteSpace(id))
                {
                    throw new ArgumentException("id");
                }

                var reservation = _reservationService.GetReservation(id);
                if (reservation == null)
                {
                    throw new iPemException("未找到数据对象");
                }

                reservation.Status = Enum.IsDefined(typeof(EnmResult), status) ? (EnmResult)status : EnmResult.Failure;
                if (reservation.Status == EnmResult.Success)
                {
                    var interval = 0d;
                    var rtValues = _workContext.RtValues();
                    if (rtValues != null)
                    {
                        interval = rtValues.gcyyshsxShiChang;
                    }

                    var now = DateTime.Now;
                    if (now >= reservation.ExpStartTime)
                    {
                        reservation.StartTime = now;
                    }
                    else
                    {
                        reservation.StartTime = now.AddMinutes(interval);
                        if (reservation.StartTime >= reservation.ExpStartTime)
                        {
                            reservation.StartTime = reservation.ExpStartTime;
                        }
                    }
                }

                _reservationService.Check(reservation.Id, reservation.StartTime, reservation.Status, comment);

                #region 通知服务重载配置
                if (reservation.Status == EnmResult.Success)
                {
                    _noteService.Add(new H_Note {
                        SysType = 2, GroupID = "-1", Name = "M_Reservations", DtType = 0, OpType = 0, Time = DateTime.Now, Desc = "同步工程预约"
                    });
                }
                #endregion

                #region 通知用户审核结果
                var newNotice = new H_Notice {
                    Id          = Guid.NewGuid(),
                    Title       = "工程预约审核结果",
                    Content     = reservation.Status == EnmResult.Failure ? string.Format("您于 [ {0} ] 申请的工程预约 [ {1} ] 由于 [ {2} ] 原因,审核未通过。", reservation.ExpStartTime, reservation.Name, comment) : string.Format("您于 [ {0} ] 申请的工程预约 [ {1} ] 已通过审核,该预约将于[ {2} ]生效。", reservation.ExpStartTime, reservation.Name, reservation.StartTime),
                    CreatedTime = DateTime.Now,
                    Enabled     = true
                };

                var roleId         = _roleService.GetRoleByUid(reservation.UserId).Id;
                var toUsers        = _userService.GetUsersInRole(roleId, false);
                var noticesInUsers = toUsers.Select(u => new H_NoticeInUser {
                    NoticeId = newNotice.Id,
                    UserId   = u.Id,
                    Readed   = false,
                    ReadTime = DateTime.MinValue
                });

                _noticeService.Add(newNotice);
                _noticeInUserService.Add(noticesInUsers.ToArray());
                #endregion

                _webLogger.Information(EnmEventType.Other, string.Format("审核工程预约[ {0} ],审核结果:[ {1} ],预约编号:[ {2} ],预期开始时间:[ {3} ],实际开始时间:[ {4} ],结束时间:[ {5} ],创建人员:[ {6} ],备注[ {7} ]", reservation.Name, Common.GetResStatusDisplay(reservation.Status), reservation.Id, CommonHelper.DateTimeConverter(reservation.ExpStartTime), CommonHelper.DateTimeConverter(reservation.StartTime), CommonHelper.DateTimeConverter(reservation.EndTime), reservation.Creator, reservation.Comment), _workContext.User().Id, null);
                return(Json(new AjaxResultModel {
                    success = true, code = 200, message = "审核完成"
                }));
            } catch (Exception exc) {
                _webLogger.Error(EnmEventType.Other, exc.Message, _workContext.User().Id, exc);
                return(Json(new AjaxResultModel {
                    success = false, code = 400, message = exc.Message
                }));
            }
        }