package com.fdkankan.platform.goods.controller.manager;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fdkankan.common.controller.BaseController;
import com.fdkankan.common.exception.BusinessException;
import com.fdkankan.platform.order.entity.SpaceSdk;
import com.fdkankan.platform.order.service.ISpaceSdkService;
import com.fdkankan.platform.user.request.RequestSdkVersion;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 后台管理-sdk上传下载
 */
@Log4j2
@RestController
@RequestMapping("/service/platform/manager/sdk")
public class ManagerSdkController extends BaseController {

    @Autowired
    private ISpaceSdkService spaceSdkService;


    /**
     * 上传文件
     * @param file
     * @param version
     * @param imprintCh
     * @param imprintEn
     * @param isTop
     * @param platformType
     */
    @PostMapping(value = "/upload", consumes = { "multipart/form-data" })
    private String upload(@RequestParam("file") MultipartFile file,
                          @RequestParam("version") String version,
                          @RequestParam("imprintCh") String imprintCh,
                          @RequestParam("imprintEn") String imprintEn,
                          @RequestParam("isTop") Integer isTop,
                          @RequestParam("platformType") String platformType) {

        try {
            return spaceSdkService.upload(file, version,imprintCh,imprintEn,isTop,platformType);
        }catch (Exception e){
            throw new BusinessException(-1,"上传失败！");
        }
    }

    /**
     * 查询列表
     * @return
     */
    @PostMapping(value = "/list")
    private Page<SpaceSdk> list(@RequestBody RequestSdkVersion param) {
        return spaceSdkService.getPageByParam(param);
    }

    /**
     * 编辑
     */
    @PostMapping(value = "/update")
    private String update(@RequestBody SpaceSdk param) {
        return  spaceSdkService.updateByEntity(param);
    }

    /**
     * 删除
     */
    @PostMapping(value = "/del")
    private String del(@RequestBody RequestSdkVersion param) {
        return  spaceSdkService.delById(param.getId());
    }

    /**
     * 上下架
     */
    @PostMapping(value = "/online")
    private String online(@RequestBody RequestSdkVersion param) {
        return  spaceSdkService.online(param);
    }

    /**
     * 置顶
     */
    @PostMapping(value = "/top")
    private String top(@RequestBody RequestSdkVersion param) {
        return  spaceSdkService.online(param);
    }

}
