From ce80b4856af879484f039c3176843e29978b436f Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 07 十一月 2025 11:47:15 +0800
Subject: [PATCH] yys 劳动合同word模板导出
---
src/main/java/com/ruoyi/staff/service/impl/StaffOnJobServiceImpl.java | 80 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/staff/service/impl/StaffOnJobServiceImpl.java b/src/main/java/com/ruoyi/staff/service/impl/StaffOnJobServiceImpl.java
index 9fc8c43..d53cb8e 100644
--- a/src/main/java/com/ruoyi/staff/service/impl/StaffOnJobServiceImpl.java
+++ b/src/main/java/com/ruoyi/staff/service/impl/StaffOnJobServiceImpl.java
@@ -6,19 +6,34 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.dto.WordDateDto;
import com.ruoyi.staff.mapper.StaffJoinLeaveRecordMapper;
import com.ruoyi.staff.mapper.StaffOnJobMapper;
import com.ruoyi.staff.pojo.StaffJoinLeaveRecord;
import com.ruoyi.staff.pojo.StaffOnJob;
import com.ruoyi.staff.service.IStaffJoinLeaveRecordService;
import com.ruoyi.staff.service.IStaffOnJobService;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
import lombok.AllArgsConstructor;
+
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.math.BigDecimal;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
@AllArgsConstructor
@Service
@@ -69,4 +84,69 @@
}
+ @Override
+ public String exportCopy(HttpServletResponse response, StaffOnJob staffOnJob) throws Exception {
+ String url = "/javaWork/product-inventory-management/file/prod/uploads/" + staffOnJob.getStaffName() + "-鍔冲姩鍚堝悓涔�.docx";
+ Configuration cfg = new Configuration(Configuration.VERSION_2_3_32);
+ // 璁剧疆妯℃澘鏂囦欢鎵�鍦ㄧ洰褰曪紙缁濆璺緞锛屼緥濡傦細/templates/锛�
+ cfg.setClassForTemplateLoading(StaffOnJobServiceImpl.class, "/static");
+ cfg.setDefaultEncoding("UTF-8");
+ //2.瀹氫箟闇�瑕佸~鍏呯殑鍙橀噷
+ // 鈶� 鏋勯�犲憳宸ヤ俊鎭紙瀹為檯椤圭洰涓彲浠庢暟鎹簱/Excel璇诲彇锛�
+ WordDateDto staff = new WordDateDto();
+ BeanUtils.copyProperties(staffOnJob, staff);
+ // 閫氳繃鍚堝悓骞撮檺锛屽悎鍚屽埌鏈熸棩鏈熻绠楀悎鍚屽紑濮嬫棩鏈燂紝鍦ㄨ幏鍙栧紑濮嬫棩鏈燂紝缁撴潫鏃ユ湡鐨勫勾鏈堟棩鏁板瓧
+ // 鍚堝悓鍒版湡鏃ユ湡 - 鍚堝悓骞撮檺锛圖ate绫诲瀷锛�
+ // 1. 灏咲ate杞崲涓篒nstant锛堟椂闂存埑锛�
+ Instant instant = staff.getContractExpireTime().toInstant();
+
+ // 涔熷彲浠ユ寚瀹氬叿浣撴椂鍖猴紝渚嬪Asia/Shanghai锛�
+ LocalDate localDate = instant.atZone(ZoneId.of("Asia/Shanghai")).toLocalDate(); // 鍚堝悓缁撴潫鏃堕棿
+ LocalDate localDate1 = localDate.minusYears(Integer.parseInt(staff.getContractTerm()));// 鍚堝悓寮�濮嬫椂闂�
+
+ // 绛捐鏃ユ湡杞崲lcoaldate
+ LocalDate localDate2 = staff.getSignDate().toInstant().atZone(ZoneId.of("Asia/Shanghai")).toLocalDate();
+
+ // 璇曠敤鏃ユ湡杞崲lcoaldate
+ LocalDate localDate3 = staff.getTrialStartDate().toInstant().atZone(ZoneId.of("Asia/Shanghai")).toLocalDate();
+ LocalDate localDate4 = staff.getTrialEndDate().toInstant().atZone(ZoneId.of("Asia/Shanghai")).toLocalDate();
+
+
+ staff.setQyear(localDate2.getYear() + "");
+ staff.setQmoth(localDate2.getMonthValue() + "");
+ staff.setQday(localDate2.getDayOfMonth() + "");
+
+ staff.setSyear(localDate1.getYear() + "");
+ staff.setSmoth(localDate1.getMonthValue() + "");
+ staff.setSday(localDate1.getDayOfMonth() + "");
+ staff.setEyear(localDate.getDayOfMonth() + "");
+ staff.setEmoth(localDate.getDayOfMonth() + "");
+ staff.setEday(localDate.getDayOfMonth() + "");
+
+ staff.setStyear(localDate3.getYear() + "");
+ staff.setStmoth(localDate3.getMonthValue() + "");
+ staff.setStday(localDate3.getDayOfMonth() + "");
+ staff.setSeyear(localDate4.getYear() + "");
+ staff.setSemoth(localDate4.getMonthValue() + "");
+ staff.setSeday(localDate4.getDayOfMonth() + "");
+
+ Map<String,Object> data = new HashMap<>();
+ data.put("item",staff);
+ //3.鍔犺浇XML 妯℃澘
+ Template template = cfg.getTemplate("鍔冲姩鍚堝悓涔�.xml");
+ //4.鐢熸垚濉厖鍚庣殑 XML 鍐呭
+ StringWriter out = new StringWriter();
+ template.process(data, out);
+ String filledXml = out.toString();
+ //5.灏哫ML鍐呭鍐欏叆浜や欢骞舵敼涓�.docx 鏍煎紡
+ File outputFile = new File(url);
+ try(FileOutputStream fos = new FileOutputStream(outputFile);
+ OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
+ osw.write(filledXml);
+ }
+ return url;
+ }
+
+
+
}
--
Gitblit v1.9.3