PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/cn/springboot/controller/OddsController.java

https://bitbucket.org/guoj5477/lotter_customers
Java | 207 lines | 190 code | 7 blank | 10 comment | 1 complexity | dbd2c2ec6aade247d156522847c241ff MD5 | raw file
Possible License(s): JSON
  1. package cn.springboot.controller;
  2. import cn.springboot.config.shiro.TokenManager;
  3. import cn.springboot.config.shiro.vo.Principal;
  4. import cn.springboot.model.OddsModel;
  5. import cn.springboot.model.auth.User;
  6. import cn.springboot.service.odds.OddsService;
  7. import com.alibaba.fastjson.JSONObject;
  8. import org.apache.log4j.Logger;
  9. import org.apache.shiro.SecurityUtils;
  10. import org.apache.shiro.subject.Subject;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Controller;
  13. import org.springframework.ui.ModelMap;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.ResponseBody;
  17. import org.springframework.web.servlet.ModelAndView;
  18. import javax.servlet.http.HttpServletRequest;
  19. import javax.servlet.http.HttpSession;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * @author eric
  25. * @date 2017/9/11/011 14:05
  26. * @todo 赔率设置
  27. */
  28. @Controller
  29. @RequestMapping(value = "odds")
  30. public class OddsController extends BaseController{
  31. @Autowired
  32. private OddsService oddsService;
  33. private Logger logger= Logger.getLogger(OddsController.class);
  34. /**
  35. * 赔率设置
  36. * @return
  37. */
  38. @RequestMapping(value = "/Canada28oddsSet",method = RequestMethod.GET)
  39. public String Canada28oddsSet(HttpServletRequest request, ModelMap modelMap){
  40. logger.info("【##】 Start Query CQSSCOddsSet / 查询加拿大28赔率");
  41. String json = null;
  42. try {
  43. int lotteryId=10;
  44. List<OddsModel> list= oddsService.queryOdds(new OddsModel(lotteryId,null,null,0));
  45. json = JSONObject.toJSONString(list);
  46. logger.info("【##】 Result / 返回结果:"+json);
  47. logger.info("【##】End Query 加拿大28 / 结束查询");
  48. modelMap.addAttribute("list",list);
  49. } catch (NumberFormatException e) {
  50. logger.error(e.getMessage());
  51. e.printStackTrace();
  52. }
  53. return "view/odds/canada28Odds";
  54. }
  55. @RequestMapping(value = "/bj28OddsSet",method = RequestMethod.GET)
  56. public String bj28OddsSet(HttpServletRequest request, ModelMap modelMap){
  57. //获取彩票ID
  58. logger.info("【##】 Start Query XYNCOddsSet / 查询北京28赔率");
  59. String json = null;
  60. try {
  61. int lotteryId = 11;
  62. List<OddsModel> list= oddsService.queryOdds(new OddsModel(lotteryId,null,null,0));
  63. json = JSONObject.toJSONString(list);
  64. logger.info("【##】 Result / 返回结果:"+json);
  65. logger.info("【##】End Query 北京28 / 结束查询");
  66. modelMap.addAttribute("list",list);
  67. } catch (NumberFormatException e) {
  68. logger.error(e.getMessage());
  69. e.printStackTrace();
  70. }
  71. return "view/odds/bj28Odds";
  72. }
  73. @RequestMapping(value = "/updateOdds",method = RequestMethod.POST)
  74. @ResponseBody
  75. public Map<String,Object> updateOdds(String jsonStr,HttpServletRequest request){
  76. HttpSession session=request.getSession();
  77. Principal principal = (Principal)SecurityUtils.getSubject().getPrincipal();
  78. User user = principal.getUser();
  79. if(user==null){
  80. logger.info("## operator is null !");
  81. resultMap.put("success",false);
  82. resultMap.put("message","你已退出,请重新登录!");
  83. return resultMap;
  84. }
  85. logger.info("【##】 /"+ user.getUsername()+"/Start Update Odds /修改赔率");
  86. String js=jsonStr.replaceAll("\\\\","");
  87. String str=js.substring(1,js.length()-1);
  88. logger.info(js);
  89. com.alibaba.fastjson.JSONObject obj = com.alibaba.fastjson.JSONObject.parseObject(js);
  90. List<Map<String,Object>> jsonArray = (List<Map<String,Object>>) obj.get("jsonList");
  91. String lid = obj.getString("lid");
  92. logger.info(jsonArray);
  93. List <OddsModel> list=new ArrayList<>();
  94. int lotteryId=Integer.parseInt(lid);
  95. try {
  96. for(int i=0;i<jsonArray.size();i++){
  97. JSONObject jsonObject2=(JSONObject)jsonArray.get(i);
  98. if(jsonObject2.getString("lid")!=""&&jsonObject2.getString("odds")!=""){
  99. OddsModel mod = new OddsModel();
  100. mod.setLid(lotteryId);
  101. mod.setOdds(Double.parseDouble(jsonObject2.getString("oddVal")));
  102. String name = jsonObject2.getString("name");
  103. String ruleName = "";
  104. if(lotteryId == 10){
  105. //特码
  106. if(name.indexOf("HZ_") != -1){
  107. ruleName = name.substring("HZ_".length());
  108. }else if(name.equals("DX_D")){
  109. ruleName = "大";
  110. }else if(name.equals("DS_D")){
  111. ruleName = "单";
  112. }else if(name.equals("JZDX_D")){
  113. ruleName = "极大";
  114. }else if(name.equals("DXDS_DD")){
  115. ruleName = "大单";
  116. }else if(name.equals("DXDS_DS")){
  117. ruleName = "大双";
  118. }else if(name.equals("DX_X")){
  119. ruleName = "小";
  120. }else if(name.equals("DS_S")){
  121. ruleName = "双";
  122. }else if(name.equals("JZDX_X")){
  123. ruleName = "极小";
  124. }else if(name.equals("DXDS_XD")){
  125. ruleName = "小单";
  126. }else if(name.equals("DXDS_XS")){
  127. ruleName = "小双";
  128. }else if(name.equals("SB_R")){
  129. ruleName = "红波";
  130. }else if(name.equals("SB_G")){
  131. ruleName = "绿波";
  132. }else if(name.equals("SB_B")){
  133. ruleName = "蓝波";
  134. }else if(name.equals("BZ_0")){
  135. ruleName = "豹子";
  136. }
  137. }else if(lotteryId == 11){
  138. //特码
  139. if(name.indexOf("HZ_") != -1){
  140. ruleName = name.substring("HZ_".length());
  141. }else if(name.equals("DX_D")){
  142. ruleName = "大";
  143. }else if(name.equals("DS_D")){
  144. ruleName = "单";
  145. }else if(name.equals("JZDX_D")){
  146. ruleName = "极大";
  147. }else if(name.equals("DXDS_DD")){
  148. ruleName = "大单";
  149. }else if(name.equals("DXDS_DS")){
  150. ruleName = "大双";
  151. }else if(name.equals("DX_X")){
  152. ruleName = "小";
  153. }else if(name.equals("DS_S")){
  154. ruleName = "双";
  155. }else if(name.equals("JZDX_X")){
  156. ruleName = "极小";
  157. }else if(name.equals("DXDS_XD")){
  158. ruleName = "小单";
  159. }else if(name.equals("DXDS_XS")){
  160. ruleName = "小双";
  161. }else if(name.equals("SB_R")){
  162. ruleName = "红波";
  163. }else if(name.equals("SB_G")){
  164. ruleName = "绿波";
  165. }else if(name.equals("SB_B")){
  166. ruleName = "蓝波";
  167. }else if(name.equals("BZ_0")){
  168. ruleName = "豹子";
  169. }else if(name.equals("TMBS_0")){
  170. ruleName = "包三";
  171. }
  172. }
  173. mod.setRule(ruleName);
  174. list.add(mod);
  175. }
  176. }
  177. String event="";
  178. if(!list.isEmpty()){
  179. switch (lotteryId){
  180. case 10:
  181. event="加拿大28-修改赔率";
  182. break;
  183. case 11:
  184. event="北京28-修改赔率";
  185. break;
  186. }
  187. }
  188. oddsService.updateLotteryOddsbyList(list,user.getUsername(),request,event,null);
  189. resultMap.put("status",200);
  190. resultMap.put("message","修改成功");
  191. logger.info("【##】 End Update Odds / 修改结束");
  192. } catch (Exception e) {
  193. logger.error(e.getMessage());
  194. e.printStackTrace();
  195. resultMap.put("status",300);
  196. resultMap.put("message","服务异常");
  197. }
  198. return resultMap;
  199. }
  200. }