FormController.java
1.74 KB
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
package com.xly.web;
import com.xly.service.FormResolverService;
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.Map;
/**
* FormCollect 的**FK 二级选择器**数据端点:外键字段(客户/产品/物料…)的候选从对应表实时取,
* 多列展示 + 名称搜索 + 分页。
*
* <p>前端渲染 {@code type=fkselect} 字段时调
* {@code GET /api/agent/form/options?table=elecustomer&q=..&page=1&pageSize=20},
* 返回 {@code {columns:[{col,label}…], rows:[{sId, 列:值…}], total, page, pageSize}}。
* 安全:{@link FormResolverService#fkOptionPage} 只允许「在字段字典里作为外键目标出现过」的表,
* 并按名称字段模糊匹配 + 租户过滤 + LIMIT,避免任意读表。
*/
@RestController
@RequestMapping("/api/agent/form")
public class FormController {
private final FormResolverService resolver;
public FormController(FormResolverService resolver) {
this.resolver = resolver;
}
@GetMapping("/options")
public Map<String, Object> options(@RequestParam("table") String table,
@RequestParam(value = "q", required = false) String q,
@RequestParam(value = "brandsid", required = false) String brandsid,
@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
return resolver.fkOptionPage(table, brandsid, q, page, pageSize);
}
}