对比新文件 |
| | |
| | | package com.gk.firework.Controller; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.gk.firework.Domain.DistrictInfo; |
| | | import com.gk.firework.Domain.RoleInfo; |
| | | import com.gk.firework.Domain.RolePermissionsInfo; |
| | | import com.gk.firework.Domain.UserInfo; |
| | | import com.gk.firework.Domain.Utils.*; |
| | | import com.gk.firework.Domain.Vo.Menu; |
| | | import com.gk.firework.Service.*; |
| | | import io.swagger.annotations.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.management.relation.Role; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.InputStream; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | @Api(tags = "角色管理数据接口") |
| | | @RestController |
| | | public class RoleController { |
| | | |
| | | @Autowired |
| | | UserService userService; |
| | | @Autowired |
| | | RoleService roleService; |
| | | @Autowired |
| | | UserRolesService userRolesService; |
| | | @Autowired |
| | | RolePermissionsService rolePermissionsService; |
| | | @Autowired |
| | | ExcelExportService excelExportService; |
| | | |
| | | @GetMapping("/role") |
| | | @ApiOperation(value = "获取角色数据",response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name",value = "角色名"), |
| | | }) |
| | | public Msg getRoleInfo(String name){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | List<RoleInfo> roleInfos = roleService.selectList(name); |
| | | msg.setResult(roleInfos); |
| | | return msg; |
| | | } |
| | | |
| | | @GetMapping("/rolepermissions") |
| | | @ApiOperation(value = "获取角色菜单数据",response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "roleId",value = "角色id"), |
| | | }) |
| | | public Msg getRolePermissions(String roleId){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | List<Menu> roleInfos = rolePermissionsService.selectMenuList(roleId); |
| | | msg.setResult(roleInfos); |
| | | return msg; |
| | | } |
| | | |
| | | @PostMapping("/addrole") |
| | | @ApiOperation(value = "添加角色数据",response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name",value = "角色名",required = true), |
| | | @ApiImplicitParam(name = "operator",value = "操作人"), |
| | | @ApiImplicitParam(name = "btnaccess",value = "按钮权限"), |
| | | }) |
| | | public Msg addRoleInfo(@RequestBody JSONObject jsonObject){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | String name = jsonObject.getString("name"); |
| | | String operator = jsonObject.getString("operator"); |
| | | String btnaccess = jsonObject.getString("btnaccess"); |
| | | RoleInfo roleInfo = new RoleInfo(); |
| | | roleInfo.setName(name); |
| | | RoleInfo roleInfoExist = roleService.selectRoleByName(roleInfo); |
| | | if (roleInfoExist != null){ |
| | | msg.setCode("500"); |
| | | msg.setMessage("角色名重复"); |
| | | return msg; |
| | | }else { |
| | | roleInfo.setBtnaccess(btnaccess); |
| | | roleInfo.setCreatedby(operator); |
| | | roleInfo.setCreateddate(new Date()); |
| | | roleInfo.setLastmodifiedby(operator); |
| | | roleInfo.setLastmodifieddate(new Date()); |
| | | roleInfo.setIsdel((byte)0); |
| | | roleService.save(roleInfo); |
| | | return msg; |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/putrole") |
| | | @ApiOperation(value = "修改角色数据",response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id",value = "角色id",required = true), |
| | | @ApiImplicitParam(name = "name",value = "角色名",required = true), |
| | | @ApiImplicitParam(name = "btnaccess",value = "按钮权限"), |
| | | @ApiImplicitParam(name = "operator",value = "操作人"), |
| | | }) |
| | | public Msg putRoleInfo(@RequestBody JSONObject jsonObject){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | String name = jsonObject.getString("name"); |
| | | String operator = jsonObject.getString("operator"); |
| | | String btnaccess = jsonObject.getString("btnaccess"); |
| | | Long id = jsonObject.getLong("id"); |
| | | List<RoleInfo> roleInfoExist = roleService.selectExistRole(id,name); |
| | | if (roleInfoExist.size() > 0){ |
| | | msg.setCode("500"); |
| | | msg.setMessage("角色名重复"); |
| | | return msg; |
| | | }else { |
| | | RoleInfo roleInfo = new RoleInfo(); |
| | | roleInfo.setId(id); |
| | | roleInfo.setName(name); |
| | | roleInfo.setBtnaccess(btnaccess); |
| | | roleInfo.setLastmodifiedby(operator); |
| | | roleInfo.setLastmodifieddate(new Date()); |
| | | roleService.updateById(roleInfo); |
| | | return msg; |
| | | } |
| | | } |
| | | |
| | | @PostMapping("/rolepermissions") |
| | | @ApiOperation(value = "获取角色菜单数据",response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id",value = "角色id"), |
| | | }) |
| | | public Msg putRolePermissions(@ApiParam(value = "permissionIds,id") |
| | | @RequestBody JSONObject jsonObject){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | JSONArray permissionId = jsonObject.getJSONArray("permissionIds"); |
| | | Long roleid = jsonObject.getLong("id"); |
| | | rolePermissionsService.delRolePermissionByRoleId(roleid); |
| | | for (int i = 0; i < permissionId.size(); i++) { |
| | | RolePermissionsInfo rolePermissionsInfo = new RolePermissionsInfo(); |
| | | rolePermissionsInfo.setRoleid(roleid); |
| | | rolePermissionsInfo.setPermissionid(Long.parseLong(permissionId.get(i).toString())); |
| | | rolePermissionsService.save(rolePermissionsInfo); |
| | | } |
| | | return msg; |
| | | } |
| | | |
| | | @PostMapping("/delrole") |
| | | @ApiOperation(value = "删除角色数据", response = Msg.class) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(paramType="query",name = "id",value = "id",required = true), |
| | | @ApiImplicitParam(paramType="body",name = "operator",value = "更新人"), |
| | | |
| | | }) |
| | | public Msg delRoleInfo(@ApiParam(value = "id,operator") |
| | | @RequestBody JSONObject jsonObject){ |
| | | Msg msg = new Msg(); |
| | | msg.setCode("200"); |
| | | msg.setMessage("success"); |
| | | Long id = jsonObject.getLong("id"); |
| | | if (id == 1 || id == 2 || id == 3){ |
| | | msg.setCode("999"); |
| | | msg.setMessage("内置角色不允许删除"); |
| | | return msg; |
| | | } |
| | | RoleInfo roleInfo = new RoleInfo(); |
| | | roleInfo.setId(jsonObject.getLong("id")); |
| | | roleInfo.setLastmodifiedby(jsonObject.getString("operator")); |
| | | roleInfo.setLastmodifieddate(new Date()); |
| | | roleInfo.setIsdel((byte)1); |
| | | roleService.updateById(roleInfo); |
| | | return msg; |
| | | } |
| | | |
| | | } |