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

/**
 * 实体[SYXXX] 服务对象接口实现
 */
@Service
public class SYXXXServiceImpl implements ISYXXXService {

    @Autowired
    com.sinosig.core.repository.SYXXXRepository sYXXXRepository;




    @Override
    public SYXXX createTempMajor(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public SYXXX updateTemp(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public SYXXX getDraftTempMajor(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public boolean create(SYXXX syxxx) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.SYXXX t_SYXXX = sYXXXRepository.convert2PO(syxxx,null);
        bOk = sYXXXRepository.create(t_SYXXX);
        sYXXXRepository.convert2Domain(t_SYXXX,syxxx);

        return bOk ;
    }

    @Override
    public SYXXX get(String syxxxid) {
        com.sinosig.core.repository.po.SYXXX t_SYXXX = sYXXXRepository.get(syxxxid);
        return sYXXXRepository.convert2Domain(t_SYXXX,null);
    }

    @Override
    public SYXXX get(SYXXX syxxx) {
        com.sinosig.core.repository.po.SYXXX t_SYXXX = sYXXXRepository.get(syxxx.getSYXXXId());
        sYXXXRepository.convert2Domain(t_SYXXX,syxxx);
        return syxxx;
    }

    @Override
    public SYXXX removeTempMajor(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public SYXXX createTemp(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public boolean remove(String syxxxid) {
        boolean bOk = false ;
        bOk = sYXXXRepository.remove(syxxxid);

        return bOk ;
    }

    @Override
    public boolean update(SYXXX syxxx) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.SYXXX t_SYXXX = sYXXXRepository.convert2PO(syxxx,null);
        bOk = sYXXXRepository.update(t_SYXXX);
        sYXXXRepository.convert2Domain(t_SYXXX,syxxx) ;

        return bOk ;
    }

    @Override
    public SYXXX updateTempMajor(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public SYXXX getTempMajor(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public SYXXX getDraft(SYXXX syxxx) {
        return syxxx;
    }

    @Override
    public boolean checkKey(SYXXX syxxx) {
        return true;
    }
    @Override
    public SYXXX removeTemp(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public SYXXX getDraftTemp(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public SYXXX getTemp(SYXXX syxxx) {
         return syxxx;
    }

    @Override
    public boolean save(SYXXX syxxx) {
        if(syxxx.getSYXXXId()==null){
    		return create(syxxx);
    	}else{
            if(this.get(syxxx.getSYXXXId())!=null){
    			return update(syxxx);
    		}
    		return create(syxxx);
    	}
    }

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


    /**
     * 根据车险单查询
     */
    @Override
    public Page<SYXXX> selectByCID(String cidid ){
        SYXXXSearchContext context = new SYXXXSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(cidid)){
            com.sinosig.util.SearchFieldFilter fieldFilter=new com.sinosig.util.SearchFieldFilter();
            fieldFilter.setParam("cidid");
            fieldFilter.setCondition(com.sinosig.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(cidid);
            context.getCondition().add(fieldFilter);
        }
        List<SYXXX> list = new ArrayList<SYXXX>();
        Page<com.sinosig.core.repository.po.SYXXX> t_SYXXXs = sYXXXRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.SYXXX t_SYXXX : t_SYXXXs){
            list.add(sYXXXRepository.convert2Domain(t_SYXXX,null));
        }
        return new PageImpl<SYXXX>(list, context.getPageable(), t_SYXXXs.getTotalElements());
    }

    /**
     * 根据车险单查询
     */
    @Override
    public List<SYXXX> selectByCID2(String cidid ){

        SYXXXSearchContext context = new SYXXXSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(cidid)){
            com.sinosig.util.SearchFieldFilter fieldFilter=new com.sinosig.util.SearchFieldFilter();
            fieldFilter.setParam("cidid");
            fieldFilter.setCondition(com.sinosig.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(cidid);
            context.getCondition().add(fieldFilter);
        }
        List<SYXXX> list = new ArrayList<SYXXX>();
        Page<com.sinosig.core.repository.po.SYXXX> t_SYXXXs = sYXXXRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.SYXXX t_SYXXX : t_SYXXXs){
            list.add(sYXXXRepository.convert2Domain(t_SYXXX,null));
        }
        return list;
    }



}
