admin
2022-05-10 2922e51a7a8e657a8467c818ae16700e41ddac77
app/src/main/java/com/yeshi/makemoney/app/controller/client/api/GoldCornController.java
@@ -24,15 +24,23 @@
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;
@@ -46,6 +54,9 @@
@Controller
@RequestMapping("api/v1/goldcorn")
public class GoldCornController {
    Logger logger = LoggerFactory.getLogger(GoldCornController.class);
    @Resource
    private GoldCornGetRecordService goldCornGetRecordService;
@@ -70,6 +81,9 @@
    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    @Resource
    private JedisPool jedisPool;
    @Resource
    private GoldCornTaskTypeInfoService goldCornTaskTypeInfoService;
@@ -162,9 +176,13 @@
        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);
        }
@@ -216,34 +234,48 @@
            return JsonUtil.loadFalseResult("参数不完整");
        }
        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());
        String key = "dotask-" + acceptData.getSign();
        Jedis jedis = jedisPool.getResource();
        try {
            if (!StringUtil.isNullOrEmpty(jedis.get(key))) {
                return JsonUtil.loadFalseResult("重复的请求");
            }
            jedis.set(key, "1");
            //30分钟有效期
            jedis.expire(key, 60 * 30);
            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());
            }
        } finally {
            jedis.close();
        }
    }
@@ -283,11 +315,11 @@
                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);