/**
* Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.stylefeng.guns.sys.modular.rest.controller;
import cn.stylefeng.guns.base.auth.context.LoginContextHolder;
import cn.stylefeng.guns.base.consts.ConstantsContext;
import cn.stylefeng.guns.base.log.BussinessLog;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.core.constant.Const;
import cn.stylefeng.guns.sys.core.constant.dictmap.UserDict;
import cn.stylefeng.guns.sys.core.constant.state.ManagerStatus;
import cn.stylefeng.guns.sys.core.exception.enums.BizExceptionEnum;
import cn.stylefeng.guns.sys.core.util.SaltUtil;
import cn.stylefeng.guns.sys.modular.rest.entity.RestUser;
import cn.stylefeng.guns.sys.modular.rest.model.UserQueryParam;
import cn.stylefeng.guns.sys.modular.rest.service.RestUserService;
import cn.stylefeng.guns.sys.modular.system.model.UserDto;
import cn.stylefeng.guns.sys.modular.system.warpper.UserWrapper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.datascope.DataScope;
import cn.stylefeng.roses.core.util.ToolUtil;
import cn.stylefeng.roses.kernel.model.exception.RequestEmptyException;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import cn.stylefeng.roses.kernel.model.response.SuccessResponseData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.Map;
import java.util.UUID;
/**
* 系统管理员控制器
*
* @author fengshuonan
* @Date 2017年1月11日 下午1:08:17
*/
@RestController
@RequestMapping("/rest/mgr")
public class RestUserMgrController extends BaseController {
@Autowired
private RestUserService restUserService;
/**
* 通过用户id获取用户的信息
*
* @author fengshuonan
* @Date 2018/12/24 22:43
*/
@RequestMapping("/getUserById")
public ResponseData getUserById(@RequestParam("userId") Long userId) {
if (ToolUtil.isEmpty(userId)) {
throw new ServiceException(BizExceptionEnum.REQUEST_NULL);
}
Map user = restUserService.getUserInfo(userId);
return new SuccessResponseData(user);
}
/**
* 获取用户详情
*
* @author fengshuonan
* @Date 2018/12/24 22:43
*/
@RequestMapping("/getUserInfo")
public SuccessResponseData getUserInfo(@RequestParam("userId") Long userId) {
if (ToolUtil.isEmpty(userId)) {
throw new RequestEmptyException();
}
this.restUserService.assertAuth(userId);
return new SuccessResponseData(restUserService.getUserInfo(userId));
}
/**
* 修改当前用户的密码
*
* @author fengshuonan
* @Date 2018/12/24 22:43
*/
@RequestMapping("/changePwd")
public Object changePwd(@RequestParam("oldPassword") String oldPassword, @RequestParam("newPassword") String newPassword) {
if (ToolUtil.isOneEmpty(oldPassword, newPassword)) {
throw new RequestEmptyException();
}
this.restUserService.changePwd(oldPassword, newPassword);
return SUCCESS_TIP;
}
/**
* 查询管理员列表
*
* @author fengshuonan
* @Date 2018/12/24 22:43
*/
@RequestMapping("/list")
public Object list(@RequestBody UserQueryParam userQueryParam) {
//拼接查询条件
String beginTime = "";
String endTime = "";
if (ToolUtil.isNotEmpty(userQueryParam.getTimeLimit())) {
String[] split = userQueryParam.getTimeLimit().split(" - ");
beginTime = split[0];
endTime = split[1];
}
if (LoginContextHolder.getContext().isAdmin()) {
Page