| | |
| | | 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; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | * @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; |
| | |
| | | |
| | | /** |
| | | * 按分类筛选 |
| | | * |
| | | * @param comCvtServeDOS |
| | | * @param categoryId |
| | | * @return |
| | |
| | | }); |
| | | 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())); |
| | | comCvtServeDOS.add(comCvtServeDO); |
| | | } |
| | | }); |
| | | this.saveBatch(comCvtServeDOS); |
| | | return R.ok(); |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | } |