package com.oqpo.api.service;

import com.oqpo.api.mapper.CommonMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class CommonService {
    @Autowired
    private CommonMapper commonMapper;

    public String fnGetKeyNo(Integer numNo) {
        return commonMapper.selectKeyNo(numNo);
    }

    public String fnGetDealNo(Integer numNo, String afflAbbr) {
        return commonMapper.selectDealNo(numNo, afflAbbr);
    }

    public int fnCalculateGridTotal(int gridSize, int gridRecords) {
        int gridTotal = 0;
        if (gridSize > 0) {
            if (gridRecords % gridSize == 0) {
                gridTotal = gridRecords / gridSize;
            } else {
                gridTotal = (gridRecords / gridSize) + 1;
            }
        }
        return gridTotal;
    }

    public int fnCalculateGridFirst(int gridPage, int gridSize) {
        int gridFirst = 0;
        if (gridPage == 0) {gridPage = 1;}
        gridFirst = (gridPage - 1) * gridSize;
        return gridFirst;
    }
}
