PrizeController.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. package com.hssx.controller;
  2. import java.io.IOException;
  3. import java.security.KeyManagementException;
  4. import java.security.NoSuchAlgorithmException;
  5. import java.security.NoSuchProviderException;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Random;
  10. import javax.servlet.http.HttpServletResponse;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import com.hssx.entity.Prize;
  16. import com.hssx.entity.PrizeExample;
  17. import com.hssx.entity.PrizeRecord;
  18. import com.hssx.entity.PrizeRecordExample;
  19. import com.hssx.entity.User;
  20. import com.hssx.entity.UserPrizeCountExample;
  21. import com.hssx.mapper.PrizeMapper;
  22. import com.hssx.mapper.PrizeRecordMapper;
  23. import com.hssx.mapper.UserMapper;
  24. import com.hssx.mapper.UserPrizeCountMapper;
  25. import com.hssx.utils.HttpRespMsg;
  26. import com.sun.javafx.collections.MappingChange.Map;
  27. @Controller
  28. @RequestMapping("/prize")
  29. public class PrizeController {
  30. @Autowired
  31. UserMapper usermapper;
  32. @Autowired
  33. PrizeMapper prizeMapper;
  34. @Autowired
  35. PrizeRecordMapper prizeRecordMapper;
  36. @Autowired
  37. UserPrizeCountMapper UserPrizeCountMapper;
  38. /**
  39. * 小游戏抽奖 参数: userId:当前抽奖人id
  40. *
  41. * @return
  42. */
  43. @RequestMapping(value = "/luckDraw")
  44. public void luckDraw(Integer userId, HttpServletResponse response)
  45. throws Exception, KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
  46. HttpRespMsg msg = new HttpRespMsg();
  47. Integer count = -1;
  48. PrizeRecord prizeRecord = new PrizeRecord();
  49. User user = usermapper.selectByPrimaryKey(userId);
  50. prizeRecord.setUid(user.getId());
  51. prizeRecord.setType(user.getType());
  52. prizeRecord.setVoucherId(user.getVoucherId());
  53. prizeRecord.setNickName(user.getNickName());
  54. UserPrizeCountExample uExp = new UserPrizeCountExample();
  55. Integer luckDrawCount = UserPrizeCountMapper.selectCountByToday();
  56. if (luckDrawCount < 2) {
  57. synchronized (this) {
  58. Random ran = new Random();
  59. int num = ran.nextInt(9999);
  60. Prize prize = prizeMapper.selectByPrimaryKey(num);
  61. if (prize == null) {
  62. count = -1;
  63. } else {
  64. if (prize.getPrizeLevel() == 0 && prize.getIsSelected() == 0) {
  65. count = 0;
  66. // prize.setIsSelected(1);
  67. // prizeMapper.updateByPrimaryKeySelective(prize);
  68. prizeRecord.setPrizeId(prize.getPrizeLevel());
  69. prizeRecord.setPrize(prize.getName());
  70. prizeRecordMapper.insert(prizeRecord);
  71. } else if (prize.getPrizeLevel() == 1 && prize.getIsSelected() == 0) {
  72. count = 1;
  73. // prize.setIsSelected(1);
  74. // prizeMapper.updateByPrimaryKeySelective(prize);
  75. prizeRecord.setPrizeId(prize.getPrizeLevel());
  76. prizeRecord.setPrize(prize.getName());
  77. prizeRecordMapper.insert(prizeRecord);
  78. } else if (prize.getPrizeLevel() == 2 && prize.getIsSelected() == 0) {
  79. count = 2;
  80. // prize.setIsSelected(1);
  81. // prizeMapper.updateByPrimaryKeySelective(prize);
  82. prizeRecord.setPrizeId(prize.getPrizeLevel());
  83. prizeRecord.setPrize(prize.getName());
  84. prizeRecordMapper.insert(prizeRecord);
  85. } else if (prize.getPrizeLevel() == 3 && prize.getIsSelected() == 0) {
  86. count = 3;
  87. // prize.setIsSelected(1);
  88. // prizeMapper.updateByPrimaryKeySelective(prize);
  89. prizeRecord.setPrizeId(prize.getPrizeLevel());
  90. prizeRecord.setPrize(prize.getName());
  91. prizeRecordMapper.insert(prizeRecord);
  92. } else if (prize.getPrizeLevel() == 4 && prize.getIsSelected() == 0) {
  93. count = 4;
  94. // prize.setIsSelected(1);
  95. // prizeMapper.updateByPrimaryKeySelective(prize);
  96. prizeRecord.setPrizeId(prize.getPrizeLevel());
  97. prizeRecord.setPrize(prize.getName());
  98. prizeRecordMapper.insert(prizeRecord);
  99. } else {
  100. count = -1;
  101. }
  102. }
  103. }
  104. HashMap<String, Object> map = new HashMap<String, Object>();
  105. map.put("prizeLevel", count);
  106. map.put("prizeRecord", prizeRecord);
  107. msg.data = map;
  108. }else{
  109. }
  110. response.setContentType("application/json");
  111. response.setCharacterEncoding("UTF-8");
  112. response.getWriter().println(msg.toJSONStr());
  113. }
  114. /**
  115. * 小游戏抽奖列表
  116. *
  117. * @return
  118. */
  119. @RequestMapping(value = "/luckDrawList")
  120. public void luckDrawList(HttpServletResponse response)
  121. throws Exception, KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
  122. HttpRespMsg msg = new HttpRespMsg();
  123. List<PrizeRecord> list = prizeRecordMapper.selectByExample(new PrizeRecordExample());
  124. msg.data = list;
  125. response.setContentType("application/json");
  126. response.setCharacterEncoding("UTF-8");
  127. response.getWriter().println(msg.toJSONStr());
  128. }
  129. /**
  130. * 小游戏抽奖填写用户信息 参数:phone:电话 username:姓名 id:中奖纪录id
  131. *
  132. * @return
  133. */
  134. @RequestMapping(value = "/luckDrawAddInfo")
  135. public void luckDrawAddInfo(PrizeRecord prizeRecord, HttpServletResponse response)
  136. throws Exception, KeyManagementException, NoSuchAlgorithmException, NoSuchProviderException, IOException {
  137. HttpRespMsg msg = new HttpRespMsg();
  138. prizeRecordMapper.updateByPrimaryKeySelective(prizeRecord);
  139. msg.data = prizeRecord;
  140. response.setContentType("application/json");
  141. response.setCharacterEncoding("UTF-8");
  142. response.getWriter().println(msg.toJSONStr());
  143. }
  144. }