package com.nantian.sc.cloud.admin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nantian.sc.cloud.admin.api.entity.OperationLog;
import com.nantian.sc.cloud.admin.mapper.OperationLogMapper;
import com.nantian.sc.cloud.admin.service.OperationLogService;
import com.nantian.sc.cloud.common.security.service.ScUser;
import com.nantian.sc.cloud.common.security.util.SecurityUtils;
import org.springframework.stereotype.Service;

/**
 *
 * @date 2018-09-27
 */
@Service("operationLogService")
public class OperationLogServiceImpl extends ServiceImpl<OperationLogMapper, OperationLog> implements OperationLogService {

    @Override
    public IPage<OperationLog> getPageScope(Page page, OperationLog operationLog) {
        ScUser u = SecurityUtils.getUser();
        String deptId = u.getDeptId().toString();
        if (deptId.contains("0000")) {
            deptId = StrUtil.subWithLength(deptId, 0, 2);
        }else if (deptId.contains("00")) {
            deptId = StrUtil.subWithLength(deptId, 0, 4);
        }
        operationLog.setUserDept(u.getUserDept());
        return baseMapper.getPageScope(page, operationLog, deptId);
    }
}

