From 34981c30a78e8bbd7791131059a9210f9928b62c Mon Sep 17 00:00:00 2001
From: 刘光辉 <347230014@qq.com>
Date: 星期四, 17 九月 2026 09:24:09 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master' into master
---
jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsApplyTestServiceImpl.java | 133 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 133 insertions(+), 0 deletions(-)
diff --git a/jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsApplyTestServiceImpl.java b/jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsApplyTestServiceImpl.java
new file mode 100644
index 0000000..89519a3
--- /dev/null
+++ b/jnpf-lims/jnpf-lims-biz/src/main/java/jnpf/limsService/impl/LimsApplyTestServiceImpl.java
@@ -0,0 +1,133 @@
+package jnpf.limsService.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import jnpf.base.service.SuperServiceImpl;
+import jnpf.enums.LimsSampleEnum;
+import jnpf.limsEntity.*;
+import jnpf.limsMapper.LimsApplyTestMapper;
+import jnpf.limsService.*;
+import jnpf.util.DateUtil;
+import jnpf.util.StringUtil;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.EmptyResultDataAccessException;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import java.util.Comparator;
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Service
+public class LimsApplyTestServiceImpl extends SuperServiceImpl<LimsApplyTestMapper, LimsApplyTestEntity> implements LimsApplyTestService {
+
+ @Autowired
+ private LimsApplyTestItemService limsApplyTestItemService;
+ @Autowired
+ private LimsSampleInfoService limsSampleInfoService;
+ @Autowired
+ private LimsSamplingRecordService limsSamplingRecordService;
+ @Autowired
+ private LimsTestTaskService limsTestTaskService;
+
+ @Autowired
+ private JdbcTemplate jdbcTemplate;
+
+ /**
+ * 鏍规嵁妫�楠屼俊鎭敓鎴愭牱鍝佷俊鎭�
+ * @param limsApplyTestEntity
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void createSampleInfo(LimsApplyTestEntity limsApplyTestEntity) {
+
+ LimsSampleInfoEntity limsSampleInfoEntity = new LimsSampleInfoEntity();
+ LimsSamplingRecordEntity limsSamplingRecordEntity = new LimsSamplingRecordEntity();
+
+ // 鑾峰彇鏍峰搧缂栧彿
+ String sampleCode = creatSampleCode();
+ limsApplyTestEntity.setSampleCode(sampleCode);
+
+ // 鏌ヨsampleId 鏄惁鏈夊�� 锛岄伩鍏嶉噸澶嶇敓鎴�
+ String sampleId = limsApplyTestEntity.getSampleId();
+ if (StringUtil.isNotEmpty(sampleId)) {
+ limsSampleInfoEntity = limsSampleInfoService.getById(sampleId);
+ }
+
+ // 澶嶅埗淇℃伅
+ BeanUtils.copyProperties(limsApplyTestEntity, limsSampleInfoEntity,"fId");
+ BeanUtils.copyProperties(limsApplyTestEntity, limsSamplingRecordEntity,"fId");
+
+ // 鍥炲啓璇锋ID
+ limsSampleInfoEntity.setApplyId(limsApplyTestEntity.getId());
+
+ //鑾峰彇瀵瑰簲娴佺▼淇℃伅
+ LimsSampleEnum sampleRecord = LimsSampleEnum.SAMPLE_RECORD;
+ // 璇锋宸插畬鎴� 鐘舵�佷负寰呭彇鏍�
+ limsSampleInfoEntity.setSampleStatus(String.valueOf(sampleRecord.getCode()));
+ //limsSamplingRecordEntity.setApplyId(limsApplyTestEntity.getFId());
+
+ // 淇濆瓨瀵瑰簲淇℃伅
+ limsSampleInfoService.save(limsSampleInfoEntity);
+
+ // 鍥炲啓SampleId
+ limsSamplingRecordEntity.setSampleId(limsSampleInfoEntity.getId());
+ limsSamplingRecordService.save(limsSamplingRecordEntity);
+
+ // 璇锋宸插畬鎴� 鍥炲啓SampleId
+ limsApplyTestEntity.setSampleId(limsSampleInfoEntity.getId());
+ limsApplyTestEntity.setApplyStatus("2");
+ this.updateById(limsApplyTestEntity);
+
+ // 鐢熸垚瀵瑰簲鐨勬楠屼换鍔�
+ LambdaQueryWrapper<LimsApplyTestItemEntity> itemQueryWrapper = new LambdaQueryWrapper<>();
+ itemQueryWrapper.eq(LimsApplyTestItemEntity::getFForeignId, limsApplyTestEntity.getId());
+ // 鑾峰彇妫�楠岄」鐩俊鎭�
+ List<LimsApplyTestItemEntity> itemList = limsApplyTestItemService.list(itemQueryWrapper);
+ // 璧嬪��
+ List<LimsTestTaskEntity> taskEntityList = itemList.stream().map(item -> {
+ LimsTestTaskEntity limsTestTaskEntity = new LimsTestTaskEntity();
+ BeanUtils.copyProperties(item, limsTestTaskEntity, "id");
+ BeanUtils.copyProperties(limsApplyTestEntity, limsTestTaskEntity, "id");
+ limsTestTaskEntity.setCheckStatus(String.valueOf(sampleRecord.getItemCode()));
+ return limsTestTaskEntity;
+ }).collect(Collectors.toList());
+
+ // 灏� null 鍊兼帓鍦ㄦ渶鍚庨潰
+ taskEntityList = taskEntityList.stream()
+ .sorted(Comparator.nullsLast(
+ Comparator.comparing(LimsTestTaskEntity::getItemSort)))
+ .collect(Collectors.toList());
+
+ // 淇濆瓨淇℃伅
+ limsTestTaskService.saveBatch(taskEntityList);
+ }
+
+ public String creatSampleCode() {
+ String sql = "SELECT MAX(SAMPLE_CODE) FROM lims_sample_info";
+
+ String maxCode;
+ try {
+ maxCode = jdbcTemplate.queryForObject(sql, String.class);
+ } catch (EmptyResultDataAccessException e) {
+ maxCode = null;
+ }
+
+ // 鑾峰彇骞翠唤
+ String year = DateUtil.getNow().split("-")[0];
+
+ if (StringUtil.isEmpty(maxCode)) {
+ maxCode = "SAMPLE-" + year + "-001";
+ } else {
+ // 鍒ゆ柇鏄惁涓烘柊鐨勪竴骞�
+ if (year.equals(maxCode.split("-")[1])){
+ maxCode = "SAMPLE-" + year + "-" + String.format("%03d", Integer.parseInt(maxCode.split("-")[2] + 1));
+ } else {
+ maxCode = "SAMPLE-" + year + "-001";
+ }
+ }
+ return maxCode;
+ }
+}
--
Gitblit v1.8.0