package com.cool.bang.common.base;

import com.cool.bang.common.constant.enums.UserType;
import com.cool.bang.common.tools.number.IncrUtil;
import com.cool.bang.common.tools.secure.SecurityUtil;
import com.cool.bang.common.web.response.ResultController;
import com.cool.bang.modules.approval.domain.ApprovalRecord;
import com.cool.bang.modules.approval.service.IApprovalFlowService;
import com.cool.bang.modules.approval.service.IApprovalNodeService;
import com.cool.bang.modules.approval.service.IApprovalRecordService;
import com.cool.bang.modules.system.domain.po.User;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Base Controller (基础控制器类)
 *
 * @author PeiZhi Guo
 * 2021-2-18 15:58
 */
public class BaseController extends ResultController {

    @Autowired
    protected IncrUtil incrUtil;

    @Autowired
    protected IApprovalFlowService approvalFlowService;

    @Autowired
    protected IApprovalNodeService approvalNodeService;

    @Autowired
    protected IApprovalRecordService approvalRecordService;

    /**
     * 获取当前登录用户的信息
     *
     * Return SysUser
     */
    protected static User getCurrentUser() {
        return (User) SecurityUtil.getAuthentication().getPrincipal();
    }


    /**
     * 获取审批历史
     *
     * Return list
     */
    protected List<ApprovalRecord> getApprovalHistory(Long tableId, String flowNumber) {
        ApprovalRecord approval = new ApprovalRecord(tableId, flowNumber);
        return approvalRecordService.list(approval);
    }
}
