Java Code Examples for com.baomidou.mybatisplus.core.conditions.query.QueryWrapper#last()
The following examples show how to use
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper#last() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdminServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 6 votes |
@Override public Admin getAdminByUser(String userName) { QueryWrapper<Admin> queryWrapper = new QueryWrapper<>(); queryWrapper.eq(SQLConf.USER_NAME, userName); queryWrapper.last("LIMIT 1"); //清空密码,防止泄露 Admin admin = adminService.getOne(queryWrapper); admin.setPassWord(null); //获取图片 if (StringUtils.isNotEmpty(admin.getAvatar())) { String pictureList = this.pictureFeignClient.getPicture(admin.getAvatar(), ","); admin.setPhotoList(webUtil.getPicture(pictureList)); } Admin result = new Admin(); result.setNickName(admin.getNickName()); result.setOccupation(admin.getOccupation()); result.setSummary(admin.getSummary()); result.setAvatar(admin.getAvatar()); result.setPhotoList(admin.getPhotoList()); result.setPersonResume(admin.getPersonResume()); return result; }
Example 2
Source File: SysDictTypeServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 6 votes |
@Override public String addSysDictType(SysDictTypeVO sysDictTypeVO) { HttpServletRequest request = RequestHolder.getRequest(); // 判断添加的字典类型是否存在 QueryWrapper<SysDictType> queryWrapper = new QueryWrapper<>(); queryWrapper.eq(SQLConf.DICT_TYPE, sysDictTypeVO.getDictType()); queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); queryWrapper.last("LIMIT 1"); SysDictType temp = sysDictTypeService.getOne(queryWrapper); if (temp != null) { return ResultUtil.result(SysConf.ERROR, MessageConf.ENTITY_EXIST); } SysDictType sysDictType = new SysDictType(); sysDictType.setDictName(sysDictTypeVO.getDictName()); sysDictType.setDictType(sysDictTypeVO.getDictType()); sysDictType.setRemark(sysDictTypeVO.getRemark()); sysDictType.setIsPublish(sysDictTypeVO.getIsPublish()); sysDictType.setSort(sysDictTypeVO.getSort()); sysDictType.setCreateByUid(request.getAttribute(SysConf.ADMIN_UID).toString()); sysDictType.setUpdateByUid(request.getAttribute(SysConf.ADMIN_UID).toString()); sysDictType.insert(); return ResultUtil.result(SysConf.SUCCESS, MessageConf.INSERT_SUCCESS); }
Example 3
Source File: SysDictDataServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@Override public String addSysDictData(SysDictDataVO sysDictDataVO) { HttpServletRequest request = RequestHolder.getRequest(); String adminUid = request.getAttribute(SysConf.ADMIN_UID).toString(); // 判断添加的字典数据是否存在 QueryWrapper<SysDictData> queryWrapper = new QueryWrapper<>(); queryWrapper.eq(SQLConf.DICT_LABEL, sysDictDataVO.getDictLabel()); queryWrapper.eq(SQLConf.DICT_TYPE_UID, sysDictDataVO.getDictTypeUid()); queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); queryWrapper.last("LIMIT 1"); SysDictData temp = sysDictDataService.getOne(queryWrapper); if (temp != null) { return ResultUtil.result(SysConf.ERROR, MessageConf.ENTITY_EXIST); } SysDictData sysDictData = new SysDictData(); sysDictData.setDictLabel(sysDictDataVO.getDictLabel()); sysDictData.setDictTypeUid(sysDictDataVO.getDictTypeUid()); sysDictData.setDictValue(sysDictDataVO.getDictValue()); sysDictData.setIsDefault(sysDictDataVO.getIsDefault()); sysDictData.setCssClass(sysDictDataVO.getCssClass()); sysDictData.setListClass(sysDictDataVO.getListClass()); sysDictData.setRemark(sysDictDataVO.getRemark()); sysDictData.setIsPublish(sysDictDataVO.getIsPublish()); sysDictData.setSort(sysDictDataVO.getSort()); sysDictData.setCreateByUid(adminUid); sysDictData.setUpdateByUid(adminUid); sysDictData.insert(); return ResultUtil.result(SysConf.SUCCESS, MessageConf.INSERT_SUCCESS); }
Example 4
Source File: SysDictDataServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@Override public String editSysDictData(SysDictDataVO sysDictDataVO) { HttpServletRequest request = RequestHolder.getRequest(); String adminUid = request.getAttribute(SysConf.ADMIN_UID).toString(); SysDictData sysDictData = sysDictDataService.getById(sysDictDataVO.getUid()); // 更改了标签名时,判断更改的字典数据是否存在 if (!sysDictData.getDictLabel().equals(sysDictDataVO.getDictLabel())) { QueryWrapper<SysDictData> queryWrapper = new QueryWrapper<>(); queryWrapper.eq(SQLConf.DICT_LABEL, sysDictDataVO.getDictLabel()); queryWrapper.eq(SQLConf.DICT_TYPE_UID, sysDictDataVO.getDictTypeUid()); queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); queryWrapper.last("LIMIT 1"); SysDictData temp = sysDictDataService.getOne(queryWrapper); if (temp != null) { return ResultUtil.result(SysConf.ERROR, MessageConf.ENTITY_EXIST); } } sysDictData.setDictLabel(sysDictDataVO.getDictLabel()); sysDictData.setDictTypeUid(sysDictDataVO.getDictTypeUid()); sysDictData.setDictValue(sysDictDataVO.getDictValue()); sysDictData.setIsDefault(sysDictDataVO.getIsDefault()); sysDictData.setCssClass(sysDictDataVO.getCssClass()); sysDictData.setListClass(sysDictDataVO.getListClass()); sysDictData.setRemark(sysDictDataVO.getRemark()); sysDictData.setSort(sysDictDataVO.getSort()); sysDictData.setIsPublish(sysDictDataVO.getIsPublish()); sysDictData.setCreateByUid(adminUid); sysDictData.setUpdateByUid(adminUid); sysDictData.setUpdateTime(new Date()); sysDictData.updateById(); // 获取Redis中特定前缀 Set<String> keys = redisUtil.keys(SysConf.REDIS_DICT_TYPE + SysConf.REDIS_SEGMENTATION + "*"); redisUtil.delete(keys); return ResultUtil.result(SysConf.SUCCESS, MessageConf.UPDATE_SUCCESS); }
Example 5
Source File: SysDictDataServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@Override public Map<String, Object> getListByDictType(String dictType) { //从Redis中获取内容 String jsonResult = redisUtil.get(SysConf.REDIS_DICT_TYPE + SysConf.REDIS_SEGMENTATION + dictType); //判断redis中是否有字典 if (StringUtils.isNotEmpty(jsonResult)) { Map<String, Object> map = JsonUtils.jsonToMap(jsonResult); return map; } QueryWrapper<SysDictType> queryWrapper = new QueryWrapper<>(); queryWrapper.eq(SQLConf.DICT_TYPE, dictType); queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); queryWrapper.eq(SQLConf.IS_PUBLISH, EPublish.PUBLISH); queryWrapper.last("LIMIT 1"); SysDictType sysDictType = sysDictTypeService.getOne(queryWrapper); if (sysDictType == null) { return new HashMap<>(); } QueryWrapper<SysDictData> sysDictDataQueryWrapper = new QueryWrapper<>(); sysDictDataQueryWrapper.eq(SQLConf.IS_PUBLISH, EPublish.PUBLISH); sysDictDataQueryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); sysDictDataQueryWrapper.eq(SQLConf.DICT_TYPE_UID, sysDictType.getUid()); sysDictDataQueryWrapper.orderByDesc(SQLConf.SORT, SQLConf.CREATE_TIME); List<SysDictData> list = sysDictDataService.list(sysDictDataQueryWrapper); String defaultValue = null; for (SysDictData sysDictData : list) { // 获取默认值 if (sysDictData.getIsDefault() == SysConf.ONE) { defaultValue = sysDictData.getDictValue(); break; } } Map<String, Object> result = new HashMap<>(); result.put(SysConf.DEFAULT_VALUE, defaultValue); result.put(SysConf.LIST, list); redisUtil.setEx(SysConf.REDIS_DICT_TYPE + SysConf.REDIS_SEGMENTATION + dictType, JsonUtils.objectToJson(result).toString(), 1, TimeUnit.DAYS); return result; }
Example 6
Source File: TagServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@Override public Tag getTopTag() { QueryWrapper<Tag> tagQueryWrapper = new QueryWrapper<>(); tagQueryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); tagQueryWrapper.last("LIMIT 1"); tagQueryWrapper.orderByDesc(SQLConf.SORT); Tag tag = tagService.getOne(tagQueryWrapper); return tag; }
Example 7
Source File: CategoryMenuServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@Override public String stickCategoryMenu(CategoryMenuVO categoryMenuVO) { CategoryMenu categoryMenu = categoryMenuService.getById(categoryMenuVO.getUid()); //查找出最大的那一个 QueryWrapper<CategoryMenu> queryWrapper = new QueryWrapper<>(); //如果是二级菜单 或者 按钮,就在当前的兄弟中,找出最大的一个 if (categoryMenu.getMenuLevel() == 2 || categoryMenu.getMenuType() == EMenuType.BUTTON) { queryWrapper.eq(SQLConf.PARENT_UID, categoryMenu.getParentUid()); } queryWrapper.eq(SQLConf.MENU_LEVEL, categoryMenu.getMenuLevel()); queryWrapper.orderByDesc(SQLConf.SORT); queryWrapper.last("limit 1"); CategoryMenu maxSort = categoryMenuService.getOne(queryWrapper); if (StringUtils.isEmpty(maxSort.getUid())) { return ResultUtil.result(SysConf.ERROR, MessageConf.OPERATION_FAIL); } Integer sortCount = maxSort.getSort() + 1; categoryMenu.setSort(sortCount); categoryMenu.setUpdateTime(new Date()); categoryMenu.updateById(); return ResultUtil.result(SysConf.SUCCESS, MessageConf.OPERATION_SUCCESS); }
Example 8
Source File: PictureServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@Override public Picture getTopOne() { QueryWrapper<Picture> queryWrapper = new QueryWrapper<>(); queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); queryWrapper.orderByAsc(SQLConf.CREATE_TIME); queryWrapper.last(SysConf.LIMIT_ONE); Picture picture = pictureService.getOne(queryWrapper); return picture; }
Example 9
Source File: SysDictTypeServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@Override public String editSysDictType(SysDictTypeVO sysDictTypeVO) { HttpServletRequest request = RequestHolder.getRequest(); SysDictType sysDictType = sysDictTypeService.getById(sysDictTypeVO.getUid()); // 判断编辑的字典类型是否存在 if (!sysDictType.getDictType().equals(sysDictTypeVO.getDictType())) { QueryWrapper<SysDictType> queryWrapper = new QueryWrapper<>(); queryWrapper.eq(SQLConf.DICT_TYPE, sysDictTypeVO.getDictType()); queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); queryWrapper.last("LIMIT 1"); SysDictType temp = sysDictTypeService.getOne(queryWrapper); if (temp != null) { return ResultUtil.result(SysConf.ERROR, MessageConf.ENTITY_EXIST); } } sysDictType.setDictName(sysDictTypeVO.getDictName()); sysDictType.setDictType(sysDictTypeVO.getDictType()); sysDictType.setRemark(sysDictTypeVO.getRemark()); sysDictType.setIsPublish(sysDictTypeVO.getIsPublish()); sysDictType.setSort(sysDictTypeVO.getSort()); sysDictType.setUpdateByUid(request.getAttribute(SysConf.ADMIN_UID).toString()); sysDictType.setUpdateTime(new Date()); sysDictType.updateById(); // 获取Redis中特定前缀 Set<String> keys = redisUtil.keys(SysConf.REDIS_DICT_TYPE + SysConf.REDIS_SEGMENTATION + "*"); redisUtil.delete(keys); return ResultUtil.result(SysConf.SUCCESS, MessageConf.UPDATE_SUCCESS); }
Example 10
Source File: BlogSortServiceImpl.java From mogu_blog_v2 with Apache License 2.0 | 5 votes |
@Override public BlogSort getTopOne() { QueryWrapper<BlogSort> blogSortQueryWrapper = new QueryWrapper<>(); blogSortQueryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); blogSortQueryWrapper.last("LIMIT 1"); blogSortQueryWrapper.orderByDesc(SQLConf.SORT); BlogSort blogSort = blogSortService.getOne(blogSortQueryWrapper); return blogSort; }
Example 11
Source File: TopicService.java From pybbs with GNU Affero General Public License v3.0 | 5 votes |
@Override public List<Topic> selectAuthorOtherTopic(Integer userId, Integer topicId, Integer limit) { QueryWrapper<Topic> wrapper = new QueryWrapper<>(); wrapper.eq("user_id", userId).orderByDesc("in_time"); if (topicId != null) { wrapper.lambda().ne(Topic::getId, topicId); } if (limit != null) wrapper.last("limit " + limit); return topicMapper.selectList(wrapper); }
Example 12
Source File: LoginRestApi.java From mogu_blog_v2 with Apache License 2.0 | 4 votes |
@ApiOperation(value = "用户登录", notes = "用户登录") @PostMapping("/login") public String login(@Validated({GetOne.class}) @RequestBody UserVO userVO, BindingResult result) { ThrowableUtils.checkParamArgument(result); String userName = userVO.getUserName(); QueryWrapper<User> queryWrapper = new QueryWrapper<>(); queryWrapper.and(wrapper -> wrapper.eq(SQLConf.USER_NAME, userName).or().eq(SQLConf.EMAIL, userName)); queryWrapper.last("limit 1"); User user = userService.getOne(queryWrapper); if (user == null || EStatus.DISABLED == user.getStatus()) { return ResultUtil.result(SysConf.ERROR, "用户不存在"); } if (EStatus.FREEZE == user.getStatus()) { return ResultUtil.result(SysConf.ERROR, "用户账号未激活"); } if (StringUtils.isNotEmpty(user.getPassWord()) && user.getPassWord().equals(MD5Utils.string2MD5(userVO.getPassWord()))) { // 更新登录信息 HttpServletRequest request = RequestHolder.getRequest(); String ip = IpUtils.getIpAddr(request); Map<String, String> userMap = IpUtils.getOsAndBrowserInfo(request); user.setBrowser(userMap.get(SysConf.BROWSER)); user.setOs(userMap.get(SysConf.OS)); user.setLastLoginIp(ip); user.setLastLoginTime(new Date()); user.updateById(); // 获取用户头像 if (!StringUtils.isEmpty(user.getAvatar())) { String avatarResult = pictureFeignClient.getPicture(user.getAvatar(), ","); List<String> picList = webUtil.getPicture(avatarResult); if (picList != null && picList.size() > 0) { user.setPhotoUrl(webUtil.getPicture(avatarResult).get(0)); } } // 生成token String token = StringUtils.getUUID(); // 过滤密码 user.setPassWord(""); //将从数据库查询的数据缓存到redis中 redisUtil.setEx(SysConf.USER_TOEKN + SysConf.REDIS_SEGMENTATION + token, JsonUtils.objectToJson(user), userTokenSurvivalTime, TimeUnit.HOURS); return ResultUtil.result(SysConf.SUCCESS, token); } else { return ResultUtil.result(SysConf.ERROR, "账号或密码错误"); } }
Example 13
Source File: AuthRestApi.java From mogu_blog_v2 with Apache License 2.0 | 4 votes |
private void updateUserPhoto(Map<String, Object> data, User user) { QueryWrapper<SystemConfig> queryWrapper = new QueryWrapper<>(); queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); queryWrapper.last("LIMIT 1"); Map<String, Object> systemConfigMap = systemConfigService.getMap(queryWrapper); // 获取到头像,然后上传到自己服务器 FileVO fileVO = new FileVO(); fileVO.setAdminUid(SysConf.DEFAULT_UID); fileVO.setUserUid(SysConf.DEFAULT_UID); fileVO.setProjectName(SysConf.BLOG); fileVO.setSortName(SysConf.ADMIN); fileVO.setSystemConfig(systemConfigMap); List<String> urlList = new ArrayList<>(); urlList.add(data.get(SysConf.AVATAR).toString()); fileVO.setUrlList(urlList); String res = this.pictureFeignClient.uploadPicsByUrl(fileVO); Map<String, Object> resultMap = JsonUtils.jsonToMap(res); if (resultMap.get(SysConf.CODE) != null && SysConf.SUCCESS.equals(resultMap.get(SysConf.CODE).toString())) { if (resultMap.get(SysConf.DATA) != null) { List<Map<String, Object>> listMap = (List<Map<String, Object>>) resultMap.get(SysConf.DATA); if (listMap != null && listMap.size() > 0) { Map<String, Object> pictureMap = listMap.get(0); String localPictureBaseUrl = systemConfigMap.get(SQLConf.LOCAL_PICTURE_BASE_URL).toString(); String qiNiuPictureBaseUrl = systemConfigMap.get(SQLConf.QI_NIU_PICTURE_BASE_URL).toString(); String picturePriority = systemConfigMap.get(SQLConf.PICTURE_PRIORITY).toString(); user.setAvatar(pictureMap.get(SysConf.UID).toString()); // 判断图片优先展示 if ("1".equals(picturePriority)) { // 使用七牛云 if (pictureMap != null && pictureMap.get(SysConf.QI_NIU_URL) != null && pictureMap.get(SysConf.UID) != null) { user.setPhotoUrl(qiNiuPictureBaseUrl + pictureMap.get(SysConf.QI_NIU_URL).toString()); } } else { // 使用自建图片服务器 if (pictureMap != null && pictureMap.get(SysConf.PIC_URL) != null && pictureMap.get(SysConf.UID) != null) { user.setPhotoUrl(localPictureBaseUrl + pictureMap.get(SysConf.PIC_URL).toString()); } } } } } }
Example 14
Source File: AuthRestApi.java From mogu_blog_v2 with Apache License 2.0 | 4 votes |
@ApiOperation(value = "申请友链", notes = "申请友链") @PostMapping("/replyBlogLink") public String replyBlogLink(HttpServletRequest request, @RequestBody LinkVO linkVO) { if (request.getAttribute(SysConf.USER_UID) == null) { return ResultUtil.result(SysConf.ERROR, MessageConf.INVALID_TOKEN); } String userUid = request.getAttribute(SysConf.USER_UID).toString(); User user = userService.getById(userUid); // 判断该用户是否被禁言,被禁言的用户,也无法进行友链申请操作 if (user != null && user.getCommentStatus() == SysConf.ZERO) { return ResultUtil.result(SysConf.ERROR, MessageConf.YOU_DONT_HAVE_PERMISSION_TO_REPLY); } // 判断是否开启邮件通知 SystemConfig systemConfig = systemConfigService.getConfig(); if (systemConfig != null && EOpenStatus.OPEN.equals(systemConfig.getStartEmailNotification())) { if (StringUtils.isNotEmpty(systemConfig.getEmail())) { log.info("发送友链申请邮件通知"); String feedback = "收到新的友链申请: " + "<br />" + "名称:" + linkVO.getTitle() + "<br />" + "简介:" + linkVO.getSummary() + "<br />" + "地址:" + linkVO.getUrl(); rabbitMqUtil.sendSimpleEmail(systemConfig.getEmail(), feedback); } else { log.error("网站没有配置通知接收的邮箱地址!"); } } QueryWrapper<Link> queryWrapper = new QueryWrapper<>(); queryWrapper.eq(SQLConf.USER_UID, userUid); queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE); queryWrapper.eq(SQLConf.TITLE, linkVO.getTitle()); queryWrapper.last("LIMIT 1"); Link existLink = linkService.getOne(queryWrapper); if (existLink != null) { Integer linkStatus = existLink.getLinkStatus(); String message = ""; switch (linkStatus) { case 0: { message = MessageConf.BLOG_LINK_IS_EXIST; } break; case 1: { message = MessageConf.BLOG_LINK_IS_PUBLISH; } break; case 2: { message = MessageConf.BLOG_LINK_IS_NO_PUBLISH; } break; } return ResultUtil.result(SysConf.ERROR, message); } Link link = new Link(); link.setLinkStatus(ELinkStatus.APPLY); link.setTitle(linkVO.getTitle()); link.setSummary(linkVO.getSummary()); link.setUrl(linkVO.getUrl()); link.setClickCount(0); link.setSort(0); link.setStatus(EStatus.ENABLE); link.setUserUid(userUid); link.insert(); return ResultUtil.result(SysConf.SUCCESS, MessageConf.OPERATION_SUCCESS); }