package com.sckw.system.controller;

import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.system.model.KwsMenu;
import com.sckw.system.model.vo.req.*;
import com.sckw.system.service.KwsMenuService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 菜单
 * @author zk
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/kwsMenu")
public class KwsMenuController {

    @Autowired
    private KwsMenuService kwsMenuService;

    /**
     * @param id 主键ID
     * @return KwsMenu
     * @desc 根据主键查询
     * @author zk
     * @date 2023/5/30
     **/
    @GetMapping("/detail")
    public HttpResult selectByKey(@RequestParam("id") Long id) {
        return HttpResult.ok(kwsMenuService.selectByKey(id));
    }

    /**
     * @param reqVo 分页查询
     * @return KwsMenuResVo
     * @desc 分页查询
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/findMenuTree")
    public HttpResult findTree(@RequestBody FindMenuTreeReqVo reqVo) {
        return HttpResult.ok(kwsMenuService.findTree(reqVo));
    }

    /**
     * @param params {clientType:终端类型、parentId：父级id、name：菜单名称、url：跳转地址、perms：权限标识、
     *               type：类型:0目录/1菜单/2按钮、icon：图标、sort：排序、level：层级、custom：是否定制、
     *               isMain：是否主账号、usingRoles：适用企业类型（1供应商，2采购商，34PL物流，43PL物流）}
     * @return
     * @description 新增
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/add")
    public HttpResult add(@Valid @RequestBody KwsMenu params) {
        kwsMenuService.add(params);
        return HttpResult.ok(HttpStatus.MSG_003);
    }

    /**
     * @param params {id：主键，clientType:终端类型、parentId：父级id、name：菜单名称、url：跳转地址、perms：权限标识、
     *               type：类型:0目录/1菜单/2按钮、icon：图标、sort：排序、level：层级、custom：是否定制、
     *               isMain：是否主账号、usingRoles：适用企业类型（1供应商，2采购商，34PL物流，43PL物流）}
     * @desc 更新
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/update")
    public HttpResult update(@Valid @RequestBody KwsMenu params) {
        kwsMenuService.update(params);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    /**
     * @param ids {ids：主键ID（多个以逗号隔开）}
     * @return
     * @description 更新
     * @author zk
     * @date 2023/5/30
     **/
    @PostMapping("/dels")
    public HttpResult del(@Valid @RequestBody DelsMenuReqVo ids) {
        kwsMenuService.deleteByKey(ids.getIds());
        return HttpResult.ok(HttpStatus.MSG_008);
    }

    /**
     * @param  reqVo 菜单ID多个用","隔开
     * @return HttpResult
     * @desc: 角色分配菜单
     * @author: czh
     * @date: 2023/6/13
     */
    @PostMapping("/roleBindMeun")
    public HttpResult roleBindMenu(@Valid @RequestBody RoleBindMenuReqVo reqVo) {
        kwsMenuService.roleBindMenu(reqVo);
        return HttpResult.ok(HttpStatus.MSG_010);
    }

    /**
     * @param  reqVo 入参
     * @return HttpResult
     * @desc: 移动菜单
     * @author: czh
     * @date: 2023/6/13
     */
    @PostMapping("/moveMenu")
    public HttpResult moveMenu(@Valid @RequestBody MoveMenuReqVo reqVo) {
        kwsMenuService.moveMenu(reqVo);
        return HttpResult.ok(HttpStatus.MSG_005);
    }

    /**
     * @param  reqVo 入参
     * @return HttpResult
     * @desc: 查子菜单
     * @author: czh
     * @date: 2023/6/13
     */
    @PostMapping("/queryChildMenu")
    public HttpResult queryChildMenu(@Valid @RequestBody QueryChildMenuReqVo reqVo) {
        return HttpResult.ok(kwsMenuService.queryChildMenu(reqVo));
    }

    /**
     * @param  reqVo 入参
     * @return HttpResult
     * @desc: 保存映射关系
     * @author: czh
     * @date: 2023/6/13
     */
    @PostMapping("/saveMapping")
    public HttpResult saveMapping(@Valid @RequestBody SaveMappingReqVo reqVo) {
        kwsMenuService.saveMapping(reqVo);
        return HttpResult.ok();
    }

    /**
     * @param  reqVo 入参
     * @return HttpResult
     * @desc: 根据菜单查映射关系
     * @author: czh
     * @date: 2023/6/13
     */
    @PostMapping("/queryMapping")
    public HttpResult queryMapping(@Valid @RequestBody QueryMappingReqVo reqVo) {
        return HttpResult.ok(kwsMenuService.queryMapping(reqVo.getMenuId()));
    }

    @GetMapping("/test")
    public HttpResult test(@RequestParam String ids) {
        return HttpResult.ok(kwsMenuService.test(ids));
    }


}
