package com.sinosig.core.module.service.impl;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
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 com.sinosig.core.module.domain.DBD;
import com.sinosig.core.module.filter.DBDSearchContext;
import com.sinosig.core.module.service.IDBDService;
import org.springframework.beans.factory.annotation.Autowired;
import com.sinosig.util.SearchResult;

/**
 * 实体[DBD] 服务对象接口实现
 */
@Service
public class DBDServiceImpl implements IDBDService {

    @Autowired
    com.sinosig.core.repository.DBDRepository dBDRepository;




    @Override
    public boolean save(DBD dbd) {
        if(dbd.getDBDId()==null){
    		return create(dbd);
    	}else{
            if(this.get(dbd.getDBDId())!=null){
    			return update(dbd);
    		}
    		return create(dbd);
    	}
    }

    @Override
    public boolean update(DBD dbd) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.DBD t_DBD = dBDRepository.convert2PO(dbd,null);
        bOk = dBDRepository.update(t_DBD);
        dBDRepository.convert2Domain(t_DBD,dbd) ;

        return bOk ;
    }

    @Override
    public DBD getDraft(DBD dbd) {
        return dbd;
    }

    @Override
    public boolean create(DBD dbd) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.DBD t_DBD = dBDRepository.convert2PO(dbd,null);
        bOk = dBDRepository.create(t_DBD);
        dBDRepository.convert2Domain(t_DBD,dbd);

        return bOk ;
    }

    @Override
    public boolean checkKey(DBD dbd) {
        return true;
    }
    @Override
    public boolean remove(String dbdid) {
        boolean bOk = false ;
        bOk = dBDRepository.remove(dbdid);

        return bOk ;
    }

    @Override
    public DBD get(String dbdid) {
        com.sinosig.core.repository.po.DBD t_DBD = dBDRepository.get(dbdid);
        return dBDRepository.convert2Domain(t_DBD,null);
    }

    @Override
    public DBD get(DBD dbd) {
        com.sinosig.core.repository.po.DBD t_DBD = dBDRepository.get(dbd.getDBDId());
        dBDRepository.convert2Domain(t_DBD,dbd);
        return dbd;
    }

    /**
     * 查询集合 DEFAULT
     */
    @Override
    public Page<DBD> searchDefault(DBDSearchContext context) {
        List<DBD> list = new ArrayList<DBD>();
        Page<com.sinosig.core.repository.po.DBD> t_DBDs = dBDRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.DBD t_DBD : t_DBDs){
            list.add(dBDRepository.convert2Domain(t_DBD,null));
        }
        return new PageImpl<DBD>(list, context.getPageable(), t_DBDs.getTotalElements());
    }





}
