314adfe6f0e495e121b291870ce99c8dab5349a6.svn-base 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package com.chinacreator.videoalliance.query.action;
  2. import java.net.URLEncoder;
  3. import java.util.HashMap;
  4. import java.util.Map;
  5. import javax.servlet.http.HttpServletRequest;
  6. import org.apache.commons.lang.StringUtils;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.web.bind.annotation.RequestMapping;
  10. import org.springframework.web.bind.annotation.ResponseBody;
  11. import com.chinacreator.common.exception.BusinessException;
  12. import com.chinacreator.common.util.DESUtil;
  13. import com.chinacreator.common.util.URLUtil;
  14. import com.chinacreator.videoalliance.order.bean.EmeiBean;
  15. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  16. import com.chinacreator.videoalliance.order.dao.OrderDao;
  17. import com.chinacreator.videoalliance.query.dao.ImeiDao;
  18. import com.google.gson.Gson;
  19. import com.google.gson.GsonBuilder;
  20. import com.google.gson.reflect.TypeToken;
  21. @Controller
  22. public class ImeiQueryAction {
  23. @Autowired
  24. ImeiDao imeiDao;
  25. @Autowired
  26. OrderDao orderDao;
  27. @RequestMapping("/imeiQuery.do")
  28. @ResponseBody
  29. public Object query(HttpServletRequest request) throws Exception {
  30. Map<String,Object> outmap = new HashMap<String, Object>();
  31. String resultcode = "0";
  32. String resultinfo = "";
  33. String orderInfo = "";
  34. String content = null;
  35. Map<String,String> orderInfoMap = new HashMap<String, String>();
  36. Gson gson = new GsonBuilder().disableHtmlEscaping().serializeNulls().create();
  37. try{
  38. content = URLUtil.readInputStream(request.getInputStream());
  39. HashMap<String, String> requestmap = gson.fromJson(content, new TypeToken<HashMap<String, String>>(){}.getType());
  40. String cpid = requestmap.get("cpid");
  41. String spid = requestmap.get("spid");
  42. String imeiNum = requestmap.get("imeiNum");
  43. if(StringUtils.isEmpty(cpid) || !cpid.equals("huasheng")){
  44. throw new BusinessException("8002", "参数[{0}]无效","cpid");
  45. }
  46. if(StringUtils.isEmpty(spid) || !spid.equals("57")){
  47. throw new BusinessException("8002", "参数[{0}]无效","spid");
  48. }
  49. if(StringUtils.isEmpty(imeiNum)){
  50. throw new BusinessException("8002", "参数[{0}]无效","imeiNum");
  51. }
  52. EmeiBean bean = imeiDao.queryListBean(imeiNum);
  53. if(bean == null){
  54. throw new BusinessException("9016", "IMEI号[{0}]无效",imeiNum);
  55. }
  56. if(bean.getStatus().equals("0")){
  57. throw new BusinessException("9017", "IMEI号[{0}]未激活",imeiNum);
  58. }
  59. orderInfoMap.put("userid", bean.getUserid());
  60. OrderInfo orderBean = orderDao.findByUser(bean.getUserid(), cpid, spid);
  61. if(orderBean != null){
  62. orderInfoMap.put("ordertime",orderBean.getOrdertime());
  63. orderInfoMap.put("endtime", orderBean.getEndtime());
  64. }else{
  65. orderInfoMap.put("ordertime","");
  66. orderInfoMap.put("endtime","");
  67. }
  68. }catch(Exception e){
  69. e.printStackTrace();
  70. if(e instanceof BusinessException){
  71. resultcode = ((BusinessException) e).getCode();
  72. resultinfo = e.getMessage();
  73. if(((BusinessException) e).getParams().length != 0){
  74. resultinfo = resultinfo.replace("[{0}]",((BusinessException) e).getParams()[0]);
  75. }
  76. }else{
  77. resultcode = "8000";
  78. resultinfo = "系统忙,请稍后再试!";
  79. }
  80. }
  81. if(!orderInfoMap.isEmpty()){
  82. orderInfo = URLEncoder.encode(DESUtil.encode(gson.toJson(orderInfoMap), "7dda13d5"),"utf-8");
  83. }
  84. outmap.put("resultcode", resultcode);
  85. outmap.put("resultinfo", resultinfo);
  86. outmap.put("orderInfo", orderInfo);
  87. return outmap;
  88. }
  89. public static void main(String[] args) {
  90. String cpid ="";
  91. if(StringUtils.isEmpty(cpid)){
  92. try {
  93. throw new BusinessException("8002", "参数[{0}]无效","cpid");
  94. } catch (BusinessException e) {
  95. if(e instanceof BusinessException){
  96. System.out.println(e.getParams()[0]);
  97. System.out.println(e.getMessage());
  98. String resultcode = ((BusinessException) e).getMessage().replace("[{0}]",((BusinessException) e).getParams()[0]);
  99. System.out.println(resultcode);
  100. }
  101. }
  102. }
  103. }
  104. }