package com.ibiz.mybatis.external;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.math.BigInteger;
import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

import com.ibiz.core.repository.JQXBJRepository;
import com.ibiz.core.repository.po.JQXBJ;
import com.ibiz.core.external.filter.JQXBJSearchContext;
import com.ibiz.mybatis.external.mapper.T_JQXBJMapper;
import com.ibiz.mybatis.external.po.T_JQXBJImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ibiz.mybatis.util.helper.QueryBuilder;


/**
 * 关系型数据实体表[T_JQXBJ] 存储对象
 */
@Repository
@ConditionalOnProperty(prefix = "jqxbj", value="store" , havingValue = "sql", matchIfMissing = true)
public class T_JQXBJRepositoryImpl extends ServiceImpl<T_JQXBJMapper, T_JQXBJImpl> implements JQXBJRepository {

    @Autowired
    QueryBuilder queryBuilder;

    private boolean isLogicValid = false ;

    @Autowired
	T_JQXBJMapper t_JQXBJMapper;

    public JQXBJ createPO(){
        return new T_JQXBJImpl();
    }

    public JQXBJ get(String key){
        return this.getById(key);
    }


    public boolean create(JQXBJ po){
        return this.save((T_JQXBJImpl)po);
    }

    public boolean update(JQXBJ po){
        return this.updateById((T_JQXBJImpl)po);
    }

    public boolean remove(String key){
        return this.removeById(key);
    }

    public Page<JQXBJ> searchDefault(JQXBJSearchContext context){
        QueryWrapper qw=queryBuilder.buildQueryWrapper(context);
        com.baomidou.mybatisplus.extension.plugins.pagination.Page page=queryBuilder.buildPage(context);
        com.baomidou.mybatisplus.extension.plugins.pagination.Page<JQXBJ> page_datas=t_JQXBJMapper.searchDefault(page,context,qw);
        List<JQXBJ> list_datas=queryBuilder.page2List(page_datas);
        return new PageImpl<JQXBJ>(list_datas, context.getPageable(), page_datas.getTotal());
    }


    public com.ibiz.core.external.domain.JQXBJ convert2Domain( JQXBJ po ,com.ibiz.core.external.domain.JQXBJ domain){
              if(po == null)
                     return domain ;
              if(domain == null){
                     domain = new com.ibiz.core.external.domain.JQXBJ();
              }
            //if(po.getFlxsDirtyFlag())
                domain.setFlxs(po.getFlxs());
            //if(po.getJQXBJNameDirtyFlag())
                domain.setJQXBJName(po.getJQXBJName());
            //if(po.getCreateDateDirtyFlag())
                domain.setCreateDate(po.getCreateDate());
            //if(po.getSjbfDirtyFlag())
                domain.setSjbf(po.getSjbf());
            //if(po.getZrxeDirtyFlag())
                domain.setZrxe(po.getZrxe());
            //if(po.getUpdateDateDirtyFlag())
                domain.setUpdateDate(po.getUpdateDate());
            //if(po.getJQXBJIdDirtyFlag())
                domain.setJQXBJId(po.getJQXBJId());
            //if(po.getTkdmDirtyFlag())
                domain.setTkdm(po.getTkdm());
            //if(po.getCreateManDirtyFlag())
                domain.setCreateMan(po.getCreateMan());
            //if(po.getUpdateManDirtyFlag())
                domain.setUpdateMan(po.getUpdateMan());
            //if(po.getTkmcDirtyFlag())
                domain.setTkmc(po.getTkmc());
            //if(po.getJzbfDirtyFlag())
                domain.setJzbf(po.getJzbf());
              return domain ;
    }

    public JQXBJ convert2PO(com.ibiz.core.external.domain.JQXBJ domain , JQXBJ po){
        if(domain == null)
            return po ;
        if(po==null){
            po = createPO() ;
        }
        if(domain.getFlxsDirtyFlag())
            po.setFlxs(domain.getFlxs());
        if(domain.getJQXBJNameDirtyFlag())
            po.setJQXBJName(domain.getJQXBJName());
        if(domain.getCreateDateDirtyFlag())
            po.setCreateDate(domain.getCreateDate());
        if(domain.getSjbfDirtyFlag())
            po.setSjbf(domain.getSjbf());
        if(domain.getZrxeDirtyFlag())
            po.setZrxe(domain.getZrxe());
        if(domain.getUpdateDateDirtyFlag())
            po.setUpdateDate(domain.getUpdateDate());
        if(domain.getJQXBJIdDirtyFlag())
            po.setJQXBJId(domain.getJQXBJId());
        if(domain.getTkdmDirtyFlag())
            po.setTkdm(domain.getTkdm());
        if(domain.getCreateManDirtyFlag())
            po.setCreateMan(domain.getCreateMan());
        if(domain.getUpdateManDirtyFlag())
            po.setUpdateMan(domain.getUpdateMan());
        if(domain.getTkmcDirtyFlag())
            po.setTkmc(domain.getTkmc());
        if(domain.getJzbfDirtyFlag())
            po.setJzbf(domain.getJzbf());

        return po ;
    }
}
