public IActionResult Create(SigninRemind signinremind)
        {
            if (ModelState.IsValid)
            {
                if (_context.SigninReminds.Where(m => m.Userid == signinremind.Userid).Count() > 0)//如果存在数据,则更新
                {
                    SigninRemind sr = _context.SigninReminds.Single(m => m.Userid == signinremind.Userid);
                    sr.IsEnable    = signinremind.IsEnable;
                    sr.Name        = signinremind.Name;
                    sr.OffTime     = signinremind.OffTime;
                    sr.RemindMode  = signinremind.RemindMode;
                    sr.WorkTime    = signinremind.WorkTime;
                    sr._OffRemind  = signinremind._OffRemind;
                    sr._WorkRemind = signinremind._WorkRemind;

                    sr.Avatar          = signinremind.Avatar;
                    sr.DeviceId        = signinremind.DeviceId;
                    sr.IsAdmin         = signinremind.IsAdmin;
                    sr.IsBoss          = signinremind.IsBoss;
                    sr.Is_sys          = signinremind.Is_sys;
                    sr.Mobile          = signinremind.Mobile;
                    sr.Sys_level       = signinremind.Sys_level;
                    sr.Position        = signinremind.Position;
                    sr.Department      = signinremind.Department;
                    sr.IsLeaderInDepts = signinremind.IsLeaderInDepts;

                    _context.SaveChanges();
                }
                else
                {
                    signinremind.RegDateTime = DateTime.Now;
                    _context.SigninReminds.Add(signinremind);
                    _context.SaveChanges();
                    //通知管理员
                    Services.DTServerClass.DTSC_SendEnterpriseOaMsg sendoaMsg = new Services.DTServerClass.DTSC_SendEnterpriseOaMsg();
                    sendoaMsg.agentid         = Startup.settings.AgentID;
                    sendoaMsg.msgtype         = "oa";
                    sendoaMsg.touser          = Startup.settings.UserId;
                    sendoaMsg.oa.head.bgcolor = "FFBBBBBB";
                    sendoaMsg.oa.head.text    = "签到提醒";

                    sendoaMsg.oa.body.title     = "新用户注册";
                    sendoaMsg.oa.body.image     = "@lADOADmaWMzazQKA";
                    sendoaMsg.oa.message_url    = settings.Value.Url + "&userid=" + signinremind.Userid;
                    sendoaMsg.oa.pc_message_url = settings.Value.Url + "&userid=" + signinremind.Userid;

                    sendoaMsg.oa.body.form          = new Services.DTServerClass.DTSC_SendEnterpriseOaMsg.OaContent.OaBodyContent.OaBodyFormContent[5];
                    sendoaMsg.oa.body.form[0]       = new Services.DTServerClass.DTSC_SendEnterpriseOaMsg.OaContent.OaBodyContent.OaBodyFormContent();
                    sendoaMsg.oa.body.form[0].key   = "姓名:";
                    sendoaMsg.oa.body.form[0].value = signinremind.Name;

                    sendoaMsg.oa.body.form[1]       = new Services.DTServerClass.DTSC_SendEnterpriseOaMsg.OaContent.OaBodyContent.OaBodyFormContent();
                    sendoaMsg.oa.body.form[1].key   = "上班时间:";
                    sendoaMsg.oa.body.form[1].value = signinremind.WorkTime.HasValue ? signinremind.WorkTime.Value.ToString() : null;

                    sendoaMsg.oa.body.form[2]       = new Services.DTServerClass.DTSC_SendEnterpriseOaMsg.OaContent.OaBodyContent.OaBodyFormContent();
                    sendoaMsg.oa.body.form[2].key   = "下班时间:";
                    sendoaMsg.oa.body.form[2].value = signinremind.OffTime.HasValue ? signinremind.OffTime.Value.ToString() : null;

                    sendoaMsg.oa.body.form[3]       = new Services.DTServerClass.DTSC_SendEnterpriseOaMsg.OaContent.OaBodyContent.OaBodyFormContent();
                    sendoaMsg.oa.body.form[3].key   = "提醒方式:";
                    sendoaMsg.oa.body.form[3].value = signinremind.RemindMode == "App" ? "应用内" : "短信";

                    sendoaMsg.oa.body.form[4]       = new Services.DTServerClass.DTSC_SendEnterpriseOaMsg.OaContent.OaBodyContent.OaBodyFormContent();
                    sendoaMsg.oa.body.form[4].key   = "是否启用:";
                    sendoaMsg.oa.body.form[4].value = signinremind.IsEnable ? "是" : "否";

                    sendoaMsg.oa.body.rich.num  = _context.SigninReminds.Count().ToString();
                    sendoaMsg.oa.body.rich.unit = "名";
                    sendoaMsg.oa.body.author    = settings.Value.UserName;

                    Dictionary <string, string> myDictionary = new Dictionary <string, string>();
                    myDictionary.Add("access_token", Services.Token.GetToken());

                    Services.DTServerClass.GetErrInfo getErrInfo = JsonConvert.DeserializeObject <Services.DTServerClass.GetErrInfo>(httpx.PostJson("https://oapi.dingtalk.com/message/send", JsonConvert.SerializeObject(sendoaMsg), myDictionary));
                }
                return(View("Index1"));
            }
            else
            {
                return(View("Index2"));
            }
        }
