Authored by chaogeng

Merge branch 'test' of http://git.dev.yoho.cn/yoho30/yohobuy-activity into test

package com.yoho.activity.queue.restapi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yoho.activity.queue.ApiResponse;
import com.yoho.activity.queue.service.ITimeTaskService;
import com.yoho.queue.dal.IDrawlineActivityDAO;
import com.yoho.queue.dal.model.DrawlineActivity;
@Controller
@RequestMapping("/LuckyDrawHandlerRest")
public class LuckyDrawHandlerRest {
private static Logger logger = LoggerFactory.getLogger(LuckyDrawHandlerRest.class);
@Autowired
private ITimeTaskService timeTaskService;
@Autowired
private IDrawlineActivityDAO drawlineActivityDAO;
@RequestMapping("/luckyDraw")
@ResponseBody
public ApiResponse luckyDraw(@RequestParam("activityId") int activityId) {
logger.info("Enter luckyDraw. param activityId is {}", activityId);
DrawlineActivity drawlineActivity = drawlineActivityDAO.selectByPrimaryKey(activityId);
if (null == drawlineActivity) {
logger.warn("luckyDraw: drawlineActivity is not exists.");
return new ApiResponse(200, "luckyDraw: drawlineActivity is not exists.", new Object());
}
if (null == drawlineActivity.getEndTime()) {
logger.warn("luckyDraw: drawlineActivity endTime is not setting.");
return new ApiResponse(200, "luckyDraw: drawlineActivity endTime is not setting.", new Object());
}
long endTime = drawlineActivity.getEndTime().longValue() * 1000;
long currTime = System.currentTimeMillis();
if (endTime > currTime) {
logger.warn("luckyDraw: drawlineActivity is not end.");
return new ApiResponse(200, "luckyDraw: drawlineActivity is not end.", new Object());
}
ApiResponse apiResponse = new ApiResponse();
apiResponse.setData(timeTaskService.luckyDraw(activityId, endTime));
return apiResponse;
}
@RequestMapping("/shutdownLuckyDraw")
@ResponseBody
public ApiResponse shutdownLuckyDraw() {
logger.info("Enter shutdownLuckyDraw.");
timeTaskService.shutdownLuckyDraw();
return new ApiResponse();
}
}
... ...
... ... @@ -24,7 +24,7 @@ public class TimeTaskRest {
public ApiResponse luckyDraw() {
logger.info("Enter luckyDraw.");
JSONArray jsonArray = timeTaskService.luckyDraw(true);
JSONArray jsonArray = timeTaskService.luckyDraw();
ApiResponse apiResponse = new ApiResponse();
apiResponse.setData(jsonArray);
... ...
package com.yoho.activity.queue.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public interface ITimeTaskService {
JSONArray luckyDraw(boolean handler);
JSONArray luckyDraw();
void shutdownLuckyDraw();
... ... @@ -23,4 +24,6 @@ public interface ITimeTaskService {
void shutdownLuckyUserNotice();
JSONObject luckyDraw(Integer activityId, long endTime);
}
... ...
... ... @@ -77,8 +77,8 @@ public class TimeTaskServiceImpl implements ITimeTaskService {
}
}
public JSONArray luckyDraw(boolean handler) {
logger.info("Enter luckyDraw. param handler is {}", handler);
public JSONArray luckyDraw() {
logger.info("Enter luckyDraw.");
// (1)查询未成功抽奖的活动
List<DrawlineActivity> drawlineActivityList = drawlineActivityDAO.selectByNotLuckydraw();
... ... @@ -102,12 +102,10 @@ public class TimeTaskServiceImpl implements ITimeTaskService {
if (currentTime > endTime) {
jsonArray.add(luckyDraw(id, endTime));
} else {
if (!handler) {
if (TIMETASK_LUCKYDRAW_LIST.contains(id)) {
continue;
}
TIMETASK_LUCKYDRAW_LIST.add(id);
if (TIMETASK_LUCKYDRAW_LIST.contains(id)) {
continue;
}
TIMETASK_LUCKYDRAW_LIST.add(id);
long delay = endTime - currentTime - 300000;
delay = 0 > delay ? 0 : delay;
... ... @@ -125,7 +123,7 @@ public class TimeTaskServiceImpl implements ITimeTaskService {
return jsonArray;
}
private JSONObject luckyDraw(Integer id, long endTime) {
public JSONObject luckyDraw(Integer id, long endTime) {
logger.info("luckyDraw. param id is {}, endTiem is {}", id, endTime);
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", id);
... ...
... ... @@ -34,7 +34,7 @@ public class LuckyDrawService {
return;
}
timeTaskService.luckyDraw(false);
timeTaskService.luckyDraw();
logger.info("Outer LuckyDrawService thread run.");
}
... ...