提交 59b165e8 authored 作者: Mangostiffy's avatar Mangostiffy

新增抽奖接口

上级 16094efc
package com.mall.controller.api;
import com.jfinal.i18n.Res;
import com.mall.controller.base.BaseController;
import com.mall.service.mengbeng.lottery.LotteryManager;
import com.mall.util.PageData;
import com.mall.util.ResultOutDto;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@RequestMapping(value="/api/lottery",produces="application/json;charset=UTF-8")
public class LotteryApi extends BaseController {
@Resource(name="lotteryService")
private LotteryManager lotteryService;
/**
* 抽奖
* @return
*/
@RequestMapping("/lottery")
@ResponseBody
public ResultOutDto lottery(String store_id){
try {
if(null==store_id){
return ResultOutDto.err(null,"店铺id为空");
}
PageData pd=new PageData();
List<PageData> list=lotteryService.listAll(pd);
List resultnumberlist=new ArrayList();
for(int i=0;i<3;i++){
//T抽奖算法
int resultnumber= (int) (Math.random()*list.size());
PageData result=list.get(resultnumber);//单次结果
resultnumberlist.add((int) result.get("c_lottery_number"));
}
if(resultnumberlist.get(0)==resultnumberlist.get(1)&&resultnumberlist.get(1)==resultnumberlist.get(2)){
pd.put("c_lottery_number",resultnumberlist.get(0));
pd=lotteryService.findByLotterynumber(pd);
if(null!=pd){
//TODO:根据数字处理奖品
System.out.println("中奖");
Map resultmap=new HashMap();
resultmap.put("result",1);
resultmap.put("resultnumber",resultnumberlist);
resultmap.put("reward",pd);
return ResultOutDto.ok(resultmap);
}else{
return ResultOutDto.err(null,"奖品不存在");
}
}else{
Map resultmap=new HashMap();
resultmap.put("result",0);
resultmap.put("resultnumber",resultnumberlist);
resultmap.put("reward",null);
System.out.println("未中奖");
return ResultOutDto.ok(resultmap);
}
}catch (Exception e){
return ResultOutDto.err(null,"错误");
}
}
}
......@@ -52,6 +52,14 @@ public interface LotteryManager{
* @throws Exception
*/
public void deleteAll(String[] ArrayDATA_IDS)throws Exception;
/**
* 根据中奖数字查找
* @param pd
* @return
* @throws Exception
*/
public PageData findByLotterynumber(PageData pd) throws Exception;
}
......@@ -77,6 +77,11 @@ public class LotteryService implements LotteryManager {
public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
dao.delete("LotteryMapper.deleteAll", ArrayDATA_IDS);
}
@Override
public PageData findByLotterynumber(PageData pd) throws Exception {
return (PageData) dao.findForObject("LotteryMapper.findByLotterynumber",pd);
}
}
......@@ -102,5 +102,14 @@
#{item}
</foreach>
</delete>
<!--根中奖数字查找-->
<select id="findByLotterynumber" parameterType="pd" resultType="pd">
select
<include refid="Field"></include>
from
<include refid="tableName"></include>
where c_lottery_number = #{c_lottery_number}
</select>
</mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论