92ac6cb9e52aa1f481b2eeb29b7beb0b40e8753f.svn-base 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package com.chinacreator.videoalliance.order.action;
  2. import com.chinacreator.common.exception.BusinessException;
  3. import com.chinacreator.common.util.AESUtil;
  4. import com.chinacreator.common.util.URLUtil;
  5. import com.chinacreator.common.util.UsermobUtil;
  6. import com.chinacreator.videoalliance.common.bean.AreaInfo;
  7. import com.chinacreator.videoalliance.common.util.AreaUtil;
  8. import com.chinacreator.videoalliance.order.bean.ChannelOrgBean;
  9. import com.chinacreator.videoalliance.order.bean.ChannelSyncBean;
  10. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  11. import com.chinacreator.videoalliance.order.bean.SPInfo;
  12. import com.chinacreator.videoalliance.order.dao.ChannelDao;
  13. import com.chinacreator.videoalliance.order.dao.SPDao;
  14. import com.chinacreator.videoalliance.order.service.OrderService;
  15. import com.chinacreator.videoalliance.order.util.JsonUtil;
  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 org.springframework.web.bind.annotation.ResponseBody;
  21. import javax.servlet.http.HttpServletRequest;
  22. import java.util.HashMap;
  23. import java.util.Map;
  24. @Controller
  25. public class ChannelSyncAction {
  26. @Autowired
  27. private OrderService orderService;
  28. @Autowired
  29. private SPDao spDao;
  30. @Autowired
  31. private ChannelDao channelDao;
  32. @RequestMapping({"/channelSync.do"})
  33. @ResponseBody
  34. public Object doOrder(HttpServletRequest request)
  35. throws Exception
  36. {
  37. Map<String,String> pipe = new HashMap<String, String>();
  38. String resultcode = "0";
  39. String resultinfo = "";
  40. try{
  41. String requestStr = URLUtil.readInputStream(request.getInputStream());
  42. Map<?,?> map = JsonUtil.jsonToMap(requestStr);
  43. String channelcode = (String)map.get("channelcode");
  44. String syncOrder = (String)map.get("syncOrder");
  45. ChannelSyncBean bean = null;
  46. ChannelOrgBean channelBean = channelDao.findByChannelId(channelcode);
  47. if(channelBean == null || !channelBean.getStatus().equals("0")){
  48. throw new BusinessException("9040", "渠道同步已关闭");
  49. }
  50. try{
  51. String desSyncOrder = AESUtil.decrypt(syncOrder, channelBean.getPassword());
  52. bean = (ChannelSyncBean) JsonUtil.jsonToBean(desSyncOrder, ChannelSyncBean.class);
  53. if(StringUtils.isEmpty(bean.getProductid()) && StringUtils.isEmpty(bean.getType()) && StringUtils.isEmpty(bean.getUpdateTime()) && StringUtils.isEmpty(bean.getUserid()) ){
  54. throw new BusinessException("9036", "渠道同步参数错误");
  55. }
  56. }catch(Exception e){
  57. throw new BusinessException("9036", "渠道同步参数错误");
  58. }
  59. SPInfo spInfo = spDao.findByVacId(bean.getProductid());
  60. if(spInfo == null){
  61. throw new BusinessException("9037", "渠道同步产品id验证失败");
  62. }
  63. if(!UsermobUtil.isValid(bean.getUserid())){
  64. throw new BusinessException("9038", "渠道同步产品手机号码验证失败");
  65. }
  66. if(!(bean.getType().equals("0") || bean.getType().equals("1"))){
  67. throw new BusinessException("9039", "渠道同步产品操作验证失败");
  68. }
  69. OrderInfo orderInfo =new OrderInfo();
  70. orderInfo.setUserid(bean.getUserid());
  71. orderInfo.setCpid(spInfo.getCpid());
  72. orderInfo.setSpid(spInfo.getSpid());
  73. AreaInfo areaInfo = AreaUtil.getAreaInfoByUserid(bean.getUserid());
  74. if (areaInfo == null) {
  75. areaInfo = new AreaInfo();
  76. }
  77. orderInfo.setProvince(areaInfo.getProvince());
  78. orderInfo.setArea(areaInfo.getArea());
  79. orderInfo.setPaytype(2);
  80. if(bean.getType().equals("0")){
  81. orderInfo.setStatus(0);
  82. orderInfo.setOrdertime(bean.getUpdateTime());
  83. orderInfo.setOrderchannel(channelcode);
  84. orderInfo.setOrderstatus(3);
  85. orderService.order(orderInfo);
  86. }else{
  87. orderInfo.setStatus(1);
  88. orderInfo.setOrderstatus(5);
  89. orderInfo.setCanceltime(bean.getUpdateTime());
  90. orderInfo.setCancelchannel(channelcode);
  91. orderService.cancelOrder(orderInfo);
  92. }
  93. }catch(Exception e){
  94. e.printStackTrace();
  95. if(e instanceof BusinessException){
  96. resultcode = ((BusinessException) e).getCode();
  97. resultinfo = ((BusinessException) e).getMessage();
  98. }else{
  99. resultcode = "8000";
  100. resultinfo = "系统忙";
  101. }
  102. }finally {
  103. pipe.put("resultcode", resultcode);
  104. pipe.put("resultinfo", resultinfo);
  105. }
  106. return pipe;
  107. }
  108. public static void main(String[] args) throws Exception {
  109. Map<String,String> map = new HashMap<String, String>();
  110. Map<String,String> syncmap = new HashMap<String, String>();
  111. syncmap.put("userid", "18574414678");
  112. syncmap.put("productid", "8000610900");
  113. syncmap.put("type", "0");
  114. syncmap.put("updateTime", "20170605235959");
  115. map.put("channelcode", "hnsync");
  116. map.put("syncOrder", AESUtil.encrypt(JsonUtil.objectToJson(syncmap), "exsgt73abb2f4521"));
  117. String result = URLUtil.post("http://114.255.201.228:86/videoif/channelSync.do", JsonUtil.objectToJson(map));
  118. System.out.println(result);
  119. }
  120. }