| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.service.GroupService; |
| | |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.PageResult; |
| | | import com.moral.util.WebUtils; |
| | | |
| | | @Slf4j |
| | | @Api(tags = {"组"}) |
| | | @Api(tags = {"组管理"}) |
| | | @RestController |
| | | @RequestMapping("/group") |
| | | public class GroupController { |
| | |
| | | |
| | | @ApiOperation(value = "删除组", notes = "删除组") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "组id", required = true, paramType = "query", dataType = "int"), |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "delete", method = RequestMethod.POST) |
| | | public ResultMessage delete(@RequestBody Group group) { |
| | | if (group.getId() == null) { |
| | | @RequestMapping(value = "delete", method = RequestMethod.GET) |
| | | public ResultMessage delete(Integer id) { |
| | | if (id == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | QueryWrapper<Group> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("id", group.getId()); |
| | | group = groupService.getOne(queryWrapper); |
| | | if (group == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode(), ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); |
| | | } |
| | | groupService.deleteGroup(group); |
| | | groupService.deleteGroup(id); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "update", method = RequestMethod.POST) |
| | | public ResultMessage update(@RequestBody Group group, HttpServletRequest request) { |
| | | String token = request.getHeader("token"); |
| | | public ResultMessage update(@RequestBody Group group) { |
| | | Map<String, Object> result = groupService.updateGroup(group); |
| | | if (!result.isEmpty()) { |
| | | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); |
| | |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), |
| | | @ApiImplicitParam(name = "groupName", value = "组名模糊查询", required = false, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "select", method = RequestMethod.POST) |
| | | public ResultMessage select(@RequestBody Map<String, Object> parameters) { |
| | | @RequestMapping(value = "select", method = RequestMethod.GET) |
| | | public ResultMessage select(HttpServletRequest request) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | Page<Group> userPage = groupService.selectGroups(parameters); |
| | | PageResult<Group> pageResult = new PageResult<>( |
| | | userPage.getTotal(), userPage.getPages(), userPage.getRecords() |
| | |
| | | return ResultMessage.ok(pageResult); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取用户所属组ids", notes = "获取用户所属组ids") |
| | | @ApiOperation(value = "获取用户组(角色)", notes = "获取用户组(角色)") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "userId", value = "用户id", required = true, paramType = "query", dataType = "int"), |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "get-group-ids", method = RequestMethod.GET) |
| | | public ResultMessage getGroupIds(Integer userId) { |
| | | List<Integer> groupIds = userGroupService.getGroupIds(userId); |
| | | return ResultMessage.ok(groupIds); |
| | | @RequestMapping(value = "getGroup", method = RequestMethod.GET) |
| | | public ResultMessage getGroup(Integer userId) { |
| | | if (ObjectUtils.isEmpty(userId)) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | Map<String, Object> group = groupService.getGroup(userId); |
| | | return ResultMessage.ok(group); |
| | | } |
| | | |
| | | @ApiOperation(value = "用户分配组", notes = "用户分配组") |