package com.xiang.xservice;

import com.xiang.xservice.basic.common.resp.Result;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xiang
 * @Date: 2025-05-13 10:08
 */
@RestController
@RequestMapping("/system/demo")
@RequiredArgsConstructor
public class IndexController {

    private final RedisTemplate<String, String> redisTemplate;

    @Value("${spring.profiles.active}")
    private String env;

    @Value("${server.port}")
    private String port;

    @Value("${spring.datasource.dynamic.datasource.master.url}")
    private String url;

    @GetMapping("/index")
    public Result<String> index() {
        String  msg = "已激活环境：" + env + "，web端口启用：" + port + "使用datasource:" + url;
        return Result.success(msg);
    }

    @GetMapping("/redisTest")
    private Result<String> redisTest() {
        redisTemplate.opsForValue().set("2222", "231");

        return Result.success("redis获取到key为test的值为：" + redisTemplate.opsForValue().get("2222"));
    }
}
