From 18d187869d098a2893d79acdadc7d7a99aad28e6 Mon Sep 17 00:00:00 2001
From: kongdeqiang <123456>
Date: 星期一, 24 三月 2025 15:23:37 +0800
Subject: [PATCH] fix: 更新设备项目表和项目子表接口

---
 platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandTotalController.java |  101 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 84 insertions(+), 17 deletions(-)

diff --git a/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandTotalController.java b/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandTotalController.java
index 8ebe9d6..914cdb9 100644
--- a/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandTotalController.java
+++ b/platformx-device-biz/src/main/java/com/by4cloud/platformx/device/controller/DeviceDemandTotalController.java
@@ -3,11 +3,15 @@
 import cn.hutool.core.util.ArrayUtil;
 import cn.hutool.core.collection.CollUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.by4cloud.platformx.common.core.util.R;
 import com.by4cloud.platformx.common.log.annotation.SysLog;
+import com.by4cloud.platformx.device.entity.DeviceDemandPlan;
+import com.by4cloud.platformx.device.entity.DeviceDemandSub;
 import com.by4cloud.platformx.device.entity.DeviceDemandTotal;
+import com.by4cloud.platformx.device.service.DeviceDemandSubService;
 import com.by4cloud.platformx.device.service.DeviceDemandTotalService;
 import org.springframework.security.access.prepost.PreAuthorize;
 import com.by4cloud.platformx.common.excel.annotation.ResponseExcel;
@@ -36,6 +40,7 @@
 public class DeviceDemandTotalController {
 
     private final  DeviceDemandTotalService deviceDemandTotalService;
+    private final DeviceDemandSubService deviceDemandSubService;
 
     /**
      * 鍒嗛〉鏌ヨ
@@ -61,10 +66,31 @@
     @GetMapping("/{id}" )
     @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_view')" )
     public R getById(@PathVariable("id" ) Long id) {
-        return R.ok(deviceDemandTotalService.getById(id));
+		DeviceDemandTotal demandTotal = deviceDemandTotalService.getById(id);
+		QueryWrapper<DeviceDemandSub> wrapper = new QueryWrapper<>();
+		wrapper.lambda()
+				.eq(DeviceDemandSub::getTotalId,demandTotal.getId());
+		List<DeviceDemandSub> list = deviceDemandSubService.list(wrapper);
+		demandTotal.setSubList(list);
+		return R.ok(demandTotal);
     }
 
-    /**
+	/**
+	 * 閫氳繃id鏌ヨ璁惧闇�姹傝鍒掗」鐩瓙琛�
+	 * @param id id
+	 * @return R
+	 */
+	@Operation(summary = "閫氳繃id鏌ヨ" , description = "閫氳繃id鏌ヨ" )
+	@GetMapping("/getByPlanId/{id}" )
+	public R getByPlanId(@PathVariable("id" ) Long id) {
+		QueryWrapper<DeviceDemandTotal> wrapper = new QueryWrapper<>();
+		wrapper.lambda()
+				.eq(DeviceDemandTotal::getPlanId,id);
+		return R.ok(deviceDemandTotalService.list(wrapper));
+	}
+
+
+	/**
      * 鏂板璁惧闇�姹傝鍒掗」鐩瓙琛�
      * @param deviceDemandTotal 璁惧闇�姹傝鍒掗」鐩瓙琛�
      * @return R
@@ -72,9 +98,17 @@
     @Operation(summary = "鏂板璁惧闇�姹傝鍒掗」鐩瓙琛�" , description = "鏂板璁惧闇�姹傝鍒掗」鐩瓙琛�" )
     @SysLog("鏂板璁惧闇�姹傝鍒掗」鐩瓙琛�" )
     @PostMapping
-    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_add')" )
     public R save(@RequestBody DeviceDemandTotal deviceDemandTotal) {
-        return R.ok(deviceDemandTotalService.save(deviceDemandTotal));
+		if(deviceDemandTotal.getPlanId()==null){
+			return R.failed("璁″垝id蹇呬紶");
+		}
+		deviceDemandTotalService.save(deviceDemandTotal);
+		List<DeviceDemandSub> subList = deviceDemandTotal.getSubList();
+		for (DeviceDemandSub deviceDemandSub : subList) {
+			deviceDemandSub.setTotalId(deviceDemandTotal.getId());
+			deviceDemandSubService.save(deviceDemandSub);
+		}
+		return R.ok("娣诲姞鎴愬姛");
     }
 
     /**
@@ -87,21 +121,54 @@
     @PutMapping
     @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_edit')" )
     public R updateById(@RequestBody DeviceDemandTotal deviceDemandTotal) {
-        return R.ok(deviceDemandTotalService.updateById(deviceDemandTotal));
+		List<DeviceDemandSub> subList = deviceDemandTotal.getSubList();
+		QueryWrapper<DeviceDemandSub> wrapper = new QueryWrapper<>();
+		wrapper.lambda()
+				.eq(DeviceDemandSub::getTotalId,deviceDemandTotal.getId());
+		List<DeviceDemandSub> list = deviceDemandSubService.list(wrapper);
+		deviceDemandSubService.removeBatchByIds(list);
+		for (DeviceDemandSub deviceDemandSub : subList) {
+			deviceDemandSub.setTotalId(deviceDemandTotal.getId());
+			deviceDemandSubService.save(deviceDemandSub);
+		}
+		return R.ok(deviceDemandTotalService.updateById(deviceDemandTotal));
     }
 
-    /**
-     * 閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�
-     * @param ids id鍒楄〃
-     * @return R
-     */
-    @Operation(summary = "閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�" , description = "閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�" )
-    @SysLog("閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�" )
-    @DeleteMapping
-    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_del')" )
-    public R removeById(@RequestBody Long[] ids) {
-        return R.ok(deviceDemandTotalService.removeBatchByIds(CollUtil.toList(ids)));
-    }
+	/**
+	 * 閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�
+	 * @param id id
+	 * @return R
+	 */
+	@Operation(summary = "閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�" , description = "閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�" )
+	@SysLog("閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�" )
+	@GetMapping("/deleteById/{id}")
+	public R deleteById(@PathVariable("id" ) Long id) {
+		DeviceDemandTotal byId = deviceDemandTotalService.getById(id);
+		if(byId != null){
+			deviceDemandTotalService.removeById(id);
+			QueryWrapper<DeviceDemandSub> wrapper = new QueryWrapper<>();
+			wrapper.lambda()
+					.eq(DeviceDemandSub::getTotalId,byId.getId());
+			List<DeviceDemandSub> list = deviceDemandSubService.list(wrapper);
+			deviceDemandSubService.removeBatchByIds(list);
+		}else {
+			return R.failed("鏈煡璇㈠埌璇ラ」鐩�");
+		}
+		return R.ok();
+	}
+
+//    /**
+//     * 閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�
+//     * @param ids id鍒楄〃
+//     * @return R
+//     */
+//    @Operation(summary = "閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�" , description = "閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�" )
+//    @SysLog("閫氳繃id鍒犻櫎璁惧闇�姹傝鍒掗」鐩瓙琛�" )
+//    @DeleteMapping
+//    @PreAuthorize("@pms.hasPermission('platformx_deviceDemandTotal_del')" )
+//    public R removeById(@RequestBody Long[] ids) {
+//        return R.ok(deviceDemandTotalService.removeBatchByIds(CollUtil.toList(ids)));
+//    }
 
 
     /**

--
Gitblit v1.9.1