package com.xdap.self_development.controller;


import com.definesys.mpaas.common.http.Response;
import com.xdap.api.moudle.user.pojo.XdapUsers;
import com.xdap.self_development.domain.view.UserInfoView;
import com.xdap.self_development.service.XdapDeptUsersService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 部门用户控制器
 * 提供部门用户相关的功能，用于选择参数填写人等
 *
 * @version 1.0
 * @since 2025
 */
@RestController
@RequestMapping("/custom/xdapDeptUsersPojo")
public class XdapDeptUsersController {
    @Resource
    private XdapDeptUsersService xdapDeptUsersService;

    @GetMapping("/getUserInfo")
    public Response getDeptAndUserById(
            @NotBlank(message = "用户不能为空") String userId
    ) {
        UserInfoView userInfo = xdapDeptUsersService.getUserInfo(userId);
        return Response.ok().data(userInfo);
    }

    /**
     * 查询部门下的人（用于选择参数填写人）
     *
     * @param deptName 部门名称
     * @return 部门用户列表
     */
    @PostMapping("/selectUsersByDept")
    public Response selectUsersByDept(@RequestParam("deptName") String deptName) {
        List<XdapUsers> xdapUsersPojos = xdapDeptUsersService.selectUserByName(deptName);
        if (ObjectUtils.isNotEmpty(xdapUsersPojos)) {
            return Response.ok().data(xdapUsersPojos);
        }
        return null;
    }
}

