package com.changhu.module.policeManagement.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.policeManagement.pojo.params.UserSaveOrUpdateParams;
import com.changhu.module.policeManagement.pojo.queryParams.UserPagerQueryParams;
import com.changhu.module.policeManagement.pojo.vo.UserPagerVo;
import com.changhu.module.policeManagement.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:26
 * @desc UserController...
 */
@Tag(name = "公安后台-用户管理")
@JsonBody
@RequestMapping("/m2/user")
@RestController("policeUserManagement")
@CheckUserType(userTypes = UserType.MANAGEMENT_POLICE)
public class UserController {
    @Autowired
    private UserService userService;

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

    @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 managementPoliceUnitUserId) {
        userService.deleteById(managementPoliceUnitUserId);
    }

}
