133 lines
4.7 KiB
Plaintext
133 lines
4.7 KiB
Plaintext
package com.nationalelectric.greenH5;
|
|
|
|
import java.sql.Timestamp;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import org.codehaus.jackson.map.ObjectMapper;
|
|
import org.codehaus.jackson.type.TypeReference;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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.RequestMethod;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
import com.nationalelectirc.Constant.Constant;
|
|
import com.nationalelectirc.utils.RestResult;
|
|
import com.nationalelectric.greenH5.bizc.BaseServiceImpl;
|
|
import com.nationalelectric.greenH5.bizc.IGreenFoodLotteryBizc;
|
|
import com.nationalelectric.greenH5.po.GreenFoodLottery;
|
|
import com.nationalelectric.greenH5.po.GreenUserInfo;
|
|
import com.nationalelectric.greenH5.po.TorderEvaluate;
|
|
import com.sgcc.uap.persistence.IHibernateDao;
|
|
|
|
@Controller
|
|
@RequestMapping("/lottery")
|
|
public class GreenFoodLotterController extends GreenBaseController {
|
|
@Resource
|
|
private IHibernateDao hibernateDao;
|
|
@Resource
|
|
private IGreenFoodLotteryBizc greenFoodLotteryBizc;
|
|
@Autowired
|
|
private BaseServiceImpl baseService;
|
|
/**
|
|
* 添加抽奖
|
|
* @param requestBody
|
|
* @return
|
|
*/
|
|
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public RestResult add(@RequestBody Object requestBody) {
|
|
|
|
try {
|
|
GreenFoodLottery lottery= new ObjectMapper().convertValue(requestBody, new TypeReference<GreenFoodLottery>(){});
|
|
String userId = lottery.getUserId();
|
|
//主键
|
|
String uuid = UUID.randomUUID().toString().replaceAll("-","");
|
|
lottery.setId(uuid);
|
|
//时间
|
|
Timestamp t = new Timestamp(new Date().getTime());
|
|
lottery.setGmtCreated(t);
|
|
lottery.setGmtModified(t);
|
|
//查询活动次数
|
|
String sql = " select max(activity_no) from t_activity where activity_code = 'dining_new_products' and is_deleted = 'N' ";
|
|
List<Object> list = hibernateDao.executeSqlQuery(sql);
|
|
|
|
int activityNo = list == null ? 1 : Integer.parseInt(list.get(0).toString());
|
|
lottery.setActivityNo(activityNo);
|
|
|
|
hibernateDao.saveObject(lottery);
|
|
} catch (Exception e) {
|
|
System.out.print(e.getMessage());
|
|
return new RestResult(Constant.FAILED, "添加失败");
|
|
}
|
|
|
|
return new RestResult(Constant.SUCCESS, "添加成功");
|
|
}
|
|
/**
|
|
* 查询抽奖食品
|
|
* @param requestBody
|
|
* @return
|
|
*/
|
|
@RequestMapping(value = "/query", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
public RestResult query(@RequestBody Object requestBody) {
|
|
|
|
try {
|
|
Map<String, Object> map = new ObjectMapper().convertValue(requestBody, new TypeReference<Map<String, Object>>(){});
|
|
String userId = map.get("userId") == null || "".equals(map.get("userId")) ? null : map.get("userId").toString();
|
|
GreenUserInfo info = getUserInfo(userId);
|
|
if (info == null) {
|
|
return new RestResult(Constant.FAILED, "非法用户");
|
|
}
|
|
|
|
List<Object> params = new ArrayList<Object>();
|
|
StringBuffer sql = new StringBuffer();
|
|
sql.append(" select id,food_name name from green_food_feature where activity_no = ")
|
|
.append(" (select max(activity_no) from t_activity where activity_code = 'dining_new_products' and is_deleted = 'N') ")
|
|
.append(" and vote_no is not null ")
|
|
.append(" and is_deleted = 'N' order by vote_no desc ");
|
|
sql.append( "limit ?,? ");
|
|
|
|
params.add(0);
|
|
params.add(9);
|
|
// hibernateDao.executeSqlQuery(arg0)
|
|
List<Map<String,Object>> list = hibernateDao.queryForListWithSql(sql.toString(),params.toArray());
|
|
|
|
Map<String, Object> result = new HashMap<String, Object>();
|
|
result.put("isPrizeTime", list == null || list.size() == 0 ? 0 : 1);
|
|
|
|
if(list.size()<10){
|
|
int k= 10-list.size();
|
|
for(int i=0;i<k;i++){
|
|
Map<String,Object> m = new HashMap<String,Object>();
|
|
m.put("id", "");
|
|
m.put("name", "谢谢参与");
|
|
list.add(m);
|
|
}
|
|
}
|
|
result.put("list", list);
|
|
|
|
StringBuffer isPrize = new StringBuffer();
|
|
isPrize.append(" select id from green_food_lottery gl where ")
|
|
.append(" gl.activity_no = (select max(activity_no) from t_activity where activity_code = 'dining_new_products' and is_deleted = 'N') ")
|
|
.append(" and gl.user_id = ? ");
|
|
|
|
List<Map<String,Object>> prize = hibernateDao.queryForListWithSql(isPrize.toString(), new String[]{userId});
|
|
|
|
result.put("isPrize", prize == null || prize.size() == 0 ? 0 : 1);
|
|
return new RestResult(Constant.SUCCESS,"成功",result);
|
|
} catch (Exception e) {
|
|
return new RestResult(Constant.FAILED, "查询失败");
|
|
}
|
|
|
|
}
|
|
}
|