Exemplo n.º 1
0
        /// <summary>
        /// 发送考勤异常的消息记录消息
        /// </summary>
        /// <param name="calculateAt"></param>
        public void SendAttWarnMsgRecordMessage(DateTime calculateAt, List <string> shiftCodes)
        {
            AttWarnEmailParameter attWarnParam = new AttWarnEmailParameter()
            {
                AttWarnDate = calculateAt,
                ShiftCodes  = shiftCodes
            };
            TaskSetting task = new TaskSetting()
            {
                TaskCreateAt  = DateTime.Now,
                TaskType      = TaskType.AttExceptionWarn,
                JsonParameter = JSONHelper.stringify(attWarnParam),
                LogTaskRound  = false
            };

            SendMQMessage(task);
            //IShiftScheduleService sss = new ShiftSheduleService(this.DbString);
            //List<ShiftScheduleView> shifts = sss.GetDetailViewByDateTime(calculateAt, shiftCodes);
            //if (shifts.Count > 0)
            //{
            //    List<DateTime> datetimes = shifts.Select(s => s.scheduleAt).Distinct().ToList();
            //    foreach (var dt in datetimes)
            //    {
            //        AttWarnParameter attWarnParam = new AttWarnParameter()
            //        {
            //            AttWarnDate = dt,
            //            ShiftCodes = shiftCodes
            //        };


            //        TaskSetting task = new TaskSetting()
            //        {
            //            TaskCreateAt = DateTime.Now,
            //            TaskType = TaskType.AttExceptionWarn,
            //            JsonParameter = JSONHelper.stringify(attWarnParam),
            //            LogTaskRound = false
            //        };

            //        SendMQMessage(task);
            //    }
            //}
        }
Exemplo n.º 2
0
        /// <summary>
        /// 分发任务
        /// </summary>
        /// <param name="ts"></param>
        public void Dispatch(TaskSetting ts)
        {
            ITaskRoundService trs       = new TaskRoundService(this.DbString);
            TaskRound         taskRound = null;

            try
            {
                if (ts.LogTaskRound)
                {
                    taskRound = trs.Create(ts.TaskType);
                }
                LogUtil.Logger.Info("获取到任务信息:");
                LogUtil.Logger.Info(ts.TaskType);
                LogUtil.Logger.Info(ts.JsonParameter);
                switch (ts.TaskType)
                {
                case TaskType.CalAtt:
                    CalAttParameter          calAtt = JSONHelper.parse <CalAttParameter>(ts.JsonParameter);
                    IAttendanceRecordService ars    = new AttendanceRecordService(this.DbString);
                    //ars.CalculateAttendRecord(calAtt.AttCalculateDateTime, calAtt.ShiftCodes);
                    ars.CalculateAttendRecordWithExtrawork(calAtt.AttCalculateDateTime);
                    // add send email to queue
                    SendAttWarnEmailMessage(calAtt.AttCalculateDateTime, calAtt.ShiftCodes);
                    // create message record
                    SendAttWarnMsgRecordMessage(calAtt.AttCalculateDateTime, calAtt.ShiftCodes);
                    break;

                case TaskType.SendMail:
                    break;

                case TaskType.SendAttExceptionMail:
                    AttWarnEmailParameter       attWarn = JSONHelper.parse <AttWarnEmailParameter>(ts.JsonParameter);
                    IAttendanceRecordCalService arcs    = new AttendanceRecordCalService(this.DbString);
                    arcs.SendWarnEmail(attWarn.AttWarnDate);
                    break;

                case TaskType.ToFullMemeberWarn:
                    IMessageRecordService mrs = new MessageRecordService(this.DbString);
                    mrs.CreateToFullMemberMessage(ts.TaskCreateAt.Date);
                    break;

                case TaskType.AttExceptionWarn:
                    AttWarnParameter      attWarnP = JSONHelper.parse <AttWarnParameter>(ts.JsonParameter);
                    IMessageRecordService mrss     = new MessageRecordService(this.DbString);
                    mrss.CreateAttExceptionMessage(attWarnP.AttWarnDate);
                    break;

                case TaskType.ReStartSvc:
                    this.IsRestartSvc = true;
                    break;

                default:
                    throw new TaskTypeNotSupportException();
                }
                if (ts.LogTaskRound && taskRound != null)
                {
                    trs.FinishTaskByUniqId(taskRound.uuid, "任务运行成功");
                }
            }
            catch (Exception ex)
            {
                string msg = string.Format("{0}: {1}", ex.Message, ex.StackTrace);

                LogUtil.Logger.Error("任务执行错误:", ex);

                try
                {
                    if (ts.LogTaskRound && taskRound != null)
                    {
                        trs.FinishTaskByUniqId(taskRound.uuid, msg, true);
                    }
                }
                catch
                {
                }
                throw new Exception(msg, ex);
            }
        }