package com.shkj.wcs.third.rcs;

public class CounterService {
    private static int i = 200000; // 2楼
    private static int j = 300000; // 3楼

    public static synchronized int incrementAndGet(int code) {
        if (code == 2) {
            return handleIncrement(i, 200000);
        } else if (code == 3) {
            return handleIncrement(j, 300000);
        } else {
            throw new IllegalArgumentException("Invalid code: " + code + "楼层错误");
        }
    }

    private static int handleIncrement(int current, int base) {
        int next = current + 1;
        int lastThreeDigits = next % 1000;

        if (lastThreeDigits > 500) {
            next = base + 1;
        }

        // 更新对应的计数器
        if (base == 200000) {
            i = next;
        } else {
            j = next;
        }

        return next;
    }

    public static void main(String[] args) {
        String toSide = "SC-G3-00-00-2001";
        String substring = toSide.substring(4, 5);
        int number = Integer.parseInt(substring);
        int carrierCode = 0;
        if(number ==2){
            carrierCode = incrementAndGet(2);
        }else if(number ==3){
            carrierCode = incrementAndGet(3);
        }
        System.out.println(carrierCode);
    }
}
