From 2f8e173048d22c5b40612c3538b9c1aa5a5397f6 Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期五, 27 三月 2026 13:38:05 +0800
Subject: [PATCH] #乐观锁
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/WaveController.java | 45 +++++++++++++++++++++++++++------------------
1 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/WaveController.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/WaveController.java
index 77fd2ea..160818c 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/WaveController.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/WaveController.java
@@ -9,6 +9,7 @@
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.common.domain.PageResult;
import com.vincent.rsf.server.common.utils.ExcelUtil;
+import com.vincent.rsf.server.common.utils.OptimisticLockUtils;
import com.vincent.rsf.server.common.annotation.OperationLog;
import com.vincent.rsf.server.common.domain.BaseParam;
import com.vincent.rsf.server.common.domain.KeyValVo;
@@ -24,6 +25,7 @@
import com.vincent.rsf.server.manager.service.TaskItemService;
import com.vincent.rsf.server.manager.service.WaveService;
import com.vincent.rsf.server.manager.service.impl.TaskItemLogServiceImpl;
+import com.vincent.rsf.server.manager.service.impl.WaveItemServiceImpl;
import com.vincent.rsf.server.system.controller.BaseController;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
@@ -31,7 +33,7 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
-import javax.servlet.http.HttpServletResponse;
+import jakarta.servlet.http.HttpServletResponse;
import java.util.*;
@RestController
@@ -45,6 +47,8 @@
private OutStockService outStockService;
@Autowired
private TaskItemLogService taskItemLogService;
+ @Autowired
+ private WaveItemServiceImpl waveItemService;
@PreAuthorize("hasAuthority('manager:wave:list')")
@PostMapping("/wave/page")
@@ -88,6 +92,7 @@
@OperationLog("Update 娉㈡鍗曟嵁")
@PostMapping("/wave/update")
public R update(@RequestBody Wave wave) {
+ OptimisticLockUtils.requireVersion("娉㈡", wave.getVersion());
wave.setUpdateBy(getLoginUserId());
wave.setUpdateTime(new Date());
if (!waveService.updateById(wave)) {
@@ -169,9 +174,14 @@
@ApiOperation("鏆傚仠涓嬪彂浠诲姟")
@PostMapping("/wave/pause/pub/{id}")
public R pausePublicTask(@PathVariable Long id) {
- waveService.update(new LambdaUpdateWrapper<Wave>()
- .eq(Wave::getId, id)
- .set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_PAUSE.val));
+ Wave wave = waveService.getById(id);
+ if (Objects.isNull(wave)) {
+ throw new CoolException("娉㈡鏁版嵁涓嶅瓨鍦紒锛�");
+ }
+ wave.setExceStatus(WaveExceStatus.WAVE_EXCE_STATUS_PAUSE.val);
+ if (!waveService.updateById(wave)) {
+ throw new CoolException("娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+ }
return R.ok();
}
@@ -179,9 +189,14 @@
@ApiOperation("缁х画涓嬪彂浠诲姟")
@PostMapping("/wave/continue/pub/{id}")
public R continuePublicTask(@PathVariable Long id) {
- waveService.update(new LambdaUpdateWrapper<Wave>()
- .eq(Wave::getId, id)
- .set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_EXCING.val));
+ Wave wave = waveService.getById(id);
+ if (Objects.isNull(wave)) {
+ throw new CoolException("娉㈡鏁版嵁涓嶅瓨鍦紒锛�");
+ }
+ wave.setExceStatus(WaveExceStatus.WAVE_EXCE_STATUS_EXCING.val);
+ if (!waveService.updateById(wave)) {
+ throw new CoolException("娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+ }
return R.ok();
}
@@ -195,20 +210,14 @@
}
Wave wave = waveService.getById(id);
if (Objects.isNull(wave)) {
- throw new CoolException("娉㈡鍗曚笉瀛樺湪锛侊紒");
+ throw new CoolException("娉㈡鏁版嵁涓嶅瓨鍦紒锛�");
}
- List<TaskItemLog> taskItems = taskItemLogService.list(new LambdaQueryWrapper<TaskItemLog>().eq(TaskItemLog::getSourceId, wave.getId()));
- if (taskItems.isEmpty()) {
-
-
- } else {
-
+ wave.setExceStatus(WaveExceStatus.WAVE_EXCE_STATUS_PAUSE.val);
+ if (!waveService.updateById(wave)) {
+ throw new CoolException("娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
}
- waveService.update(new LambdaUpdateWrapper<Wave>()
- .eq(Wave::getId, id)
- .set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_TASK.val));
- return R.ok();
+ return waveService.stopPubTask(id);
}
}
--
Gitblit v1.9.1