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/service/Impl/VwCjScSjTsBbServiceImpl.java | 125 ++++++++++++++++++++++++++++++++++++++---
1 files changed, 115 insertions(+), 10 deletions(-)
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();
+ }
}
--
Gitblit v1.9.3