| | |
| | | package com.yeshi.fanli.controller.client.v2;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.lang.reflect.Type;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Calendar;
|
| | | import java.util.Date;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.google.gson.JsonElement;
|
| | | import com.google.gson.JsonPrimitive;
|
| | | import com.google.gson.JsonSerializationContext;
|
| | | import com.google.gson.JsonSerializer;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserRank;
|
| | | import com.yeshi.fanli.entity.integral.CodePublishRecord;
|
| | | import com.yeshi.fanli.entity.integral.IntegralExchange;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum;
|
| | |
| | | import com.yeshi.fanli.exception.integral.IntegralExchangeException;
|
| | | import com.yeshi.fanli.exception.integral.IntegralTaskRecordException;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.integral.CodePublishRecordService;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralExchangeRecordService;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralExchangeService;
|
| | | import com.yeshi.fanli.service.inter.integral.IntegralTaskClassService;
|
| | |
| | | public class IntegralControllerV2 {
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | | |
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | |
| | |
|
| | | @Resource
|
| | | private IntegralExchangeRecordService integralExchangeRecordService;
|
| | | |
| | | @Resource
|
| | | private CodePublishRecordService codePublishRecordService;
|
| | |
|
| | | /**
|
| | | * 获取任务列表
|
| | |
| | | Gson gson = gsonBuilder.create();
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("goldCoin", extraVO.getGoldCoin());
|
| | | data.put("goldCoin", extraVO.getGoldCoin() + "枚");
|
| | | data.put("count", count);
|
| | | data.put("list", gson.toJson(list));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | |
| | | data.put("result", gson.toJson(exchange));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (IntegralExchangeException e) {
|
| | | e.printStackTrace();
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | @RequestMapping(value = "exchange", method = RequestMethod.POST)
|
| | | public void exchange(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
|
| | | try {
|
| | | ExchangeTipVO exchange = integralExchangeService.verifyExchange(uid, id);
|
| | | IntegralExchange exchange = integralExchangeService.exchange(uid, id);
|
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
|
| | | Gson gson = gsonBuilder.create();
|
| | |
| | | data.put("result", gson.toJson(exchange));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (IntegralExchangeException e) {
|
| | | e.printStackTrace();
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 兑换金币检验-邀请码
|
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param id
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "verifyInviteCode", method = RequestMethod.POST)
|
| | | public void verifyInviteCode(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
|
| | | try {
|
| | | ExchangeTipVO exchange = integralExchangeService.verifyInviteCode(uid, id);
|
| | | |
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
|
| | | Gson gson = gsonBuilder.create();
|
| | | |
| | | JSONObject data = new JSONObject();
|
| | | data.put("result", gson.toJson(exchange));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (IntegralExchangeException e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 兑换金币-邀请码
|
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param id
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "exchangeInviteCode", method = RequestMethod.POST)
|
| | | public void exchangeInviteCode(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
|
| | | try {
|
| | | integralExchangeService.exchangeInviteCode(uid, id);
|
| | | out.print(JsonUtil.loadTrueResult("邀请码激活成功"));
|
| | | } catch (IntegralExchangeException e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | }
|
| | | }
|
| | | |
| | | |
| | | |
| | | /**
|
| | | * 邀请码发布列表
|
| | | * @param acceptData
|
| | | * @param page
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getPublishList", method = RequestMethod.POST)
|
| | | public void getPublishList(AcceptData acceptData, Integer page, PrintWriter out) {
|
| | | if (page == null || page < 1) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "页码不正确"));
|
| | | return;
|
| | | }
|
| | | |
| | | List<CodePublishRecord> list = codePublishRecordService.listValid((page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
|
| | | if (list == null) {
|
| | | list = new ArrayList<CodePublishRecord>();
|
| | | } |
| | | |
| | | long count = codePublishRecordService.countValid();
|
| | | |
| | | JSONObject data = new JSONObject();
|
| | | data.put("count", count);
|
| | | data.put("list", getGson().toJson(list));
|
| | | data.put("helpLink", configService.get("publish_list_help_link"));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | | |
| | | |
| | |
|
| | | /**
|
| | | * 时间处理
|
| | | * @return
|
| | | */
|
| | | private Gson getGson() {
|
| | | GsonBuilder gb = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder());
|
| | | gb.excludeFieldsWithoutExposeAnnotation();
|
| | | gb.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
|
| | | @Override
|
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
|
| | | String desc = "";
|
| | | if (value != null) {
|
| | | // 判断是否是同一天
|
| | | |
| | | Calendar calendar = Calendar.getInstance();
|
| | | calendar.setTime(value);
|
| | | int y1 = calendar.get(Calendar.YEAR);//获取年份
|
| | | int d1 = calendar.get(Calendar.DAY_OF_YEAR);//获取年中第几天
|
| | |
|
| | | Date nowDate = new Date();
|
| | | Calendar calendar2 = Calendar.getInstance();
|
| | | calendar2.setTime(nowDate);
|
| | | int y2 = calendar2.get(Calendar.YEAR);//获取年份
|
| | | int d2 = calendar2.get(Calendar.DAY_OF_YEAR);//获取年中第几天
|
| | | |
| | | long old = value.getTime();
|
| | | long now = nowDate.getTime();
|
| | | if (y1 == y2) {
|
| | | if (d1 == d2) {
|
| | | long cha = now - old;
|
| | | if (cha < 1000 * 60 * 2L) {
|
| | | desc = "刚刚";
|
| | | }else if (cha < 1000 * 60 * 60L) {
|
| | | desc = (cha / (1000 * 60)) + "分钟前";
|
| | | }else {
|
| | | desc = (cha / (1000 * 60 * 60)) + "小时前";
|
| | | }
|
| | | } else if (d2 - d1 == 1) {
|
| | | desc = "昨天";
|
| | | } else {
|
| | | desc = (d2 - d1) + "天前";
|
| | | }
|
| | | } else {
|
| | | int timeDistance = 0;
|
| | | for (int i = y1; i < y2; i++) {
|
| | | if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {
|
| | | timeDistance += 366; // 闰年
|
| | | } else {
|
| | | timeDistance += 365; // 不是闰年
|
| | | }
|
| | | }
|
| | | desc = timeDistance + (d2 - d1) + "天前";
|
| | | }
|
| | |
|
| | | return new JsonPrimitive(desc);
|
| | | }
|
| | |
|
| | | return new JsonPrimitive("");
|
| | | }
|
| | | });
|
| | |
|
| | | Gson gson = gb.create();
|
| | | return gson;
|
| | | }
|
| | | |
| | | |
| | | |
| | | |
| | | }
|