package com.tuoheng.admin.service.user;

import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.request.user.QueryUserPageListRequest;
import com.tuoheng.admin.request.user.UserInitRequest;
import com.tuoheng.admin.request.user.UserResetPwdRequest;
import com.tuoheng.admin.service.user.add.AddUserService;
import com.tuoheng.admin.service.user.delete.DeleteUserService;
import com.tuoheng.admin.service.user.init.SystemUserInitService;
import com.tuoheng.admin.service.user.query.QueryUserInfoByIdService;
import com.tuoheng.admin.service.user.query.QueryUserListByDeptIdService;
import com.tuoheng.admin.service.user.query.QueryUserPageListService;
import com.tuoheng.admin.service.user.update.UpdateUserPasswordService;
import com.tuoheng.admin.service.user.update.UpdateUserService;
import com.tuoheng.admin.service.user.update.UpdateUserStatusService;
import com.tuoheng.common.core.utils.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;


/**
 * <p>
 * 后台用户管理表 服务实现类
 * </p>
 *
 * @author 拓恒
 * @since 2020-10-30
 */
@Slf4j
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private QueryUserPageListService queryUserPageListService;

    @Autowired
    private QueryUserListByDeptIdService queryUserListByDeptIdService;

    @Autowired
    private AddUserService addUserService;

    @Autowired
    private UpdateUserService updateUserService;

    @Autowired
    private DeleteUserService deleteUserService;

    @Autowired
    private UpdateUserStatusService updateUserStatusService;

    @Autowired
    private UpdateUserPasswordService updateUserPasswordService;

    @Autowired
    private QueryUserInfoByIdService queryUserInfoByIdService;

    @Autowired
    private SystemUserInitService systemUserInitService;

    /**
     * 获取用户分页列表
     *
     * @param request 查询条件
     * @return
     */
    @Override
    public JsonResult getPageList(QueryUserPageListRequest request) {
        return queryUserPageListService.getPageList(request);
    }

    /**
     * 获取用户详情
     *
     * @return
     */
    @Override
    public JsonResult getUserInfo() {
        return queryUserInfoByIdService.getUserInfo();
    }

    /**
     * 添加用户
     *
     * @param user 实体对象
     * @return
     */
    @Override
    public JsonResult add(User user) {
        return addUserService.add(user);
    }

    /**
     * 编辑用户
     *
     * @param user 实体对象
     * @return
     */
    @Override
    public JsonResult edit(User user) {
        return updateUserService.update(user);
    }

    /**
     * 删除用户
     *
     * @param idList 用户ID
     * @return
     */
    @Override
    public JsonResult deleteByIdList(List<String> idList) {
        return deleteUserService.deleteByIdList(idList);
    }

    /**
     * 设置状态
     *
     * @param id
     * @param status
     *
     * @return
     */
    @Override
    public JsonResult updeateStatus(String id, Integer status) {
        return updateUserStatusService.update(id, status);
    }

    /**
     * 重置密码
     *
     * @param id
     * @return
     */
    @Override
    public JsonResult resetPassword(String id) {
        return updateUserPasswordService.resetPassword(id);
    }


    /**
     * 根据部门id查询用户列表
     */
    @Override
    public JsonResult getListByDeptId(String deptId) {
        return queryUserListByDeptIdService.getListByDeptId(deptId);
    }

    /**
     * 初始化系统超级管理员用户
     */
    @Override
    public JsonResult init(UserInitRequest request) {
        return systemUserInitService.init(request);
    }

}
