|
|
@@ -0,0 +1,273 @@
|
|
|
+package com.fs.admin.controller;
|
|
|
+
|
|
|
+import com.fs.common.core.controller.BaseController;
|
|
|
+import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.core.page.TableDataInfo;
|
|
|
+import com.fs.common.enums.DataSourceType;
|
|
|
+import com.fs.framework.datasource.DynamicDataSourceContextHolder;
|
|
|
+import com.fs.framework.datasource.TenantDataSourceManager;
|
|
|
+import com.fs.his.domain.FsAiWorkflow;
|
|
|
+import com.fs.his.domain.FsAiWorkflowNodeType;
|
|
|
+import com.fs.his.param.FsAiWorkflowSaveParam;
|
|
|
+import com.fs.his.param.FsAiWorkflowUpdateBindWCParam;
|
|
|
+import com.fs.his.service.IFsAiWorkflowService;
|
|
|
+import com.fs.tenant.domain.TenantInfo;
|
|
|
+import com.fs.tenant.mapper.TenantInfoMapper;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * AI工作流桥接Controller - adminui端(fs-admin 8004)
|
|
|
+ * 替代 com.fs.his.controller.FsAiWorkflowController(已从admin扫描中排除)
|
|
|
+ * <p>
|
|
|
+ * AI工作流数据存储在租户库中,admin端需根据请求中的租户上下文切换数据源后查询。
|
|
|
+ * 请求头需携带 tenant-code 或 tenant-id 来指定目标租户。
|
|
|
+ *
|
|
|
+ * @author fs
|
|
|
+ * @date 2026-05-12
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/his/aiWorkflow")
|
|
|
+public class AdminAiWorkflowBridgeController extends BaseController {
|
|
|
+
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(AdminAiWorkflowBridgeController.class);
|
|
|
+
|
|
|
+ @Autowired(required = false)
|
|
|
+ private IFsAiWorkflowService fsAiWorkflowService;
|
|
|
+
|
|
|
+ @Autowired(required = false)
|
|
|
+ private TenantDataSourceManager tenantDataSourceManager;
|
|
|
+
|
|
|
+ @Autowired(required = false)
|
|
|
+ private TenantInfoMapper tenantInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private HttpServletRequest request;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 尝试切换到租户数据源
|
|
|
+ * @return true=切换成功,false=无租户上下文或切换失败
|
|
|
+ */
|
|
|
+ private boolean trySwitchToTenant() {
|
|
|
+ if (tenantDataSourceManager == null || tenantInfoMapper == null) {
|
|
|
+ log.debug("[AiWorkflowBridge] 多租户组件不可用,使用主库");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 优先从请求头获取 tenant-id
|
|
|
+ String tenantIdStr = request.getHeader("tenant-id");
|
|
|
+ if (tenantIdStr == null || tenantIdStr.isEmpty()) {
|
|
|
+ // 尝试 tenant-code
|
|
|
+ String tenantCode = request.getHeader("tenant-code");
|
|
|
+ if (tenantCode != null && !tenantCode.isEmpty()) {
|
|
|
+ DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
|
|
|
+ try {
|
|
|
+ TenantInfo info = tenantInfoMapper.getTenByCode(tenantCode);
|
|
|
+ if (info != null) {
|
|
|
+ tenantDataSourceManager.switchTenant(info);
|
|
|
+ log.debug("[AiWorkflowBridge] 通过 tenant-code={} 切换到租户: {}", tenantCode, info.getId());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ // 如果没找到,已经切到MASTER,需要回切?
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 尝试查询参数 tenantId
|
|
|
+ tenantIdStr = request.getParameter("tenantId");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (tenantIdStr != null && !tenantIdStr.isEmpty()) {
|
|
|
+ try {
|
|
|
+ Long tenantId = Long.parseLong(tenantIdStr);
|
|
|
+ tenantDataSourceManager.ensureSwitchByTenantId(tenantId);
|
|
|
+ log.debug("[AiWorkflowBridge] 通过 tenant-id={} 切换到租户", tenantId);
|
|
|
+ return true;
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("[AiWorkflowBridge] tenantId格式错误: {}", tenantIdStr);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清理数据源上下文
|
|
|
+ */
|
|
|
+ private void clearDataSource() {
|
|
|
+ if (tenantDataSourceManager != null) {
|
|
|
+ tenantDataSourceManager.clear();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询AI工作流列表
|
|
|
+ */
|
|
|
+ @GetMapping("/list")
|
|
|
+ public TableDataInfo list(FsAiWorkflow fsAiWorkflow) {
|
|
|
+ if (fsAiWorkflowService == null || !trySwitchToTenant()) {
|
|
|
+ return getDataTable(new ArrayList<>());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ startPage();
|
|
|
+ List<FsAiWorkflow> list = fsAiWorkflowService.selectFsAiWorkflowList(fsAiWorkflow);
|
|
|
+ return getDataTable(list);
|
|
|
+ } finally {
|
|
|
+ clearDataSource();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出AI工作流列表
|
|
|
+ */
|
|
|
+ @GetMapping("/export")
|
|
|
+ public AjaxResult export(FsAiWorkflow fsAiWorkflow) {
|
|
|
+ if (fsAiWorkflowService == null || !trySwitchToTenant()) {
|
|
|
+ return AjaxResult.error("请先选择租户");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ List<FsAiWorkflow> list = fsAiWorkflowService.selectFsAiWorkflowList(fsAiWorkflow);
|
|
|
+ // 导出功能在admin端简化为返回数据
|
|
|
+ return AjaxResult.success(list);
|
|
|
+ } finally {
|
|
|
+ clearDataSource();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取AI工作流详细信息(包含节点和连线)
|
|
|
+ */
|
|
|
+ @GetMapping(value = "/{workflowId}")
|
|
|
+ public AjaxResult getInfo(@PathVariable("workflowId") Long workflowId) {
|
|
|
+ if (fsAiWorkflowService == null || !trySwitchToTenant()) {
|
|
|
+ return AjaxResult.error("请先选择租户");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return AjaxResult.success(fsAiWorkflowService.selectFsAiWorkflowById(workflowId));
|
|
|
+ } finally {
|
|
|
+ clearDataSource();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存AI工作流(新增或更新) - admin端不支持直接写入
|
|
|
+ */
|
|
|
+ @PostMapping("/save")
|
|
|
+ public AjaxResult save(@RequestBody FsAiWorkflowSaveParam param) {
|
|
|
+ return AjaxResult.error("总后台不支持直接操作租户工作流,请在租户端操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改AI工作流状态 - admin端不支持直接写入
|
|
|
+ */
|
|
|
+ @PutMapping("/status/{workflowId}/{status}")
|
|
|
+ public AjaxResult updateStatus(@PathVariable("workflowId") Long workflowId,
|
|
|
+ @PathVariable("status") Integer status) {
|
|
|
+ return AjaxResult.error("总后台不支持直接操作租户工作流,请在租户端操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除AI工作流 - admin端不支持直接写入
|
|
|
+ */
|
|
|
+ @DeleteMapping("/{workflowIds}")
|
|
|
+ public AjaxResult remove(@PathVariable Long[] workflowIds) {
|
|
|
+ return AjaxResult.error("总后台不支持直接操作租户工作流,请在租户端操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复制AI工作流 - admin端不支持直接写入
|
|
|
+ */
|
|
|
+ @PostMapping("/copy/{workflowId}")
|
|
|
+ public AjaxResult copy(@PathVariable("workflowId") Long workflowId) {
|
|
|
+ return AjaxResult.error("总后台不支持直接操作租户工作流,请在租户端操作");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取所有启用的节点类型
|
|
|
+ */
|
|
|
+ @GetMapping("/nodeTypes")
|
|
|
+ public AjaxResult getNodeTypes() {
|
|
|
+ if (fsAiWorkflowService == null || !trySwitchToTenant()) {
|
|
|
+ return AjaxResult.success(new ArrayList<>());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ List<FsAiWorkflowNodeType> list = fsAiWorkflowService.selectAllEnabledNodeTypes();
|
|
|
+ return AjaxResult.success(list);
|
|
|
+ } finally {
|
|
|
+ clearDataSource();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出工作流流程图JSON
|
|
|
+ */
|
|
|
+ @GetMapping("/exportJson/{workflowId}")
|
|
|
+ public AjaxResult exportJson(@PathVariable("workflowId") Long workflowId) {
|
|
|
+ if (fsAiWorkflowService == null || !trySwitchToTenant()) {
|
|
|
+ return AjaxResult.error("请先选择租户");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return AjaxResult.success(fsAiWorkflowService.exportWorkflowJson(workflowId));
|
|
|
+ } finally {
|
|
|
+ clearDataSource();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页销售
|
|
|
+ */
|
|
|
+ @GetMapping("/listCompanyUser")
|
|
|
+ public AjaxResult listCompanyUser() {
|
|
|
+ if (fsAiWorkflowService == null || !trySwitchToTenant()) {
|
|
|
+ return AjaxResult.success(new ArrayList<>());
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return AjaxResult.success(fsAiWorkflowService.listCompanyUser());
|
|
|
+ } finally {
|
|
|
+ clearDataSource();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查销售
|
|
|
+ */
|
|
|
+ @GetMapping("/getCompanyUserById/{companyUserId}")
|
|
|
+ public AjaxResult getCompanyUserById(@PathVariable("companyUserId") Long companyUserId) {
|
|
|
+ if (fsAiWorkflowService == null || !trySwitchToTenant()) {
|
|
|
+ return AjaxResult.error("请先选择租户");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return AjaxResult.success(fsAiWorkflowService.getCompanyUserById(companyUserId));
|
|
|
+ } finally {
|
|
|
+ clearDataSource();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查工作流已绑定的销售
|
|
|
+ */
|
|
|
+ @GetMapping("/getBindCompanyUserByWorkflowId/{workflowId}")
|
|
|
+ public AjaxResult getBindCompanyUserByWorkflowId(@PathVariable("workflowId") Long workflowId) {
|
|
|
+ if (fsAiWorkflowService == null || !trySwitchToTenant()) {
|
|
|
+ return AjaxResult.error("请先选择租户");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return AjaxResult.success(fsAiWorkflowService.getBindCompanyUserByWorkflowId(workflowId));
|
|
|
+ } finally {
|
|
|
+ clearDataSource();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改工作流绑定的销售 - admin端不支持直接写入
|
|
|
+ */
|
|
|
+ @PostMapping("/updateWorkflowBindCompanyUser")
|
|
|
+ public AjaxResult updateWorkflowBindCompanyUser(@RequestBody FsAiWorkflowUpdateBindWCParam param) {
|
|
|
+ return AjaxResult.error("总后台不支持直接操作租户工作流,请在租户端操作");
|
|
|
+ }
|
|
|
+}
|