From e84eb88617326313e9f4543a2220a68e8f119dce Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期三, 12 十一月 2025 17:38:54 +0800
Subject: [PATCH] 更新钉钉配置

---
 src/main/java/com/gs/xky/entity/VwCjScSjTsBb.java                  |  142 ++++++++++-------------
 src/main/java/com/gs/xky/service/VwCjScSjTsBbService.java          |   16 +
 src/main/java/com/gs/xky/service/Impl/VwCjScSjTsBbServiceImpl.java |  125 +++++++++++++++++++-
 pom.xml                                                            |    7 +
 src/test/java/com/gs/xky/XkyApplicationTests.java                  |   29 ++++
 5 files changed, 226 insertions(+), 93 deletions(-)

diff --git a/pom.xml b/pom.xml
index f9b3e16..8d554bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -96,6 +96,13 @@
             <artifactId>hutool-all</artifactId>
             <version>5.8.18</version>
         </dependency>
+
+        <!-- Apache POI for Excel (required by Hutool) -->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>5.2.3</version>
+        </dependency>
     </dependencies>
 
     <build>
diff --git a/src/main/java/com/gs/xky/entity/VwCjScSjTsBb.java b/src/main/java/com/gs/xky/entity/VwCjScSjTsBb.java
index f12a947..1e1c7d2 100644
--- a/src/main/java/com/gs/xky/entity/VwCjScSjTsBb.java
+++ b/src/main/java/com/gs/xky/entity/VwCjScSjTsBb.java
@@ -2,91 +2,77 @@
 
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableName;
-import java.io.Serializable;
 import lombok.Data;
 
+import java.io.Serializable;
+
 /**
- * 
+ *
  * @TableName VW_CJ_SC_SJ_TS_BB
  */
-@TableName(value ="VW_CJ_SC_SJ_TS_BB")
+@TableName(value = "VW_CJ_SC_SJ_TS_BB")
 @Data
 public class VwCjScSjTsBb implements Serializable {
-    /**
-     * 
-     */
-    private Object itemName;
-
-    /**
-     * 
-     */
-    private Object itemNo;
-
-    /**
-     * 
-     */
-    private Object departmentname;
-
-    /**
-     * 
-     */
-    private Object departmentcode;
-
-    /**
-     * 
-     */
-    private Object daa001;
-
-    /**
-     * 
-     */
-    private Object lineName;
-
-    /**
-     * 
-     */
-    private Object lineNo;
-
-    /**
-     * 
-     */
-    private Object daa008;
-
-    /**
-     * 
-     */
-    private Object yjkg;
-
-    /**
-     * 
-     */
-    private Object sjkg;
-
-    /**
-     * 
-     */
-    private Object sq;
-
-    /**
-     * 
-     */
-    private Object rk;
-
-    /**
-     * 
-     */
-    private Object sqwwg;
-
-    /**
-     * 
-     */
-    private Object rkwwg;
-
-    /**
-     * 
-     */
-    private Object sqwrk;
-
     @TableField(exist = false)
     private static final long serialVersionUID = 1L;
+    /**
+     * 鐗╂枡鍚嶇О
+     */
+    private String itemName;
+    /**
+     * 鐗╂枡缂栫爜
+     */
+    private String itemNo;
+    /**
+     * 杞﹂棿鍚嶇О
+     */
+    private String departmentname;
+    /**
+     * 杞﹂棿缂栫爜
+     */
+    private String departmentcode;
+    /**
+     * 宸ュ崟鍙�
+     */
+    private String daa001;
+    /**
+     * 绾夸綋鍚嶇О
+     */
+    private String lineName;
+    /**
+     * 绾夸綋缂栫爜
+     */
+    private String lineNo;
+    /**
+     * 宸ュ崟鏁伴噺
+     */
+    private String daa008;
+    /**
+     * 棰勮寮�宸�
+     */
+    private String yjkg;
+    /**
+     * 瀹為檯寮�宸�
+     */
+    private String sjkg;
+    /**
+     * 鐢宠鍏ュ簱鏁�
+     */
+    private String sq;
+    /**
+     * 鍏ュ簱
+     */
+    private String rk;
+    /**
+     * 鐢宠鏈畬宸ユ暟
+     */
+    private String sqwwg;
+    /**
+     * 鍏ュ簱鏈畬宸�
+     */
+    private String rkwwg;
+    /**
+     * 鐢宠鏈叆搴�
+     */
+    private String sqwrk;
 }
\ No newline at end of file
diff --git a/src/main/java/com/gs/xky/service/Impl/VwCjScSjTsBbServiceImpl.java b/src/main/java/com/gs/xky/service/Impl/VwCjScSjTsBbServiceImpl.java
index 142533b..fe5f79b 100644
--- a/src/main/java/com/gs/xky/service/Impl/VwCjScSjTsBbServiceImpl.java
+++ b/src/main/java/com/gs/xky/service/Impl/VwCjScSjTsBbServiceImpl.java
@@ -1,20 +1,125 @@
 package com.gs.xky.service.Impl;
 
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import generator.domain.VwCjScSjTsBb;
-import com.gs.xky.service.VwCjScSjTsBbService;
+import com.gs.xky.entity.VwCjScSjTsBb;
 import com.gs.xky.mapper.VwCjScSjTsBbMapper;
