package com.xjrsoft.module.system.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjrsoft.common.constant.GlobalConstant;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.xjrsoft.common.page.ConventPage;
import com.xjrsoft.common.page.PageOutput;
import com.xjrsoft.common.model.result.RT;
import com.xjrsoft.common.utils.VoToColumnUtil;
import com.xjrsoft.module.evaluate.vo.EvaluateTemplatePageVo;
import com.xjrsoft.module.system.dto.AddXjrMenuDeptRelationDto;
import com.xjrsoft.module.system.dto.UpdateXjrMenuDeptRelationDto;
import cn.dev33.satoken.annotation.SaCheckPermission;

import com.xjrsoft.module.system.dto.XjrMenuDeptRelationPageDto;
import com.xjrsoft.module.system.entity.XjrMenuDeptRelation;
import com.xjrsoft.module.system.service.IXjrMenuDeptRelationService;
import com.xjrsoft.module.system.vo.XjrMenuDeptRelationPageVo;

import com.xjrsoft.module.system.vo.XjrMenuDeptRelationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
* @title: 菜单部门关联表
* @Author brealinxx
* @Date: 2024-04-09
* @Version 1.0
*/
@RestController
@RequestMapping("/system" + "/xjrMenuDeptRelation")
@Api(value = "/system"  + "/xjrMenuDeptRelation",tags = "菜单部门关联表代码")
@AllArgsConstructor
public class XjrMenuDeptRelationController {


    private final IXjrMenuDeptRelationService xjrMenuDeptRelationService;

    @GetMapping(value = "/page")
    @ApiOperation(value="菜单部门关联表列表(分页)")
    @SaCheckPermission("xjrmenudeptrelation:detail")
    public RT<PageOutput<XjrMenuDeptRelationPageVo>> page(@Valid XjrMenuDeptRelationPageDto dto){
        Page<XjrMenuDeptRelationPageVo> page = xjrMenuDeptRelationService.getPage(new Page<>(dto.getLimit(), dto.getSize()), dto);
        PageOutput<XjrMenuDeptRelationPageVo> pageOutput = ConventPage.getPageOutput(page, XjrMenuDeptRelationPageVo.class);
        return RT.ok(pageOutput);
    }

    @GetMapping(value = "/info")
    @ApiOperation(value="根据id查询菜单部门关联表信息")
    @SaCheckPermission("xjrmenudeptrelation:detail")
    public RT<XjrMenuDeptRelationVo> info(@RequestParam Long id){
        XjrMenuDeptRelation xjrMenuDeptRelation = xjrMenuDeptRelationService.getById(id);
        if (xjrMenuDeptRelation == null) {
           return RT.error("找不到此数据！");
        }
        return RT.ok(BeanUtil.toBean(xjrMenuDeptRelation, XjrMenuDeptRelationVo.class));
    }


    @PostMapping
    @ApiOperation(value = "新增菜单部门关联表")
    @SaCheckPermission("xjrmenudeptrelation:add")
    public RT<Boolean> add(@Valid @RequestBody AddXjrMenuDeptRelationDto dto){
        XjrMenuDeptRelation xjrMenuDeptRelation = BeanUtil.toBean(dto, XjrMenuDeptRelation.class);
        boolean isSuccess = xjrMenuDeptRelationService.save(xjrMenuDeptRelation);
        return RT.ok(isSuccess);
    }

    @PutMapping
    @ApiOperation(value = "修改菜单部门关联表")
    @SaCheckPermission("xjrmenudeptrelation:edit")
    public RT<Boolean> update(@Valid @RequestBody UpdateXjrMenuDeptRelationDto dto){

        XjrMenuDeptRelation xjrMenuDeptRelation = BeanUtil.toBean(dto, XjrMenuDeptRelation.class);
        return RT.ok(xjrMenuDeptRelationService.updateById(xjrMenuDeptRelation));

    }

    @DeleteMapping
    @ApiOperation(value = "删除菜单部门关联表")
    @SaCheckPermission("xjrmenudeptrelation:delete")
    public RT<Boolean> delete(@Valid @RequestBody List<Long> ids){
        return RT.ok(xjrMenuDeptRelationService.removeBatchByIds(ids));

    }

}