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.ORGUSERRepository;
import com.ibiz.core.repository.po.ORGUSER;
import com.ibiz.core.external.filter.ORGUSERSearchContext;
import com.ibiz.mybatis.external.mapper.T_ORGUSERMapper;
import com.ibiz.mybatis.external.po.T_ORGUSERImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ibiz.mybatis.util.helper.QueryBuilder;


/**
 * 关系型数据实体表[T_ORGUSER] 存储对象
 */
@Repository
@ConditionalOnProperty(prefix = "orguser", value="store" , havingValue = "sql", matchIfMissing = true)
public class T_ORGUSERRepositoryImpl extends ServiceImpl<T_ORGUSERMapper, T_ORGUSERImpl> implements ORGUSERRepository {

    @Autowired
    QueryBuilder queryBuilder;

    private boolean isLogicValid = false ;

    @Autowired
	T_ORGUSERMapper t_ORGUSERMapper;

    public ORGUSER createPO(){
        return new T_ORGUSERImpl();
    }

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


    public boolean create(ORGUSER po){
        return this.save((T_ORGUSERImpl)po);
    }

    public boolean update(ORGUSER po){
        return this.updateById((T_ORGUSERImpl)po);
    }

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

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

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


    public com.ibiz.core.external.domain.ORGUSER convert2Domain( ORGUSER po ,com.ibiz.core.external.domain.ORGUSER domain){
              if(po == null)
                     return domain ;
              if(domain == null){
                     domain = new com.ibiz.core.external.domain.ORGUSER();
              }
            //if(po.getORGUSERNameDirtyFlag())
                domain.setORGUSERName(po.getORGUSERName());
            //if(po.getCreateManDirtyFlag())
                domain.setCreateMan(po.getCreateMan());
            //if(po.getCreateDateDirtyFlag())
                domain.setCreateDate(po.getCreateDate());
            //if(po.getORGUSERIdDirtyFlag())
                domain.setORGUSERId(po.getORGUSERId());
            //if(po.getUpdateDateDirtyFlag())
                domain.setUpdateDate(po.getUpdateDate());
            //if(po.getUpdateManDirtyFlag())
                domain.setUpdateMan(po.getUpdateMan());
            //if(po.getORGNameDirtyFlag())
                domain.setORGName(po.getORGName());
            //if(po.getORGIdDirtyFlag())
                domain.setORGId(po.getORGId());
              return domain ;
    }

    public ORGUSER convert2PO(com.ibiz.core.external.domain.ORGUSER domain , ORGUSER po){
        if(domain == null)
            return po ;
        if(po==null){
            po = createPO() ;
        }
        if(domain.getORGUSERNameDirtyFlag())
            po.setORGUSERName(domain.getORGUSERName());
        if(domain.getCreateManDirtyFlag())
            po.setCreateMan(domain.getCreateMan());
        if(domain.getCreateDateDirtyFlag())
            po.setCreateDate(domain.getCreateDate());
        if(domain.getORGUSERIdDirtyFlag())
            po.setORGUSERId(domain.getORGUSERId());
        if(domain.getUpdateDateDirtyFlag())
            po.setUpdateDate(domain.getUpdateDate());
        if(domain.getUpdateManDirtyFlag())
            po.setUpdateMan(domain.getUpdateMan());
        if(domain.getORGNameDirtyFlag())
            po.setORGName(domain.getORGName());
        if(domain.getORGIdDirtyFlag())
            po.setORGId(domain.getORGId());

        return po ;
    }
}
