From c924d59a94fc17d570610cbf2b691481dd0b2e4d Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期五, 16 一月 2026 17:50:09 +0800
Subject: [PATCH] Merge branch 'dev_New' of http://114.132.189.42:9002/r/product-inventory-management-after into dev_New
---
src/main/java/com/ruoyi/staff/service/impl/StaffOnJobServiceImpl.java | 215 +++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 204 insertions(+), 11 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 8aaa840..69e0638 100644
--- a/src/main/java/com/ruoyi/staff/service/impl/StaffOnJobServiceImpl.java
+++ b/src/main/java/com/ruoyi/staff/service/impl/StaffOnJobServiceImpl.java
@@ -1,23 +1,44 @@
package com.ruoyi.staff.service.impl;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.dto.WordDateDto;
+import com.ruoyi.project.system.domain.SysPost;
+import com.ruoyi.project.system.mapper.SysPostMapper;
+import com.ruoyi.staff.dto.StaffOnJobDto;
+import com.ruoyi.staff.mapper.StaffContractMapper;
import com.ruoyi.staff.mapper.StaffJoinLeaveRecordMapper;
+import com.ruoyi.staff.mapper.StaffLeaveMapper;
import com.ruoyi.staff.mapper.StaffOnJobMapper;
+import com.ruoyi.staff.pojo.StaffContract;
import com.ruoyi.staff.pojo.StaffJoinLeaveRecord;
+import com.ruoyi.staff.pojo.StaffLeave;
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 lombok.AllArgsConstructor;
-import org.springframework.stereotype.Service;
-import javax.annotation.Resource;
+import org.springframework.beans.BeanUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
+
import javax.servlet.http.HttpServletResponse;
-import java.util.List;
+import java.io.*;
+import java.nio.charset.StandardCharsets;
+import java.time.Instant;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.util.*;
+
+import static com.ruoyi.common.enums.StaffJoinLeaveRecordDimissionReason.StaffJoinLeaveRecordDimissionReasonOther;
@AllArgsConstructor
@Service
@@ -26,27 +47,106 @@
private StaffOnJobMapper staffOnJobMapper;
+ private SysPostMapper sysPostMapper;
+
private StaffJoinLeaveRecordMapper staffJoinLeaveRecordMapper;
+ private StaffContractMapper staffContractMapper;
+ private StaffLeaveMapper staffLeaveMapper;
+
//鍦ㄨ亴鍛樺伐鍙拌处鍒嗛〉鏌ヨ
@Override
- public IPage<StaffOnJob> staffOnJobListPage(Page page, StaffOnJob staffOnJob) {
+ public IPage<StaffOnJobDto> staffOnJobListPage(Page page, StaffOnJob staffOnJob) {
return staffOnJobMapper.staffOnJobListPage(page,staffOnJob);
+ }
+
+ //鏂板鍏ヨ亴
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int add(StaffOnJobDto staffOnJobPrams) {
+ String[] ignoreProperties = {"id"};//鎺掗櫎id灞炴��
+ // 鍒ゆ柇缂栧彿鏄惁瀛樺湪
+ List<StaffOnJob> staffOnJobs = staffOnJobMapper.selectList(Wrappers.<StaffOnJob>lambdaQuery().eq(StaffOnJob::getStaffNo, staffOnJobPrams.getStaffNo()));
+ if (staffOnJobs.size()>0){
+ throw new BaseException("缂栧彿涓�"+staffOnJobPrams.getStaffNo()+"鐨勫憳宸ュ凡缁忓瓨鍦�,鏃犳硶鏂板!!!");
+ }
+ // 鍒涘缓鍏ヨ亴鏁版嵁
+ staffOnJobMapper.insert(staffOnJobPrams);
+
+ // 鍒涘缓鍚堝悓璁板綍
+ StaffContract staffContract = new StaffContract();
+ staffContract.setStaffOnJobId(staffOnJobPrams.getId());
+ staffContract.setContractTerm(staffOnJobPrams.getContractTerm());
+ staffContract.setContractStartTime(staffOnJobPrams.getContractStartTime());
+ staffContract.setContractEndTime(staffOnJobPrams.getContractEndTime());
+ return staffContractMapper.insert(staffContract);
+ }
+
+ //鏇存柊鍏ヨ亴淇℃伅
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int update(Long id, StaffOnJobDto staffOnJobParams) {
+ // 鍒ゆ柇瀵硅薄鏄惁瀛樺湪
+ StaffOnJob job = staffOnJobMapper.selectById(id);
+ if (job == null){
+ throw new BaseException("缂栧彿涓�"+staffOnJobParams.getStaffNo()+"鐨勫憳宸ヤ笉瀛樺湪,鏃犳硶鏇存柊!!!");
+ }
+
+ // 鏇存柊鍛樺伐鏁版嵁
+ String[] ignoreProperties = {"id"};//鎺掗櫎id灞炴��
+ BeanUtils.copyProperties(staffOnJobParams,job,ignoreProperties);
+ staffOnJobMapper.updateById(job);
+
+ // 鑾峰彇鏈�鏂板悎鍚屾暟鎹紝骞朵笖鏇存柊
+ StaffContract contract = staffContractMapper.selectOne(Wrappers.<StaffContract>lambdaQuery()
+ .eq(StaffContract::getStaffOnJobId, id)
+ .orderByDesc(StaffContract::getId));
+ if (contract != null){
+ BeanUtils.copyProperties(staffOnJobParams,contract,ignoreProperties);
+ return staffContractMapper.updateById(contract);
+ }
+ return 0;
+ }
+
+ //鍒犻櫎鍏ヨ亴
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public int delStaffOnJobs(List<Integer> ids) {
+ // 鍒犻櫎鍏ヨ亴鏁版嵁
+ staffOnJobMapper.deleteBatchIds(ids);
+ // 鍒犻櫎绂昏亴鏁版嵁
+ staffLeaveMapper.delete(Wrappers.<StaffLeave>lambdaQuery().in(StaffLeave::getStaffOnJobId, ids));
+ // 鍒犻櫎鍚堝悓鏁版嵁
+ return staffContractMapper.delete(Wrappers.<StaffContract>lambdaQuery().in(StaffContract::getStaffOnJobId, ids));
}
//鍦ㄨ亴鍛樺伐璇︽儏
@Override
- public List<StaffJoinLeaveRecord> staffOnJobDetail(String staffNo) {
- return staffJoinLeaveRecordMapper.selectList(Wrappers.<StaffJoinLeaveRecord>lambdaQuery()
- .eq(StaffJoinLeaveRecord::getStaffState,1)
- .eq(StaffJoinLeaveRecord::getStaffNo,staffNo));
+ public StaffOnJobDto staffOnJobDetail(Long id) {
+ StaffOnJob staffOnJob = staffOnJobMapper.selectById(id);
+ StaffOnJobDto staffOnJobDto = new StaffOnJobDto();
+ BeanUtils.copyProperties(staffOnJob, staffOnJobDto);
+ // 鏌ヨ宀椾綅鍚嶇О
+ SysPost post = sysPostMapper.selectPostById((long) staffOnJob.getSysPostId());
+ staffOnJobDto.setPostName(post.getPostName());
+
+ // 鏌ヨ鍚堝悓淇℃伅
+ StaffContract contract = staffContractMapper.selectOne(Wrappers.<StaffContract>lambdaQuery()
+ .eq(StaffContract::getStaffOnJobId, staffOnJob.getId())
+ .orderByDesc(StaffContract::getId));
+ if (contract != null){
+ staffOnJobDto.setContractTerm(contract.getContractTerm());
+ staffOnJobDto.setContractStartTime(contract.getContractStartTime());
+ staffOnJobDto.setContractEndTime(contract.getContractEndTime());
+ }
+ return staffOnJobDto;
}
//鍦ㄨ亴鍛樺伐瀵煎嚭
@Override
public void staffOnJobExport(HttpServletResponse response, StaffOnJob staffOnJob) {
- List<StaffOnJob> staffOnJobs = staffOnJobMapper.staffOnJobList(staffOnJob);
- ExcelUtil<StaffOnJob> util = new ExcelUtil<StaffOnJob>(StaffOnJob.class);
+ List<StaffOnJobDto> staffOnJobs = staffOnJobMapper.staffOnJobList(staffOnJob);
+ ExcelUtil<StaffOnJobDto> util = new ExcelUtil<StaffOnJobDto>(StaffOnJobDto.class);
util.exportExcel(response, staffOnJobs, "鍦ㄨ亴鍛樺伐鍙拌处瀵煎嚭");
}
@@ -55,5 +155,98 @@
return staffJoinLeaveRecordMapper.staffOnJobList();
}
+ @Override
+ public Boolean importData(MultipartFile file) {
+ try {
+ ExcelUtil<StaffOnJob> util = new ExcelUtil<>(StaffOnJob.class);
+ List<StaffOnJob> staffOnJobs = util.importExcel(file.getInputStream());
+ return saveOrUpdateBatch(staffOnJobs);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return false;
+ }
+ }
+
+
+ @Override
+ public String exportCopy(HttpServletResponse response, StaffOnJob staffOnJob) throws Exception {
+ String url = "/javaWork/product-inventory-management/file/prod/" + 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() + "");
+ if(staff.getDateSelect().equals("A")){
+ 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() + "");
+ }else if (staff.getDateSelect().equals("B")){
+
+ staff.setBsyear(localDate1.getYear() + "");
+ staff.setBsmoth(localDate1.getMonthValue() + "");
+ staff.setBsday(localDate1.getDayOfMonth() + "");
+
+ staff.setBstyear(localDate3.getYear() + "");
+ staff.setBstmoth(localDate3.getMonthValue() + "");
+ staff.setBstday(localDate3.getDayOfMonth() + "");
+ staff.setBseyear(localDate4.getYear() + "");
+ staff.setBsemoth(localDate4.getMonthValue() + "");
+ staff.setBseday(localDate4.getDayOfMonth() + "");
+ }else if (staff.getDateSelect().equals("C")){
+ staff.setCsyear(localDate1.getYear() + "");
+ staff.setCsmoth(localDate1.getMonthValue() + "");
+ staff.setCsday(localDate1.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