From adf749e8da2bfce006390b008f6b9e8606b62180 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期四, 28 八月 2025 17:02:30 +0800
Subject: [PATCH] update

---
 cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/HomeModuleController.java |   55 ++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 42 insertions(+), 13 deletions(-)

diff --git a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/HomeModuleController.java b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/HomeModuleController.java
index 700baed..bf9f737 100644
--- a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/HomeModuleController.java
+++ b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/HomeModuleController.java
@@ -1,6 +1,7 @@
 package com.dsh.guns.modular.system.controller.code;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.dsh.guns.config.UserExt;
 import com.dsh.guns.core.util.ToolUtil;
 import com.dsh.guns.modular.system.model.HomeModule;
@@ -8,6 +9,7 @@
 import com.dsh.guns.modular.system.service.IStoreService;
 import com.dsh.guns.modular.system.util.ImageUtils;
 import com.dsh.guns.modular.system.util.ResultUtil;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -34,7 +36,10 @@
 
     @RequestMapping("/tHomeModule_platformSet/{id}")
     public String tHomeModulePlatformSet(@PathVariable Integer id, Model model) {
-        HomeModule data = homeModuleService.getById(id);
+        HomeModule data = homeModuleService.getOne(new LambdaQueryWrapper<HomeModule>().eq(HomeModule::getStoreId, id));
+        if(data==null){
+            data =homeModuleService.getById(1);
+        }
         List<Map<String, Object>> pages = storeService.typeChange(data.getModel());
         List<Map<String, Object>> types = storeService.typeChangeOne(data.getJumpPage());
         // type=1 查看详情 type=2 编辑
@@ -44,26 +49,50 @@
         model.addAttribute("data",data);
         model.addAttribute("pages",pages);
         model.addAttribute("types",types);
+        model.addAttribute("id",id);
         return PREFIX + "tHomeModule.html";
     }
 
     @ResponseBody
     @RequestMapping("/updateHomeModule")
     public ResultUtil updateAdvertisement(@RequestBody HomeModule homeModule) {
-        if (homeModule.getType().equals("请选择")){
-            homeModule.setType(null);
-        }
-        if (homeModule.getPage().equals("请选择")){
-            homeModule.setPage(null);
-        }
-        if (ToolUtil.isNotEmpty(homeModule.getBackgroundImage())) {
-            try {
-                homeModule.setDisplayType(ImageUtils.getImageDimensions(homeModule.getBackgroundImage()).getDisplayType());
-            } catch (IOException e) {
-                throw new RuntimeException(e);
+        HomeModule one = homeModuleService.getOne(new LambdaQueryWrapper<HomeModule>().eq(HomeModule::getStoreId, homeModule.getStoreId()));
+        if(one==null){
+            one = new HomeModule();
+            BeanUtils.copyProperties(homeModule,one);
+            one.setId(null);
+            if (homeModule.getType().equals("请选择")){
+                one.setType(null);
             }
+            if (homeModule.getPage().equals("请选择")){
+                one.setPage(null);
+            }
+            if (ToolUtil.isNotEmpty(homeModule.getBackgroundImage())) {
+                try {
+                    one.setDisplayType(ImageUtils.getImageDimensions(homeModule.getBackgroundImage()).getDisplayType());
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            return ResultUtil.success(homeModuleService.saveOrUpdate(one));
+
+        }else {
+            if (homeModule.getType().equals("请选择")){
+                homeModule.setType(null);
+            }
+            if (homeModule.getPage().equals("请选择")){
+                homeModule.setPage(null);
+            }
+            if (ToolUtil.isNotEmpty(homeModule.getBackgroundImage())) {
+                try {
+                    homeModule.setDisplayType(ImageUtils.getImageDimensions(homeModule.getBackgroundImage()).getDisplayType());
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+            return ResultUtil.success(homeModuleService.updateById(homeModule));
         }
-        return ResultUtil.success(homeModuleService.updateById(homeModule));
+
     }
 
 }

--
Gitblit v1.7.1