package com.securitycontrol.system.base.controller;

import com.securitycontrol.common.core.web.controller.BaseController;
import com.securitycontrol.common.core.web.domain.AjaxResult;
import com.securitycontrol.common.core.web.page.TableDataInfo;
import com.securitycontrol.common.log.annotation.Log;
import com.securitycontrol.common.log.enums.OperationType;
import com.securitycontrol.entity.system.dto.UserDto;
import com.securitycontrol.entity.system.vo.UserVo;
import com.securitycontrol.system.base.service.IUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

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

/**
 * @author：cwchen
 * @date：2024-02-20-15:49
 * @version：1.0
 * @description：用户管理-web
 */
@RestController
@RequestMapping("/sys/user/")
public class UserController extends BaseController {

    @Resource(name = "IUserService")
    private IUserService service;

    @ApiOperation(value = "获取用户列表")
    @GetMapping("getUserLists")
    @Log(title = "系统管理", menu = "系统管理->用户管理", grade = OperationType.QUERY_SYS, details = "查询用户", type = "系统日志")
    public TableDataInfo getUserLists(UserDto dto) {
        startPage();
        List<UserVo> list = service.getUserLists(dto);
        return getDataTable(list);
    }

    @ApiOperation(value = "新增用户")
    @PostMapping("addUser")
    @Log(title = "系统管理", menu = "系统管理->用户管理", grade = OperationType.ADD_SYS, details = "新增用户", type = "系统日志")
    public AjaxResult addUser(@RequestBody UserVo vo) {
        return service.addOrUpdateUser(vo);
    }

    @ApiOperation(value = "修改用户")
    @PostMapping("editUser")
    @Log(title = "系统管理", menu = "系统管理->用户管理", grade = OperationType.UPDATE_SYS, details = "修改用户", type = "系统日志")
    public AjaxResult editUser(@RequestBody UserVo vo) {
        return service.addOrUpdateUser(vo);
    }

    @ApiOperation(value = "用户详情")
    @GetMapping("getUserById")
    public AjaxResult getUserById(UserDto dto) {
        return service.getUserById(dto);
    }

    @ApiOperation(value = "删除用户")
    @PostMapping("delUser")
    @Log(title = "系统管理", menu = "系统管理->用户管理", grade = OperationType.DELETE_SYS, details = "删除用户", type = "系统日志")
    public AjaxResult delUser(UserDto dto) {
        return service.delUser(dto);
    }

    @ApiOperation(value = "重置密码")
    @PostMapping("editPwd")
    @Log(title = "系统管理", menu = "系统管理->用户管理", grade = OperationType.RESET_USER_PWD, details = "重置密码", type = "系统日志")
    public AjaxResult editPwd(@RequestBody UserVo vo) {
        return service.editPwd(vo);
    }
}
