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

/**
 * 实体[SYXBJ] 服务对象接口实现
 */
@Service
public class SYXBJServiceImpl implements ISYXBJService {

    @Autowired
    com.ibiz.core.repository.SYXBJRepository sYXBJRepository;




    @Override
    public boolean save(SYXBJ syxbj) {
        if(syxbj.getSYXBJId()==null){
    		return create(syxbj);
    	}else{
            if(this.get(syxbj.getSYXBJId())!=null){
    			return update(syxbj);
    		}
    		return create(syxbj);
    	}
    }

    @Override
    public boolean remove(String syxbjid) {
        boolean bOk = false ;
        bOk = sYXBJRepository.remove(syxbjid);

        return bOk ;
    }

    @Override
    public SYXBJ getDraft(SYXBJ syxbj) {
        return syxbj;
    }

    @Override
    public boolean checkKey(SYXBJ syxbj) {
        return true;
    }
    @Override
    public boolean update(SYXBJ syxbj) {
        boolean bOk = false ;
        com.ibiz.core.repository.po.SYXBJ t_SYXBJ = sYXBJRepository.convert2PO(syxbj,null);
        bOk = sYXBJRepository.update(t_SYXBJ);
        sYXBJRepository.convert2Domain(t_SYXBJ,syxbj) ;

        return bOk ;
    }

    @Override
    public boolean create(SYXBJ syxbj) {
        boolean bOk = false ;
        com.ibiz.core.repository.po.SYXBJ t_SYXBJ = sYXBJRepository.convert2PO(syxbj,null);
        bOk = sYXBJRepository.create(t_SYXBJ);
        sYXBJRepository.convert2Domain(t_SYXBJ,syxbj);

        return bOk ;
    }

    @Override
    public SYXBJ get(String syxbjid) {
        com.ibiz.core.repository.po.SYXBJ t_SYXBJ = sYXBJRepository.get(syxbjid);
        return sYXBJRepository.convert2Domain(t_SYXBJ,null);
    }

    @Override
    public SYXBJ get(SYXBJ syxbj) {
        com.ibiz.core.repository.po.SYXBJ t_SYXBJ = sYXBJRepository.get(syxbj.getSYXBJId());
        sYXBJRepository.convert2Domain(t_SYXBJ,syxbj);
        return syxbj;
    }

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





}