+import com.gs.xky.service.DingtalkInfoService;
+import com.gs.xky.service.VwCjScSjTsBbService;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
-/**
-* @author Administrator
-* @description 閽堝琛ㄣ�怴W_CJ_SC_SJ_TS_BB銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
-* @createDate 2025-11-12 16:42:06
-*/
-@Service
-public class VwCjScSjTsBbServiceImpl extends ServiceImpl<VwCjScSjTsBbMapper, VwCjScSjTsBb>
-    implements VwCjScSjTsBbService{
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
 
+/**
+ * @author Administrator
+ * @description 閽堝琛ㄣ�怴W_CJ_SC_SJ_TS_BB銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
+ * @createDate 2025-11-12 16:42:06
+ */
+@Service
+@Slf4j
+@RequiredArgsConstructor
+public class VwCjScSjTsBbServiceImpl extends ServiceImpl<VwCjScSjTsBbMapper, VwCjScSjTsBb>
+        implements VwCjScSjTsBbService {
+
+    private final DingtalkInfoService dingtalkInfoService;
+
+    @Override
+    public boolean exportAndSendToDingtalk() throws Exception {
+        String exportFilePath = null;
+        try {
+            // 1. 鏌ヨ鎵�鏈夋暟鎹�
+            log.info("寮�濮嬫煡璇㈢敓浜ф暟鎹�...");
+            List<VwCjScSjTsBb> dataList = list();
+
+            if (dataList == null || dataList.isEmpty()) {
+                log.warn("娌℃湁鏁版嵁闇�瑕佸鍑�");
+                return false;
+            }
+
+            log.info("鏌ヨ鍒� {} 鏉℃暟鎹�", dataList.size());
+
+            // 2. 鍑嗗瀵煎嚭鏂囦欢璺緞
+            String timestamp = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
+            String fileName = "鐢熶骇鏁版嵁鎶ヨ〃_" + timestamp + ".xlsx";
+            exportFilePath = "D:\\BIFile\\" + fileName;
+
+            // 纭繚鐩綍瀛樺湪
+            FileUtil.mkdir("D:\\BIFile");
+
+            // 3. 瀵煎嚭鍒癊xcel
+            log.info("寮�濮嬪鍑篍xcel鏂囦欢: {}", exportFilePath);
+            exportToExcel(dataList, exportFilePath);
+            log.info("Excel鏂囦欢瀵煎嚭鎴愬姛");
+
+            // 4. 鍙戦�侀拤閽夋秷鎭�
+            log.info("寮�濮嬪彂閫侀拤閽夋枃浠舵秷鎭�...");
+            boolean sendResult = dingtalkInfoService.sendFileMessage(exportFilePath);
+
+            if (sendResult) {
+                log.info("閽夐拤鏂囦欢娑堟伅鍙戦�佹垚鍔�");
+            } else {
+                log.warn("閽夐拤鏂囦欢娑堟伅鍙戦�佸け璐�");
+            }
+
+            return sendResult;
+
+        } catch (Exception e) {
+            log.error("瀵煎嚭骞跺彂閫佸け璐�", e);
+            throw e;
+        } finally {
+            // 鍙�夛細鍙戦�佸悗鍒犻櫎涓存椂鏂囦欢
+            // if (exportFilePath != null && FileUtil.exist(exportFilePath)) {
+            //     FileUtil.del(exportFilePath);
+            //     log.info("涓存椂鏂囦欢宸插垹闄�: {}", exportFilePath);
+            // }
+        }
+    }
+
+    /**
+     * 瀵煎嚭鏁版嵁鍒癊xcel
+     *
+     * @param dataList 鏁版嵁鍒楄〃
+     * @param filePath 鏂囦欢璺緞
+     */
+    private void exportToExcel(List<VwCjScSjTsBb> dataList, String filePath) {
+        // 鍒涘缓Excel鍐欏叆鍣�
+        ExcelWriter writer = ExcelUtil.getWriter(filePath);
+
+        // 璁剧疆琛ㄥご鍒悕锛堜腑鏂囧垪鍚嶏級
+        writer.addHeaderAlias("itemName", "鐗╂枡鍚嶇О");
+        writer.addHeaderAlias("itemNo", "鐗╂枡缂栫爜");
+        writer.addHeaderAlias("departmentname", "杞﹂棿鍚嶇О");
+        writer.addHeaderAlias("departmentcode", "杞﹂棿缂栫爜");
+        writer.addHeaderAlias("daa001", "宸ュ崟鍙�");
+        writer.addHeaderAlias("lineName", "绾夸綋鍚嶇О");
+        writer.addHeaderAlias("lineNo", "绾夸綋缂栫爜");
+        writer.addHeaderAlias("daa008", "宸ュ崟鏁伴噺");
+        writer.addHeaderAlias("yjkg", "棰勮寮�宸�");
+        writer.addHeaderAlias("sjkg", "瀹為檯寮�宸�");
+        writer.addHeaderAlias("sq", "鐢宠鍏ュ簱鏁�");
+        writer.addHeaderAlias("rk", "鍏ュ簱鏁�");
+        writer.addHeaderAlias("sqwwg", "鐢宠鏈畬宸ユ暟");
+        writer.addHeaderAlias("rkwwg", "鍏ュ簱鏈畬宸�");
+        writer.addHeaderAlias("sqwrk", "鐢宠鏈叆搴�");
+
+        // 鍚堝苟鍗曞厓鏍煎悗鏍囬琛�
+        writer.merge(14, "杞﹂棿鐢熶骇鏁版嵁缁熻鎶ヨ〃");
+
+        // 鍐欏叆鏁版嵁锛岄粯璁や細浣跨敤鍒悕浣滀负琛ㄥご
+        writer.write(dataList, true);
+
+        // 璁剧疆鍒楀鑷�傚簲
+        writer.autoSizeColumnAll();
+
+        // 鍏抽棴writer锛岄噴鏀惧唴瀛�
+        writer.close();
+    }
 }
 
 
diff --git a/src/main/java/com/gs/xky/service/VwCjScSjTsBbService.java b/src/main/java/com/gs/xky/service/VwCjScSjTsBbService.java
index 0997297..3047a94 100644
--- a/src/main/java/com/gs/xky/service/VwCjScSjTsBbService.java
+++ b/src/main/java/com/gs/xky/service/VwCjScSjTsBbService.java
@@ -1,13 +1,19 @@
 package com.gs.xky.service;
 
-import generator.domain.VwCjScSjTsBb;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.gs.xky.entity.VwCjScSjTsBb;
 
 /**
-* @author Administrator
-* @description 閽堝琛ㄣ�怴W_CJ_SC_SJ_TS_BB銆戠殑鏁版嵁搴撴搷浣淪ervice
-* @createDate 2025-11-12 16:42:06
-*/
+ * @author Administrator
+ * @description 閽堝琛ㄣ�怴W_CJ_SC_SJ_TS_BB銆戠殑鏁版嵁搴撴搷浣淪ervice
+ * @createDate 2025-11-12 16:42:06
+ */
 public interface VwCjScSjTsBbService extends IService<VwCjScSjTsBb> {
 
+    /**
+     * 瀵煎嚭鏁版嵁鍒癊xcel骞跺彂閫侀拤閽夋秷鎭�
+     *
+     * @return 鏄惁鎴愬姛
+     */
+    boolean exportAndSendToDingtalk() throws Exception;
 }
diff --git a/src/test/java/com/gs/xky/XkyApplicationTests.java b/src/test/java/com/gs/xky/XkyApplicationTests.java
index 1a699b8..9b398de 100644
--- a/src/test/java/com/gs/xky/XkyApplicationTests.java
+++ b/src/test/java/com/gs/xky/XkyApplicationTests.java
@@ -41,6 +41,8 @@
     private PurchaseService service;
     @Autowired
     private DingtalkInfoService dingtalkInfoService;
+    @Autowired
+    private VwCjScSjTsBbService vwCjScSjTsBbService;
 
     @Test
     void contextLoads() throws IOException {
@@ -217,4 +219,31 @@
 
         System.out.println("=== 娴嬭瘯缁撴潫 ===");
     }
+
+    /**
+     * 娴嬭瘯瀵煎嚭鐢熶骇鏁版嵁骞跺彂閫侀拤閽夋秷鎭�
+     * 鍔熻兘锛氭煡璇W_CJ_SC_SJ_TS_BB琛ㄦ暟鎹� -> 瀵煎嚭Excel -> 鍙戦�侀拤閽夋枃浠舵秷鎭�
+     */
+    @Test
+    void testExportAndSendProductionData() throws Exception {
+        System.out.println("=== 寮�濮嬫祴璇曞鍑虹敓浜ф暟鎹苟鍙戦�侀拤閽� ===");
+
+        try {
+            boolean result = vwCjScSjTsBbService.exportAndSendToDingtalk();
+
+            if (result) {
+                System.out.println("鉁� 鐢熶骇鏁版嵁瀵煎嚭骞跺彂閫佹垚鍔�");
+                System.out.println("  - 鏁版嵁宸蹭粠 VW_CJ_SC_SJ_TS_BB 琛ㄦ煡璇�");
+                System.out.println("  - Excel 鏂囦欢宸茬敓鎴愬苟淇濆瓨鍒� D:\\BIFile\\");
+                System.out.println("  - 閽夐拤鏂囦欢娑堟伅宸插彂閫�");
+            } else {
+                System.out.println("鉁� 鐢熶骇鏁版嵁瀵煎嚭鎴栧彂閫佸け璐�");
+            }
+        } catch (Exception e) {
+            System.out.println("鉁� 瀵煎嚭骞跺彂閫佹椂鍙戠敓寮傚父: " + e.getMessage());
+            e.printStackTrace();
+        }
+
+        System.out.println("=== 娴嬭瘯缁撴潫 ===");
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3