增加App与Topic自动化审批开关

This commit is contained in:
zengqiao
2021-04-28 10:48:17 +08:00
parent fe5cf2d922
commit 65e3782b2e
4 changed files with 16 additions and 10 deletions

View File

@@ -1,6 +1,5 @@
package com.xiaojukeji.kafka.manager.task.dispatch.op; package com.xiaojukeji.kafka.manager.task.dispatch.op;
import com.alibaba.fastjson.JSON;
import com.xiaojukeji.kafka.manager.bpm.OrderService; import com.xiaojukeji.kafka.manager.bpm.OrderService;
import com.xiaojukeji.kafka.manager.bpm.common.OrderStatusEnum; import com.xiaojukeji.kafka.manager.bpm.common.OrderStatusEnum;
import com.xiaojukeji.kafka.manager.bpm.common.OrderTypeEnum; import com.xiaojukeji.kafka.manager.bpm.common.OrderTypeEnum;
@@ -11,6 +10,7 @@ import com.xiaojukeji.kafka.manager.common.constant.TopicCreationConstant;
import com.xiaojukeji.kafka.manager.common.entity.ResultStatus; import com.xiaojukeji.kafka.manager.common.entity.ResultStatus;
import com.xiaojukeji.kafka.manager.common.entity.ao.config.CreateTopicElemConfig; import com.xiaojukeji.kafka.manager.common.entity.ao.config.CreateTopicElemConfig;
import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.OrderExtensionApplyTopicDTO; import com.xiaojukeji.kafka.manager.bpm.common.entry.apply.OrderExtensionApplyTopicDTO;
import com.xiaojukeji.kafka.manager.common.utils.JsonUtils;
import com.xiaojukeji.kafka.manager.common.utils.ListUtils; import com.xiaojukeji.kafka.manager.common.utils.ListUtils;
import com.xiaojukeji.kafka.manager.common.utils.ValidateUtils; import com.xiaojukeji.kafka.manager.common.utils.ValidateUtils;
import com.xiaojukeji.kafka.manager.common.entity.pojo.*; import com.xiaojukeji.kafka.manager.common.entity.pojo.*;
@@ -23,6 +23,7 @@ import com.xiaojukeji.kafka.manager.task.component.EmptyEntry;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Arrays; import java.util.Arrays;
@@ -35,6 +36,7 @@ import java.util.Properties;
*/ */
@Component @Component
@CustomScheduled(name = "autoHandleTopicOrder", cron = "0 0/1 * * * ?", threadNum = 1) @CustomScheduled(name = "autoHandleTopicOrder", cron = "0 0/1 * * * ?", threadNum = 1)
@ConditionalOnProperty(prefix = "task.op.order-auto-exec", name = "topic-enabled", havingValue = "true", matchIfMissing = false)
public class AutoHandleTopicOrder extends AbstractScheduledTask<EmptyEntry> { public class AutoHandleTopicOrder extends AbstractScheduledTask<EmptyEntry> {
private static final Logger LOGGER = LoggerFactory.getLogger(LogConstant.SCHEDULED_TASK_LOGGER); private static final Logger LOGGER = LoggerFactory.getLogger(LogConstant.SCHEDULED_TASK_LOGGER);
@@ -72,11 +74,8 @@ public class AutoHandleTopicOrder extends AbstractScheduledTask<EmptyEntry> {
Integer maxPassedOrderNumPerTask = configService.getAutoPassedTopicApplyOrderNumPerTask(); Integer maxPassedOrderNumPerTask = configService.getAutoPassedTopicApplyOrderNumPerTask();
for (OrderDO orderDO: doList) { for (OrderDO orderDO: doList) {
if (!OrderTypeEnum.APPLY_TOPIC.getCode().equals(orderDO.getType())) {
continue;
}
try { try {
if (!handleApplyTopicOrder(orderDO)) { if (!OrderTypeEnum.APPLY_TOPIC.getCode().equals(orderDO.getType()) && !handleApplyTopicOrder(orderDO)) {
continue; continue;
} }
maxPassedOrderNumPerTask -= 1; maxPassedOrderNumPerTask -= 1;
@@ -91,7 +90,7 @@ public class AutoHandleTopicOrder extends AbstractScheduledTask<EmptyEntry> {
} }
private boolean handleApplyTopicOrder(OrderDO orderDO) { private boolean handleApplyTopicOrder(OrderDO orderDO) {
OrderExtensionApplyTopicDTO dto = JSON.parseObject(orderDO.getExtensions(), OrderExtensionApplyTopicDTO.class); OrderExtensionApplyTopicDTO dto = JsonUtils.stringToObj(orderDO.getExtensions(), OrderExtensionApplyTopicDTO.class);
Long physicalClusterId = Long physicalClusterId =
logicalClusterMetadataManager.getPhysicalClusterId(dto.getClusterId(), dto.isPhysicalClusterId()); logicalClusterMetadataManager.getPhysicalClusterId(dto.getClusterId(), dto.isPhysicalClusterId());

View File

@@ -20,6 +20,7 @@ import com.xiaojukeji.kafka.manager.task.component.EmptyEntry;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.*; import java.util.*;
@@ -31,6 +32,7 @@ import java.util.*;
*/ */
@Component @Component
@CustomScheduled(name = "automatedHandleOrder", cron = "0 0/1 * * * ?", threadNum = 1) @CustomScheduled(name = "automatedHandleOrder", cron = "0 0/1 * * * ?", threadNum = 1)
@ConditionalOnProperty(prefix = "task.op.order-auto-exec", name = "app-enabled", havingValue = "true", matchIfMissing = false)
public class AutomatedHandleOrder extends AbstractScheduledTask<EmptyEntry> { public class AutomatedHandleOrder extends AbstractScheduledTask<EmptyEntry> {
private static final Logger LOGGER = LoggerFactory.getLogger(LogConstant.SCHEDULED_TASK_LOGGER); private static final Logger LOGGER = LoggerFactory.getLogger(LogConstant.SCHEDULED_TASK_LOGGER);
@@ -51,6 +53,7 @@ public class AutomatedHandleOrder extends AbstractScheduledTask<EmptyEntry> {
public void processTask(EmptyEntry entryEntry) { public void processTask(EmptyEntry entryEntry) {
List<OrderDO> waitDealOrderList = orderService.getWaitDealOrder(); List<OrderDO> waitDealOrderList = orderService.getWaitDealOrder();
if (ValidateUtils.isEmptyList(waitDealOrderList)) { if (ValidateUtils.isEmptyList(waitDealOrderList)) {
LOGGER.info("class=AutomatedHandleOrder||method=processTask||msg=waiting deal order is empty");
return; return;
} }
@@ -65,17 +68,18 @@ public class AutomatedHandleOrder extends AbstractScheduledTask<EmptyEntry> {
} }
private void handleAppApplyOrder(List<OrderDO> waitDealOrderList, List<OrderDO> passedOrderList) { private void handleAppApplyOrder(List<OrderDO> waitDealOrderList, List<OrderDO> passedOrderList) {
LOGGER.info("start handle app apply order."); LOGGER.info("class=AutomatedHandleOrder||method=processTask||msg=start handle app apply order");
if (ValidateUtils.isEmptyList(waitDealOrderList)) { if (ValidateUtils.isEmptyList(waitDealOrderList)) {
return; return;
} }
Integer maxNum = Constant.HANDLE_APP_APPLY_MAX_NUM_DEFAULT; Integer maxNum = Constant.HANDLE_APP_APPLY_MAX_NUM_DEFAULT;
ConfigDO configDO = configService.getByKey(Constant.HANDLE_APP_APPLY_MAX_NUM); ConfigDO configDO = configService.getByKey(Constant.HANDLE_APP_APPLY_MAX_NUM);
if (!ValidateUtils.isNull(configDO)) { if (!ValidateUtils.isNull(configDO)) {
try { try {
maxNum = Integer.parseInt(configDO.getConfigValue()); maxNum = Integer.parseInt(configDO.getConfigValue());
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("", e); LOGGER.error("class=AutomatedHandleOrder||method=processTask||configDO={}||msg=config value illegal", configDO, e);
} }
} }
int handleNum = Math.min(maxNum - passedOrderList.size(), waitDealOrderList.size()); int handleNum = Math.min(maxNum - passedOrderList.size(), waitDealOrderList.size());
@@ -97,7 +101,7 @@ public class AutomatedHandleOrder extends AbstractScheduledTask<EmptyEntry> {
applyAppOrder.updateOrder(orderDO, baseDTO, Constant.AUTO_HANDLE_USER_NAME); applyAppOrder.updateOrder(orderDO, baseDTO, Constant.AUTO_HANDLE_USER_NAME);
} }
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("", e); LOGGER.error("class=AutomatedHandleOrder||method=processTask||orderDO={}||msg=auto handle app order failed", orderDO, e);
} }
} }
} }

View File

@@ -33,7 +33,7 @@ import java.util.stream.Collectors;
@Api(tags = "开放接口-Broker相关接口(REST)") @Api(tags = "开放接口-Broker相关接口(REST)")
@RestController @RestController
@RequestMapping(ApiPrefix.API_V1_THIRD_PART_OP_PREFIX) @RequestMapping(ApiPrefix.API_V1_THIRD_PART_OP_PREFIX)
public class ThirdPartOpBrokerController { public class ThirdPartBrokerController {
@Autowired @Autowired
private BrokerService brokerService; private BrokerService brokerService;

View File

@@ -46,6 +46,9 @@ custom:
task: task:
op: op:
sync-topic-enabled: false # 未落盘的Topic定期同步到DB中 sync-topic-enabled: false # 未落盘的Topic定期同步到DB中
order-auto-exec: # 工单自动化审批线程的开关
topic-enabled: false # Topic工单自动化审批开关, false:关闭自动化审批, true:开启
app-enabled: false # App工单自动化审批开关, false:关闭自动化审批, true:开启
account: account:
ldap: ldap: