刘光辉
14 小时以前 34981c30a78e8bbd7791131059a9210f9928b62c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package jnpf.limsController;
 
import com.alibaba.fastjson.JSONObject;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.Collections;
import java.util.List;
import java.util.Map;
 
/**
 * 工作流表配置测试数据查询。
 *
 * <p>该 Controller 仅用于验证前端配置页面,保持只读,不影响现有业务接口。</p>
 */
@Slf4j
@Tag(name = "工作流表配置测试", description = "按流程查询发起表单关联的数据表")
@RestController
@RequestMapping("/custom/workflow-table-config")
public class WorkflowTableConfigTestController {
 
    private static final String DEFAULT_FLOW_ID = "864125763559883717";
 
    private final JdbcTemplate jdbcTemplate;
 
    public WorkflowTableConfigTestController(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }
 
    @Operation(summary = "查询流程表配置")
    @GetMapping
    public JSONObject list(@RequestParam(value = "flowId", required = false) String flowId) {
        String queryFlowId = StringUtils.hasText(flowId) ? flowId.trim() : DEFAULT_FLOW_ID;
        JSONObject result = new JSONObject();
        result.put("code", 200);
        result.put("msg", "查询成功");
 
        try {
            String sql = "SELECT n.f_form_id AS \"formId\", "
                    + "v.f_full_name AS \"formName\", "
                    + "item.value ->> 'typeId' AS \"tableType\", "
                    + "item.value ->> 'table' AS \"tableName\", "
                    + "item.value ->> 'tableName' AS \"tableDisplayName\" "
                    + "FROM public.workflow_node n "
                    + "JOIN public.base_visual_release v ON v.f_id = n.f_form_id "
                    + "CROSS JOIN LATERAL jsonb_array_elements("
                    + "CASE WHEN v.f_tables_data IS NULL OR btrim(v.f_tables_data) = '' "
                    + "THEN '[]'::jsonb ELSE v.f_tables_data::jsonb END) AS item(value) "
                    + "WHERE n.f_flow_id = ? AND n.f_node_type = 'start' "
                    + "AND item.value ->> 'typeId' = '1'";
 
            List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, queryFlowId);
            result.put("data", rows == null ? Collections.emptyList() : rows);
            return result;
        } catch (Exception ex) {
            log.error("查询流程表配置失败,flowId={}", queryFlowId, ex);
            result.put("code", 500);
            result.put("msg", "查询失败:" + ex.getMessage());
            result.put("data", Collections.emptyList());
            return result;
        }
    }
}