From 77946261ec663aa1fe7f6f97e550532ed879f982 Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期五, 06 六月 2025 13:47:46 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/2.0.1' into 2.0.1

---
 server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwMaterialServiceImpl.java |   95 ++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 89 insertions(+), 6 deletions(-)

diff --git a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwMaterialServiceImpl.java b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwMaterialServiceImpl.java
index a434cd2..ea498da 100644
--- a/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwMaterialServiceImpl.java
+++ b/server/visits/dmvisit_service/src/main/java/com/doumee/service/business/impl/YwMaterialServiceImpl.java
@@ -1,6 +1,8 @@
 package com.doumee.service.business.impl;
 
+import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
 import com.doumee.biz.system.SystemDictDataBiz;
+import com.doumee.core.annotation.excel.ExcelImporter;
 import com.doumee.core.constants.ResponseStatus;
 import com.doumee.core.exception.BusinessException;
 import com.doumee.core.model.LoginUserInfo;
@@ -9,11 +11,14 @@
 import com.doumee.core.model.PageWrap;
 import com.doumee.core.utils.Constants;
 import com.doumee.core.utils.Utils;
+import com.doumee.dao.business.CategoryMapper;
 import com.doumee.dao.business.YwMaterialMapper;
 import com.doumee.dao.business.YwOutinboundMapper;
 import com.doumee.dao.business.YwOutinboundRecordMapper;
 import com.doumee.dao.business.model.*;
 import com.doumee.dao.system.MultifileMapper;
+import com.doumee.dao.system.dto.ImportMaterialDTO;
+import com.doumee.dao.system.dto.ImportSystemUserDTO;
 import com.doumee.dao.system.model.Multifile;
 import com.doumee.service.business.YwMaterialService;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -22,16 +27,19 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.base.MPJBaseMapper;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
+import javafx.scene.paint.Material;
 import org.apache.commons.lang.StringUtils;
-import org.checkerframework.checker.units.qual.A;
+import org.apache.shiro.SecurityUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Bean;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
+import org.springframework.web.multipart.MultipartFile;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 杩愮淮璧勪骇淇℃伅琛⊿ervice瀹炵幇
@@ -51,6 +59,9 @@
     private YwOutinboundRecordMapper ywOutinboundRecordMapper;
 
     @Autowired
+    private CategoryMapper categoryMapper;
+
+    @Autowired
     private SystemDictDataBiz systemDictDataBiz;
 
     @Override
@@ -67,8 +78,17 @@
         ywMaterial.setId(null);
         if(StringUtils.isBlank(ywMaterial.getCode())){
             //鑷姩鐢熸垚 TODO 瀛樺湪闂
-            Long countCode = ywMaterialMapper.selectCount(new QueryWrapper<YwMaterial>().lambda().eq(YwMaterial::getAutoCode, Constants.ONE));
-            String nextCode = StringUtils.leftPad(Long.toString(countCode + 1),4,"0");
+            YwMaterial lastAutoMaterial = ywMaterialMapper.selectOne(new QueryWrapper<YwMaterial>().lambda().eq(YwMaterial::getAutoCode,Constants.ONE).last("limit 1 "));
+            Long countCode = 0L;
+            String nextCode = StringUtils.leftPad(Long.toString(countCode + 1 ),4,"0");
+            if(Objects.nonNull(lastAutoMaterial)){
+                Long maxCode = Long.valueOf(lastAutoMaterial.getCode().replace("P",""));
+                nextCode = StringUtils.leftPad(Long.toString(maxCode + 1),4,"0");
+                while (ywMaterialMapper.selectCount(new QueryWrapper<YwMaterial>().lambda().eq(YwMaterial::getCode, "P"+nextCode))>Constants.ZERO){
+                    countCode = countCode + 1 ;
+                    nextCode = StringUtils.leftPad(Long.toString(countCode),4,"0");
+                }
+            }
             ywMaterial.setCode("P"+nextCode);
             ywMaterial.setAutoCode(Constants.ONE);
         }else{
@@ -247,4 +267,67 @@
         QueryWrapper<YwMaterial> wrapper = new QueryWrapper<>(ywMaterial);
         return ywMaterialMapper.selectCount(wrapper);
     }
+
+
+    @Override
+    public Integer importMaterialBatch(MultipartFile file,LoginUserInfo loginUserInfo) {
+        try {
+            ExcelImporter ie = new ExcelImporter(file, 0, 0);
+            List<ImportMaterialDTO> dataList = ie.getDataList(ImportMaterialDTO.class, null);
+            if (CollectionUtils.isEmpty(dataList)) {
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝褰曞叆鏁版嵁涓虹┖锛�");
+            }
+
+            List<Category> allCategory = categoryMapper.selectList(new QueryWrapper<Category>().lambda()
+                    .eq(Category::getIsdeleted,Constants.ZERO).eq(Category::getIsdeleted,Constants.ZERO)
+                    .eq(Category::getType,Constants.SEVEN)
+            );
+            if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isEmpty(allCategory)){
+                throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝鏃犲垎绫诲熀纭�鏁版嵁锛�");
+            }
+            List<Category> categoryList = allCategory.stream().filter(i->Objects.isNull(i.getParentId())).collect(Collectors.toList());
+            for (Category category: categoryList) {
+                category.setChildCategoryList(
+                        allCategory.stream().filter(i->Objects.nonNull(i.getParentId())&&Constants.equalsInteger(i.getParentId(),category.getId())).collect(Collectors.toList())
+                );
+            }
+            List<YwMaterial> ywMaterialList = new ArrayList<>();
+            for (int i = 0; i < dataList.size(); i++) {
+                ImportMaterialDTO importMaterialDTO = dataList.get(i);
+                if(Objects.isNull(importMaterialDTO)
+                    || StringUtils.isBlank(importMaterialDTO.getName())
+                    || StringUtils.isBlank(importMaterialDTO.getCategoryName())
+                    || StringUtils.isBlank(importMaterialDTO.getCategoryChildName())
+                    || StringUtils.isBlank(importMaterialDTO.getQrcode())
+                ){
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝绗�"+(i+1)+"琛屽繀濉」缂哄け锛�");
+                }
+                YwMaterial ywMaterial = new YwMaterial();
+                BeanUtils.copyProperties(importMaterialDTO,ywMaterial);
+                Optional<Category> categoryOptional = categoryList.stream().filter(j->j.getName().equals(importMaterialDTO.getCategoryName())).findAny();
+                if(categoryOptional.isPresent()){
+                    Category category = categoryOptional.get();
+                    ywMaterial.setParentCateId(category.getId());
+                    Optional<Category> childCategoryOptional = category.getChildCategoryList().stream().filter(j->j.getName().equals(importMaterialDTO.getCategoryChildName())).findAny();
+                    if(childCategoryOptional.isPresent()){
+                        ywMaterial.setCateId(childCategoryOptional.get().getId());
+                    }else{
+                        throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝绗�"+(i+1)+"琛岀墿鏂欏瓙鍒嗙被鏈煡璇㈠埌锛�");
+                    }
+                }else{
+                    throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "瀵逛笉璧凤紝绗�"+(i+1)+"琛岀墿鏂欏垎绫绘湭鏌ヨ鍒帮紒");
+                }
+                ywMaterialList.add(ywMaterial);
+            }
+
+            for (YwMaterial ywMaterial:ywMaterialList) {
+                ywMaterial.setLoginUserInfo(loginUserInfo);
+                this.create(ywMaterial);
+            }
+        } catch (Exception e) {
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),e.getMessage());
+
+        }
+        return null;
+    }
 }

--
Gitblit v1.9.3