package com.crm.manager.controller;

import com.crm.manager.service.CommonService;
import com.crm.manager.service.CustomFileFeignService;
import com.crm.rely.backend.core.constant.Constants;
import com.crm.rely.backend.core.dto.base.BaseResultDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @description: 客户文件控制器
 * @author: houn
 * @create: 2020-06-13 17:58
 **/
@RestController
@RequestMapping("/custom/file")
public class CustomFileController {

    @Autowired
    private CustomFileFeignService customFileFeignService;

    @Autowired
    private CommonService commonService;

    @PostMapping("/upload/{customId}/{type}")
    public BaseResultDto mangerUpload(@RequestParam(value = "file", required = false) MultipartFile file, @PathVariable("customId") Long customId, @PathVariable("type") Integer type) throws Exception {

        return customFileFeignService.mangerUpload(file, customId, type);
    }

    @PostMapping("/upload/{customId}/{type}/{id}")
    public BaseResultDto mangerUpload(@RequestParam(value = "file", required = false) MultipartFile file, @PathVariable("customId") Long customId, @PathVariable("type") Integer type, @PathVariable("id") Long id) throws Exception {

        return customFileFeignService.mangerUpload(file, customId, type, id);
    }

    @PostMapping("/bank/upload/{customId}")
    public BaseResultDto upload(@RequestParam(value = "file", required = false) MultipartFile file, @PathVariable("customId") Long customId) throws Exception {

        commonService.validated(file);
        String middlePath = "/bank/"+customId;
        String path = commonService.uploadFile(middlePath, file);
        return BaseResultDto.success(Constants.UPLOAD_SUCCESS, path);
    }
}
