package net.northking.cctp.project.api.env;

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.project.api.software.service.CpProjectSoftwareApiService;
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;

@Api(tags = "系统环境同步")
@RequestMapping("/pub/cpProjectEnvAndSoft")
@RestController
public class CpProjectEnvPubCtrl {
    private final static Logger logger = LoggerFactory.getLogger(CpProjectEnvPubCtrl.class);

    @Autowired
    private CpProjectSoftwareApiService cpProjectSoftwareApiService;

    @ApiOperation("monster同步接口")
    @GetMapping("/addProjectEnvAndSoft")
    public ResultWrapper addProjectEnvAndSoft(@RequestParam(name = "projectId") String projectId,@RequestParam(name = "operateType")String operateType){
        ResultWrapper resultWrapper = new ResultWrapper();
        try {
            cpProjectSoftwareApiService.addProjectSoftware(projectId,operateType);
        } catch (PlatformRuntimeException e){
            logger.error("系统环境或软件信息保存失败，系统id,{}",projectId);
            return resultWrapper.fail(e.getError());
        } catch (Exception e){
            logger.error("系统环境或软件信息保存失败，系统id,{}",projectId);
            throw e;
        }
        return resultWrapper.success();
    }
}
