f073a948fd49ba89f5be77821f9989b1cb0554bd.svn-base 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. package com.chinacreator.videoalliance.order.action;
  2. import com.chinacreator.common.exception.BusinessException;
  3. import com.chinacreator.common.pipe.DataOutPipe;
  4. import com.chinacreator.common.util.DESUtil;
  5. import com.chinacreator.common.util.RequestUtil;
  6. import com.chinacreator.common.util.URLUtil;
  7. import com.chinacreator.videoalliance.common.annotation.DataOut;
  8. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  9. import com.chinacreator.videoalliance.common.util.ConfigUtil;
  10. import com.chinacreator.videoalliance.order.bean.EcbProductInfo;
  11. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  12. import com.chinacreator.videoalliance.order.dao.CsOrderControlDao;
  13. import com.chinacreator.videoalliance.order.service.OrderService;
  14. import com.chinacreator.videoalliance.order.util.JsonUtil;
  15. import com.chinacreator.videoalliance.query.dao.ChangshiDebugDao;
  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 java.io.UnsupportedEncodingException;
  22. import java.util.HashMap;
  23. import java.util.Map;
  24. @Controller
  25. public class CSChannleOrderAction {
  26. @Autowired
  27. private OrderService orderService;
  28. @Autowired
  29. private CsOrderControlDao csOrderControlDao;
  30. @Autowired
  31. private ChangshiDebugDao changshiDebugDao;
  32. @Autowired
  33. private DictionaryDao dictionaryDao;
  34. @RequestMapping({ "/cschannelorder.do" })
  35. @DataOut(callback = "cschannelorder")
  36. public DataOutPipe doOrder(HttpServletRequest request, OrderInfo orderInfo, String orderType, String channel,
  37. String productinfos,String sign) throws Exception {
  38. long begintime = System.currentTimeMillis();
  39. orderInfo.setTimes(begintime+"");
  40. String result = "0";
  41. DataOutPipe pipe = new DataOutPipe();
  42. try {
  43. if(StringUtils.isEmpty(productinfos)){
  44. throw new BusinessException("7002", "参数无效");
  45. }
  46. EcbProductInfo ecbProductInfo = (EcbProductInfo) JsonUtil.jsonToBean(productinfos, EcbProductInfo.class);
  47. String userid = orderInfo.getUserid();
  48. if (StringUtils.isEmpty(userid)) {
  49. throw new BusinessException("7002", "手机号码无效");
  50. }
  51. if (StringUtils.isEmpty(orderType) || (!orderType.equals("1") && !orderType.equals("0"))) {
  52. throw new BusinessException("7002", "操作类型无效无效");
  53. }
  54. try {
  55. orderInfo.setUserid(ConfigUtil.decrypt(userid, orderInfo.getCpid()));
  56. if ((orderInfo.getUserid() != null) && (orderInfo.getUserid().length() > 11)) {
  57. orderInfo.setUserid(ConfigUtil.getUserid(orderInfo.getUserid(), orderInfo.getCpid()));
  58. }
  59. } catch (Exception e) {
  60. throw new BusinessException("7002", "手机号码无效");
  61. }
  62. if(!changshiDebugDao.query(orderInfo.getUserid())){
  63. if(StringUtils.isEmpty(sign)){
  64. throw new BusinessException("7002", "参数无效");
  65. }
  66. if(!sign.equals(DESUtil.encode(orderInfo.getUserid()+ecbProductInfo.getProductId()+ecbProductInfo.getPackageCode()+ecbProductInfo.getDiscntCode()+ecbProductInfo.getDiscntValue(), "chsh5a1d"))){
  67. throw new BusinessException("9999", "订购失败");
  68. }
  69. }
  70. //System.out.println("+++++++orderType:"+orderType+"+++++++cpid:"+orderInfo.getCpid()+">>>>spid:"+orderInfo.getSpid()+">>>>>DiscntFee:"+ecbProductInfo.getDiscntFee()+">>>>DiscntValue:"+ecbProductInfo.getDiscntValue());
  71. orderInfo.setApptype(RequestUtil.getMobType(request));
  72. if (orderType.equals("0")) {//订购
  73. if("1150".equals(orderInfo.getSpid())){
  74. //20190628,xu.zhou 下线订购无限畅视产品
  75. throw new BusinessException("7020", "该产品已下线。");
  76. }
  77. //20190301,只允许畅视20元高清产品订购
  78. if("changshi".equals(orderInfo.getCpid()) && "1150".equals(orderInfo.getSpid())
  79. && "2000".equals(ecbProductInfo.getDiscntFee()) && "1".equals(ecbProductInfo.getDiscntValue())){
  80. //畅视20元高清产品,允许订购
  81. }else{
  82. throw new BusinessException("9923", "非畅视产品20元资费,不能订购");
  83. }
  84. if(!changshiDebugDao.query(orderInfo.getUserid())){
  85. if(ecbProductInfo.getDiscntCode().equals("8217798") || ecbProductInfo.getDiscntFee().equals("0")){
  86. throw new BusinessException("8006", "订购失败");
  87. }
  88. }
  89. orderInfo.setStatus(0);
  90. orderInfo.setOrderchannel(channel);
  91. orderInfo.setOrderstatus(2);
  92. orderInfo.setEndtime(ecbProductInfo.getDiscntEndDate());
  93. orderService.checkOrder(orderInfo);
  94. this.orderService.order(orderInfo, ecbProductInfo);
  95. } else {//退订
  96. orderInfo.setStatus(1);
  97. orderInfo.setOrderstatus(4);
  98. orderInfo.setCancelchannel(channel);
  99. orderService.checkCancelOrder(orderInfo);
  100. this.orderService.cancelOrder(orderInfo, ecbProductInfo);
  101. }
  102. if(orderInfo.getCpid().equals("changshi") && orderInfo.getSpid().equals("1150")){
  103. insertOrderMq(orderInfo, orderType, ecbProductInfo);
  104. insertHisMq(orderInfo, orderType);
  105. }
  106. } catch (Exception e) {
  107. result = "8000";
  108. if (e instanceof BusinessException) {
  109. result = ((BusinessException) e).getCode();
  110. }
  111. throw e;
  112. } finally {
  113. long endtime = System.currentTimeMillis();
  114. long times = (begintime - endtime);
  115. if (times > 5000) {
  116. Map<String, String> map = new HashMap<String, String>();
  117. map.put("userid", orderInfo.getUserid());
  118. map.put("cpid", orderInfo.getCpid());
  119. map.put("spid", orderInfo.getSpid());
  120. map.put("result", result);
  121. map.put("channel", channel);
  122. if ((!result.equals("0")) && (times > 5000 && times < 30000)) {
  123. map.put("style", "0");
  124. } else if ((!result.equals("0")) && (times > 30000)) {
  125. map.put("style", "1");
  126. } else if (result.equals("0")) {
  127. if(!orderInfo.getSpid().equals("1150")){
  128. map.put("style", "3");
  129. }
  130. }
  131. map.put("times", times + "");
  132. map.put("orderType", orderType);
  133. map.put("type", "cssms");
  134. URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map));
  135. //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
  136. }
  137. }
  138. return pipe;
  139. }
  140. public void insertOrderMq(OrderInfo orderInfo, String orderType, EcbProductInfo ecbProductInfo) {
  141. try {
  142. if (!csOrderControlDao.discntFeeControl(ecbProductInfo.getDiscntCode(), orderInfo.getCpid(),
  143. orderInfo.getSpid())) {
  144. Map<String, String> map = new HashMap<String, String>();
  145. map.put("userid", orderInfo.getUserid());
  146. map.put("cpid", orderInfo.getCpid());
  147. map.put("spid", orderInfo.getSpid());
  148. map.put("province", orderInfo.getProvince());
  149. map.put("area", orderInfo.getArea());
  150. map.put("ordertime", orderInfo.getOrdertime());
  151. map.put("canceltime", orderInfo.getCanceltime());
  152. if (orderType.equals("0")) {
  153. map.put("status", "0");
  154. } else {
  155. map.put("status", "1");
  156. }
  157. map.put("orderchannel", orderInfo.getOrderchannel());
  158. map.put("cancelchannel", orderInfo.getCancelchannel());
  159. map.put("videoid", orderInfo.getVideoid());
  160. map.put("type", "order");
  161. //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
  162. URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map));
  163. if(orderType.equals("0")){
  164. map = new HashMap<String, String>();
  165. map.put("userid", orderInfo.getUserid());
  166. map.put("cpid", orderInfo.getCpid());
  167. map.put("spid", orderInfo.getSpid());
  168. map.put("result", "0");
  169. map.put("channel", orderInfo.getOrderchannel());
  170. map.put("style", "6");
  171. map.put("times","");
  172. map.put("orderType", orderType);
  173. map.put("type", "cssms");
  174. //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
  175. URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map));
  176. }
  177. }
  178. } catch (Exception e) {
  179. e.printStackTrace();
  180. }
  181. }
  182. public void insertHisMq(OrderInfo orderInfo, String orderType) {
  183. try {
  184. if(orderInfo.getSpid().equals("1150")){
  185. Map<String, String> map = new HashMap<String, String>();
  186. map.put("userid", orderInfo.getUserid());
  187. map.put("cpid", orderInfo.getCpid());
  188. map.put("spid", orderInfo.getSpid());
  189. map.put("histype", "1");
  190. if (orderType.equals("0")) {
  191. map.put("result", "1");
  192. } else {
  193. map.put("result", "2");
  194. }
  195. map.put("vipcode", "");
  196. map.put("vipcpid", "");
  197. map.put("type", "cshis");
  198. //URLUtil.post("http://10.199.99.144:8090/mq-service/recive.do", JsonUtil.objectToJson(map));
  199. URLUtil.post(dictionaryDao.getValue("mqReciveUrl"), JsonUtil.objectToJson(map));
  200. }
  201. } catch (Exception e) {
  202. e.printStackTrace();
  203. }
  204. }
  205. public static void main(String[] args) throws UnsupportedEncodingException, BusinessException, Exception {
  206. }
  207. }