package com.njcn.user.controller;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.LogInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.constant.SecurityConstants;
import com.njcn.common.pojo.enums.common.DataStateEnum;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.common.utils.sm.DesUtils;
import com.njcn.common.utils.sm.Sm2;
import com.njcn.minioss.bo.MinIoUploadResDTO;
import com.njcn.poi.util.PoiUtil;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.user.enums.UserResponseEnum;
import com.njcn.user.pojo.dto.UserDTO;
import com.njcn.user.pojo.param.UserInfoParm;
import com.njcn.user.pojo.param.UserParam;
import com.njcn.user.pojo.param.UserPasswordParam;
import com.njcn.user.pojo.po.User;
import com.njcn.user.pojo.vo.UserVO;
import com.njcn.user.service.IUserService;
import com.njcn.web.controller.BaseController;
import com.njcn.web.utils.RequestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2021-12-13
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户信息管理")
@AllArgsConstructor
public class UserController extends BaseController {

    private final IUserService userService;

    private final RedisUtil redisUtil;

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getUserByName/{loginName}")
    @ApiOperation("根据登录名查询用户信息")
    @ApiImplicitParam(name = "loginName", value = "登录名", required = true)
    public HttpResult<UserDTO> getUserByName(@PathVariable String loginName) {
        RequestUtil.saveLoginName(loginName);
        String methodDescribe = getMethodDescribe("getUserByName");
        LogUtil.njcnDebug(log, "{},登录名为：{}", methodDescribe, loginName);
        UserDTO user = userService.getUserByName(loginName);
        if (Objects.isNull(user)) {
            throw new BusinessException(UserResponseEnum.LOGIN_WRONG_PWD);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, user, methodDescribe);
        }
    }


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiIgnore
    @GetMapping("/getUserByPhone/{phone}")
    @ApiOperation("根据手机号查询用户信息")
    @ApiImplicitParam(name = "phone", value = "手机号", required = true)
    public HttpResult<UserDTO> getUserByPhone(@PathVariable String phone) {
        RequestUtil.saveLoginName(phone);
        String methodDescribe = getMethodDescribe("getUserByPhone");
        LogUtil.njcnDebug(log, "{},手机号为：{}", methodDescribe, phone);
        UserDTO user = userService.loadUserByPhone(phone);
        if (Objects.isNull(user)) {
            throw new BusinessException(UserResponseEnum.LOGIN_PHONE_NOT_REGISTER);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, user, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/judgeUserStatus/{loginName}")
    @ApiOperation("认证后根据用户名判断用户状态")
    @ApiImplicitParam(name = "loginName", value = "登录名", required = true)
    public HttpResult<Boolean> judgeUserStatus(@PathVariable String loginName) {
        RequestUtil.saveLoginName(loginName);
        String methodDescribe = getMethodDescribe("judgeUserStatus");
        LogUtil.njcnDebug(log, "{},登录名为：{}", methodDescribe, loginName);
        userService.judgeUserStatus(loginName);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }


    /**
     * 新增用户
     *
     * @param addUserParam 用户数据
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增用户")
    @ApiImplicitParam(name = "addUserParam", value = "新增用户", required = true)
    public HttpResult<Boolean> add(@RequestBody @Validated UserParam.UserAddParam addUserParam) {
        String methodDescribe = getMethodDescribe("add");
        LogUtil.njcnDebug(log, "{}，用户数据为：{}", methodDescribe, addUserParam);
        boolean result = userService.addUser(addUserParam);
        //更新redis数据
        userService.userRoleList();
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    /**
     * 删除用户
     *
     * @param id 用户id
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
    @DeleteMapping("/delete")
    @ApiOperation("删除用户")
    @ApiImplicitParam(name = "id", value = "用户id", required = true)
    public HttpResult<Boolean> delete(@RequestParam @Validated String id) {
        String methodDescribe = getMethodDescribe("delete");
        LogUtil.njcnDebug(log, "{}，用户id为：{}", methodDescribe, id);
        boolean result = userService.deleteUser(id);
        //更新redis数据
        userService.userRoleList();
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    /**
     * 修改用户
     *
     * @param updateUserParam 用户数据
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @PutMapping("/update")
    @ApiOperation("修改用户")
    @ApiImplicitParam(name = "updateUserParam", value = "修改用户", required = true)
    public HttpResult<Boolean> update(@RequestBody @Validated UserParam.UserUpdateParam updateUserParam) {
        String methodDescribe = getMethodDescribe("update");
        LogUtil.njcnDebug(log, "{}，用户数据为：{}", methodDescribe, updateUserParam);
        boolean result = userService.updateUser(updateUserParam);
        //更新redis数据
        userService.userRoleList();
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @PutMapping("/updateAppUser")
    @ApiOperation("修改用户头像,昵称")
    @ApiImplicitParam(name = "userInfoParm", value = "修改用户", required = true)
    public HttpResult<Boolean> update(@RequestBody @Validated UserInfoParm userInfoParm) {
        String methodDescribe = getMethodDescribe("update");
        LogUtil.njcnDebug(log, "{}，用户数据为：{}", methodDescribe, userInfoParm);
        boolean result = userService.updateAppUser(userInfoParm);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPLOAD)
    @PostMapping("/uploadImage")
    @ApiOperation("上传头像")
    public HttpResult<MinIoUploadResDTO> uploadImage(MultipartFile issuesFile) {
        String methodDescribe = getMethodDescribe("uploadImage");
        String filePath = userService.uploadImage(issuesFile);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, new MinIoUploadResDTO(issuesFile.getOriginalFilename(), filePath), methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPLOAD)
    @PostMapping("/getUrl")
    @ApiOperation("获取头像url")
    public HttpResult<String> getUrl(@RequestParam("headSculpture") String headSculpture) {
        String methodDescribe = getMethodDescribe("getUrl");
        String url = userService.getUrl(headSculpture);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, url, methodDescribe);
    }


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/list")
    @ApiOperation("查询用户列表分页")
    @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
    public HttpResult<Page<UserVO>> getUserList(@RequestBody @Validated UserParam.UserQueryParam queryParam) {
        String methodDescribe = getMethodDescribe("getUserList");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, queryParam);
        Page<UserVO> list = userService.userList(queryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/listAllUserByDeptId")
    @ApiOperation("查询部门下所有状态正常的用户")
    public HttpResult<List<UserVO>> listAllUserByDeptId(String deptId) {
        String methodDescribe = getMethodDescribe("listAllUserByDeptId");
        List<UserVO> list = userService.listAllUserByDeptId(deptId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/exportUser")
    @ApiOperation("用户数据")
    @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
    public HttpResult<String> exportUser(@RequestBody @Validated UserParam.UserQueryParam queryParam) {
        String methodDescribe = getMethodDescribe("exportUser");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, queryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userService.exportUser(queryParam, methodDescribe), methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DOWNLOAD)
    @GetMapping("/exportUserExcel")
    @ApiOperation("导出用户数据")
    @ApiImplicitParam(name = "filePath", value = "报表路径", required = true)
    public void exportUserExcel(String filePath, HttpServletResponse response) {
        PoiUtil.exportFileByAbsolutePath(filePath, response);
    }


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/checkUserList")
    @ApiOperation("审核用户列表")
    @ApiImplicitParam(name = "queryParam", value = "查询参数", required = true)
    public HttpResult<Page<UserVO>> getCheckList(@RequestBody @Validated UserParam.UserQueryParam queryParam) {
        String methodDescribe = getMethodDescribe("getCheckList");
        LogUtil.njcnDebug(log, "{}，查询数据为：{}", methodDescribe, queryParam);
        Page<UserVO> list = userService.checkUserList(queryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    /**
     * 根据用户id获取用户详情
     *
     * @param id 用户id
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getUserById")
    @ApiOperation("用户详情")
    @ApiImplicitParam(name = "id", value = "用户id", required = true)
    public HttpResult<UserVO> getUserById(@RequestParam @Validated String id) {
        String methodDescribe = getMethodDescribe("getUserById");
        LogUtil.njcnDebug(log, "{}，用户id为：{}", methodDescribe, id);
        UserVO userVO = userService.getUserById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userVO, methodDescribe);
    }


    /**
     * 根据用户id获取该用户同部门下所有的所有用户id
     *
     * @param id 用户id
     */
    @ApiIgnore
    @GetMapping("/getColleaguesIdByUserId")
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @ApiOperation("根据用户id获取该用户同部门下所有的所有用户id")
    @ApiImplicitParam(name = "id", value = "用户id", required = true)
    HttpResult<List<String>> getColleaguesIdByUserId(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getColleaguesIdByUserId");
        LogUtil.njcnDebug(log, "{}，用户id为：{}", methodDescribe, id);
        List<String> colleagueIds = userService.getColleaguesIdByUserId(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, colleagueIds, methodDescribe);
    }

    /**
     * 审核用户
     *
     * @param list 用户id集合
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @PutMapping("/check")
    @ApiOperation("审核用户")
    @ApiImplicitParam(name = "list", value = "用户id集合", required = true)
    public HttpResult<Boolean> check(@RequestBody @Validated List<String> list) {
        String methodDescribe = getMethodDescribe("check");
        LogUtil.njcnDebug(log, "{}，用户id集合为：{}", methodDescribe, list);
        boolean result = userService.checkUser(list);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    /**
     * 修改密码
     *
     * @param id          用户id
     * @param newPassword 用户新密码
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @PutMapping("/updatePassword")
    @ApiOperation("修改密码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true),
            @ApiImplicitParam(name = "newPassword", value = "用户新密码", required = true)
    })
    public HttpResult<Boolean> updatePassword(String id, String newPassword) {
        String methodDescribe = getMethodDescribe("updatePassword");
        LogUtil.njcnDebug(log, "{}，用户id:{},修改的用户密码为:{}", methodDescribe, id, newPassword);
        boolean result = userService.updatePassword(id, newPassword);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/generateSm2Key")
    @ApiOperation("根据登录名获取公钥")
    @ApiImplicitParam(name = "loginName", value = "登录名", required = true)
    public HttpResult<String> generateSm2Key(String loginName, @ApiIgnore HttpServletRequest request) {
        System.out.println("request1==:" + request);
        if (StrUtil.isBlankIfStr(loginName)) {
            RequestUtil.saveLoginName(LogInfo.UNKNOWN_USER);
            throw new BusinessException(UserResponseEnum.LOGIN_USERNAME_INVALID);
        }
        String methodDescribe = getMethodDescribe("generateSm2Key");
        loginName = DesUtils.aesDecrypt(loginName);
        RequestUtil.saveLoginName(loginName);
        Map<String, String> keyMap;
        try {
            keyMap = Sm2.getSm2CipHer();
        } catch (NoSuchAlgorithmException e) {
            throw new BusinessException(CommonResponseEnum.SM2_CIPHER_ERROR);
        }
        String publicKey = keyMap.get("publicKey");
        String privateKey = keyMap.get("privateKey");
        String ip = request.getHeader(SecurityConstants.REQUEST_HEADER_KEY_CLIENT_REAL_IP);

        if (redisUtil.hasKey(loginName + ip)) {
            //秘钥先删除再添加
            redisUtil.delete(loginName + ip);
        }
        // 保存私钥到 redis
        redisUtil.saveByKeyWithExpire(loginName + ip, privateKey, 5 * 60L);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, publicKey, methodDescribe);
    }

    @OperateInfo(operateType = OperateType.UPDATE, info = LogEnum.SYSTEM_SERIOUS)
    @PutMapping("/updateUserLoginErrorTimes/{loginName}")
    @ApiOperation("更新用户登录认证密码错误次数")
    @ApiImplicitParam(name = "loginName", value = "登录名", required = true)
    public HttpResult<String> updateUserLoginErrorTimes(@PathVariable String loginName) {
        RequestUtil.saveLoginName(loginName);
        String methodDescribe = getMethodDescribe("updateUserLoginErrorTimes");
        LogUtil.njcnDebug(log, "{}，登录名为：{}", methodDescribe, loginName);
        String result = userService.updateUserLoginErrorTimes(loginName);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }


    /**
     * 密码二次确认
     *
     * @param password 确认密码
     */
    @OperateInfo(operateType = OperateType.AUTHENTICATE, info = LogEnum.SYSTEM_SERIOUS)
    @GetMapping("/passwordConfirm")
    @ApiOperation("密码二次确认")
    @ApiImplicitParam(name = "password", value = "确认密码")
    public HttpResult<Boolean> passwordConfirm(String password) {
        String methodDescribe = getMethodDescribe("passwordConfirm");
        LogUtil.njcnDebug(log, "{}，用户输入的密码：{}", methodDescribe, password);
        boolean result = userService.passwordConfirm(password);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    /**
     * 首次登录修改密码
     *
     * @param userPasswordParam 用户信息
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @PutMapping("/updateFirstPassword")
    @ApiOperation("首次登录修改密码")
    @ApiImplicitParam(name = "userPasswordParam", value = "加密用户信息", required = true)
    public HttpResult<Boolean> updateFirstPassword(@RequestBody @Validated UserPasswordParam userPasswordParam, @ApiIgnore HttpServletRequest request) {
        RequestUtil.saveLoginName(DesUtils.aesDecrypt(userPasswordParam.getName()));
        String methodDescribe = getMethodDescribe("updateFirstPassword");
        LogUtil.njcnDebug(log, "{}，加密用户信息为:{}", methodDescribe, userPasswordParam);
        String ip = request.getHeader(SecurityConstants.REQUEST_HEADER_KEY_CLIENT_REAL_IP);
        boolean result = userService.updateFirstPassword(userPasswordParam.getName(), userPasswordParam.getPassword(), ip);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
        }
    }

    /**
     * 用于激活处于休眠、锁定、密码过期的用户
     *
     * @param id 用户ID
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
    @PutMapping("/activateUser")
    @ApiOperation("用户激活")
    @ApiImplicitParam(name = "id", value = "用户id")
    public HttpResult<Boolean> activateUser(String id) {
        String methodDescribe = getMethodDescribe("activateUser");
        LogUtil.njcnDebug(log, "{}，用户输入的id：{}", methodDescribe, id);
        boolean result = userService.activateUser(id);
        if (result) {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
        } else {
            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
        }
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/userByIdList")
    @ApiOperation("根据用户id集合查询用户信息")
    @ApiImplicitParam(name = "ids", value = "用户id集合", required = true)
    public HttpResult<List<User>> getUserByIdList(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("getUserByIdList");
        List<User> users = userService.list((new LambdaQueryWrapper<User>()
                .in(CollUtil.isNotEmpty(ids), User::getId, ids)
                .isNotNull(User::getDeptId)
                .ne(User::getDeptId, "")
                .ne(User::getState, "0")
        ));
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getUserVOByIdList")
    @ApiOperation("根据用户id集合查询用户VO")
    @ApiImplicitParam(name = "ids", value = "用户id集合", required = true)
    public HttpResult<List<UserVO>> getUserVOByIdList(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("getUserVOByIdList");
        LogUtil.njcnDebug(log, "{}，用户id为：{}", methodDescribe, ids);
        List<UserVO> userVO = userService.getUserVOByIdList(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userVO, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/appuserByIdList")
    @ApiOperation("根据用户id集合查询用户信息")
    @ApiImplicitParam(name = "ids", value = "用户id集合", required = true)
    public HttpResult<List<User>> appuserByIdList(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("appuserByIdList");
        List<User> users = userService.list((new LambdaQueryWrapper<User>()
                .in(CollUtil.isNotEmpty(ids), User::getId, ids)
        ));
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getUserListByIds")
    @ApiOperation("根据用户id集合查询用户信息")
    @ApiImplicitParam(name = "ids", value = "用户id集合", required = true)
    public HttpResult<List<User>> getUserListByIds(@RequestBody List<String> ids) {
        String methodDescribe = getMethodDescribe("getUserListByIds");
        List<User> users = userService.list((new LambdaQueryWrapper<User>().in(CollUtil.isNotEmpty(ids), User::getId, ids)));
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getMarketList")
    @ApiOperation("获取营销用户列表")
    public HttpResult<List<User>> getMarketList() {
        String methodDescribe = getMethodDescribe("getMarketList");

        List<User> users = userService.getMarketList();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getFormalUserList")
    @ApiOperation("获取移动端、便携式正式用户列表")
    public HttpResult<List<UserVO>> getFormalUserList() {
        String methodDescribe = getMethodDescribe("getFormalUserList");
        List<UserVO> users = userService.getFormalUserList();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }


    /**
     * 获取同级部门用户，以及下级部门所有用户
     *
     * @author cdf
     * @date 2023/7/31
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getUserListByDeptId")
    @ApiOperation("根据用户id集合查询用户信息")
    @ApiImplicitParam(name = "deptId", value = "用户部门id", required = true)
    public HttpResult<List<User>> getUserListByDeptId(@RequestParam("deptId") String deptId) {
        String methodDescribe = getMethodDescribe("getUserListByDeptId");
        List<User> users = userService.getUserListByDeptId(deptId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }


    /**
     * 根据部门ids查询用户信息
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getUserByDeptIds")
    @ApiOperation("根据部门ids查询接收短信通知的用户信息")
    @ApiImplicitParam(name = "deptId", value = "用户部门id", required = true)
    public HttpResult<List<User>> getUserByDeptIds(@RequestBody List<String> deptId) {
        String methodDescribe = getMethodDescribe("getUserByDeptIds");
        List<User> users = userService.list(new LambdaQueryWrapper<User>()
                .in(User::getDeptId, deptId)
                .eq(User::getSmsNotice, 1)
                .eq(User::getState, 1)
        );
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getUserInfoByDeptIds")
    @ApiOperation("根据部门ids查询用户信息")
    @ApiImplicitParam(name = "deptId", value = "用户部门id", required = true)
    public HttpResult<List<User>> getUserInfoByDeptIds(@RequestBody List<String> deptId) {
        String methodDescribe = getMethodDescribe("getUserInfoByDeptIds");
        List<User> users = userService.list(new LambdaQueryWrapper<User>()
                .in(User::getDeptId, deptId)
                .eq(User::getState, DataStateEnum.ENABLE.getCode())
        );
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }

    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @PostMapping("/getUserIdByRoleId")
    @ApiOperation("根据角色id查询用户id")
    @ApiImplicitParam(name = "roleId", value = "用户角色id", required = true)
    public HttpResult<List<String>> getUserIdByRoleId(@RequestBody List<String> roleId) {
        String methodDescribe = getMethodDescribe("getUserInfoByRoleId");
        List<String> userId = userService.getUserIdByRoleId(roleId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, userId, methodDescribe);
    }

    /**
     * 获取同级部门用户，以及下级部门所有用户
     *
     * @author cdf
     * @date 2023/7/31
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getUserListByRoleCode")
    @ApiOperation("根据角色Code集合查询用户信息")
    @ApiImplicitParam(name = "roleCode", value = "角色Code", required = true)
    public HttpResult<List<User>> getUserListByRoleCode(@RequestParam("roleCode") String roleCode) {
        String methodDescribe = getMethodDescribe("getUserListByRoleCode");
        List<User> users = userService.getUserListByRoleCode(roleCode);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }


    /**
     * 根据角色类型获取用户 角色类型 type0:超级管理员；1:管理员；2:普通用户' 3:'审核角色',
     *
     * @author cdf
     * @date 2024/3/29
     */
    @OperateInfo(info = LogEnum.SYSTEM_SERIOUS)
    @GetMapping("/getUserByRoleType")
    @ApiOperation("根据角色类型获取用户")
    @ApiImplicitParam(name = "roleType", value = "角色类型", required = true)
    public HttpResult<List<User>> getUserByRoleType(@RequestParam("roleType") Integer roleType) {
        String methodDescribe = getMethodDescribe("getUserByRoleType");
        List<User> users = userService.getUserByRoleType(roleType);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, users, methodDescribe);
    }


    /**
     * 查询所有用户不包含管理员
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/simpleList")
    @ApiOperation("查询所有普通用户作为下拉框")
    public HttpResult<Object> simpleList() {
        String methodDescribe = getMethodDescribe("simpleList");
        List<User> result = userService.simpleList(false);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 查询所有用户包含管理员
     */
    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getAllUserSimpleList")
    @ApiOperation("查询所有用户作为下拉框")
    public HttpResult<Object> getAllUserSimpleList() {
        String methodDescribe = getMethodDescribe("getAllUserSimpleList");
        List<User> result = userService.simpleList(true);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    /**
     * 查询用户的角色
     *
     * @author cdf
     * @date 2024/8/29
     */
    @GetMapping("/userRoleList")
    @ApiOperation("获取所有用户角色")
    public HttpResult<Boolean> userRoleList() {
        String methodDescribe = getMethodDescribe("userRoleList");
        userService.userRoleList();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }
}

