package com.chinacreator.videoalliance.order.service; import java.sql.SQLException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.HashMap; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.chinacreator.common.exception.BusinessException; import com.chinacreator.videoalliance.order.bean.OrderInfo; import com.chinacreator.videoalliance.order.dao.BackBusiOrderDao; import com.chinacreator.videoalliance.order.dao.HeyueOrderDao; /** * 合约包服务类 * @author xu.zhou * @date 20210830 1. 合约产品订购后只能在第6个月才能退订,如果1至5月要退订,客户通过客服在鉴权平台进行退订。 2. 客户再订购时,如果退订时间在订购起的1至5月份退订的,且再次订购时间未超过合约期的,不能再订购, 比如:前次订购日期是2月,客户通过客服退订,那么在2月到7月之间不能再订购。但在8月份可以再订购。 3. 客户投诉,客服通过鉴权平台把客户号码和产品SPID增加到白名单,可以再次订购,订购完成后,白名单失效 4、合约包黑名单用户如果在原合约期内订购,订购报错提示文案: 因您之前在合约期内退订,请在原合约期结束后再订购。 */ @Component public class HeyueOrderService { private static Logger logger = Logger.getLogger("orderError"); @Autowired private HeyueOrderDao heyueOrderDao; @Autowired private BackBusiOrderDao backBusiOrderDao; /** * 合约产品订购成功,更新白名单表状态 * @param orderInfo * @param spinfo * @param result * @throws Exception */ public void heyueOrderAfter(OrderInfo orderInfo) { try { //判断订购的是否合约产品且是通过合约白名单订购的,如果是,则更改合约白名单表的状态为已使用 if(orderInfo.getDirectype() != null && orderInfo.getDirectype().split("#").length == 2 //是否有对directype进行处理 && "3".equals(orderInfo.getDirectype().split("#")[0]) //是否为合约产品 && "heyuewhitelist".equals(orderInfo.getDirectype().split("#")[1])){ orderInfo.setDirectype(orderInfo.getDirectype().split("#")[0]); //还原directype设置 boolean updres = heyueOrderDao.updWhiteList(orderInfo.getUserid(), orderInfo.getSpid()); logger.error(orderInfo.getUserid()+","+orderInfo.getSpid()+",更新合约产品白名单状态完成,"+updres); } } catch (Exception e) { e.printStackTrace(); logger.error(orderInfo.getUserid()+","+orderInfo.getSpid()+",合约产品更新白名单出现异常,"+e.getMessage()); } } /** * 订购前合约产品判断 * @param orderInfo * @param spinfo * @throws Exception */ public void heyueOrderBefore(OrderInfo orderInfo) throws Exception{ //是合约产品 ,且不是违约金合约产品 if("3".equals(orderInfo.getDirectype()) && !"wyj".equals(orderInfo.getCpid())){//如果是合约产品 //获取用户订购关系,判断是否退订,且退订时间是否在订购时间5个月内 HashMap reMap = backBusiOrderDao.findByUserAndSpid(orderInfo.getUserid(), orderInfo.getCpid(), orderInfo.getSpid()); if(reMap != null && reMap.size()>0){ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); //订购日期 String ordertime = (String)reMap.get("ORDERTIME"); //退订日期 String canceltime = (String)reMap.get("CANCELTIME"); String currmonth = sdf.format(new Date()); if(canceltime != null && canceltime.length() == 14){//已退订 if(getDifMonth(canceltime, ordertime) < 5 && getDifMonth(currmonth, ordertime) < 6){//退订月份在订购日期后的5月内,且当前月与订购月份在6个月内 //是合约产吕白名单 if(heyueOrderDao.isWhiteList(orderInfo.getUserid(), orderInfo.getSpid())){ orderInfo.setDirectype("3#heyuewhitelist"); //用于区分是走白名单进行订购的,用于订购成功后更新合约白名单表的状态,减少数据库查询 logger.error(orderInfo.getUserid()+","+orderInfo.getSpid()+",合约产品白名单,允许订购"); }else{ throw new BusinessException("9046", "因您之前在合约期内退订,请在原合约期结束后再订购", new String[0]); } } } } } } /** * 获取月份差值 * @param canceltime 格式YYYYMMDDHH24MISS * @param ordertime 格式YYYYMMDDHH24MISS * @return 月份差值,比如canceltime是202108XXXXXX,ordertime202103XXXXXX,返回5 * 退订日期在订购日期的5月内,返回小于5,比如2月份订,6月份退,返回4,7月退返回5 * @throws Exception */ private int getDifMonth(String canceltime, String ordertime) throws Exception{ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); start.setTime(sdf.parse(ordertime.substring(0, 6))); end.setTime(sdf.parse(canceltime.substring(0, 6))); int result = end.get(Calendar.MONTH) - start.get(Calendar.MONTH); int month = (end.get(Calendar.YEAR) - start.get(Calendar.YEAR)) * 12; return Math.abs(month + result); } }