コード例 #1
0
ファイル: TaskPush.cs プロジェクト: Cloud33/K2.Tasks-Service
 public static void SaveMsgId(QuanShiMsgModel msg)
 {
     using (SqlConnection conn = new SqlConnection(TasksDB))
     {
         conn.Open();
         SqlCommand comm = new SqlCommand("INSERT INTO [dbo].[QuanShiMsg]([sysId],[msgId]) values(@sysId,@msgId)", conn);
         //@ProcInstID,@Folio,@ActivityName,@ProcessName,@Destination,@SN,@BusinessData,@Data,@Status,@State,@CreationTime,@SendTime
         comm.Parameters.Add(new SqlParameter("@sysId", SqlNull(msg.sysId)));
         comm.Parameters.Add(new SqlParameter("@msgId", SqlNull(msg.msgId)));
         int i = comm.ExecuteNonQuery();
         conn.Close();
     }
 }
コード例 #2
0
ファイル: TaskPush.cs プロジェクト: Cloud33/K2.Tasks-Service
        public static int QuanShiPush(TaskDto task, string[] actions, log4net.ILog logger)
        {
            //_sem.Wait();
            try
            {
                //var CreateQuanShiToKenAsync = TaskPush.CreateQuanShiToKenAsync();
                //_sem.Wait();
                string data = TaskPush.CreateQuanShiToKen();
                LoginRequestModel re = new LoginRequestModel();
                re = JsonConvert.DeserializeObject<LoginRequestModel>(data);

                if (re.crrorCode == 0)
                {
                    OANewsModel oa = new OANewsModel();
                    oa.username = re.data.username;
                    oa.token = re.data.token;
                    OANewsDataModel oaData = new OANewsDataModel();
                    List<string> users = new List<string>();
                    if (string.IsNullOrEmpty(IsEmail))
                    {
                        users.Add(task.Destination.Replace(WindowDomain + @"\", ""));
                    }
                    else
                    {
                        users.Add(task.Destination.Replace(WindowDomain + @"\", "") + IsEmail);
                    }
                    oaData.toUsers = users.ToArray();
                    oaData.toPartyIds = new int[] { };
                    oaData.appId = 136;
                    oaData.title = task.Folio;
                    oaData.color = "red";
                    oaData.status = 11;
                    oaData.elements = new List<object>();
                    string sharedUser = string.IsNullOrEmpty(task.SharedUser) ? "null" : task.SharedUser;
                    oaData.detailURL = string.Format(TaskUrl + "task/{0}/{1}/{2}/{3}", task.SN, task.ProcInstID, System.Web.HttpUtility.UrlEncode(task.Destination), sharedUser);
                    oaData.detailAuth = 1;
                    //申请信息
                    OANewsDataTextRichModel text1 = new OANewsDataTextRichModel();
                    text1.type = "text";
                    //text1.status = 11;
                    text1.content = new List<OANewsDataTextContentModel>();
                    OANewsDataTextContentModel content = new OANewsDataTextContentModel() { size = 2, bold = 1, text = "申请信息" };
                    text1.content.Add(content);
                    oaData.elements.Add(text1);

                    OANewsDataTextModel text6 = new OANewsDataTextModel() { type = "text", content = " " };
                    oaData.elements.Add(text6);

                    //申请人
                    OANewsDataTextRichModel text2 = new OANewsDataTextRichModel();
                    text2.type = "text";
                    //text2.status = 11;
                    text2.content = new List<OANewsDataTextContentModel>();
                    content = new OANewsDataTextContentModel() { bold = 1, text = "申请人:" };
                    text2.content.Add(content);
                    content = new OANewsDataTextContentModel() { bold = 0, text = task.Originator };
                    text2.content.Add(content);
                    oaData.elements.Add(text2);

                    OANewsDataTextRichModel text3 = new OANewsDataTextRichModel();
                    text3.type = "text";
                    //text3.status = 11;
                    text3.content = new List<OANewsDataTextContentModel>();
                    content = new OANewsDataTextContentModel() { bold = 1, text = "申请时间:" };
                    text3.content.Add(content);
                    content = new OANewsDataTextContentModel() { bold = 0, text = task.StartDate.ToString("yyyy-MM-dd HH:mm") };
                    text3.content.Add(content);
                    oaData.elements.Add(text3);

                    OANewsDataTextRichModel text4 = new OANewsDataTextRichModel();
                    text4.type = "text";
                    //text4.status = 11;
                    text4.content = new List<OANewsDataTextContentModel>();
                    content = new OANewsDataTextContentModel() { bold = 1, text = "当前环节:" };
                    text4.content.Add(content);
                    content = new OANewsDataTextContentModel() { bold = 0, text = task.ActivityName };
                    text4.content.Add(content);
                    oaData.elements.Add(text4);
                    OANewsDataTextModel text7 = new OANewsDataTextModel() { type = "text", content = " " };
                    oaData.elements.Add(text7);
                    //操作
                    OANewsDataTextRichModel text5 = new OANewsDataTextRichModel();
                    text5.type = "text";
                    text5.status = 11;
                    text5.content = new List<OANewsDataTextContentModel>();
                    content = new OANewsDataTextContentModel() { size = 2, bold = 1, text = "操作" };
                    text5.content.Add(content);
                    oaData.elements.Add(text5);

                    //操作
                    OANewsDataTextRichModel text11 = new OANewsDataTextRichModel();
                    text11.type = "text";
                    text11.status = 12;
                    text11.content = new List<OANewsDataTextContentModel>();
                    content = new OANewsDataTextContentModel() { size = 2, bold = 1, text = "操作" };
                    text11.content.Add(content);
                    oaData.elements.Add(text11);

                    OANewsDataTextRichModel text10 = new OANewsDataTextRichModel();
                    text10.type = "text";
                    text10.status = 12;
                    text10.content = new List<OANewsDataTextContentModel>();
                    content = new OANewsDataTextContentModel() { color = "#FF0000", bold = 1, text = "审批过程中出现错误,请重试或联系管理员处理!" };
                    text10.content.Add(content);
                    oaData.elements.Add(text10);
                    // status=11
                    OANewsDataActionModel action = new OANewsDataActionModel();
                    action.type = "action";
                    action.status = 11;
                    action.buttons = new List<OANewsDataButtonModel>();

                    Guid sysId = Guid.NewGuid();
                    foreach (var item in actions)
                    {

                        string actionUrl = string.Format(TaskUrl + "quanShiExecuteTask?ActionName={0}&SN={1}&Destination={2}&SharedUser={3}&ProcInstID={4}", System.Web.HttpUtility.UrlEncode(item), task.SN, System.Web.HttpUtility.UrlEncode(task.Destination), sharedUser, sysId);
                        OANewsDataButtonModel button = new OANewsDataButtonModel() { title = item, url = actionUrl };
                        action.buttons.Add(button);
                    }
                    oaData.elements.Add(action);

                    // status=11
                    action = new OANewsDataActionModel();
                    action.type = "action";
                    action.status = 12;
                    action.buttons = new List<OANewsDataButtonModel>();
                    foreach (var item in actions)
                    {

                        string actionUrl = string.Format(TaskUrl + "quanShiExecuteTask?ActionName={0}&SN={1}&Destination={2}&SharedUser={3}&ProcInstID={4}", System.Web.HttpUtility.UrlEncode(item), task.SN, System.Web.HttpUtility.UrlEncode(task.Destination), sharedUser, sysId);
                        OANewsDataButtonModel button = new OANewsDataButtonModel() { title = item, url = actionUrl };
                        action.buttons.Add(button);
                    }
                    oaData.elements.Add(action);



                    //状态
                    OANewsDataTextRichModel text8 = new OANewsDataTextRichModel();
                    text8.type = "text";
                    text8.status = 1;
                    text8.content = new List<OANewsDataTextContentModel>();
                    content = new OANewsDataTextContentModel() { bold = 1, color = "#808080", text = "状态:" };
                    text8.content.Add(content);
                    content = new OANewsDataTextContentModel() { bold = 0, color = "#FF0000", text = "已处理" };
                    text8.content.Add(content);
                    oaData.elements.Add(text8);

                    OANewsDataTextRichModel text9 = new OANewsDataTextRichModel();
                    text9.type = "text";
                    text9.status = 9;
                    text9.content = new List<OANewsDataTextContentModel>();
                    content = new OANewsDataTextContentModel() { bold = 1, color = "#808080", text = "状态:" };
                    text9.content.Add(content);
                    content = new OANewsDataTextContentModel() { bold = 0, color = "#FF0000", text = "任务已经被处理" };
                    text9.content.Add(content);
                    oaData.elements.Add(text9);

                    oa.data = oaData;
                    string psp = JsonConvert.SerializeObject(oa);
                    //var CreateQuanShiOAAsync = TaskPush.CreateQuanShiOAAsync(psp);
                    string dataCheck = TaskPush.PostWebRequest(QuanShiOASendAPIUrl, psp, Encoding.UTF8);
                    JObject obj = JObject.Parse(dataCheck);
                    if (obj["errorCode"].ToString() == "0")
                    {
                        QuanShiMsgModel msg = new QuanShiMsgModel() { sysId = sysId.ToString(), msgId = obj["data"][0]["msgId"].ToString() };
                        SaveMsgId(msg);
                        logger.Info("QuanShiPush_任务推送请求成功,请求消息:" + psp + ";返回消息:" + dataCheck);

                    }
                    else
                    {
                        logger.Error("QuanShiPush_任务推送请求失败,请求消息:" + psp + ";返回消息:" + dataCheck);
                    }
                }
                //_sem.Release();
                return 1;
            }
            catch (Exception ex)
            {
                logger.Error("QuanShiPush_请求失败,在执行过程中出现异常", ex);
                //_sem.Release();
                return 2;
            }
        }