package cn.superdesk.uniorder.service.order._leaveover.impl;

import cn.hutool.core.collection.CollUtil;
import cn.superdesk.uniorder.common.exception.UnifiedOrderRuntimeException;
import cn.superdesk.uniorder.common.lamda.AnLamdaUtils;
import cn.superdesk.uniorder.dao.entity.order.ExpressCompany;
import cn.superdesk.uniorder.dao.mapper.order.ExpressCompanyMapper;
import cn.superdesk.uniorder.service.order._leaveover.ExpressCompanyService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @Description: 快递公司
 * @Author: linjinyu 补充 修扆
 * @CreateDate: 5/12/20 3:49 PM
 * @UpdateUser: linjinyu
 * @UpdateDate: 5/12/20 3:49 PM
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Service
public class ExpressCompanyServiceImpl implements ExpressCompanyService {

    @Autowired
    private ExpressCompanyMapper expressCompanyMapper;


    @Override
    public ExpressCompany findById(Long id) {

        return expressCompanyMapper.selectByPrimaryKey(id);
    }

    @Deprecated
    @Override
    public int insertSelective(ExpressCompany t) {
        return 0;

    }

    @Deprecated
    @Override
    public int updateByPrimaryKeySelective(ExpressCompany t) {
        return 0;

    }

    @Override
    public void deleteObj(Long id) {


    }

    @Override
    public List<ExpressCompany> findAll(Map<String, Object> queryMap) {

        return null;
    }

    @Override
    public PageInfo<ExpressCompany> findByPaging(Map<String, Object> params, Integer pageNo, Integer pageSize) {

        return null;
    }

    /**
     * 待重构
     *
     * @return
     * @throws UnifiedOrderRuntimeException
     */
    @Override
    public List<ExpressCompany> findAllExpressCompany() throws UnifiedOrderRuntimeException {
        return expressCompanyMapper.findAll();
    }

    @Override
    public Map<Long, ExpressCompany> findAllConvertKV() {

        Map<Long, ExpressCompany> result = new HashMap<>();


        List<ExpressCompany> expressCompanyList = findAllExpressCompany();

        if (CollUtil.isNotEmpty(expressCompanyList)) {

            result = expressCompanyList
                    .stream()
                    .filter(AnLamdaUtils.distinctByKey(o -> o.getId()))
                    .collect(Collectors.toMap(ExpressCompany::getId, v -> v, (k, v) -> v));
        }

        return result;

    }

}
