找不到匹配的方法-JIRA/Groovy
我试图计算某个问题在某个状态下花费的时间。但是遇到了一些错误。下面的脚本进入脚本字段。以下是我的脚本:找不到匹配的方法-JIRA/Groovy,groovy,jira,Groovy,Jira,我试图计算某个问题在某个状态下花费的时间。但是遇到了一些错误。下面的脚本进入脚本字段。以下是我的脚本: import com.atlassian.jira.component.ComponentAccessor def changeHistoryManager = ComponentAccessor.changeHistoryManager def currentStatusName = issue?.status?.name def rt = [0L] changeHistoryManag
import com.atlassian.jira.component.ComponentAccessor
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def currentStatusName = issue?.status?.name
def rt = [0L]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == currentStatusName) {
rt = -timeDiff
}
if (item.toString == currentStatusName){
rt = timeDiff
}
}
return (Math.round(rt.sum() / 3600000)) as Double
错误出现在脚本的最后一行(return语句)。
我不确定我做错了什么
我得到的错误是:
静态类型检查-找不到匹配的java.lang.Object#sum(),也找不到匹配的方法java.lang.Match#round(java.lang.Object)
您正在将
rt
分配给两个if
块中的一个Long。(只是一个long,而不是long数组。)因此没有可用的.sum()
方法
你可以用
rt << -timeDiff
// or
rt << timeDiff
我可以用什么来代替.sum?
import com.atlassian.jira.component.ComponentAccessor
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def currentStatusName = issue?.status?.name
def rt = 0L
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == currentStatusName) {
rt -= timeDiff
}
if (item.toString == currentStatusName){
rt += timeDiff
}
}
return rt / 3600000
// this could still be Math.round(rt/3600000) as Double if you need that; not sure what you're trying to do with the actual result