package com.yh.saas.plugin.clouddisk.controller;

import com.winsea.svc.base.security.util.AuthSecurityUtils;
import com.yh.saas.common.support.plugin.PluginFeature;
import com.yh.saas.common.support.util.StringUtils;
import com.yh.saas.plugin.clouddisk.entity.DataManagerFolder;
import com.yh.saas.plugin.clouddisk.entity.DataManagerFolderFileView;
import com.yh.saas.plugin.clouddisk.service.IDataManagerFolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 资料管理 - Controller
 * </p>
 *
 * @author ZhangMingYu
 * @since 2019年11月4日15:52:09
 */
@RestController
@RequestMapping("/dataManagerFolder")
public class DataManagerFolderController {

    @Autowired
    private IDataManagerFolderService dataManagerFolderService;

    /**
     * 查询 - 文件夹(树形结构)
     *
     * @param dataManagerFolder compId 必传
     * @return 返回树形结构
     */
    @GetMapping("/query/findTreeList")
    @PluginFeature(id = "DataManager-Review", name = "资料管理_查看")
    public List<DataManagerFolder> findTreeList(DataManagerFolder dataManagerFolder) {
        if (StringUtils.isEmpty(dataManagerFolder.getCompId())) {
            dataManagerFolder.setCompId(AuthSecurityUtils.getCurrentUserInfo().getCompId());
        }
        return dataManagerFolderService.findTreeList(dataManagerFolder);
    }

    /**
     * 查询 - 文件夹详情
     *
     * @return 返回树形结构
     */
    @GetMapping("/query/getDataManagerFolderList")
    public List<DataManagerFolder> getDataManagerFolderDetail(String parentFolderId,String fileName,String orderColumn,String orderBy) {
        return dataManagerFolderService.getDataManagerFolderList(parentFolderId,fileName,orderColumn,orderBy);
    }

    /**
     * 新增 - 文件夹
     *
     * @param dataManagerFolder 新增文件夹
     */
    @PostMapping("/api/saveInfo")
    @PluginFeature(id = "DataManager-Manage", name = "资料管理_管理")
    public void saveInfo(@RequestBody DataManagerFolder dataManagerFolder) {
        if (StringUtils.isEmpty(dataManagerFolder.getCompId())) {
            dataManagerFolder.setCompId(AuthSecurityUtils.getCurrentUserInfo().getCompId());
        }
        dataManagerFolderService.save(dataManagerFolder);
    }

    /**
     * 修改 - 文件夹
     *
     * @param dataManagerFolder 文件夹对象
     */
    @PostMapping("/api/changeInfo")
    @PluginFeature(id = "DataManager-Manage", name = "资料管理_管理")
    public void changeInfo(@RequestBody DataManagerFolder dataManagerFolder) {
        dataManagerFolderService.changeInfo(dataManagerFolder);
    }

    /**
     * 删除 - 文件夹
     *
     * @param dataManagerFolder 文件夹对象
     */
    @PostMapping("/api/remove")
    @PluginFeature(id = "DataManager-Manage", name = "资料管理_管理")
    public void remove(@RequestBody DataManagerFolder dataManagerFolder) {
        dataManagerFolderService.remove(dataManagerFolder);
    }

    /**
     * 删除 - 文件夹和文件
     *
     * @param list 文件夹文件对象
     */
    @PostMapping("/api/removeFolderFile")
    public void removeFolderFile(@RequestBody List<DataManagerFolderFileView> list) {
        dataManagerFolderService.removeFolderFile(list);
    }

    /**
     * 移动文件夹
     *
     * @param list 父节点id
     */
    @PostMapping("/api/moveFolder")
    public void moveFolder(@RequestBody List<DataManagerFolderFileView> list) {
        dataManagerFolderService.moveFolder(list);
    }


}
