Java Code Examples for cn.hutool.core.date.DateUtil#thisMonth()
The following examples show how to use
cn.hutool.core.date.DateUtil#thisMonth() .
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: CommonUtils.java From feiqu-opensource with Apache License 2.0 | 6 votes |
public static void addActiveNum(Integer userId,double score){ int month = DateUtil.thisMonth()+1; String key = CommonConstant.FQ_ACTIVE_USER_SORT+month; try { JedisCommands commands = JedisProviderFactory.getJedisCommands(null); Double scoreStore = commands.zscore(key,userId.toString()); if(scoreStore == null){ scoreStore = score; }else { scoreStore += score; } commands.zadd(key,scoreStore,userId.toString()); commands.expire(key,180*24*60*60); } catch (Exception e) { logger.error(e); }finally { JedisProviderFactory.getJedisProvider(null).release(); } }
Example 2
Source File: CommonController.java From feiqu-opensource with Apache License 2.0 | 5 votes |
@PostMapping("findActiveUserNames") @ResponseBody public Object findActiveUserNames(){ BaseResult result = new BaseResult(); try {int month = DateUtil.thisMonth()+1; JedisCommands commands = JedisProviderFactory.getJedisCommands(null); String key = "activeUserNames"+month; Set<String> activeNames = commands.smembers(key); if(CollectionUtil.isEmpty(activeNames)){ Set<String> userIds =commands.zrevrange(CommonConstant.FQ_ACTIVE_USER_SORT+month,0,9); if(CollectionUtils.isNotEmpty(userIds)){ List<Integer> userIdList = Lists.newArrayList(); for(String userId : userIds){ userIdList.add(Integer.valueOf(userId)); } FqUserExample example = new FqUserExample(); example.createCriteria().andIdIn(userIdList); List<FqUser> fqUsers = fqUserService.selectByExample(example); List<String> names = fqUsers.stream().map(FqUser::getNickname).collect(Collectors.toList()); result.setData(names); commands.sadd(key,names.toArray(new String[names.size()])); commands.expire(key,7*24*60*60); } }else { result.setData(activeNames); } } catch (Exception e) { logger.error("获取活跃用户信息报错",e); } finally { JedisProviderFactory.getJedisProvider(null).release(); } return result; }
Example 3
Source File: UserController.java From feiqu-opensource with Apache License 2.0 | 5 votes |
@GetMapping("upLevel") public String upLevel(Model model){ FqUserCache fqUserCache = getCurrentUser(); int month = DateUtil.thisMonth()+1; int lastMonth = month == 1? 12 : month-1; JedisCommands commands = JedisProviderFactory.getJedisCommands(null); Double score = commands.zscore(CommonConstant.FQ_ACTIVE_USER_SORT+month,fqUserCache.getId().toString()); Double lastMonthScore = commands.zscore(CommonConstant.FQ_ACTIVE_USER_SORT+lastMonth,fqUserCache.getId().toString()); Double totolScore = (score == null?0:score)+(lastMonthScore==null?0:lastMonthScore); model.addAttribute("totolScore",totolScore); return "/user/upLevel.html"; }
Example 4
Source File: AttachmentServiceImpl.java From SENS with GNU General Public License v3.0 | 4 votes |
/** * 又拍云上传 * * @param file file * @param request request * @return Map */ @Override public Map<String, String> attachUpYunUpload(MultipartFile file, HttpServletRequest request) { final Map<String, String> resultMap = new HashMap<>(6); try { String key = "uploads/" + DateUtil.thisYear() + "/" + (DateUtil.thisMonth() + 1) + "/" + Md5Util.getMD5Checksum(file); final String ossSrc = SensConst.OPTIONS.get("upyun_oss_src"); final String ossPwd = SensConst.OPTIONS.get("upyun_oss_pwd"); final String bucket = SensConst.OPTIONS.get("upyun_oss_bucket"); final String domain = SensConst.OPTIONS.get("upyun_oss_domain"); final String operator = SensConst.OPTIONS.get("upyun_oss_operator"); final String smallUrl = SensConst.OPTIONS.get("upyun_oss_small"); if (StrUtil.isEmpty(ossSrc) || StrUtil.isEmpty(ossPwd) || StrUtil.isEmpty(domain) || StrUtil.isEmpty(bucket) || StrUtil.isEmpty(operator)) { return resultMap; } final String fileName = file.getOriginalFilename(); final String fileSuffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf('.')); final UpYun upYun = new UpYun(bucket, operator, ossPwd); upYun.setTimeout(60); upYun.setApiDomain(UpYun.ED_AUTO); upYun.setDebug(true); upYun.writeFile(ossSrc + key + fileSuffix, file.getBytes(), true, null); final String filePath = domain.trim() + ossSrc + key + fileSuffix; String smallPath = filePath; if (smallUrl != null) { smallPath += smallUrl; } final BufferedImage image = ImageIO.read(file.getInputStream()); if (image != null) { resultMap.put("wh", image.getWidth() + "x" + image.getHeight()); } resultMap.put("fileName", fileName); resultMap.put("filePath", filePath.trim()); resultMap.put("smallPath", smallPath.trim()); resultMap.put("suffix", fileSuffix); resultMap.put("size", SensUtils.parseSize(file.getSize())); resultMap.put("location", AttachLocationEnum.UPYUN.getValue()); } catch (Exception e) { e.printStackTrace(); } return resultMap; }
Example 5
Source File: HotContentJob.java From feiqu-opensource with Apache License 2.0 | 4 votes |
@Scheduled(cron = "0 0/30 9-18 * * ? ")//从9点到18点 每半个小时更新一次 // @Scheduled(cron = "0 51 15 * * ? ") public void work(){ Stopwatch stopwatch = Stopwatch.createStarted(); PageHelper.startPage(1, 5 , false); ThoughtExample thoughtExample = new ThoughtExample(); thoughtExample.setOrderByClause("create_time desc"); thoughtExample.createCriteria().andDelFlagEqualTo(YesNoEnum.NO.getValue()); List<ThoughtWithUser> newThoughts = thoughtService.getThoughtWithUser(thoughtExample); if(CollectionUtil.isNotEmpty(newThoughts)){ newThoughts.forEach(t->{ if(StringUtils.isNotEmpty(t.getPicList())){ t.setPictures(Arrays.asList(t.getPicList().split(","))); } }); } CommonConstant.NEW_THOUGHT_LIST = newThoughts; PageHelper.startPage(1, 5 , false); thoughtExample.clear(); thoughtExample.setOrderByClause("comment_count desc "); thoughtExample.createCriteria().andDelFlagEqualTo(YesNoEnum.NO.getValue()); CommonConstant.HOT_THOUGHT_LIST = thoughtService.getThoughtWithUser(thoughtExample); ArticleExample example = new ArticleExample(); example.setOrderByClause("browse_count desc"); example.createCriteria().andCreateTimeGreaterThan(DateUtil.offsetDay(new Date(),-31)); PageHelper.startPage(0,10,false); List<Article> hotArticles = articleService.selectByExample(example); /*for(Article article : hotArticles){ if(article.getArticleTitle().length() > 20){ article.setArticleTitle(StringUtils.substring(article.getArticleTitle(),0,20) + "……"); } }*/ if(CollectionUtil.isNotEmpty(hotArticles)){ CommonConstant.HOT_ARTICLE_LIST = hotArticles; } FqNoticeExample fqNoticeExample = new FqNoticeExample(); fqNoticeExample.setOrderByClause("fq_order asc"); fqNoticeExample.createCriteria().andIsShowEqualTo(YesNoEnum.YES.getValue()); List<FqNotice> list = fqNoticeService.selectByExample(fqNoticeExample); if(CollectionUtil.isNotEmpty(list)){ CommonConstant.FQ_NOTICE_LIST = list; } PageHelper.startPage(0,5,false); SuperBeautyExample beautyExample = new SuperBeautyExample(); beautyExample.setOrderByClause("like_count desc"); List<BeautyUserResponse> beauties = superBeautyService.selectDetailByExample(beautyExample); if(CollectionUtil.isNotEmpty(beauties)){ CommonConstant.HOT_BEAUTY_LIST = beauties; } try { int month = DateUtil.thisMonth()+1; JedisCommands commands = JedisProviderFactory.getJedisCommands(null); Set<String> userIds =commands.zrevrange(CommonConstant.FQ_ACTIVE_USER_SORT+month,0,4); if(CollectionUtils.isNotEmpty(userIds)){ List<Integer> userIdList = Lists.newArrayList(); for(String userId : userIds){ userIdList.add(Integer.valueOf(userId)); } FqUserExample fqUserExample = new FqUserExample(); example.createCriteria().andIdIn(userIdList); List<FqUser> fqUsers = fqUserService.selectByExample(fqUserExample); Map<Integer,FqUser> userMap = Maps.newHashMap(); fqUsers.forEach(fqUser -> { userMap.put(fqUser.getId(),fqUser); }); List<UserActiveNumResponse> responses = Lists.newArrayList(); for(int i = 0;i<userIdList.size();i++){ double score = commands.zscore(CommonConstant.FQ_ACTIVE_USER_SORT+month,userIdList.get(i).toString()); if(userMap.get(userIdList.get(i)) == null){ continue; } UserActiveNumResponse userActiveNumResponse = new UserActiveNumResponse(userMap.get(userIdList.get(i)),score,i+1); responses.add(userActiveNumResponse); } CommonConstant.FQ_ACTIVE_USER_LIST = responses; } } catch (Exception e) { logger.error("",e); } Runtime runtime = Runtime.getRuntime(); String memoryInfo ="freeMemory:"+runtime.freeMemory()+",totalMemory:"+runtime.totalMemory(); stopwatch.stop(); long seconds = stopwatch.elapsed(TimeUnit.SECONDS); logger.info("热门文章以及通知以及热门图片更新完毕,耗时{}秒,内存信息:{}",seconds,memoryInfo); }
Example 6
Source File: DailyOnceJob.java From feiqu-opensource with Apache License 2.0 | 4 votes |
@Scheduled(cron = "30 0 0 * * ? ") public void activeCount(){ Stopwatch stopwatch = Stopwatch.createStarted(); try { Date now = new Date(); int day = DateUtil.dayOfMonth(now); DateTime tbegin = DateUtil.beginOfDay(now); DateTime ybegin = DateUtil.beginOfDay(DateUtil.yesterday()); boolean isfirstDay = day == 1; int month = DateUtil.thisMonth()+1; JedisCommands commands = JedisProviderFactory.getJedisCommands(null); Set<String> userIds =commands.zrevrange(CommonConstant.FQ_ACTIVE_USER_SORT+month,0,-1); if(CollectionUtils.isNotEmpty(userIds)){ List<Integer> userIdList = Lists.newArrayList(); for(String userId : userIds){ userIdList.add(Integer.valueOf(userId)); } FqUserExample fqUserExample = new FqUserExample(); fqUserExample.createCriteria().andIdIn(userIdList); List<FqUser> fqUsers = fqUserService.selectByExample(fqUserExample); Map<Integer,FqUser> userMap = Maps.newHashMap(); fqUsers.forEach(fqUser -> { userMap.put(fqUser.getId(),fqUser); }); FqUserActiveNumExample example = new FqUserActiveNumExample(); for(int i = 0;i<userIdList.size();i++){ Double score = commands.zscore(CommonConstant.FQ_ACTIVE_USER_SORT+month,userIdList.get(i).toString()); if(isfirstDay){ FqUserActiveNum fqUserActiveNum = new FqUserActiveNum(); fqUserActiveNum.setGmtCreate(now); fqUserActiveNum.setActiveNum(score == null ? 0 : score.intValue()); fqUserActiveNum.setUserId(userIdList.get(i)); fqUserActiveNum.setMark(userMap.get(userIdList.get(i)).getNickname()+":当天活跃度:"+fqUserActiveNum.getActiveNum()); fqUserActiveNumService.insert(fqUserActiveNum); }else { example.clear(); example.createCriteria().andUserIdEqualTo(userIdList.get(i)).andGmtCreateBetween(ybegin.toJdkDate(),tbegin.toJdkDate()); FqUserActiveNum yesactive = fqUserActiveNumService.selectFirstByExample(example); if(yesactive == null){ yesactive = new FqUserActiveNum(); yesactive.setGmtCreate(now); yesactive.setActiveNum(score == null ? 0 : score.intValue()); yesactive.setUserId(userIdList.get(i)); yesactive.setMark(userMap.get(userIdList.get(i)).getNickname()+":当天活跃度:"+yesactive.getActiveNum()); fqUserActiveNumService.insert(yesactive); }else { //如果昨天的和今天的数据不一样 进行插入 if(yesactive.getActiveNum() != score.intValue()){ yesactive = new FqUserActiveNum(); yesactive.setGmtCreate(now); yesactive.setActiveNum(score.intValue() - yesactive.getActiveNum()); yesactive.setUserId(userIdList.get(i)); yesactive.setMark(userMap.get(userIdList.get(i)).getNickname()+":当天活跃度:"+yesactive.getActiveNum()); fqUserActiveNumService.insert(yesactive); } } } } } } catch (Exception e) { logger.error("活跃度计算出错!",e); }finally { JedisProviderFactory.getJedisProvider(null).release(); } stopwatch.stop(); long seconds = stopwatch.elapsed(TimeUnit.SECONDS); logger.info("活跃度计算完毕,耗时{}秒",seconds); }
Example 7
Source File: UserController.java From feiqu-opensource with Apache License 2.0 | 4 votes |
@PostMapping("upLevel") @ResponseBody public BaseResult upLevelGo(){ BaseResult result = new BaseResult(); try { FqUserCache fqUserCache = getCurrentUser(); if(fqUserCache == null){ result.setResult(ResultEnum.USER_NOT_LOGIN); return result; } int originLevel = fqUserCache.getLevel() == null?1:fqUserCache.getLevel(); int needActiveNum = 0; switch (originLevel){ case 1:needActiveNum = 300;break; case 2:needActiveNum = 800;break; case 3:needActiveNum = 1500;break; case 4:needActiveNum = 3000;break; default:needActiveNum = 300;break; } int month = DateUtil.thisMonth()+1; int lastMonth = month == 1? 12 : month-1; JedisCommands commands = JedisProviderFactory.getJedisCommands(null); Double score = commands.zscore(CommonConstant.FQ_ACTIVE_USER_SORT+month,fqUserCache.getId().toString()); Double lastMonthScore = commands.zscore(CommonConstant.FQ_ACTIVE_USER_SORT+lastMonth,fqUserCache.getId().toString()); Double totolScore = (score == null?0:score)+(lastMonthScore==null?0:lastMonthScore); if(totolScore < needActiveNum){ result.setResult(ResultEnum.PARAM_ERROR); result.setMessage("活跃度不足"); return result; } FqUser toUpdate = new FqUser(); toUpdate.setId(fqUserCache.getId()); toUpdate.setLevel(originLevel+1); userService.updateByPrimaryKeySelective(toUpdate); CacheManager.refreshUserCacheByUid(fqUserCache.getId()); commands.zadd(CommonConstant.FQ_ACTIVE_USER_SORT+month,totolScore.intValue()-needActiveNum,fqUserCache.getId().toString()); result.setData(originLevel+1); } catch (Exception e) { result.setResult(ResultEnum.FAIL); logger.error("升级报错",e); }finally { JedisProviderFactory.getJedisProvider(null).release(); } return result; }
Example 8
Source File: ThoughtController.java From feiqu-opensource with Apache License 2.0 | 4 votes |
@GetMapping(value = "/{thoughtId}") public String commentList(Model model, @PathVariable Integer thoughtId){ try { FqUserCache fqUserCache = getCurrentUser(); Thought thought = thoughtService.selectByPrimaryKey(thoughtId); FqUser thoughtUser = null; if(thought != null){ thoughtUser = fqUserService.selectByPrimaryKey(thought.getUserId()); ThoughtWithUser thoughtWithUser = new ThoughtWithUser(thought); model.addAttribute("thought",thoughtWithUser); model.addAttribute("oUser",thoughtUser); }else { return "/404.html"; } //如果想法被删除 if(YesNoEnum.YES.getValue().equals(thought.getDelFlag())){ return "/topic-deleted.html"; } boolean isCollected = false; if(fqUserCache != null){ FqCollectExample fqCollectExample = new FqCollectExample(); fqCollectExample.createCriteria().andDelFlagEqualTo(YesNoEnum.NO.getValue()) .andUserIdEqualTo(fqUserCache.getId()).andTopicIdEqualTo(thoughtId) .andTopicTypeEqualTo(TopicTypeEnum.THOUGHT_TYPE.getValue()); FqCollect fqCollect = fqCollectService.selectFirstByExample(fqCollectExample); if(fqCollect != null){ isCollected = true; } } model.addAttribute("isCollected",isCollected); GeneralCommentExample commentExample = new GeneralCommentExample(); commentExample.setOrderByClause("create_time asc"); commentExample.createCriteria().andTopicIdEqualTo(thoughtId) .andTopicTypeEqualTo(TopicTypeEnum.THOUGHT_TYPE.getValue()) .andDelFlagEqualTo(YesNoEnum.NO.getValue()); List<DetailCommentResponse> comments = commentService.selectUserByExample(commentExample); model.addAttribute("comments",comments); model.addAttribute("count",comments.size()); ThoughtExample thoughtExample = new ThoughtExample(); thoughtExample.setOrderByClause("create_time desc"); thoughtExample.createCriteria().andDelFlagEqualTo(YesNoEnum.NO.getValue()) .andUserIdEqualTo(thought.getUserId()) .andIdNotEqualTo(thoughtId); PageHelper.startPage(1,10,false); List<Thought> theirThoughts = thoughtService.selectByExample(thoughtExample); model.addAttribute("theirThoughts",theirThoughts); int month = DateUtil.thisMonth()+1; JedisCommands commands = JedisProviderFactory.getJedisCommands(null); Double score = commands.zscore(CommonConstant.FQ_ACTIVE_USER_SORT+month,thoughtUser.getId().toString()); model.addAttribute("activeNum",score == null?0:score.intValue()); } catch (Exception e) { logger.error("thought 详情失败!",e); }finally { JedisProviderFactory.getJedisProvider(null).release(); } return "/thought/detail.html"; }