package com.ruoyi.ibs.dashboard.service.impl;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ibs.dashboard.domain.vo.CampaignVO;
import com.ruoyi.ibs.dashboard.service.DashboardCampaignService;
import com.ruoyi.ibs.list.mapper.SysCampaignMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.ruoyi.common.utils.SecurityUtils.*;
import static com.ruoyi.common.utils.SecurityUtils.userRoleHeadOrBranch;

/**
 * @Author 吴凯程
 * @Date 2025/3/19
 **/
@Service
public class DashboardCampaignServiceImpl implements DashboardCampaignService {
    @Autowired
    private SysCampaignMapper sysCampaignMapper;


    /**
     * @return
     */
    @Override
    public List<CampaignVO> getListByManager() {
        List<CampaignVO> listByManager;
        if (SecurityUtils.userRole().equals("manager") || SecurityUtils.userRole().equals("outlet")){
            listByManager = sysCampaignMapper.getListByManager(getUserId());
        }else{
            throw new ServiceException ("该用户没有权限") ;
        }
        return listByManager;
    }

    /**
     * @return
     */
    @Override
    public List<CampaignVO> getListByBranchAdmin(Boolean isFinish) {
        if (!SecurityUtils.hasRole("branchAdmin")){
            throw new ServiceException ("该用户没有支行管理员权限") ;
        }
        return sysCampaignMapper.getListByBranchAdmin(getDeptId(), getUserId(), isFinish);
    }


    @Override
    public List<CampaignVO> getListByHeadAdmin(Boolean isFinish) {
        if (!Constants.HEAD_ADMIN.equalsIgnoreCase(userRoleHeadOrBranch())){
            throw new ServiceException ("该用户没有总行相关权限") ;
        }
        return sysCampaignMapper.getListByHeadAdmin(getDeptId(), userRoleNum(), isFinish);
    }
}
