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

/**
 * 实体[SJZD] 服务对象接口实现
 */
@Service
public class SJZDServiceImpl implements ISJZDService {

    @Autowired
    com.sinosig.core.repository.SJZDRepository sJZDRepository;




    @Override
    public boolean update(SJZD sjzd) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.SJZD t_SJZD = sJZDRepository.convert2PO(sjzd,null);
        bOk = sJZDRepository.update(t_SJZD);
        sJZDRepository.convert2Domain(t_SJZD,sjzd) ;

        return bOk ;
    }

    @Override
    public boolean remove(String sjzdid) {
        boolean bOk = false ;
        bOk = sJZDRepository.remove(sjzdid);

        return bOk ;
    }

    @Override
    public SJZD getDraft(SJZD sjzd) {
        return sjzd;
    }

    @Override
    public SJZD get(String sjzdid) {
        com.sinosig.core.repository.po.SJZD t_SJZD = sJZDRepository.get(sjzdid);
        return sJZDRepository.convert2Domain(t_SJZD,null);
    }

    @Override
    public SJZD get(SJZD sjzd) {
        com.sinosig.core.repository.po.SJZD t_SJZD = sJZDRepository.get(sjzd.getSJZDId());
        sJZDRepository.convert2Domain(t_SJZD,sjzd);
        return sjzd;
    }

    @Override
    public boolean checkKey(SJZD sjzd) {
        return true;
    }
    @Override
    public boolean create(SJZD sjzd) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.SJZD t_SJZD = sJZDRepository.convert2PO(sjzd,null);
        bOk = sJZDRepository.create(t_SJZD);
        sJZDRepository.convert2Domain(t_SJZD,sjzd);

        return bOk ;
    }

    @Override
    public boolean save(SJZD sjzd) {
        if(sjzd.getSJZDId()==null){
    		return create(sjzd);
    	}else{
            if(this.get(sjzd.getSJZDId())!=null){
    			return update(sjzd);
    		}
    		return create(sjzd);
    	}
    }

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





}
