package com.cm.common.plugin.oauth.controller.app.apis.user;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.cm.common.base.AbstractController;
import com.cm.common.constants.ISystemConstant;
import com.cm.common.exception.ParamsException;
import com.cm.common.plugin.oauth.service.user.IUserService;
import com.cm.common.result.ErrorResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: UserAppController
 * @Description: 用户管理
 * @Author: WangGeng
 * @Date: 2020/2/9 12:07 下午
 * @Version: 1.0
 **/
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "用户管理")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/user")
public class UserAppController extends AbstractController {

    @Autowired
    private IUserService userService;

    @ApiOperation(value = "通过用户和部门ID列表获取部门用户列表", notes = "通过用户和部门ID列表获取部门用户列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "selectedUsers", value = "用户和部门ID列表", paramType = "body")
    })
    @ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
    @PostMapping("listdepartmentuserbyuserdepartmentid")
    public JSONArray listDepartmentUserByUserDepartmentId(@RequestBody JSONObject params) {
        JSONArray selectedUsers = params.getJSONArray("selectedUsers");
        if (selectedUsers == null || selectedUsers.isEmpty()) {
            throw new ParamsException("参数列表不能为空");
        }
        return userService.listDepartmentUserByUserDepartmentId(params);
    }

}
