From 6cc97918a5a42e37a3c3867cc5b78a0b9fd43a24 Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 29 四月 2022 19:55:41 +0800 Subject: [PATCH] 功能完善 --- app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java | 118 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 92 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java index 75f01d2..b5e4d94 100644 --- a/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java +++ b/app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java @@ -1,6 +1,7 @@ package com.yeshi.makemoney.app.service.impl.goldcorn; import com.ks.lib.common.exception.ParamsException; +import com.yeshi.makemoney.app.dto.goldcorn.GoldCornMakeResultDTO; import com.yeshi.makemoney.app.entity.config.SystemConfigKey; import com.yeshi.makemoney.app.entity.goldcorn.*; import com.yeshi.makemoney.app.entity.money.UserMoneyRecord; @@ -33,6 +34,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; /** @@ -69,7 +71,17 @@ private UserMoneyRecordService userMoneyRecordService; - private void frequencyVerify(UserInfo user, GoldCornGetType type, Date time) throws GoldCornGetFrequencyConfigException, GoldCornMakeException { + /** + * @return int 褰撳墠鏃堕棿娈佃繕鍓╀綑鐨勪簨浠舵暟閲� + * @author hxh + * @description 棰戠巼闄愬埗 + * @date 11:02 2022/4/28 + * @param: user + * @param: type + * @param: time + **/ + @Override + public long frequencyVerify(UserInfo user, GoldCornGetType type, Date time) throws GoldCornGetFrequencyConfigException, GoldCornMakeException { GoldCornGetFrequencyConfig config = goldCornGetFrequencyConfigService.getConfig(user.getSystem(), type, time); if (config == null) { throw new GoldCornGetFrequencyConfigException(GoldCornGetFrequencyConfigException.CODE_NOT_EXIST, "棰戠巼閰嶇疆涓嶅瓨鍦�"); @@ -112,18 +124,18 @@ //service閲岄潰鏈夊噺鍘�1澶� query.setEndTime(TimeUtil.getGernalTime(endTime.getTime() - 1000 * 60 * 60 * 24L, query.getFormat())); - long count = goldCornGetRecordService.count(query); - if (count >= config.getLimitCount()) { + Map<GoldCornGetType, Long> countMap = goldCornGetRecordService.sumEventCount(query); + if (countMap.get(type) != null && (countMap.get(type) >= config.getLimitCount())) { String msg = String.format("瓒呭嚭%s娆�/%s鐨勯檺鍒�", config.getLimitCount(), config.getTimeUnit().getName()); throw new GoldCornMakeException(GoldCornMakeException.CODE_GET_FREQUENCY_LIMIT, msg); } - + return config.getLimitCount() - (countMap.get(type) != null ? countMap.get(type) : 0); } @RequestSerializableByKey(key = "'addgoldcorn-'+#uid+'-'+#type") @Override - public GoldCornGetRecord addGoldCorn(Long uid, GoldCornGetType type, boolean isDouble, Date currentTime, Integer price) throws UserInfoException, GoldCornGetFrequencyConfigException, GoldCornMakeException { + public GoldCornGetRecord addGoldCorn(Long uid, GoldCornGetType type, boolean isDouble, Date currentTime, Integer price, Long eventCount) throws UserInfoException, GoldCornGetFrequencyConfigException, GoldCornMakeException { if (uid == null || type == null || currentTime == null) { throw new GoldCornMakeException(GoldCornMakeException.CODE_PARAMS_NOT_ENOUGH, "鍙傛暟涓嶅畬鏁�"); } @@ -131,8 +143,6 @@ if (user == null) { throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�"); } - //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� - frequencyVerify(user, type, currentTime); GoldCornGetPrice getPrice = goldCornGetPriceService.getPrice(user.getSystem(), GoldCornGetType.watchVideo, currentTime); @@ -146,6 +156,7 @@ record.setUid(uid); record.setLevel(GoldCornGetRecord.LEVEL_OWN); record.setCreateTime(currentTime); + record.setEventCount(eventCount); GoldCornGetRecord recordD = null; if (isDouble) { recordD = new GoldCornGetRecord(); @@ -156,6 +167,7 @@ recordD.setLevel(GoldCornGetRecord.LEVEL_OWN); recordD.setCreateTime(currentTime); recordD.setDubble(true); + recordD.setEventCount(eventCount); } //鍏佽涓婄骇鎻愭垚 @@ -274,37 +286,43 @@ public GoldCornGetRecord signIn(Long uid) throws GoldCornGetFrequencyConfigException, UserInfoException, GoldCornGetPriceException, GoldCornMakeException { UserInfo user = userInfoService.get(uid); + + Date now = new Date(); + //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� + long leftCount = frequencyVerify(user, GoldCornGetType.signIn, now); //鑾峰彇杩炵画绛惧埌娆℃暟 Integer price = goldCornGetPriceService.getSingInPrice(user.getSystem(), getContinueSignDay(uid) + 1); - - - return addGoldCorn(uid, GoldCornGetType.signIn, false, new Date(), price); + return addGoldCorn(uid, GoldCornGetType.signIn, false, now, price, 1L); } @Transactional(rollbackFor = Exception.class) @Override - public Integer watchVideo(Long uid, boolean isDouble, Date time, int timeSeconds) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException { + public GoldCornMakeResultDTO watchVideo(Long uid, boolean isDouble, Date time, long timeSeconds) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException { UserInfo user = userInfoService.get(uid); if (user == null) { throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�"); } - Integer price = goldCornGetPriceService.getWatchVideoPrice(user, time, timeSeconds); + //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� + long leftCount = frequencyVerify(user, GoldCornGetType.watchVideo, time); + timeSeconds = timeSeconds > leftCount ? leftCount : timeSeconds; + + Integer price = goldCornGetPriceService.getCountPrice(GoldCornGetType.watchVideo, user, user.getSystem(), time, timeSeconds); //浠锋牸涓�0鏃朵笉鍔犲叆璁板綍 if (price == 0) { - return 0; + return new GoldCornMakeResultDTO(0, leftCount); } - GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.watchVideo, isDouble, time, price); - return record.getCornNum() * (isDouble ? 2 : 1); + GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.watchVideo, isDouble, time, price, (long) timeSeconds); + return new GoldCornMakeResultDTO(record.getCornNum() * (isDouble ? 2 : 1), leftCount - timeSeconds); } @Transactional(rollbackFor = Exception.class) @Override - public Integer readNovel(Long uid, boolean isDouble, Date time, int timeSeconds) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException { + public GoldCornMakeResultDTO readNovel(Long uid, boolean isDouble, Date time, long timeSeconds) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException { String readNovelCacheKey = "task-n-" + uid + "-" + TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"); - Integer readNovelNowSeconds = timeSeconds; + long readNovelNowSeconds = timeSeconds; Integer start = (Integer) redisTemplate.opsForValue().get(readNovelCacheKey); if (start == null) { @@ -318,35 +336,83 @@ throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�"); } - Integer price = goldCornGetPriceService.getReadNovelPrice(user, time, timeSeconds); + //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� + long leftCount = frequencyVerify(user, GoldCornGetType.readNovel, time); + timeSeconds = timeSeconds > leftCount ? leftCount : timeSeconds; + + Integer price = goldCornGetPriceService.getCountPrice(GoldCornGetType.readNovel, user, user.getSystem(), time, timeSeconds); //浠锋牸涓�0鏃朵笉鍔犲叆璁板綍 if (price == 0) { - return 0; + return new GoldCornMakeResultDTO(0, leftCount); } - GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.readNovel, isDouble, time, price); + GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.readNovel, isDouble, time, price, (long) timeSeconds); //璁板綍褰撳ぉ鐨勫疄鏃堕槄璇诲垎閽熸暟 redisTemplate.opsForValue().set(readNovelCacheKey, readNovelNowSeconds, 60 * 60 * 24, TimeUnit.SECONDS); - return record.getCornNum() * (isDouble ? 2 : 1); + return new GoldCornMakeResultDTO(record.getCornNum() * (isDouble ? 2 : 1), leftCount - timeSeconds); } @Transactional(rollbackFor = Exception.class) @Override - public Integer scanNews(Long uid, boolean isDouble, Date time, int num) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException { + public GoldCornMakeResultDTO scanNews(Long uid, boolean isDouble, Date time, int num) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException { UserInfo user = userInfoService.get(uid); if (user == null) { throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�"); } - Integer price = goldCornGetPriceService.getScanNewsPrice(user, time, num); + //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� + long leftCount = frequencyVerify(user, GoldCornGetType.scanNews, time); + + Integer price = goldCornGetPriceService.getCountPrice(GoldCornGetType.scanNews, user, user.getSystem(), time, num); //浠锋牸涓�0鏃朵笉鍔犲叆璁板綍 if (price == 0) { - return 0; + return new GoldCornMakeResultDTO(0, leftCount); } - GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.scanNews, isDouble, time, price); - return record.getCornNum() * (isDouble ? 2 : 1); + GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.scanNews, isDouble, time, price, (long) num); + return new GoldCornMakeResultDTO(record.getCornNum() * (isDouble ? 2 : 1), leftCount - num); + } + + @Override + public GoldCornMakeResultDTO inviteFriends(Long uid, UserInfo friendInfo, Date time) throws UserInfoException, GoldCornGetPriceException, GoldCornMakeException, GoldCornGetFrequencyConfigException { + UserInfo user = userInfoService.get(uid); + if (user == null) { + throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� + long leftCount = frequencyVerify(user, GoldCornGetType.invite, time); + + Integer price = goldCornGetPriceService.getCountPrice(GoldCornGetType.invite, user, user.getSystem(), time, 1); + //浠锋牸涓�0鏃朵笉鍔犲叆璁板綍 + if (price == 0) { + return new GoldCornMakeResultDTO(0, leftCount); + } + + GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.invite, false, time, price, (long) price); + return new GoldCornMakeResultDTO(record.getCornNum(), leftCount - 1); + } + + @Override + public GoldCornMakeResultDTO extract(Long uid, Date time) throws UserInfoException, GoldCornGetPriceException, GoldCornMakeException, GoldCornGetFrequencyConfigException { + + UserInfo user = userInfoService.get(uid); + if (user == null) { + throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� + long leftCount = frequencyVerify(user, GoldCornGetType.extract, time); + + Integer price = goldCornGetPriceService.getCountPrice(GoldCornGetType.extract, user, user.getSystem(), time, 1); + //浠锋牸涓�0鏃朵笉鍔犲叆璁板綍 + if (price == 0) { + return new GoldCornMakeResultDTO(0, leftCount); + } + + GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.extract, false, time, price, (long) price); + return new GoldCornMakeResultDTO(record.getCornNum(), leftCount - 1); } -- Gitblit v1.8.0