From 3c884ccd7b51edf3b36840bf99de5edaa41a38a7 Mon Sep 17 00:00:00 2001 From: 张天森 <1292933220@qq.com> Date: 星期三, 12 十月 2022 19:05:28 +0800 Subject: [PATCH] 三说会堂事件流程处理 --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComCvtServeServiceImpl.java | 120 ++++++++++++++++++++++++++++++++++++----------------------- 1 files changed, 73 insertions(+), 47 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 c6d9062..ff49f3d 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,18 @@ package com.panzhihua.service_community.service.impl; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.annotation.Resource; + +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; + +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; @@ -11,22 +24,14 @@ 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.service_community.dao.ComCvtBusinessAreaDAO; +import com.panzhihua.common.model.vos.community.ComMngPopulationImportErrorVO; import com.panzhihua.service_community.dao.ComCvtBusinessDAO; import com.panzhihua.service_community.dao.ComCvtCategoryDAO; import com.panzhihua.service_community.dao.ComCvtServeDAO; -import com.panzhihua.service_community.model.dos.ComCvtBusinessAreaDO; import com.panzhihua.service_community.model.dos.ComCvtBusinessDO; import com.panzhihua.service_community.model.dos.ComCvtCategoryDO; import com.panzhihua.service_community.model.dos.ComCvtServeDO; import com.panzhihua.service_community.service.ComCvtServeService; -import org.springframework.beans.BeanUtils; -import org.springframework.stereotype.Service; -import org.springframework.util.ObjectUtils; - -import javax.annotation.Resource; -import java.util.*; -import java.util.stream.Collectors; /** * @description: 社区 便民服务接口实现类 @@ -67,7 +72,7 @@ public R addComCvtServe(ComCvtServeDTO comCvtServeDTO) { ComCvtServeDO comCvtServeDO = new ComCvtServeDO(); BeanUtils.copyProperties(comCvtServeDTO, comCvtServeDO); - if(checkRepeat(comCvtServeDO)){ + if (checkRepeat(comCvtServeDO)) { return R.fail("服务已存在"); } int insert = comCvtServeDAO.insert(comCvtServeDO); @@ -85,7 +90,7 @@ } ComCvtServeDO comCvtServeDO2 = new ComCvtServeDO(); BeanUtils.copyProperties(comCvtServeDTO, comCvtServeDO2); - if(!comCvtServeDO.equals(comCvtServeDO2) && checkRepeat(comCvtServeDO2)){ + if (!comCvtServeDO.equals(comCvtServeDO2) && checkRepeat(comCvtServeDO2)) { return R.fail("该服务与其他服务重复"); } int update = comCvtServeDAO.updateById(comCvtServeDO2); @@ -130,8 +135,10 @@ @Override public List<ComCvtBusinessCategoryServeVO> getBusinessCategoryServeVOS(Long businessId) { List<ComCvtBusinessCategoryServeVO> comCvtBusinessCategoryServeVOS = new ArrayList<>(); - List<ComCvtServeDO> comCvtServeDOS = comCvtServeDAO.selectList(new QueryWrapper<ComCvtServeDO>().lambda().eq(ComCvtServeDO::getBusinessId, businessId)); - List<ComCvtCategoryDO> categoryDOS = comCvtCategoryDAO.selectList(new QueryWrapper<ComCvtCategoryDO>().lambda().orderByDesc(ComCvtCategoryDO::getWeight)); + List<ComCvtServeDO> comCvtServeDOS = comCvtServeDAO + .selectList(new QueryWrapper<ComCvtServeDO>().lambda().eq(ComCvtServeDO::getBusinessId, businessId)); + List<ComCvtCategoryDO> categoryDOS = comCvtCategoryDAO + .selectList(new QueryWrapper<ComCvtCategoryDO>().lambda().orderByDesc(ComCvtCategoryDO::getWeight)); categoryDOS.stream().forEach(categoryDO -> { List<ComCvtServeVO> serveVOS = getComCvtServeDOSByCategory(comCvtServeDOS, categoryDO.getId()); if (!ObjectUtils.isEmpty(serveVOS)) { @@ -153,7 +160,8 @@ */ private List<ComCvtServeVO> getComCvtServeDOSByCategory(List<ComCvtServeDO> comCvtServeDOS, Long categoryId) { List<ComCvtServeVO> comCvtServeVOS = new ArrayList<>(); - comCvtServeDOS = comCvtServeDOS.stream().filter(dos -> dos.getCategoryId() == categoryId).collect(Collectors.toList()); + comCvtServeDOS = + comCvtServeDOS.stream().filter(dos -> dos.getCategoryId() == categoryId).collect(Collectors.toList()); comCvtServeDOS.forEach(comCvtServeDO -> { ComCvtServeVO vo = new ComCvtServeVO(); BeanUtils.copyProperties(comCvtServeDO, vo); @@ -165,56 +173,74 @@ @Override public R listSaveConvenientServeExcelVO(List<ComCvtServeExcelVO> list, Long communityId) { List<ComCvtServeDO> comCvtServeDOS = new ArrayList<>(); - List<ComCvtCategoryDO> categoryDOS = comCvtCategoryDAO.selectList(new QueryWrapper<ComCvtCategoryDO>().lambda().orderByDesc(ComCvtCategoryDO::getWeight)); + 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)); + comCvtBusinessDOS = comCvtBusinessDAO.selectList( + new QueryWrapper<ComCvtBusinessDO>().lambda().eq(ComCvtBusinessDO::getCommunityId, communityId)); } else { comCvtBusinessDOS = comCvtBusinessDAO.selectList(new LambdaQueryWrapper<>()); } Map<String, Long> businessMap = getBusinessMap(comCvtBusinessDOS); - List<String> errorInfo = new ArrayList<>(); int index = 2; - for (ComCvtServeExcelVO comCvtServeExcelVO:list) { + for (ComCvtServeExcelVO comCvtServeExcelVO : list) { + /** * 便民服务分类存在 并且 便民服务商家 匹配上 */ - if (categoryMap.containsKey(comCvtServeExcelVO.getCategoryName()) && businessMap.containsKey(comCvtServeExcelVO.getBusinessName())) { + if (categoryMap.containsKey(comCvtServeExcelVO.getCategoryName()) + && businessMap.containsKey(comCvtServeExcelVO.getBusinessName())) { ComCvtServeDO comCvtServeDO = new ComCvtServeDO(); BeanUtils.copyProperties(comCvtServeExcelVO, comCvtServeDO); comCvtServeDO.setCategoryId(categoryMap.get(comCvtServeExcelVO.getCategoryName())); comCvtServeDO.setBusinessId(businessMap.get(comCvtServeExcelVO.getBusinessName())); - //检查商家是否已有某服务 - if(!checkRepeat(comCvtServeDO)){ + // 检查商家是否已有某服务 + if (!checkRepeat(comCvtServeDO)) { comCvtServeDOS.add(comCvtServeDO); - }else{ - log.error(String.format("导入失败:商家【%s】下已有服务【%s】",comCvtServeExcelVO.getBusinessName(),comCvtServeExcelVO.getServiceName())); + } 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())) { - errorInfo.add(comCvtServeExcelVO.getCategoryName() +"导入失败: 服务分类不存在"); + } 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())) { - errorInfo.add(comCvtServeExcelVO.getBusinessName() +"导入失败: 便民服务商家不存在"); + if (!businessMap.containsKey(comCvtServeExcelVO.getBusinessName())) { + ComMngPopulationImportErrorVO importErrorVO = new ComMngPopulationImportErrorVO(); + importErrorVO.setErrorMsg("导入失败: 便民服务商家" + comCvtServeExcelVO.getBusinessName() + "不存在"); +// importErrorVO.setErrorPosition("第" + index + "行,第5列"); + populationImportErrorVOList.add(importErrorVO); } } + index++; } boolean saveBatched = this.saveBatch(comCvtServeDOS); - if(saveBatched) { - if (comCvtServeDOS.size()>0 && errorInfo != null && errorInfo.size() > 0) { - return R.fail("导入部分成功:" + errorInfo.toString()); + if (saveBatched) { + if (comCvtServeDOS.size() > 0 && populationImportErrorVOList.size() > 0) { + return R.fail(JSON.toJSONString(populationImportErrorVOList)); } - if(comCvtServeDOS.size()==0 && errorInfo != null && errorInfo.size() > 0){ - return R.fail("导入失败:" + errorInfo.toString()); + if (comCvtServeDOS.size() == 0 && populationImportErrorVOList.size() > 0) { + return R.fail(JSON.toJSONString(populationImportErrorVOList)); } - }else { - return R.fail("导入失败:" + errorInfo.toString()); + } else { + return R.fail(JSON.toJSONString(populationImportErrorVOList)); } - return R.ok("共计导入服务数量:"+comCvtServeDOS.size()); + return R.ok("共计导入服务数量:" + comCvtServeDOS.size()); } - //获取分类集合 + // 获取分类集合 private Map<String, Long> getCategoryMap(List<ComCvtCategoryDO> categoryDOS) { Map<String, Long> categoryMap = new HashMap<>(); if (!ObjectUtils.isEmpty(categoryDOS)) { @@ -225,7 +251,7 @@ return categoryMap; } - //获取商家集合 + // 获取商家集合 private Map<String, Long> getBusinessMap(List<ComCvtBusinessDO> comCvtBusinessDOS) { Map<String, Long> businessMap = new HashMap<>(); if (!ObjectUtils.isEmpty(comCvtBusinessDOS)) { @@ -238,17 +264,17 @@ /** * 检查服务是否重复 商家名称、分类名称,服务名称、服务价格、服务描述不能同时重复 + * * @param comCvtServeDO * @return */ - private boolean checkRepeat(ComCvtServeDO comCvtServeDO){ - Integer count = comCvtServeDAO.selectCount(new QueryWrapper<ComCvtServeDO>().lambda() - .eq(ComCvtServeDO::getBusinessId,comCvtServeDO.getBusinessId()) - .and(wrapper->wrapper.eq(ComCvtServeDO::getCategoryId,comCvtServeDO.getCategoryId())) - .and(wrapper->wrapper.eq(ComCvtServeDO::getServiceName,comCvtServeDO.getServiceName())) - .and(wrapper->wrapper.eq(ComCvtServeDO::getServicePrice,comCvtServeDO.getServicePrice())) - .and(wrapper->wrapper.eq(ComCvtServeDO::getServiceDesc,comCvtServeDO.getServiceDesc())) - ); - return count>0 ? true : false; + private boolean checkRepeat(ComCvtServeDO comCvtServeDO) { + Integer count = comCvtServeDAO.selectCount( + new QueryWrapper<ComCvtServeDO>().lambda().eq(ComCvtServeDO::getBusinessId, comCvtServeDO.getBusinessId()) + .and(wrapper -> wrapper.eq(ComCvtServeDO::getCategoryId, comCvtServeDO.getCategoryId())) + .and(wrapper -> wrapper.eq(ComCvtServeDO::getServiceName, comCvtServeDO.getServiceName())) + .and(wrapper -> wrapper.eq(ComCvtServeDO::getServicePrice, comCvtServeDO.getServicePrice())) + .and(wrapper -> wrapper.eq(ComCvtServeDO::getServiceDesc, comCvtServeDO.getServiceDesc()))); + return count > 0; } } -- Gitblit v1.7.1