找不到匹配方法 - JIRA/Groovy
Cannot find matching method - JIRA/Groovy
我正在尝试计算问题在某种状态下花费的时间。但是遇到一些错误。下面的脚本进入脚本字段。下面是我的脚本:
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 语句)。
我不确定我做错了什么。
我得到的错误是:
Static type checking - Cannot find matching java.lang.Object#sum() and Cannot find matching method java.lang.Match#round(java.lang.Object)
您正在将 rt
分配给两个 if
块中的 Long。 (只是一个 long,而不是一个 long 数组。)因此没有 .sum()
方法可用。
你可以使用
rt << -timeDiff
// or
rt << timeDiff
将您的 timeDiffs 添加到数组而不是重新定义它。
您也可以将 rt 初始化为 0,然后根据需要使用 rt += timeDiff
或 rt -= timeDiff
。看起来你根本不需要它作为数组存在。
可能适合您的示例:
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
我正在尝试计算问题在某种状态下花费的时间。但是遇到一些错误。下面的脚本进入脚本字段。下面是我的脚本:
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 语句)。 我不确定我做错了什么。
我得到的错误是:
Static type checking - Cannot find matching java.lang.Object#sum() and Cannot find matching method java.lang.Match#round(java.lang.Object)
您正在将 rt
分配给两个 if
块中的 Long。 (只是一个 long,而不是一个 long 数组。)因此没有 .sum()
方法可用。
你可以使用
rt << -timeDiff
// or
rt << timeDiff
将您的 timeDiffs 添加到数组而不是重新定义它。
您也可以将 rt 初始化为 0,然后根据需要使用 rt += timeDiff
或 rt -= timeDiff
。看起来你根本不需要它作为数组存在。
可能适合您的示例:
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