| | |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | 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(); |
| | |
| | | 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(); |
| | | } |
| | |
| | | BeanUtils.copyProperties(comCvtServeExcelVO, comCvtServeDO); |
| | | comCvtServeDO.setCategoryId(categoryMap.get(comCvtServeExcelVO.getCategoryName())); |
| | | comCvtServeDO.setBusinessId(businessMap.get(comCvtServeExcelVO.getBusinessName())); |
| | | comCvtServeDOS.add(comCvtServeDO); |
| | | //检查商家是否已有某服务 |
| | | if(!checkRepeat(comCvtServeDO)){ |
| | | comCvtServeDOS.add(comCvtServeDO); |
| | | }else{ |
| | | log.error(String.format("导入失败:商家【%s】下已有服务【%s】",comCvtServeExcelVO.getBusinessName(),comCvtServeExcelVO.getServiceName())); |
| | | } |
| | | } |
| | | }); |
| | | this.saveBatch(comCvtServeDOS); |
| | | return R.ok(); |
| | | return R.ok("共计导入服务数量:"+comCvtServeDOS.size()); |
| | | } |
| | | |
| | | //获取分类集合 |
| | | private Map<String, Long> getCategoryMap(List<ComCvtCategoryDO> categoryDOS) { |
| | | Map<String, Long> categoryMap = new HashMap<>(); |
| | | if (!ObjectUtils.isEmpty(categoryDOS)) { |
| | |
| | | return categoryMap; |
| | | } |
| | | |
| | | //获取商家集合 |
| | | private Map<String, Long> getBusinessMap(List<ComCvtBusinessDO> comCvtBusinessDOS) { |
| | | Map<String, Long> businessMap = new HashMap<>(); |
| | | if (!ObjectUtils.isEmpty(comCvtBusinessDOS)) { |
| | |
| | | } |
| | | 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; |
| | | } |
| | | } |