package com.xhkjedu.sapi.controller.component;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.service.component.UserComponentService;
import com.xhkjedu.sapi.vo.component.ComponentParams;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description：用户组件
 * @Author: WN
 * @Date: 2024/7/19 15:14:51
 **/
@RestController
@RequestMapping("/zj")
public class UserComponentController {
    @Resource
    private UserComponentService userComponentService;


    /*
     * @Description 保存组件
     * @Date 2024/7/19 15:19:41
     * @Author WN
     * @Param [componentParams]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/save")
    @Action("用户组件-增加")
    public ResultVo save(@RequestBody ComponentParams componentParams) {
        N_Utils.validation(new Object[]{componentParams.getUserid(),"用户ID",1});
        userComponentService.save(componentParams);
        return new ResultVo(0, "保存成功");
    }

    /*
     * @Description 用户组件集合
     * @Date 2024/7/19 15:21:27
     * @Author WN
     * @Param [componentParams]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_user")
    public ResultVo listComponentsByUserid(@RequestBody ComponentParams componentParams) {
        Integer userid = componentParams.getUserid();
        N_Utils.validation(new Object[]{userid,"用户ID",1});
        return new ResultVo(0, "获取成功", userComponentService.listComponentsByUserid(userid));
    }

    /*
     * @Description 获取用户角色权限模块（匹配组件）
     * @Date 2024/7/26 15:08:01
     * @Author WN
     * @Param [componentParams]
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @PostMapping("/list_module")
    public ResultVo listUserRoleModule(@RequestBody ComponentParams componentParams) {
        Integer userid = componentParams.getUserid();
        N_Utils.validation(new Object[]{userid,"用户ID",1});
        return new ResultVo(0, "获取成功", userComponentService.listUserRoleModule(userid));
    }

    /*
     * @Description 初始化用户组件
     * @Date 2024/7/31 17:12:26
     * @Author WN
     * @Param []
     * @Return com.xhkjedu.vo.ResultVo
     **/
    @GetMapping("/init")
    public ResultVo initUserComponent() {
        userComponentService.initAllUserComponent();
        return new ResultVo(0, "初始化用户组件成功");
    }
}
