package com.fufan.mtsaas.util;

import com.fufan.mtsaas.constant.RedisKeyConstant;
import com.fufan.mtsaas.constant.RedisKeyConstant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisUtil {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    public String getOrderPrintRedisConstant(String companyId,String userId){
       return RedisKeyConstant.ORDER_PRINT_AMOUNT + companyId + ":";
    }

    public String getOrderPrintedRedisConstant(String companyId,String userId){
        return RedisKeyConstant.ORDER_PRINTED_AMOUNT + companyId + ":";
    }
    public String getOrderPrintedOneRedisConstant(String companyId,String userId,String orderId){
        return RedisKeyConstant.ORDER_PRINTED_AMOUNT_ONE + companyId + ":" + orderId + ":";
    }
    public String getOrderPrintedTwoRedisConstant(String companyId,String userId,String orderId){
        return RedisKeyConstant.ORDER_PRINTED_AMOUNT_TWO + companyId + ":" + orderId + ":";
    }
    public String getOrderPrintedThreeRedisConstant(String companyId,String userId,String orderId){
        return RedisKeyConstant.ORDER_PRINTED_AMOUNT_THREE + companyId + ":" + orderId + ":";
    }
    public Integer getOrderPrinted(String companyId,String userId,String id){
        String amount = stringRedisTemplate.opsForValue().get(getOrderPrintedRedisConstant(companyId,userId) + id);
        if(StringUtils.isEmpty(amount)){
            return 0;
        }else {
            return Integer.valueOf(amount);
        }
    }

    public Integer getOrderPrintedLevelOne(String companyId,String userId,String id){
        String amount = stringRedisTemplate.opsForValue().get(getOrderPrintedOneRedisConstant(companyId,userId,id));
        if(StringUtils.isEmpty(amount)){
            return 0;
        }else {
            return Integer.valueOf(amount);
        }
    }

    public Integer getOrderPrintedLevelTwo(String companyId,String userId,String id){
        String amount = stringRedisTemplate.opsForValue().get(getOrderPrintedTwoRedisConstant(companyId,userId,id));
        if(StringUtils.isEmpty(amount)){
            return 0;
        }else {
            return Integer.valueOf(amount);
        }
    }
    public Integer getOrderPrintedLevelThree(String companyId,String userId,String id){
        String amount = stringRedisTemplate.opsForValue().get(getOrderPrintedThreeRedisConstant(companyId,userId,id));
        if(StringUtils.isEmpty(amount)){
            return 0;
        }else {
            return Integer.valueOf(amount);
        }
    }
}
