package com.changhu.module.securityManagement.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.changhu.common.annotation.CheckUserType;
import com.changhu.common.annotation.JsonBody;
import com.changhu.common.db.enums.UserType;
import com.changhu.module.securityManagement.pojo.params.UserSaveOrUpdateParams;
import com.changhu.module.securityManagement.pojo.queryParams.UserPagerQueryParams;
import com.changhu.module.securityManagement.pojo.vo.UserPagerVo;
import com.changhu.module.securityManagement.service.UserService;
import com.changhu.support.mybatisplus.pojo.params.PageParams;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 20252
 * @createTime 2024/11/22 上午9:46
 * @desc UserController...
 */
@Tag(name = "保安后台-用户管理")
@JsonBody
@RequestMapping("/m3/user")
@RestController("securityUserManagement")
@CheckUserType(userTypes = UserType.MANAGEMENT_SECURITY)
public class UserController {

    @Autowired
    private UserService userService;

    @Operation(summary = "新增或修改后台用户")
    @PostMapping("/add_upd")
    public void userSaveOrUpdate(@RequestBody @Valid UserSaveOrUpdateParams saveOrUpdateParams) {
        userService.saveOrUpdate(saveOrUpdateParams);
    }

    @Operation(summary = "分页查询后台用户")
    @PostMapping("/pager")
    public Page<UserPagerVo> userPager(@RequestBody PageParams<UserPagerQueryParams, UserPagerVo> queryParams) {
        return userService.pager(queryParams);
    }

    @Operation(summary = "根据id删除后台用户")
    @DeleteMapping("/del_id")
    public void userDeleteById(@RequestParam @Schema(description = "后台保安用户id") Long managementSecurityUnitUserId) {
        userService.deleteById(managementSecurityUnitUserId);
    }

}
