7f52f94ad3810f30fd95eb378cbfd45568b0f72d.svn-base 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package com.chinacreator.videoalliance.order.service;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.stereotype.Component;
  4. import org.springframework.util.StringUtils;
  5. import com.chinacreator.common.exception.BusinessException;
  6. import com.chinacreator.common.util.Base64;
  7. import com.chinacreator.common.util.UsermobUtil;
  8. import com.chinacreator.videoalliance.common.bean.AreaInfo;
  9. import com.chinacreator.videoalliance.common.bean.CPInfo;
  10. import com.chinacreator.videoalliance.common.dao.DictionaryDao;
  11. import com.chinacreator.videoalliance.common.dao.ProvinceControlDao;
  12. import com.chinacreator.videoalliance.common.dao.SysDao;
  13. import com.chinacreator.videoalliance.common.util.AreaUtil;
  14. import com.chinacreator.videoalliance.common.util.ConfigUtil;
  15. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  16. import com.chinacreator.videoalliance.order.bean.OrderLog;
  17. import com.chinacreator.videoalliance.order.bean.SPInfo;
  18. import com.chinacreator.videoalliance.order.dao.BlackWhiteDao;
  19. import com.chinacreator.videoalliance.order.dao.OrderDao;
  20. import com.chinacreator.videoalliance.order.dao.OrderLogDao;
  21. import com.chinacreator.videoalliance.order.dao.SPDao;
  22. @Component
  23. public class ExperienceOrderService {
  24. @Autowired
  25. private OrderLogDao orderLogDao;
  26. @Autowired
  27. private BlackWhiteDao blackWhiteDao;
  28. @Autowired
  29. private SPDao spDao;
  30. @Autowired
  31. private DictionaryDao dictionaryDao;
  32. @Autowired
  33. private SysDao sysDao;
  34. @Autowired
  35. private ProvinceControlDao provinceControlDao;
  36. @Autowired
  37. private OrderDao orderDao;
  38. private void checkUserid(OrderInfo orderInfo)
  39. throws Exception
  40. {
  41. String userid = orderInfo.getUserid();
  42. if ((StringUtils.isEmpty(userid)) || ("null".equals(userid)))
  43. throw new BusinessException("7002", "手机号码无效", new String[0]);
  44. if (!UsermobUtil.isValid(userid)) {
  45. userid = ConfigUtil.decrypt(userid, orderInfo.getCpid());
  46. userid = ConfigUtil.getUserid(userid, orderInfo.getCpid());
  47. }
  48. if (!UsermobUtil.isValid(userid)) {
  49. throw new BusinessException("7002", "手机号码无效", new String[0]);
  50. }
  51. orderInfo.setUserid(userid);
  52. }
  53. private void checkSpInfo(OrderInfo orderInfo) throws Exception {
  54. SPInfo spInfo = getSPInfo(orderInfo);
  55. if (spInfo.getCanorder() == 1) {
  56. throw new BusinessException("9012", "该产品不支持订购操作", new String[0]);
  57. }
  58. if (orderInfo.getOrdertype() == 1) {
  59. if (spInfo.getType() != 0) {
  60. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  61. }
  62. if (StringUtils.isEmpty(orderInfo.getVideoid())) {
  63. throw new BusinessException("8002", "{0}参数无效", new String[] { "videoid" });
  64. }
  65. if (StringUtils.isEmpty(orderInfo.getVideoname()))
  66. throw new BusinessException("8002", "{0}参数无效", new String[] { "videoname" });
  67. try
  68. {
  69. String videoname = new String(Base64.decodeBase64(orderInfo.getVideoname()), "UTF-8");
  70. orderInfo.setVideoname(videoname);
  71. } catch (Exception e) {
  72. throw new BusinessException("8002", "{0}参数无效", new String[] { "videoname" });
  73. }
  74. orderInfo.setEndtime(this.sysDao.getLastDay());
  75. } else if (orderInfo.getOrdertype() == 0) {
  76. if (spInfo.getType() == 0)
  77. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  78. }
  79. else {
  80. throw new BusinessException("8002", "{0}参数无效", new String[] { "ordertype" });
  81. }
  82. orderInfo.setSpid(spInfo.getSpid());
  83. }
  84. public void checkOrder(OrderInfo orderInfo)
  85. throws Exception
  86. {
  87. checkUserid(orderInfo);
  88. checkSpInfo(orderInfo);
  89. String userid = orderInfo.getUserid();
  90. if (this.blackWhiteDao.isBlackUser(userid, orderInfo.getCpid())) {
  91. throw new BusinessException("9002", "用户为黑名单用户", new String[0]);
  92. }
  93. AreaInfo areaInfo = getAreaInfo(userid);
  94. orderInfo.setProvince(areaInfo.getProvince());
  95. orderInfo.setArea(areaInfo.getArea());
  96. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), areaInfo.getProvince());
  97. if (cpInfo == null) {
  98. throw new BusinessException("7005", "CP标识无效", new String[0]);
  99. }
  100. String allowOrder = this.dictionaryDao.getValue("allowOrder");
  101. if (("1".equals(allowOrder)) || (areaInfo.getStatus() == 1)) {
  102. throw new BusinessException("9002", "该业务暂未开放,敬请期待。", new String[0]);
  103. }
  104. if ((areaInfo.getProvince() != null) && (this.provinceControlDao.isNotOpen(areaInfo.getProvince())))
  105. throw new BusinessException("9003", "您号码的归属地{0}暂未开放该业务,敬请期待。", new String[] { areaInfo.getProvince() });
  106. }
  107. private SPInfo getSPInfo(OrderInfo orderInfo) throws Exception {
  108. SPInfo spInfo = null;
  109. if (StringUtils.isEmpty(orderInfo.getSpid()))
  110. spInfo = this.spDao.findDefaultByCP(orderInfo.getCpid());
  111. else {
  112. spInfo = this.spDao.findById(orderInfo.getSpid());
  113. }
  114. if (spInfo == null) {
  115. throw new BusinessException("5305", "产品标识符无效", new String[0]);
  116. }
  117. orderInfo.setSpid(spInfo.getSpid());
  118. return spInfo;
  119. }
  120. private AreaInfo getAreaInfo(String userid) throws Exception
  121. {
  122. AreaInfo areaInfo = AreaUtil.getAreaInfoByUserid(userid);
  123. if (areaInfo == null) {
  124. areaInfo = new AreaInfo();
  125. }
  126. return areaInfo;
  127. }
  128. public void order(OrderInfo orderInfo)
  129. throws Exception
  130. {
  131. String errorcode = "0";
  132. String errorinfo = "";
  133. try {
  134. if (!this.orderDao.hasValid(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid())) {
  135. if (!this.blackWhiteDao.isWhiteUser(orderInfo.getUserid(), orderInfo.getCpid())) {
  136. CPInfo cpInfo = ConfigUtil.getCPInfo(orderInfo.getCpid(), null);
  137. if ((cpInfo.getStatus() != 0) && (cpInfo.getStatus() != 4)) {
  138. throw new BusinessException("9002", "该业务暂未开放,敬请期待。", new String[0]);
  139. }
  140. }
  141. String currentTime = this.sysDao.getCurrentTime();
  142. orderInfo.setOrdertime(currentTime);
  143. if (orderInfo.getEffecttime() == null) {
  144. orderInfo.setEffecttime(currentTime);
  145. }
  146. orderInfo.setOrderstatus(7);
  147. orderInfo.setIsexperience(1);
  148. orderInfo.setShowstatus("0");
  149. this.orderDao.order(orderInfo);
  150. }else{
  151. throw new BusinessException("9002", "该业务还在有效期内,过期后请重新订购", new String[0]);
  152. }
  153. } catch (Exception e) {
  154. errorcode = "8000";
  155. if ((e instanceof BusinessException)) {
  156. errorcode = ((BusinessException)e).getCode();
  157. }
  158. throw e;
  159. } finally {
  160. saveLog(orderInfo, errorcode, errorinfo);
  161. }
  162. }
  163. public void saveLog(OrderInfo orderInfo, String errorcode, String errorinfo) {
  164. OrderLog orderLog = new OrderLog();
  165. System.out.println("orderInfo==null=======>"+(orderInfo==null));
  166. orderLog.setApptype(orderInfo.getApptype());
  167. orderLog.setArea(orderInfo.getArea());
  168. orderLog.setChannel(orderInfo.getOrderchannel());
  169. orderLog.setOrderstatus(orderInfo.getOrderstatus());
  170. orderLog.setStatus(orderInfo.getStatus());
  171. orderLog.setCpid(orderInfo.getCpid());
  172. orderLog.setIsexperience(orderInfo.getIsexperience());
  173. orderLog.setOrdertype(orderInfo.getOrdertype()+"");
  174. orderLog.setProvince(orderInfo.getProvince());
  175. orderLog.setArea(orderInfo.getArea());
  176. orderLog.setSpid(orderInfo.getSpid());
  177. orderLog.setUserid(orderInfo.getUserid());
  178. orderLog.setErrorcode(errorcode);
  179. orderLog.setErrorinfo(errorinfo);
  180. this.orderLogDao.addOrderLog(orderLog);
  181. }
  182. }