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

/**
 * 实体[SJZDX] 服务对象接口实现
 */
@Service
public class SJZDXServiceImpl implements ISJZDXService {

    @Autowired
    com.sinosig.core.repository.SJZDXRepository sJZDXRepository;




    @Override
    public boolean create(SJZDX sjzdx) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.SJZDX t_SJZDX = sJZDXRepository.convert2PO(sjzdx,null);
        bOk = sJZDXRepository.create(t_SJZDX);
        sJZDXRepository.convert2Domain(t_SJZDX,sjzdx);

        return bOk ;
    }

    @Override
    public SJZDX get(String sjzdxid) {
        com.sinosig.core.repository.po.SJZDX t_SJZDX = sJZDXRepository.get(sjzdxid);
        return sJZDXRepository.convert2Domain(t_SJZDX,null);
    }

    @Override
    public SJZDX get(SJZDX sjzdx) {
        com.sinosig.core.repository.po.SJZDX t_SJZDX = sJZDXRepository.get(sjzdx.getSJZDXId());
        sJZDXRepository.convert2Domain(t_SJZDX,sjzdx);
        return sjzdx;
    }

    @Override
    public boolean remove(String sjzdxid) {
        boolean bOk = false ;
        bOk = sJZDXRepository.remove(sjzdxid);

        return bOk ;
    }

    @Override
    public boolean checkKey(SJZDX sjzdx) {
        return true;
    }
    @Override
    public boolean update(SJZDX sjzdx) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.SJZDX t_SJZDX = sJZDXRepository.convert2PO(sjzdx,null);
        bOk = sJZDXRepository.update(t_SJZDX);
        sJZDXRepository.convert2Domain(t_SJZDX,sjzdx) ;

        return bOk ;
    }

    @Override
    public SJZDX getDraft(SJZDX sjzdx) {
        return sjzdx;
    }

    @Override
    public boolean save(SJZDX sjzdx) {
        if(sjzdx.getSJZDXId()==null){
    		return create(sjzdx);
    	}else{
            if(this.get(sjzdx.getSJZDXId())!=null){
    			return update(sjzdx);
    		}
    		return create(sjzdx);
    	}
    }

    /**
     * 查询集合 车类种类
     */
    @Override
    public Page<SJZDX> searchCLZL(SJZDXSearchContext context) {
        List<SJZDX> list = new ArrayList<SJZDX>();
        Page<com.sinosig.core.repository.po.SJZDX> t_SJZDXs = sJZDXRepository.searchCLZL(context) ;
        for(com.sinosig.core.repository.po.SJZDX t_SJZDX : t_SJZDXs){
            list.add(sJZDXRepository.convert2Domain(t_SJZDX,null));
        }
        return new PageImpl<SJZDX>(list, context.getPageable(), t_SJZDXs.getTotalElements());
    }

    /**
     * 查询集合 业务来源
     */
    @Override
    public Page<SJZDX> searchYWLY(SJZDXSearchContext context) {
        List<SJZDX> list = new ArrayList<SJZDX>();
        Page<com.sinosig.core.repository.po.SJZDX> t_SJZDXs = sJZDXRepository.searchYWLY(context) ;
        for(com.sinosig.core.repository.po.SJZDX t_SJZDX : t_SJZDXs){
            list.add(sJZDXRepository.convert2Domain(t_SJZDX,null));
        }
        return new PageImpl<SJZDX>(list, context.getPageable(), t_SJZDXs.getTotalElements());
    }

    /**
     * 查询集合 车辆大类
     */
    @Override
    public Page<SJZDX> searchCLDL(SJZDXSearchContext context) {
        List<SJZDX> list = new ArrayList<SJZDX>();
        Page<com.sinosig.core.repository.po.SJZDX> t_SJZDXs = sJZDXRepository.searchCLDL(context) ;
        for(com.sinosig.core.repository.po.SJZDX t_SJZDX : t_SJZDXs){
            list.add(sJZDXRepository.convert2Domain(t_SJZDX,null));
        }
        return new PageImpl<SJZDX>(list, context.getPageable(), t_SJZDXs.getTotalElements());
    }

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


    /**
     * 根据数据字典查询
     */
    @Override
    public Page<SJZDX> selectBySJZD(String sjzdid ){
        SJZDXSearchContext context = new SJZDXSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(sjzdid)){
            com.sinosig.util.SearchFieldFilter fieldFilter=new com.sinosig.util.SearchFieldFilter();
            fieldFilter.setParam("sjzdid");
            fieldFilter.setCondition(com.sinosig.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(sjzdid);
            context.getCondition().add(fieldFilter);
        }
        List<SJZDX> list = new ArrayList<SJZDX>();
        Page<com.sinosig.core.repository.po.SJZDX> t_SJZDXs = sJZDXRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.SJZDX t_SJZDX : t_SJZDXs){
            list.add(sJZDXRepository.convert2Domain(t_SJZDX,null));
        }
        return new PageImpl<SJZDX>(list, context.getPageable(), t_SJZDXs.getTotalElements());
    }

    /**
     * 根据数据字典查询
     */
    @Override
    public List<SJZDX> selectBySJZD2(String sjzdid ){

        SJZDXSearchContext context = new SJZDXSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(sjzdid)){
            com.sinosig.util.SearchFieldFilter fieldFilter=new com.sinosig.util.SearchFieldFilter();
            fieldFilter.setParam("sjzdid");
            fieldFilter.setCondition(com.sinosig.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(sjzdid);
            context.getCondition().add(fieldFilter);
        }
        List<SJZDX> list = new ArrayList<SJZDX>();
        Page<com.sinosig.core.repository.po.SJZDX> t_SJZDXs = sJZDXRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.SJZDX t_SJZDX : t_SJZDXs){
            list.add(sJZDXRepository.convert2Domain(t_SJZDX,null));
        }
        return list;
    }



}
