package com.friday.custody.service.basicService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.friday.custody.dao.DataDictionaryProjectProgressDao;
import com.friday.custody.entity.DataDictionaryProjectProgressDetailsEntity;
import com.friday.custody.entity.DataDictionaryProjectProgressEntity;
import com.friday.custody.enums.DataDictionaryTypeEnum;
import com.friday.custody.service.basicService.DataDictionaryProjectProgressDetailsService;
import com.friday.custody.service.basicService.DataDictionaryProjectProgressService;
import com.friday.custody.service.logicService.DataDictionaryBasicService;
import com.friday.custody.utils.PageUtils;
import com.friday.custody.utils.Query;
import com.friday.custody.utils.R;
import org.apache.commons.collections4.CollectionUtils;
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;
/*
* 项目进度字典表
* */

@Service("dataDictionaryProjectProgressService")
public class DataDictionaryProjectProgressServiceImpl extends ServiceImpl<DataDictionaryProjectProgressDao, DataDictionaryProjectProgressEntity> implements DataDictionaryProjectProgressService, DataDictionaryBasicService {
    @Autowired
    //private DataDictionaryTypeOfSellerDetailsService detailsService;
    private DataDictionaryProjectProgressDetailsService detailsService;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<DataDictionaryProjectProgressEntity> page = this.page(
                new Query<DataDictionaryProjectProgressEntity>().getPage(params),
                new QueryWrapper<DataDictionaryProjectProgressEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<DataDictionaryProjectProgressEntity> selectVByTrustNo(String trustNo) {
        return null;
    }

    @Override
    public Map<String, String> queryWithDetail(DataDictionaryTypeEnum dicType, String trustNo) {
        return null;
    }

    @Override
    public Map<String, String> queryWithDetail(String trustNo) {
        HashMap<String, String> result = new HashMap<>();
        List<DataDictionaryProjectProgressEntity> allDatas = baseMapper.selectList(new QueryWrapper<>());
        if (!CollectionUtils.isEmpty(allDatas)) {
            List<DataDictionaryProjectProgressDetailsEntity> detailsEntities = detailsService.selectVByTrustNo(trustNo);
            if (!CollectionUtils.isEmpty(detailsEntities)) {
                Map<String, Integer> originValueKeyMap = detailsEntities.stream().collect(Collectors.toMap(DataDictionaryProjectProgressDetailsEntity::getOriginValue, DataDictionaryProjectProgressDetailsEntity::getDicId));
                Map<Integer, String> idKeyMap = allDatas.stream().collect(Collectors.toMap(DataDictionaryProjectProgressEntity::getId, DataDictionaryProjectProgressEntity::getKeyStr));
                originValueKeyMap.forEach((originValue, id) -> {
                    result.put(originValue, idKeyMap.get(id));
                });
            } else {
                log.error("DataDictionaryProjectProgressEntity 查询失败！");
            }
        } else {
            log.error("DataDictionaryTypeOfSellerEntity 查询失败！");
        }
        return result;
    }

    @Override
    public R queryData(String type) {
        return null;
    }
}