package com.dxhy.common.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.constant.RedisConstant;
import com.dxhy.common.service.TabulateRedisService;
import com.dxhy.common.util.redis.RedisUtils;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jiaohongyang（焦红阳）
 * @date 2020-10-07
 */
@Service("tabulateRedisService")
@Slf4j
public class TabulateRedisServiceImpl implements TabulateRedisService {

    @Resource
    private RedisUtils redisUtils;

    @Override
    public JSONObject getTabulateMenu(String company, String menuId) {
        log.info("列表查询条件，集团编码：{} ， 菜单ID：{}", company, menuId);
        JSONObject jsonObject;
        String redisKey = RedisConstant.MENU_TABULATE_COMPANY + company + ":" + company + "_" + menuId;
        jsonObject = redisUtils.get(redisKey, JSONObject.class);
        if (jsonObject == null) {
            redisKey = RedisConstant.MENU_TABULATE_COMPANY + "ZXQY:ZXQY_" + menuId;
            jsonObject = redisUtils.get(redisKey, JSONObject.class);
            if (jsonObject == null) {
                jsonObject = new JSONObject();
            }
        }
        log.info("key:{}", redisKey);
        log.info("返回列表信息：{}", jsonObject);
        return jsonObject;
    }

    @Override
    public JSONObject getTabulateExcel(String company, String menuId) {
        log.info("列表查询条件，集团编码：{} ， 菜单ID：{}", company, menuId);
        JSONObject jsonObject;
        String redisKey = RedisConstant.MENU_TABULATE_EXCEL + company + ":" + company + "_" + menuId;
        jsonObject = redisUtils.get(redisKey, JSONObject.class);
        if (jsonObject == null) {
            redisKey = RedisConstant.MENU_TABULATE_EXCEL + "ZXQY:ZXQY_" + menuId;
            jsonObject = redisUtils.get(redisKey, JSONObject.class);
            if (jsonObject == null) {
                jsonObject = new JSONObject();
            }
        }
        log.info("key:{}", redisKey);

        log.info("返回导出列表信息：{}", jsonObject.toJSONString());
        return jsonObject;
    }
}
