1.手动发放积分时默认过期时间为第二年的最后一天
Showing
3 changed files
with
190 additions
and
2 deletions
| ... | @@ -17,11 +17,13 @@ import com.topdraw.business.process.service.dto.CustomPointsResult; | ... | @@ -17,11 +17,13 @@ import com.topdraw.business.process.service.dto.CustomPointsResult; |
| 17 | import com.topdraw.business.process.service.member.MemberOperationService; | 17 | import com.topdraw.business.process.service.member.MemberOperationService; |
| 18 | import com.topdraw.business.process.service.PointsOperationService; | 18 | import com.topdraw.business.process.service.PointsOperationService; |
| 19 | import com.topdraw.business.process.domian.TempPoints; | 19 | import com.topdraw.business.process.domian.TempPoints; |
| 20 | import com.topdraw.util.DateUtil; | ||
| 20 | import com.topdraw.util.IdWorker; | 21 | import com.topdraw.util.IdWorker; |
| 21 | import com.topdraw.util.TimestampUtil; | 22 | import com.topdraw.util.TimestampUtil; |
| 22 | import com.topdraw.utils.RedisUtils; | 23 | import com.topdraw.utils.RedisUtils; |
| 23 | import com.topdraw.utils.StringUtils; | 24 | import com.topdraw.utils.StringUtils; |
| 24 | import lombok.extern.slf4j.Slf4j; | 25 | import lombok.extern.slf4j.Slf4j; |
| 26 | import org.apache.commons.lang3.time.DateUtils; | ||
| 25 | import org.slf4j.Logger; | 27 | import org.slf4j.Logger; |
| 26 | import org.slf4j.LoggerFactory; | 28 | import org.slf4j.LoggerFactory; |
| 27 | import org.springframework.aop.framework.AopContext; | 29 | import org.springframework.aop.framework.AopContext; |
| ... | @@ -35,6 +37,7 @@ import org.springframework.util.CollectionUtils; | ... | @@ -35,6 +37,7 @@ import org.springframework.util.CollectionUtils; |
| 35 | 37 | ||
| 36 | import java.time.LocalDateTime; | 38 | import java.time.LocalDateTime; |
| 37 | import java.util.*; | 39 | import java.util.*; |
| 40 | import java.util.concurrent.TimeUnit; | ||
| 38 | import java.util.stream.Collectors; | 41 | import java.util.stream.Collectors; |
| 39 | 42 | ||
| 40 | /** | 43 | /** |
| ... | @@ -92,6 +95,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { | ... | @@ -92,6 +95,7 @@ public class PointsOperationServiceImpl implements PointsOperationService { |
| 92 | @Override | 95 | @Override |
| 93 | public void grantPointsByManualByTempPoints(TempPoints tempPoints) { | 96 | public void grantPointsByManualByTempPoints(TempPoints tempPoints) { |
| 94 | if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) { | 97 | if (Objects.nonNull(tempPoints) && Objects.nonNull(tempPoints.getPoints())) { |
| 98 | tempPoints.setExpireTime(DateUtil.getLastDateTimeSecondYear()); | ||
| 95 | this.refresh(tempPoints); | 99 | this.refresh(tempPoints); |
| 96 | } | 100 | } |
| 97 | } | 101 | } | ... | ... |
| 1 | package com.topdraw.util; | 1 | package com.topdraw.util; |
| 2 | 2 | ||
| 3 | import java.time.Instant; | ||
| 4 | import java.time.LocalDate; | ||
| 3 | import java.time.LocalDateTime; | 5 | import java.time.LocalDateTime; |
| 6 | import java.time.ZoneId; | ||
| 7 | import java.util.Calendar; | ||
| 4 | import java.util.Date; | 8 | import java.util.Date; |
| 9 | import java.util.TimeZone; | ||
| 5 | 10 | ||
| 6 | public class DateUtil { | 11 | public class DateUtil { |
| 7 | 12 | ||
| ... | @@ -13,5 +18,184 @@ public class DateUtil { | ... | @@ -13,5 +18,184 @@ public class DateUtil { |
| 13 | return System.currentTimeMillis(); | 18 | return System.currentTimeMillis(); |
| 14 | } | 19 | } |
| 15 | 20 | ||
| 21 | public static LocalDateTime getLastDateTimeCurrentYear(){ | ||
| 22 | Long currentTime = System.currentTimeMillis(); | ||
| 23 | Long yearEnd = getYearEndTime(currentTime, "GMT+8:00"); | ||
| 24 | LocalDateTime localDateTime = TimestampUtil.long2LocalDateTime(yearEnd); | ||
| 25 | return localDateTime; | ||
| 26 | } | ||
| 27 | |||
| 28 | public static LocalDateTime getLastDateTimeSecondYear(){ | ||
| 29 | int year = LocalDateTime.now().getYear()+1; | ||
| 30 | Long yearEndTime = getYearEndTime(year, "GMT+8:00"); | ||
| 31 | LocalDateTime localDateTime = TimestampUtil.long2LocalDateTime(yearEndTime); | ||
| 32 | return localDateTime; | ||
| 33 | } | ||
| 34 | |||
| 35 | |||
| 36 | /** | ||
| 37 | * 获取指定某一天的开始时间戳 | ||
| 38 | * | ||
| 39 | * @param timeStamp 毫秒级时间戳 | ||
| 40 | * @param timeZone 如 GMT+8:00 | ||
| 41 | * @return | ||
| 42 | */ | ||
| 43 | public static Long getDailyStartTime(Long timeStamp, String timeZone) { | ||
| 44 | Calendar calendar = Calendar.getInstance(); | ||
| 45 | calendar.setTimeZone(TimeZone.getTimeZone(timeZone)); | ||
| 46 | calendar.setTimeInMillis(timeStamp); | ||
| 47 | calendar.set(Calendar.HOUR_OF_DAY, 0); | ||
| 48 | calendar.set(Calendar.SECOND, 0); | ||
| 49 | calendar.set(Calendar.MINUTE, 0); | ||
| 50 | calendar.set(Calendar.MILLISECOND, 0); | ||
| 51 | return calendar.getTimeInMillis(); | ||
| 52 | } | ||
| 53 | |||
| 54 | /** | ||
| 55 | * 获取指定某一天的结束时间戳 | ||
| 56 | * | ||
| 57 | * @param timeStamp 毫秒级时间戳 | ||
| 58 | * @param timeZone 如 GMT+8:00 | ||
| 59 | * @return | ||
| 60 | */ | ||
| 61 | public static Long getDailyEndTime(Long timeStamp, String timeZone) { | ||
| 62 | Calendar calendar = Calendar.getInstance(); | ||
| 63 | calendar.setTimeZone(TimeZone.getTimeZone(timeZone)); | ||
| 64 | calendar.setTimeInMillis(timeStamp); | ||
| 65 | calendar.set(Calendar.HOUR_OF_DAY, 23); | ||
| 66 | calendar.set(Calendar.MINUTE, 59); | ||
| 67 | calendar.set(Calendar.SECOND, 59); | ||
| 68 | calendar.set(Calendar.MILLISECOND, 999); | ||
| 69 | return calendar.getTimeInMillis(); | ||
| 70 | } | ||
| 71 | |||
| 72 | /** | ||
| 73 | * 获取当月开始时间戳 | ||
| 74 | * | ||
| 75 | * @param timeStamp 毫秒级时间戳 | ||
| 76 | * @param timeZone 如 GMT+8:00 | ||
| 77 | * @return | ||
| 78 | */ | ||
| 79 | public static Long getMonthStartTime(Long timeStamp, String timeZone) { | ||
| 80 | Calendar calendar = Calendar.getInstance();// 获取当前日期 | ||
| 81 | calendar.setTimeZone(TimeZone.getTimeZone(timeZone)); | ||
| 82 | calendar.setTimeInMillis(timeStamp); | ||
| 83 | calendar.add(Calendar.YEAR, 0); | ||
| 84 | calendar.add(Calendar.MONTH, 0); | ||
| 85 | calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天 | ||
| 86 | calendar.set(Calendar.HOUR_OF_DAY, 0); | ||
| 87 | calendar.set(Calendar.MINUTE, 0); | ||
| 88 | calendar.set(Calendar.SECOND, 0); | ||
| 89 | calendar.set(Calendar.MILLISECOND, 0); | ||
| 90 | return calendar.getTimeInMillis(); | ||
| 91 | } | ||
| 92 | |||
| 93 | /** | ||
| 94 | * 获取当月的结束时间戳 | ||
| 95 | * | ||
| 96 | * @param timeStamp 毫秒级时间戳 | ||
| 97 | * @param timeZone 如 GMT+8:00 | ||
| 98 | * @return | ||
| 99 | */ | ||
| 100 | public static Long getMonthEndTime(Long timeStamp, String timeZone) { | ||
| 101 | Calendar calendar = Calendar.getInstance();// 获取当前日期 | ||
| 102 | calendar.setTimeZone(TimeZone.getTimeZone(timeZone)); | ||
| 103 | calendar.setTimeInMillis(timeStamp); | ||
| 104 | calendar.add(Calendar.YEAR, 0); | ||
| 105 | calendar.add(Calendar.MONTH, 0); | ||
| 106 | calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));// 获取当前月最后一天 | ||
| 107 | calendar.set(Calendar.HOUR_OF_DAY, 23); | ||
| 108 | calendar.set(Calendar.MINUTE, 59); | ||
| 109 | calendar.set(Calendar.SECOND, 59); | ||
| 110 | calendar.set(Calendar.MILLISECOND, 999); | ||
| 111 | return calendar.getTimeInMillis(); | ||
| 112 | } | ||
| 113 | |||
| 114 | /** | ||
| 115 | * 获取当年的开始时间戳 | ||
| 116 | * | ||
| 117 | * @param timeStamp 毫秒级时间戳 | ||
| 118 | * @param timeZone 如 GMT+8:00 | ||
| 119 | * @return | ||
| 120 | */ | ||
| 121 | public static Long getYearStartTime(Long timeStamp, String timeZone) { | ||
| 122 | Calendar calendar = Calendar.getInstance();// 获取当前日期 | ||
| 123 | calendar.setTimeZone(TimeZone.getTimeZone(timeZone)); | ||
| 124 | calendar.setTimeInMillis(timeStamp); | ||
| 125 | calendar.add(Calendar.YEAR, 0); | ||
| 126 | calendar.add(Calendar.DATE, 0); | ||
| 127 | calendar.add(Calendar.MONTH, 0); | ||
| 128 | calendar.set(Calendar.DAY_OF_YEAR, 1); | ||
| 129 | calendar.set(Calendar.HOUR_OF_DAY, 0); | ||
| 130 | calendar.set(Calendar.MINUTE, 0); | ||
| 131 | calendar.set(Calendar.SECOND, 0); | ||
| 132 | calendar.set(Calendar.MILLISECOND, 0); | ||
| 133 | return calendar.getTimeInMillis(); | ||
| 134 | } | ||
| 135 | |||
| 136 | /** | ||
| 137 | * 获取当年的最后时间戳 | ||
| 138 | * | ||
| 139 | * @param timeStamp 毫秒级时间戳 | ||
| 140 | * @param timeZone 如 GMT+8:00 | ||
| 141 | * @return | ||
| 142 | */ | ||
| 143 | public static Long getYearEndTime(Long timeStamp, String timeZone) { | ||
| 144 | Calendar calendar = Calendar.getInstance();// 获取当前日期 | ||
| 145 | calendar.setTimeZone(TimeZone.getTimeZone(timeZone)); | ||
| 146 | calendar.setTimeInMillis(timeStamp); | ||
| 147 | int year = calendar.get(Calendar.YEAR); | ||
| 148 | calendar.clear(); | ||
| 149 | calendar.set(Calendar.YEAR, year); | ||
| 150 | calendar.set(Calendar.HOUR_OF_DAY, 23); | ||
| 151 | calendar.set(Calendar.MINUTE, 59); | ||
| 152 | calendar.set(Calendar.SECOND, 59); | ||
| 153 | calendar.set(Calendar.MILLISECOND, 999); | ||
| 154 | calendar.roll(Calendar.DAY_OF_YEAR, -1); | ||
| 155 | return calendar.getTimeInMillis(); | ||
| 156 | } | ||
| 157 | |||
| 158 | public static Long getYearEndTime(int year, String timeZone) { | ||
| 159 | Calendar calendar = Calendar.getInstance();// 获取当前日期 | ||
| 160 | calendar.setTimeZone(TimeZone.getTimeZone(timeZone)); | ||
| 161 | calendar.clear(); | ||
| 162 | calendar.set(Calendar.YEAR, year); | ||
| 163 | calendar.set(Calendar.HOUR_OF_DAY, 23); | ||
| 164 | calendar.set(Calendar.MINUTE, 59); | ||
| 165 | calendar.set(Calendar.SECOND, 59); | ||
| 166 | calendar.set(Calendar.MILLISECOND, 000); | ||
| 167 | calendar.roll(Calendar.DAY_OF_YEAR, -1); | ||
| 168 | return calendar.getTimeInMillis(); | ||
| 169 | } | ||
| 170 | |||
| 171 | /** | ||
| 172 | * 时间戳转字符串 | ||
| 173 | * | ||
| 174 | * @param timestamp 毫秒级时间戳 | ||
| 175 | * @param zoneId 如 GMT+8或UTC+08:00 | ||
| 176 | * @return | ||
| 177 | */ | ||
| 178 | public static String timestampToStr(long timestamp, String zoneId) { | ||
| 179 | ZoneId timezone = ZoneId.of(zoneId); | ||
| 180 | LocalDateTime localDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), timezone); | ||
| 181 | return localDateTime.toString(); | ||
| 182 | } | ||
| 183 | |||
| 184 | public static void main(String[] args) { | ||
| 185 | /*Long currentTime = System.currentTimeMillis(); | ||
| 186 | System.out.println("Current Time : " + currentTime + " = " + timestampToStr(currentTime, "GMT+8")); | ||
| 187 | Long dailyStart = getDailyStartTime(currentTime, "GMT+8:00"); | ||
| 188 | Long dailyEnd = getDailyEndTime(currentTime, "GMT+8:00"); | ||
| 189 | Long monthStart = getMonthStartTime(currentTime, "GMT+8:00"); | ||
| 190 | Long monthEnd = getMonthEndTime(currentTime, "GMT+8:00"); | ||
| 191 | Long yearStart = getYearStartTime(currentTime, "GMT+8:00"); | ||
| 192 | Long yearEnd = getYearEndTime(currentTime, "GMT+8:00"); | ||
| 193 | |||
| 194 | System.out.println("Daily Start : " + dailyStart + " = " + timestampToStr(dailyStart, "GMT+8") + " Daily End : " + dailyEnd + " = " + timestampToStr(dailyEnd, "GMT+8")); | ||
| 195 | System.out.println("Month Start : " + monthStart + " = " + timestampToStr(monthStart, "GMT+8") + " Month End : " + monthEnd + " = " + timestampToStr(monthEnd, "GMT+8")); | ||
| 196 | System.out.println("Year Start : " + yearStart + " = " + timestampToStr(yearStart, "GMT+8") + " Year End : " + yearEnd + " = " + timestampToStr(yearEnd, "GMT+8")); | ||
| 197 | */ | ||
| 198 | LocalDateTime lastDateTimeCurrentYear = getLastDateTimeSecondYear(); | ||
| 199 | } | ||
| 16 | 200 | ||
| 17 | } | 201 | } | ... | ... |
| ... | @@ -47,8 +47,8 @@ public class PointsOperationControllerTest extends BaseTest { | ... | @@ -47,8 +47,8 @@ public class PointsOperationControllerTest extends BaseTest { |
| 47 | tempPoints.setActivityId(null); | 47 | tempPoints.setActivityId(null); |
| 48 | tempPoints.setItemId(null); | 48 | tempPoints.setItemId(null); |
| 49 | tempPoints.setDescription("系统发放"); | 49 | tempPoints.setDescription("系统发放"); |
| 50 | tempPoints.setEvtType(1); | 50 | tempPoints.setEvtType(98); |
| 51 | tempPoints.setActivityId(1L); | 51 | // tempPoints.setActivityId(1L); |
| 52 | String s = JSON.toJSONString(tempPoints); | 52 | String s = JSON.toJSONString(tempPoints); |
| 53 | ResultInfo byId = this.pointsOperationController.addPoints(tempPoints); | 53 | ResultInfo byId = this.pointsOperationController.addPoints(tempPoints); |
| 54 | LOG.info("===>>>"+byId); | 54 | LOG.info("===>>>"+byId); | ... | ... |
-
Please register or sign in to post a comment