package com.css.simulation.resource.common.app.algorithm;

import api.common.pojo.common.ResponseBodyVO;
import com.css.simulation.resource.common.infra.acl.algorithm.AlgorithmExpandAcl;
import com.css.simulation.resource.common.domain.service.algorithm.AlgorithmExpandDomainService;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;

@Service
public class AlgorithmExpandApplication {

    @Resource
    private AlgorithmExpandAcl algorithmExpandAcl;

    @Resource
    private AlgorithmExpandDomainService algorithmExpandDomainService;

    /**
     * String urlParam = "";
     * if (StringUtil.isNotEmpty(algorithmId)) {
     * urlParam = urlParam + "&algorithmId=" + algorithmId;
     * }
     * if (StringUtil.isNotEmpty(algorithmName)) {
     * urlParam = urlParam + "&algorithmName=" + algorithmName;
     * }
     * if (StringUtil.isNotEmpty(description)) {
     * urlParam = urlParam + "&description=" + description;
     * }
     * if (StringUtil.isNotEmpty(page)) {
     * urlParam = urlParam + "&page=" + page;
     * }
     * if (StringUtil.isNotEmpty(size)) {
     * urlParam = urlParam + "&size=" + size;
     * }
     * urlParam = urlParam + "&sort=" + sort;
     *
     * @param param 参数
     * @return 结果
     */
    public ResponseBodyVO<String> getAlgorithmList(@RequestBody String param) {
        //1 获取第三方算法平台列表
        final ResponseBodyVO<String> algorithmList = algorithmExpandAcl.getAlgorithmList(param);
        //2 检查仿真平台数据库中是否有该算法，没有则添加，同时设置状态为”未测试“
        algorithmExpandDomainService.checkIsExisted(algorithmList);
        return algorithmList;
    }

    @SneakyThrows
    public ResponseBodyVO<String> selectAlgorithmNameByAlgorithmId(@RequestBody String algorithmId) {
        return algorithmExpandAcl.selectAlgorithmNameByAlgorithmId(algorithmId);
    }

    public void download(String algorithmId) {
        algorithmExpandAcl.download(algorithmId);
    }
}
