From 3ca7f722f25c1908bc4588c75dbde1f56a8d9877 Mon Sep 17 00:00:00 2001 From: DESKTOP-71BH0QO\L、ming <172680469@qq.com> Date: 星期五, 26 三月 2021 10:08:46 +0800 Subject: [PATCH] Merge branch 'master' of http://gitlab.nhys.cdnhxx.com/root/zhihuishequ --- springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ComCvtServeServiceImpl.java | 89 ++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 84 insertions(+), 5 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 cae6884..a42f323 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 @@ -3,14 +3,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.panzhihua.common.model.dtos.community.ComCvtServeDTO; import com.panzhihua.common.model.dtos.community.PageComCvtServeDTO; import com.panzhihua.common.model.vos.R; 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.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; @@ -20,8 +24,7 @@ import org.springframework.util.ObjectUtils; import javax.annotation.Resource; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; /** @@ -30,7 +33,7 @@ * @date: 2021/3/12 8:58 */ @Service -public class ComCvtServeServiceImpl implements ComCvtServeService { +public class ComCvtServeServiceImpl extends ServiceImpl<ComCvtServeDAO, ComCvtServeDO> implements ComCvtServeService { @Resource private ComCvtServeDAO comCvtServeDAO; @@ -63,6 +66,9 @@ public R addComCvtServe(ComCvtServeDTO comCvtServeDTO) { ComCvtServeDO comCvtServeDO = new ComCvtServeDO(); BeanUtils.copyProperties(comCvtServeDTO, comCvtServeDO); + if(checkRepeat(comCvtServeDO)){ + return R.fail("服务已存在"); + } int insert = comCvtServeDAO.insert(comCvtServeDO); if (insert > 0) { return R.ok(); @@ -76,8 +82,12 @@ if (null == comCvtServeDO) { return R.fail("该服务不存在"); } - BeanUtils.copyProperties(comCvtServeDTO, comCvtServeDO); - int update = comCvtServeDAO.updateById(comCvtServeDO); + ComCvtServeDO comCvtServeDO2 = new ComCvtServeDO(); + BeanUtils.copyProperties(comCvtServeDTO, comCvtServeDO2); + if(!comCvtServeDO.equals(comCvtServeDO2) && checkRepeat(comCvtServeDO2)){ + return R.fail("该服务与其他服务重复"); + } + int update = comCvtServeDAO.updateById(comCvtServeDO2); if (update > 0) { return R.ok(); } @@ -135,6 +145,7 @@ /** * 按分类筛选 + * * @param comCvtServeDOS * @param categoryId * @return @@ -149,4 +160,72 @@ }); return comCvtServeVOS; } + + @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)); + 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); + } + Map<String, Long> businessMap = getBusinessMap(comCvtBusinessDOS); + list.forEach(comCvtServeExcelVO -> { + 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)){ + comCvtServeDOS.add(comCvtServeDO); + }else{ + log.error(String.format("导入失败:商家【%s】下已有服务【%s】",comCvtServeExcelVO.getBusinessName(),comCvtServeExcelVO.getServiceName())); + } + } + }); + this.saveBatch(comCvtServeDOS); + return R.ok("共计导入服务数量:"+comCvtServeDOS.size()); + } + + //获取分类集合 + private Map<String, Long> getCategoryMap(List<ComCvtCategoryDO> categoryDOS) { + Map<String, Long> categoryMap = new HashMap<>(); + if (!ObjectUtils.isEmpty(categoryDOS)) { + categoryDOS.forEach(categoryDO -> { + categoryMap.put(categoryDO.getName(), categoryDO.getId()); + }); + } + return categoryMap; + } + + //获取商家集合 + private Map<String, Long> getBusinessMap(List<ComCvtBusinessDO> comCvtBusinessDOS) { + Map<String, Long> businessMap = new HashMap<>(); + if (!ObjectUtils.isEmpty(comCvtBusinessDOS)) { + comCvtBusinessDOS.forEach(businessDO -> { + businessMap.put(businessDO.getName(), businessDO.getId()); + }); + } + return businessMap; + } + + /** + * 检查服务是否重复 商家名称、分类名称,服务名称、服务价格、服务描述不能同时重复 + * @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; + } } -- Gitblit v1.7.1