package com.xhpc.general.service;

import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * program: ruoyi
 * User: HongYun
 * Date:2021-08-12 14
 */
@Service
public class XhpcServiceDataUpdateServiceImpl implements IXhpcServiceDataUpdateService{

    @Autowired
    private RedisService redisService;
    @Override
    public Map<String, Object> list() {

        Map<String,Object> list=new HashMap<>();
        String cacheSOC = redisService.getCacheObject("global:SOC");
        String cacheVersion = redisService.getCacheObject("global:version");
        String cachePhone = redisService.getCacheObject("global:phone");
        String cacheAliyunMessageCount = redisService.getCacheObject("global:AliyunMessageCount");
        list.put("SOC",cacheSOC);
        list.put("version",cacheVersion);
        list.put("phone", cachePhone);
        list.put("AliyunMessageCount", cacheAliyunMessageCount);
        return list;
    }


    @Override
    public AjaxResult update(String SOC, String version, String phone, String aliyunMessageCount) {

        if (SOC != null) {
            int soc = Integer.parseInt(SOC);
            if (!(soc >= 1 && soc <= 100)) {
                return AjaxResult.error("范围应为[1-100]");
            }
        }
        if (phone != null) {
            if (phone.length() > 20) {
                return AjaxResult.error("号码格式错误");
            }
        }
        if (aliyunMessageCount == null && "".equals(aliyunMessageCount)) {
            return AjaxResult.error("短信条数为空");
        }

        redisService.setCacheObject("global:SOC", SOC);
        redisService.setCacheObject("global:version", version);
        redisService.setCacheObject("global:phone", phone);
        redisService.setCacheObject("global:AliyunMessageCount", aliyunMessageCount);


        return AjaxResult.success();
    }
}
