1.处理入库接口效率慢,修改入库接口循环去操作数据库的逻辑
2.启动两个线程处理不同的统计数据
master
陈江保 3 weeks ago
parent 8ae29232a2
commit 42d59923e0
  1. 4
      src/main/java/digital/laboratory/platform/imr/controller/SamplePutInStorageController.java
  2. 21
      src/main/java/digital/laboratory/platform/imr/service/impl/DrugHandingOverStatisticServiceImpl.java
  3. 56
      src/main/java/digital/laboratory/platform/imr/service/impl/SamplePutInStorageServiceImpl.java

@ -302,10 +302,10 @@ public class SamplePutInStorageController {
@PreAuthorize("@pms.hasPermission('imr_inbound_or_outbound_edit')")
public R sampleDepositRepository(@RequestBody DepositDTO dto) {
if (dto.getIds() == null) {
throw new RuntimeException("样本不能为空");
return R.failed("样本不能为空");
}
if (StrUtil.isEmpty(dto.getCellId())) {
throw new RuntimeException("存放位置不能为空");
return R.failed("存放位置不能为空");
}
List<OutSampleVO> vo = samplePutInStorageService.sampleDepositRepository(dto);

@ -25,7 +25,8 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -52,8 +53,22 @@ public class DrugHandingOverStatisticServiceImpl implements DrugHandingOverStati
@Override
public DrugStatisticVO statistic(DrugStatisticQuery query) {
DrugStatisticVO drugStatisticVO = new DrugStatisticVO();
buildLineChartData(query, drugStatisticVO);
buildBarChartData(query, drugStatisticVO);
// 创建 CompletableFuture 用于异步执行 buildLineChartData 和 buildBarChartData
CompletableFuture<Void> lineChartFuture = CompletableFuture.runAsync(() -> buildLineChartData(query, drugStatisticVO));
CompletableFuture<Void> barChartFuture = CompletableFuture.runAsync(() -> buildBarChartData(query, drugStatisticVO));
// 等待两个任务完成
CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(lineChartFuture, barChartFuture);
try {
// 等待所有异步任务执行完成
combinedFuture.get();
} catch (InterruptedException | ExecutionException e) {
// 处理异常
e.printStackTrace();
}
// 返回最终构建好的 DrugStatisticVO
return drugStatisticVO;
}

@ -19,6 +19,7 @@ import digital.laboratory.platform.imr.feign.dto.UpdateHolderDTO;
import digital.laboratory.platform.imr.mapper.*;
import digital.laboratory.platform.imr.service.DrugMaterialInfoService;
import digital.laboratory.platform.imr.service.SamplePutInStorageService;
import digital.laboratory.platform.imr.service.SampleStorageService;
import digital.laboratory.platform.imr.vo.InboundRecordVO;
import digital.laboratory.platform.imr.vo.OutSampleVO;
import digital.laboratory.platform.imr.vo.RepositorySampleVO;
@ -34,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
@Slf4j
@ -50,6 +52,8 @@ public class SamplePutInStorageServiceImpl implements SamplePutInStorageService
private final SampleStorageMapper storageMapper;
private final SampleStorageService sampleStorageService;
private final TransferFeignService transferFeignService;
private final CabinetOpeningRecordMapper openingRecordMapper;
@ -449,16 +453,24 @@ public class SamplePutInStorageServiceImpl implements SamplePutInStorageService
@Override
@GlobalTransactional
public List<OutSampleVO> sampleDepositRepository(DepositDTO dto) {
/**
* 优化接口效率不在循环中操作数据库提前获取需要的数据转成map操作
*/
List<String> ids = dto.getIds();
Map<String, SampleStorage> sampleStorageMap = storageMapper
.selectList(Wrappers.<SampleStorage>lambdaQuery().in(SampleStorage::getId, ids))
.stream().collect(Collectors.toMap(SampleStorage::getId, Function.identity()));
ArrayList<String> sampleIds = new ArrayList<>();
List<OutSampleVO> outSampleVOS = new ArrayList<>();
for (String id:dto.getIds()) {//这里的id是样本存储表的id
SampleStorage sampleStorage = storageMapper.selectById(id);
if(sampleStorage==null){
throw new RuntimeException(String.format("当前"+id+"样本存储数据为空"));
List<SampleStorage> sampleStorageList = ids.stream().map(id -> {
//这里的id是样本存储表的id
SampleStorage sampleStorage = sampleStorageMap.get(id);
if (sampleStorage == null) {
throw new RuntimeException(String.format("当前id为 %s 样本存储数据为空", id));
}
if(sampleStorage.getStatus()!=1){
throw new RuntimeException(String.format("当前"+id+"样本不是待存放的状态"));
if (sampleStorage.getStatus() != 1) {
throw new RuntimeException(String.format("当前id为 %s 样本不是待存放的状态", id));
}
sampleStorage.setStorageLocation(dto.getStorageLocation());
sampleStorage.setStatus(2);//入库已经存放
@ -467,24 +479,28 @@ public class SamplePutInStorageServiceImpl implements SamplePutInStorageService
sampleStorage.setBoxId(dto.getBoxId());
sampleStorage.setCabinetName(dto.getCabinetName());//柜子名称
sampleStorage.setBuildingLv(dto.getBuildingLv());//楼层
//数据修改
storageMapper.updateById(sampleStorage);
//添加样本id
sampleIds.add(sampleStorage.getSampleId());
OutSampleVO sampleVO;
if (dto.getType() == 0) {
sampleVO = storageMapper.getSampleById(sampleStorage.getSampleId());
} else {
sampleVO = drugMaterialInfoService.drugMaterialToOutSampleVO(sampleStorage, sampleStorage.getSampleId());
//3.毒品库中的毒品检材信息样本状态为已入库
drugMaterialInfoService.update(Wrappers.<DrugMaterialInfo>lambdaUpdate().eq(DrugMaterialInfo::getId, sampleStorage.getSampleId())
.set(DrugMaterialInfo::getStatus, DrugMaterialStatus.FINISH_INBOUND.getStatus()));
}
sampleVO.setStorageLocation(dto.getStorageLocation());
outSampleVOS.add(sampleVO);
return sampleStorage;
}).collect(Collectors.toList());
// 批量更新
sampleStorageService.updateBatchById(sampleStorageList);
// 根据检材的类型做对应的处理
if (dto.getType() == 0) {
sampleStorageList.forEach(sampleStorage -> {
OutSampleVO sampleVO = storageMapper.getSampleById(sampleStorage.getSampleId());
sampleVO.setStorageLocation(dto.getStorageLocation());
outSampleVOS.add(sampleVO);
});
} else {
sampleStorageList.forEach(sampleStorage ->
outSampleVOS.add(drugMaterialInfoService.drugMaterialToOutSampleVO(sampleStorage, sampleStorage.getSampleId()))
);
//3.毒品库中的毒品检材信息样本状态为已入库
drugMaterialInfoService.update(Wrappers.<DrugMaterialInfo>lambdaUpdate().in(DrugMaterialInfo::getId, sampleIds)
.set(DrugMaterialInfo::getStatus, DrugMaterialStatus.FINISH_INBOUND.getStatus()));
}
//去除最后一个“,”
//String str = sampleIds.substring(0,sampleIds.lastIndexOf(","));

Loading…
Cancel
Save