Null
2021-03-12 5abbd247039800d7540e30bcbb4ef79f480a40e8
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;
@@ -21,7 +25,9 @@
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;
/**
@@ -30,7 +36,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;
@@ -135,6 +141,7 @@
    /**
     * 按分类筛选
     *
     * @param comCvtServeDOS
     * @param categoryId
     * @return
@@ -149,4 +156,49 @@
        });
        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;
    }
}