PreviewController.java
2.57 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
51
52
53
54
55
56
package com.xly.web;
import com.xly.agent.AgentIdentity;
import com.xly.service.AuthzService;
import com.xly.service.PreviewService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;
import java.util.Map;
/**
* 预览卡按钮端点(**确定性、不经过 LLM**)—— 用户在预览卡上点【保存/审核/作废/…】后调用。
*
* <p>{@link PreviewService#save} 按 previewId 取回服务端暂存的解析产物,**重读记录重校验**
* (所见即所写:记录被他人改过/状态已变 → 拒绝),通过后写一行 ai_op_queue(AI 侧唯一写入口)。
* **xlyAi 到此为止**:是否/何时执行由 ERP 侧负责。
*
* <p>安全:需登录(token 服务端内省 fail-closed);预览归属本人(previewId 服务端绑定 userId);
* 写队列前重查表单权限——三层都在 PreviewService.save 内完成。
*/
@RestController
@RequestMapping("/api/agent/preview")
public class PreviewController {
private final PreviewService previews;
private final AuthzService authz;
public PreviewController(PreviewService previews, AuthzService authz) {
this.previews = previews;
this.authz = authz;
}
public static class SaveReq {
/** 可编辑预览(update)上用户最终确认的 字段技术名->值(空值=放弃该字段的改动);状态类操作可空。 */
public Map<String, String> fields;
/** 外键字段在选择器里点中的记录 id(字段技术名->id):有则直接绑定,不按名称反查。 */
public Map<String, String> boundIds;
}
@PostMapping("/{id}/save")
public Map<String, Object> save(@PathVariable("id") String id,
@RequestBody(required = false) SaveReq req,
@RequestHeader(value = "Authorization", required = false) String auth) {
AgentIdentity me = authz.resolveIdentity(auth);
if (me == null) {
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "登录已过期或未登录");
}
return previews.save(me, id, req == null ? null : req.fields, req == null ? null : req.boundIds);
}
}