|
@@ -3,19 +3,12 @@
|
|
|
*/
|
|
*/
|
|
|
package com.jeeplus.modules.workstaff.service;
|
|
package com.jeeplus.modules.workstaff.service;
|
|
|
|
|
|
|
|
-import java.io.InputStream;
|
|
|
|
|
-import java.lang.reflect.Field;
|
|
|
|
|
-import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
-import java.lang.reflect.Method;
|
|
|
|
|
-import java.text.ParseException;
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
|
-import java.util.*;
|
|
|
|
|
-
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Maps;
|
|
|
-import com.jeeplus.common.bos.BOSClientUtil;
|
|
|
|
|
import com.jeeplus.common.config.Global;
|
|
import com.jeeplus.common.config.Global;
|
|
|
import com.jeeplus.common.oss.OSSClientUtil;
|
|
import com.jeeplus.common.oss.OSSClientUtil;
|
|
|
|
|
+import com.jeeplus.common.persistence.Page;
|
|
|
|
|
+import com.jeeplus.common.service.CrudService;
|
|
|
import com.jeeplus.common.utils.DateUtils;
|
|
import com.jeeplus.common.utils.DateUtils;
|
|
|
import com.jeeplus.common.utils.IdGen;
|
|
import com.jeeplus.common.utils.IdGen;
|
|
|
import com.jeeplus.common.utils.StringUtils;
|
|
import com.jeeplus.common.utils.StringUtils;
|
|
@@ -25,18 +18,27 @@ import com.jeeplus.modules.sys.entity.User;
|
|
|
import com.jeeplus.modules.sys.service.WorkattachmentService;
|
|
import com.jeeplus.modules.sys.service.WorkattachmentService;
|
|
|
import com.jeeplus.modules.sys.utils.DictUtils;
|
|
import com.jeeplus.modules.sys.utils.DictUtils;
|
|
|
import com.jeeplus.modules.workstaff.dao.WorkStaffBasicInfoDao;
|
|
import com.jeeplus.modules.workstaff.dao.WorkStaffBasicInfoDao;
|
|
|
-import com.jeeplus.modules.workstaff.entity.*;
|
|
|
|
|
|
|
+import com.jeeplus.modules.workstaff.dao.WorkStaffCertificateDao;
|
|
|
|
|
+import com.jeeplus.modules.workstaff.entity.WorkStaffBasicInfo;
|
|
|
|
|
+import com.jeeplus.modules.workstaff.entity.WorkStaffCertificate;
|
|
|
|
|
+import com.jeeplus.modules.workstaff.entity.WorkStaffCertificateImport;
|
|
|
|
|
+import com.jeeplus.modules.workstaff.utils.PdfSignUtil;
|
|
|
import com.jeeplus.modules.workstaffachiveslog.entity.WorkStaffAchivesLog;
|
|
import com.jeeplus.modules.workstaffachiveslog.entity.WorkStaffAchivesLog;
|
|
|
import com.jeeplus.modules.workstaffachiveslog.service.WorkStaffAchivesLogService;
|
|
import com.jeeplus.modules.workstaffachiveslog.service.WorkStaffAchivesLogService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.mock.web.MockMultipartFile;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
|
|
-import com.jeeplus.common.persistence.Page;
|
|
|
|
|
-import com.jeeplus.common.service.CrudService;
|
|
|
|
|
-import com.jeeplus.modules.workstaff.dao.WorkStaffCertificateDao;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
|
|
|
|
+import java.io.*;
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
|
|
+import java.text.ParseException;
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 执业资格证书Service
|
|
* 执业资格证书Service
|
|
|
* @author ssrh
|
|
* @author ssrh
|
|
@@ -132,11 +134,106 @@ public class WorkStaffCertificateService extends CrudService<WorkStaffCertificat
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
if(entity!=null){
|
|
if(entity!=null){
|
|
|
- if(entity.getFile()!=null&&!entity.getFile().isEmpty()&&entity.getFile().getSize()>0){
|
|
|
|
|
- MultipartFile file = entity.getFile();
|
|
|
|
|
- entity.setFileName(file.getOriginalFilename());
|
|
|
|
|
- entity.setFilePath(this.uploadFile(file,entity.getFilePath()));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 先处理文件上传(按系统区分路径,临时存储)
|
|
|
|
|
+ String staffId = workStaffBasicInfo.getId();
|
|
|
|
|
+ MultipartFile file = entity.getFile();
|
|
|
|
|
+
|
|
|
|
|
+ // 临时文件路径(用于try中处理,处理完自动删除)
|
|
|
|
|
+ String tempFilePath = null;
|
|
|
|
|
+
|
|
|
|
|
+ if (file != null && !file.isEmpty() && file.getSize() > 0) {
|
|
|
|
|
+
|
|
|
|
|
+ String name = entity.getName();
|
|
|
|
|
+ // 生成临时文件名(避免重名)
|
|
|
|
|
+ String originalFileName = file.getOriginalFilename();
|
|
|
|
|
+ String basePath = "";
|
|
|
|
|
+ try {
|
|
|
|
|
+ if ("161".equals(name)
|
|
|
|
|
+ && StringUtils.isNotBlank(originalFileName)
|
|
|
|
|
+ && originalFileName.toLowerCase().endsWith(".pdf")) {
|
|
|
|
|
+ // -------------------------- 1. 按系统生成临时存储路径 --------------------------
|
|
|
|
|
+ String os = System.getProperty("os.name").toLowerCase();
|
|
|
|
|
+ if (os.contains("win")) {
|
|
|
|
|
+ // Windows系统:D盘根目录
|
|
|
|
|
+ basePath = "D:/attachment-file/staffCertificate/" + staffId + "/";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Linux系统:根目录
|
|
|
|
|
+ basePath = "/attachment-file/staffCertificate/" + staffId + "/";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 确保目录存在,不存在则自动创建
|
|
|
|
|
+ File dir = new File(basePath);
|
|
|
|
|
+ if (!dir.exists()) {
|
|
|
|
|
+ dir.mkdirs();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String tempFileName = System.currentTimeMillis() + "_" + originalFileName;
|
|
|
|
|
+ tempFilePath = basePath + tempFileName;
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 将上传的文件保存到临时路径
|
|
|
|
|
+ File tempFile = new File(tempFilePath);
|
|
|
|
|
+ file.transferTo(tempFile);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> map = null;
|
|
|
|
|
+ if(null != tempFile && StringUtils.isNotBlank(workStaffBasicInfo.getHandSignature())){
|
|
|
|
|
+ // 入参传临时文件路径,方便你在方法里直接读取处理
|
|
|
|
|
+ map = disposeFile(tempFile, workStaffBasicInfo.getHandSignature(), basePath);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取处理好的一造文件
|
|
|
|
|
+ String outPdfPath = (String) map.get("outPdfPath");
|
|
|
|
|
+ MultipartFile multipartFile = transformFile(new File(outPdfPath));
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 调用原有的uploadFile方法,上传到CDN(保持你原有逻辑不变)
|
|
|
|
|
+ String cdnFilePath = this.uploadFile(multipartFile, entity.getFilePath());
|
|
|
|
|
+ entity.setFileName(originalFileName);
|
|
|
|
|
+ entity.setFilePath(cdnFilePath);
|
|
|
|
|
+
|
|
|
|
|
+ //获取本次生成的一级造价师的文件的使用时效时间
|
|
|
|
|
+ String startDateStr = (String) map.get("startDate");
|
|
|
|
|
+ String endDateStr = (String) map.get("endDate");
|
|
|
|
|
+ //获取一级造价师文件的有效时间
|
|
|
|
|
+ String certValidStartDateStr = (String) map.get("certValidStart");
|
|
|
|
|
+ String certValidEndDateStr = (String) map.get("certValidEnd");
|
|
|
|
|
+
|
|
|
|
|
+ // 转换为 Date
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
|
|
+
|
|
|
|
|
+ entity.setValidStartDate(sdf.parse(startDateStr));
|
|
|
|
|
+ entity.setValidEndDate(sdf.parse(endDateStr));
|
|
|
|
|
+ entity.setStartDate(sdf.parse(certValidStartDateStr));
|
|
|
|
|
+ entity.setEndDate(sdf.parse(certValidEndDateStr));
|
|
|
|
|
+
|
|
|
|
|
+ // -------------------------- 4. 条件判断:name=161 且 是PDF,调用disposeFile --------------------------
|
|
|
|
|
+
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //如果不是一造 也不是pdf文件的话,按照以前的处理方式进行处理
|
|
|
|
|
+ entity.setFileName(file.getOriginalFilename());
|
|
|
|
|
+ entity.setFilePath(this.uploadFile(file,entity.getFilePath()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 异常处理:打印日志,抛出业务异常(可根据你的项目规范调整)
|
|
|
|
|
+ throw new RuntimeException("证书文件处理失败:" + e.getMessage());
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // -------------------------- 5. 无论成功失败,最终删除临时文件 --------------------------
|
|
|
|
|
+ if (StringUtils.isNotBlank(tempFilePath)) {
|
|
|
|
|
+ File tempFile = new File(tempFilePath);
|
|
|
|
|
+ if (tempFile.exists()) {
|
|
|
|
|
+ tempFile.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(basePath)) {
|
|
|
|
|
+ File basePathFile = new File(basePath);
|
|
|
|
|
+ if (basePathFile.exists() && basePathFile.isDirectory()) {
|
|
|
|
|
+ // 清空目录下所有文件/子文件夹,保留目录本身
|
|
|
|
|
+ clearDirectory(basePathFile);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
entity.setStaffId(workStaffBasicInfo.getId());
|
|
entity.setStaffId(workStaffBasicInfo.getId());
|
|
|
this.save(entity);
|
|
this.save(entity);
|
|
|
if(first){
|
|
if(first){
|
|
@@ -150,6 +247,121 @@ public class WorkStaffCertificateService extends CrudService<WorkStaffCertificat
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 清空指定目录下的所有内容(文件+子文件夹),保留目录本身
|
|
|
|
|
+ */
|
|
|
|
|
+ private void clearDirectory(File dir) {
|
|
|
|
|
+ if (!dir.exists() || !dir.isDirectory()) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ File[] files = dir.listFiles();
|
|
|
|
|
+ if (files == null || files.length == 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ for (File file : files) {
|
|
|
|
|
+ deleteRecursively(file);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 递归删除文件/目录(内部工具方法)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void deleteRecursively(File file) {
|
|
|
|
|
+ if (file.isDirectory()) {
|
|
|
|
|
+ File[] children = file.listFiles();
|
|
|
|
|
+ if (children != null) {
|
|
|
|
|
+ for (File child : children) {
|
|
|
|
|
+ deleteRecursively(child);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ // 删除文件或空目录
|
|
|
|
|
+ file.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * File转MultipartFile
|
|
|
|
|
+ * @param file
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public static MultipartFile transformFile(File file) {
|
|
|
|
|
+ InputStream inputStream = null;
|
|
|
|
|
+ MultipartFile multipartFile = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ inputStream = new FileInputStream(file);
|
|
|
|
|
+ // 完整构造:name(表单字段名), originalFilename(原始文件名), contentType, 输入流
|
|
|
|
|
+ multipartFile = new MockMultipartFile(
|
|
|
|
|
+ "certificateList[0].file", // 对应前端表单的name属性
|
|
|
|
|
+ file.getName(), // 原始文件名(和前端一致)
|
|
|
|
|
+ "application/pdf", // 正确的contentType(PDF场景)
|
|
|
|
|
+ inputStream
|
|
|
|
|
+ );
|
|
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // 注意:MockMultipartFile会自动关闭流,这里不需要手动关,避免报错
|
|
|
|
|
+ // IOUtils.close(inputStream);
|
|
|
|
|
+ }
|
|
|
|
|
+ return multipartFile;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param tempFile 一造文件
|
|
|
|
|
+ * @param handSignature 个人签名章
|
|
|
|
|
+ */
|
|
|
|
|
+ private Map<String,Object> disposeFile(File tempFile, String handSignature, String path) {
|
|
|
|
|
+ Map<String,Object> map = null;
|
|
|
|
|
+ File srcFile = null;
|
|
|
|
|
+ try{
|
|
|
|
|
+ String file = handSignature;
|
|
|
|
|
+ file = file.replace("amp;","");
|
|
|
|
|
+ String fileName = file.substring(file.lastIndexOf("/") + 1, file.length());
|
|
|
|
|
+ String aliyunUrl = Global.getAliyunUrl();
|
|
|
|
|
+ String aliDownloadUrl = Global.getAliDownloadUrl();
|
|
|
|
|
+ String cons = "";
|
|
|
|
|
+ if (file.contains(aliyunUrl)){
|
|
|
|
|
+ cons = aliyunUrl;
|
|
|
|
|
+ }else if (file.contains("http://gangwan-app.oss-cn-hangzhou.aliyuncs.com")){
|
|
|
|
|
+ cons = "http://gangwan-app.oss-cn-hangzhou.aliyuncs.com";
|
|
|
|
|
+ }else {
|
|
|
|
|
+ cons = aliDownloadUrl;
|
|
|
|
|
+ }
|
|
|
|
|
+ String ossKey;
|
|
|
|
|
+
|
|
|
|
|
+ // 判断是否以 / 开头
|
|
|
|
|
+ if (file.startsWith("/")) {
|
|
|
|
|
+ // 情况1:以 / 开头 → 去掉第一个 /
|
|
|
|
|
+ ossKey = file.substring(1);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 情况2:不以 / 开头 → 按 cons/ 分割取后面部分
|
|
|
|
|
+ String[] split = file.split(cons + "/");
|
|
|
|
|
+ // 安全取值,防止数组越界
|
|
|
|
|
+ ossKey = split.length > 1 ? split[1] : file;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ new OSSClientUtil().downByStreamSaveLocal(ossKey,fileName,path+fileName);
|
|
|
|
|
+ //将下载下来的文件转换为file文件
|
|
|
|
|
+ srcFile = new File(path+fileName);
|
|
|
|
|
+
|
|
|
|
|
+ map = PdfSignUtil.disposePdfFile(tempFile, srcFile, path);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ //删除本地文件
|
|
|
|
|
+ if (!srcFile.isDirectory()) {
|
|
|
|
|
+ srcFile.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return map;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 导入职业资格文件处理
|
|
* 导入职业资格文件处理
|
|
|
* @param list
|
|
* @param list
|
|
|
* @return
|
|
* @return
|
|
@@ -647,11 +859,26 @@ public class WorkStaffCertificateService extends CrudService<WorkStaffCertificat
|
|
|
workStaffBasicInfo.setCertificateList(newList);
|
|
workStaffBasicInfo.setCertificateList(newList);
|
|
|
}
|
|
}
|
|
|
@Transactional(readOnly = false)
|
|
@Transactional(readOnly = false)
|
|
|
- public void saveEdu(WorkStaffBasicInfo workStaffBasicInfo) {
|
|
|
|
|
|
|
+ public String saveEdu(WorkStaffBasicInfo workStaffBasicInfo) {
|
|
|
|
|
+
|
|
|
|
|
+ String result = "";
|
|
|
|
|
+
|
|
|
|
|
+ if(StringUtils.isBlank(workStaffBasicInfo.getHandSignature())){
|
|
|
|
|
+ WorkStaffBasicInfo workStaffBasicInfo1 = workStaffBasicInfoDao.getWorkStaffBasicInfoByUserId(workStaffBasicInfo.getUserId());
|
|
|
|
|
+ workStaffBasicInfo.setHandSignature(workStaffBasicInfo1.getHandSignature());
|
|
|
|
|
+ }
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
List<WorkStaffCertificate> certificateList =workStaffBasicInfo.getCertificateList();
|
|
List<WorkStaffCertificate> certificateList =workStaffBasicInfo.getCertificateList();
|
|
|
if(certificateList!=null&&certificateList.size()>0){
|
|
if(certificateList!=null&&certificateList.size()>0){
|
|
|
for(WorkStaffCertificate newCertificate:certificateList){
|
|
for(WorkStaffCertificate newCertificate:certificateList){
|
|
|
|
|
+ //数据处理
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
if(null != newCertificate.getFile() && StringUtils.isNotBlank(newCertificate.getFile().getOriginalFilename())){
|
|
if(null != newCertificate.getFile() && StringUtils.isNotBlank(newCertificate.getFile().getOriginalFilename())){
|
|
|
String fileName = newCertificate.getFile().getOriginalFilename();
|
|
String fileName = newCertificate.getFile().getOriginalFilename();
|
|
|
newCertificate.setFileName(fileName);
|
|
newCertificate.setFileName(fileName);
|
|
@@ -659,10 +886,107 @@ public class WorkStaffCertificateService extends CrudService<WorkStaffCertificat
|
|
|
Class<? extends WorkStaffCertificate> newClass = newCertificate.getClass();
|
|
Class<? extends WorkStaffCertificate> newClass = newCertificate.getClass();
|
|
|
Field[] declaredFields = newClass.getDeclaredFields();
|
|
Field[] declaredFields = newClass.getDeclaredFields();
|
|
|
if(newCertificate.getId()!=null&&!"1".equals(newCertificate.getDelFlag())&&!"".equals(newCertificate.getId())){
|
|
if(newCertificate.getId()!=null&&!"1".equals(newCertificate.getDelFlag())&&!"".equals(newCertificate.getId())){
|
|
|
- if(newCertificate.getFile()!=null&&!newCertificate.getFile().isEmpty()&&newCertificate.getFile().getSize()>0){
|
|
|
|
|
- MultipartFile file = newCertificate.getFile();
|
|
|
|
|
- newCertificate.setFilePath(this.uploadFile(file,newCertificate.getFilePath()));
|
|
|
|
|
|
|
+ // 1. 先处理文件上传(按系统区分路径,临时存储)
|
|
|
|
|
+ String staffId = workStaffBasicInfo.getId();
|
|
|
|
|
+ MultipartFile file = newCertificate.getFile();
|
|
|
|
|
+
|
|
|
|
|
+ // 临时文件路径(用于try中处理,处理完自动删除)
|
|
|
|
|
+ String tempFilePath = null;
|
|
|
|
|
+
|
|
|
|
|
+ if (file != null && !file.isEmpty() && file.getSize() > 0) {
|
|
|
|
|
+
|
|
|
|
|
+ String name = newCertificate.getName();
|
|
|
|
|
+ // 生成临时文件名(避免重名)
|
|
|
|
|
+ String originalFileName = file.getOriginalFilename();
|
|
|
|
|
+ String basePath = "";
|
|
|
|
|
+ try {
|
|
|
|
|
+ if ("161".equals(name)
|
|
|
|
|
+ && StringUtils.isNotBlank(originalFileName)
|
|
|
|
|
+ && originalFileName.toLowerCase().endsWith(".pdf") && StringUtils.isNotBlank(workStaffBasicInfo.getHandSignature())) {
|
|
|
|
|
+ // -------------------------- 1. 按系统生成临时存储路径 --------------------------
|
|
|
|
|
+ String os = System.getProperty("os.name").toLowerCase();
|
|
|
|
|
+ if (os.contains("win")) {
|
|
|
|
|
+ // Windows系统:D盘根目录
|
|
|
|
|
+ basePath = "D:/attachment-file/staffCertificate/" + staffId + "/";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Linux系统:根目录
|
|
|
|
|
+ basePath = "/attachment-file/staffCertificate/" + staffId + "/";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 确保目录存在,不存在则自动创建
|
|
|
|
|
+ File dir = new File(basePath);
|
|
|
|
|
+ if (!dir.exists()) {
|
|
|
|
|
+ dir.mkdirs();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String tempFileName = System.currentTimeMillis() + "_" + originalFileName;
|
|
|
|
|
+ tempFilePath = basePath + tempFileName;
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 将上传的文件保存到临时路径
|
|
|
|
|
+ File tempFile = new File(tempFilePath);
|
|
|
|
|
+ file.transferTo(tempFile);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> map = null;
|
|
|
|
|
+ if(null != tempFile && StringUtils.isNotBlank(workStaffBasicInfo.getHandSignature())){
|
|
|
|
|
+ // 入参传临时文件路径,方便你在方法里直接读取处理
|
|
|
|
|
+ map = disposeFile(tempFile, workStaffBasicInfo.getHandSignature(), basePath);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //获取处理好的一造文件
|
|
|
|
|
+ String outPdfPath = (String) map.get("outPdfPath");
|
|
|
|
|
+ MultipartFile multipartFile = transformFile(new File(outPdfPath));
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 调用原有的uploadFile方法,上传到CDN(保持你原有逻辑不变)
|
|
|
|
|
+ String cdnFilePath = this.uploadFile(multipartFile, newCertificate.getFilePath());
|
|
|
|
|
+ newCertificate.setFileName(originalFileName);
|
|
|
|
|
+ newCertificate.setFilePath(cdnFilePath);
|
|
|
|
|
+
|
|
|
|
|
+ //获取本次生成的一级造价师的文件的使用时效时间
|
|
|
|
|
+ String startDateStr = (String) map.get("startDate");
|
|
|
|
|
+ String endDateStr = (String) map.get("endDate");
|
|
|
|
|
+ //获取一级造价师文件的有效时间
|
|
|
|
|
+ String certValidStartDateStr = (String) map.get("certValidStart");
|
|
|
|
|
+ String certValidEndDateStr = (String) map.get("certValidEnd");
|
|
|
|
|
+
|
|
|
|
|
+ // 转换为 Date
|
|
|
|
|
+ sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
|
|
|
|
+
|
|
|
|
|
+ newCertificate.setValidStartDate(sdf.parse(startDateStr));
|
|
|
|
|
+ newCertificate.setValidEndDate(sdf.parse(endDateStr));
|
|
|
|
|
+ newCertificate.setStartDate(sdf.parse(certValidStartDateStr));
|
|
|
|
|
+ newCertificate.setEndDate(sdf.parse(certValidEndDateStr));
|
|
|
|
|
+
|
|
|
|
|
+ // -------------------------- 4. 条件判断:name=161 且 是PDF,调用disposeFile --------------------------
|
|
|
|
|
+
|
|
|
|
|
+ }else{
|
|
|
|
|
+ //如果不是一造 也不是pdf文件的话,按照以前的处理方式进行处理
|
|
|
|
|
+ newCertificate.setFileName(file.getOriginalFilename());
|
|
|
|
|
+ newCertificate.setFilePath(this.uploadFile(file,newCertificate.getFilePath()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ // 异常处理:打印日志,抛出业务异常(可根据你的项目规范调整)
|
|
|
|
|
+ //throw new RuntimeException("证书文件处理失败:" + e.getMessage());
|
|
|
|
|
+ result = "一级造价师证书处理失败" + e.getMessage();
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ // -------------------------- 5. 无论成功失败,最终删除临时文件 --------------------------
|
|
|
|
|
+ if (StringUtils.isNotBlank(tempFilePath)) {
|
|
|
|
|
+ File tempFile = new File(tempFilePath);
|
|
|
|
|
+ if (tempFile.exists()) {
|
|
|
|
|
+ tempFile.delete();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StringUtils.isNotBlank(basePath)) {
|
|
|
|
|
+ File basePathFile = new File(basePath);
|
|
|
|
|
+ if (basePathFile.exists() && basePathFile.isDirectory()) {
|
|
|
|
|
+ // 清空目录下所有文件/子文件夹,保留目录本身
|
|
|
|
|
+ clearDirectory(basePathFile);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
WorkStaffCertificate oldCertificate=this.get(newCertificate.getId());
|
|
WorkStaffCertificate oldCertificate=this.get(newCertificate.getId());
|
|
|
if(oldCertificate!=null){
|
|
if(oldCertificate!=null){
|
|
|
Class<? extends WorkStaffCertificate> oldClass = oldCertificate.getClass();
|
|
Class<? extends WorkStaffCertificate> oldClass = oldCertificate.getClass();
|
|
@@ -730,7 +1054,7 @@ public class WorkStaffCertificateService extends CrudService<WorkStaffCertificat
|
|
|
}else{
|
|
}else{
|
|
|
if("1".equals(workStaffBasicInfo.getAuditStatus())){
|
|
if("1".equals(workStaffBasicInfo.getAuditStatus())){
|
|
|
if(newCertificate.getFile()!=null&&!newCertificate.getFile().isEmpty()&&newCertificate.getFile().getSize()>0){
|
|
if(newCertificate.getFile()!=null&&!newCertificate.getFile().isEmpty()&&newCertificate.getFile().getSize()>0){
|
|
|
- MultipartFile file = newCertificate.getFile();
|
|
|
|
|
|
|
+ //MultipartFile file = newCertificate.getFile();
|
|
|
newCertificate.setFilePath(this.uploadFile(file,newCertificate.getFilePath()));
|
|
newCertificate.setFilePath(this.uploadFile(file,newCertificate.getFilePath()));
|
|
|
}
|
|
}
|
|
|
String newId=IdGen.uuid();
|
|
String newId=IdGen.uuid();
|
|
@@ -846,6 +1170,7 @@ public class WorkStaffCertificateService extends CrudService<WorkStaffCertificat
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Transactional(readOnly = false)
|
|
@Transactional(readOnly = false)
|
|
@@ -1060,4 +1385,8 @@ public class WorkStaffCertificateService extends CrudService<WorkStaffCertificat
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public List<WorkStaffCertificate> getFirstCostEngineerList(){
|
|
|
|
|
+ return dao.getFirstCostEngineerList();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|