package cn.ibizlab.core.analysis.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.HashSet;
import java.util.HashMap;
import java.util.Collection;
import java.util.Objects;
import java.util.Optional;
import java.math.BigInteger;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Value;
import cn.ibizlab.util.errors.BadRequestAlertException;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Lazy;
import cn.ibizlab.core.analysis.domain.DADimension;
import cn.ibizlab.core.analysis.filter.DADimensionSearchContext;
import cn.ibizlab.core.analysis.service.IDADimensionService;

import cn.ibizlab.util.helper.CachedBeanCopier;
import cn.ibizlab.util.helper.DEFieldCacheMap;


/**
 * 实体[维度] 无存储服务对象接口实现
 */
@Slf4j
@Service
public class DADimensionServiceImpl implements IDADimensionService {


    @Override
    public boolean create(DADimension et) {
        //代码实现
        return true;
    }

    public void createBatch(List<DADimension> list){
    }

    @Override
    public boolean update(DADimension et) {
        //代码实现
        return true;
    }

    public void updateBatch(List<DADimension> list){
    }

    @Override
    public boolean remove(String key) {
        return true;
    }

    public void removeBatch(Collection<String> idList){
    }

    @Override
    public DADimension get(String key) {
        DADimension et = new DADimension();
        et.setId(key);
        return et;
    }

    @Override
    public DADimension getDraft(DADimension et) {
        return et;
    }

    @Override
    public boolean checkKey(DADimension et) {
        return false;
    }
    @Override
    @Transactional
    public boolean save(DADimension et) {
        //代码实现
        return true;
    }

    @Override
    public void saveBatch(List<DADimension> list) {
    }



	@Override
    public List<DADimension> selectByBuildid(String build_id) {
        return null;
    }

    @Override
    public void removeByBuildid(String build_id) {
        Set<String> delIds=new HashSet<String>();
        for(DADimension before:selectByBuildid(build_id)){
            delIds.add(before.getId());
        }
        if(delIds.size()>0)
            this.removeBatch(delIds);
    }

    public IDADimensionService getProxyService() {
        return cn.ibizlab.util.security.SpringContextHolder.getBean(this.getClass());
    }
	@Override
    public void saveByBuildid(String build_id,List<DADimension> list) {
        if(list==null)
            return;
        Set<String> delIds=new HashSet<String>();
        List<DADimension> _update=new ArrayList<DADimension>();
        List<DADimension> _create=new ArrayList<DADimension>();
        for(DADimension before:selectByBuildid(build_id)){
            delIds.add(before.getId());
        }
        for(DADimension sub:list) {
            sub.setBuildid(build_id);
            if(ObjectUtils.isEmpty(sub.getId()))
                sub.setId((String)sub.getDefaultKey(true));
            if(delIds.contains(sub.getId())) {
                delIds.remove(sub.getId());
                _update.add(sub);
            }
            else
                _create.add(sub);
        }
        if(_update.size()>0)
            getProxyService().updateBatch(_update);
        if(_create.size()>0)
            getProxyService().createBatch(_create);
        if(delIds.size()>0)
            getProxyService().removeBatch(delIds);
	}



    /**
     * 查询集合 数据集
     */
    @Override
    public Page<DADimension> searchDefault(DADimensionSearchContext context) {
        return new PageImpl<DADimension>(new ArrayList(),context.getPageable(),0);
    }


}


