package com.sckw.manage.dubbo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sckw.core.model.constant.Global;
import com.sckw.core.utils.BeanUtils;
import com.sckw.core.utils.CollectionUtils;
import com.sckw.manage.api.RemoteManageService;
import com.sckw.manage.api.model.dto.res.EntAddressResDto;
import com.sckw.manage.dao.KwmAddressMapper;
import com.sckw.manage.model.entity.KwmAddress;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author czh
 * @desc 基础信息+合作管理远程接口实现
 * @date 2023/7/31
 */
@DubboService(group = "design", version = "2.0.0")
public class RemoteManageServiceImpl implements RemoteManageService {

    @Autowired
    private KwmAddressMapper kwmAddressMapper;

    /**
     * @param idList 企业id集合
     * @return Map<Long, List<EntAddressResDto>>
     * @desc: 根据企业id查下面的地址
     * @author: czh
     * @date: 2023/7/31
     */
    @Override
    public Map<Long, List<EntAddressResDto>> queryEntAddressByEntIdList(List<Long> idList) {
        Map<Long, List<EntAddressResDto>> map = new HashMap<>(4);
        LambdaQueryWrapper<KwmAddress> kwmAddressLambdaQueryWrapper = new LambdaQueryWrapper<>();
        kwmAddressLambdaQueryWrapper.in(KwmAddress::getEntId, idList).
                                     eq(KwmAddress::getDelFlag, Global.NO);
        List<KwmAddress> kwmAddressList = kwmAddressMapper.selectList(kwmAddressLambdaQueryWrapper);
        if (CollectionUtils.isEmpty(kwmAddressList)) {
            return map;
        }

        List<EntAddressResDto> entAddressResDtoList = BeanUtils.copyToList(kwmAddressList, EntAddressResDto.class);
        return entAddressResDtoList.stream().collect(Collectors.groupingBy(EntAddressResDto::getEntId));
    }
}
