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.UserRoleDetailMapper;
import com.sa.ibiz.demo.demo.domain.UserRoleDetail;
import com.sa.ibiz.demo.demo.service.UserRoleDetailService;
import com.sa.ibiz.demo.ibizutil.service.ServiceImplBase;
import com.sa.ibiz.demo.demo.service.dto.UserRoleDetailSearchFilter;
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.UserObjectService;
import com.sa.ibiz.demo.demo.service.UserRoleService;

/**
 * 实体[UserRoleDetail] 服务对象接口实现
 */
@Service
public class UserRoleDetailServiceImpl extends ServiceImplBase<UserRoleDetailMapper, UserRoleDetail> implements UserRoleDetailService{

    @Autowired
    private UserObjectService userobjectService;
    @Autowired
    private UserRoleService userroleService;

    @Resource
    private UserRoleDetailMapper userroledetailMapper;


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

    @Override
   	public boolean remove(UserRoleDetail et) {
        String primaryKey=et.getUserroledetailid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setUserroledetailid(primaryKey);
          }
   		     return super.remove(et);
   	}

    @Override
    public boolean update(UserRoleDetail et){
        String primaryKey=et.getUserroledetailid();
         if(StringUtils.isEmpty(primaryKey))
         {
             primaryKey=(String)et.getDefaultPrimaryKey();
             et.setUserroledetailid(primaryKey);
          }
		     this.userroledetailMapper.updateOne(et);
		     this.get(et);
             return true;
    }


    public Object getEntityKey(UserRoleDetail et){
		return et.getUserroledetailid();  
    }

    @Override
    public boolean getDraft(UserRoleDetail et)  {
    if((!StringUtils.isEmpty(et.getUserobjectid())) && et.getUserobject() == null){
            try {
                et.setUserobject(userobjectService.getById(et.getUserobjectid()));
            }catch (Exception ex){}
        }
    if((!StringUtils.isEmpty(et.getUserroleid())) && et.getUserrole() == null){
            try {
                et.setUserrole(userroleService.getById(et.getUserroleid()));
            }catch (Exception ex){}
        }
            return true;
    }

	public List<UserRoleDetail> listDefault(UserRoleDetailSearchFilter filter) {
		return userroledetailMapper.searchDefault(filter,filter.getSelectCond());
	}

	public Page<UserRoleDetail> searchDefault(UserRoleDetailSearchFilter filter) {
		return userroledetailMapper.searchDefault(filter.getPage(),filter,filter.getSelectCond());
	}

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

 }