package com.sinosig.core.module2.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.module2.domain.YDJJDC;
import com.sinosig.core.module2.filter.YDJJDCSearchContext;
import com.sinosig.core.module2.service.IYDJJDCService;
import org.springframework.beans.factory.annotation.Autowired;
import com.sinosig.util.SearchResult;

/**
 * 实体[YDJJDC] 服务对象接口实现
 */
@Service
public class YDJJDCServiceImpl implements IYDJJDCService {

    @Autowired
    com.sinosig.core.repository.YDJJDCRepository yDJJDCRepository;




    @Override
    public boolean remove(String ydjjdcid) {
        boolean bOk = false ;
        bOk = yDJJDCRepository.remove(ydjjdcid);

        return bOk ;
    }

    @Override
    public boolean update(YDJJDC ydjjdc) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.YDJJDC t_YDJJDC = yDJJDCRepository.convert2PO(ydjjdc,null);
        bOk = yDJJDCRepository.update(t_YDJJDC);
        yDJJDCRepository.convert2Domain(t_YDJJDC,ydjjdc) ;

        return bOk ;
    }

    @Override
    public YDJJDC getDraft(YDJJDC ydjjdc) {
        return ydjjdc;
    }

    @Override
    public boolean create(YDJJDC ydjjdc) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.YDJJDC t_YDJJDC = yDJJDCRepository.convert2PO(ydjjdc,null);
        bOk = yDJJDCRepository.create(t_YDJJDC);
        yDJJDCRepository.convert2Domain(t_YDJJDC,ydjjdc);

        return bOk ;
    }

    @Override
    public boolean save(YDJJDC ydjjdc) {
        if(ydjjdc.getYDJJDCId()==null){
    		return create(ydjjdc);
    	}else{
            if(this.get(ydjjdc.getYDJJDCId())!=null){
    			return update(ydjjdc);
    		}
    		return create(ydjjdc);
    	}
    }

    @Override
    public boolean checkKey(YDJJDC ydjjdc) {
        return true;
    }
    @Override
    public YDJJDC get(String ydjjdcid) {
        com.sinosig.core.repository.po.YDJJDC t_YDJJDC = yDJJDCRepository.get(ydjjdcid);
        return yDJJDCRepository.convert2Domain(t_YDJJDC,null);
    }

    @Override
    public YDJJDC get(YDJJDC ydjjdc) {
        com.sinosig.core.repository.po.YDJJDC t_YDJJDC = yDJJDCRepository.get(ydjjdc.getYDJJDCId());
        yDJJDCRepository.convert2Domain(t_YDJJDC,ydjjdc);
        return ydjjdc;
    }

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





}
