groovy - 找不到匹配方法 - 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 语句)。我不确定我做错了什么。
我得到的错误是:
静态类型检查 - 找不到匹配的 java.lang.Object#sum() 和找不到匹配的方法 java.lang.Match#round(java.lang.Object)
解决方案
您在两个块中分配rt
一个 Long 。if
(只是一个 long,而不是 long 数组。)因此没有.sum()
可用的方法。
你可以使用
rt << -timeDiff
// or
rt << timeDiff
将您的 timeDiffs 添加到数组中,而不是重新定义它。
您也可以将 rt 初始化为 0,然后使用rt += timeDiff
orrt -= 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
推荐阅读
- gem5 - 优先读取优先于写入
- tensorflow - Keras LSTM 的维度问题
- apache-spark - VectorAssembler 强制数据进入驱动程序。我们怎样才能避免呢?
- eclipse - 我应该在 LiClipse 中注册哪些“可用软件站点”才能成功升级?
- flutter - 单击复选框或按钮时,如何检测是否按下了键?
- matlab - 图像中的平均像素(Matlab)
- r - 在 R 中使用 rjson 包读取 iso_3166_2.js
- python - 梯度下降图是如何工作的
- kotlin - 使用 Dagger Hilt 解决多个字符串的注入
- amazon-redshift - 将 `GETDATE()` Redshift 函数与 psycopg2 execute_values 一起使用