| | |
| | | package com.yeshi.fanli.controller.client.v2;
|
| | |
|
| | | import java.io.IOException;
|
| | | 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 javax.annotation.Resource;
|
| | |
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | 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.TypeAdapter;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | | import com.google.gson.stream.JsonReader;
|
| | | import com.google.gson.stream.JsonWriter;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail.TaoLiJinDetailTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra;
|
| | | import com.yeshi.fanli.entity.bus.user.UserRank;
|
| | | import com.yeshi.fanli.entity.common.JumpDetailV2;
|
| | | import com.yeshi.fanli.entity.integral.CodePublishRecord;
|
| | | import com.yeshi.fanli.entity.integral.IntegralExchange;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTask;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTask.TaskUniqueKeyEnum;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum;
|
| | | import com.yeshi.fanli.entity.integral.IntegralTaskRecord;
|
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum;
|
| | | 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.common.JumpDetailV2Service;
|
| | | import com.yeshi.fanli.service.inter.config.ConfigService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.CodePublishRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralGetService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskClassService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRankService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService;
|
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.TimeUtil;
|
| | | import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
|
| | | import com.yeshi.fanli.vo.integral.DailySignVO;
|
| | | import com.yeshi.fanli.vo.integral.ExchangeTipVO;
|
| | | import com.yeshi.fanli.vo.integral.IntegralDetailVO;
|
| | | import com.yeshi.fanli.vo.integral.IntegralTaskClassVO;
|
| | | import com.yeshi.fanli.vo.user.UserInfoExtraVO;
|
| | |
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller
|
| | | @RequestMapping("api/v2/integral")
|
| | | public class IntegralControllerV2 {
|
| | |
|
| | | @Resource
|
| | | private ConfigService configService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoService userInfoService;
|
| | |
|
| | | @Resource
|
| | | private UserInfoExtraService userInfoExtraService;
|
| | |
|
| | | @Resource
|
| | | private IntegralTaskClassService integralTaskClassService;
|
| | |
|
| | | @Resource
|
| | | private IntegralTaskRecordService integralTaskRecordService;
|
| | |
|
| | | @Resource
|
| | | private IntegralExchangeService integralExchangeService;
|
| | |
|
| | | @Resource
|
| | | private IntegralExchangeRecordService integralExchangeRecordService;
|
| | |
|
| | | @Resource
|
| | | private IntegralDetailService integralDetailService;
|
| | |
|
| | | @Resource
|
| | | private IntegralTaskRankService integralTaskRankService;
|
| | |
|
| | | @Resource
|
| | | private CodePublishRecordService codePublishRecordService;
|
| | |
|
| | | @Resource
|
| | | private IntegralTaskService integralTaskService;
|
| | |
|
| | | @Resource
|
| | | private IntegralGetService integralGetService;
|
| | |
|
| | | @Resource
|
| | | private JumpDetailV2Service jumpDetailV2Service;
|
| | |
|
| | | /**
|
| | | * 获取任务列表
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param page
|
| | | * @param out
|
| | | */
|
| | | // @RequestSerializableByKey(key="#acceptData.device")
|
| | | @RequestMapping(value = "getTaskList", method = RequestMethod.POST)
|
| | | public void getTaskList(AcceptData acceptData, Long uid, Integer page, PrintWriter out) {
|
| | | if (uid == null || uid <= 0) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (page == null || page < 1) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "页码不正确"));
|
| | | return;
|
| | | }
|
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
|
| | | Gson gson = gsonBuilder.create();
|
| | | try {
|
| | | JSONObject data = new JSONObject();
|
| | | List<IntegralTaskClassVO> list = integralTaskClassService.getIntegralTaskClassVO(uid,
|
| | | (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE);
|
| | | if (list == null) {
|
| | | list = new ArrayList<IntegralTaskClassVO>();
|
| | | }
|
| | | long count = integralTaskClassService.countTaskClass();
|
| | |
|
| | | // 用户签到
|
| | | Integer signState = 0;
|
| | | if (page == 1) {
|
| | |
|
| | | // 签到
|
| | | try {
|
| | | signState = integralTaskClassService.finishedDailySign(uid);
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
|
| | | UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
|
| | | if (extraVO == null) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户相关信息不存在"));
|
| | | return;
|
| | | }
|
| | |
|
| | | UserInfo userInfo = extraVO.getUserInfo();
|
| | | if (userInfo == null) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "查询用户信息不全"));
|
| | | return;
|
| | | }
|
| | |
|
| | | UserRank userRank = extraVO.getUserRank();
|
| | | if (userRank == null) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户等级不存在"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 签到日期信息
|
| | | DailySignVO dailySignVO = integralTaskClassService.getDailySignList(uid, userRank.getId());
|
| | |
|
| | | boolean ejectSign = false;
|
| | | if (signState == 1)
|
| | | ejectSign = true;
|
| | |
|
| | | data.put("signState", ejectSign);
|
| | | data.put("goldCoin", extraVO.getGoldCoin());
|
| | | data.put("portrait", userInfo.getPortrait());
|
| | | data.put("userRank", gson.toJson(userRank));
|
| | | data.put("dailySign", dailySignVO);
|
| | | }
|
| | | for (int i = 0; i < list.size(); i++) {
|
| | | IntegralTaskClassVO taskClassVO = list.get(i);
|
| | |
|
| | | UniqueKeyEnum uniqueKey = taskClassVO.getUniqueKey();
|
| | |
|
| | | // 邀请好友:是否激活邀请码
|
| | | if (uniqueKey == UniqueKeyEnum.inviteTeam) {
|
| | | UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
|
| | | if (extraVO == null || StringUtil.isNullOrEmpty(extraVO.getInviteCode())) {
|
| | | JumpDetailV2 jumpDetailV2 = jumpDetailV2Service.getByTypeCache("invite_activate",
|
| | | Constant.getPlatformCode(acceptData.getPlatform()),
|
| | | Integer.parseInt(acceptData.getVersion()));
|
| | | taskClassVO.setJumpDetail(jumpDetailV2);
|
| | | }
|
| | | }
|
| | |
|
| | | String progress = taskClassVO.getProgress();
|
| | | if (StringUtil.isNullOrEmpty(progress))
|
| | | continue;
|
| | |
|
| | | Integer taskNum = taskClassVO.getTaskNum();
|
| | | if (taskNum == null)
|
| | | continue;
|
| | |
|
| | | if (uniqueKey == UniqueKeyEnum.dailySign) {
|
| | | if (signState == 0) {
|
| | | taskClassVO.setLightUp(true); // 签到失败
|
| | | } else if (signState == 1) {
|
| | | taskClassVO.setLightUp(false);
|
| | | } else if (signState == 2) {
|
| | | taskClassVO.setLightUp(false);
|
| | | }
|
| | |
|
| | | // 根据天数变化更改签到金额
|
| | | Integer num = integralTaskRecordService.getNowdaySignNum(uid, taskClassVO.getId());
|
| | |
|
| | | String uniqueKeyTask = UniqueKeyEnum.dailySign.name() + num;
|
| | | IntegralTask integralTask = integralTaskService.getByCidAndUniqueKey(taskClassVO.getId(),
|
| | | uniqueKeyTask);
|
| | | Integer goldCoin = 0;
|
| | | if (integralTask != null) {
|
| | | goldCoin = integralTask.getGoldCoin();
|
| | | Integer baseDoubleNum = integralTask.getDoubleNum();
|
| | | if (baseDoubleNum != null && baseDoubleNum > 0)
|
| | | goldCoin = goldCoin * baseDoubleNum;
|
| | | }
|
| | | taskClassVO.setTotalCoin(goldCoin);
|
| | | } else {
|
| | | taskClassVO.setLightUp(true);
|
| | | }
|
| | |
|
| | | int countFinished = 0;
|
| | | Long id = taskClassVO.getId();
|
| | | // 查询当日
|
| | | Integer totalGoldCoin = integralTaskRecordService.getTotalGoldCoin(uid, id, 1);
|
| | | if (totalGoldCoin != null && totalGoldCoin > 0) {
|
| | | taskClassVO.setFinishedCoin("+" + totalGoldCoin);
|
| | | if (uniqueKey != UniqueKeyEnum.dailySign && uniqueKey != UniqueKeyEnum.accountMaintain) {
|
| | | countFinished = integralTaskRecordService.countFinished(uid, id, 1);
|
| | | }
|
| | | }
|
| | |
|
| | | if (uniqueKey == UniqueKeyEnum.accountMaintain) {
|
| | | countFinished = integralTaskRecordService.countFinished(uid, id, null); // 查询历史
|
| | | }
|
| | |
|
| | | /*
|
| | | * // 完善信息完成后,列表中消失 if (uniqueKey ==
|
| | | * UniqueKeyEnum.accountMaintain && taskNum == countFinished) {
|
| | | * list.remove(i); i --; continue; }
|
| | | */
|
| | |
|
| | | progress = progress.replace("{已完成}", countFinished + "").replace("{总任务}", taskNum + "");
|
| | |
|
| | | if (signState == 0 && uniqueKey == UniqueKeyEnum.dailySign) {
|
| | | progress = "未签到";
|
| | | taskClassVO.setBtnName("签到");
|
| | | }
|
| | | taskClassVO.setProgress(progress);
|
| | | }
|
| | |
|
| | | data.put("count", count);
|
| | | data.put("list", gson.toJson(list));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (Exception e) {
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取已完成任务 未领取金币
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getNotReceived", method = RequestMethod.POST)
|
| | | public void getNotReceived(AcceptData acceptData, Long uid, PrintWriter out) {
|
| | | if (uid == null || uid <= 0) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | int count = Integer.MAX_VALUE;
|
| | |
|
| | | List<IntegralTaskRecord> list = integralTaskRecordService.listNotReceived(count, uid);
|
| | | if (list == null) {
|
| | | list = new ArrayList<IntegralTaskRecord>();
|
| | | }
|
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
|
| | | Gson gson = gsonBuilder.create();
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("list", gson.toJson(list));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 领取金币
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param ids
|
| | | * // 领取id
|
| | | * @param gids
|
| | | * // 未领取id
|
| | | * @param out
|
| | | */
|
| | | @RequestSerializableByKey(key = "'receiveGoldCoin-'+#uid")
|
| | | @RequestMapping(value = "receiveGoldCoin", method = RequestMethod.POST)
|
| | | public void receiveGoldCoin(AcceptData acceptData, Long uid, Integer type, String ids, String gids,
|
| | | PrintWriter out) {
|
| | | if (uid == null || uid <= 0) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | try {
|
| | | // 全部领取
|
| | | if (type != null && type == 1) {
|
| | | Integer goldCoin = integralTaskRecordService.receiveGoldCoinALL(uid);
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("goldCoin", goldCoin);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 部分领取
|
| | | Gson gson = new Gson();
|
| | | Set<Long> idList = gson.fromJson(ids, new TypeToken<HashSet<Long>>() {
|
| | | }.getType());
|
| | | if (idList == null || idList.size() == 0) {
|
| | | out.print(JsonUtil.loadFalseResult("领取id不能为空"));
|
| | | return;
|
| | | }
|
| | | Integer goldCoin = integralTaskRecordService.receiveGoldCoin(uid, idList);
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("goldCoin", goldCoin);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (IntegralTaskRecordException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getMsg()));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 金币兑换列表
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param ids
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getExchangeList", method = RequestMethod.POST)
|
| | | public void getExchangeList(AcceptData acceptData, Long uid, Integer page, PrintWriter out) {
|
| | | if (uid == null || uid <= 0) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (page == null || page < 1) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "页码不正确"));
|
| | | return;
|
| | | }
|
| | |
|
| | | UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid);
|
| | | if (extraVO == null) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户相关信息不存在"));
|
| | | return;
|
| | | }
|
| | |
|
| | | List<IntegralExchange> list = integralExchangeRecordService.listExchange((page - 1) * Constant.PAGE_SIZE,
|
| | | Constant.PAGE_SIZE, uid);
|
| | | if (list == null)
|
| | | list = new ArrayList<IntegralExchange>();
|
| | |
|
| | | // Long count = integralExchangeService.countValid();
|
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
|
| | | Gson gson = gsonBuilder.create();
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("goldCoin", extraVO.getGoldCoin() + "枚");
|
| | | data.put("count", list.size());
|
| | | data.put("list", gson.toJson(list));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | @RequestMapping(value = "getExchangeDetail")
|
| | | public void getExchangeDetail(AcceptData acceptData, Long id, String callback, PrintWriter out) {
|
| | | if (id == null || id <= 0) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "兑换ID有误"));
|
| | | return;
|
| | | }
|
| | | IntegralExchange exchange = integralExchangeService.selectByPrimaryKey(id);
|
| | | if (exchange != null) {
|
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
|
| | | Gson gson = gsonBuilder.create();
|
| | | if (StringUtil.isNullOrEmpty(callback))
|
| | | out.print(JsonUtil.loadTrueResult(gson.toJson(exchange)));
|
| | | else
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(gson.toJson(exchange))));
|
| | | } else {
|
| | | if (StringUtil.isNullOrEmpty(callback))
|
| | | out.print(JsonUtil.loadFalseResult("未找到"));
|
| | | else
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("未找到")));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 兑换金币检验
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param id
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "verifyExchange")
|
| | | public void verifyExchange(AcceptData acceptData, Long uid, Long id, String callback, PrintWriter out) {
|
| | | try {
|
| | | ExchangeTipVO exchange = integralExchangeService.verifyExchange(uid, id);
|
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
|
| | | Gson gson = gsonBuilder.create();
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("result", gson.toJson(exchange));
|
| | | if (StringUtil.isNullOrEmpty(callback)) {
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } else {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
|
| | | }
|
| | | } catch (IntegralExchangeException e) {
|
| | | if (StringUtil.isNullOrEmpty(callback)) {
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | } else {
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(1, e.getMsg())));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 兑换金币
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param id
|
| | | * @param out
|
| | | */
|
| | | @RequestSerializableByKey(key = "'integralexchange-'+#uid")
|
| | | @RequestMapping(value = "exchange")
|
| | | public void exchange(AcceptData acceptData, Long uid, Long id, String callback, PrintWriter out) {
|
| | | try {
|
| | | IntegralExchange exchange = integralExchangeService.exchange(uid, id);
|
| | |
|
| | | UserInfoExtra extraVO = userInfoExtraService.getUserInfoExtra(uid);
|
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
|
| | | Gson gson = gsonBuilder.create();
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("result", gson.toJson(exchange));
|
| | | data.put("goldCoin", extraVO.getGoldCoin() + "枚");
|
| | | if (StringUtil.isNullOrEmpty(callback))
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | else
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
|
| | | } catch (IntegralExchangeException e) {
|
| | | if (StringUtil.isNullOrEmpty(callback))
|
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg()));
|
| | | else
|
| | | out.print(JsonUtil.loadJSONP(callback, 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
|
| | | */
|
| | | @RequestSerializableByKey(key = "'exchangeInviteCode-'+#uid")
|
| | | @RequestMapping(value = "exchangeInviteCode", method = RequestMethod.POST)
|
| | | public void exchangeInviteCode(AcceptData acceptData, Long uid, Long id, PrintWriter out) {
|
| | | try {
|
| | | String inviteCode = integralExchangeService.exchangeInviteCode(uid, id);
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("msg", "兑换成功,金币已消耗 ");
|
| | | data.put("inviteCode", inviteCode);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } 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;
|
| | | }
|
| | |
|
| | | try {
|
| | | List<CodePublishRecord> list = codePublishRecordService.listValid(null, (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(ConfigKeyEnum.publishListHelpLink.getKey()));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "获取失败"));
|
| | | return;
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 事件推送
|
| | | * |
| | | * @param acceptData
|
| | | * @param event
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "pushEvent", method = RequestMethod.POST)
|
| | | public void pushEvent(AcceptData acceptData, String event, Long uid, String data, PrintWriter out) {
|
| | | if (uid == null || uid == 0) {
|
| | | out.print(JsonUtil.loadFalseResult("用户尚未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(event)) {
|
| | | out.print(JsonUtil.loadFalseResult("事件为空"));
|
| | | return;
|
| | | }
|
| | | IntegralTaskRecord record = null;
|
| | |
|
| | | try {
|
| | | if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)) {
|
| | | record = integralGetService.addRecommendSearch(uid);
|
| | | } else if (TaskUniqueKeyEnum.shareInvite.name().equalsIgnoreCase(event)) {
|
| | | record = integralGetService.addShareInvite(uid);
|
| | | } else if (TaskUniqueKeyEnum.inShop.name().equalsIgnoreCase(event)) {
|
| | | JSONObject json = JSONObject.fromObject(data);
|
| | | record = integralGetService.addIntoShop(uid, StringUtil.Md5(json.optString("url")));
|
| | | } else if (TaskUniqueKeyEnum.scanPush.name().equalsIgnoreCase(event)) {
|
| | | record = integralGetService.addScanPushHistory(uid);
|
| | | } else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)) {
|
| | | JSONObject json = JSONObject.fromObject(data);
|
| | | record = integralGetService.addScanGoodsDetail(uid, json.optInt("goodsType"), json.optLong("goodsId"));
|
| | | } else if (TaskUniqueKeyEnum.scanHomeBanner.name().equalsIgnoreCase(event)) {
|
| | | JSONObject json = JSONObject.fromObject(data);
|
| | | record = integralGetService.addScanRecommendBanner(uid, json.optString("id"));
|
| | | } else if (TaskUniqueKeyEnum.scanSpecial.name().equalsIgnoreCase(event)) {
|
| | | JSONObject json = JSONObject.fromObject(data);
|
| | | record = integralGetService.addScanRecommendSpecial(uid, json.optString("id"));
|
| | | } else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) {
|
| | | record = integralGetService.addScanTaoBaoCart(uid);
|
| | | }
|
| | |
|
| | | if (record != null) {
|
| | | JSONObject notifyData = new JSONObject();
|
| | | if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)
|
| | | || TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)
|
| | | || TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) {
|
| | | JSONObject notify = new JSONObject();
|
| | | if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event))
|
| | | notify.put("name", "完成一次智能搜索");
|
| | | else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event))
|
| | | notify.put("name", "完成一次商品浏览");
|
| | | else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event))
|
| | | notify.put("name", "完成一次购物车浏览");
|
| | |
|
| | | notify.put("score", String.format("+%s金币", record.getGoldCoin()));
|
| | | notifyData.put("notify", notify);
|
| | | }
|
| | | out.print(JsonUtil.loadTrueResult(notifyData));
|
| | | } else {
|
| | | out.print(JsonUtil.loadFalseResult(""));
|
| | | }
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult(""));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 时间处理
|
| | | * |
| | | * @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;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 明细详情
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param index
|
| | | * List最末的主键ID
|
| | | * @param year
|
| | | * 年份
|
| | | * @param month
|
| | | * 月份
|
| | | * @param type
|
| | | * 统计类型 0全部 1
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getDetails")
|
| | | public void getDetails(AcceptData acceptData, Long uid, Long index, Integer year, Integer month, Integer type,
|
| | | PrintWriter out) {
|
| | | if (uid == null || uid == 0) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if ((year == null && month != null) || (year != null && month == null)) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "日期不完整"));
|
| | | return;
|
| | | }
|
| | |
|
| | | Date date = null;
|
| | |
|
| | | if (year != null && month != null) {
|
| | | date = new Date(TimeUtil.convertToTimeTemp(year + "-" + month, "yyyy-M"));
|
| | | Calendar ca = Calendar.getInstance();
|
| | | ca.setTime(date);
|
| | | ca.add(Calendar.MONTH, 1);
|
| | | date = new Date(ca.getTimeInMillis() - 1);
|
| | | }
|
| | |
|
| | | // 查询列表
|
| | | List<IntegralDetailVO> list = integralDetailService.listDetailForClient(uid, index, date, type);
|
| | | // 统计总条数
|
| | | long count = integralDetailService.countDetailForClient(uid, index, date, type);
|
| | |
|
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation();
|
| | | gsonBuilder.registerTypeAdapter(TaoLiJinDetailTypeEnum.class, new TypeAdapter<TaoLiJinDetailTypeEnum>() {
|
| | | @Override
|
| | | public TaoLiJinDetailTypeEnum read(JsonReader arg0) throws IOException {
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void write(JsonWriter out, TaoLiJinDetailTypeEnum arg1) throws IOException {
|
| | | out.beginObject();
|
| | | out.name("portrait").value(arg1.getPicture());
|
| | | out.endObject();
|
| | | }
|
| | | }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
|
| | | @Override
|
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
|
| | | if (value == null) {
|
| | | return new JsonPrimitive("");
|
| | | } else {
|
| | | return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy.MM.dd HH:mm"));
|
| | | }
|
| | | }
|
| | | });
|
| | |
|
| | | Gson gson = gsonBuilder.create();
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("count", count);
|
| | | data.put("data", gson.toJson(list));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | | }
|
| | | package com.yeshi.fanli.controller.client.v2; |
| | | |
| | | import java.io.IOException; |
| | | 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 javax.annotation.Resource; |
| | | |
| | | import com.yeshi.fanli.util.*; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.yeshi.utils.JsonUtil; |
| | | |
| | | 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.TypeAdapter; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.google.gson.stream.JsonReader; |
| | | import com.google.gson.stream.JsonWriter; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.bus.tlj.UserTaoLiJinDetail.TaoLiJinDetailTypeEnum; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfo; |
| | | import com.yeshi.fanli.entity.bus.user.UserInfoExtra; |
| | | import com.yeshi.fanli.entity.bus.user.UserRank; |
| | | import com.yeshi.fanli.entity.common.JumpDetailV2; |
| | | import com.yeshi.fanli.entity.integral.CodePublishRecord; |
| | | import com.yeshi.fanli.entity.integral.IntegralExchange; |
| | | import com.yeshi.fanli.entity.integral.IntegralExchange.ExchangeTypeEnum; |
| | | import com.yeshi.fanli.entity.integral.IntegralTask; |
| | | import com.yeshi.fanli.entity.integral.IntegralTask.TaskUniqueKeyEnum; |
| | | import com.yeshi.fanli.entity.integral.IntegralTaskClass.UniqueKeyEnum; |
| | | import com.yeshi.fanli.entity.integral.IntegralTaskRecord; |
| | | import com.yeshi.fanli.entity.system.ConfigKeyEnum; |
| | | 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.common.JumpDetailV2Service; |
| | | import com.yeshi.fanli.service.inter.config.ConfigService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService; |
| | | import com.yeshi.fanli.service.inter.user.UserInfoService; |
| | | import com.yeshi.fanli.service.inter.user.integral.CodePublishRecordService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralDetailService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeRecordService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralExchangeService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralGetService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskClassService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRankService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskRecordService; |
| | | import com.yeshi.fanli.service.inter.user.integral.IntegralTaskService; |
| | | import com.yeshi.fanli.util.annotation.RequestSerializableByKey; |
| | | import com.yeshi.fanli.vo.integral.DailySignVO; |
| | | import com.yeshi.fanli.vo.integral.ExchangeTipVO; |
| | | import com.yeshi.fanli.vo.integral.IntegralDetailVO; |
| | | import com.yeshi.fanli.vo.integral.IntegralTaskClassVO; |
| | | import com.yeshi.fanli.vo.user.UserInfoExtraVO; |
| | | |
| | | import net.sf.json.JSONObject; |
| | | import org.yeshi.utils.TimeUtil; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/v2/integral") |
| | | public class IntegralControllerV2 { |
| | | |
| | | @Resource |
| | | private ConfigService configService; |
| | | |
| | | @Resource |
| | | private UserInfoService userInfoService; |
| | | |
| | | @Resource |
| | | private UserInfoExtraService userInfoExtraService; |
| | | |
| | | @Resource |
| | | private IntegralTaskClassService integralTaskClassService; |
| | | |
| | | @Resource |
| | | private IntegralTaskRecordService integralTaskRecordService; |
| | | |
| | | @Resource |
| | | private IntegralExchangeService integralExchangeService; |
| | | |
| | | @Resource |
| | | private IntegralExchangeRecordService integralExchangeRecordService; |
| | | |
| | | @Resource |
| | | private IntegralDetailService integralDetailService; |
| | | |
| | | @Resource |
| | | private IntegralTaskRankService integralTaskRankService; |
| | | |
| | | @Resource |
| | | private CodePublishRecordService codePublishRecordService; |
| | | |
| | | @Resource |
| | | private IntegralTaskService integralTaskService; |
| | | |
| | | @Resource |
| | | private IntegralGetService integralGetService; |
| | | |
| | | @Resource |
| | | private JumpDetailV2Service jumpDetailV2Service; |
| | | |
| | | /** |
| | | * 获取任务列表 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param page |
| | | * @param out |
| | | */ |
| | | // @RequestSerializableByKey(key="#acceptData.device") |
| | | @RequestMapping(value = "getTaskList", method = RequestMethod.POST) |
| | | public void getTaskList(AcceptData acceptData, Long uid, Integer page, PrintWriter out) { |
| | | if (uid == null || uid <= 0) { |
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | if (page == null || page < 1) { |
| | | out.print(JsonUtil.loadFalseResult(1, "页码不正确")); |
| | | return; |
| | | } |
| | | |
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); |
| | | Gson gson = gsonBuilder.create(); |
| | | try { |
| | | JSONObject data = new JSONObject(); |
| | | List<IntegralTaskClassVO> list = integralTaskClassService.getIntegralTaskClassVO(uid, |
| | | (page - 1) * Constant.PAGE_SIZE, Constant.PAGE_SIZE); |
| | | if (list == null) { |
| | | list = new ArrayList<IntegralTaskClassVO>(); |
| | | } |
| | | long count = integralTaskClassService.countTaskClass(); |
| | | |
| | | // 用户签到 |
| | | Integer signState = 0; |
| | | if (page == 1) { |
| | | |
| | | // 签到 |
| | | try { |
| | | signState = integralTaskClassService.finishedDailySign(uid); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid); |
| | | if (extraVO == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "用户相关信息不存在")); |
| | | return; |
| | | } |
| | | |
| | | UserInfo userInfo = extraVO.getUserInfo(); |
| | | if (userInfo == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "查询用户信息不全")); |
| | | return; |
| | | } |
| | | |
| | | UserRank userRank = extraVO.getUserRank(); |
| | | if (userRank == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "用户等级不存在")); |
| | | return; |
| | | } |
| | | |
| | | // 签到日期信息 |
| | | DailySignVO dailySignVO = integralTaskClassService.getDailySignList(uid, userRank.getId()); |
| | | |
| | | boolean ejectSign = false; |
| | | if (signState == 1) |
| | | ejectSign = true; |
| | | |
| | | data.put("signState", ejectSign); |
| | | data.put("goldCoin", extraVO.getGoldCoin()); |
| | | data.put("portrait", userInfo.getPortrait()); |
| | | data.put("userRank", gson.toJson(userRank)); |
| | | data.put("dailySign", dailySignVO); |
| | | } |
| | | for (int i = 0; i < list.size(); i++) { |
| | | IntegralTaskClassVO taskClassVO = list.get(i); |
| | | |
| | | UniqueKeyEnum uniqueKey = taskClassVO.getUniqueKey(); |
| | | |
| | | // 邀请好友:是否激活邀请码 |
| | | if (uniqueKey == UniqueKeyEnum.inviteTeam) { |
| | | UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid); |
| | | if (extraVO == null || StringUtil.isNullOrEmpty(extraVO.getInviteCode())) { |
| | | JumpDetailV2 jumpDetailV2 = jumpDetailV2Service.getByTypeCache("invite_activate", |
| | | Constant.getPlatformCode(acceptData.getPlatform()), |
| | | Integer.parseInt(acceptData.getVersion()),acceptData.getSystem()); |
| | | taskClassVO.setJumpDetail(jumpDetailV2); |
| | | } |
| | | } |
| | | |
| | | String progress = taskClassVO.getProgress(); |
| | | if (StringUtil.isNullOrEmpty(progress)) |
| | | continue; |
| | | |
| | | Integer taskNum = taskClassVO.getTaskNum(); |
| | | if (taskNum == null) |
| | | continue; |
| | | |
| | | if (uniqueKey == UniqueKeyEnum.dailySign) { |
| | | if (signState == 0) { |
| | | taskClassVO.setLightUp(true); // 签到失败 |
| | | } else if (signState == 1) { |
| | | taskClassVO.setLightUp(false); |
| | | } else if (signState == 2) { |
| | | taskClassVO.setLightUp(false); |
| | | } |
| | | |
| | | // 根据天数变化更改签到金额 |
| | | Integer num = integralTaskRecordService.getNowdaySignNum(uid, taskClassVO.getId()); |
| | | |
| | | String uniqueKeyTask = UniqueKeyEnum.dailySign.name() + num; |
| | | IntegralTask integralTask = integralTaskService.getByCidAndUniqueKey(taskClassVO.getId(), |
| | | uniqueKeyTask); |
| | | Integer goldCoin = 0; |
| | | if (integralTask != null) { |
| | | goldCoin = integralTask.getGoldCoin(); |
| | | Integer baseDoubleNum = integralTask.getDoubleNum(); |
| | | if (baseDoubleNum != null && baseDoubleNum > 0) |
| | | goldCoin = goldCoin * baseDoubleNum; |
| | | } |
| | | taskClassVO.setTotalCoin(goldCoin); |
| | | } else { |
| | | taskClassVO.setLightUp(true); |
| | | } |
| | | |
| | | int countFinished = 0; |
| | | Long id = taskClassVO.getId(); |
| | | // 查询当日 |
| | | Integer totalGoldCoin = integralTaskRecordService.getTotalGoldCoin(uid, id, 1); |
| | | if (totalGoldCoin != null && totalGoldCoin > 0) { |
| | | taskClassVO.setFinishedCoin("+" + totalGoldCoin); |
| | | if (uniqueKey != UniqueKeyEnum.dailySign && uniqueKey != UniqueKeyEnum.accountMaintain) { |
| | | countFinished = integralTaskRecordService.countFinished(uid, id, 1); |
| | | } |
| | | } |
| | | |
| | | if (uniqueKey == UniqueKeyEnum.accountMaintain) { |
| | | countFinished = integralTaskRecordService.countFinished(uid, id, null); // 查询历史 |
| | | } |
| | | |
| | | /* |
| | | * // 完善信息完成后,列表中消失 if (uniqueKey == |
| | | * UniqueKeyEnum.accountMaintain && taskNum == countFinished) { |
| | | * list.remove(i); i --; continue; } |
| | | */ |
| | | |
| | | progress = progress.replace("{已完成}", countFinished + "").replace("{总任务}", taskNum + ""); |
| | | |
| | | if (signState == 0 && uniqueKey == UniqueKeyEnum.dailySign) { |
| | | progress = "未签到"; |
| | | taskClassVO.setBtnName("签到"); |
| | | } |
| | | taskClassVO.setProgress(progress); |
| | | } |
| | | |
| | | data.put("count", count); |
| | | data.put("list", gson.toJson(list)); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } catch (Exception e) { |
| | | LogHelper.errorDetailInfo(e); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取已完成任务 未领取金币 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "getNotReceived", method = RequestMethod.POST) |
| | | public void getNotReceived(AcceptData acceptData, Long uid, PrintWriter out) { |
| | | if (uid == null || uid <= 0) { |
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | int count = Integer.MAX_VALUE; |
| | | |
| | | List<IntegralTaskRecord> list = integralTaskRecordService.listNotReceived(count, uid); |
| | | if (list == null) { |
| | | list = new ArrayList<IntegralTaskRecord>(); |
| | | } |
| | | |
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); |
| | | Gson gson = gsonBuilder.create(); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("list", gson.toJson(list)); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } |
| | | |
| | | /** |
| | | * 领取金币 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param ids |
| | | * // 领取id |
| | | * @param gids |
| | | * // 未领取id |
| | | * @param out |
| | | */ |
| | | @RequestSerializableByKey(key = "'receiveGoldCoin-'+#uid") |
| | | @RequestMapping(value = "receiveGoldCoin", method = RequestMethod.POST) |
| | | public void receiveGoldCoin(AcceptData acceptData, Long uid, Integer type, String ids, String gids, |
| | | PrintWriter out) { |
| | | if (uid == null || uid <= 0) { |
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | // 全部领取 |
| | | if (type != null && type == 1) { |
| | | Integer goldCoin = integralTaskRecordService.receiveGoldCoinALL(uid); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("goldCoin", goldCoin); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | return; |
| | | } |
| | | |
| | | // 部分领取 |
| | | Gson gson = new Gson(); |
| | | Set<Long> idList = gson.fromJson(ids, new TypeToken<HashSet<Long>>() { |
| | | }.getType()); |
| | | if (idList == null || idList.size() == 0) { |
| | | out.print(JsonUtil.loadFalseResult("领取id不能为空")); |
| | | return; |
| | | } |
| | | Integer goldCoin = integralTaskRecordService.receiveGoldCoin(uid, idList); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("goldCoin", goldCoin); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } catch (IntegralTaskRecordException e) { |
| | | out.print(JsonUtil.loadFalseResult(e.getMsg())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 金币兑换列表 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param ids |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "getExchangeList", method = RequestMethod.POST) |
| | | public void getExchangeList(AcceptData acceptData, Long uid, Integer page, PrintWriter out) { |
| | | if (uid == null || uid <= 0) { |
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | if (page == null || page < 1) { |
| | | out.print(JsonUtil.loadFalseResult(1, "页码不正确")); |
| | | return; |
| | | } |
| | | |
| | | UserInfoExtraVO extraVO = userInfoExtraService.getInfoExtraVOByUid(uid); |
| | | if (extraVO == null) { |
| | | out.print(JsonUtil.loadFalseResult(1, "用户相关信息不存在")); |
| | | return; |
| | | } |
| | | |
| | | List<IntegralExchange> list = integralExchangeRecordService.listExchange((page - 1) * Constant.PAGE_SIZE, |
| | | Constant.PAGE_SIZE, uid); |
| | | |
| | | List<IntegralExchange> listNew = new ArrayList<>(); |
| | | if (list != null) |
| | | listNew.addAll(list); |
| | | |
| | | if (VersionUtil.greaterThan_2_0_7(acceptData.getPlatform(), acceptData.getVersion())) { |
| | | for (int i=0; i < listNew.size(); i ++) { |
| | | IntegralExchange integralExchange = listNew.get(i); |
| | | ExchangeTypeEnum type = integralExchange.getType(); |
| | | if (type != null && |
| | | (type == ExchangeTypeEnum.inviteCodeActivate || type == ExchangeTypeEnum.inviteCodePublish)) { |
| | | listNew.remove(i); |
| | | i--; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // Long count = integralExchangeService.countValid(); |
| | | |
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); |
| | | Gson gson = gsonBuilder.create(); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("goldCoin", extraVO.getGoldCoin() + "枚"); |
| | | data.put("count", listNew.size()); |
| | | data.put("list", gson.toJson(listNew)); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } |
| | | |
| | | @RequestMapping(value = "getExchangeDetail") |
| | | public void getExchangeDetail(AcceptData acceptData, Long id, String callback, PrintWriter out) { |
| | | if (id == null || id <= 0) { |
| | | out.print(JsonUtil.loadFalseResult(1, "兑换ID有误")); |
| | | return; |
| | | } |
| | | IntegralExchange exchange = integralExchangeService.selectByPrimaryKey(id); |
| | | if (exchange != null) { |
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); |
| | | Gson gson = gsonBuilder.create(); |
| | | if (StringUtil.isNullOrEmpty(callback)) |
| | | out.print(JsonUtil.loadTrueResult(gson.toJson(exchange))); |
| | | else |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(gson.toJson(exchange)))); |
| | | } else { |
| | | if (StringUtil.isNullOrEmpty(callback)) |
| | | out.print(JsonUtil.loadFalseResult("未找到")); |
| | | else |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult("未找到"))); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 兑换金币检验 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param id |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "verifyExchange") |
| | | public void verifyExchange(AcceptData acceptData, Long uid, Long id, String callback, PrintWriter out) { |
| | | try { |
| | | ExchangeTipVO exchange = integralExchangeService.verifyExchange(uid, id); |
| | | |
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); |
| | | Gson gson = gsonBuilder.create(); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("result", gson.toJson(exchange)); |
| | | if (StringUtil.isNullOrEmpty(callback)) { |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } else { |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); |
| | | } |
| | | } catch (IntegralExchangeException e) { |
| | | if (StringUtil.isNullOrEmpty(callback)) { |
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg())); |
| | | } else { |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadFalseResult(1, e.getMsg()))); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 兑换金币 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param id |
| | | * @param out |
| | | */ |
| | | @RequestSerializableByKey(key = "'integralexchange-'+#uid") |
| | | @RequestMapping(value = "exchange") |
| | | public void exchange(AcceptData acceptData, Long uid, Long id, String callback, PrintWriter out) { |
| | | try { |
| | | IntegralExchange exchange = integralExchangeService.exchange(uid, id); |
| | | |
| | | UserInfoExtra extraVO = userInfoExtraService.getUserInfoExtra(uid); |
| | | |
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); |
| | | Gson gson = gsonBuilder.create(); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("result", gson.toJson(exchange)); |
| | | data.put("goldCoin", extraVO.getGoldCoin() + "枚"); |
| | | if (StringUtil.isNullOrEmpty(callback)) |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | else |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); |
| | | } catch (IntegralExchangeException e) { |
| | | if (StringUtil.isNullOrEmpty(callback)) |
| | | out.print(JsonUtil.loadFalseResult(1, e.getMsg())); |
| | | else |
| | | out.print(JsonUtil.loadJSONP(callback, 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 |
| | | */ |
| | | @RequestSerializableByKey(key = "'exchangeInviteCode-'+#uid") |
| | | @RequestMapping(value = "exchangeInviteCode", method = RequestMethod.POST) |
| | | public void exchangeInviteCode(AcceptData acceptData, Long uid, Long id, PrintWriter out) { |
| | | try { |
| | | String inviteCode = integralExchangeService.exchangeInviteCode(uid, id); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("msg", "兑换成功,金币已消耗 "); |
| | | data.put("inviteCode", inviteCode); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } 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; |
| | | } |
| | | |
| | | try { |
| | | List<CodePublishRecord> list = codePublishRecordService.listValid(null, (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.getValue(ConfigKeyEnum.publishListHelpLink.getKey(), SystemInfoUtil.getSystem(acceptData))); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult(1, "获取失败")); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 事件推送 |
| | | * |
| | | * @param acceptData |
| | | * @param event |
| | | * @param uid |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "pushEvent", method = RequestMethod.POST) |
| | | public void pushEvent(AcceptData acceptData, String event, Long uid, String data, PrintWriter out) { |
| | | if (uid == null || uid == 0) { |
| | | out.print(JsonUtil.loadFalseResult("用户尚未登录")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(event)) { |
| | | out.print(JsonUtil.loadFalseResult("事件为空")); |
| | | return; |
| | | } |
| | | IntegralTaskRecord record = null; |
| | | |
| | | try { |
| | | if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)) { |
| | | record = integralGetService.addRecommendSearch(uid); |
| | | } else if (TaskUniqueKeyEnum.shareInvite.name().equalsIgnoreCase(event)) { |
| | | record = integralGetService.addShareInvite(uid); |
| | | } else if (TaskUniqueKeyEnum.inShop.name().equalsIgnoreCase(event)) { |
| | | JSONObject json = JSONObject.fromObject(data); |
| | | record = integralGetService.addIntoShop(uid, StringUtil.Md5(json.optString("url"))); |
| | | } else if (TaskUniqueKeyEnum.scanPush.name().equalsIgnoreCase(event)) { |
| | | record = integralGetService.addScanPushHistory(uid); |
| | | } else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)) { |
| | | JSONObject json = JSONObject.fromObject(data); |
| | | record = integralGetService.addScanGoodsDetail(uid, json.optInt("goodsType"), json.optString("goodsId")); |
| | | } else if (TaskUniqueKeyEnum.scanHomeBanner.name().equalsIgnoreCase(event)) { |
| | | JSONObject json = JSONObject.fromObject(data); |
| | | record = integralGetService.addScanRecommendBanner(uid, json.optString("id")); |
| | | } else if (TaskUniqueKeyEnum.scanSpecial.name().equalsIgnoreCase(event)) { |
| | | JSONObject json = JSONObject.fromObject(data); |
| | | record = integralGetService.addScanRecommendSpecial(uid, json.optString("id")); |
| | | } else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) { |
| | | record = integralGetService.addScanTaoBaoCart(uid); |
| | | } |
| | | |
| | | if (record != null) { |
| | | JSONObject notifyData = new JSONObject(); |
| | | if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event) |
| | | || TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event) |
| | | || TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) { |
| | | JSONObject notify = new JSONObject(); |
| | | if (TaskUniqueKeyEnum.recommendSearch.name().equalsIgnoreCase(event)) |
| | | notify.put("name", "完成一次智能搜索"); |
| | | else if (TaskUniqueKeyEnum.scanGoods.name().equalsIgnoreCase(event)) |
| | | notify.put("name", "完成一次商品浏览"); |
| | | else if (TaskUniqueKeyEnum.scanTBCart.name().equalsIgnoreCase(event)) |
| | | notify.put("name", "完成一次购物车浏览"); |
| | | |
| | | notify.put("score", String.format("+%s金币", record.getGoldCoin())); |
| | | notifyData.put("notify", notify); |
| | | } |
| | | out.print(JsonUtil.loadTrueResult(notifyData)); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseResult("")); |
| | | } |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseResult("")); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 时间处理 |
| | | * |
| | | * @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; |
| | | } |
| | | |
| | | /** |
| | | * 明细详情 |
| | | * |
| | | * @param acceptData |
| | | * @param uid |
| | | * @param index |
| | | * List最末的主键ID |
| | | * @param year |
| | | * 年份 |
| | | * @param month |
| | | * 月份 |
| | | * @param type |
| | | * 统计类型 0全部 1 |
| | | * @param out |
| | | */ |
| | | @RequestMapping(value = "getDetails") |
| | | public void getDetails(AcceptData acceptData, Long uid, Long index, Integer year, Integer month, Integer type, |
| | | PrintWriter out) { |
| | | if (uid == null || uid == 0) { |
| | | out.print(JsonUtil.loadFalseResult(1, "用户未登录")); |
| | | return; |
| | | } |
| | | |
| | | if ((year == null && month != null) || (year != null && month == null)) { |
| | | out.print(JsonUtil.loadFalseResult(1, "日期不完整")); |
| | | return; |
| | | } |
| | | |
| | | Date date = null; |
| | | |
| | | if (year != null && month != null) { |
| | | date = new Date(TimeUtil.convertToTimeTemp(year + "-" + month, "yyyy-M")); |
| | | Calendar ca = Calendar.getInstance(); |
| | | ca.setTime(date); |
| | | ca.add(Calendar.MONTH, 1); |
| | | date = new Date(ca.getTimeInMillis() - 1); |
| | | } |
| | | |
| | | // 查询列表 |
| | | List<IntegralDetailVO> list = integralDetailService.listDetailForClient(uid, index, date, type); |
| | | // 统计总条数 |
| | | long count = integralDetailService.countDetailForClient(uid, index, date, type); |
| | | |
| | | GsonBuilder gsonBuilder = new GsonBuilder().excludeFieldsWithoutExposeAnnotation(); |
| | | gsonBuilder.registerTypeAdapter(TaoLiJinDetailTypeEnum.class, new TypeAdapter<TaoLiJinDetailTypeEnum>() { |
| | | @Override |
| | | public TaoLiJinDetailTypeEnum read(JsonReader arg0) throws IOException { |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public void write(JsonWriter out, TaoLiJinDetailTypeEnum arg1) throws IOException { |
| | | out.beginObject(); |
| | | out.name("portrait").value(arg1.getPicture()); |
| | | out.endObject(); |
| | | } |
| | | }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | @Override |
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive(""); |
| | | } else { |
| | | return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy.MM.dd HH:mm")); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | Gson gson = gsonBuilder.create(); |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("count", count); |
| | | data.put("data", gson.toJson(list)); |
| | | out.print(JsonUtil.loadTrueResult(data)); |
| | | } |
| | | } |