From eeb8d7faa8d25b3ca9fe75ef28f035c49af5b06d Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期二, 11 三月 2025 11:05:38 +0800
Subject: [PATCH] Merge branch 'dev' into dev_zj

---
 basic-server/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java |  186 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 186 insertions(+), 0 deletions(-)

diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java b/basic-server/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java
new file mode 100644
index 0000000..f6ec4d6
--- /dev/null
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/impl/ProductServiceImpl.java
@@ -0,0 +1,186 @@
+package com.ruoyi.basic.service.impl;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.dto.ProductDTO1;
+import com.ruoyi.basic.excel.StructureTestObjectData;
+import com.ruoyi.basic.mapper.ProductMapper;
+import com.ruoyi.basic.mapper.StandardTreeMapper;
+import com.ruoyi.basic.mapper.StructureTestObjectMapper;
+import com.ruoyi.basic.pojo.*;
+import com.ruoyi.basic.service.LaboratoryService;
+import com.ruoyi.basic.service.ProductService;
+import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.QueryWrappers;
+import com.ruoyi.basic.service.StandardProductListService;
+import com.ruoyi.basic.service.StructureItemParameterService;
+import lombok.AllArgsConstructor;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+/**
+* @author z1292
+* @description 閽堝琛ㄣ�恜roduct(浜у搧琛�)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
+* @createDate 2024-04-26 01:11:02
+*/
+@Service
+@AllArgsConstructor
+public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product>
+    implements ProductService {
+
+    private ProductMapper productMapper;
+
+    private LaboratoryService laboratoryService;
+
+    private StructureTestObjectMapper structureTestObjectMapper;
+
+    private StandardProductListService standardProductListService;
+
+    private StandardTreeMapper standardTreeMapper;
+
+    private StructureItemParameterService structureItemParameterService;
+
+    @Override
+    public IPage<Product> selectProductListByObjectId(Page page, ProductDTO1 product) {
+        String partNo = product.getPartNo();
+        product.setPartNo(null);
+        return productMapper.selectProductListByObjectId(page, QueryWrappers.queryWrappers(product), partNo);
+    }
+
+    @Override
+    public int addProduct(Product product) {
+
+        return productMapper.insert(product);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int upProduct(Product product) {
+        // 鏌ヨ鍘熸湰鐨勫悕绉�
+        Product oldProduct = productMapper.selectById(product.getId());
+
+        if (!oldProduct.getName().equals(product.getName())) {
+            // 淇敼鍚嶇О鍖归厤鐨勬爣鍑嗘爲涓嬬殑妫�楠岄」鐩�
+            // 鏌ヨ鎵�鏈夊璞�+鍚嶇О鐨勬爲
+            StructureTestObject testObject = structureTestObjectMapper.selectById(oldProduct.getObjectId());
+
+            List<StandardProductList> standardProductLists = standardProductListService.list(Wrappers.<StandardProductList>lambdaUpdate()
+                    .eq(StandardProductList::getSample, oldProduct.getName())
+                    .eq(StandardProductList::getSampleType, testObject.getSpecimenName()));
+            if (CollectionUtils.isNotEmpty(standardProductLists)) {
+                for (StandardProductList standardProductList : standardProductLists) {
+                    // 淇敼鏍峰搧鍚嶇О
+                    standardProductList.setSample(product.getName());
+                    // 淇敼鏍戝悕绉�
+                    // 闇�瑕佹埅鍙栫鍥涚骇, 閬垮厤涓夊洓绾у悕绉颁竴鏍蜂慨鏀归敊璇�
+                    String[] trees = standardProductList.getTree().split(" - ");
+                    trees[3] = product.getName();
+                    List<String> list = CollUtil.newArrayList(trees);
+                    String newName = CollUtil.join(list, " - ");
+                    standardProductList.setTree(newName);
+                }
+                standardProductListService.updateBatchById(standardProductLists);
+            }
+
+            // 淇敼妫�楠岄」鐩弬鏁扮殑妫�楠屽璞�
+            // 鎷兼帴["object","product"]鏌ヨ妫�楠岄」鐩弬鏁颁慨鏀圭粦瀹氱殑妫�楠屽璞�
+            String format = "[\"{}\",\"{}\"]";
+            String sampleOld = StrUtil.format(format, testObject.getSpecimenName(), oldProduct.getName());
+            List<StructureItemParameter> itemParameterList = structureItemParameterService.list(Wrappers.<StructureItemParameter>lambdaQuery()
+                    .like(StructureItemParameter::getSample, sampleOld));
+            if (CollectionUtils.isNotEmpty(itemParameterList)) {
+                for (StructureItemParameter structureItemParameter : itemParameterList) {
+                    // 淇敼缁戝畾鐨勬牱鍝佸悕绉�
+                    String sampleNew = StrUtil.format(format, testObject.getSpecimenName(), product.getName());
+                    String sampleUp = structureItemParameter.getSample().replace(sampleOld, sampleNew);
+                    structureItemParameter.setSample(sampleUp);
+                }
+                structureItemParameterService.updateBatchById(itemParameterList);
+            }
+
+            // 淇敼鏍戠殑鍨嬪彿
+            standardTreeMapper.update(null, Wrappers.<StandardTree>lambdaUpdate()
+                    .eq(StandardTree::getSampleType, testObject.getSpecimenName())
+                    .eq(StandardTree::getSample, oldProduct.getName())
+                    .set(StandardTree::getSample, product.getName()));
+        }
+
+        return productMapper.updateById(product);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int delProduct(Integer id) {
+        return productMapper.deleteById(id);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void importPartExcel(List<StructureTestObjectData> list) {
+        list.forEach(i -> {
+            // 妫�楠屽璞�
+            StructureTestObject structureTestObject1 = structureTestObjectMapper.selectOne(Wrappers.<StructureTestObject>lambdaQuery()
+                    .eq(StructureTestObject::getSpecimenName, i.getSpecimenName())
+                    .eq(StructureTestObject::getSpecimenNameEn, i.getSpecimenNameEn()));
+            Laboratory laboratory = laboratoryService.getOne(Wrappers.<Laboratory>lambdaQuery()
+                    .eq(Laboratory::getLaboratoryName, i.getLaboratory()));
+            if (ObjectUtils.isEmpty(laboratory)) {
+                throw new BaseException("鏈壘鍒拌鍦烘墍锛�" + i.getLaboratory() + "锛岃妫�鏌ユ槸鍚﹀瓨鍦ㄨ鍦烘墍锛�");
+            }
+            // 濡傛灉涓虹┖杩涜鏂板
+            if(ObjectUtils.isEmpty(structureTestObject1)) {
+                StructureTestObject structureTestObject = new StructureTestObject();
+                structureTestObject.setLaboratoryId(laboratory.getId());
+                structureTestObject.setSpecimenName(i.getSpecimenName());
+                structureTestObject.setSpecimenNameEn(i.getSpecimenNameEn());
+                structureTestObject.setCode(i.getCode());
+                structureTestObjectMapper.insert(structureTestObject);
+
+                // 浜у搧
+                Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery()
+                        .eq(Product::getName, i.getName())
+                        .eq(Product::getNameEn, i.getNameEn()));
+                if (ObjectUtils.isEmpty(product)){
+                    Product product1 = new Product();
+                    product1.setName(i.getName());
+                    product1.setNameEn(i.getNameEn());
+                    product1.setObjectId(structureTestObject.getId());
+                    baseMapper.insert(product1);
+                }
+            } else {
+                structureTestObject1.setCode(i.getCode());
+                structureTestObject1.setLaboratoryId(laboratory.getId());
+                structureTestObjectMapper.updateById(structureTestObject1);
+                // 浜у搧
+                Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery()
+                        .eq(Product::getName, i.getName())
+                        .eq(Product::getNameEn, i.getNameEn()));
+                if (ObjectUtils.isEmpty(product)){
+                    Product product1 = new Product();
+                    product1.setName(i.getName());
+                    product1.setNameEn(i.getNameEn());
+                    product1.setObjectId(structureTestObject1.getId());
+                    baseMapper.insert(product1);
+                } else {
+                    product.setName(i.getName());
+                    product.setNameEn(i.getNameEn());
+                    product.setObjectId(structureTestObject1.getId());
+                    baseMapper.updateById(product);
+                }
+            }
+        });
+    }
+
+    @Override
+    public String getWordQrModel(Integer orderId) {
+        return baseMapper.getWordQrModel(orderId);
+    }
+}

--
Gitblit v1.9.3