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.SYXTBYD;
import com.sinosig.core.module.filter.SYXTBYDSearchContext;
import com.sinosig.core.module.service.ISYXTBYDService;
import com.sinosig.core.module.service.logic.ISYXTBYDGetTBYDKXXLogic;
import org.springframework.beans.factory.annotation.Autowired;
import com.sinosig.util.SearchResult;

/**
 * 实体[SYXTBYD] 服务对象接口实现
 */
@Service
public class SYXTBYDServiceImpl implements ISYXTBYDService {

    @Autowired
    com.sinosig.core.repository.SYXTBYDRepository sYXTBYDRepository;



    @Autowired
    private ISYXTBYDGetTBYDKXXLogic gettbydkxxLogic ;


    @Override
    public boolean remove(String syxtbydid) {
        boolean bOk = false ;
        bOk = sYXTBYDRepository.remove(syxtbydid);

        return bOk ;
    }

    @Override
    public boolean update(SYXTBYD syxtbyd) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.SYXTBYD t_SYXTBYD = sYXTBYDRepository.convert2PO(syxtbyd,null);
        bOk = sYXTBYDRepository.update(t_SYXTBYD);
        sYXTBYDRepository.convert2Domain(t_SYXTBYD,syxtbyd) ;

        return bOk ;
    }

    @Override
    public SYXTBYD getTempMajor(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

    @Override
    public SYXTBYD createTemp(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

    @Override
    public SYXTBYD updateTempMajor(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

    @Override
    public SYXTBYD getTemp(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

    @Override
    public boolean save(SYXTBYD syxtbyd) {
        if(syxtbyd.getSYXTBYDId()==null){
    		return create(syxtbyd);
    	}else{
            if(this.get(syxtbyd.getSYXTBYDId())!=null){
    			return update(syxtbyd);
    		}
    		return create(syxtbyd);
    	}
    }

    @Override
    public SYXTBYD getDraft(SYXTBYD syxtbyd) {
        return syxtbyd;
    }

    @Override
    public SYXTBYD removeTempMajor(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

    @Override
    public SYXTBYD getTBYDKXX(SYXTBYD syxtbyd) {
         gettbydkxxLogic.execute(syxtbyd);
         return syxtbyd ;
    }
    @Override
    public boolean checkKey(SYXTBYD syxtbyd) {
        return true;
    }
    @Override
    public SYXTBYD removeTemp(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

    @Override
    public SYXTBYD updateTemp(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

    @Override
    public boolean create(SYXTBYD syxtbyd) {
        boolean bOk = false ;
        com.sinosig.core.repository.po.SYXTBYD t_SYXTBYD = sYXTBYDRepository.convert2PO(syxtbyd,null);
        bOk = sYXTBYDRepository.create(t_SYXTBYD);
        sYXTBYDRepository.convert2Domain(t_SYXTBYD,syxtbyd);

        return bOk ;
    }

    @Override
    public SYXTBYD createTempMajor(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

    @Override
    public SYXTBYD get(String syxtbydid) {
        com.sinosig.core.repository.po.SYXTBYD t_SYXTBYD = sYXTBYDRepository.get(syxtbydid);
        return sYXTBYDRepository.convert2Domain(t_SYXTBYD,null);
    }

    @Override
    public SYXTBYD get(SYXTBYD syxtbyd) {
        com.sinosig.core.repository.po.SYXTBYD t_SYXTBYD = sYXTBYDRepository.get(syxtbyd.getSYXTBYDId());
        sYXTBYDRepository.convert2Domain(t_SYXTBYD,syxtbyd);
        return syxtbyd;
    }

    @Override
    public SYXTBYD getDraftTempMajor(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

    @Override
    public SYXTBYD getDraftTemp(SYXTBYD syxtbyd) {
         return syxtbyd;
    }

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


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

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

        SYXTBYDSearchContext context = new SYXTBYDSearchContext();
        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<SYXTBYD> list = new ArrayList<SYXTBYD>();
        Page<com.sinosig.core.repository.po.SYXTBYD> t_SYXTBYDs = sYXTBYDRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.SYXTBYD t_SYXTBYD : t_SYXTBYDs){
            list.add(sYXTBYDRepository.convert2Domain(t_SYXTBYD,null));
        }
        return list;
    }
    /**
     * 根据特别约定库查询
     */
    @Override
    public Page<SYXTBYD> selectByTBYDK(String tbydkid ){
        SYXTBYDSearchContext context = new SYXTBYDSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(tbydkid)){
            com.sinosig.util.SearchFieldFilter fieldFilter=new com.sinosig.util.SearchFieldFilter();
            fieldFilter.setParam("tbydkid");
            fieldFilter.setCondition(com.sinosig.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(tbydkid);
            context.getCondition().add(fieldFilter);
        }
        List<SYXTBYD> list = new ArrayList<SYXTBYD>();
        Page<com.sinosig.core.repository.po.SYXTBYD> t_SYXTBYDs = sYXTBYDRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.SYXTBYD t_SYXTBYD : t_SYXTBYDs){
            list.add(sYXTBYDRepository.convert2Domain(t_SYXTBYD,null));
        }
        return new PageImpl<SYXTBYD>(list, context.getPageable(), t_SYXTBYDs.getTotalElements());
    }

    /**
     * 根据特别约定库查询
     */
    @Override
    public List<SYXTBYD> selectByTBYDK2(String tbydkid ){

        SYXTBYDSearchContext context = new SYXTBYDSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(tbydkid)){
            com.sinosig.util.SearchFieldFilter fieldFilter=new com.sinosig.util.SearchFieldFilter();
            fieldFilter.setParam("tbydkid");
            fieldFilter.setCondition(com.sinosig.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(tbydkid);
            context.getCondition().add(fieldFilter);
        }
        List<SYXTBYD> list = new ArrayList<SYXTBYD>();
        Page<com.sinosig.core.repository.po.SYXTBYD> t_SYXTBYDs = sYXTBYDRepository.searchDefault(context) ;
        for(com.sinosig.core.repository.po.SYXTBYD t_SYXTBYD : t_SYXTBYDs){
            list.add(sYXTBYDRepository.convert2Domain(t_SYXTBYD,null));
        }
        return list;
    }



}
