Commit 5031fa57636bde933abd69dd5906f8c1c98c0531
1 parent
50231151
积分奖励年底重置任务
Showing
4 changed files
with
117 additions
and
3 deletions
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/controller/admin/assigntasksinfo/AssignTasksInfoController.java
| ... | ... | @@ -186,7 +186,9 @@ public class AssignTasksInfoController { |
| 186 | 186 | triggerTime.atZone(ZoneId.systemDefault()) // 绑定时区 |
| 187 | 187 | .toInstant() // 转为Instant(含时区的时间戳) |
| 188 | 188 | ); |
| 189 | - quartzRemindService.registerRemindJob(id, triggerDate); | |
| 189 | + //quartzRemindService.registerRemindJob(id, triggerDate); | |
| 190 | + | |
| 191 | + unitIntegralService.resetUnitIntegralTotal(); | |
| 190 | 192 | } catch (Exception e) { |
| 191 | 193 | throw new RuntimeException("任务创建失败"); |
| 192 | 194 | } | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/job/task/ResetYearUnitIntegralJob.java
0 → 100644
| 1 | +package com.zteits.urbanops.module.garden.job.task; | |
| 2 | + | |
| 3 | +import com.zteits.urbanops.framework.quartz.core.handler.JobHandler; | |
| 4 | +import com.zteits.urbanops.module.garden.service.unitintegraltotal.UnitIntegralService; | |
| 5 | +import jakarta.annotation.Resource; | |
| 6 | +import lombok.extern.slf4j.Slf4j; | |
| 7 | +import org.springframework.stereotype.Component; | |
| 8 | + | |
| 9 | +import java.time.LocalDateTime; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * @Classname ResetYearPointJob | |
| 13 | + * @Description 年底积分清零 | |
| 14 | + * @Date 2026/3/11 17:04 | |
| 15 | + * @Created by wangqian | |
| 16 | + */ | |
| 17 | +@Component | |
| 18 | +@Slf4j | |
| 19 | +public class ResetYearUnitIntegralJob implements JobHandler { | |
| 20 | + | |
| 21 | + @Resource | |
| 22 | + private UnitIntegralService unitIntegralService; | |
| 23 | + | |
| 24 | + @Override | |
| 25 | + public String execute(String param) throws Exception { | |
| 26 | + log.info("【年底积分清零】开始执行" + LocalDateTime.now()); | |
| 27 | + unitIntegralService.resetUnitIntegralTotal(); | |
| 28 | + log.info("【年底积分清零】开始结束" + LocalDateTime.now()); | |
| 29 | + return "Successfully"; | |
| 30 | + } | |
| 31 | +} | ... | ... |
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/unitintegraltotal/UnitIntegralService.java
urbanops-module-garden/src/main/java/com/zteits/urbanops/module/garden/service/unitintegraltotal/UnitIntegralServiceImpl.java
| ... | ... | @@ -10,14 +10,17 @@ import com.zteits.urbanops.module.garden.controller.admin.unitintegralsub.vo.Uni |
| 10 | 10 | import com.zteits.urbanops.module.garden.controller.admin.unitintegraltotal.vo.UnitIntegralRespVO; |
| 11 | 11 | import com.zteits.urbanops.module.garden.controller.admin.unitintegraltotal.vo.UnitIntegralSaveReqVO; |
| 12 | 12 | import com.zteits.urbanops.module.garden.dal.dataobject.unitintegraladd.UnitIntegralAddDO; |
| 13 | +import com.zteits.urbanops.module.garden.dal.dataobject.unitintegralsub.UnitIntegralSubDO; | |
| 13 | 14 | import com.zteits.urbanops.module.garden.dal.dataobject.unitintegraltotal.UnitIntegralTotalDO; |
| 14 | 15 | import com.zteits.urbanops.module.garden.dal.mysql.unitintegraladd.UnitIntegralAddMapper; |
| 16 | +import com.zteits.urbanops.module.garden.dal.mysql.unitintegralsub.UnitIntegralSubMapper; | |
| 15 | 17 | import com.zteits.urbanops.module.garden.dal.mysql.unitintegraltotal.UnitIntegralTotalMapper; |
| 16 | 18 | import com.zteits.urbanops.module.garden.dal.redis.IntegralLockCoreRedisDAO; |
| 17 | 19 | import com.zteits.urbanops.module.garden.service.unitintegraladd.UnitIntegralAddService; |
| 18 | 20 | import com.zteits.urbanops.module.garden.service.unitintegralsub.UnitIntegralSubService; |
| 19 | 21 | import jakarta.annotation.Resource; |
| 20 | 22 | import lombok.extern.slf4j.Slf4j; |
| 23 | +import org.apache.commons.collections4.CollectionUtils; | |
| 21 | 24 | import org.apache.commons.lang3.ObjectUtils; |
| 22 | 25 | import org.apache.commons.lang3.StringUtils; |
| 23 | 26 | import org.redisson.api.RLock; |
| ... | ... | @@ -30,6 +33,7 @@ import java.time.LocalDateTime; |
| 30 | 33 | import java.time.format.DateTimeFormatter; |
| 31 | 34 | import java.util.List; |
| 32 | 35 | import java.util.concurrent.TimeUnit; |
| 36 | +import java.util.stream.Collectors; | |
| 33 | 37 | |
| 34 | 38 | import static com.zteits.urbanops.framework.common.exception.enums.GlobalErrorCodeConstants.BAD_REQUEST; |
| 35 | 39 | import static com.zteits.urbanops.framework.common.exception.enums.GlobalErrorCodeConstants.INTERNAL_SERVER_ERROR; |
| ... | ... | @@ -60,8 +64,8 @@ public class UnitIntegralServiceImpl implements UnitIntegralService{ |
| 60 | 64 | private RedissonClient redissonClient; |
| 61 | 65 | @Resource |
| 62 | 66 | private IntegralLockCoreRedisDAO integralLockCoreRedisDAO; |
| 63 | - | |
| 64 | - | |
| 67 | + @Resource | |
| 68 | + private UnitIntegralSubMapper unitIntegralSubMapper; | |
| 65 | 69 | // 锁前缀(区分加/减积分锁) |
| 66 | 70 | private static final String LOCK_PREFIX_INTEGRAL = "integral:"; |
| 67 | 71 | |
| ... | ... | @@ -257,6 +261,76 @@ public class UnitIntegralServiceImpl implements UnitIntegralService{ |
| 257 | 261 | } |
| 258 | 262 | ); |
| 259 | 263 | } |
| 264 | + | |
| 265 | + @Override | |
| 266 | + @Transactional | |
| 267 | + public void resetUnitIntegralTotal() { | |
| 268 | + // 1. 记录方法执行开始 | |
| 269 | + log.info("【单位积分重置】开始执行单位积分数据重置操作"); | |
| 270 | + try { | |
| 271 | + // ========== 处理单位积分总额表 ========== | |
| 272 | + log.info("【单位积分重置】开始处理单位积分总额表数据"); | |
| 273 | + List<UnitIntegralTotalDO> unitIntegralTotaList = unitIntegralTotalMapper.selectList(UnitIntegralTotalDO::getDeleted, 0); | |
| 274 | + if (CollectionUtils.isEmpty(unitIntegralTotaList)) { | |
| 275 | + log.info("【单位积分重置】单位积分总额表无未重置数据,无需处理"); | |
| 276 | + } else { | |
| 277 | + log.info("【单位积分重置】单位积分总额表重置完成,共重置{}条数据", unitIntegralTotaList.size()); | |
| 278 | + for (UnitIntegralTotalDO unitIntegralTotalDO : unitIntegralTotaList) { | |
| 279 | + String statDate = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy")); | |
| 280 | + if (statDate.equals(unitIntegralTotalDO.getStatDate())){ | |
| 281 | + unitIntegralTotalDO.setTotalIntegral(0); | |
| 282 | + unitIntegralTotalDO.setTotalAdd(0); | |
| 283 | + unitIntegralTotalDO.setTotalSub(0); | |
| 284 | + unitIntegralTotalMapper.updateById(unitIntegralTotalDO); | |
| 285 | + } else { | |
| 286 | + unitIntegralTotalMapper.deleteById(unitIntegralTotalDO.getId()); | |
| 287 | + } | |
| 288 | + } | |
| 289 | +// List<Long> idList = unitIntegralTotaList.stream() | |
| 290 | +// .map(UnitIntegralTotalDO::getId) | |
| 291 | +// .collect(Collectors.toList()); | |
| 292 | +// int deleteCount = unitIntegralTotalMapper.deleteByIds(idList); | |
| 293 | +// log.info("【单位积分重置】单位积分总额表删除完成,共删除{}条数据,删除的ID列表:{}", deleteCount, idList); | |
| 294 | + } | |
| 295 | + | |
| 296 | + // ========== 处理单位积分增加表 ========== | |
| 297 | + log.info("【单位积分重置】开始处理单位积分增加表数据"); | |
| 298 | + List<UnitIntegralAddDO> unitIntegralAddList = unitIntegralAddMapper.selectList(UnitIntegralAddDO::getDeleted, 0); | |
| 299 | + if (CollectionUtils.isEmpty(unitIntegralAddList)) { | |
| 300 | + log.info("【单位积分重置】单位积分增加表无未重置数据,无需处理"); | |
| 301 | + } else { | |
| 302 | + List<Long> addIdList = unitIntegralAddList.stream() | |
| 303 | + .map(UnitIntegralAddDO::getId) | |
| 304 | + .collect(Collectors.toList()); | |
| 305 | + int addDeleteCount = unitIntegralAddMapper.deleteByIds(addIdList); | |
| 306 | + log.info("【单位积分重置】单位积分增加表重置完成,共重置{}条数据,重置的ID列表:{}", addDeleteCount, addIdList); | |
| 307 | + } | |
| 308 | + | |
| 309 | + // ========== 处理单位积分扣减表 ========== | |
| 310 | + log.info("【单位积分重置】开始处理单位积分扣减表数据"); | |
| 311 | + List<UnitIntegralSubDO> unitIntegralSubList = unitIntegralSubMapper.selectList(UnitIntegralSubDO::getDeleted, 0); | |
| 312 | + if (CollectionUtils.isEmpty(unitIntegralSubList)) { | |
| 313 | + log.info("【单位积分重置】单位积分扣减表无未重置数据,无需处理"); | |
| 314 | + } else { | |
| 315 | + List<Long> subIdList = unitIntegralSubList.stream() | |
| 316 | + .map(UnitIntegralSubDO::getId) | |
| 317 | + .collect(Collectors.toList()); | |
| 318 | + int subDeleteCount = unitIntegralSubMapper.deleteByIds(subIdList); | |
| 319 | + // 修复原日志中“重置增加单位积分总额”的文案错误,改为“单位积分扣减表” | |
| 320 | + log.info("【单位积分重置】单位积分扣减表重置完成,共删除{}条数据,重置的ID列表:{}", subDeleteCount, subIdList); | |
| 321 | + } | |
| 322 | + | |
| 323 | + // 2. 记录方法执行成功 | |
| 324 | + log.info("【单位积分重置】单位积分数据重置操作执行完成,所有表处理完毕"); | |
| 325 | + | |
| 326 | + } catch (Exception e) { | |
| 327 | + // 3. 记录异常日志(包含堆栈信息) | |
| 328 | + log.error("【单位积分重置】执行单位积分数据重置操作失败", e); | |
| 329 | + // 抛出异常触发事务回滚,保证数据一致性 | |
| 330 | + throw new RuntimeException("重置单位积分数据失败", e); | |
| 331 | + } | |
| 332 | + } | |
| 333 | + | |
| 260 | 334 | /** |
| 261 | 335 | * 扣减积分核心执行方法(带事务,内部调用) |
| 262 | 336 | */ |
| ... | ... | @@ -317,4 +391,6 @@ public class UnitIntegralServiceImpl implements UnitIntegralService{ |
| 317 | 391 | return SpringUtil.getBean(getClass()); |
| 318 | 392 | } |
| 319 | 393 | |
| 394 | + | |
| 395 | + | |
| 320 | 396 | } | ... | ... |