FormController.java
2.31 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
40
41
42
43
44
45
46
47
48
49
50
package com.xly.web;
import com.xly.agent.AgentIdentity;
import com.xly.service.AuthzService;
import com.xly.service.FormResolverService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import java.util.Map;
/**
* FormCollect 的**FK 二级选择器**数据端点:外键字段(客户/产品/物料…)的候选从对应表实时取,
* 多列展示 + 名称搜索 + 分页。
*
* <p>前端调 {@code GET /api/agent/form/options?table=elecustomer&q=..&page=1&pageSize=20},
* 返回 {@code {columns:[{col,label}…], rows:[{sId, 列:值…}], total, page, pageSize}}。
*
* <p><b>安全</b>:需登录;**租户来自服务端内省的身份**(不接受客户端传 brandsid,否则不传即可跨租户全库翻页);
* 表名限于「在字段字典里作为外键目标出现过」的白名单(见 {@link FormResolverService#fkOptionPage})。
*/
@RestController
@RequestMapping("/api/agent/form")
public class FormController {
private final FormResolverService resolver;
private final AuthzService authz;
public FormController(FormResolverService resolver, AuthzService authz) {
this.resolver = resolver;
this.authz = authz;
}
@GetMapping("/options")
public Map<String, Object> options(@RequestParam("table") String table,
@RequestParam(value = "q", required = false) String q,
@RequestParam(value = "page", defaultValue = "1") int page,
@RequestParam(value = "pageSize", defaultValue = "20") int pageSize,
@RequestHeader(value = "Authorization", required = false) String auth) {
AgentIdentity id = authz.resolveIdentity(auth);
if (id == null) {
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "登录已过期或未登录");
}
return resolver.fkOptionPage(table, id.brandsId(), q, page, pageSize);
}
}