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.JQXBJ;
import com.ibiz.core.external.filter.JQXBJSearchContext;
import com.ibiz.core.external.service.IJQXBJService;
import org.springframework.beans.factory.annotation.Autowired;
import com.ibiz.util.SearchResult;

/**
 * 实体[JQXBJ] 服务对象接口实现
 */
@Service
public class JQXBJServiceImpl implements IJQXBJService {

    @Autowired
    com.ibiz.core.repository.JQXBJRepository jQXBJRepository;




    @Override
    public boolean update(JQXBJ jqxbj) {
        boolean bOk = false ;
        com.ibiz.core.repository.po.JQXBJ t_JQXBJ = jQXBJRepository.convert2PO(jqxbj,null);
        bOk = jQXBJRepository.update(t_JQXBJ);
        jQXBJRepository.convert2Domain(t_JQXBJ,jqxbj) ;

        return bOk ;
    }

    @Override
    public JQXBJ get(String jqxbjid) {
        com.ibiz.core.repository.po.JQXBJ t_JQXBJ = jQXBJRepository.get(jqxbjid);
        return jQXBJRepository.convert2Domain(t_JQXBJ,null);
    }

    @Override
    public JQXBJ get(JQXBJ jqxbj) {
        com.ibiz.core.repository.po.JQXBJ t_JQXBJ = jQXBJRepository.get(jqxbj.getJQXBJId());
        jQXBJRepository.convert2Domain(t_JQXBJ,jqxbj);
        return jqxbj;
    }

    @Override
    public boolean remove(String jqxbjid) {
        boolean bOk = false ;
        bOk = jQXBJRepository.remove(jqxbjid);

        return bOk ;
    }

    @Override
    public boolean save(JQXBJ jqxbj) {
        if(jqxbj.getJQXBJId()==null){
    		return create(jqxbj);
    	}else{
            if(this.get(jqxbj.getJQXBJId())!=null){
    			return update(jqxbj);
    		}
    		return create(jqxbj);
    	}
    }

    @Override
    public boolean create(JQXBJ jqxbj) {
        boolean bOk = false ;
        com.ibiz.core.repository.po.JQXBJ t_JQXBJ = jQXBJRepository.convert2PO(jqxbj,null);
        bOk = jQXBJRepository.create(t_JQXBJ);
        jQXBJRepository.convert2Domain(t_JQXBJ,jqxbj);

        return bOk ;
    }

    @Override
    public boolean checkKey(JQXBJ jqxbj) {
        return true;
    }
    @Override
    public JQXBJ getDraft(JQXBJ jqxbj) {
        return jqxbj;
    }

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





}
