| | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeRecord; |
| | | import com.yeshi.makemoney.app.entity.goldcorn.GoldCornConsumeType; |
| | | import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetRecord; |
| | | import com.yeshi.makemoney.app.entity.goldcorn.GoldCornGetType; |
| | | import com.yeshi.makemoney.app.dto.goldcorn.GoldCornMakeResultDTO; |
| | | import com.yeshi.makemoney.app.entity.goldcorn.*; |
| | | import com.yeshi.makemoney.app.entity.user.UserInfo; |
| | | import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetFrequencyConfigException; |
| | | import com.yeshi.makemoney.app.exception.goldcorn.GoldCornGetPriceException; |
| | | import com.yeshi.makemoney.app.exception.goldcorn.GoldCornMakeException; |
| | | import com.yeshi.makemoney.app.exception.user.UserInfoException; |
| | | import com.yeshi.makemoney.app.service.inter.goldcorn.GoldCornConsumeRecordService; |
| | | 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.goldcorn.*; |
| | | import com.yeshi.makemoney.app.service.inter.team.TeamInviteRelationService; |
| | | import com.yeshi.makemoney.app.service.inter.user.UserExtraInfoService; |
| | | import com.yeshi.makemoney.app.service.inter.user.UserInfoService; |
| | | import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornConsumeRecordQuery; |
| | | import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornGetRecordQuery; |
| | | import com.yeshi.makemoney.app.service.query.goldcorn.GoldCornTaskTypeInfoQuery; |
| | | import com.yeshi.makemoney.app.utils.Constant; |
| | | import com.yeshi.makemoney.app.utils.annotation.UserLogin; |
| | | import com.yeshi.makemoney.app.utils.goldcorn.GoldCornUtil; |
| | |
| | | import com.yeshi.makemoney.app.vo.goldcorn.*; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.yeshi.utils.JsonUtil; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.TimeUtil; |
| | | import org.yeshi.utils.annotation.RequestSerializableByKey; |
| | | import redis.clients.jedis.Jedis; |
| | | import redis.clients.jedis.JedisPool; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | |
| | | @Controller |
| | | @RequestMapping("api/v1/goldcorn") |
| | | public class GoldCornController { |
| | | |
| | | Logger logger = LoggerFactory.getLogger(GoldCornController.class); |
| | | |
| | | @Resource |
| | | private GoldCornGetRecordService goldCornGetRecordService; |
| | | |
| | |
| | | private UserExtraInfoService userExtraInfoService; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | @Resource |
| | | private JedisPool jedisPool; |
| | | |
| | | @Resource |
| | | private GoldCornTaskTypeInfoService goldCornTaskTypeInfoService; |
| | | |
| | | @Resource |
| | | private GoldCornGetFrequencyConfigService goldCornGetFrequencyConfigService; |
| | | |
| | | private Gson gson = JsonUtil.getConvertBigDecimalToStringBuilder(new GsonBuilder()).create(); |
| | | |
| | |
| | | List<GoldCornExchangeRecordVO> voList = new ArrayList<>(); |
| | | for (GoldCornConsumeRecord record : recordList) { |
| | | GoldCornExchangeRecordVO vo = new GoldCornExchangeRecordVO(); |
| | | vo.setDateTime(TimeUtil.getGernalTime(record.getCreateTime().getTime(), "yyyy.MM.dd HH:mm")); |
| | | if (record.getEventTime() == null) { |
| | | vo.setDateTime(TimeUtil.getGernalTime(record.getCreateTime().getTime(), "yyyy.MM.dd HH:mm")); |
| | | } else { |
| | | vo.setDateTime(TimeUtil.getGernalTime(record.getEventTime().getTime(), "yyyy.MM.dd")); |
| | | } |
| | | vo.setNum(record.getCornNum()); |
| | | vo.setMoney(record.getMoney().setScale(2).toString()); |
| | | vo.setMoney(new BigDecimal(record.getMoney()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR).toString()); |
| | | voList.add(vo); |
| | | } |
| | | |
| | |
| | | return JsonUtil.loadFalseResult("参数不完整"); |
| | | } |
| | | |
| | | |
| | | String key = "dotask-" + acceptData.getSign(); |
| | | Jedis jedis = jedisPool.getResource(); |
| | | try { |
| | | JSONObject data = new JSONObject(); |
| | | Integer result = null; |
| | | if (vo.getType() == GoldCornGetType.watchVideo) { |
| | | result = goldCornMakeService.watchVideo(uid, vo.getDouble(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getTimeSeconds()); |
| | | } else if (vo.getType() == GoldCornGetType.readNovel) { |
| | | result = goldCornMakeService.readNovel(uid, vo.getDouble(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getTimeSeconds()); |
| | | } else if (vo.getType() == GoldCornGetType.scanNews) { |
| | | result = goldCornMakeService.scanNews(uid, vo.getDouble(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getNum()); |
| | | } else { |
| | | return JsonUtil.loadFalseResult("任务类型出错"); |
| | | if (!StringUtil.isNullOrEmpty(jedis.get(key))) { |
| | | return JsonUtil.loadFalseResult("重复的请求"); |
| | | } |
| | | data.put("goldCorn", result); |
| | | jedis.set(key, "1"); |
| | | //30分钟有效期 |
| | | jedis.expire(key, 60 * 30); |
| | | |
| | | return JsonUtil.loadTrueResult(data); |
| | | try { |
| | | JSONObject data = new JSONObject(); |
| | | GoldCornMakeResultDTO result = null; |
| | | if (vo.getType() == GoldCornGetType.watchVideo) { |
| | | result = goldCornMakeService.watchVideo(uid, vo.getDoubles(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getTimeSeconds()); |
| | | } else if (vo.getType() == GoldCornGetType.readNovel) { |
| | | result = goldCornMakeService.readNovel(uid, vo.getDoubles() == null ? false : vo.getDoubles(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getTimeSeconds()); |
| | | } else if (vo.getType() == GoldCornGetType.scanNews) { |
| | | result = goldCornMakeService.scanNews(uid, vo.getDoubles() == null ? false : vo.getDoubles(), vo.getFinishTime() == null ? new Date() : new Date(vo.getFinishTime()), vo.getNum()); |
| | | } else { |
| | | return JsonUtil.loadFalseResult("任务类型出错"); |
| | | } |
| | | data.put("goldCorn", result.getGoldCorn()); |
| | | data.put("leftCount", result.getLeftEventCount()); |
| | | return JsonUtil.loadTrueResult(data); |
| | | |
| | | } catch (GoldCornGetPriceException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult("业务错误"); |
| | | } catch (UserInfoException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } catch (GoldCornMakeException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } catch (GoldCornGetFrequencyConfigException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } catch (GoldCornGetPriceException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult("业务错误"); |
| | | } catch (UserInfoException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } catch (GoldCornMakeException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } catch (GoldCornGetFrequencyConfigException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtil.loadFalseResult(e.getMessage()); |
| | | } |
| | | } finally { |
| | | jedis.close(); |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * @return java.lang.String |
| | | * @author hxh |
| | | * @description 获取任务信息 |
| | | * @date 18:58 2022/4/28 |
| | | * @param: acceptData |
| | | * @param: uid |
| | | * @param: vo |
| | | **/ |
| | | @RequestMapping("getTaskInfo") |
| | | @ResponseBody |
| | | public String getTaskInfo(AcceptData acceptData, Long uid, String type) { |
| | | |
| | | GoldCornGetType goldCornGetType = GoldCornGetType.valueOf(type); |
| | | if (goldCornGetType == null) { |
| | | return JsonUtil.loadFalseResult("类型不存在"); |
| | | } |
| | | |
| | | Date now = new Date(); |
| | | UserInfo user = null; |
| | | if (uid != null) { |
| | | user = userInfoService.get(uid); |
| | | } |
| | | //获取单价 |
| | | GoldCornGetPrice price = goldCornGetPriceService.getCountPrice(goldCornGetType, user, acceptData.getSystem(), now); |
| | | boolean finish = true; |
| | | if (uid != null) { |
| | | try { |
| | | if (goldCornMakeService.frequencyVerify(user, goldCornGetType, now) > 0) { |
| | | finish = false; |
| | | } |
| | | } catch (GoldCornGetFrequencyConfigException e) { |
| | | e.printStackTrace(); |
| | | } catch (GoldCornMakeException e) { |
| | | e.printStackTrace(); |
| | | finish = false; |
| | | } |
| | | } else { |
| | | finish = false; |
| | | } |
| | | JSONObject data = new JSONObject(); |
| | | data.put("price", price.getCornNum()); |
| | | data.put("finish", finish); |
| | | return JsonUtil.loadTrueResult(data); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @return java.lang.String |
| | | * @author hxh |
| | | * @description 获取任务列表 |
| | | * @date 11:27 2022/4/28 |
| | | * @param: acceptData |
| | | * @param: uid |
| | | **/ |
| | | @RequestMapping("getTaskList") |
| | | @ResponseBody |
| | | public String getTaskList(AcceptData acceptData, Long uid) { |
| | | Date now = new Date(); |
| | | |
| | | GoldCornTaskTypeInfoQuery query = new GoldCornTaskTypeInfoQuery(); |
| | | query.setSystem(acceptData.getSystem()); |
| | | query.setShow(true); |
| | | query.setShowTime(now); |
| | | |
| | | List<GoldCornTaskTypeInfo> list = goldCornTaskTypeInfoService.list(query, 1, 100); |
| | | |
| | | List<GoldCornTaskVO> voList = new ArrayList<>(); |
| | | if (list != null) { |
| | | UserInfo user = null; |
| | | if (uid != null) { |
| | | user = userInfoService.get(uid); |
| | | } |
| | | //查询价格 |
| | | List<GoldCornGetType> typeList = list.stream().map(item -> { |
| | | return item.getType(); |
| | | }).collect(Collectors.toList()); |
| | | |
| | | Map<GoldCornGetType, GoldCornGetPrice> priceMap = goldCornGetPriceService.getCountPrice(typeList, user, acceptData.getSystem(), now); |
| | | |
| | | Map<GoldCornGetType, Long> processMap = new HashMap<>(); |
| | | if (uid != null) { |
| | | GoldCornGetRecordQuery goldCornGetRecordQuery = new GoldCornGetRecordQuery(); |
| | | goldCornGetRecordQuery.setUid(uid); |
| | | goldCornGetRecordQuery.setDay(GoldCornUtil.getFormatDay(now)); |
| | | //获取今日的进度 |
| | | processMap = goldCornGetRecordService.sumEventCount(goldCornGetRecordQuery); |
| | | } |
| | | List<GoldCornGetFrequencyConfig> frequencyConfigs = goldCornGetFrequencyConfigService.listByTypes(typeList, acceptData.getSystem(), now); |
| | | Map<GoldCornGetType, GoldCornGetFrequencyConfig> frequencyConfigsMaps = frequencyConfigs.stream().collect(Collectors.toMap(GoldCornGetFrequencyConfig::getType, config -> config)); |
| | | |
| | | |
| | | for (GoldCornTaskTypeInfo task : list) { |
| | | if (priceMap.get(task.getType()) == null) { |
| | | continue; |
| | | } |
| | | if (frequencyConfigsMaps.get(task.getType()) == null) { |
| | | continue; |
| | | } |
| | | GoldCornTaskVO vo = GoldCornTaskVO.create(task, priceMap.get(task.getType()), frequencyConfigsMaps.get(task.getType()), processMap.get(task.getType())); |
| | | voList.add(vo); |
| | | } |
| | | } |
| | | JSONObject data = new JSONObject(); |
| | | data.put("list", JsonUtil.getSimpleGson().toJson(voList)); |
| | | data.put("count", voList.size()); |
| | | return JsonUtil.loadTrueResult(data); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @return java.lang.String |
| | | * @author hxh |
| | | * @description 获取签到信息 |
| | | * @date 17:12 2022/4/21 |
| | | * @param: acceptData |