package com.bocloud.ims.booter.controller.upgrade;

import com.alibaba.fastjson.JSONObject;
import com.bocloud.common.model.BocloudResult;
import com.bocloud.common.model.RequestContext;
import com.bocloud.common.utils.Common;
import com.bocloud.ims.service.upgrade.UpgradeService;
import com.bocloud.ims.service.upgrade.UpgradeVersion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * 系统升级
 * @author luyanchao
 * @date 2021-06-09
 */
@RestController
@RequestMapping("/v1/upgrade")
@Api(value = "系统升级", tags = "系统升级")
public class UpgradeController {

    @Autowired
    private UpgradeService upgradeService;

    /**
     * 数据迁移，5.0到5.5
     *
     * @param host
     * @param port
     * @param user
     * @param pass
     * @param database
     * @return
     */
    @ApiOperation(tags = {"CMC"}, value = "数据迁移")
    @PostMapping("/migration/{version}")
    public BocloudResult<?> dataMigration(
            @PathVariable(value = "version") String version,
            @RequestParam(value = "host") String host,
            @RequestParam(value = "port") Integer port,
            @RequestParam(value = "user") String user,
            @RequestParam(value = "pass") String pass,
            @RequestParam(value = "database") String database,
            @Value(Common.REQ_CONTEXT) RequestContext context) {
        return upgradeService.dataMigration(host, port, user, pass, database, UpgradeVersion.valueOf(version), context);
    }

}
