package net.northking.cctp.dataPool.api.dataRule;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.exception.PlatformRuntimeException;
import net.northking.cctp.common.http.ResultWrapper;
import net.northking.cctp.dataPool.api.dataRule.service.DataRuleApiService;
import net.northking.cctp.dataPool.enums.DataPoolError;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

@RestController
@RequestMapping("/pub")
@Api(tags = "数据集管理无token请求")
public class DataRulePubCtrl {
    /**
     * 日志
     */
    private final static Logger logger = LoggerFactory.getLogger(DataRulePubCtrl.class);

    @Autowired
    private DataRuleApiService apiService;

    @ApiOperation(value = "执行计划根据规则名称取值")
    @GetMapping(value = "/dataRule/getRuleDataByName")
    public ResultWrapper<String> getRuleDataByName(@RequestParam String ruleName,@RequestParam String proId) throws Exception
    {
        if (StringUtils.isBlank(ruleName) || StringUtils.isBlank(proId)) {
            throw new PlatformRuntimeException(DataPoolError.PARAM_IS_MISSING);
        }
        ResultWrapper<String> wrapper = new ResultWrapper<>();
        String decodeRuleName = URLDecoder.decode(ruleName, StandardCharsets.UTF_8.name());
        String result = apiService.getRuleDataByName(decodeRuleName,proId);
        return wrapper.success(result);
    }
}
