package com.cpop.mall.business.controller.backstage;

import com.cpop.core.base.R;
import com.cpop.mall.business.bo.MallRoleBo;
import com.cpop.mall.business.bo.MallRolePageBo;
import com.cpop.mall.business.service.RoleBrandService;
import com.cpop.mall.business.vo.MallRolePageVo;
import com.cpop.system.business.bo.MenuListBo;
import com.cpop.system.business.bo.RoleStatusBo;
import com.cpop.system.business.service.MenuService;
import com.cpop.system.business.vo.MenuVo;
import com.mybatisflex.core.paginate.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author DB
 * @createTime 2023/10/19 18:14
 * @description
 */
@RestController
@Api(tags = "商城角色定制接口")
@RequestMapping("/backstage/mallRole")
public class BackstageMallRoleController {

    @Autowired
    private RoleBrandService roleBrandService;

    @Autowired
    private MenuService menuService;

    /**
     * @descriptions 查询商城角色分页列表
     * @author DB
     * @date 2023/09/10 16:51
     * @param bo 请求参数
     * @return R<PageVo<SysRolePageVo>>
     */
    @PreAuthorize("@aps.hasPermission('system:role:list')")
    @ApiOperation("查询商城角色分页列表")
    @GetMapping("/getMallRolePageList")
    public R<Page<MallRolePageVo>> getMallRolePageList(MallRolePageBo bo) {
        Page<MallRolePageVo> pageVo = roleBrandService.getMallRolePageList(bo);
        return R.ok(pageVo);
    }

    /**
     * @descriptions 新增角色
     * @author DB
     * @date 2023/10/12 10:48
     * @param bo 请求参数
     * @return: com.cpop.core.base.R<java.lang.Void>
     */
    @PreAuthorize("@aps.hasPermission('system:role:insert')")
    @ApiOperation("新增商城角色")
    @PostMapping("/insertMallRole")
    public R<Void> insertMallRole(@RequestBody @Validated MallRoleBo bo) {
        roleBrandService.insertMallRole(bo);
        return R.ok();
    }

    /**
     * @Description: 获取系统菜单树列表
     * @return: R<List<SysMenuVo>>
     * @Author: DB
     * @Date: 2023/5/10 14:39
     **/
    @ApiOperation("获取菜单树列表")
    @GetMapping("/getSysMenuTreeList")
    public R<List<MenuVo>> getSysMenuTreeList() {
        List<MenuVo> list = menuService.getSysMenuTreeList(new MenuListBo());
        //过滤掉没有权限的数据
        return R.ok(list);
    }

    /**
     * @descriptions 修改角色
     * @author DB
     * @date 2023/09/10 17:45
     * @param bo 请求参数
     * @return com.jambox.core.base.R<java.lang.Void>
     */
    @PreAuthorize("@aps.hasPermission('system:role:update')")
    @ApiOperation("修改商城角色")
    @PutMapping("/updateMallRole")
    public R<Void> updateMallRole(@RequestBody @Validated MallRoleBo bo) {
        roleBrandService.updateMallRole(bo);
        return R.ok();
    }

    /**
     * @Description: 删除商城角色
     * @param id 主键
     * @return R<Void>
     * @Author DB
     * @Date: 2023/10/19 22:34
     */
    @PreAuthorize("@aps.hasPermission('system:role:remove')")
    @ApiOperation("删除商城角色")
    @DeleteMapping("/removeMallRole/{id}")
    public R<Void> removeMallRole(@PathVariable("id") String id) {
        roleBrandService.removeMallRole(id);
        return R.ok();
    }

    /**
     * @Description: 设置角色状态
     * @param bo 请求参数
     * @return: R<Void>
     * @Author: DB
     * @Date: 2023/5/9 14:13
     **/
    @PreAuthorize("@aps.hasPermission('system:role:update')")
    @ApiOperation("设置商城角色状态")
    @PutMapping("/setMallRoleStatus")
    public R<Void> setMallRoleStatus(@RequestBody @Validated RoleStatusBo bo) {
        roleBrandService.setMallRoleStatus(bo);
        return R.ok();
    }
}
