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.OrgSectorMapper;
import com.sa.ibiz.demo.demo.domain.OrgSector;
import com.sa.ibiz.demo.demo.service.OrgSectorService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.OrgSectorSearchFilter;
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.OrgSectorService;
import com.sa.ibiz.demo.demo.service.OrgService;

/**
 * 实体[OrgSector] 服务对象接口实现
 */
@Service
public class OrgSectorServiceImpl extends ServiceImplBase<OrgSectorMapper, OrgSector> implements OrgSectorService{

    @Autowired
    private OrgSectorService porgsectorService;
    @Autowired
    private OrgSectorService reporgsectorService;
    @Autowired
    private OrgService orgService;

    @Resource
    private OrgSectorMapper orgsectorMapper;


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

    public Object getEntityKey(OrgSector et){
		return et.getOrgsectorid();  
    }

    @Override
    public boolean getDraft(OrgSector et)  {
    if((!StringUtils.isEmpty(et.getPorgsectorid())) && et.getPorgsector() == null){
            try {
                et.setPorgsector(porgsectorService.getById(et.getPorgsectorid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getReporgsectorid())) && et.getReporgsector() == null){
            try {
                et.setReporgsector(reporgsectorService.getById(et.getReporgsectorid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getOrgid())) && et.getOrg() == null){
            try {
                et.setOrg(orgService.getById(et.getOrgid()));
            }catch (Exception ex){}
        }
            return true;
    }
    @Override
    public OrgSector initUserObject(OrgSector et)  {
		return et;
    }

	public List<OrgSector> listUserOrg(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchUserOrg(filter,filter.getSelectCond());
	}

	public Page<OrgSector> searchUserOrg(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchUserOrg(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgSector> listDefault(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchDefault(filter,filter.getSelectCond());
	}

	public Page<OrgSector> searchDefault(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchDefault(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgSector> listCurChild(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchCurChild(filter,filter.getSelectCond());
	}

	public Page<OrgSector> searchCurChild(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchCurChild(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgSector> listUserOrgSector(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchUserOrgSector(filter,filter.getSelectCond());
	}

	public Page<OrgSector> searchUserOrgSector(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchUserOrgSector(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgSector> listOrgRoot(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchOrgRoot(filter,filter.getSelectCond());
	}

	public Page<OrgSector> searchOrgRoot(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchOrgRoot(filter.getPage(),filter,filter.getSelectCond());
	}


	public List<OrgSector> listCurOrg(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchCurOrg(filter,filter.getSelectCond());
	}

	public Page<OrgSector> searchCurOrg(OrgSectorSearchFilter filter) {
		return orgsectorMapper.searchCurOrg(filter.getPage(),filter,filter.getSelectCond());
	}

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

 }