From 2e64c232ab6b51b2cecf1ee96e1e9b709234f326 Mon Sep 17 00:00:00 2001
From: huanghongfa <huanghongfa123456>
Date: 星期六, 21 八月 2021 16:35:14 +0800
Subject: [PATCH] 随手拍改版接口开发

---
 springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComCvtServeServiceImpl.java |   46 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComCvtServeServiceImpl.java b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComCvtServeServiceImpl.java
index a42f323..59bafa6 100644
--- a/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComCvtServeServiceImpl.java
+++ b/springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComCvtServeServiceImpl.java
@@ -1,5 +1,7 @@
 package com.panzhihua.service_community.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -10,6 +12,7 @@
 import com.panzhihua.common.model.vos.community.ComCvtBusinessCategoryServeVO;
 import com.panzhihua.common.model.vos.community.ComCvtServeExcelVO;
 import com.panzhihua.common.model.vos.community.ComCvtServeVO;
+import com.panzhihua.common.model.vos.community.ComMngPopulationImportErrorVO;
 import com.panzhihua.service_community.dao.ComCvtBusinessAreaDAO;
 import com.panzhihua.service_community.dao.ComCvtBusinessDAO;
 import com.panzhihua.service_community.dao.ComCvtCategoryDAO;
@@ -164,16 +167,22 @@
     @Override
     public R listSaveConvenientServeExcelVO(List<ComCvtServeExcelVO> list, Long communityId) {
         List<ComCvtServeDO> comCvtServeDOS = new ArrayList<>();
+        List<ComMngPopulationImportErrorVO> populationImportErrorVOList = new ArrayList<>();
         List<ComCvtCategoryDO> categoryDOS = comCvtCategoryDAO.selectList(new QueryWrapper<ComCvtCategoryDO>().lambda().orderByDesc(ComCvtCategoryDO::getWeight));
         Map<String, Long> categoryMap = getCategoryMap(categoryDOS);
         List<ComCvtBusinessDO> comCvtBusinessDOS;
         if (null != communityId && communityId != 0) {
             comCvtBusinessDOS = comCvtBusinessDAO.selectList(new QueryWrapper<ComCvtBusinessDO>().lambda().eq(ComCvtBusinessDO::getCommunityId, communityId));
         } else {
-            comCvtBusinessDOS = comCvtBusinessDAO.selectList(null);
+            comCvtBusinessDOS = comCvtBusinessDAO.selectList(new LambdaQueryWrapper<>());
         }
         Map<String, Long> businessMap = getBusinessMap(comCvtBusinessDOS);
-        list.forEach(comCvtServeExcelVO -> {
+        int index = 2;
+        for (ComCvtServeExcelVO comCvtServeExcelVO:list) {
+
+            /**
+             * 便民服务分类存在 并且 便民服务商家 匹配上
+             */
             if (categoryMap.containsKey(comCvtServeExcelVO.getCategoryName()) && businessMap.containsKey(comCvtServeExcelVO.getBusinessName())) {
                 ComCvtServeDO comCvtServeDO = new ComCvtServeDO();
                 BeanUtils.copyProperties(comCvtServeExcelVO, comCvtServeDO);
@@ -183,11 +192,40 @@
                 if(!checkRepeat(comCvtServeDO)){
                     comCvtServeDOS.add(comCvtServeDO);
                 }else{
+                    ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO();
+                    importErrorVO.setErrorMsg(String.format("导入失败:商家【%s】下已有服务【%s】",comCvtServeExcelVO.getBusinessName(),comCvtServeExcelVO.getServiceName()));
+                    importErrorVO.setErrorPosition("第" + index + "行");
+                    populationImportErrorVOList.add(importErrorVO);
                     log.error(String.format("导入失败:商家【%s】下已有服务【%s】",comCvtServeExcelVO.getBusinessName(),comCvtServeExcelVO.getServiceName()));
                 }
+            }else{
+                if(!categoryMap.containsKey(comCvtServeExcelVO.getCategoryName())) {
+                    ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO();
+                    importErrorVO.setErrorMsg("导入失败: 服务分类" + comCvtServeExcelVO.getCategoryName() +"不存在");
+                    importErrorVO.setErrorPosition("第" + index + "行,第1列");
+                    populationImportErrorVOList.add(importErrorVO);
+//                    errorInfo.add(comCvtServeExcelVO.getCategoryName() +"导入失败: 服务分类不存在");
+                }
+                if(!businessMap.containsKey(comCvtServeExcelVO.getBusinessName())) {
+                    ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO();
+                    importErrorVO.setErrorMsg("导入失败: 便民服务商家" + comCvtServeExcelVO.getBusinessName() +"不存在");
+                    importErrorVO.setErrorPosition("第" + index + "行,第5列");
+                    populationImportErrorVOList.add(importErrorVO);
+                }
             }
-        });
-        this.saveBatch(comCvtServeDOS);
+            index++;
+        }
+        boolean saveBatched = this.saveBatch(comCvtServeDOS);
+        if(saveBatched) {
+            if (comCvtServeDOS.size()>0 && populationImportErrorVOList.size() > 0) {
+                return R.fail(JSON.toJSONString(populationImportErrorVOList));
+            }
+            if(comCvtServeDOS.size()==0 && populationImportErrorVOList.size() > 0){
+                return R.fail(JSON.toJSONString(populationImportErrorVOList));
+            }
+        }else {
+            return R.fail(JSON.toJSONString(populationImportErrorVOList));
+        }
         return R.ok("共计导入服务数量:"+comCvtServeDOS.size());
     }
 

--
Gitblit v1.7.1