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();
|
}
|
}
|