刘光辉
8 小时以前 06f314545ac3514d7ce28939920866ae8188d31c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package jnpf.limsController;
 
import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.same.SaSameUtil;
import jnpf.base.ActionResult;
import jnpf.base.UserInfo;
import jnpf.lims.api.TestWorkItemSnapshotApi;
import jnpf.lims.api.model.TestWorkItemSnapshotBatch;
import jnpf.lims.api.model.TestWorkItemSnapshotRequest;
import jnpf.lims.api.model.TestWorkItemSnapshotActorRequest;
import jnpf.lims.api.model.TestWorkItemRequestIdentityActorRequest;
import jnpf.lims.api.model.TestWorkItemRequestIdentityBatch;
import jnpf.limsService.LimsTestWorkItemActorSnapshotService;
import jnpf.limsService.LimsTestWorkItemRequestIdentityActorService;
import jnpf.limsService.LimsTestWorkItemSnapshotService;
import jnpf.util.NoDataSourceBind;
import jnpf.util.UserProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
@RestController
@RequestMapping("/Internal/lims/testWorkItems")
public class LimsTestWorkItemSnapshotController implements TestWorkItemSnapshotApi {
 
    private final CurrentUser currentUser;
    private final LimsTestWorkItemSnapshotService snapshotService;
    private final LimsTestWorkItemActorSnapshotService actorSnapshotService;
    private final LimsTestWorkItemRequestIdentityActorService actorIdentityService;
 
    @Autowired
    public LimsTestWorkItemSnapshotController(LimsTestWorkItemSnapshotService snapshotService,
                                                LimsTestWorkItemActorSnapshotService actorSnapshotService,
                                                LimsTestWorkItemRequestIdentityActorService actorIdentityService) {
        this(UserProvider::getUser, snapshotService, actorSnapshotService, actorIdentityService);
    }
 
    LimsTestWorkItemSnapshotController(CurrentUser currentUser,
                                         LimsTestWorkItemSnapshotService snapshotService,
                                         LimsTestWorkItemActorSnapshotService actorSnapshotService,
                                         LimsTestWorkItemRequestIdentityActorService actorIdentityService) {
        this.currentUser = currentUser;
        this.snapshotService = snapshotService;
        this.actorSnapshotService = actorSnapshotService;
        this.actorIdentityService = actorIdentityService;
    }
 
    @Override
    @PostMapping("/snapshots")
    @SaCheckLogin
    public ActionResult<TestWorkItemSnapshotBatch> snapshots(
            @RequestBody TestWorkItemSnapshotRequest request) {
        UserInfo user = currentUser.get();
        String tenantId = user != null && StringUtils.hasText(user.getTenantId())
                ? user.getTenantId().trim() : "0";
        String userId = user != null && StringUtils.hasText(user.getUserId())
                ? user.getUserId().trim() : null;
        return ActionResult.success("检验任务快照读取成功",
                snapshotService.resolve(request, tenantId, userId));
    }
 
    @Override
    @PostMapping("/snapshots/asActor")
    @NoDataSourceBind
    public ActionResult<TestWorkItemSnapshotBatch> snapshotsAsActor(
            @RequestBody TestWorkItemSnapshotActorRequest actor) {
        SaSameUtil.checkCurrentRequestToken();
        return ActionResult.success("检验任务快照读取成功", actorSnapshotService.resolve(actor));
    }
 
    @Override
    @PostMapping("/requestIdentities/asActor")
    @NoDataSourceBind
    public ActionResult<TestWorkItemRequestIdentityBatch> requestIdentitiesAsActor(
            @RequestBody TestWorkItemRequestIdentityActorRequest actor) {
        SaSameUtil.checkCurrentRequestToken();
        return ActionResult.success("检验项请验单身份读取成功",
                actorIdentityService.resolve(actor));
    }
 
    @FunctionalInterface
    interface CurrentUser {
        UserInfo get();
    }
 
}