Newer
Older
huludao / src / main / java / com / newfiber / api / pc / controller / RoleController.java
package com.newfiber.api.pc.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.newfiber.api.core.annotation.SysLog;
import com.newfiber.api.core.bean.ReqBodyObj;
import com.newfiber.api.core.bean.RespBodyObj;
import com.newfiber.api.pc.dto.CommonDto;
import com.newfiber.api.pc.dto.RoleDto;
import com.newfiber.api.pc.model.entity.Sys_Roles;
import com.newfiber.api.pc.model.request.SysRolesSaveRequest;
import com.newfiber.api.pc.model.request.SysRolesUpdateRequest;
import com.newfiber.api.pc.service.Sys_RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.net.URLDecoder;
import java.util.List;
import java.util.Map;

@RestController
@Api(value = "RoleController",tags = "SYS-04、角色管理", position = 104)
public class RoleController {
	@Autowired
	private Sys_RoleService sysRoleService;
	
	//获取所有角色
	@PostMapping(value="/RoleManager",produces = "application/json;charset=utf-8")
	@SysLog(actionType="4",value = "获取所有角色")
	@ApiOperation("角色管理-获取所有角色")
	public RespBodyObj<Page<Sys_Roles>> RoleManager(@RequestBody ReqBodyObj<CommonDto> params){
        String str=null;
		int pageSize=params.getSize();
		int pageNo=(params.getCurrent()-1)*pageSize;
		try {
			CommonDto sr = params.getData();
			  if(sr.getFuzzyQuery()!=null&&sr.getFuzzyQuery()!=""){
				  str = URLDecoder.decode(sr.getFuzzyQuery(),"UTF-8");
			  }
			Page<Sys_Roles> json=sysRoleService.RoleList(sr.getSort() ,sr.getOrder(),pageNo, pageSize, str);
			return RespBodyObj.ok(json);
		} catch (Exception e) {
			e.printStackTrace();
			return RespBodyObj.error("查询失败!");
		}
		
	}

	//添加角色
	@PostMapping(value="/AddRole",produces = "application/json;charset=utf-8")
	@SysLog(actionType="1",value = "添加角色")
	@ApiOperation("角色管理-添加橘色")
	public RespBodyObj AddRole(@RequestBody SysRolesSaveRequest params){
	  try {
		sysRoleService.addRole(null, params.getRoleName(), params.getRoleType(), params.getRoleState(), params.getRemark(), params.getOrderSort());
		return RespBodyObj.ok("添加成功!");
		} catch (Exception e) {
			e.printStackTrace();
			return RespBodyObj.error("添加失败!");
		}
	}
	//修改角色
	@PostMapping(value="/UpdateRole",produces = "application/json;charset=utf-8")
	@SysLog(actionType="3",value = "修改角色")
	@ApiOperation("角色管理-修改角色")
	public RespBodyObj UpDateRole(@RequestBody SysRolesUpdateRequest params){
		try {
			sysRoleService.updateRole(params.getSerial(), params.getRoleNo(), params.getRoleName(), params.getRoleType(), params.getRoleState(), params.getRemark(), params.getOrderSort());
			return RespBodyObj.ok("修改成功!");
		} catch (Exception e) {
			e.printStackTrace();
			return RespBodyObj.error("修改失败!");
		}
	}
	

	 //删除角色信息
	@PostMapping(value="/deleteRole",produces = "application/json;charset=utf-8")
	@SysLog(actionType="2",value = "删除角色信息")
	@ApiOperation("角色管理-删除角色信息")
	public RespBodyObj deleteRole(@RequestParam("serial") String serial){
		try {
			if(serial !=null && serial != ""){
			sysRoleService.deleteRole(serial);
				return RespBodyObj.ok("删除成功!");
			}else{
				return RespBodyObj.error("未选中删除项");
			}
			} catch (Exception e) {
			e.printStackTrace();
			return RespBodyObj.error("删除失败!");
		}
	}
}