package com.goldenwater.web.controller.efinder;

import com.goldenwater.slgc.entity.efinder.DocFolder;
import com.goldenwater.slgc.service.efinder.IDocFolderService;
import com.goldenwater.common.core.controller.BaseController;
import com.goldenwater.common.core.domain.AjaxResult;
import com.goldenwater.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.goldenwater.common.annotation.Log;
import com.goldenwater.common.enums.BusinessType;
import org.springframework.validation.annotation.Validated;

import java.util.List;
import java.util.Map;

@RestController
@Validated
@RequestMapping("/efinder/folder")
public class DocFolderController extends BaseController {
    @Autowired
    private IDocFolderService docFolderService;

    /**
     * 查询文件夹列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DocFolder docFolder) {
        startPage();
        List<DocFolder> list = docFolderService.selectList(docFolder);
        return getDataTable(list);
    }

    /**
     * 获取文件夹详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(docFolderService.selectById(id));
    }

    /**
     * 查询文件夹树
     */
    @GetMapping("/tree")
    public AjaxResult tree() {
        return success(docFolderService.selectList(new DocFolder()));
    }

    /**
     * 新增文件夹
     */
    @Log(title = "文件夹管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DocFolder docFolder) {
        return toAjax(docFolderService.insert(docFolder));
    }

    /**
     * 修改文件夹
     */
    @Log(title = "文件夹管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DocFolder docFolder) {
        return toAjax(docFolderService.update(docFolder));
    }

    /**
     * 删除文件夹
     */
    @Log(title = "文件夹管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(docFolderService.deleteByIds(ids));
    }

    /**
     * 查询文件夹计划进度值
     */
    @GetMapping("/planValue/{id}")
    public AjaxResult getPlanValue(@PathVariable Long id) {
        return success(docFolderService.selectPlanValue(id));
    }

    /**
     * 更新文件夹计划进度值
     */
    @Log(title = "文件夹管理", businessType = BusinessType.UPDATE)
    @PutMapping("/planValue")
    public AjaxResult updatePlanValue(@RequestBody Map<String, Object> params) {
        Long id = Long.valueOf(params.get("id").toString());
        Integer planValue = Integer.valueOf(params.get("planValue").toString());
        return toAjax(docFolderService.updatePlanValue(id, planValue));
    }

    /**
     * 按顺序查询文件夹列表
     */
    @GetMapping("/list/orderBySeq")
    public AjaxResult listOrderBySeq(@RequestParam Long pid) {
        return success(docFolderService.selectByParentIdOrderBySeq(pid));
    }

    /**
     * 按文件夹ID查询
     */
    @GetMapping("/list/orderFdId")
    public AjaxResult listOrderByFdId(@RequestParam Long pid) {
        return success(docFolderService.selectByParentIdOrderBySeq(pid));
    }

    /**
     * 直管工程文件夹列表
     */
    @GetMapping("/list/zggc")
    public AjaxResult listZggc(@RequestParam Long pid) {
        return success(docFolderService.selectByParentIdOrderBySeq(pid));
    }
}
