package com.skr.mdm.controller;

import com.skr.mdm.dto.LoginUserDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.impl.content.ClientFileServiceImpl;
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 org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @ProjectName: mdm_new
 * @Package: com.skr.mdm.controller
 * @ClassName: FileAccessController
 * @Author: Tty
 * @Description: 客户端文件上传信息
 * @Date: 2021/2/26 15:02
 * @Version: 1.0
 */
@RestController
@RequestMapping("client/file")
@Api(tags = "客户端文件信息上报")
public class FileAccessController {

    @Autowired
    private ClientFileServiceImpl clientFileService;

    @PostMapping("information")
    @ApiOperation("文件层级信息")
    public ResponseResult information(@RequestParam @ApiParam(value = "上传文件信息", required = true) String data,
                                      @ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        return clientFileService.cmdHandler(loginUserDTO, data);
    }

    @PostMapping("upload")
    @ApiOperation("文件信息上传")
    public ResponseResult upload(@ApiParam(value = "批量文件信息", required = true) MultipartFile file,
                                 @ApiIgnore Authentication authentication) {
        // 上传文件
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        return clientFileService.upload(file, loginUserDTO);
    }
}
