package com.sa.ibiz.demo.demo.service.impl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.mapper.OrgMapper;
import com.sa.ibiz.demo.demo.domain.Org;
import com.sa.ibiz.demo.demo.service.OrgService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.OrgSearchFilter;
import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils;
import java.util.UUID;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.math.BigInteger;
import com.sa.ibiz.demo.ibizutil.annotation.PreField;
import java.lang.reflect.Field;

import com.sa.ibiz.demo.demo.service.OrgService;

/**
 * 实体[Org] 服务对象接口实现
 */
@Service
public class OrgServiceImpl extends ServiceImplBase<OrgMapper, Org> implements OrgService{

    @Autowired
    private OrgService porgService;

    @Resource
    private OrgMapper orgMapper;


    @Override
    public boolean create(Org et) {
        this.beforeCreate(et);
         return super.create(et);
    }
    @Override
    public boolean update(Org et){
        this.beforeUpdate(et);
		this.orgMapper.updateOne(et);
		this.get(et);
		return true;
    }

    public Object getEntityKey(Org et){
		return et.getOrgid();  
    }

    @Override
    public boolean getDraft(Org et)  {
    if((!StringUtils.isEmpty(et.getPorgid())) && et.getPorg() == null){
            try {
                et.setPorg(porgService.getById(et.getPorgid()));
            }catch (Exception ex){}
        }
            return true;
    }
    @Override
    public Org initUserObject(Org et)  {
		return et;
    }
    @Override
    public Org initAll(Org et)  {
		return et;
    }

	public List<Org> listCurChild(OrgSearchFilter filter) {
		return orgMapper.searchCurChild(filter,filter.getSelectCond());
	}

	public Page<Org> searchCurChild(OrgSearchFilter filter) {
		return orgMapper.searchCurChild(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<Org> listDefault(OrgSearchFilter filter) {
		return orgMapper.searchDefault(filter,filter.getSelectCond());
	}

	public Page<Org> searchDefault(OrgSearchFilter filter) {
		return orgMapper.searchDefault(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<Org> listCurCat(OrgSearchFilter filter) {
		return orgMapper.searchCurCat(filter,filter.getSelectCond());
	}

	public Page<Org> searchCurCat(OrgSearchFilter filter) {
		return orgMapper.searchCurCat(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<Org> listAllRoot(OrgSearchFilter filter) {
		return orgMapper.searchAllRoot(filter,filter.getSelectCond());
	}

	public Page<Org> searchAllRoot(OrgSearchFilter filter) {
		return orgMapper.searchAllRoot(filter.getPage(),filter,filter.getSelectCond());
	}

    public  List<Map<String,Object>> selectRow(String sql){
       return orgMapper.selectRow(sql);
    }

 }