| | |
| | | |
| | | import com.vci.frameworkcore.compatibility.SmRoleQueryServiceI; |
| | | 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.VciBaseUtil; |
| | | 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 java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 角色查询控制器 |
| | | * @author weidy |
| | | * @date 2020/3/4 |
| | | */ |
| | | @Controller |
| | | @RestController |
| | | @RequestMapping("/roleQueryController") |
| | | @Slf4j |
| | | public class SmRoleQueryController { |
| | | |
| | | /** |
| | |
| | | * @throws VciBaseException 查询出错的时候会抛出异常,如果是老的项目里不抛出异常 |
| | | */ |
| | | @RequestMapping(value = "/refDataGrid",method = RequestMethod.GET) |
| | | @ResponseBody |
| | | public BaseResult<SmRoleVO> refDataGrid(BaseQueryObject queryObject) throws VciBaseException { |
| | | if(queryObject == null){ |
| | | queryObject = new BaseQueryObject(); |
| | | public BaseResult<SmRoleVO> refDataGrid(BaseQueryObject queryObject) { |
| | | try { |
| | | if(queryObject == null){ |
| | | queryObject = new BaseQueryObject(); |
| | | } |
| | | DataGrid<SmRoleVO> roleVODataGrid = roleQueryService.refGridRoles(queryObject.getConditionMap(),queryObject.getPageHelper()); |
| | | return BaseResult.dataGrid(roleVODataGrid); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = VciBaseUtil.getExceptionMessage(e); |
| | | log.error("查询角色列表时出现错误,原因:" + exceptionMessage); |
| | | return BaseResult.fail("查询角色列表时出现错误,原因" + exceptionMessage); |
| | | } |
| | | DataGrid<SmRoleVO> roleVODataGrid = roleQueryService.refGridRoles(queryObject.getConditionMap(),queryObject.getPageHelper()); |
| | | return BaseResult.dataGrid(roleVODataGrid); |
| | | //如果是老的项目,应该在refGridRoles上添加try,catch,然后catch里应该使用下面的代码 |
| | | //BaseResult.fail("这里返回前端的错误信息"); |
| | | } |
| | | |
| | | /** |
| | | * 角色的列表查询:用于下拉,还有列表等全查询场景 |
| | | * @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(); |
| | | } |
| | | DataGrid<SmRoleVO> roleVOData = roleQueryService.gridRoles(queryObject.getConditionMap(),queryObject.getPageHelper()); |
| | | return BaseResult.dataGrid(roleVOData); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = VciBaseUtil.getExceptionMessage(e); |
| | | log.error("查询角色列表时出现错误,原因:" + exceptionMessage); |
| | | return BaseResult.fail("查询角色列表时出现错误,原因:"+exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据用户主键获取关联的角色 |
| | | * @param userOid 用户主键 |
| | | * @param queryMap 查询条件,如果需要使用用户的属性来查询可以使用pkUser.xxxx |
| | | * @return 角色的显示对象 |
| | | */ |
| | | @RequestMapping(value = "/listRoleByUserOid",method = RequestMethod.GET) |
| | | public BaseResult<List<SmRoleVO>> listRoleByUserOid(String userOid, Map<String, String> queryMap){ |
| | | try { |
| | | return BaseResult.dataList(roleQueryService.listRoleByUserOid(userOid,queryMap)); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | String exceptionMessage = VciBaseUtil.getExceptionMessage(e); |
| | | log.error("根据用户主键获取,关联的角色时出现错误,原因:" + exceptionMessage); |
| | | return BaseResult.fail("根据用户主键获取,关联的角色时出现错误,原因:" + exceptionMessage); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 分配角色:保存用户角色关联关系 |
| | | * @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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @throws VciBaseException 查询出错的时候会抛出异常,如果是老的项目里不抛出异常 |
| | | */ |
| | | @RequestMapping(value = "/refTree",method = RequestMethod.GET) |
| | | @ResponseBody |
| | | public BaseResult<Tree> refTree(TreeQueryObject treeQueryObject) throws VciBaseException{ |
| | | List<Tree> roleTreeList = roleQueryService.refTreeRoles(treeQueryObject); |
| | | return BaseResult.tree(roleTreeList); |