76857db94a4522b43f2efe4411ff0c20e8bc6f54.svn-base 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package com.chinacreator.videoalliance.order.service;
  2. import java.sql.SQLException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import org.apache.log4j.Logger;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Component;
  10. import com.chinacreator.common.exception.BusinessException;
  11. import com.chinacreator.videoalliance.order.bean.OrderInfo;
  12. import com.chinacreator.videoalliance.order.dao.BackBusiOrderDao;
  13. import com.chinacreator.videoalliance.order.dao.HeyueOrderDao;
  14. /**
  15. * 合约包服务类
  16. * @author xu.zhou
  17. * @date 20210830
  18. 1. 合约产品订购后只能在第6个月才能退订,如果1至5月要退订,客户通过客服在鉴权平台进行退订。
  19. 2. 客户再订购时,如果退订时间在订购起的1至5月份退订的,且再次订购时间未超过合约期的,不能再订购,
  20. 比如:前次订购日期是2月,客户通过客服退订,那么在2月到7月之间不能再订购。但在8月份可以再订购。
  21. 3. 客户投诉,客服通过鉴权平台把客户号码和产品SPID增加到白名单,可以再次订购,订购完成后,白名单失效
  22. 4、合约包黑名单用户如果在原合约期内订购,订购报错提示文案:
  23. 因您之前在合约期内退订,请在原合约期结束后再订购。
  24. */
  25. @Component
  26. public class HeyueOrderService {
  27. private static Logger logger = Logger.getLogger("orderError");
  28. @Autowired
  29. private HeyueOrderDao heyueOrderDao;
  30. @Autowired
  31. private BackBusiOrderDao backBusiOrderDao;
  32. /**
  33. * 合约产品订购成功,更新白名单表状态
  34. * @param orderInfo
  35. * @param spinfo
  36. * @param result
  37. * @throws Exception
  38. */
  39. public void heyueOrderAfter(OrderInfo orderInfo) {
  40. try {
  41. //判断订购的是否合约产品且是通过合约白名单订购的,如果是,则更改合约白名单表的状态为已使用
  42. if(orderInfo.getDirectype() != null
  43. && orderInfo.getDirectype().split("#").length == 2 //是否有对directype进行处理
  44. && "3".equals(orderInfo.getDirectype().split("#")[0]) //是否为合约产品
  45. && "heyuewhitelist".equals(orderInfo.getDirectype().split("#")[1])){
  46. orderInfo.setDirectype(orderInfo.getDirectype().split("#")[0]); //还原directype设置
  47. boolean updres = heyueOrderDao.updWhiteList(orderInfo.getUserid(), orderInfo.getSpid());
  48. logger.error(orderInfo.getUserid()+","+orderInfo.getSpid()+",更新合约产品白名单状态完成,"+updres);
  49. }
  50. } catch (Exception e) {
  51. e.printStackTrace();
  52. logger.error(orderInfo.getUserid()+","+orderInfo.getSpid()+",合约产品更新白名单出现异常,"+e.getMessage());
  53. }
  54. }
  55. /**
  56. * 订购前合约产品判断
  57. * @param orderInfo
  58. * @param spinfo
  59. * @throws Exception
  60. */
  61. public void heyueOrderBefore(OrderInfo orderInfo) throws Exception{
  62. //是合约产品 ,且不是违约金合约产品
  63. if("3".equals(orderInfo.getDirectype()) && !"wyj".equals(orderInfo.getCpid())){//如果是合约产品
  64. //获取用户订购关系,判断是否退订,且退订时间是否在订购时间5个月内
  65. HashMap reMap = backBusiOrderDao.findByUserAndSpid(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid());
  66. if(reMap != null && reMap.size()>0){
  67. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
  68. //订购日期
  69. String ordertime = (String)reMap.get("ORDERTIME");
  70. //退订日期
  71. String canceltime = (String)reMap.get("CANCELTIME");
  72. String currmonth = sdf.format(new Date());
  73. if(canceltime != null && canceltime.length() == 14){//已退订
  74. if(getDifMonth(canceltime, ordertime) < 5 && getDifMonth(currmonth, ordertime) < 6){//退订月份在订购日期后的5月内,且当前月与订购月份在6个月内
  75. //是合约产吕白名单
  76. if(heyueOrderDao.isWhiteList(orderInfo.getUserid(), orderInfo.getSpid())){
  77. orderInfo.setDirectype("3#heyuewhitelist"); //用于区分是走白名单进行订购的,用于订购成功后更新合约白名单表的状态,减少数据库查询
  78. logger.error(orderInfo.getUserid()+","+orderInfo.getSpid()+",合约产品白名单,允许订购");
  79. }else{
  80. throw new BusinessException("9046", "因您之前在合约期内退订,请在原合约期结束后再订购", new String[0]);
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }
  87. /**
  88. * 获取月份差值
  89. * @param canceltime 格式YYYYMMDDHH24MISS
  90. * @param ordertime 格式YYYYMMDDHH24MISS
  91. * @return 月份差值,比如canceltime是202108XXXXXX,ordertime202103XXXXXX,返回5
  92. * 退订日期在订购日期的5月内,返回小于5,比如2月份订,6月份退,返回4,7月退返回5
  93. * @throws Exception
  94. */
  95. private int getDifMonth(String canceltime, String ordertime) throws Exception{
  96. SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
  97. Calendar start = Calendar.getInstance();
  98. Calendar end = Calendar.getInstance();
  99. start.setTime(sdf.parse(ordertime.substring(0, 6)));
  100. end.setTime(sdf.parse(canceltime.substring(0, 6)));
  101. int result = end.get(Calendar.MONTH) - start.get(Calendar.MONTH);
  102. int month = (end.get(Calendar.YEAR) - start.get(Calendar.YEAR)) * 12;
  103. return Math.abs(month + result);
  104. }
  105. }