| | |
| | | package com.vci.frameworkcore.controller; |
| | | |
| | | import com.vci.frameworkcore.compatibility.SmRoleQueryServiceI; |
| | | import com.vci.frameworkcore.constant.FrameWorkLangCodeConstant; |
| | | import com.vci.frameworkcore.dto.SmRoleDTO; |
| | | import com.vci.frameworkcore.pagemodel.SmRoleVO; |
| | | import com.vci.starter.web.annotation.controller.VciUnCheckRight; |
| | | import com.vci.starter.web.exception.VciBaseException; |
| | | import com.vci.starter.web.pagemodel.*; |
| | | import com.vci.starter.web.util.LocalFileUtil; |
| | | import com.vci.starter.web.util.VciBaseUtil; |
| | | import com.vci.starter.web.util.WebThreadLocalUtil; |
| | | import com.vci.web.enumpck.UserTypeEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * 角色的列表查询:用于下拉,还有列表等全查询场景 |
| | | * 角色的列表查询:用于角色管理列表等查询场景:会根据当前登录的用户类型来决定查询那些角色 |
| | | * @param queryObject 查询对象,包含了查询条件,分页,排序等,即允许使用SmRoleVO里的所有属性作为查询条件 |
| | | * @return 包含三员的角色 的显示对象列表数据,请获取其中的data属性 |
| | | * @throws VciBaseException 查询出错的时候会抛出异常,如果是老的项目里不抛出异常 |
| | | */ |
| | | @RequestMapping(value = "/gridRoles",method = RequestMethod.GET) |
| | | //@VciUnCheckRight |
| | | public BaseResult<SmRoleVO> gridRoles(BaseQueryObject queryObject) { |
| | | try { |
| | | if(queryObject == null){ |
| | | queryObject = new BaseQueryObject(); |
| | | } |
| | | //根据当前用户来决定能查那些角色 |
| | | String usertype = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUsertype(); |
| | | if(UserTypeEnum.SUPPER_ADMIN.getValue().equals(usertype)){ |
| | | queryObject.getConditionMap().put("pltype","1"); |
| | | }else { |
| | | queryObject.getConditionMap().put("pltype","2"); |
| | | } |
| | | DataGrid<SmRoleVO> roleVOData = roleQueryService.gridRoles(queryObject.getConditionMap(),queryObject.getPageHelper()); |
| | | return BaseResult.dataGrid(roleVOData); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 分配角色:保存用户角色关联关系 |
| | | * @param userOid |
| | | * @param roleIds |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/saveRights",method = RequestMethod.POST) |
| | | public BaseResult saveRights(String userOid, String[] roleIds){ |
| | | try { |
| | | return roleQueryService.saveRights(userOid,roleIds) ? BaseResult.success("角色分配成功!"):BaseResult.fail("角色分配失败!"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = VciBaseUtil.getExceptionMessage(e); |
| | | log.error("根据用户主键获取,关联的角色时出现错误,原因:" + exceptionMessage); |
| | | return BaseResult.fail("根据用户主键获取,关联的角色时出现错误,原因:" + exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 角色的树形参照 |
| | | * @param treeQueryObject 树形数据的查询对象,包括查询条件,上级主键,是否多选等,extandParamsMap中添加"showAllRoleNode"为"true"时,返回结果中会包含“所有角色”这个节点 |
| | | * @return 角色的树形参照,无上下级关系 |
| | |
| | | //BaseResult.fail("这里返回前端的错误信息"); |
| | | } |
| | | |
| | | /** |
| | | * 新增单条角色 |
| | | * @param smRoleDTO |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/addRole",method = RequestMethod.POST) |
| | | public BaseResult addRole(@RequestBody SmRoleDTO smRoleDTO){ |
| | | try { |
| | | return roleQueryService.addRole(smRoleDTO) ? BaseResult.success("角色添加成功!"):BaseResult.fail("角色添加失败!"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = VciBaseUtil.getExceptionMessage(e); |
| | | log.error("添加角色时出现错误,原因:" + exceptionMessage); |
| | | return BaseResult.fail("添加角色时出现错误,原因:" + exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改角色 |
| | | * @param smRoleDTO |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/updateRole",method = RequestMethod.PUT) |
| | | public BaseResult updateRole(@RequestBody SmRoleDTO smRoleDTO){ |
| | | try { |
| | | return roleQueryService.updateRole(smRoleDTO) ? BaseResult.success("角色修改成功!"):BaseResult.fail("角色修改失败!"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = VciBaseUtil.getExceptionMessage(e); |
| | | log.error("修改角色时出现错误,原因:" + exceptionMessage); |
| | | return BaseResult.fail("修改角色时出现错误,原因:" + exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除角色 |
| | | * @param ids |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/deleteRole",method = RequestMethod.DELETE) |
| | | public BaseResult deleteRole(String[] ids){ |
| | | try { |
| | | return roleQueryService.deleteRole(ids) ? BaseResult.success("删除用户成功!"):BaseResult.fail("删除用户失败!"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = VciBaseUtil.getExceptionMessage(e); |
| | | log.error("添加用户时出现错误,原因:" + exceptionMessage); |
| | | return BaseResult.fail("添加用户时出现错误,原因:" + exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 导入角色 |
| | | * @param file |
| | | * @return |
| | | * @throws VciBaseException |
| | | */ |
| | | @RequestMapping(value = "/importRole",method = RequestMethod.POST) |
| | | public BaseResult importRole(MultipartFile file){ |
| | | String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename()); |
| | | File file1 = new File(excelFileName); |
| | | try { |
| | | file.transferTo(new File(excelFileName)); |
| | | if (file != null) { |
| | | return roleQueryService.importRole(file1); |
| | | } else { |
| | | return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"无导入的文件"}); |
| | | } |
| | | }catch (Throwable e) { |
| | | throw new VciBaseException(e.getMessage(),new String[0],e); |
| | | }finally { |
| | | file1.delete(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 分配角色:保存用户角色关联关系,用户管理的分配角色和角色管理的分配成员共用 |
| | | * @param userOids |
| | | * @param roleIds |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = "/saveRights",method = RequestMethod.POST) |
| | | public BaseResult saveRights(String[] userOids, String[] roleIds){ |
| | | try { |
| | | return roleQueryService.saveRights(userOids,roleIds) ? BaseResult.success("角色分配成功!"):BaseResult.fail("角色分配失败!"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = VciBaseUtil.getExceptionMessage(e); |
| | | log.error("根据用户主键获取,关联的角色时出现错误,原因:" + exceptionMessage); |
| | | return BaseResult.fail("根据用户主键获取,关联的角色时出现错误,原因:" + exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | } |