package com.ibiz.core.external.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.ibiz.core.external.domain.CPXH;
import com.ibiz.core.external.filter.CPXHSearchContext;
import com.ibiz.core.external.service.ICPXHService;
import org.springframework.beans.factory.annotation.Autowired;
import com.ibiz.util.SearchResult;

/**
 * 实体[CPXH] 服务对象接口实现
 */
@Service
public class CPXHServiceImpl implements ICPXHService {

    @Autowired
    com.ibiz.core.repository.CPXHRepository cPXHRepository;




    @Override
    public boolean create(CPXH cpxh) {
        boolean bOk = false ;
        com.ibiz.core.repository.po.CPXH t_CPXH = cPXHRepository.convert2PO(cpxh,null);
        bOk = cPXHRepository.create(t_CPXH);
        cPXHRepository.convert2Domain(t_CPXH,cpxh);

        return bOk ;
    }

    @Override
    public boolean update(CPXH cpxh) {
        boolean bOk = false ;
        com.ibiz.core.repository.po.CPXH t_CPXH = cPXHRepository.convert2PO(cpxh,null);
        bOk = cPXHRepository.update(t_CPXH);
        cPXHRepository.convert2Domain(t_CPXH,cpxh) ;

        return bOk ;
    }

    @Override
    public CPXH getDraft(CPXH cpxh) {
        return cpxh;
    }

    @Override
    public boolean remove(String cpxhid) {
        boolean bOk = false ;
        bOk = cPXHRepository.remove(cpxhid);

        return bOk ;
    }

    @Override
    public boolean checkKey(CPXH cpxh) {
        return true;
    }
    @Override
    public boolean save(CPXH cpxh) {
        if(cpxh.getCPXHId()==null){
    		return create(cpxh);
    	}else{
            if(this.get(cpxh.getCPXHId())!=null){
    			return update(cpxh);
    		}
    		return create(cpxh);
    	}
    }

    @Override
    public CPXH get(String cpxhid) {
        com.ibiz.core.repository.po.CPXH t_CPXH = cPXHRepository.get(cpxhid);
        return cPXHRepository.convert2Domain(t_CPXH,null);
    }

    @Override
    public CPXH get(CPXH cpxh) {
        com.ibiz.core.repository.po.CPXH t_CPXH = cPXHRepository.get(cpxh.getCPXHId());
        cPXHRepository.convert2Domain(t_CPXH,cpxh);
        return cpxh;
    }

    /**
     * 查询集合 DEFAULT
     */
    @Override
    public Page<CPXH> searchDefault(CPXHSearchContext context) {
        List<CPXH> list = new ArrayList<CPXH>();
        Page<com.ibiz.core.repository.po.CPXH> t_CPXHs = cPXHRepository.searchDefault(context) ;
        for(com.ibiz.core.repository.po.CPXH t_CPXH : t_CPXHs){
            list.add(cPXHRepository.convert2Domain(t_CPXH,null));
        }
        return new PageImpl<CPXH>(list, context.getPageable(), t_CPXHs.getTotalElements());
    }





}
