package com.github.wxiaoqi.security.admin.biz;

import com.ace.cache.annotation.Cache;
import com.ace.cache.annotation.CacheClear;
import com.github.wxiaoqi.security.admin.entity.AppUserDetail;
import com.github.wxiaoqi.security.admin.mapper.AppUserDetailMapper;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * ${DESCRIPTION}
 *
 * @author wanghaobin
 * @create 2017-06-08 16:23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class AppUserDetailBiz extends BaseBiz<AppUserDetailMapper, AppUserDetail> {

    @Override
    @CacheClear(pre="user{1.userid}")
    public void updateSelectiveById(AppUserDetail entity) {
        super.updateSelectiveById(entity);
    }

    /**
     * 根据用户id获取用户信息
     * @param userid
     * @return
     */
    @Cache(key="user{1}")
    public AppUserDetail getUserByUserid(Integer userid){
        Example example = new Example(AppUserDetail.class);
        example.createCriteria().andEqualTo("userid", userid).andEqualTo("isdel", 0);
        List<AppUserDetail> list = mapper.selectByExample(example);
        if (list != null && list.size() != 0) {
            return list.get(0);
        }
        return null;
    }





}
