金蝶资产卡片

This commit is contained in:
tzy 2025-09-14 20:35:15 +08:00
parent 0c2b53478d
commit 16853a9dc9

View File

@ -24,6 +24,10 @@ import com.google.gson.JsonObject;
import com.kingdee.bos.webapi.sdk.K3CloudApi;
import com.ruoyi.common.utils.HttpRequestUtil;
import com.ruoyi.common.utils.WxRobotUtil;
import com.ruoyi.common.utils.file.SmbUtil;
import com.ruoyi.common.poi.ExcelTemplateProc;
import com.ruoyi.common.poi.DynamicDataMapping;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.system.domain.SafetyStock;
import com.ruoyi.system.domain.WlStockData;
import com.ruoyi.system.domain.dto.*;
@ -846,40 +850,49 @@ public class KingdeeWorkCenterDataController extends BaseController {
.append("更新时间:").append(currentTime).append("\n\n")
.append("🔧 订单数据统计:\n");
// 获取并统计每个工段的数据
for (String workCenter : workCenters) {
try {
R<List<KingdeeWorkCenterDataBo>> result = getKingdeeDelayData(workCenter);
if (R.isError(result) || CollUtil.isEmpty(result.getData())) {
msg.append("- ").append(workCenter).append(" (无数据)\n");
continue;
}
// 获取采购订单和采购申请数据
List<PurchaseOrderExcelDTO> purchaseOrderList = JdUtil.getPurchaseOrder();
List<PurchaseRequestExcelDTO> purchaseRequestList = JdUtil.getPurchaseRequestOrder();
msg.append("- 采购订单:").append(purchaseOrderList.size()).append("\n");
msg.append("- 采购申请:").append(purchaseRequestList.size()).append("\n");
List<KingdeeWorkCenterDataBo> dataList = result.getData();
msg.append("- ").append(workCenter).append(" (共").append(dataList.size()).append("条数据)\n");
// 生成Excel文件使用采购模板
String fileName = String.format("采购订单和申请数据_%s.xlsx",
DateUtil.format(new Date(), "yyyyMMddHHmmss"));
String filePath = FileUtils.getTempDirectoryPath() + File.separator + fileName;
// 生成Excel文件
String fileName = String.format("%s生产延期数据_%s.xlsx", workCenter,
DateUtil.format(new Date(), "yyyyMMddHHmmss"));
String filePath = FileUtils.getTempDirectoryPath() + File.separator + fileName;
// 准备模板数据
Map<String, Object> staticDataMap = new HashMap<>();
staticDataMap.put("currentTime", DateUtil.format(new Date(), "yyyy年MM月dd日 HH:mm:ss"));
staticDataMap.put("purchaseOrderCount", purchaseOrderList.size());
staticDataMap.put("purchaseRequestCount", purchaseRequestList.size());
// 使用EasyExcel写入数据
EasyExcel.write(filePath, KingdeeWorkCenterDataVo.class)
.sheet("工段数据")
.doWrite(BeanUtil.copyToList(dataList, KingdeeWorkCenterDataVo.class));
// 发送Excel文件
File excelFile = new File(filePath);
wxRobotUtil.sendFileToWeChatGroup(excelFile, robotId);
// 删除临时文件
FileUtils.deleteQuietly(excelFile);
} catch (Exception e) {
log.error("获取工段{}数据失败", workCenter, e);
msg.append("- ").append(workCenter).append(" (获取失败: ").append(e.getMessage()).append(")\n");
}
List<DynamicDataMapping> dynamicDataMappingList = new ArrayList<>();
// 添加采购订单数据
if (!purchaseOrderList.isEmpty()) {
List<Map<String, Object>> orderDataList = convertPurchaseOrderToMapList(purchaseOrderList);
dynamicDataMappingList.addAll(DynamicDataMapping.createOneDataList("PurchaseOrder", orderDataList));
}
// 添加采购申请数据
if (!purchaseRequestList.isEmpty()) {
List<Map<String, Object>> requestDataList = convertPurchaseRequestToMapList(purchaseRequestList);
dynamicDataMappingList.addAll(DynamicDataMapping.createOneDataList("PurchaseRequest", requestDataList));
}
// 使用采购模板生成Excel
String templatePath = "EXCEL模板/采购订单模板.xlsx";
ExcelTemplateProc.doExportExcelByTemplateProc(templatePath, filePath, staticDataMap, dynamicDataMappingList);
// 发送Excel文件
File excelFile = new File(filePath);
if (excelFile.exists()) {
wxRobotUtil.sendFileToWeChatGroup(excelFile, robotId);
FileUtils.deleteQuietly(excelFile);
}
msg.append("\n详细数据请查看发送的Excel文件");
wxRobotUtil.sendMsgToWeChatGroup(msg.toString(), robotId, true); // @所有人
@ -892,6 +905,53 @@ public class KingdeeWorkCenterDataController extends BaseController {
}
}
/**
* 转换采购订单数据为Map列表
*/
private List<Map<String, Object>> convertPurchaseOrderToMapList(List<PurchaseOrderExcelDTO> purchaseOrderList) {
List<Map<String, Object>> mapList = new ArrayList<>();
int index = 1;
for (PurchaseOrderExcelDTO item : purchaseOrderList) {
Map<String, Object> map = new HashMap<>();
map.put("index", index);
map.put("orderNo", item.getFBillNo());
map.put("supplierName", item.getFSupplierIdFName());
map.put("materialCode", item.getFMaterialIdFNumber());
map.put("materialName", item.getFMaterialName());
map.put("quantity", item.getFQty());
map.put("orderDate", item.getFDate());
map.put("deliveryDate", item.getFDeliveryDate());
map.put("productionOrderNo", item.getFUCHNText2());
mapList.add(map);
index++;
}
return mapList;
}
/**
* 转换采购申请数据为Map列表
*/
private List<Map<String, Object>> convertPurchaseRequestToMapList(List<PurchaseRequestExcelDTO> purchaseRequestList) {
List<Map<String, Object>> mapList = new ArrayList<>();
int index = 1;
for (PurchaseRequestExcelDTO item : purchaseRequestList) {
Map<String, Object> map = new HashMap<>();
map.put("index", index);
map.put("requestNo", item.getFBillNo());
map.put("billType", item.getFBillTypeID());
map.put("suggestPurDate", item.getFSuggestPurDate());
map.put("suggestSupplier", item.getFSuggestSupplierId_FName());
map.put("materialCode", item.getFMaterialId_FNumber());
map.put("materialName", item.getFMaterialName());
map.put("priceUnit", item.getFPriceUnitId_FName());
map.put("quantity", item.getFReqQty());
map.put("arrivalDate", item.getFArrivalDate());
map.put("applicationDate", item.getFApplicationDate());
map.put("productionOrderNo", item.getFUCHNText());
mapList.add(map);
index++;
}
return mapList;
}
}