From 0e9b6603d4ae9d11c1fbc90257ce816c5807b8ff Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 28 十月 2022 16:55:02 +0800 Subject: [PATCH] 批量添加结算消息 --- app/src/main/java/com/yeshi/makemoney/app/service/impl/goldcorn/GoldCornMakeServiceImpl.java | 416 ++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 336 insertions(+), 80 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 e7e32cc..10294be 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,10 +1,10 @@ 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.GoldCornGetFrequencyConfig; -import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetPrice; -import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetRecord; -import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType; +import com.yeshi.makemoney.app.entity.goldcorn.*; +import com.yeshi.makemoney.app.entity.money.UserMoneyRecord; import com.yeshi.makemoney.app.entity.user.UserInfo; import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetFrequencyConfigException; import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetPriceException; @@ -16,11 +16,18 @@ import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetPriceService; import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornGetRecordService; import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornMakeService; +import com.yeshi.makemoney.app.service.inter.money.UserMoneyRecordService; import com.yeshi.makemoney.app.service.inter.team.TeamInviteRelationService; import com.yeshi.makemoney.app.service.inter.user.UserInfoService; import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornGetRecordQuery; +import com.yeshi.makemoney.app.utils.factory.UserMoneyRecordFactory; +import com.yeshi.makemoney.app.utils.factory.goldcorn.GoldCornConsumeRecordFactory; +import com.yeshi.makemoney.app.utils.goldcorn.GoldCornUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.yeshi.utils.TimeUtil; import org.yeshi.utils.annotation.RequestSerializableByKey; @@ -29,6 +36,8 @@ import java.util.Calendar; import java.util.Date; import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; /** * @author hxh @@ -38,6 +47,7 @@ */ @Service public class GoldCornMakeServiceImpl implements GoldCornMakeService { + Logger taskLogger = LoggerFactory.getLogger("taskLog"); @Resource private GoldCornGetFrequencyConfigService goldCornGetFrequencyConfigService; @@ -46,7 +56,7 @@ private GoldCornGetRecordService goldCornGetRecordService; @Resource - private RedisTemplate<String, String> redisTemplate; + private RedisTemplate<String, Object> redisTemplate; @Resource private GoldCornGetPriceService goldCornGetPriceService; @@ -60,8 +70,21 @@ @Resource private SystemConfigService systemConfigService; + @Resource + 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, "棰戠巼閰嶇疆涓嶅瓨鍦�"); @@ -72,42 +95,51 @@ query.setUid(user.getId()); query.setType(type); - //闂撮殧鍒ゆ柇 - if (config.getMinSpaceTime() != null) { - List<GoldCornGetRecord> list = goldCornGetRecordService.list(query, 1, 1); - if (list != null && list.size() > 0 && System.currentTimeMillis() - list.get(0).getCreateTime().getTime() < config.getMinSpaceTime() * 1000L) { - String msg = String.format("闇�瑕侀棿闅�%s绉掍互涓�", config.getMinSpaceTime()); - throw new GoldCornMakeException(GoldCornMakeException.CODE_GET_FREQUENCY_LIMIT, msg); + try { + //闂撮殧鍒ゆ柇 + if (config.getMinSpaceTime() != null) { + List<GoldCornGetRecord> list = goldCornGetRecordService.list(query, 1, 1); + if (list != null && list.size() > 0 && time.getTime() - list.get(0).getCreateTime().getTime() < config.getMinSpaceTime() * 1000L) { + String msg = String.format("闇�瑕侀棿闅�%s绉掍互涓�", config.getMinSpaceTime()); + throw new GoldCornMakeException(GoldCornMakeException.CODE_GET_FREQUENCY_TIME_LIMIT, msg); + } } - } - Date startTime = null; - Date endTime = time; - if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.minute) { - startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyyMMdd HHmm"), "yyyyMMdd HHmm")); - } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.hour) { - startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyyMMdd HH"), "yyyyMMdd HH")); - } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.day) { - startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyyMMdd"), "yyyyMMdd")); - } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.week) { - Calendar calendar = Calendar.getInstance(); - calendar.setTimeInMillis(endTime.getTime()); - int subDay = (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 2 + 7) % 7; - startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime() - 1000 * 60 * 60 * 24L * subDay, "yyyyMMdd"), "yyyyMMdd")); - } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.month) { - startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyyMM"), "yyyyMM")); - } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.year) { - startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyy"), "yyyy")); - } - query.setFormat("yyyyMMdd HH:mm:ss"); - query.setStartTime(TimeUtil.getGernalTime(startTime.getTime(), query.getFormat())); - //service閲岄潰鏈夊噺鍘�1澶� - query.setEndTime(TimeUtil.getGernalTime(endTime.getTime() - 1000 * 60 * 60 * 24L, query.getFormat())); + Date startTime = null; + Date endTime = time; + if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.minute) { + startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyyMMdd HHmm"), "yyyyMMdd HHmm")); + } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.hour) { + startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyyMMdd HH"), "yyyyMMdd HH")); + } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.day) { + startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyyMMdd"), "yyyyMMdd")); + } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.week) { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(endTime.getTime()); + int subDay = (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 2 + 7) % 7; + startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime() - 1000 * 60 * 60 * 24L * subDay, "yyyyMMdd"), "yyyyMMdd")); + } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.month) { + startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyyMM"), "yyyyMM")); + } else if (config.getTimeUnit() == GoldCornGetFrequencyConfig.GoldCornGetFrequencyTimeUnit.year) { + startTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(endTime.getTime(), "yyyy"), "yyyy")); + } + query.setFormat("yyyyMMdd HH:mm:ss"); + query.setStartTime(TimeUtil.getGernalTime(startTime.getTime(), query.getFormat())); + //service閲岄潰鏈夊噺鍘�1澶� + query.setEndTime(TimeUtil.getGernalTime(endTime.getTime() - 1000 * 60 * 60 * 24L, query.getFormat())); - long count = goldCornGetRecordService.count(query); - if (count >= config.getLimitCount()) { - String msg = String.format("瓒呭嚭%s娆�/%s鐨勯檺鍒�", config.getLimitCount(), config.getTimeUnit().getName()); - throw new GoldCornMakeException(GoldCornMakeException.CODE_GET_FREQUENCY_LIMIT, msg); + 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_COUNT_LIMIT, msg); + } + + return config.getLimitCount() - (countMap.get(type) != null ? countMap.get(type) : 0); + + } catch (GoldCornMakeException e) { + //棰戠巼闄愬埗 + taskLogger.error("#棰戠巼鍙楅檺# uid:{} type:{} time:{} msg:{}", user.getId(), type.name(), TimeUtil.getGernalTime(time.getTime(), "yyyy-MM-dd HH:mm:ss SSS"), e.getMsg()); + throw e; } } @@ -115,7 +147,7 @@ @RequestSerializableByKey(key = "'addgoldcorn-'+#uid+'-'+#type") @Override - public void addGoldCorn(Long uid, GoldCornGetType type, Date currentTime) throws UserInfoException, GoldCornGetPriceException, 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, "鍙傛暟涓嶅畬鏁�"); } @@ -123,67 +155,291 @@ if (user == null) { throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�"); } - //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� - frequencyVerify(user, type, currentTime); - //鑾峰彇浠锋牸 - GoldCornGetPrice price = goldCornGetPriceService.getPrice(user.getSystem(), type, currentTime); - if (price == null) { - throw new GoldCornGetPriceException(GoldCornGetPriceException.CODE_NOT_EXIST, "浠锋牸淇℃伅缂哄け"); - } + GoldCornGetPrice getPrice = goldCornGetPriceService.getPrice(user.getSystem(), GoldCornGetType.watchVideo, currentTime); + + + //鍗曚环鐢卞闈紶鍏� + int baseCornNum = price; + GoldCornGetRecord record = new GoldCornGetRecord(); - record.setCornNum(price.getCornNum()); + record.setCornNum(baseCornNum); record.setDay(TimeUtil.getGernalTime(currentTime.getTime(), "yyyy-MM-dd")); record.setType(type); record.setUid(uid); + record.setSystem(user.getSystem()); record.setLevel(GoldCornGetRecord.LEVEL_OWN); record.setCreateTime(currentTime); + record.setEventCount(eventCount); + GoldCornGetRecord recordD = null; + if (isDouble) { + recordD = new GoldCornGetRecord(); + recordD.setCornNum(baseCornNum); + record.setSystem(user.getSystem()); + recordD.setDay(TimeUtil.getGernalTime(currentTime.getTime(), "yyyy-MM-dd")); + recordD.setType(type); + recordD.setUid(uid); + recordD.setLevel(GoldCornGetRecord.LEVEL_OWN); + recordD.setCreateTime(currentTime); + recordD.setDubble(true); + recordD.setEventCount(eventCount); + } + + //鍏佽涓婄骇鎻愭垚 try { goldCornGetRecordService.add(record); + if (recordD != null) { + goldCornGetRecordService.add(recordD); + } //鏄惁鏈変笂绾� - Long bossUid = teamInviteRelationService.getBossUid(uid); - if (bossUid != null) { - BigDecimal rate = new BigDecimal(systemConfigService.getValueCache(user.getSystem(), SystemConfigKey.teamFirstDivideRate)); - GoldCornGetRecord cRecord = new GoldCornGetRecord(); - cRecord.setCornNum(price.getCornNum()); - cRecord.setDay(record.getDay()); - cRecord.setType(type); - cRecord.setUid(bossUid); - cRecord.setCornNum(new BigDecimal(record.getCornNum()).multiply(rate).intValue()); - cRecord.setFromId(record.getId()); - cRecord.setFromUid(record.getUid()); - cRecord.setLevel(GoldCornGetRecord.LEVEL_FIRST); - cRecord.setCreateTime(currentTime); - if (cRecord.getCornNum() > 0) { - goldCornGetRecordService.add(cRecord); - } - //鏄惁鏈変笂涓婄骇 - bossUid = teamInviteRelationService.getBossUid(bossUid); + if (getPrice.getTeamDivide() != null && getPrice.getTeamDivide()) { + Long bossUid = teamInviteRelationService.getBossUid(user.getId()); if (bossUid != null) { - rate = new BigDecimal(systemConfigService.getValueCache(user.getSystem(), SystemConfigKey.teamSecondDivideRate)); - GoldCornGetRecord ccRecord = new GoldCornGetRecord(); - ccRecord.setCornNum(price.getCornNum()); - ccRecord.setDay(record.getDay()); - ccRecord.setType(type); - ccRecord.setUid(bossUid); - ccRecord.setFromId(record.getId()); - ccRecord.setFromUid(record.getUid()); - ccRecord.setCornNum(new BigDecimal(record.getCornNum()).multiply(rate).intValue()); - ccRecord.setLevel(GoldCornGetRecord.LEVEL_SECOND); - ccRecord.setCreateTime(currentTime); - if (ccRecord.getCornNum() > 0) { - goldCornGetRecordService.add(ccRecord); + BigDecimal rate = new BigDecimal(systemConfigService.getValueCache(user.getSystem(), SystemConfigKey.teamFirstDivideRate)); + GoldCornGetRecord cRecord = new GoldCornGetRecord(); + cRecord.setDay(record.getDay()); + cRecord.setType(type); + cRecord.setUid(bossUid); + record.setSystem(user.getSystem()); + cRecord.setCornNum(new BigDecimal(baseCornNum).multiply(rate).intValue()); + cRecord.setFromId(record.getId()); + cRecord.setFromUid(record.getUid()); + cRecord.setLevel(GoldCornGetRecord.LEVEL_FIRST); + cRecord.setCreateTime(currentTime); + if (cRecord.getCornNum() > 0) { + goldCornGetRecordService.add(cRecord); } + //鏄惁鏈変笂涓婄骇 +// bossUid = teamInviteRelationService.getBossUid(bossUid); +// if (bossUid != null) { +// rate = new BigDecimal(systemConfigService.getValueCache(user.getSystem(), SystemConfigKey.teamSecondDivideRate)); +// GoldCornGetRecord ccRecord = new GoldCornGetRecord(); +// ccRecord.setDay(record.getDay()); +// ccRecord.setType(type); +// ccRecord.setUid(bossUid); +// ccRecord.setFromId(record.getId()); +// ccRecord.setFromUid(record.getUid()); +// ccRecord.setCornNum(new BigDecimal(baseCornNum).multiply(rate).intValue()); +// ccRecord.setLevel(GoldCornGetRecord.LEVEL_SECOND); +// ccRecord.setCreateTime(currentTime); +// if (ccRecord.getCornNum() > 0) { +// goldCornGetRecordService.add(ccRecord); +// } +// } } } } catch (GoldCornGetRecordException e) { throw new GoldCornMakeException(GoldCornMakeException.CODE_ADD_RECORD_ERROR, e.getMsg()); } + + return record; } @Override - public Long getGoldCornByDay(Long uid, String day) { + public Long getGoldCornByDay(Long uid, Date day) { //TODO redis缂撳瓨 return goldCornGetRecordService.getGoldCornByDay(uid, day); } + + @Override + public Long getExchangingGoldCorn(Long uid, int dayCount) { + long goldCornNum = 0; + long now = System.currentTimeMillis(); + //鏌ヨ鏈�杩�3澶╂湭鍏戞崲鐨勯噾甯佹暟閲忥紝 + for (int i = 1; i <= dayCount; i++) { + Date date = new Date(now - 1000 * 60 * 60 * 24L * i); + long count = getGoldCornByDay(uid, date); + if (count == 0L) { + continue; + } + //鑾峰彇鍏戞崲璁板綍鐨勪富閿甀D,涓嶉渶瑕佸浣欑殑鏁版嵁 + GoldCornConsumeRecord record = GoldCornConsumeRecordFactory.createExchange(uid, GoldCornUtil.getFormatDay(date), 0, new BigDecimal(0.1), null); + //鏌ヨ璧勯噾璁板綍鏄惁鏈夎璁板綍 + try { + UserMoneyRecord userMoneyRecord = UserMoneyRecordFactory.createGoldCornExchange(record); + //鏌ヨ璁板綍 + userMoneyRecord = userMoneyRecordService.selectBySerialNo(userMoneyRecord.getSerialNo()); + + if (userMoneyRecord == null) { + //鏈厬鎹� + goldCornNum += count; + } + + } catch (ParamsException e) { + e.printStackTrace(); + } + } + return goldCornNum; + } + + @Override + public int getContinueSignDay(Long uid) { + Date now = new Date(); + //鏌ヨ浠婃棩鏄惁宸茬粡绛惧埌 + boolean isSignIn = isSignIn(uid, now); + Date deadDate = now; + if (!isSignIn) { + deadDate = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now.getTime(), "yyyyMMdd"), "yyyyMMdd")); + } + + //浠婃棩鏈鍒扮殑锛屾煡璇㈣繛缁鍒版鏁板簲璇ヤ粠鍓嶄竴澶╁紑濮嬭绠� + int continueDay = goldCornGetRecordService.getContinueDay(uid, GoldCornGetType.signIn, deadDate); + return continueDay; + } + + @Override + public boolean isSignIn(Long uid, Date date) { + GoldCornGetRecordQuery query = new GoldCornGetRecordQuery(); + query.setUid(uid); + query.setType(GoldCornGetType.signIn); + query.setDay(GoldCornUtil.getFormatDay(date)); + long count = goldCornGetRecordService.count(query); + return count > 0L; + } + + @Override + 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, now, price, 1L); + } + + @Transactional(rollbackFor = Exception.class) + @Override + 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, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� + 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 new GoldCornMakeResultDTO(0, leftCount); + } + + 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 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"); + long readNovelNowSeconds = timeSeconds; + + Integer start = (Integer) redisTemplate.opsForValue().get(readNovelCacheKey); + if (start == null) { + start = 0; + } + + timeSeconds = timeSeconds - start; + + UserInfo user = userInfoService.get(uid); + if (user == null) { + throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� + 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 new GoldCornMakeResultDTO(0, leftCount); + } + + GoldCornGetRecord record = addGoldCorn(uid, GoldCornGetType.readNovel, isDouble, time, price, (long) timeSeconds); + + //璁板綍褰撳ぉ鐨勫疄鏃堕槄璇诲垎閽熸暟 + redisTemplate.opsForValue().set(readNovelCacheKey, readNovelNowSeconds, 60 * 60 * 24, TimeUnit.SECONDS); + return new GoldCornMakeResultDTO(record.getCornNum() * (isDouble ? 2 : 1), leftCount - timeSeconds); + } + + @Transactional(rollbackFor = Exception.class) + @Override + public GoldCornMakeResultDTO scanNews(Long uid, boolean isDouble, Date time, int num) throws GoldCornGetPriceException, UserInfoException, GoldCornMakeException, GoldCornGetFrequencyConfigException { + //闃插埛鏈哄埗 + if (num < 0) { + num = 0; + } + + //1涓緢澶х殑鏁� + if (num > 20) { + num = 1; + } + + + UserInfo user = userInfoService.get(uid); + if (user == null) { + throw new UserInfoException(UserInfoException.CODE_NOT_EXIST, "鐢ㄦ埛涓嶅瓨鍦�"); + } + + //鍒ゆ柇鏄惁瓒呭嚭浜嗘鏁伴檺鍒� + long leftCount = frequencyVerify(user, GoldCornGetType.scanNews, time); + + Integer price = goldCornGetPriceService.getCountPrice(GoldCornGetType.scanNews, user, user.getSystem(), time, num); + //浠锋牸涓�0鏃朵笉鍔犲叆璁板綍 + if (price == 0) { + return new GoldCornMakeResultDTO(0, leftCount); + } + + 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