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.bean.so.content.ContentDocumentSO;
import com.skr.mdm.service.CmdHandlerService;
import com.skr.mdm.service.StrategyFactory;
import io.swagger.annotations.*;
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;

/**
 * @author nfq
 * @date 2020/8/11 16:54
 */
@RestController
@RequestMapping("document")
@Api(tags = "文档管理")
public class DocumentManageController {

    @PostMapping("callback")
    @ApiOperation("文档下发回调")
    @ApiResponses({
            @ApiResponse(code = 200, message = "成功", response = ContentDocumentSO.class)
    })
    public ResponseResult documentCallback(@RequestParam @ApiParam(value = "回调内容", required = true) String data, @ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.DOCUMENT_ISSUE);
        return strategy.cmdHandler(loginUserDTO.getId(), data);
    }
}
