mirror of
https://github.com/hpd840321/starRiverProperty.git
synced 2026-06-09 08:20:31 +08:00
elevator(updateFloors): walkthrough §3.5; guard task null and CloudwalkResult per §2.2
Made-with: Cursor
This commit is contained in:
+1
@@ -18,6 +18,7 @@ public class UpdateFloorsTaskExecutor {
|
||||
threadPoolTaskExecutor.setAllowCoreThreadTimeOut(this.updateFloorsPoolProperties.isAllowCoreThreadTimeOut());
|
||||
threadPoolTaskExecutor.setMaxPoolSize(this.updateFloorsPoolProperties.getMaxPoolSize());
|
||||
threadPoolTaskExecutor.setQueueCapacity(this.updateFloorsPoolProperties.getQueueCapacity());
|
||||
threadPoolTaskExecutor.setKeepAliveSeconds(this.updateFloorsPoolProperties.getKeepAliveSeconds());
|
||||
threadPoolTaskExecutor.setThreadNamePrefix("update-floors-pool-");
|
||||
threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
|
||||
threadPoolTaskExecutor.initialize();
|
||||
|
||||
+31
-4
@@ -2,6 +2,7 @@ package cn.cloudwalk.elevator.device.impl;
|
||||
|
||||
import cn.cloudwalk.cloud.context.CloudwalkCallContext;
|
||||
import cn.cloudwalk.cloud.exception.ServiceException;
|
||||
import cn.cloudwalk.cloud.result.CloudwalkResult;
|
||||
import cn.cloudwalk.elevator.common.AbstractAcsDeviceService;
|
||||
import cn.cloudwalk.elevator.device.dao.AcsDeviceTaskDao;
|
||||
import cn.cloudwalk.elevator.device.dto.AcsDeviceTaskAddDto;
|
||||
@@ -46,6 +47,10 @@ public class AcsDeviceTaskServiceImpl extends AbstractAcsDeviceService implement
|
||||
if (!CollectionUtils.isEmpty(addFloors)) {
|
||||
for (AcsPassRuleImageResultDto addFloor : addFloors) {
|
||||
AcsDeviceTaskDTO task = this.acsDeviceTaskDao.getById(param.getTaskId());
|
||||
if (task == null) {
|
||||
this.logger.error("updateFloors 任务不存在 taskId={}", param.getTaskId());
|
||||
throw new ServiceException("设备任务不存在");
|
||||
}
|
||||
if (task.getIsStop().intValue() == 0) {
|
||||
if (!ObjectUtils.isEmpty(param.getPersonId())) {
|
||||
AcsPersonAddParam addParam = new AcsPersonAddParam();
|
||||
@@ -53,7 +58,8 @@ public class AcsDeviceTaskServiceImpl extends AbstractAcsDeviceService implement
|
||||
addParam.setParentId(param.getParentId());
|
||||
addParam.setZoneId(addFloor.getZoneId());
|
||||
addParam.setZoneName(addFloor.getZoneName());
|
||||
this.personRuleService.add(addParam, context);
|
||||
CloudwalkResult<Boolean> addResult = this.personRuleService.add(addParam, context);
|
||||
requireTaskStepSuccess(addResult, "personRuleService.add");
|
||||
} else {
|
||||
AcsPassRuleNewParam ruleParam = new AcsPassRuleNewParam();
|
||||
ruleParam.setParentId(param.getParentId());
|
||||
@@ -67,7 +73,9 @@ public class AcsDeviceTaskServiceImpl extends AbstractAcsDeviceService implement
|
||||
ruleParam.setIncludeOrganizations(Collections.singletonList(param.getOrgId()));
|
||||
ruleParam.setRuleName(addFloor.getZoneName() + param.getOrgName());
|
||||
}
|
||||
this.imageRuleRefService.addOnlyRule(ruleParam, context);
|
||||
CloudwalkResult<Boolean> addRuleResult =
|
||||
this.imageRuleRefService.addOnlyRule(ruleParam, context);
|
||||
requireTaskStepSuccess(addRuleResult, "imageRuleRefService.addOnlyRule");
|
||||
}
|
||||
AcsDeviceTaskAddDto addDto = new AcsDeviceTaskAddDto();
|
||||
addDto.setId(task.getId());
|
||||
@@ -82,13 +90,18 @@ public class AcsDeviceTaskServiceImpl extends AbstractAcsDeviceService implement
|
||||
ruleList.forEach(rule -> ruleMap.put(rule.getZoneId(), rule.getZoneName()));
|
||||
for (String delFloorId : delFloorIds) {
|
||||
AcsDeviceTaskDTO task = this.acsDeviceTaskDao.getById(param.getTaskId());
|
||||
if (task == null) {
|
||||
this.logger.error("updateFloors 任务不存在 taskId={}", param.getTaskId());
|
||||
throw new ServiceException("设备任务不存在");
|
||||
}
|
||||
if (task.getIsStop().intValue() == 0) {
|
||||
if (!ObjectUtils.isEmpty(param.getPersonId())) {
|
||||
AcsPersonDeleteParam delParam = new AcsPersonDeleteParam();
|
||||
delParam.setParentId(param.getParentId());
|
||||
delParam.setZoneId(delFloorId);
|
||||
delParam.setPersonIds(Collections.singletonList(param.getPersonId()));
|
||||
this.personRuleService.delete(delParam, context);
|
||||
CloudwalkResult<Boolean> delResult = this.personRuleService.delete(delParam, context);
|
||||
requireTaskStepSuccess(delResult, "personRuleService.delete");
|
||||
} else {
|
||||
String ruleName = "";
|
||||
if (!ObjectUtils.isEmpty(param.getLabelName())) {
|
||||
@@ -103,7 +116,9 @@ public class AcsDeviceTaskServiceImpl extends AbstractAcsDeviceService implement
|
||||
deleteParam.setIds(Collections.singletonList(ruleId));
|
||||
deleteParam.setZoneId(delFloorId);
|
||||
deleteParam.setParentId(param.getParentId());
|
||||
this.imageRuleRefService.delete(deleteParam, context);
|
||||
CloudwalkResult<Boolean> delRuleResult =
|
||||
this.imageRuleRefService.delete(deleteParam, context);
|
||||
requireTaskStepSuccess(delRuleResult, "imageRuleRefService.delete");
|
||||
} else {
|
||||
AcsPassRuleDeleteDto dto = new AcsPassRuleDeleteDto();
|
||||
dto.setZoneId(delFloorId);
|
||||
@@ -124,4 +139,16 @@ public class AcsDeviceTaskServiceImpl extends AbstractAcsDeviceService implement
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 约定 §2.2:异步任务内对业务服务返回的 {@link CloudwalkResult} 须校验成功后再推进进度(避免失败仍递增 bindDevices)。
|
||||
*/
|
||||
private void requireTaskStepSuccess(CloudwalkResult<?> result, String op) throws ServiceException {
|
||||
if (result == null || !result.isSuccess()) {
|
||||
String code = result != null ? result.getCode() : "76260540";
|
||||
String msg = result != null ? result.getMessage() : op + " 返回为空";
|
||||
this.logger.error("updateFloors 步骤失败 op={} code={} msg={}", op, code, msg);
|
||||
throw new ServiceException(code, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user