2013-02-13 56 views
1

我有一個CF計劃任務,通過電子郵件發送給管理員用戶的電話摘要。我想添加爲某些管理員用戶發送報告的功能。附加報告對於每個管理員用戶都是動態的,並存儲在一個表中。我不能只是報告代碼,因爲它可能會改變或不存在爲下一個用戶。也許我應該使用CFHTTP,但我不熟練。從計劃任務內的coldfusion cfhttp帖子

<cfloop query="qGetTelemateEmails">    
    <cfif trim(QGetTime.Call_Email_On_Hour) eq "" or  listfind(#QGetTime.Call_Email_On_Hour#,datepart("h",now()))> 
    <cfset TotalTime = 0> 
    <cfset NumberOfCalls = 0> 
    <cfmail ........></cfmail> 

以下代碼是我想通過電子郵件發送報告的地方。

<cfquery name="QAdditionalReports" datasource="#request.dtsrc#"> 
Select * 
From Admin_Telemate_Additional_Query_Daily as a LEFT OUTER JOIN 
    Admin_Users AS C ON A.AdminID = C.adminID LEFT OUTER JOIN 
    Admin_Telemate_Available_Queries AS b ON A.description = b.description 
where a.adminid = #val(QGetTime.call_admin_user_id)# 
</cfquery> 
<cfif QAdditionalReports.recordcount gt 0> 
SEE CODE BELOW -------------------------------------------------------------  
</cfif> 

</cfif> 
</cfloop> 

這是我想「包含/執行」的報告代碼。我從查詢表條目中獲取代碼的URL。

<cfquery name="QGetCommEct" datasource="#request.dsn#"> 
     select * 
     from Q_ES_Communications_by_Search_Number 
     where upper(communication_type) = 'T' 
     and Date_Entered = '#dateformat(now(),"yyyy/mm/dd")#' 
    and consultant_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#url.adminid#"> 
     order by date_Entered 
    </cfquery> 
    <cfmail> 
     <div style="text-align:center; font-weight:bold; ">Communications Files Query</div> 
    <table> 
    <tr> 
     <td> 
     <table style="font:Arial, Helvetica, sans-serif x-small; border:1px solid black; "> 
     <tr> 
     <td><strong>Type</strong></td> 
     <td><strong>Cons</strong></td> 
     <td><strong>Last Name</strong></td> 
     </tr> 
    <cfoutput query="QGetCommEct">  
    <tr valign="top"> 
     <td>#QGetCommEct.Communication_Type#-#QGetCommEct.Category#</td> 
      <td>#QGetCommEct.AS400_Initials#</td> 
      <td>#QGetCommEct.lastname#</td> 
     </tr> 
    </cfoutput>  
    </table> 
    </td> 
    </tr> 
</table> 
</cfmail> 

我更換了CFIF QAdditionalReports.recordcount GT 0與

<cfloop query="QAdditionalReports"> 
<cfhttp url="#QAdditionalReports.QueryURL##QAdditionalReports.QueryName#?adminid=#val(QGetTime.call_admin_user_id)#&emailto=#qGetTelemateEmails.Telemate_Email#"> 
<cfmail to="[email protected]" from="[email protected]" subject="Recap of daily phone calls" type="html" spoolenable="false"><cfdump var="#cfhttp#"></cfmail> 
</cfloop> 

和電子郵件包含;

struct 
Charset [empty string] 
ErrorDetail [empty string] 
Filecontent [empty string] 
Header HTTP/1.1 503 Server Error Content-Type: text/html Date: Wed, 13 Feb 2013 15:11:17 GMT Server: Microsoft-IIS/7.0 
Mimetype text/html 
Responseheader struct 
Content-Type text/html 
Date Wed, 13 Feb 2013 15:11:17 GMT 
Explanation Server Error 
Http_Version HTTP/1.1 
Server Microsoft-IIS/7.0 
Status_Code 503 

Statuscode 503 Server Error 
Text YES 

這可能是因爲我需要做的HTTPS

+4

有什麼問題嗎? – 2013-02-13 04:25:23

+1

'cfhttp'非常簡單。看看文檔 - http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_g-h_09.html – 2013-02-13 04:26:36

+0

我沒有看到cfhttp進入這個等式的位置。 – Travis 2013-02-13 14:13:05

回答

0

你可以把你想重用和「遠程調用」在CFC或包括其與cfinclude的代碼。

寫一個CFC是最好的方法。 Here is some documentation.

<cfcomponent ...> 
    <cffunction name = "additionalReports" ...> 
     <cfargument name = "adminid" ...> 
     <cfargument name = "emailto" ...> 

     <!--- dynamic query using your adminid here ----> 

     <cfmail to = "#arguments.emailTo#" ...> 
     <!--- nicely formated output ---> 
     </cfmail> 
    </cffunction> 
<cfcomponent> 

你會致電CFC在你的計劃任務這樣

<!--- make the object. assume the cfc is in the same folder named adminreports.cfc ---> 
<cfset reportObject = createObject("component", "adminReports")> 
<cfset reportObject.additionalReports(val(QGetTime.call_admin_user_id), qGetTelemateEmails.Telemate_Email)> 
+0

我想我可以在這個功能中加入一個cfinclude。但是當我到達下一個用戶時會發生什麼情況,並且他們對cfinclude有不同的「附加報告」。 cffunction是否仍然包含之前調用的包含? cfcomponent的持續時間是多少?我在白天每小時運行一次這個過程。 – user990016 2013-02-13 18:43:51

+0

爲什麼每個報告都有不同的文件?我仍然只理解你想要完成的一部分。抱歉。 CFC在請求期間存活,因此每次進程運行時都會創建一個新對象。 – Travis 2013-02-13 18:46:28

+0

但無論哪種方式,您都可以使用cfinclude和動態頁面名稱,前提是queryName是您的文件名:'' – Travis 2013-02-13 18:53:36