package com.skr.mdm.controller;

import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dto.LoginUserDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import com.skr.mdm.service.StrategyFactory;
import com.skr.mdm.service.impl.certificate.SysChangeCertificateImpl;
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.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;


/**
 * @ProjectName: mdm_new
 * @Package: com.skr.mdm.controller
 * @ClassName: FileAccessController
 * @Author: Tty
 * @Description: z
 * @Date: 2021/3/10 10:35
 * @Version: 1.0
 */
@RestController
@RequestMapping("sysChangeCertificate")
@Api(tags = "服务器变更")
public class SysChangeCertificateController {

    @Autowired
    private SysChangeCertificateImpl sysChangeCertificate;

    @PostMapping("upload")
    @ApiOperation("服务器变更上传")
    public ResponseResult upload(@RequestParam @ApiParam(value = "回调信息", required = true) String data,
                                 @ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.SYS_CHANGE_CERTIFICATE);
        return strategy.cmdHandler(loginUserDTO.getId(), data);
    }

    @PostMapping("checkMsg")
    @ApiOperation("校验服务器信息")
    public ResponseResult checkMsg(@RequestParam @ApiParam(value = "校验数据信息", required = true) String data,
                                   @ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        return sysChangeCertificate.changeCertificateCheck(loginUserDTO.getId(), data);
    }

}
