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.OrgSecUserMapper;
import com.sa.ibiz.demo.demo.domain.OrgSecUser;
import com.sa.ibiz.demo.demo.service.OrgSecUserService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.OrgSecUserSearchFilter;
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.OrgUserService;
import com.sa.ibiz.demo.demo.service.OrgService;

/**
 * 实体[OrgSecUser] 服务对象接口实现
 */
@Service
public class OrgSecUserServiceImpl extends ServiceImplBase<OrgSecUserMapper, OrgSecUser> implements OrgSecUserService{

    @Autowired
    private OrgSectorService orgsectorService;
    @Autowired
    private OrgSecUserTypeService orgsecusertypeService;
    @Autowired
    private OrgUserService orguserService;
    @Autowired
    private OrgService orgService;

    @Resource
    private OrgSecUserMapper orgsecuserMapper;


    @Override
    public boolean create(OrgSecUser et) {
        this.beforeCreate(et);
        String primaryKey=et.getOrgsecuserid();
        if(StringUtils.isEmpty(primaryKey))
        {
            primaryKey=(String)et.getDefaultPrimaryKey();
            et.setOrgsecuserid(primaryKey);
         }
         return super.create(et);
    }
    @Override
	public OrgSecUser get(OrgSecUser et) {
        String primaryKey=et.getOrgsecuserid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setOrgsecuserid(primaryKey);
          }
		      return super.get(et);
	}

    @Override
   	public boolean remove(OrgSecUser et) {
        String primaryKey=et.getOrgsecuserid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setOrgsecuserid(primaryKey);
          }
   		     return super.remove(et);
   	}

    @Override
    public boolean update(OrgSecUser et){
        String primaryKey=et.getOrgsecuserid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setOrgsecuserid(primaryKey);
          }
		     this.orgsecuserMapper.updateOne(et);
		     this.get(et);
             return true;
    }


    public Object getEntityKey(OrgSecUser et){
		return et.getOrgsecuserid();  
    }

    @Override
    public boolean getDraft(OrgSecUser 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.getOrguserid())) && et.getOrguser() == null){
            try {
                et.setOrguser(orguserService.getById(et.getOrguserid()));
            }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 OrgSecUser removeDefault(OrgSecUser et)  {
		return et;
    }

	public List<OrgSecUser> listDefault(OrgSecUserSearchFilter filter) {
		return orgsecuserMapper.searchDefault(filter,filter.getSelectCond());
	}

	public Page<OrgSecUser> searchDefault(OrgSecUserSearchFilter filter) {
		return orgsecuserMapper.searchDefault(filter.getPage(),filter,filter.getSelectCond());
	}

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

 }