3be9a94d379440b383b443ef73f30442cf3d1967.svn-base 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. package com.chinacreator.videoalliance.order.action;
  2. import com.chinacreator.cache.util.AESUtil;
  3. import com.chinacreator.common.exception.BusinessException;
  4. import com.chinacreator.common.util.URLUtil;
  5. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  6. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  7. import com.chinacreator.videoalliance.order.bean.QueryOrder;
  8. import com.chinacreator.videoalliance.order.bean.SPInfo;
  9. import com.chinacreator.videoalliance.order.dao.OrderDao;
  10. import com.chinacreator.videoalliance.order.dao.SPDao;
  11. import com.chinacreator.videoalliance.order.service.OrderService;
  12. import com.chinacreator.videoalliance.order.util.ExternalUtil;
  13. import com.chinacreator.videoalliance.order.util.JsonUtil;
  14. import net.sf.json.JSONObject;
  15. import net.sf.json.JSONSerializer;
  16. import org.apache.commons.lang.StringUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Controller;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import javax.servlet.http.HttpServletRequest;
  21. import javax.servlet.http.HttpServletResponse;
  22. import java.io.IOException;
  23. import java.io.PrintWriter;
  24. import java.sql.SQLException;
  25. import java.util.ArrayList;
  26. import java.util.HashMap;
  27. import java.util.List;
  28. import java.util.Map;
  29. @Controller
  30. public class ExternalOrderAction
  31. {
  32. @Autowired
  33. private OrderService orderService;
  34. @Autowired
  35. private SPDao spDao;
  36. @Autowired
  37. private OrderDao orderDao;
  38. @Autowired
  39. private DictionaryDao dictionaryDao;
  40. @RequestMapping({"/orderex.do"})
  41. public void Order(HttpServletRequest request, HttpServletResponse response)
  42. {
  43. String resultcode = "0";
  44. String resultinfo = "操作成功";
  45. String channelcode = null;
  46. String params = null;
  47. Map<String,String> map = new HashMap<String,String>();
  48. try
  49. {
  50. params = URLUtil.readInputStream(request.getInputStream());
  51. JSONObject jsonobj = JSONObject.fromObject(params);
  52. if (!jsonobj.containsKey("channelcode")) {
  53. throw new BusinessException("5101", "渠道编码无效", new String[0]);
  54. }
  55. channelcode = jsonobj.getString("channelcode");
  56. String password = getValue(channelcode);
  57. if (password == null) {
  58. throw new BusinessException("5101", "渠道编码无效", new String[0]);
  59. }
  60. params = jsonobj.getString("order");
  61. if (StringUtils.isEmpty(params)) {
  62. throw new BusinessException("8002", "参数无效", new String[0]);
  63. }
  64. params = AESUtil.decrypt(params, password);
  65. jsonobj = JSONObject.fromObject(params);
  66. String productid = ExternalUtil.getValue(jsonobj, "productid", "产品编码");
  67. OrderInfo orderinfo = toBean(jsonobj, channelcode);
  68. SPInfo info = this.spDao.findByVacId(productid);
  69. orderinfo.setSpid(info.getSpid());
  70. orderinfo.setCpid(info.getCpid());
  71. this.orderService.checkOrder(orderinfo);
  72. this.orderService.order(orderinfo);
  73. try{
  74. Map<String,String> mqmap = new HashMap<String, String>();
  75. mqmap.put("userid", orderinfo.getUserid());
  76. mqmap.put("cpid",orderinfo.getCpid());
  77. mqmap.put("spid", orderinfo.getSpid());
  78. mqmap.put("province", orderinfo.getProvince());
  79. mqmap.put("area", orderinfo.getArea());
  80. mqmap.put("ordertime", orderinfo.getOrdertime());
  81. mqmap.put("canceltime", "");
  82. mqmap.put("status", "0");
  83. mqmap.put("orderchannel", "spfbtx8");
  84. mqmap.put("cancelchannel", "");
  85. mqmap.put("videoid", orderinfo.getVideoid());
  86. mqmap.put("type","order");
  87. //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
  88. URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map));
  89. }catch(Exception e){
  90. e.printStackTrace();
  91. }
  92. } catch (Exception e) {
  93. if ((e instanceof BusinessException)) {
  94. BusinessException be = (BusinessException)e;
  95. resultcode = be.getCode();
  96. resultinfo = be.getMessage();
  97. } else {
  98. resultcode = "8000";
  99. resultinfo = "系统忙,请稍候再试";
  100. }
  101. }
  102. map.put("resultcode", resultcode);
  103. map.put("resultinfo", resultinfo);
  104. println(response, JSONSerializer.toJSON(map).toString());
  105. }
  106. @RequestMapping({"/queryorderex.do"})
  107. public void QueryOrder(HttpServletRequest request, HttpServletResponse response)
  108. {
  109. String resultcode = "0";
  110. String resultinfo = "操作成功";
  111. String channelcode = null;
  112. String params = null;
  113. String userid = "";
  114. Map<String,Object> map = new HashMap<String,Object>();
  115. List<QueryOrder> lists = new ArrayList<QueryOrder>();
  116. try {
  117. params = URLUtil.readInputStream(request.getInputStream());
  118. JSONObject jsonobj = JSONObject.fromObject(params);
  119. if (!jsonobj.containsKey("channelcode")) {
  120. throw new BusinessException("5101", "渠道编码无效", new String[0]);
  121. }
  122. channelcode = jsonobj.getString("channelcode");
  123. String password = getValue(channelcode);
  124. if (password == null) {
  125. throw new BusinessException("5101", "渠道编码无效", new String[0]);
  126. }
  127. userid = jsonobj.getString("userid");
  128. userid = AESUtil.decrypt(userid, password);
  129. List<OrderInfo> list = queryOrder(userid);
  130. for (OrderInfo bean : list) {
  131. QueryOrder order = new QueryOrder();
  132. order.setProductid(bean.getProductid());
  133. order.setExpiredate(bean.getOrdertime());
  134. order.setEffectivedate(bean.getEndtime());
  135. lists.add(order);
  136. }
  137. } catch (Exception e) {
  138. if ((e instanceof BusinessException)) {
  139. BusinessException be = (BusinessException)e;
  140. resultcode = be.getCode();
  141. resultinfo = be.getMessage();
  142. } else {
  143. resultcode = "8000";
  144. resultinfo = "系统忙,请稍候再试";
  145. }
  146. }
  147. map.put("resultcode", resultcode);
  148. map.put("resultinfo", resultinfo);
  149. map.put("userinfo", lists);
  150. println(response, JSONSerializer.toJSON(map).toString());
  151. }
  152. private OrderInfo toBean(JSONObject json, String channelcode)
  153. throws Exception
  154. {
  155. String userid = ExternalUtil.getValue(json, "userid", "手机号码");
  156. OrderInfo orderBean = new OrderInfo();
  157. if (ExternalUtil.isValid(userid))
  158. userid = ExternalUtil.format(userid);
  159. else {
  160. throw new BusinessException("7002", "手机号码无效", new String[0]);
  161. }
  162. orderBean.setUserid(userid);
  163. orderBean.setApptype("");
  164. orderBean.setStatus(0);
  165. orderBean.setOrderchannel(channelcode);
  166. orderBean.setOrderstatus(2);
  167. orderBean.setOrdertype(0);
  168. return orderBean;
  169. }
  170. public String getValue(String key)
  171. throws BusinessException
  172. {
  173. try
  174. {
  175. return this.orderDao.getValue(key); } catch (SQLException e) {
  176. }
  177. throw new BusinessException("5101", "渠道编码无效", new String[0]);
  178. }
  179. public List<OrderInfo> queryOrder(String userid)
  180. throws SQLException
  181. {
  182. return this.orderDao.findByUser(userid);
  183. }
  184. public void println(HttpServletResponse res, String message)
  185. {
  186. PrintWriter out = null;
  187. try {
  188. res.setCharacterEncoding("UTF-8");
  189. out = res.getWriter();
  190. out.print(message);
  191. } catch (IOException e) {
  192. e.printStackTrace();
  193. } finally {
  194. if (out != null) {
  195. out.flush();
  196. out.close();
  197. }
  198. }
  199. }
  200. }