From 04e0677e23d17324ef80508b1019a0fa19db6aa4 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 10 十月 2024 15:52:18 +0800
Subject: [PATCH] #
---
zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java | 36 +++++++++++++++++++++++++++++-------
1 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java
index 3a3dc37..cfe3057 100644
--- a/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java
+++ b/zy-acs-manager/src/main/java/com/zy/acs/manager/manager/controller/RouteController.java
@@ -6,6 +6,7 @@
import com.zy.acs.common.utils.Utils;
import com.zy.acs.framework.common.Cools;
import com.zy.acs.framework.common.R;
+import com.zy.acs.framework.exception.CoolException;
import com.zy.acs.manager.common.annotation.OperationLog;
import com.zy.acs.manager.common.domain.BaseParam;
import com.zy.acs.manager.common.domain.KeyValVo;
@@ -20,6 +21,7 @@
import com.zy.acs.manager.system.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
@@ -67,6 +69,7 @@
@PreAuthorize("hasAuthority('manager:route:save')")
@OperationLog("Create Route")
@PostMapping("/route/save")
+ @Transactional
public R save(@RequestBody Route route) {
if (route.getStartCode() == null || route.getEndCode() == null) {
return R.error("Save Fail");
@@ -78,17 +81,24 @@
.eq(Route::getStartCode, route.getStartCode())
.eq(Route::getEndCode, route.getEndCode())) > 0 ||
routeService.count(new LambdaQueryWrapper<Route>()
- .eq(Route::getStartCode, route.getStartCode())
- .eq(Route::getEndCode, route.getEndCode())) > 0
+ .eq(Route::getStartCode, route.getEndCode())
+ .eq(Route::getEndCode, route.getStartCode())) > 0
) {
return R.error("Save Fail");
}
- route.setCreateBy(getLoginUserId());
- route.setCreateTime(new Date());
- route.setUpdateBy(getLoginUserId());
- route.setUpdateTime(new Date());
- if (!routeService.save(route)) {
+
+ Code startCode = codeService.getById(route.getStartCode());
+ Code endCode = codeService.getById(route.getEndCode());
+
+ if (null == startCode || null == endCode) {
return R.error("Save Fail");
+ }
+
+ Route result = routeService.createRouteByCode(startCode, endCode, route.getDirection(), getLoginUserId());
+ codeGapService.createCodeGapByCode(startCode, endCode, getLoginUserId());
+
+ if (null == result) {
+ throw new CoolException("Save Fail");
}
return R.ok("Save Success").add(route);
}
@@ -100,6 +110,18 @@
if (route.getStartCode().equals(route.getEndCode())) {
return R.error("Update Fail");
}
+ if (routeService.count(new LambdaQueryWrapper<Route>()
+ .eq(Route::getStartCode, route.getStartCode())
+ .eq(Route::getEndCode, route.getEndCode())
+ .ne(Route::getId, route.getId())) > 0 ||
+ routeService.count(new LambdaQueryWrapper<Route>()
+ .eq(Route::getStartCode, route.getEndCode())
+ .eq(Route::getEndCode, route.getStartCode())
+ .ne(Route::getId, route.getId())) > 0
+ ) {
+ return R.error("Update Fail");
+ }
+
route.setUpdateBy(getLoginUserId());
route.setUpdateTime(new Date());
if (!routeService.updateById(route)) {
--
Gitblit v1.9.1