Ejemplo n.º 1
0
        private void Execute(object paremeter)
        {
            ThreadParameter p = paremeter as ThreadParameter;

            if (p.Items == null || p.Items.Count == 0)
            {
                logger.Error("未修改关键字段,document的ID为" + p.DataID + ";");
                return;
            }

            //logger.Error("p.IsAdministrator:" + p.IsAdministrator + ";");
            try
            {
                String         json = Newtonsoft.Json.JsonConvert.SerializeObject(p.Items);
                DocumentHelper dh   = new DocumentHelper();
                Sys_Document   doc  = dh.GetDocumentBaseInfoByID(p.DataID);
                if (doc != null)
                {
                    String    sql = string.Empty;
                    string    JLUserName = string.Empty, JLContent = string.Empty, SGUserName = string.Empty, SGContent = string.Empty;
                    DateTime  JLOPTime = DateTime.Now, SGOPTime = DateTime.Now;
                    DataTable dtJL = new DataTable();
                    #region 处理监理和施工意见
                    if (p.RequestID != Guid.Empty)
                    {
                        sql  = string.Format("SELECT RequestBy,RequestTime,Reason,ApprovePerson,ApproveTime,ProcessReason FROM dbo.sys_request_change WHERE id='{0}'", p.RequestID);
                        dtJL = GetDataTable(sql);
                        if (dtJL != null && dtJL.Rows.Count > 0)
                        {
                            JLUserName = dtJL.Rows[0]["ApprovePerson"] == null ? "" : dtJL.Rows[0]["ApprovePerson"].ToString();
                            JLContent  = dtJL.Rows[0]["ProcessReason"] == null ? "" : dtJL.Rows[0]["ProcessReason"].ToString();
                            SGUserName = dtJL.Rows[0]["RequestBy"] == null ? "" : dtJL.Rows[0]["RequestBy"].ToString();
                            SGContent  = dtJL.Rows[0]["Reason"] == null ? "" : dtJL.Rows[0]["Reason"].ToString();
                            JLOPTime   = dtJL.Rows[0]["ApproveTime"] == null ? DateTime.Now : DateTime.Parse(dtJL.Rows[0]["ApproveTime"].ToString());
                            SGOPTime   = dtJL.Rows[0]["RequestTime"] == null ? DateTime.Now : DateTime.Parse(dtJL.Rows[0]["RequestTime"].ToString());
                            JLContent  = JLContent.Replace("'", " ");
                            SGContent  = SGContent.Replace("'", " ");
                            sql        = "SELECT 1 FROM dbo.sys_KeyModify WHERE RequestID='" + p.RequestID + "' AND ModifyItem='" + json + "'";
                            DataTable dtIsExist = GetDataTable(sql);
                            if (dtIsExist != null && dtIsExist.Rows.Count == 0)
                            {
                                #region INSERT
                                sql = String.Format(@"INSERT INTO dbo.sys_KeyModify
                                ( DataID ,
                                  ModuleID ,
                                  RequestID ,
                                  TestRoomCode ,
                                  BGBH ,
                                  DataName ,
                                  ModifyItem ,
                                  ModifyBy ,
                                  ModifyTime ,
                                  Status,JLUserName ,JLOPTime ,JLContent ,SGUserName ,SGOPTime ,SGContent 
                                )
                        VALUES  ( '{0}' ,
                                  '{1}' ,
                                  '{2}' ,
                                  '{3}' ,
                                  '{4}' ,
                                  '{5}' ,
                                  '{6}' ,
                                  '{7}' ,
                                  GETDATE(),
                                  0,'{8}','{9}','{10}','{11}','{12}','{13}' 
                                )", doc.ID, doc.ModuleID, p.RequestID, doc.TestRoomCode, doc.BGBH, doc.DataName, json, p.UserName, JLUserName, JLOPTime, JLContent, SGUserName, SGOPTime, SGContent);
                                ExcuteCommand(sql);
                                #endregion
                                #region 发送短信
                                if (!p.IsAdministrator && ConfigurationManager.AppSettings["ChangedSMSStart"] == "1")
                                {
                                    String smsContent = GetSMSContent(doc.ID, p.Items, p.UserName, p.RequestID, dtJL);
                                    //logger.Error("smsContent:" + smsContent);
                                    if (String.IsNullOrEmpty(smsContent))
                                    {
                                        logger.Error("未得到短信信息,document的ID为" + p.DataID + ";");
                                        return;
                                    }
                                    String[] cells = GetSMSCells();
                                    if (cells.Length == 0)
                                    {
                                        logger.Error("未设置手机收信人信息,document的ID为" + p.DataID + ";");
                                        return;
                                    }
                                    String     errorMsg   = SMSAgent.CallRemoteService(cells, smsContent);
                                    SMSManager smsManager = new SMSManager();
                                    smsManager.SendAppMessage(p.LineID, doc.ID.ToString(), p.TestRoomCode, p.SegmentName, p.CompanyName, p.TestRoomName, p.LineName, 2, smsContent);
                                    if (!string.IsNullOrEmpty(errorMsg))
                                    {
                                        logger.Error("修改资料短信短信发送完成:" + errorMsg);
                                    }
                                }
                                else
                                {
                                    logger.Error("管理员不发短信或者未打开短信发送开关ChangedSMSCells,document的ID为" + p.DataID.ToString() + "");
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            logger.Error("ChangedSMSCells dtJL Is null or dtJL.Rows.Count==0!DataID:" + p.DataID.ToString() + " RequestID:" + p.RequestID);
                            return;
                        }
                    }
                    else
                    {
                        logger.Error("ChangedSMSCells RequestID Is null!DataID为" + p.DataID.ToString() + "");
                        return;
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                logger.Error("ChangedSMSCells error!DataID为" + p.DataID.ToString() + " ex:" + ex.ToString());
            }
        }