All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.javaclub.base.web.ManageUserController Maven / Gradle / Ivy

/* Automatic generated by CrudCodeGenerator wirtten by Gerald Chen
 *
 * @(#)MpUserController.java	2023-09-19
 *
 * Copyright (c) 2023 - 2099. All Rights Reserved.
 *
 */

package com.github.javaclub.base.web;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
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;

import com.github.javaclub.Constants.EnableStatus;
import com.github.javaclub.base.annotation.SysLog;
import com.github.javaclub.base.annotation.WithApiResult;
import com.github.javaclub.base.domain.AppUserDO;
import com.github.javaclub.base.domain.query.AppUserQuery;
import com.github.javaclub.base.service.UserAccountService;
import com.github.javaclub.sword.BizException;
import com.github.javaclub.sword.core.BizObjects;
import com.github.javaclub.sword.core.Strings;
import com.github.javaclub.sword.domain.QueryResult;
import com.github.javaclub.sword.web.PageResultSet;
import com.github.javaclub.toolbox.enumtype.ActionType;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;


/**
 * MpUserController
 *
 * @author Gerald Chen
 * @version $Id: MpUserController.java 2023-09-19 12:17:28 Exp $
 */
@RestController
@RequestMapping("/manage/user")
@Api(tags = "管理端: 用户管理")
@WithApiResult
@AllArgsConstructor
public class ManageUserController {
	
	private final UserAccountService userAccountService;
	
	@PostMapping(value = "/enable")
	@ApiOperation(value = "启用操作")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "token", value = "鉴权token",  paramType = "header", dataType = "string", required = true),
        @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", paramType = "query", required = true)
	})
	@PreAuthorize("@pms.hasPermission('manage:user:enable')")
	@SysLog(value = "启用用户", actionType = ActionType.ENABLE)
	public Boolean enable(Long id) throws Exception {
		BizObjects.requireNotNullGtZero(id, "主键ID不能为空!");
		AppUserDO entity = new AppUserDO(id, EnableStatus.ENABLED);
		return userAccountService.updateUserStatus(entity);
	}
	
	@PostMapping(value = "/disable")
	@ApiOperation(value = "禁用操作")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "token", value = "鉴权token",  paramType = "header", dataType = "string", required = true),
        @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", paramType = "query", required = true)
	})
	@PreAuthorize("@pms.hasPermission('manage:user:disable')")
	@SysLog(value = "禁用", actionType = ActionType.DISABLE)
	public Boolean disable(Long id) throws Exception {
		BizObjects.requireNotNullGtZero(id, "主键ID不能为空!");
		AppUserDO entity = new AppUserDO(id, EnableStatus.DISABLED);
		return userAccountService.updateUserStatus(entity);
	}
	
	
	@GetMapping(value = "/info")
	@ApiOperation(value = "查看详情")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "token", value = "鉴权token", paramType = "header", dataType = "string", required = true),
		@ApiImplicitParam(name = "id", value = "主键ID", paramType = "query", dataType = "Long", required = true)
	})
	@PreAuthorize("@pms.hasPermission('manage:user:info')")
	@SysLog(value = "查看", actionType = ActionType.QUERY)
	public AppUserDO info(Long id) {
		BizObjects.requireNotNullGtZero(id, "主键ID不能为空");
		return userAccountService.selectById(id);
	}
	
	
	@PostMapping("/page")
	@ApiOperation(value = "列表查询")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "token", value = "鉴权token", paramType = "header", dataType = "string", required = true)
	})
	@PreAuthorize("@pms.hasPermission('manage:user:page')")
	@SysLog(value = "查看用户列表", actionType = ActionType.QUERY)
	public PageResultSet queryList(@RequestBody AppUserQuery query) throws Exception {
		QueryResult qr = userAccountService.findListWithCount(query);
		if (!qr.isSuccess()) {
			throw new BizException(Strings.noneBlank(qr.getMessage(), "查询列表失败!"));
		}
		return PageResultSet.build(query.getPageNo(), query.getPageSize(), qr.getTotalCount(), qr.getEntry());
	}
	
}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy