package com.jy.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jy.framework.model.annotation.JyLog;
import com.jy.framework.model.base.BaseSelectDto;
import com.jy.framework.model.enums.BusinessType;
import com.jy.framework.model.validation.AddGroup;
import com.jy.framework.model.validation.BatchDeleteGroup;
import com.jy.framework.model.validation.DetailGroup;
import com.jy.framework.model.validation.EditGroup;
import com.jy.system.model.dto.ResetPwdDto;
import com.jy.system.model.dto.SysUserDto;
import com.jy.system.model.dto.SysUserSelectDto;
import com.jy.system.model.vo.SysUserInfoVo;
import com.jy.system.model.vo.SysUserVo;
import com.jy.system.service.SysUserService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户 前端控制器
 * </p>
 *
 * @author
 * @since 2024-06-20
 */
@RestController
@RequestMapping("/sysUser")
public class SysUserController {

    @Resource
    private SysUserService sysUserService;

    /**
     * 用户列表
     */
    @GetMapping("/getList")
    public List<SysUserInfoVo> getList(SysUserSelectDto dto) {
        return sysUserService.getList(dto);
    }

    /**
     * 用户分页
     */
    @GetMapping("/getPage")
    public Page<SysUserVo> getPage(SysUserSelectDto dto) {
        return sysUserService.getPage(dto);
    }

    /**
     * 用户明细
     */
    @GetMapping("/getDetail")
    public SysUserVo getDetail(@Validated(DetailGroup.class) BaseSelectDto dto) {
        return sysUserService.getDetail(dto.getId());
    }

    /**
     * 用户新增
     */
    @JyLog(title = "新增用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public void add(@Validated(AddGroup.class) @RequestBody SysUserDto dto) {
        sysUserService.add(dto);
    }

    /**
     * 用户编辑
     */
    @JyLog(title = "编辑用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public void edit(@Validated(EditGroup.class) @RequestBody SysUserDto dto) {
        sysUserService.edit(dto);
    }

    /**
     * 用户删除
     */
    @JyLog(title = "删除用户", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public void delete(@Validated(BatchDeleteGroup.class) @RequestBody BaseSelectDto dto) {
        sysUserService.delete(dto.getIdList());
    }

    /**
     * 重置用户密码
     */
    @JyLog(title = "重置用户密码", businessType = BusinessType.UPDATE, excludeFields = "password")
    @PostMapping("/resetPwd")
    public void resetPwd(@Validated @RequestBody ResetPwdDto dto) {
        sysUserService.resetPwd(dto);
    }

}
