package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.ActHistoryData;
import com.ruoyi.system.domain.ActHistoryDataDAO;
import com.ruoyi.system.dto.Pagination;
import com.ruoyi.system.mapper.ActHistoryDataMapper;
import com.ruoyi.system.service.IActHistoryDataService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author haiwe
 * @date 2024/7/24
 */
@Service
@RequiredArgsConstructor
public class ActHistoryDataServiceImpl implements IActHistoryDataService {
    private static final Logger log = LoggerFactory.getLogger(ActHistoryDataServiceImpl.class);
    private final ActHistoryDataMapper actHistoryDataMapper;
    private static Map<String, String> roleIdMap = new HashMap<>();

    static {
        roleIdMap.put("10", "010101");
        roleIdMap.put("11", "011704");
        roleIdMap.put("12", "011204");
        roleIdMap.put("13", "011702");
        roleIdMap.put("14", "011701");
        roleIdMap.put("15", "011502");
        roleIdMap.put("16", "010102");
    }


    @Override
    public ActHistoryData getById(Integer id) {
        return actHistoryDataMapper.getById(id);
    }

    @Override
    public void insert(ActHistoryDataDAO actHistoryDataDAO) {
        actHistoryDataMapper.removeDuplicates(actHistoryDataDAO.getType(), actHistoryDataDAO.getMineId(), actHistoryDataDAO.getDateColumn());
        actHistoryDataMapper.insert(actHistoryDataDAO);
    }

    @Override
    public List<ActHistoryData> getData(Pagination pagination) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        if (user.getRoles().size() != 0) {
            SysRole sysRole = user.getRoles().get(0);
            String roleSort = sysRole.getRoleSort();
            pagination.setMineId(roleIdMap.getOrDefault(roleSort, "0"));
        }
        int pag = (Integer.parseInt(pagination.getPageNum()) - 1) * Integer.parseInt(pagination.getPageSize());
        return actHistoryDataMapper.paginatedQueries(pagination.getMineId(), pag, pagination.getType(), pagination.getWageMonth(), Integer.parseInt(pagination.getPageSize()));
    }


}

