刘光辉
4 小时以前 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
90
package jnpf.elnService.impl;
 
import jnpf.base.ActionResult;
import jnpf.base.ActionResultCode;
import jnpf.elnService.ElnTestWorkItemSnapshotProvider;
import jnpf.exception.DataException;
import jnpf.lims.api.TestWorkItemSnapshotApi;
import jnpf.lims.api.ElnSourceApi;
import jnpf.lims.api.model.ElnSourceActorRequest;
import jnpf.lims.api.model.ElnSourcePropertyRef;
import jnpf.lims.api.model.ElnSourceSnapshot;
import jnpf.lims.api.model.TestWorkItemSnapshotBatch;
import jnpf.lims.api.model.TestWorkItemSnapshotRequest;
import jnpf.lims.api.model.TestWorkItemSnapshotActorRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
 
import java.util.List;
 
@Component
public class LimsTestWorkItemSnapshotProviderAdapter implements ElnTestWorkItemSnapshotProvider {
 
    private final TestWorkItemSnapshotApi snapshotApi;
    private final ElnSourceApi sourceApi;
 
    @Autowired
    public LimsTestWorkItemSnapshotProviderAdapter(TestWorkItemSnapshotApi snapshotApi, ElnSourceApi sourceApi) {
        this.snapshotApi = snapshotApi;
        this.sourceApi = sourceApi;
    }
 
    public LimsTestWorkItemSnapshotProviderAdapter(TestWorkItemSnapshotApi snapshotApi) {
        this(snapshotApi, null);
    }
 
    @Override
    public List<ElnSourceSnapshot> resolveConfiguredAsActor(String tenantId, String userId,
            List<String> itemIds, List<ElnSourcePropertyRef> properties) {
        if (!"0".equals(tenantId) || !StringUtils.hasText(userId)) {
            throw new DataException("LIMS 来源负责人身份无效");
        }
        if (sourceApi == null) throw new DataException("版本化 LIMS 来源接口不可用");
        ElnSourceActorRequest request = new ElnSourceActorRequest();
        request.setTenantId(tenantId);
        request.setUserId(userId.trim());
        request.setTestWorkItemIds(itemIds);
        request.setProperties(properties);
        ActionResult<List<ElnSourceSnapshot>> response = sourceApi.resolveAsActor(request);
        if (response == null || !ActionResultCode.SUCCESS.getCode().equals(response.getCode()) || response.getData() == null) {
            throw new DataException(response == null || !StringUtils.hasText(response.getMsg())
                    ? "版本化 LIMS 来源读取失败" : response.getMsg());
        }
        return response.getData();
    }
 
    @Override
    public TestWorkItemSnapshotBatch resolve(List<String> testWorkItemIds, List<String> properties) {
        TestWorkItemSnapshotRequest request = new TestWorkItemSnapshotRequest();
        request.setTestWorkItemIds(testWorkItemIds);
        request.setProperties(properties);
        return result(snapshotApi.snapshots(request));
    }
 
    @Override
    public TestWorkItemSnapshotBatch resolveAsActor(String tenantId, String userId,
                                                       List<String> testWorkItemIds, List<String> properties) {
        if (!StringUtils.hasText(tenantId) || !StringUtils.hasText(userId)) {
            throw new DataException("LIMS 负责人身份不能为空");
        }
        TestWorkItemSnapshotRequest request = new TestWorkItemSnapshotRequest();
        request.setTestWorkItemIds(testWorkItemIds);
        request.setProperties(properties);
        TestWorkItemSnapshotActorRequest actor = new TestWorkItemSnapshotActorRequest();
        actor.setTenantId(tenantId.trim());
        actor.setUserId(userId.trim());
        actor.setRequest(request);
        return result(snapshotApi.snapshotsAsActor(actor));
    }
 
    private static TestWorkItemSnapshotBatch result(ActionResult<TestWorkItemSnapshotBatch> result) {
        if (result == null
                || !ActionResultCode.SUCCESS.getCode().equals(result.getCode())
                || result.getData() == null) {
            throw new DataException(result == null || !StringUtils.hasText(result.getMsg())
                    ? "LIMS 检验任务快照读取失败,请稍后重试" : result.getMsg());
        }
        return result.getData();
    }
}