Authored by ping

update

... ... @@ -14,13 +14,13 @@ public class ActVoteResultVO extends BaseBO {
private int uid;
//活动信息
private List<ActVoteResult> itemIds;
private String itemIds;
public List<ActVoteResult> getItemIds() {
public String getItemIds() {
return itemIds;
}
public void setItemIds(List<ActVoteResult> itemIds) {
public void setItemIds(String itemIds) {
this.itemIds = itemIds;
}
... ...
... ... @@ -5,10 +5,10 @@ package com.yoho.activity.controller;
import javax.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
... ... @@ -19,20 +19,20 @@ import com.yoho.activity.service.IActVoteResultService;
/**
* 描述:
*
* @author ping.huang
* 2016年4月1日
* @author ping.huang 2016年4月1日
*/
@Controller
@RequestMapping("/ActVoteResultController")
public class ActVoteResultController {
static Logger log = LoggerFactory.getLogger(ActVoteResultController.class);
@Resource
IActVoteResultService actVoteResultService;
/**
* 根据uid查询已投票数量
*
* @param uid
* @return
* @throws Exception
... ... @@ -45,10 +45,10 @@ public class ActVoteResultController {
log.info("getActVoteNumByUid success. with uid={}", voteResult.getUid());
return response;
}
/**
* 插入投票信息
*
* @param voteResult
* @return
* @throws Exception
... ... @@ -57,12 +57,12 @@ public class ActVoteResultController {
@ResponseBody
public ApiResponse addActVoteResult(ActVoteResultVO voteResult) throws Exception {
log.info("addActVoteResult with uid={}", voteResult);
if(voteResult == null || voteResult.getItemIds().size() == 0){
if (voteResult == null || StringUtils.isEmpty(voteResult.getItemIds())) {
log.warn("addActVoteResult error. with voteResult empty ");
return new ApiResponse(500,"请求参数为空!");
return new ApiResponse(500, "请求参数为空!");
}
actVoteResultService.insertVoteResultInfo(voteResult);
ApiResponse response = actVoteResultService.insertVoteResultInfo(voteResult);
log.info("addActVoteResult success. with uid={}", voteResult);
return new ApiResponse();
return response;
}
}
... ...
... ... @@ -30,7 +30,7 @@ public interface IActVoteResultService {
* @return
* @throws Exception
*/
public void insertVoteResultInfo(ActVoteResultVO voteResult) throws Exception;
public ApiResponse insertVoteResultInfo(ActVoteResultVO voteResult) throws Exception;
}
... ...
... ... @@ -7,10 +7,12 @@ import java.util.List;
import javax.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.yoho.activity.common.ApiResponse;
import com.yoho.activity.common.vo.ActVoteResultVO;
import com.yoho.activity.dal.ActVoteResultMapper;
... ... @@ -25,31 +27,38 @@ import com.yoho.core.common.utils.DateUtil;
public class ActVoteResultServiceImpl implements IActVoteResultService {
static Logger log = LoggerFactory.getLogger(ActVoteResultServiceImpl.class);
@Resource
private ActVoteResultMapper actVoteResultMapper;
@Override
public ApiResponse selectVoteNumByUid(int uid) throws Exception {
log.info("selectVoteNumByUid with uid={}",uid);
List<ActVoteResult> votedList = actVoteResultMapper.selectActVoteResultByUid(uid);
log.info("selectVoteNumByUid success. uid={}",uid);
log.info("selectVoteNumByUid with uid={}", uid);
List<ActVoteResult> votedList = actVoteResultMapper.selectActVoteResultByUid(uid);
log.info("selectVoteNumByUid success. uid={}", uid);
return new ApiResponse(votedList);
}
@Override
public void insertVoteResultInfo(ActVoteResultVO voteResult) throws Exception {
log.info("insertVoteResultInfo with voteResult={}",voteResult);
List<ActVoteResult> actVoteResult = voteResult.getItemIds();
if(actVoteResult.size() == 0){
public ApiResponse insertVoteResultInfo(ActVoteResultVO voteResult) throws Exception {
log.info("insertVoteResultInfo with voteResult={}", voteResult);
List<ActVoteResult> votedList = actVoteResultMapper.selectActVoteResultByUid(voteResult.getUid());
if (CollectionUtils.isNotEmpty(votedList) && votedList.size() > 0) {
log.warn("insertVoteResultInfo error voteResult={}", voteResult);
return new ApiResponse(201, "您已经投过票了");
}
List<ActVoteResult> actVoteResult = JSON.parseArray(voteResult.getItemIds(), ActVoteResult.class);
if (actVoteResult.size() == 0) {
log.warn("insertVoteResultInfo with actVoteResult empty. ");
return;
return new ApiResponse(201, "您还没有投票");
}
for(ActVoteResult act : actVoteResult){
for (ActVoteResult act : actVoteResult) {
act.setCreateTime(DateUtil.getCurrentTimeSecond());
}
actVoteResultMapper.insertBatch(actVoteResult);
log.info("insertVoteResultInfo success. voteResult={}",voteResult);
log.info("insertVoteResultInfo success. voteResult={}", voteResult);
return new ApiResponse();
}
}
... ...
... ... @@ -22,6 +22,7 @@
<value>.+/CouponActivityController/.+</value>
<value>.+/staticFileManage/.+</value>
<value>.+/TencentMktController/.+</value>
<value>.+/ActVoteResultController/.+</value>
</list>
</property>
<property name="excludeMethods">
... ...
... ... @@ -83,11 +83,11 @@ img{
<div style="height:646px; background:url(images/bg_06.jpg) no-repeat center center; width:100%; margin:0 auto;">
<div class="wrap">
<div class="left_wrap">
<div id="d1" class="vote"></div>
<div id="1" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
<div class="right_wrap">
<div id="d2" class="vote"></div>
<div id="2" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
</div>
... ... @@ -95,11 +95,11 @@ img{
<div style="height:646px; background:url(images/bg_07.jpg) no-repeat center center; width:100%; margin:0 auto;">
<div class="wrap">
<div id="d3" class="left_wrap">
<div id="3" class="left_wrap">
<div class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
<div id="d4" class="right_wrap">
<div id="4" class="right_wrap">
<div class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
... ... @@ -109,11 +109,11 @@ img{
<div style="height:646px; background:url(images/bg_08.jpg) no-repeat center center; width:100%; margin:0 auto;">
<div class="wrap">
<div class="left_wrap">
<div id="d5" class="vote"></div>
<div id="5" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
<div class="right_wrap">
<div id="d6" class="vote"></div>
<div id="6" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
</div>
... ... @@ -122,11 +122,11 @@ img{
<div style="height:646px; background:url(images/bg_09.jpg) no-repeat center center; width:100%; margin:0 auto;">
<div class="wrap">
<div class="left_wrap">
<div id="d7" class="vote"></div>
<div id="7" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
<div class="right_wrap">
<div id="d8" class="vote"></div>
<div id="8" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
</div>
... ... @@ -135,11 +135,11 @@ img{
<div style="height:646px; background:url(images/bg_10.jpg) no-repeat center center; width:100%; margin:0 auto;">
<div class="wrap">
<div class="left_wrap">
<div id="d9" class="vote"></div>
<div id="9" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
<div class="right_wrap">
<div id="d10" class="vote"></div>
<div id="10" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
</div>
... ... @@ -148,11 +148,11 @@ img{
<div style="height:646px; background:url(images/bg_11.jpg) no-repeat center center; width:100%; margin:0 auto;">
<div class="wrap">
<div class="left_wrap">
<div id="d11" class="vote"></div>
<div id="11" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
<div class="right_wrap">
<div id="d12" class="vote"></div>
<div id="12" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
</div>
... ... @@ -161,11 +161,11 @@ img{
<div style="height:646px; background:url(images/bg_12.jpg) no-repeat center center; width:100%; margin:0 auto;">
<div class="wrap">
<div class="left_wrap">
<div id="d13" class="vote"></div>
<div id="13" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
<div class="right_wrap">
<div id="d14" class="vote"></div>
<div id="14" class="vote"></div>
<img src="images/blank.png" height="646" border="0" usemap="#Map" />
</div>
</div>
... ... @@ -176,116 +176,111 @@ img{
</div>
<script type="text/javascript" src="http://cdn.yoho.cn/huodong/libs/jquery.min.js"></script>
<script>
$(
function () {
$(".vote_button").click(
function () {
}
);
}
);
</script>
<script type="text/javascript">
var voteNum = 0;//已选投票数目
var maxVoteNum = 3;//最大投票数目
var uid;//用户ID
var setOut = "";
//活动细则
$('.detail_click').click(function(){
if($(this).hasClass('isclick')){
$('.detail').slideUp(500);
$(this).css("background-image", "url(images/bg_04.jpg)");
$(this).removeClass('isclick');
}else{
$('.detail').slideDown(500);
$(this).css("background-image","url(images/bg_044.jpg)");
$(this).addClass('isclick');
}
});
//点击投票
$('.vote').click(function(e){
if(e.currentTarget.classList.contains('vote_click')){
e.currentTarget.classList.remove('vote_click');
}else{
e.currentTarget.classList.add('vote_click');
}
voteNum = $(".vote_click").length;
if (voteNum <= maxVoteNum) {
} else {
diaCover("最多只能选3个!!!");
$(this).removeClass("vote_click");
}
});
//判定登录,确认投票
$('.vote_button').click(function(){
var dataRequestUrl="http://m.yohobuy.com/passport/login/user";
$.getJSON(dataRequestUrl+"?callback=?",
function(json) {
if (json.code === 200) {
/* $.getJSON("activity/ActVoteResultController/getActVoteNumByUid?debug=XYZ?callback=?",
function (json){
if (json.code === 200) {
alert("ok");
}
}
); */
var num=$('.vote_click').length;
if(num>maxVoteNum){
diaCover("您最多只能选择三位设计师!");
}else if(num<=0){
diaCover("至少选一位!");
} else{
var arr = new Array(num);
for (var i = 0; i < num; i ++) {
arr[i] = $('.vote_click:eq('+ i +')').attr("id");
}
uid = json.data;
//alert('投票成功!投票账号a为:' + json.data + ',投票数为:' + num + ',所投id是:' + arr);
$.ajax({
type: "POST",
url: '/activity/ActVoteResultController/getActVoteNumByUid?debug=XYZ',
data: {"uid":uid},
dataType: 'json',
success: function(result) {
diaCover("提示信息!!!");
}
});
}
} else {
diaCover("请先登录!!!");
window.location.href="https://www.yohobuy.com/signin.html?refer=" + window.location.href;
}
}
);
});
function diaCover(msg) {
var dataRequestUrl="http://m.yohobuy.com/passport/login/user";
var nums = 0;
var setOut = "";
var votedNum = 0;
function diaCover(msg) {
clearTimeout(setOut);
$(".diaCover-p").remove();
$("body").append("<div class='diaCover-p'>" + msg + "</div>");
setOut = setTimeout("$('.diaCover-p').remove();",3000);
}
//统计点击量
$(function () {
$.getJSON(dataRequestUrl+"?callback=?", function(json) {
if (json.code != 200) {
return;
}
if (!json.data) {
return;
}
$.post("/activity/ActVoteResultController/getActVoteNumByUid", {
uid : json.data
}, function(data) {
if (!data || data.code != 200) {
return;
}
votedNum = data.data ? data.data.length : 0;
$(data.data).each(function(index, item) {
$("div[id='"+ item.voteItemId +"']").removeClass("vote").addClass("vote_click");
});
}, "json");
});
//活动细则
$('.detail_click').click(function(){
if($(this).hasClass('isclick')){
$('.detail').slideUp(500);
$(this).css("background-image", "url(images/bg_04.jpg)");
$(this).removeClass('isclick');
}else{
$('.detail').slideDown(500);
$(this).css("background-image","url(images/bg_044.jpg)");
$(this).addClass('isclick');
}
});
$(".vote").click(function() {
if ($(this).hasClass("vote_click")) {
$(this).removeClass("vote_click");
nums--;
} else {
$(this).addClass("vote_click");
nums++;
}
});
$('.vote_button').click(function(){
if (votedNum > 0) {
diaCover("您已经投过票");
return;
}
$.getJSON(dataRequestUrl+"?callback=?", function(json) {
if (json.code != 200) {
diaCover("请先登录!!!");
window.location.href = "https://www.yohobuy.com/signin.html?refer=" + window.location.href;
return;
}
if (!json.data) {
diaCover("请先登录!!!");
window.location.href = "https://www.yohobuy.com/signin.html?refer=" + window.location.href;
return;
}
var itemIds = [];
var voted = $(".vote_click");
if (!voted || voted.length == 0) {
diaCover("您还没有投票");
return;
}
if (voted.length > 3) {
diaCover("没人最多投三张票");
return;
}
$(voted).each(function(index, item) {
itemIds.push({
uid : json.data,
voteItemId : $(item).attr("id")
});
});
$.post("/activity/ActVoteResultController/addActVoteResult", {
uid : json.data,
itemIds : JSON.stringify(itemIds)
}, function(data) {
if (!data || data.code != 200) {
diaCover(data.message);
return;
} else {
diaCover("投票成功");
}
}, "json");
});
});
});
//统计点击量
(function(w, d, s, j, f) {
var a = d.createElement(s);
var m = d.getElementsByTagName(s)[0];
... ... @@ -300,7 +295,6 @@ img{
a.src = j;
m.parentNode.insertBefore(a,m);
})(window, document, 'script', 'http://cdn.yoho.cn/yas-jssdk/1.0.17/yas.js', '_yas');
</script>
</body>
</html>
... ...