Example #2
0
        private void Global_ExecuteTask(object sender, ElapsedEventArgs e)
        {
            DateTime dtm = DateTime.Now;

            Services.Token.GetNewToken();


            TimeSpan dtmsp = TimeSpan.Parse(string.Format("{0}:{1}:{2}", dtm.TimeOfDay.Hours, dtm.TimeOfDay.Minutes, 00));

            if (_context != null)
            {
                var workData = _context.SigninReminds.Where(m => m.IsEnable == true && m.WorkRemind > 0 && TimeSpan.FromMinutes(m.WorkTime.Value.TotalMinutes - m.WorkRemind) == dtmsp).ToList();
                var offData  = _context.SigninReminds.Where(m => m.IsEnable == true && m.OffRemind > 0 && TimeSpan.FromMinutes(m.OffTime.Value.TotalMinutes + m.OffRemind) == dtmsp).ToList();

                string _mobile = string.Empty;
                string _userid = string.Empty;
                Dictionary <string, string> myDictionary;

                if (workData.Count > 0)//开始上班提醒代码
                {
                    var appworkData = workData.Where(p => p.RemindMode == "App");
                    if (appworkData.Count() > 0)
                    {
                        _mobile = string.Empty;

                        Services.DTServerClass.DTSC_SendEnterpriseTextMsg sendtextMsg = new Services.DTServerClass.DTSC_SendEnterpriseTextMsg();
                        sendtextMsg.agentid      = settings.AgentID;
                        sendtextMsg.msgtype      = "text";
                        sendtextMsg.text.content = String.Format("新的一天,从良好的工作习惯开始。快要上班了,赶快签个到吧!");

                        foreach (var item in appworkData)
                        {
                            if (!string.IsNullOrEmpty(item.Userid))
                            {
                                if (string.IsNullOrEmpty(sendtextMsg.touser))
                                {
                                    sendtextMsg.touser = item.Userid;
                                    _mobile            = item.Mobile;
                                }
                                else
                                {
                                    sendtextMsg.touser = string.Format("{0}|{1}", sendtextMsg.touser, item.Userid);
                                    _mobile            = string.Format("{0}|{1}", _mobile, item.Mobile);
                                }
                            }
                        }
                        myDictionary = new Dictionary <string, string>();
                        myDictionary.Add("access_token", Services.Token.GetToken());

                        Services.DTServerClass.GetErrInfo getErrInfo = JsonConvert.DeserializeObject <Services.DTServerClass.GetErrInfo>(httpx.PostJson("https://oapi.dingtalk.com/message/send", JsonConvert.SerializeObject(sendtextMsg), myDictionary));
                        if (getErrInfo.errmsg == "ok")
                        {
                            _context.SendLogTbs.Add(new SendLogTb()
                            {
                                CorpID = settings.CorpID, PushType = "App", Mobile = _mobile, Msgtype = "上班", Content = sendtextMsg.text.content, SendState = true, SendTime = DateTime.Now, Userid = sendtextMsg.touser
                            });
                            _context.SaveChanges();
                        }
                        myDictionary.Clear();
                        getErrInfo  = null;
                        sendtextMsg = null;
                    }
                    //---------短信发送代码开始------------

                    var msgworkData = workData.Where(p => p.RemindMode == "Msg");
                    if (msgworkData.Count() > 0)
                    {
                        _mobile = string.Empty;
                        _userid = string.Empty;
                        foreach (var item in msgworkData)
                        {
                            if (!string.IsNullOrEmpty(item.Userid) && !string.IsNullOrEmpty(item.Mobile))
                            {
                                if (string.IsNullOrEmpty(_mobile))
                                {
                                    _mobile = item.Mobile;
                                    _userid = item.Userid;
                                }
                                else
                                {
                                    _mobile = string.Format("{0};{1}", _mobile, item.Mobile);
                                    _userid = string.Format("{0};{1}", _userid, item.Userid);
                                }
                            }
                        }
                        myDictionary = new Dictionary <string, string>();
                        //企业ID
                        myDictionary.Add("CorpID", settings.SmsCorpID);
                        //登录帐号
                        myDictionary.Add("LoginName", settings.SmsLoginName);
                        //登录密码
                        myDictionary.Add("Passwd", settings.SmsPasswd);
                        //手机号
                        myDictionary.Add("send_no", _mobile);
                        //短信平台中文发送一般会乱码,所以要将中文转为GBK格式
                        myDictionary.Add("msg", HttpUtility.UrlEncode("新的一天,从良好的工作习惯开始。快要上班了,赶快签个到吧!", Encoding.GetEncoding("GBK")));
                        var remsg = httpx.GetJson("http://sms.mobset.com/SDK/Sms_Send.asp", myDictionary);
                        if (remsg != null)
                        {
                            //短信平台第一位返回的是数字,大于0代表发送成功
                            if (remsg[0] > 0)
                            {
                                //发送成功后添加到日志
                                _context.SendLogTbs.Add(new SendLogTb()
                                {
                                    CorpID = settings.CorpID, PushType = "Msg", Mobile = _mobile, Msgtype = "上班", Content = "新的一天,从良好的工作习惯开始。快要上班了,赶快签个到吧!", SendState = true, SendTime = DateTime.Now, Userid = _userid
                                });
                                _context.SaveChanges();
                            }
                        }


                        myDictionary.Clear();
                    }
                    //--------短信发送代码结束-----------
                    msgworkData = null;
                    _mobile     = string.Empty;
                    _userid     = string.Empty;
                    appworkData = null;
                }
                if (offData.Count > 0)//开始下班提醒代码
                {
                    var appoffData = offData.Where(p => p.RemindMode == "App");
                    if (appoffData.Count() > 0)
                    {
                        _mobile = string.Empty;

                        Services.DTServerClass.DTSC_SendEnterpriseTextMsg sendtextMsg = new Services.DTServerClass.DTSC_SendEnterpriseTextMsg();
                        sendtextMsg.agentid      = settings.AgentID;
                        sendtextMsg.msgtype      = "text";
                        sendtextMsg.text.content = String.Format("今天太宝贵,但它一去不复返!已经下班了,赶快签个到吧!");

                        foreach (var item in appoffData)
                        {
                            if (!string.IsNullOrEmpty(item.Userid))
                            {
                                if (string.IsNullOrEmpty(sendtextMsg.touser))
                                {
                                    sendtextMsg.touser = item.Userid;
                                    _mobile            = item.Mobile;
                                }
                                else
                                {
                                    sendtextMsg.touser = string.Format("{0}|{1}", sendtextMsg.touser, item.Userid);
                                    _mobile            = string.Format("{0}|{1}", _mobile, item.Mobile);
                                }
                            }
                        }
                        myDictionary = new Dictionary <string, string>();
                        myDictionary.Add("access_token", Services.Token.GetToken());

                        Services.DTServerClass.GetErrInfo getErrInfo = JsonConvert.DeserializeObject <Services.DTServerClass.GetErrInfo>(httpx.PostJson("https://oapi.dingtalk.com/message/send", JsonConvert.SerializeObject(sendtextMsg), myDictionary));
                        if (getErrInfo.errmsg == "ok")
                        {
                            _context.SendLogTbs.Add(new SendLogTb()
                            {
                                CorpID = settings.CorpID, PushType = "App", Mobile = _mobile, Msgtype = "下班", Content = sendtextMsg.text.content, SendState = true, SendTime = DateTime.Now, Userid = sendtextMsg.touser
                            });
                            _context.SaveChanges();
                        }
                        myDictionary.Clear();
                        getErrInfo  = null;
                        sendtextMsg = null;
                    }
                    appoffData = null;

                    //---------短信发送代码开始------------

                    var msgoffData = offData.Where(p => p.RemindMode == "Msg");
                    if (msgoffData.Count() > 0)
                    {
                        _mobile = string.Empty;
                        _userid = string.Empty;
                        foreach (var item in msgoffData)
                        {
                            if (!string.IsNullOrEmpty(item.Userid) && !string.IsNullOrEmpty(item.Mobile))
                            {
                                if (string.IsNullOrEmpty(_mobile))
                                {
                                    _mobile = item.Mobile;
                                    _userid = item.Userid;
                                }
                                else
                                {
                                    _mobile = string.Format("{0};{1}", _mobile, item.Mobile);
                                    _userid = string.Format("{0};{1}", _userid, item.Userid);
                                }
                            }
                        }
                        myDictionary = new Dictionary <string, string>();
                        myDictionary.Add("CorpID", settings.SmsCorpID);
                        myDictionary.Add("LoginName", settings.SmsLoginName);
                        myDictionary.Add("Passwd", settings.SmsPasswd);
                        myDictionary.Add("send_no", _mobile);
                        myDictionary.Add("msg", HttpUtility.UrlEncode("今天太宝贵,但它一去不复返!已经下班了,赶快签个到吧!", Encoding.GetEncoding("GBK")));
                        var remsg = httpx.GetJson("http://sms.mobset.com/SDK/Sms_Send.asp", myDictionary);
                        if (remsg != null)
                        {
                            if (remsg[0] > 0)
                            {
                                _context.SendLogTbs.Add(new SendLogTb()
                                {
                                    CorpID = settings.CorpID, PushType = "Msg", Mobile = _mobile, Msgtype = "下班", Content = "今天太宝贵,但它一去不复返!已经下班了,赶快签个到吧!", SendState = true, SendTime = DateTime.Now, Userid = _userid
                                });
                                _context.SaveChanges();
                            }
                        }


                        myDictionary.Clear();
                    }
                    //--------短信发送代码结束-----------
                    msgoffData = null;
                    _mobile    = string.Empty;
                    _userid    = string.Empty;
                }
                workData = null;
                offData  = null;
            }
        }