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

/**
 * 实体[JQXXX] 服务对象接口实现
 */
@Service
public class JQXXXServiceImpl implements IJQXXXService {

    @Autowired
    com.sinosig.core.repository.JQXXXRepository jQXXXRepository;




    @Override
    public JQXXX getDraftTemp(JQXXX jqxxx) {
         return jqxxx;
    }

    @Override
    public JQXXX getDraftTempMajor(JQXXX jqxxx) {
         return jqxxx;
    }

    @Override
    public JQXXX getDraft(JQXXX jqxxx) {
        return jqxxx;
    }

    @Override
    public JQXXX createTemp(JQXXX jqxxx) {
         return jqxxx;
    }

    @Override
    public boolean create(JQXXX jqxxx) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.JQXXX t_JQXXX = jQXXXRepository.convert2PO(jqxxx,null);
        bOk = jQXXXRepository.create(t_JQXXX);
        jQXXXRepository.convert2Domain(t_JQXXX,jqxxx);

        return bOk ;
    }

    @Override
    public boolean save(JQXXX jqxxx) {
        if(jqxxx.getJQXXXId()==null){
    		return create(jqxxx);
    	}else{
            if(this.get(jqxxx.getJQXXXId())!=null){
    			return update(jqxxx);
    		}
    		return create(jqxxx);
    	}
    }

    @Override
    public JQXXX getTempMajor(JQXXX jqxxx) {
         return jqxxx;
    }

    @Override
    public boolean update(JQXXX jqxxx) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.JQXXX t_JQXXX = jQXXXRepository.convert2PO(jqxxx,null);
        bOk = jQXXXRepository.update(t_JQXXX);
        jQXXXRepository.convert2Domain(t_JQXXX,jqxxx) ;

        return bOk ;
    }

    @Override
    public JQXXX removeTempMajor(JQXXX jqxxx) {
         return jqxxx;
    }

    @Override
    public JQXXX get(String jqxxxid) {
        com.sinosig.core.repository.po.JQXXX t_JQXXX = jQXXXRepository.get(jqxxxid);
        return jQXXXRepository.convert2Domain(t_JQXXX,null);
    }

    @Override
    public JQXXX get(JQXXX jqxxx) {
        com.sinosig.core.repository.po.JQXXX t_JQXXX = jQXXXRepository.get(jqxxx.getJQXXXId());
        jQXXXRepository.convert2Domain(t_JQXXX,jqxxx);
        return jqxxx;
    }

    @Override
    public JQXXX createTempMajor(JQXXX jqxxx) {
         return jqxxx;
    }

    @Override
    public JQXXX updateTempMajor(JQXXX jqxxx) {
         return jqxxx;
    }

    @Override
    public boolean remove(String jqxxxid) {
        boolean bOk = false ;
        bOk = jQXXXRepository.remove(jqxxxid);

        return bOk ;
    }

    @Override
    public JQXXX removeTemp(JQXXX jqxxx) {
         return jqxxx;
    }

    @Override
    public boolean checkKey(JQXXX jqxxx) {
        return true;
    }
    @Override
    public JQXXX updateTemp(JQXXX jqxxx) {
         return jqxxx;
    }

    @Override
    public JQXXX getTemp(JQXXX jqxxx) {
         return jqxxx;
    }

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


    /**
     * 根据车险单查询
     */
    @Override
    public Page<JQXXX> selectByJQXXX(String cidid ){
        JQXXXSearchContext context = new JQXXXSearchContext();
        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<JQXXX> list = new ArrayList<JQXXX>();
        Page<com.sinosig.core.repository.po.JQXXX> t_JQXXXs = jQXXXRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.JQXXX t_JQXXX : t_JQXXXs){
            list.add(jQXXXRepository.convert2Domain(t_JQXXX,null));
        }
        return new PageImpl<JQXXX>(list, context.getPageable(), t_JQXXXs.getTotalElements());
    }

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

        JQXXXSearchContext context = new JQXXXSearchContext();
        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<JQXXX> list = new ArrayList<JQXXX>();
        Page<com.sinosig.core.repository.po.JQXXX> t_JQXXXs = jQXXXRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.JQXXX t_JQXXX : t_JQXXXs){
            list.add(jQXXXRepository.convert2Domain(t_JQXXX,null));
        }
        return list;
    }



}
