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.OrgUserMapper;
import com.sa.ibiz.demo.demo.domain.OrgUser;
import com.sa.ibiz.demo.demo.service.OrgUserService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.OrgUserSearchFilter;
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.OrgSectorService;
import com.sa.ibiz.demo.demo.service.OrgSecUserTypeService;
import com.sa.ibiz.demo.demo.service.OrgUserLevelService;
import com.sa.ibiz.demo.demo.service.OrgService;

/**
 * 实体[OrgUser] 服务对象接口实现
 */
@Service
public class OrgUserServiceImpl extends ServiceImplBase<OrgUserMapper, OrgUser> implements OrgUserService{

    @Autowired
    private OrgSectorService orgsectorService;
    @Autowired
    private OrgSecUserTypeService orgsecusertypeService;
    @Autowired
    private OrgUserLevelService orguserlevelService;
    @Autowired
    private OrgService orgService;

    @Resource
    private OrgUserMapper orguserMapper;


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

    public Object getEntityKey(OrgUser et){
		return et.getOrguserid();  
    }

    @Override
    public boolean getDraft(OrgUser et)  {
    if((!StringUtils.isEmpty(et.getOrgsectorid())) && et.getOrgsector() == null){
            try {
                et.setOrgsector(orgsectorService.getById(et.getOrgsectorid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getOrgsecusertypeid())) && et.getOrgsecusertype() == null){
            try {
                et.setOrgsecusertype(orgsecusertypeService.getById(et.getOrgsecusertypeid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getOrguserlevelid())) && et.getOrguserlevel() == null){
            try {
                et.setOrguserlevel(orguserlevelService.getById(et.getOrguserlevelid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getOrgid())) && et.getOrg() == null){
            try {
                et.setOrg(orgService.getById(et.getOrgid()));
            }catch (Exception ex){}
        }
            return true;
    }
    @Autowired
    com.sa.ibiz.demo.demo.logic.OrgUserLogic orguserLogic;
    @Override
    public OrgUser updateCurUser(OrgUser et)  {
                    orguserLogic.updateCurUser(et);
		return et;
    }
    @Override
    public OrgUser getCurUser(OrgUser et)  {
                    orguserLogic.getCurUser(et);
		return et;
    }

	public List<OrgUser> listCurOrgSector(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrgSector(filter,filter.getSelectCond());
	}

	public Page<OrgUser> searchCurOrgSector(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrgSector(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgUser> listCurOrgSectorBIZLeader(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrgSectorBIZLeader(filter,filter.getSelectCond());
	}

	public Page<OrgUser> searchCurOrgSectorBIZLeader(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrgSectorBIZLeader(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgUser> listDefault(OrgUserSearchFilter filter) {
		return orguserMapper.searchDefault(filter,filter.getSelectCond());
	}

	public Page<OrgUser> searchDefault(OrgUserSearchFilter filter) {
		return orguserMapper.searchDefault(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgUser> listCurOrg(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrg(filter,filter.getSelectCond());
	}

	public Page<OrgUser> searchCurOrg(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrg(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgUser> listUserOrgSector(OrgUserSearchFilter filter) {
		return orguserMapper.searchUserOrgSector(filter,filter.getSelectCond());
	}

	public Page<OrgUser> searchUserOrgSector(OrgUserSearchFilter filter) {
		return orguserMapper.searchUserOrgSector(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgUser> listCurOrgUser(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrgUser(filter,filter.getSelectCond());
	}

	public Page<OrgUser> searchCurOrgUser(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrgUser(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgUser> listUserOrg(OrgUserSearchFilter filter) {
		return orguserMapper.searchUserOrg(filter,filter.getSelectCond());
	}

	public Page<OrgUser> searchUserOrg(OrgUserSearchFilter filter) {
		return orguserMapper.searchUserOrg(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgUser> listCurOrgSectorLeader(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrgSectorLeader(filter,filter.getSelectCond());
	}

	public Page<OrgUser> searchCurOrgSectorLeader(OrgUserSearchFilter filter) {
		return orguserMapper.searchCurOrgSectorLeader(filter.getPage(),filter,filter.getSelectCond());
	}

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

 }