package com.hzs.system.config.provider;

import cn.hutool.core.bean.BeanUtil;
import com.hzs.common.core.domain.R;
import com.hzs.common.core.utils.ComputeUtil;
import com.hzs.common.domain.system.config.BdAwards;
import com.hzs.system.base.service.IBdCountryService;
import com.hzs.system.config.IAwardsServiceApi;
import com.hzs.system.config.service.IBdAwardsService;
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;

@DubboService
public class AwardsServiceProvider implements IAwardsServiceApi {

    @Autowired
    private IBdAwardsService awardsService;

    @Override
    public R<List<BdAwards>> queryAwards(Integer pkCountry) {
        return R.ok(awardsService.queryAwards(pkCountry));
    }

    @Override
    public R<BdAwards> getAwardsOne(Integer pkId) {
        return R.ok(BeanUtil.copyProperties(awardsService.getBdAwardsOne(pkId), BdAwards.class));
    }

    @Override
    public R<Map<String, BdAwards>> getAwards() {
        List<BdAwards> awardsList = awardsService.queryAwards();
        Map<String, BdAwards> countryAwardsMap = new HashMap<>(ComputeUtil.mapInitCapacity(awardsList.size() * 10));
        for (BdAwards bdAwards : awardsList) {
            String key = bdAwards.getPkCountry().toString() + bdAwards.getPkId().toString();
            countryAwardsMap.put(key, bdAwards);
        }
        return R.ok(countryAwardsMap);
    }

    @Override
    public R<List<BdAwards>> queryByPkCountryAwards(Integer pkCountry) {
        return R.ok(awardsService.queryByPkCountryAwards(pkCountry));
    }

    @Override
    public R<List<BdAwards>> queryAwardsByIdList(List<Integer> countryList) {
        return R.ok(awardsService.queryAwardsByIdList(countryList));
    }
}
