From 5b9f71b862978c3ca16708db2f9de329bf65b3bf Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期日, 18 九月 2022 18:57:42 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/crm/manager/controller/CstmrController.java |   95 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 92 insertions(+), 3 deletions(-)

diff --git a/src/main/java/com/zy/crm/manager/controller/CstmrController.java b/src/main/java/com/zy/crm/manager/controller/CstmrController.java
index 41bd8d0..f86f7a7 100644
--- a/src/main/java/com/zy/crm/manager/controller/CstmrController.java
+++ b/src/main/java/com/zy/crm/manager/controller/CstmrController.java
@@ -13,11 +13,23 @@
 import com.zy.crm.common.web.BaseController;
 import com.zy.crm.manager.entity.Cstmr;
 import com.zy.crm.manager.service.CstmrService;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.*;
 
+@Slf4j
 @RestController
 public class CstmrController extends BaseController {
 
@@ -41,9 +53,24 @@
         EntityWrapper<Cstmr> wrapper = new EntityWrapper<>();
         excludeTrash(param);
         convert(param, wrapper);
+        hostEq(wrapper);
         allLike(Cstmr.class, param.keySet(), wrapper, condition);
-        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
-        return R.ok(cstmrService.selectPage(new Page<>(curr, limit), wrapper));
+        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} else {
+            wrapper.orderBy("create_time", false);
+        }
+        if (!Cools.isEmpty(param.get("dept_id"))) {
+            return R.ok(cstmrService.getPage(new Page<>(curr, limit)
+                    , getHostId()
+                    , String.valueOf(param.get("dept_id"))
+                    , condition)
+            );
+        } else {
+            if (Cools.isEmpty(param.get("user_id"))) {
+                wrapper.andNew();
+                wrapper.eq("user_id", getUserId());
+            }
+            return R.ok(cstmrService.selectPage(new Page<>(curr, limit), wrapper));
+        }
     }
 
     private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
@@ -67,7 +94,7 @@
             throw new CoolException("瀹㈡埛宸插瓨鍦�");
         }
         cstmr.setHostId(hostId);
-        cstmr.setUuid(cstmrService.getNextUuid(hostId));  // 瀹㈡埛浠e彿
+        cstmr.setUuid(cstmrService.getUuid(hostId));  // 瀹㈡埛浠e彿
         cstmr.setDeptId(getDeptId());               // 鎵�灞為儴闂�
         cstmr.setUserId(getUserId());               // 鎵�灞炰汉鍛�
 
@@ -138,4 +165,66 @@
         return R.ok();
     }
 
+    /*************************************** 鏁版嵁鐩稿叧 ***********************************************/
+
+    /**
+     * excel瀵煎叆
+     */
+    @PostMapping(value = "/cstmr/excel/import/auth")
+    @ManagerAuth(memo = "鐢叉柟鍗曚綅Excel瀵煎叆")
+    @Transactional
+    public R cstmrExcelImport(MultipartFile file) throws IOException {
+        try (InputStream inStream = file.getInputStream()) {
+            String fileMime = file.getContentType();
+            int excelVersion = 2007;
+            if ("application/vnd.ms-excel".equals(fileMime)) {
+                excelVersion = 2003;
+            }
+            Workbook book = null;
+            if (excelVersion == 2003) {
+                book = new HSSFWorkbook(inStream);
+            }
+            else {  // 褰� excel 鏄� 2007 鏃�
+                book = new XSSFWorkbook(inStream);
+            }
+            Sheet sheet = book.getSheetAt(0);
+            int totalRows = sheet.getPhysicalNumberOfRows() - 1;    // 鎬�
+            Long userId = getUserId();
+            Long hostId = getHostId();
+            Long deptId = getDeptId();
+            Date now = new Date();
+            for (int i = 2; i < totalRows; i++) {
+                Cstmr cstmr = new Cstmr();
+
+                Row row = sheet.getRow(i);
+                System.out.println(row.getCell(0).getStringCellValue());
+
+                cstmr.setHostId(hostId);
+                cstmr.setDeptId(deptId);
+                cstmr.setUserId(userId);
+                cstmr.setStatus(1);
+                cstmr.setCreateBy(userId);
+                cstmr.setCreateTime(now);
+                cstmr.setUpdateBy(userId);
+                cstmr.setUpdateTime(now);
+                if (!cstmrService.insert(cstmr)) {
+                    throw new CoolException("淇濆瓨澶辫触锛岃閲嶆柊瀵煎叆");
+                }
+            }
+        }  catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return R.ok();
+    }
+
+    /**
+     * excel瀵煎嚭
+     */
+    @PostMapping(value = "/cstmr/excel/export/auth")
+    @ManagerAuth
+    public void cstmrExcelExport(HttpServletResponse response) throws IOException {
+
+    }
+
 }

--
Gitblit v1.9.1