package shop.alien.store.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperationSupport;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import shop.alien.entity.result.R;
import shop.alien.util.common.CommendUtil;

/**
 * @author ssk
 * @version 1.0
 * @date 2025/6/11 13:08
 */
@Slf4j
@Api(tags = {"测试打包信息"})
@CrossOrigin
@RestController
@RequestMapping("/testInfo")
@RequiredArgsConstructor
public class TestInfoController {

    @Value("${spring.datasource.druid.url:180.0}")
    private String databasesUrl;

    @Value("${spring.redis.host:77}")
    private String redisHost;

    @Value("${spring.redis.port:3305}")
    private String redisPort;

    @Value("${spring.redis.database:q}")
    private String redisDatabase;

    @ApiOperation("获取测试打包信息")
    @ApiOperationSupport(order = 1)
    @GetMapping(value = "/getTestInfo")
    public R<JSONObject> getTestInfo() {
        JSONObject jsonObject = new JSONObject();
        String commendInfo = CommendUtil.getCommendInfo("E:\\alien\\GitCommitVersion.bat");
        String[] split = commendInfo.split(",");
        String lastLine = split[split.length - 1];
        jsonObject.put("gitVersion", lastLine);
        jsonObject.put("databasesUrl", databasesUrl);
        jsonObject.put("redisHost", redisHost);
        jsonObject.put("redisPort", redisPort);
        jsonObject.put("redisDatabase", redisDatabase);
        return R.data(jsonObject);
    }

}
