资质申请文件解析

This commit is contained in:
dxfeng 2025-03-25 18:43:58 +08:00
parent 98f184c802
commit 9b6ccc8732
11 changed files with 147 additions and 73 deletions

Binary file not shown.

View File

@ -0,0 +1,8 @@
package com.api.secret.web;
import javax.ws.rs.Path;
@Path("/secret/demand")
public class QualificationApplicationController extends com.engine.secret.web.QualificationApplicationController {
}

View File

@ -1,8 +0,0 @@
package com.api.xxx.web;
import javax.ws.rs.Path;
@Path("/jcl/xxx/demand")
public class RecruitDemandController extends com.engine.xxx.web.RecruitDemandController{
}

View File

@ -1,4 +1,4 @@
package com.engine.xxx.exception;
package com.engine.secret.exception;
/**
* @Author weaver_cl

View File

@ -0,0 +1,19 @@
package com.engine.secret.service;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2024/08/29
* @version: 1.0
*/
public interface QualificationApplicationService {
/**
* 解析文件
*
* @param param
* @return
*/
Map<String, Object> parsingFiles(Map<String, Object> param);
}

View File

@ -0,0 +1,103 @@
package com.engine.secret.service.impl;
import com.engine.core.impl.Service;
import com.engine.secret.exception.CustomizeRunTimeException;
import com.engine.secret.service.QualificationApplicationService;
import com.wbi.util.Util;
import net.lingala.zip4j.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.FileHeader;
import org.apache.commons.lang.StringUtils;
import weaver.file.ImageFileManager;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @author:dxfeng
* @createTime: 2024/08/29
* @version: 1.0
*/
public class QualificationApplicationServiceImpl extends Service implements QualificationApplicationService {
@Override
public Map<String, Object> parsingFiles(Map<String, Object> param) {
try {
int fileId = 1627;
String imageId = Util.null2String(param.get("imageId"));
if (StringUtils.isBlank(imageId)) {
throw new CustomizeRunTimeException("文件获取失败,请确认文件是否上传");
}
Map<String, Object> returnMap = new HashMap<>();
// 根据文件id获取文件流
ImageFileManager manager = new ImageFileManager();
manager.getImageFileInfoById(fileId);
manager.getImageFileName();
InputStream inputStream = manager.getInputStream();
Path tempZipFile = Files.createTempFile("temp", ".zip");
Files.copy(inputStream, tempZipFile, StandardCopyOption.REPLACE_EXISTING);
String password = "zizhi102!";
unzipWithPassword(tempZipFile, Paths.get("output"), password);
return returnMap;
} catch (Exception e) {
throw new CustomizeRunTimeException("文件解析失败", e);
}
}
private static void unzipWithPassword(Path zipFilePath, Path outputDir, String password) {
try {
ZipFile zipFile = new ZipFile(zipFilePath.toFile());
if (zipFile.isEncrypted()) {
zipFile.setPassword(password.toCharArray()); // 设置密码
}
// 遍历并解压所有文件
zipFile.extractAll(outputDir.toString());
System.out.println("解压成功");
// 12345678_资质申请附件/(database)data.json
// 存储文件
// 遍历 ZIP 内文件可选
List<FileHeader> fileHeaders = zipFile.getFileHeaders();
Optional<String> commonRoot = fileHeaders.stream()
.map(FileHeader::getFileName)
.filter(path -> !path.trim().isEmpty())
.map(path -> path.split("/")[0]) // 取第一级目录或文件名
.distinct()
.reduce((a, b) -> a.equals(b) ? a : null);
String rootPath = commonRoot.orElse(null);
Map<String,FileHeader> fileHeaderMap = new HashMap<>();
for (FileHeader header : fileHeaders) {
System.out.println("文件: " + header.getFileName());
fileHeaderMap.put(header.getFileName(),header);
}
// 遍历配置表
} catch (ZipException e) {
if (e.getMessage().contains("Wrong password")) {
System.err.println("密码错误");
} else {
e.printStackTrace();
}
} finally {
try {
Files.deleteIfExists(zipFilePath);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View File

@ -1,4 +1,4 @@
package com.engine.xxx.util;
package com.engine.secret.util;
/**
* @Author weaver_cl

View File

@ -1,11 +1,11 @@
package com.engine.xxx.util;
package com.engine.secret.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.engine.core.exception.ECException;
import com.engine.xxx.exception.CustomizeRunTimeException;
import com.engine.secret.exception.CustomizeRunTimeException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
@ -50,7 +50,7 @@ public class ResponseResult<T, R> {
log.info("run api , param {}", t);
}
return getJsonString(f.apply(t));
} catch (com.engine.xxx.exception.CustomizeRunTimeException e) {
} catch (com.engine.secret.exception.CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
@ -72,7 +72,7 @@ public class ResponseResult<T, R> {
log.info("run api , param {}", t);
}
return Ok(f.apply(t));
} catch (com.engine.xxx.exception.CustomizeRunTimeException e) {
} catch (com.engine.secret.exception.CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {
@ -95,7 +95,7 @@ public class ResponseResult<T, R> {
}
f.accept(t);
return Ok();
} catch (com.engine.xxx.exception.CustomizeRunTimeException e) {
} catch (com.engine.secret.exception.CustomizeRunTimeException e) {
log.error("api run fail", e);
return Error(e.getMessage());
} catch (ECException e) {

View File

@ -1,10 +1,10 @@
package com.engine.xxx.web;
package com.engine.secret.web;
import com.engine.common.util.ParamUtil;
import com.engine.common.util.ServiceUtil;
import com.engine.xxx.service.RecruitDemandService;
import com.engine.xxx.service.impl.RecruitDemandServiceImpl;
import com.engine.xxx.util.ResponseResult;
import com.engine.secret.service.QualificationApplicationService;
import com.engine.secret.service.impl.QualificationApplicationServiceImpl;
import com.engine.secret.util.ResponseResult;
import weaver.hrm.HrmUserVarify;
import weaver.hrm.User;
@ -22,18 +22,18 @@ import java.util.Map;
* @createTime: 2024/08/29
* @version: 1.0
*/
public class RecruitDemandController {
public RecruitDemandService getService(User user) {
return ServiceUtil.getService(RecruitDemandServiceImpl.class, user);
public class QualificationApplicationController {
public QualificationApplicationService getService(User user) {
return ServiceUtil.getService(QualificationApplicationServiceImpl.class, user);
}
@GET
@Path("/getStaffNum")
@Path("/parsingFiles")
@Produces(MediaType.APPLICATION_JSON)
public String getStaffNum(@Context HttpServletRequest request, @Context HttpServletResponse response) {
public String parsingFiles(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request);
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getService(user)::getStaffNum, params);
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getService(user)::parsingFiles, params);
}
}

View File

@ -1,13 +0,0 @@
package com.engine.xxx.service;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2024/08/29
* @version: 1.0
*/
public interface RecruitDemandService {
Map<String, Object> getStaffNum(Map<String, Object> param);
}

View File

@ -1,35 +0,0 @@
package com.engine.xxx.service.impl;
import com.engine.core.impl.Service;
import com.engine.xxx.service.RecruitDemandService;
import weaver.conn.RecordSet;
import weaver.general.Util;
import java.util.HashMap;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2024/08/29
* @version: 1.0
*/
public class RecruitDemandServiceImpl extends Service implements RecruitDemandService {
@Override
public Map<String, Object> getStaffNum(Map<String, Object> param) {
Map<String, Object> returnMap = new HashMap<>();
RecordSet rs = new RecordSet();
String sqbm = Util.null2String(param.get("sqbm"));
String xqgw = Util.null2String(param.get("xqgw"));
rs.executeQuery("select a.staff_num, a.permanent_num from jcl_org_staff a inner join JCL_ORG_STAFFPLAN b on a.plan_id = b.id and b.forbidden_tag = 0 and b.delete_type = 0 where a.delete_type = 0 and a.ec_department = ? and a.job_id = ? order by a.id desc", sqbm, xqgw);
if(rs.next()) {
String staffNum = rs.getString("staff_num");
String permanentNum = rs.getString("permanent_num");
returnMap.put("staffNum", staffNum);
returnMap.put("permanentNum", permanentNum);
}
return returnMap;
}
}