初始代码
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>yunzhupaas-visualdev-integrate</artifactId>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<version>5.2.0-RELEASE</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>yunzhupaas-visualdev-integrate-controller</artifactId>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yunzhupaas</groupId>
|
||||
<artifactId>yunzhupaas-visualdev-integrate-biz</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,306 @@
|
||||
package com.yunzhupaas.integrate.controller;
|
||||
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.base.vo.DownloadVO;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.emnus.ModuleTypeEnum;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.integrate.entity.IntegrateEntity;
|
||||
import com.yunzhupaas.integrate.entity.IntegrateQueueEntity;
|
||||
import com.yunzhupaas.integrate.job.IntegrateJobUtil;
|
||||
import com.yunzhupaas.integrate.model.integrate.*;
|
||||
import com.yunzhupaas.integrate.model.nodeJson.IntegrateModel;
|
||||
import com.yunzhupaas.integrate.service.IntegrateQueueService;
|
||||
import com.yunzhupaas.integrate.service.IntegrateService;
|
||||
import com.yunzhupaas.integrate.util.IntegrateHttpModel;
|
||||
import com.yunzhupaas.integrate.util.IntegrateUtil;
|
||||
import com.yunzhupaas.permission.entity.UserEntity;
|
||||
import com.yunzhupaas.permission.service.UserService;
|
||||
import com.yunzhupaas.util.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import jakarta.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Tag(name = "集成助手", description = "Integrate")
|
||||
@RestController
|
||||
@RequestMapping("/api/visualdev/Integrate")
|
||||
public class IntegrateController extends SuperController<IntegrateService, IntegrateEntity> {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private DataFileExport fileExport;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private IntegrateService integrateService;
|
||||
@Autowired
|
||||
private IntegrateQueueService integrateQueueService;
|
||||
@Autowired
|
||||
private IntegrateUtil integrateUtil;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "列表")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<IntegrateListVO>> list(IntegratePagination pagination) {
|
||||
List<IntegrateEntity> data = integrateService.getList(pagination);
|
||||
List<String> userId = data.stream().map(t -> t.getCreatorUserId()).collect(Collectors.toList());
|
||||
List<UserEntity> userEntities = userService.getUserName(userId);
|
||||
List<IntegrateListVO> resultList = new ArrayList<>();
|
||||
for (IntegrateEntity entity : data) {
|
||||
IntegrateListVO vo = JsonUtil.getJsonToBean(entity, IntegrateListVO.class);
|
||||
UserEntity creatorUser = userEntities.stream().filter(t -> t.getId().equals(entity.getCreatorUserId())).findFirst().orElse(null);
|
||||
vo.setCreatorUser(creatorUser != null ? creatorUser.getRealName() + "/" + creatorUser.getAccount() : "");
|
||||
resultList.add(vo);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(resultList, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 信息
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "获取信息")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult info(@PathVariable("id") String id) {
|
||||
IntegrateEntity entity = integrateService.getInfo(id);
|
||||
if (entity == null) {
|
||||
return ActionResult.fail(MsgCode.FA001.get());
|
||||
}
|
||||
IntegrateInfoVO vo = JsonUtil.getJsonToBean(entity, IntegrateInfoVO.class);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新建
|
||||
*
|
||||
* @param integrateCrForm 实体对象
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "添加")
|
||||
@Parameters({
|
||||
@Parameter(name = "integrateCrForm", description = "实体对象", required = true)
|
||||
})
|
||||
@PostMapping
|
||||
public ActionResult create(@RequestBody @Valid IntegrateCrForm integrateCrForm) {
|
||||
IntegrateEntity entity = JsonUtil.getJsonToBean(integrateCrForm, IntegrateEntity.class);
|
||||
if (integrateService.isExistByFullName(entity.getFullName(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (integrateService.isExistByEnCode(entity.getEnCode(), entity.getId())) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
String id = RandomUtil.uuId();
|
||||
entity.setId(id);
|
||||
integrateService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU001.get(), id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "修改")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true),
|
||||
@Parameter(name = "integrateUpForm", description = "实体对象", required = true)
|
||||
})
|
||||
@PutMapping("/{id}")
|
||||
public ActionResult update(@PathVariable("id") String id, @RequestBody IntegrateUpForm integrateUpForm) {
|
||||
IntegrateEntity positionEntity = integrateService.getInfo(id);
|
||||
if (positionEntity == null) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
IntegrateEntity entity = JsonUtil.getJsonToBean(integrateUpForm, IntegrateEntity.class);
|
||||
if (integrateService.isExistByFullName(entity.getFullName(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST001.get());
|
||||
}
|
||||
if (integrateService.isExistByEnCode(entity.getEnCode(), id)) {
|
||||
return ActionResult.fail(MsgCode.EXIST002.get());
|
||||
}
|
||||
boolean flag = integrateService.update(id, entity,false);
|
||||
if (flag == false) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get(), id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
IntegrateEntity entity = integrateService.getInfo(id);
|
||||
if (entity != null) {
|
||||
integrateService.delete(entity);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制功能
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "复制功能")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键"),
|
||||
})
|
||||
@PostMapping("/{id}/Actions/Copy")
|
||||
public ActionResult copyInfo(@PathVariable("id") String id) throws Exception {
|
||||
IntegrateEntity entity = integrateService.getInfo(id);
|
||||
entity.setEnabledMark(0);
|
||||
String copyNum = UUID.randomUUID().toString().substring(0, 5);
|
||||
entity.setFullName(entity.getFullName() + ".副本" + copyNum);
|
||||
entity.setLastModifyTime(null);
|
||||
entity.setLastModifyUserId(null);
|
||||
entity.setId(RandomUtil.uuId());
|
||||
entity.setEnCode(entity.getEnCode() + copyNum);
|
||||
entity.setCreatorTime(new Date());
|
||||
entity.setEnabledMark(0);
|
||||
entity.setCreatorUserId(UserProvider.getUser().getUserId());
|
||||
integrateService.create(entity);
|
||||
return ActionResult.success(MsgCode.SU007.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新功能状态
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "更新功能状态")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键"),
|
||||
})
|
||||
@PutMapping("/{id}/Actions/State")
|
||||
public ActionResult update(@PathVariable("id") String id) {
|
||||
IntegrateEntity entity = integrateService.getInfo(id);
|
||||
if (entity != null) {
|
||||
if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
|
||||
entity.setEnabledMark(0);
|
||||
} else {
|
||||
entity.setEnabledMark(1);
|
||||
}
|
||||
boolean flag = integrateService.update(entity.getId(), entity,true);
|
||||
if (flag == false) {
|
||||
return ActionResult.fail(MsgCode.FA002.get());
|
||||
}
|
||||
}
|
||||
return ActionResult.success(MsgCode.SU004.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @param id 主键
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导出")
|
||||
@PostMapping("/{id}/Actions/Export")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true),
|
||||
})
|
||||
public ActionResult<DownloadVO> exportData(@PathVariable("id") String id) {
|
||||
IntegrateEntity entity = integrateService.getInfo(id);
|
||||
DownloadVO downloadVO = fileExport.exportFile(entity, configValueUtil.getTemporaryFilePath(), entity.getFullName(), ModuleTypeEnum.BASE_INTEGRATE.getTableName());
|
||||
return ActionResult.success(downloadVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入
|
||||
*
|
||||
* @param file 文件
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "导入")
|
||||
@PostMapping(value = "/Actions/Import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public ActionResult ImportData(@RequestPart("file") MultipartFile file,@RequestParam("type") Integer type) throws WorkFlowException {
|
||||
//判断是否为.json结尾
|
||||
if (FileUtil.existsSuffix(file, ModuleTypeEnum.BASE_INTEGRATE.getTableName())) {
|
||||
return ActionResult.fail(MsgCode.IMP002.get());
|
||||
}
|
||||
try {
|
||||
String fileContent = FileUtil.getFileContent(file);
|
||||
IntegrateEntity entity = JsonUtil.getJsonToBean(fileContent, IntegrateEntity.class);
|
||||
return integrateService.ImportData(entity, type);
|
||||
} catch (Exception e) {
|
||||
throw new WorkFlowException(MsgCode.IMP004.get());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 集成助手事件触发
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/execute")
|
||||
public ActionResult execute(@RequestBody IntegrateHttpModel model) {
|
||||
integrateUtil.integrates(model.getDataInfoVOList(),model.getUserInfo());
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 集成助手定时触发
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/executeQuery")
|
||||
public ActionResult executeQuery(@RequestBody IntegrateHttpModel model) {
|
||||
IntegrateModel integrateModel = JsonUtil.getJsonToBean(model, IntegrateModel.class);
|
||||
if(ObjectUtil.isNotEmpty(model.getId())){
|
||||
IntegrateQueueEntity entity = integrateQueueService.getById(model.getId());
|
||||
if(ObjectUtil.isNotEmpty(entity)) {
|
||||
integrateUtil.integrate(entity, model.getUserInfo());
|
||||
}
|
||||
}
|
||||
IntegrateJobUtil.removeIntegrate(integrateModel, redisUtil);
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
package com.yunzhupaas.integrate.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.base.controller.SuperController;
|
||||
import com.yunzhupaas.base.vo.PageListVO;
|
||||
import com.yunzhupaas.base.vo.PaginationVO;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.integrate.entity.IntegrateNodeEntity;
|
||||
import com.yunzhupaas.integrate.entity.IntegrateQueueEntity;
|
||||
import com.yunzhupaas.integrate.entity.IntegrateTaskEntity;
|
||||
import com.yunzhupaas.integrate.model.integratetask.IntegrateQueueListVO;
|
||||
import com.yunzhupaas.integrate.model.integratetask.IntegrateTaskInfo;
|
||||
import com.yunzhupaas.integrate.model.integratetask.IntegrateTaskListVO;
|
||||
import com.yunzhupaas.integrate.model.integrate.IntegratePageModel;
|
||||
import com.yunzhupaas.integrate.model.integratetask.IntegrateTaskModel;
|
||||
import com.yunzhupaas.integrate.service.IntegrateNodeService;
|
||||
import com.yunzhupaas.integrate.service.IntegrateQueueService;
|
||||
import com.yunzhupaas.integrate.service.IntegrateTaskService;
|
||||
import com.yunzhupaas.integrate.util.IntegrateUtil;
|
||||
import com.yunzhupaas.util.JsonUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Tag(name = "集成助手日志", description = "IntegrateTask")
|
||||
@RestController
|
||||
@RequestMapping("/api/visualdev/IntegrateTask")
|
||||
public class IntegrateTaskController extends SuperController<IntegrateTaskService, IntegrateTaskEntity> {
|
||||
|
||||
@Autowired
|
||||
private IntegrateTaskService integrateTaskService;
|
||||
@Autowired
|
||||
private IntegrateNodeService integrateNodeService;
|
||||
@Autowired
|
||||
private IntegrateUtil integrateUtil;
|
||||
@Autowired
|
||||
private IntegrateQueueService integrateQueueService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "日志列表")
|
||||
@GetMapping
|
||||
public ActionResult<PageListVO<IntegrateTaskListVO>> list(IntegratePageModel pagination) {
|
||||
List<IntegrateTaskEntity> data = integrateTaskService.getList(pagination);
|
||||
List<IntegrateTaskListVO> list = JsonUtil.getJsonToList(data, IntegrateTaskListVO.class);
|
||||
for (IntegrateTaskListVO taskListVO : list) {
|
||||
taskListVO.setIsRetry("0".equals(taskListVO.getParentId()) ? 0 : 1);
|
||||
}
|
||||
PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
|
||||
return ActionResult.page(list, paginationVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param id 主键值
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "删除")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键值", required = true)
|
||||
})
|
||||
@DeleteMapping("/{id}")
|
||||
public ActionResult delete(@PathVariable("id") String id) {
|
||||
integrateTaskService.delete(id);
|
||||
return ActionResult.success(MsgCode.SU003.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "执行列表")
|
||||
@GetMapping("/queueList")
|
||||
public ActionResult<List<IntegrateQueueListVO>> queueList() {
|
||||
List<IntegrateQueueEntity> list = integrateQueueService.getList();
|
||||
List<IntegrateQueueListVO> listVO = JsonUtil.getJsonToList(list, IntegrateQueueListVO.class);
|
||||
return ActionResult.success(listVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 日志列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "日志详情")
|
||||
@GetMapping("/{id}")
|
||||
public ActionResult<IntegrateTaskInfo> list(@PathVariable("id") String id) {
|
||||
IntegrateTaskEntity taskEntity = integrateTaskService.getInfo(id);
|
||||
List<IntegrateNodeEntity> nodeList = integrateNodeService.getList(new ArrayList() {{
|
||||
add(id);
|
||||
}}, null);
|
||||
List<IntegrateTaskModel> list = JsonUtil.getJsonToList(nodeList, IntegrateTaskModel.class);
|
||||
for (IntegrateTaskModel taskModel : list) {
|
||||
boolean isType = "0".equals(taskModel.getParentId());
|
||||
taskModel.setType(isType ? 1 : 0);
|
||||
}
|
||||
IntegrateTaskInfo info = new IntegrateTaskInfo();
|
||||
info.setList(list);
|
||||
info.setData(taskEntity.getData());
|
||||
return ActionResult.success(info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 节点重试
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "节点重试")
|
||||
@GetMapping(value = "/{id}/nodeRetry")
|
||||
public ActionResult taskNode(@PathVariable("id") String id, String nodeId) {
|
||||
IntegrateTaskEntity taskEntity = integrateTaskService.getInfo(id);
|
||||
if (taskEntity != null) {
|
||||
integrateUtil.integrate(id, taskEntity.getParentId(), nodeId);
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA007.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Operation(summary = "重试")
|
||||
@PutMapping(value = "/{id}/retry")
|
||||
public ActionResult ImportData(@PathVariable("id") String id) {
|
||||
IntegrateTaskEntity taskEntity = integrateTaskService.getInfo(id);
|
||||
if (taskEntity != null) {
|
||||
integrateUtil.integrate(id, id, "0");
|
||||
return ActionResult.success(MsgCode.SU005.get());
|
||||
}
|
||||
return ActionResult.fail(MsgCode.FA007.get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
package com.yunzhupaas.integrate.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Parameters;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import com.yunzhupaas.base.ActionResult;
|
||||
import com.yunzhupaas.config.ConfigValueUtil;
|
||||
import com.yunzhupaas.constant.MsgCode;
|
||||
import com.yunzhupaas.database.util.TenantDataSourceUtil;
|
||||
import com.yunzhupaas.exception.WorkFlowException;
|
||||
import com.yunzhupaas.integrate.entity.IntegrateEntity;
|
||||
import com.yunzhupaas.integrate.model.integrate.WebHookInfoVo;
|
||||
import com.yunzhupaas.integrate.service.IntegrateService;
|
||||
import com.yunzhupaas.integrate.util.IntegrateUtil;
|
||||
import com.yunzhupaas.util.*;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
@Tag(name = "webhook触发", description = "WebHook")
|
||||
@RestController
|
||||
@RequestMapping("/api/visualdev/Hooks")
|
||||
public class WebHookController {
|
||||
|
||||
@Autowired
|
||||
private IntegrateService integrateService;
|
||||
@Autowired
|
||||
private RedisUtil redisUtil;
|
||||
@Autowired
|
||||
private ConfigValueUtil configValueUtil;
|
||||
@Autowired
|
||||
private IntegrateUtil integrateUtil;
|
||||
|
||||
|
||||
private static final String WEBHOOK_RED_KEY = "webhookencode";
|
||||
|
||||
private static long DEFAULT_CACHE_TIME = 60 * 5;
|
||||
|
||||
@Operation(summary = "数据接收接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "base64转码id", required = true),
|
||||
@Parameter(name = "tenantId", description = "租户id", required = false)
|
||||
})
|
||||
@PostMapping("/{id}")
|
||||
@NoDataSourceBind
|
||||
public ActionResult webhookTrigger(@PathVariable("id") String id,
|
||||
@RequestParam(value = "tenantId", required = false) String tenantId,
|
||||
@RequestBody Map<String, Object> body) throws WorkFlowException {
|
||||
String idReal = new String(Base64.decodeBase64(id.getBytes(StandardCharsets.UTF_8)));
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
// 判断是不是从外面直接请求
|
||||
if (StringUtil.isNotEmpty(tenantId)) {
|
||||
//切换成租户库
|
||||
try {
|
||||
TenantDataSourceUtil.switchTenant(tenantId);
|
||||
} catch (Exception e) {
|
||||
return ActionResult.fail(MsgCode.LOG105.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
integrateUtil.integrate(idReal, tenantId, body);
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取webhookUrl")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "主键", required = true)
|
||||
})
|
||||
@GetMapping("/getUrl")
|
||||
public ActionResult getWebhookUrl(@RequestParam("id") String id) {
|
||||
String enCodeBase64 = new String(Base64.encodeBase64(id.getBytes(StandardCharsets.UTF_8)));
|
||||
String randomStr = UUID.randomUUID().toString().substring(0, 5);
|
||||
WebHookInfoVo vo = new WebHookInfoVo();
|
||||
vo.setEnCodeStr(enCodeBase64);
|
||||
vo.setRandomStr(randomStr);
|
||||
vo.setWebhookUrl("/api/visualdev/Hooks/" + enCodeBase64);
|
||||
vo.setRequestUrl("/api/visualdev/Hooks/" + enCodeBase64 + "/params/" + randomStr);
|
||||
return ActionResult.success(vo);
|
||||
}
|
||||
|
||||
@Operation(summary = "通过get接口获取参数")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "base64转码id", required = true),
|
||||
@Parameter(name = "randomStr", description = "获取webhookUrl提供的随机字符", required = true)
|
||||
})
|
||||
@GetMapping("/{id}/params/{randomStr}")
|
||||
@NoDataSourceBind
|
||||
public ActionResult getWebhookParams(@PathVariable("id") String id,
|
||||
@PathVariable("randomStr") String randomStr) throws WorkFlowException {
|
||||
insertRedis(id, randomStr, new HashMap<>());
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "通过post接口获取参数")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "base64转码id", required = true),
|
||||
@Parameter(name = "randomStr", description = "获取webhookUrl提供的随机字符", required = true)
|
||||
})
|
||||
@PostMapping("/{id}/params/{randomStr}")
|
||||
@NoDataSourceBind
|
||||
public ActionResult postWebhookParams(@PathVariable("id") String id,
|
||||
@PathVariable("randomStr") String randomStr,
|
||||
@RequestBody Map<String, Object> obj) throws WorkFlowException {
|
||||
insertRedis(id, randomStr, new HashMap<>(obj));
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 助手id查询信息,写入缓存
|
||||
*
|
||||
* @param id
|
||||
* @param randomStr
|
||||
* @param resultMap
|
||||
* @throws WorkFlowException
|
||||
*/
|
||||
private void insertRedis(String id, String randomStr, Map<String, Object> resultMap) throws WorkFlowException {
|
||||
String idReal = new String(Base64.decodeBase64(id.getBytes(StandardCharsets.UTF_8)));
|
||||
String key1 = WEBHOOK_RED_KEY + "_" + idReal + "_" + randomStr;
|
||||
if (!redisUtil.exists(key1)) {
|
||||
throw new WorkFlowException(MsgCode.VS016.get());
|
||||
}
|
||||
String tenantId = redisUtil.getString(key1).toString();
|
||||
|
||||
if (configValueUtil.isMultiTenancy()) {
|
||||
// 判断是不是从外面直接请求
|
||||
if (StringUtil.isNotEmpty(tenantId)) {
|
||||
//切换成租户库
|
||||
try {
|
||||
TenantDataSourceUtil.switchTenant(tenantId);
|
||||
} catch (Exception e) {
|
||||
throw new WorkFlowException(MsgCode.LOG105.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
IntegrateEntity entity = integrateService.getInfo(idReal);
|
||||
if (Objects.equals(entity.getEnabledMark(), 0)) {
|
||||
throw new WorkFlowException(MsgCode.VS017.get());
|
||||
}
|
||||
Map<String, Object> parameterMap = new HashMap<>(ServletUtil.getRequest().getParameterMap());
|
||||
for (String key : parameterMap.keySet()) {
|
||||
String[] parameterValues = ServletUtil.getRequest().getParameterValues(key);
|
||||
if (parameterValues.length == 1) {
|
||||
parameterMap.put(key, parameterValues[0]);
|
||||
} else {
|
||||
parameterMap.put(key, parameterValues);
|
||||
}
|
||||
}
|
||||
resultMap.putAll(parameterMap);
|
||||
if (resultMap.keySet().size() > 0) {
|
||||
redisUtil.insert(WEBHOOK_RED_KEY + "_" + randomStr, resultMap, DEFAULT_CACHE_TIME);
|
||||
redisUtil.remove(key1);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "请求参数添加触发接口")
|
||||
@Parameters({
|
||||
@Parameter(name = "id", description = "base64转码id", required = true),
|
||||
@Parameter(name = "randomStr", description = "获取webhookUrl提供的随机字符", required = true)
|
||||
})
|
||||
@GetMapping("/{id}/start/{randomStr}")
|
||||
public ActionResult start(@PathVariable("id") String id,
|
||||
@PathVariable("randomStr") String randomStr) {
|
||||
redisUtil.remove(WEBHOOK_RED_KEY + "_" + randomStr);
|
||||
redisUtil.insert(WEBHOOK_RED_KEY + "_" + id + "_" + randomStr, UserProvider.getUser().getTenantId(), DEFAULT_CACHE_TIME);
|
||||
return ActionResult.success();
|
||||
}
|
||||
|
||||
@Operation(summary = "获取缓存的接口参数")
|
||||
@Parameters({
|
||||
@Parameter(name = "randomStr", description = "获取webhookUrl提供的随机字符", required = true)
|
||||
})
|
||||
@GetMapping("/getParams/{randomStr}")
|
||||
public ActionResult getRedisParams(@PathVariable("randomStr") String randomStr) {
|
||||
Map<String, Object> mapRedis = new HashMap<>();
|
||||
String key = WEBHOOK_RED_KEY + "_" + randomStr;
|
||||
if (redisUtil.exists(key)) {
|
||||
mapRedis = redisUtil.getMap(key);
|
||||
}
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (String redisKey : mapRedis.keySet()) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("id", redisKey);
|
||||
map.put("fullName", mapRedis.get(redisKey));
|
||||
list.add(map);
|
||||
}
|
||||
return ActionResult.success(list);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user