package com.pannk.mms.common.base;

import com.pannk.mms.modules.sys.entity.SysUserEntity;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;

import java.util.Date;

/**
 * Created by wolf on 20-11-2.
 */
@Slf4j
public class BaseController {

    /**
     * 获取当前登录用户
     *
     * @return sysUserEntity
     */
    protected SysUserEntity getUser() {
        return (SysUserEntity) SecurityUtils.getSubject().getPrincipal();
    }

    /**
     * 获取登录用户id
     *
     * @return long
     */
    protected Long getUserId() {
//        return getUser().getId();
        return 1L;
    }

    /**
     * 处理新建用户数据
     *
     * @param baseEntity 实体
     */
    protected void createData(BaseEntity baseEntity) {
        baseEntity.setCreateDate(new Date());
        baseEntity.setCreateUser(getUserId());
    }

    /**
     * 处理更新用户数据
     *
     * @param baseEntity 实体
     */
    protected void updateDate(BaseEntity baseEntity) {
        baseEntity.setUpdateDate(new Date());
        baseEntity.setUpdateUser(getUserId());
    }
}
