package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.Result;
import com.crunii.micro.domain.dto.Worker;
import com.crunii.micro.service.sysmgr.dto.sysmgr.MenuShortcutTreeVO;
import com.crunii.micro.service.sysmgr.dto.sysmgr.MenuShortcutVO;
import com.crunii.micro.service.sysmgr.service.YcqMenuShortcutService;
import com.crunii.micro.web.mvc.CurrWorker;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;

/**
 * 快捷服务
 * @author 15294
 */
@Api(value = "快捷菜单")
@Slf4j
@RestController
@RequestMapping("/auth/YcqMenuShortcutController")
public class YcqMenuShortcutController {


    @Resource
    private YcqMenuShortcutService service;


    /**
     * 查询未选择快捷菜单(两级)
     * @param worker
     * @return
     */
    @GetMapping("/queryUnselectedMenu")
    public Result<List<MenuShortcutTreeVO>> queryUnselectedMenu(@CurrWorker @ApiIgnore Worker worker){

        return Result.ofSuccess(service.queryUnselectedMenu(worker.getLoginId()));
    }


    /**
     * 查询已选择的快捷菜单(两级)
     * @param worker
     * @return
     */
    @GetMapping("/querySelectedMenu")
    public Result<List<MenuShortcutTreeVO>> querySelectedMenu(@CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(service.querySelectedMenu(worker.getLoginId()));
    }

    /**
     * 新增快捷菜单
     * @param dto
     * @param worker
     * @return
     */
    @PostMapping("/insertBatch")
    public Result<Boolean> insertBatch(@RequestBody List<String> menuCodeList, @CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(service.insertBatch(menuCodeList, worker.getLoginId()));
    }

    /**
     * 根据id删除菜单
     * @param id
     * @param worker
     * @return
     */
    @PostMapping("/deleteBatch")
    public Result<Boolean> deleteBatch(@RequestBody List<String> menucodeList, @CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(service.deleteBatch(menucodeList, worker.getLoginId()));
    }


    /**
     * 查询已选择的快捷菜单（平铺）
     * @param worker
     * @return
     */
    @GetMapping("/querySelectedMenuList")
    public Result<List<MenuShortcutVO>> querySelectedMenuList(@CurrWorker @ApiIgnore Worker worker){
        return Result.ofSuccess(service.querySelectedMenuList(worker.getLoginId()));
    }
}
