From 1c741aeeb78327e9ce93e6c2248e3aa779cdb030 Mon Sep 17 00:00:00 2001
From: Jinquan_Ou <Jinquan@gdut.com>
Date: 星期四, 06 四月 2023 22:16:30 +0800
Subject: [PATCH] 888

---
 zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java         |   48 ++++++++++++++++
 ruoyi-admin/src/main/resources/application-druid.yml                               |    4 
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java |   13 ---
 zhang-content/src/main/java/com/ruoyi/service/IZfPropertyService.java              |    4 +
 zhang-content/src/main/java/com/ruoyi/service/ZfEventService.java                  |    5 +
 ruoyi-admin/src/main/resources/application.yml                                     |    4 
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfEventController.java    |   11 ---
 zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java     |   50 ++++++++++++++++
 8 files changed, 115 insertions(+), 24 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfEventController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfEventController.java
index 485e78d..1b586df 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfEventController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfEventController.java
@@ -67,14 +67,7 @@
     @PostMapping("/importData")
     public AjaxResult importData(@RequestParam("excelImport") MultipartFile file) throws Exception
     {
-        ExcelUtil<ZfEvent> util = new ExcelUtil<>(ZfEvent.class);
-        List<ZfEvent> eventList = util.importExcel(file.getInputStream());
-        log.info("瀹跺涵澶т簨浠跺垪琛ㄤ负锛歿}",eventList);
-
-        if (zfEventService.saveBatch(eventList)) {
-            return AjaxResult.success("瀵煎叆鏁版嵁鎴愬姛");
-        }
-        return AjaxResult.error("瀵煎叆鏁版嵁澶辫触");
+        return zfEventService.importExcel(file);
 
     }
 
