嗨森逛服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hai-server/hai-bweb/src/main/java/com/bweb/controller/HighUserController.java

151 lines
5.2 KiB

package com.bweb.controller;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.DateUtil;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.HighUser;
import com.hai.model.ResponseData;
import com.hai.service.HighUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Sum1Dream
*/
@RestController
@RequestMapping(value = "/highUser")
@Api(value = "用户管理")
public class HighUserController {
private static Logger log = LoggerFactory.getLogger(HighUserController.class);
@Resource
private HighUserService highUserService;
@RequestMapping(value = "/getListUser", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "查询用户列表")
public ResponseData getPagePosition(
@RequestParam(value = "name", required = false) String name,
@RequestParam(value = "phone", required = false) String phone,
@RequestParam(value = "status", required = false) Integer status,
@RequestParam(value = "regTimeStart", required = false) Date regTimeStart,
@RequestParam(value = "regTimeEnd", required = false) Date regTimeEnd,
@RequestParam(name = "pageNum", required = true) Integer pageNum,
@RequestParam(name = "pageSize", required = true) Integer pageSize
) {
try {
Map<String, String> map = new HashMap<>();
if (StringUtils.isNotBlank(name)) {
map.put("name", name);
}
if (StringUtils.isNotBlank(phone)) {
map.put("phone", phone);
}
if (status != null) {
map.put("status", Integer.toString(status));
}
if (regTimeStart != null) {
map.put("regTimeStart", DateUtil.date2String(regTimeStart,DateUtil.ymd_HM));
}
if (regTimeEnd != null) {
map.put("regTimeEnd", DateUtil.date2String(regTimeEnd,DateUtil.ymd_HM));
}
PageHelper.startPage(pageNum, pageSize);
List<HighUser> highUsers = highUserService.getListUser(map);
return ResponseMsgUtil.success(new PageInfo<>(highUsers));
} catch (Exception e) {
log.error("HighUserController --> getListUser() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/findByUserId", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "根据id查询职位详情")
public ResponseData findById(@RequestParam(value = "userId", required = true) Long userId) {
try {
return ResponseMsgUtil.success(highUserService.findByUserId(userId));
} catch (Exception e) {
log.error("HighUserController --> findByUserId() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/forbiddenUser", method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "禁用账号")
public ResponseData forbiddenUser(@RequestParam(value = "userId" , required = true) Long userId) {
try {
HighUser highUser = highUserService.findByUserId(userId);
if (highUser == null) {
log.error("HighUserController --> forbiddenUser() error!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_USER_ERROR, "");
}
highUser.setStatus(0);
highUserService.updateUser(highUser);
return ResponseMsgUtil.success("禁用成功");
} catch (Exception e) {
log.error("BsPositionController --> addPosition() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value = "/updateUser", method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "修改用户")
public ResponseData updateUser(@RequestBody HighUser reqBody) {
try {
if (
reqBody.getId() == null
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
HighUser highUser = highUserService.findByUserId(reqBody.getId());
if (highUser == null) {
log.error("HighUserController --> updateUser() error!");
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_USER_ERROR, "");
}
highUserService.updateUser(reqBody);
return ResponseMsgUtil.success("修改成功");
} catch (Exception e) {
log.error("BsPositionController --> addPosition() error!", e);
return ResponseMsgUtil.exception(e);
}
}
}