ActivityUtil.java 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package com.iamberry.wechat.utils;
  2. import com.iamberry.wechat.core.entity.coupon.ActivityDate;
  3. import com.iamberry.wechat.face.admin.SystemService;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Component;
  6. import java.text.SimpleDateFormat;
  7. import java.util.Date;
  8. /**
  9. * 上朵活动类
  10. */
  11. @Component
  12. public class ActivityUtil {
  13. @Autowired
  14. private SystemService systemService;
  15. private SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  16. /**
  17. * 获取日期
  18. * @param type
  19. * @return
  20. */
  21. private ActivityDate initDate(Integer type){
  22. ActivityDate activityDate = new ActivityDate();
  23. try {
  24. switch (type){
  25. case 1:
  26. String begin = systemService.selectOneShopRuleByIdDynamic(260).getRuleDesc();
  27. activityDate.setBeginDate(sd.parse(begin)); ;
  28. String end = systemService.selectOneShopRuleByIdDynamic(261).getRuleDesc();
  29. activityDate.setEndDate(sd.parse(end));
  30. break;
  31. default:
  32. activityDate = null;
  33. break;
  34. }
  35. }catch (Exception e){
  36. activityDate = null;
  37. e.printStackTrace();
  38. }
  39. return activityDate;
  40. }
  41. /**
  42. * 判断是否在注销时间内
  43. * @return 期限内true;
  44. */
  45. public ActivityDate doubleTwelve(){
  46. ActivityDate activityDate = initDate(1);
  47. activityDate.setRemark("38女神节注销活动时间");
  48. if(activityDate == null){
  49. activityDate.setStatus(false);
  50. }
  51. Date date = new Date();
  52. if (activityDate.getBeginDate().before(date) && date.before(activityDate.getEndDate())){ //beginDate 比 date 早? true :false
  53. activityDate.setStatus(true);
  54. return activityDate;
  55. }
  56. activityDate.setStatus(false);
  57. return activityDate;
  58. }
  59. }