@@ -96,7 +89,7 @@
     @PostMapping
     public AjaxResult add(@RequestBody ZfEvent zfEvent)
     {
-        return toAjax(zfEventService.save(zfEvent));
+        return toAjax(zfEventService.addEvent(zfEvent));
     }
 
     /**
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java
index 6cd7dad..f8aab63 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/zhang/ZfPropertyController.java
@@ -69,16 +69,7 @@
     @PostMapping("/importData")
     public AjaxResult importData(@RequestParam("excelImport")MultipartFile file) throws Exception
     {
-        ExcelUtil<ZfProperty> util = new ExcelUtil<>(ZfProperty.class);
-        List<ZfProperty> propertyList = util.importExcel(file.getInputStream());
-        log.info("璧勪骇鍒楄〃涓猴細{}",propertyList);
-
-        if (zfPropertyService.saveBatch(propertyList)) {
-            return AjaxResult.success("瀵煎叆鏁版嵁鎴愬姛");
-        }
-
-        return AjaxResult.error("瀵煎叆鏁版嵁澶辫触");
-
+        return zfPropertyService.importExcel(file);
     }
 
     /**
@@ -99,7 +90,7 @@
     @PostMapping
     public AjaxResult add(@RequestBody ZfProperty zfProperty)
     {
-        return toAjax(zfPropertyService.save(zfProperty));
+        return toAjax(zfPropertyService.addProperty(zfProperty));
     }
 
     /**
diff --git a/ruoyi-admin/src/main/resources/application-druid.yml b/ruoyi-admin/src/main/resources/application-druid.yml
index 045d564..b2e66b2 100644
--- a/ruoyi-admin/src/main/resources/application-druid.yml
+++ b/ruoyi-admin/src/main/resources/application-druid.yml
@@ -6,8 +6,8 @@
         druid:
             # 涓诲簱鏁版嵁婧�
             master:
-#                url: jdbc:mysql://47.93.189.255:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
-                url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+                url: jdbc:mysql://47.93.189.255:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
+#                url: jdbc:mysql://localhost:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                 username: root
                 password: ZhangApp123!
 #                password: 123456
diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml
index ebd475f..2a71b7e 100644
--- a/ruoyi-admin/src/main/resources/application.yml
+++ b/ruoyi-admin/src/main/resources/application.yml
@@ -70,8 +70,8 @@
   # redis 閰嶇疆
   redis:
     # 鍦板潃
-    host: localhost
-#    host: 192.168.88.68
+#    host: localhost
+    host: 192.168.88.68
     # 绔彛锛岄粯璁や负6379
     port: 6379
     # 鏁版嵁搴撶储寮�
diff --git a/zhang-content/src/main/java/com/ruoyi/service/IZfPropertyService.java b/zhang-content/src/main/java/com/ruoyi/service/IZfPropertyService.java
index 87d0b3d..b68eaa9 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/IZfPropertyService.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/IZfPropertyService.java
@@ -3,6 +3,7 @@
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.domain.ZfProperty;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -19,4 +20,7 @@
 
     AjaxResult selectPropertyList(ZfProperty zfProperty,Integer pageNum,Integer pageSize);
 
+    int addProperty(ZfProperty zfProperty);
+
+    AjaxResult importExcel(MultipartFile file);
 }
diff --git a/zhang-content/src/main/java/com/ruoyi/service/ZfEventService.java b/zhang-content/src/main/java/com/ruoyi/service/ZfEventService.java
index d8b18f6..36f3cdf 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/ZfEventService.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/ZfEventService.java
@@ -4,6 +4,7 @@
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.domain.ZfEvent;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.util.List;
 
@@ -20,4 +21,8 @@
     AjaxResult selectEventList(ZfEvent zfEvent, Integer pageNum, Integer pageSize);
 
     List<ZfEvent> selectByCondition(ZfEvent zfEvent);
+
+    int addEvent(ZfEvent zfEvent);
+
+    AjaxResult importExcel(MultipartFile file);
 }
diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java
index c39ef1d..a6d3abf 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/IZfPropertyServiceImpl.java
@@ -8,7 +8,9 @@
 import com.ruoyi.common.utils.MapUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.domain.ZInfoUser;
+import com.ruoyi.domain.ZfProperty;
 import com.ruoyi.domain.ZfEvent;
 import com.ruoyi.domain.ZfProperty;
 import com.ruoyi.mapper.ZfPropertyMapper;
@@ -16,6 +18,7 @@
 import com.ruoyi.service.ZInfoUserService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import java.text.ParseException;
@@ -39,6 +42,9 @@
 
     @Resource
     ZInfoUserService zInfoUserService;
+    
+    @Resource
+    IZfPropertyService zfPropertyService;
 
     @Override
     public List<ZfProperty> selectByCondition(ZfProperty zfProperty) {
@@ -94,6 +100,50 @@
 
     }
 
+    @Override
+    public int addProperty(ZfProperty zfProperty) {
+
+        String familyIds = listFamilyIds();
+        boolean flag = false;//鍒ゆ柇褰撳墠鐢ㄦ埛鐨刬d鏄惁鏈夋潈鍔犲叆褰撳墠瀹跺涵id鐨勫璞�
+        if (familyIds.contains(",")) {
+            String[] familyList = familyIds.split(",");
+            for (String familyId : familyList) {
+                if (familyId.equals(zfProperty.getFamilyId())) {
+                    flag = true;
+                }
+            }
+        } else {
+            if (zfProperty.getFamilyId().equals(familyIds)) {
+                flag = true;
+            }
+        }
+        if (flag) {
+            boolean save = save(zfProperty);
+            return save ? 1 : 0;
+        } else {
+            throw new RuntimeException("浣犳病鏈夋搷浣滆瀹跺涵鍙蜂负" + zfProperty.getFamilyId() + "鏁版嵁鐨勬潈闄�");
+        }
+    }
+
+    @Override
+    public AjaxResult importExcel(MultipartFile file) {
+        ExcelUtil<ZfProperty> util = new ExcelUtil<>(ZfProperty.class);
+        List<ZfProperty> propertyList = null;
+        try {
+            propertyList = util.importExcel(file.getInputStream());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        log.info("璧勪骇鍒楄〃涓猴細{}", propertyList);
+
+        for (ZfProperty zfProperty : propertyList) {
+            zfPropertyService.addProperty(zfProperty);
+        }
+
+        return AjaxResult.success("瀵煎叆鏁版嵁鎴愬姛");
+        
+    }
+
 }
 
 
diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java
index d4f9477..151a865 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfEventServiceImpl.java
@@ -9,13 +9,16 @@
 import com.ruoyi.common.utils.MapUtils;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.domain.ZInfoUser;
+import com.ruoyi.domain.ZfEvent;
 import com.ruoyi.domain.ZfEvent;
 import com.ruoyi.mapper.ZfEventMapper;
 import com.ruoyi.service.ZInfoUserService;
 import com.ruoyi.service.ZfEventService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import java.util.HashMap;
@@ -35,6 +38,9 @@
 
     @Resource
     ZInfoUserService zInfoUserService;
+
+    @Resource
+    ZfEventService zfEventService;
     
     private String listFamilyIds(){
         SysUser user = SecurityUtils.getLoginUser().getUser();
@@ -68,6 +74,48 @@
         return list;
     }
 
+    @Override
+    public int addEvent(ZfEvent zfEvent) {
+        String familyIds = listFamilyIds();
+        boolean flag = false;//鍒ゆ柇褰撳墠鐢ㄦ埛鐨刬d鏄惁鏈夋潈鍔犲叆褰撳墠瀹跺涵id鐨勫璞�
+        if (familyIds.contains(",")) {
+            String[] familyList = familyIds.split(",");
+            for (String familyId : familyList) {
+                if (familyId.equals(zfEvent.getFamilyId())) {
+                    flag = true;
+                }
+            }
+        } else {
+            if (zfEvent.getFamilyId().equals(familyIds)) {
+                flag = true;
+            }
+        }
+        if (flag) {
+            boolean save = save(zfEvent);
+            return save ? 1 : 0;
+        } else {
+            throw new RuntimeException("浣犳病鏈夋搷浣滆瀹跺涵鍙蜂负" + zfEvent.getFamilyId() + "鏁版嵁鐨勬潈闄�");
+        }
+    }
+
+    @Override
+    public AjaxResult importExcel(MultipartFile file) {
+        ExcelUtil<ZfEvent> util = new ExcelUtil<>(ZfEvent.class);
+        List<ZfEvent> eventList = null;
+        try {
+            eventList = util.importExcel(file.getInputStream());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+        log.info("璧勪骇鍒楄〃涓猴細{}", eventList);
+
+        for (ZfEvent zfEvent : eventList) {
+            zfEventService.addEvent(zfEvent);
+        }
+
+        return AjaxResult.success("瀵煎叆鏁版嵁鎴愬姛");
+    }
+
     private LambdaQueryWrapper<ZfEvent> buildCondition(ZfEvent zfEvent) {
         LambdaQueryWrapper<ZfEvent> lqw = new LambdaQueryWrapper<>();
         lqw.like(!StringUtils.isEmpty(zfEvent.getAddress()),ZfEvent::getAddress,zfEvent.getAddress());

--
Gitblit v1.9.1