gpt4 book ai didi

缺少 JavaScript;在 for 循环初始化程序之后(来源未知

转载 作者:行者123 更新时间:2023-12-03 04:52:42 25 4
gpt4 key购买 nike

以下代码是我尝试运行的javascript(没有导入或初始变量声明,即使用的导入函数和下面所示的triggerStatus等变量已经声明但未粘贴)。我运行时收到的错误是 Error Running Script [scriptToRun.js]:com.sun.phobos.script.util.ExtendedScriptException: org.mozilla.javascript.EvaluatorException: missing ; after for-loop initializer (<Unknown source>#49) in <Unknown source> at line number 49

function runScript() {
let (survey = newDocument,
statusQuery = new AeSpcsrvySDTO()) {
logger.fine('Space survey [' + survey.spaceSurvey + ']');
// Look up the status
statusQuery.statusCode = survey.statusCode;
let (statuses = new StatusServiceImpl(SystemContext.getInstance()).findByDTO(statusQuery, null)) {
let (status = statuses.get(0)) {
logger.fine('Space survey [' + survey.spaceSurvey + ']'
+ ' status [' + survey.statusCode + ']'
+ ' completeYn [' + AeSpcsrvySCompleteYN.valueOfFromCode(status.completeYn).name() + ']');
if (status.completeYn != triggerStatus.code) {
logger.fine('Ignoring space survey [' + survey.spaceSurvey + ']');
return;
}
logger.fine('Space survey [' + survey.spaceSurvey + ']'
+ ' has ' + survey.aeSpcsrvyLocDTOList.size() + ' locations');
for (let location in Iterator(survey.aeSpcsrvyLocDTOList)) {
logger.fine('Space survey [' + location.spaceSurvey + ']'
+ ' region [' + location.regionCode + ']'
+ ' facility [' + location.facId + ']'
+ ' property [' + location.bldg + ']'
+ ' location [' + location.locId + ']');
let (highestUsagePercent = BigDecimal.ZERO,
highestUsage = null) {
for (let occupancy in Iterator(location.aeSpcsrvyOccDTOList)) {
logger.fine('Space survey [' + occupancy.spaceSurvey + ']'
+ ' region [' + occupancy.regionCode + ']'
+ ' facility [' + occupancy.facId + ']'
+ ' property [' + occupancy.bldg + ']'
+ ' location [' + occupancy.locId + ']'
+ ' seq [' + occupancy.seq + ']'
+ ' percent [' + occupancy.percentOccupancy + ']');
let (proration = occupancy.percentOccupancy.movePointLeft(2)) {
for (let usage in Iterator(occupancy.aeSpcsrvyOccUsgDTOList)) {
logger.fine('Space survey [' + usage.spaceSurvey + ']'
+ ' region [' + usage.regionCode + ']'
+ ' facility [' + usage.facId + ']'
+ ' property [' + usage.bldg + ']'
+ ' location [' + usage.locId + ']'
+ ' seq [' + usage.seq + ']'
+ ' sub seq [' + usage.subSeq + ']'
+ ' usage code [' + usage.usageCode + ']'
+ ' percent [' + usage.usagePercent + ']');
if (usage.usageCode && usage.usagePercent
// There's a validation for <= 100, but not for > 0.
&& usage.usagePercent.compareTo(BigDecimal.ZERO) > 0) {
let (proratedUsagePercent = usage.usagePercent.multiply(proration)) {
if (proratedUsagePercent.compareTo(highestUsagePercent) > 0
|| (proratedUsagePercent.compareTo(highestUsagePercent) == 0
&& usage.usageCode.compareTo(highestUsage.usageCode) < 0)) {
highestUsage = usage;
highestUsagePercent = proratedUsagePercent;
logger.fine('New highest usage percent is [' + highestUsagePercent + ']');
}
}
}
}
}
}
if (highestUsage) {
// Look up the location and update the usage.
let (locationKey = new AeBLocDPK(highestUsage.regionCode, highestUsage.facId,
highestUsage.bldg, highestUsage.locId),
serviceImpl = new PropertyServiceImpl(SystemContext.getInstance())) {
let (location = serviceImpl.findByPrimaryKey(locationKey, false)) {
location.usageCode = highestUsage.usageCode;
serviceImpl.save(location, false, false);
}
}
}
}
}
}
}
}
}

查看指定的第 49 行和周围的 for 循环语法,我没有看到问题,我是否遗漏了什么?

谢谢

更新使用 AP 的建议进行更改,我收到一个新错误:当前代码(错误行 3:缺少 ; 之前的语句):

function runScript() {
'use strict';
let survey = newDocument,
statusQuery = new AeSpcsrvySDTO();
logger.fine('Space survey [' + survey.spaceSurvey + ']');
// Look up the status
statusQuery.statusCode = survey.statusCode;
let statuses = new StatusServiceImpl(SystemContext.getInstance()).findByDTO(statusQuery, null);
let status = statuses.get(0);
logger.fine('Space survey [' + survey.spaceSurvey + ']' +
' status [' + survey.statusCode + ']' +
' completeYn [' + AeSpcsrvySCompleteYN.valueOfFromCode(status.completeYn).name() + ']');
if (status.completeYn != triggerStatus.code) {
logger.fine('Ignoring space survey [' + survey.spaceSurvey + ']');
return;
}
logger.fine('Space survey [' + survey.spaceSurvey + ']' +
' has ' + survey.aeSpcsrvyLocDTOList.size() + ' locations');
for (let location in Iterator(survey.aeSpcsrvyLocDTOList)) {
logger.fine('Space survey [' + location.spaceSurvey + ']' +
' region [' + location.regionCode + ']' +
' facility [' + location.facId + ']' +
' property [' + location.bldg + ']' +
' location [' + location.locId + ']');
let highestUsagePercent = BigDecimal.ZERO,
highestUsage = null;
for (let occupancy in Iterator(location.aeSpcsrvyOccDTOList)) {
logger.fine('Space survey [' + occupancy.spaceSurvey + ']' +
' region [' + occupancy.regionCode + ']' +
' facility [' + occupancy.facId + ']' +
' property [' + occupancy.bldg + ']' +
' location [' + occupancy.locId + ']' +
' seq [' + occupancy.seq + ']' +
' percent [' + occupancy.percentOccupancy + ']');
let proration = occupancy.percentOccupancy.movePointLeft(2);
for (let usage in Iterator(occupancy.aeSpcsrvyOccUsgDTOList)) {
logger.fine('Space survey [' + usage.spaceSurvey + ']' +
' region [' + usage.regionCode + ']' +
' facility [' + usage.facId + ']' +
' property [' + usage.bldg + ']' +
' location [' + usage.locId + ']' +
' seq [' + usage.seq + ']' +
' sub seq [' + usage.subSeq + ']' +
' usage code [' + usage.usageCode + ']' +
' percent [' + usage.usagePercent + ']');
if (usage.usageCode && usage.usagePercent
// There's a validation for <= 100, but not for > 0.
&&
usage.usagePercent.compareTo(BigDecimal.ZERO) > 0) {
let proratedUsagePercent = usage.usagePercent.multiply(proration);
if (proratedUsagePercent.compareTo(highestUsagePercent) > 0 ||
(proratedUsagePercent.compareTo(highestUsagePercent) == 0 &&
usage.usageCode.compareTo(highestUsage.usageCode) < 0)) {
highestUsage = usage;
highestUsagePercent = proratedUsagePercent;
logger.fine('New highest usage percent is [' + highestUsagePercent + ']');
}

}
}

}
if (highestUsage) {
// Look up the location and update the usage.
let locationKey = new AeBLocDPK(highestUsage.regionCode, highestUsage.facId, highestUsage.bldg, highestUsage.locId),
serviceImpl = new PropertyServiceImpl(SystemContext.getInstance());
let location = serviceImpl.findByPrimaryKey(locationKey, false);
location.usageCode = highestUsage.usageCode;
serviceImpl.save(location, false, false);
}
}
}

最佳答案

不确定您想通过此 block 实现什么目的:

 let (proratedUsagePercent = usage.usagePercent.multiply(proration)) {
if (proratedUsagePercent.compareTo(highestUsagePercent) > 0
|| (proratedUsagePercent.compareTo(highestUsagePercent) == 0
&& usage.usageCode.compareTo(highestUsage.usageCode) < 0)) {
highestUsage = usage;
highestUsagePercent = proratedUsagePercent;
logger.fine('New highest usage percent is [' + highestUsagePercent + ']');
}
}

您不能在 let 表达式 前面添加 block ,也许将其更改为:

let proratedUsagePercent = usage.usagePercent.multiply(proration)
if (proratedUsagePercent.compareTo(highestUsagePercent) > 0
|| (proratedUsagePercent.compareTo(highestUsagePercent) == 0
&& usage.usageCode.compareTo(highestUsage.usageCode) < 0)) {
highestUsage = usage;
highestUsagePercent = proratedUsagePercent;
logger.fine('New highest usage percent is [' + highestUsagePercent + ']');
}

另外:也许您的浏览器可能不支持严格模式之外的let声明。将其替换为 var 或将 'use strict;'(带引号)添加到函数顶部。

关于缺少 JavaScript;在 for 循环初始化程序之后(来源未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42588090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com