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.TBYDK;
import com.sinosig.core.module.filter.TBYDKSearchContext;
import com.sinosig.core.module.service.ITBYDKService;
import org.springframework.beans.factory.annotation.Autowired;
import com.sinosig.util.SearchResult;

/**
 * 实体[TBYDK] 服务对象接口实现
 */
@Service
public class TBYDKServiceImpl implements ITBYDKService {

    @Autowired
    com.sinosig.core.repository.TBYDKRepository tBYDKRepository;




    @Override
    public boolean create(TBYDK tbydk) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.TBYDK t_TBYDK = tBYDKRepository.convert2PO(tbydk,null);
        bOk = tBYDKRepository.create(t_TBYDK);
        tBYDKRepository.convert2Domain(t_TBYDK,tbydk);

        return bOk ;
    }

    @Override
    public TBYDK get(String tbydkid) {
        com.sinosig.core.repository.po.TBYDK t_TBYDK = tBYDKRepository.get(tbydkid);
        return tBYDKRepository.convert2Domain(t_TBYDK,null);
    }

    @Override
    public TBYDK get(TBYDK tbydk) {
        com.sinosig.core.repository.po.TBYDK t_TBYDK = tBYDKRepository.get(tbydk.getTBYDKId());
        tBYDKRepository.convert2Domain(t_TBYDK,tbydk);
        return tbydk;
    }

    @Override
    public boolean update(TBYDK tbydk) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.TBYDK t_TBYDK = tBYDKRepository.convert2PO(tbydk,null);
        bOk = tBYDKRepository.update(t_TBYDK);
        tBYDKRepository.convert2Domain(t_TBYDK,tbydk) ;

        return bOk ;
    }

    @Override
    public boolean checkKey(TBYDK tbydk) {
        return true;
    }
    @Override
    public boolean save(TBYDK tbydk) {
        if(tbydk.getTBYDKId()==null){
    		return create(tbydk);
    	}else{
            if(this.get(tbydk.getTBYDKId())!=null){
    			return update(tbydk);
    		}
    		return create(tbydk);
    	}
    }

    @Override
    public TBYDK getDraft(TBYDK tbydk) {
        return tbydk;
    }

    @Override
    public boolean remove(String tbydkid) {
        boolean bOk = false ;
        bOk = tBYDKRepository.remove(tbydkid);

        return bOk ;
    }

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

    /**
     * 查询集合 JQX
     */
    @Override
    public Page<TBYDK> searchJQX(TBYDKSearchContext context) {
        List<TBYDK> list = new ArrayList<TBYDK>();
        Page<com.sinosig.core.repository.po.TBYDK> t_TBYDKs = tBYDKRepository.searchJQX(context) ;
        for(com.sinosig.core.repository.po.TBYDK t_TBYDK : t_TBYDKs){
            list.add(tBYDKRepository.convert2Domain(t_TBYDK,null));
        }
        return new PageImpl<TBYDK>(list, context.getPageable(), t_TBYDKs.getTotalElements());
    }

    /**
     * 查询集合 SYX
     */
    @Override
    public Page<TBYDK> searchSYX(TBYDKSearchContext context) {
        List<TBYDK> list = new ArrayList<TBYDK>();
        Page<com.sinosig.core.repository.po.TBYDK> t_TBYDKs = tBYDKRepository.searchSYX(context) ;
        for(com.sinosig.core.repository.po.TBYDK t_TBYDK : t_TBYDKs){
            list.add(tBYDKRepository.convert2Domain(t_TBYDK,null));
        }
        return new PageImpl<TBYDK>(list, context.getPageable(), t_TBYDKs.getTotalElements());
    }





}
