|
|
@@ -1,13 +1,100 @@
|
|
|
package com.github.jfcloud.gene.form.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.lang.Assert;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.github.jfcloud.gene.common.util.CustomIdGenerator;
|
|
|
+import com.github.jfcloud.gene.file.entity.FileInfo;
|
|
|
+import com.github.jfcloud.gene.file.service.FileInfoService;
|
|
|
+import com.github.jfcloud.gene.form.entity.AnimalDemand;
|
|
|
+import com.github.jfcloud.gene.form.entity.CageDemand;
|
|
|
import com.github.jfcloud.gene.form.entity.StrainPurificationInfo;
|
|
|
import com.github.jfcloud.gene.form.mapper.StrainPurificationInfoMapper;
|
|
|
+import com.github.jfcloud.gene.form.service.AnimalDemandService;
|
|
|
+import com.github.jfcloud.gene.form.service.CageDemandService;
|
|
|
import com.github.jfcloud.gene.form.service.StrainPurificationInfoService;
|
|
|
+import com.github.jfcloud.gene.form.vo.StrainPurificationInfoVo;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
public class StrainPurificationInfoServiceImpl extends ServiceImpl<StrainPurificationInfoMapper, StrainPurificationInfo> implements StrainPurificationInfoService {
|
|
|
+
|
|
|
+ private final CageDemandService cageDemandService;
|
|
|
+
|
|
|
+ private final AnimalDemandService animalDemandService;
|
|
|
+
|
|
|
+ private final FileInfoService fileInfoService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void saveForm(StrainPurificationInfoVo vo) {
|
|
|
+ StrainPurificationInfo purificationInfo = BeanUtil.copyProperties(vo, StrainPurificationInfo.class);
|
|
|
+ purificationInfo.setId(CustomIdGenerator.nextId());
|
|
|
+ purificationInfo.insert();
|
|
|
+
|
|
|
+ saveDetailList(purificationInfo.getId(), vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveDetailList(Long id, StrainPurificationInfoVo vo) {
|
|
|
+ //保存笼位需求
|
|
|
+ if (!vo.getCageDemands().isEmpty()) {
|
|
|
+ List<CageDemand> cageDemandList = vo.getCageDemands().stream()
|
|
|
+ .map(x -> {
|
|
|
+ CageDemand cageDemand = BeanUtil.copyProperties(x, CageDemand.class);
|
|
|
+ cageDemand.setPurificationId(id);
|
|
|
+ cageDemand.setId(CustomIdGenerator.nextId());
|
|
|
+ return cageDemand;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ cageDemandService.saveBatch(cageDemandList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存动物需求
|
|
|
+ if (!vo.getAnimalDemands().isEmpty()) {
|
|
|
+ List<AnimalDemand> cageDemandList = vo.getAnimalDemands().stream()
|
|
|
+ .map(x -> {
|
|
|
+ AnimalDemand animalDemand = BeanUtil.copyProperties(x, AnimalDemand.class);
|
|
|
+ animalDemand.setPurificationId(id);
|
|
|
+ animalDemand.setId(CustomIdGenerator.nextId());
|
|
|
+ return animalDemand;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ animalDemandService.saveBatch(cageDemandList);
|
|
|
+ }
|
|
|
+
|
|
|
+ //保存附件
|
|
|
+ if (!vo.getTestingFiles().isEmpty()) {
|
|
|
+ List<FileInfo> fileList = vo.getTestingFiles().stream()
|
|
|
+ .map(x -> {
|
|
|
+ FileInfo fileInfo = BeanUtil.copyProperties(x, FileInfo.class);
|
|
|
+ fileInfo.setRelateId(id);
|
|
|
+ return fileInfo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ fileInfoService.saveBatch(fileList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void updateForm(Long id, StrainPurificationInfoVo vo) {
|
|
|
+ StrainPurificationInfo info = getById(id);
|
|
|
+ Assert.notNull(info, "品系净化扩繁不存在");
|
|
|
+
|
|
|
+ BeanUtil.copyProperties(vo, info);
|
|
|
+ info.updateById();
|
|
|
+
|
|
|
+ //先删除附件等,再进行保存
|
|
|
+ cageDemandService.remove(new LambdaQueryWrapper<>(CageDemand.class).eq(CageDemand::getPurificationId, id));
|
|
|
+ animalDemandService.remove(new LambdaQueryWrapper<>(AnimalDemand.class).eq(AnimalDemand::getPurificationId, id));
|
|
|
+ fileInfoService.remove(new LambdaQueryWrapper<>(FileInfo.class).eq(FileInfo::getRelateId, id));
|
|
|
+
|
|
|
+ saveDetailList(id, vo);
|
|
|
+ }
|
|
|
}
|