笔试结果更新功能开发

This commit is contained in:
dxfeng 2024-01-29 14:01:02 +08:00
parent 890a44585d
commit 635484199a
7 changed files with 297 additions and 25 deletions

View File

@ -63,6 +63,41 @@ public class ApplicantCommonInfo {
return cancelReason; return cancelReason;
} }
/**
* 获取表单下拉框值
*
* @param formId 表单ID
* @param fieldName 字段明湖曾
* @param selectName 下拉框展示内容
* @return
*/
public static String getSelectValue(String formId, String fieldName, String selectName) {
String selectValue = "";
RecordSet rs = new RecordSet();
rs.executeQuery("select selectvalue from workflow_selectitem where fieldid =( select id from workflow_billfield where billid = ? and fieldname = ? ) and selectname = ?", formId, fieldName, selectName);
if (rs.next()) {
selectValue = rs.getString("selectvalue");
}
return selectValue;
}
/**
* 获取表单下拉框展示文本
*
* @param formId 表单ID
* @param fieldName 字段明湖曾
* @return
*/
public static Map<String, String> getSelectMap(String formId, String fieldName) {
Map<String, String> selectMap = new HashMap<>();
RecordSet rs = new RecordSet();
rs.executeQuery("select selectvalue,selectname from workflow_selectitem where fieldid =( select id from workflow_billfield where billid = ? and fieldname = ? ) ", formId, fieldName);
while (rs.next()) {
selectMap.put(rs.getString("selectvalue"), rs.getString("selectname"));
}
return selectMap;
}
/** /**
* 获取招聘通用浏览按钮展示内容 * 获取招聘通用浏览按钮展示内容

View File

@ -10,6 +10,7 @@ import weaver.hrm.User;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
@ -32,6 +33,15 @@ public class WrittenResultsController {
public String getFormCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) { public String getFormCondition(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response); User user = HrmUserVarify.getUser(request, response);
Map<String, Object> params = ParamUtil.request2Map(request); Map<String, Object> params = ParamUtil.request2Map(request);
return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getWrittenResultsWrapper(user)::getFormCondition,params); return new ResponseResult<Map<String, Object>, Map<String, Object>>(user).run(getWrittenResultsWrapper(user)::getFormCondition, params);
}
@POST
@Path("/importExcel")
@Produces(MediaType.APPLICATION_JSON)
public String importExcel(@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(getWrittenResultsWrapper(user)::importExcel, params);
} }
} }

View File

@ -0,0 +1,23 @@
package com.engine.recruit.entity.common;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author:dxfeng
* @createTime: 2024/01/26
* @version: 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ImportLog {
private Integer rowIndex;
private String status;
private String description;
}

View File

@ -15,4 +15,12 @@ public interface WrittenResultsService {
* @return * @return
*/ */
Map<String, Object> getFormCondition(); Map<String, Object> getFormCondition();
/**
* 导入Excel
*
* @param params
* @return
*/
Map<String, Object> importExcel(Map<String, Object> params);
} }

View File

@ -1,15 +1,22 @@
package com.engine.recruit.service.impl; package com.engine.recruit.service.impl;
import com.api.browser.bean.SearchConditionGroup; import cn.hutool.core.convert.Convert;
import com.api.browser.bean.SearchConditionItem;
import com.engine.core.impl.Service; import com.engine.core.impl.Service;
import com.engine.recruit.conn.ApplicantCommonInfo;
import com.engine.recruit.entity.common.ImportLog;
import com.engine.recruit.exception.CustomizeRunTimeException;
import com.engine.recruit.service.WrittenResultsService; import com.engine.recruit.service.WrittenResultsService;
import com.engine.recruit.util.RecruitFormItemUtil; import com.engine.recruit.util.ExcelUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import weaver.conn.RecordSet;
import weaver.file.ImageFileManager;
import java.util.ArrayList; import java.io.IOException;
import java.util.HashMap; import java.util.*;
import java.util.List;
import java.util.Map;
/** /**
* @author:dxfeng * @author:dxfeng
@ -19,24 +26,155 @@ import java.util.Map;
public class WrittenResultsServiceImpl extends Service implements WrittenResultsService { public class WrittenResultsServiceImpl extends Service implements WrittenResultsService {
@Override @Override
public Map<String, Object> getFormCondition() { public Map<String, Object> getFormCondition() {
Map<String, Object> apiDatas = new HashMap<>(); return null;
List<SearchConditionItem> selectItems = new ArrayList<>(); }
List<SearchConditionGroup> addGroups = new ArrayList<>();
SearchConditionItem schemeNameCondition = RecruitFormItemUtil.inputItem(user, 2, 17, 1, 50, "导入类型", "importType");
schemeNameCondition.setRules("required|string");
schemeNameCondition.setValue("更新");
SearchConditionItem schemeNoCondition = RecruitFormItemUtil.uploadItem(user, 2, 17, 3, 50, "Excel文件", "excelFile", 5, 1, "xls,xlsx");
SearchConditionItem subCompanyIdItem = RecruitFormItemUtil.browserItem(user, 2, 17, 1, false, "所属分部", "164", "subCompanyId", "");
SearchConditionItem textareaItem = RecruitFormItemUtil.textareaItem(user, 2, 17, true, 1, 200, "方案说明", "schemeDescription");
selectItems.add(schemeNameCondition); @Override
selectItems.add(schemeNoCondition); public Map<String, Object> importExcel(Map<String, Object> params) {
selectItems.add(subCompanyIdItem); Integer excelId = Convert.toInt(params.get("excel"));
selectItems.add(textareaItem); ImageFileManager manager = new ImageFileManager();
addGroups.add(new SearchConditionGroup("基本信息", true, selectItems, "")); manager.getImageFileInfoById(excelId);
apiDatas.put("condition", addGroups);
apiDatas.put("hasRight", true);
return apiDatas;
XSSFWorkbook workbook;
try {
workbook = new XSSFWorkbook(manager.getInputStream());
} catch (IOException e) {
throw new CustomizeRunTimeException(e);
}
// 当前sheet
XSSFSheet sheetAt = workbook.getSheetAt(0);
// 最后一行
int lastRowNum = sheetAt.getLastRowNum();
if (lastRowNum < 1) {
throw new CustomizeRunTimeException("导入数据为空");
}
// 最后一列
short lastCellNum = sheetAt.getRow(0).getLastCellNum();
Map<String, Integer> keyMap = new HashMap<>(16);
// 标题行
for (int cellIndex = 0; cellIndex < lastCellNum; cellIndex++) {
XSSFRow row = sheetAt.getRow(0);
if (row == null) {
throw new CustomizeRunTimeException("表单字段名称获取失败请检查Excel文件");
}
XSSFCell cell = row.getCell((short) cellIndex);
String cellValue = ExcelUtil.getCellValue(cell).trim();
keyMap.put(cellValue, cellIndex);
}
// 校验必填列
checkRequiredFields(keyMap, "ID", "笔试成绩", "笔试结果");
Integer idCellNum = keyMap.get("ID");
Integer scoreCellNum = keyMap.get("笔试成绩");
Integer resultCellNum = keyMap.get("笔试结果");
return updateWrittenResult(sheetAt, lastRowNum, idCellNum, scoreCellNum, resultCellNum);
}
/**
* 更新笔试结果
*
* @param sheetAt
* @param lastRowNum
* @param idCellNum
* @param scoreCellNum
* @param resultCellNum
* @return
*/
private Map<String, Object> updateWrittenResult(XSSFSheet sheetAt, int lastRowNum, Integer idCellNum, Integer scoreCellNum, Integer resultCellNum) {
Map<String, Object> resultMap = new HashMap<>(4);
Integer allCount = 0;
Integer successCount = 0;
Integer failCount = 0;
List<ImportLog> logList = new ArrayList<>();
RecordSet rs = new RecordSet();
for (int rowIndex = 1; rowIndex <= lastRowNum; rowIndex++) {
allCount++;
XSSFRow row = sheetAt.getRow(rowIndex);
if (null == row) {
continue;
}
List<String> descriptionList = new ArrayList<>();
boolean success = true;
XSSFCell idCell = row.getCell(idCellNum);
String ideCellValue = ExcelUtil.getCellValue(idCell).trim();
if (StringUtils.isBlank(ideCellValue)) {
descriptionList.add("[ID]为空");
success = false;
}
XSSFCell scoreCell = row.getCell(scoreCellNum);
String scoreCellValue = ExcelUtil.getCellValue(scoreCell).trim();
if (StringUtils.isBlank(scoreCellValue)) {
descriptionList.add("[笔试成绩]为空");
success = false;
}
XSSFCell resultCell = row.getCell(resultCellNum);
String resultCellValue = ExcelUtil.getCellValue(resultCell).trim();
if (StringUtils.isBlank(resultCellValue)) {
descriptionList.add("[笔试结果]为空");
success = false;
}
resultCellValue = convertResultValue(resultCellValue);
if (StringUtils.isBlank(resultCellValue)) {
descriptionList.add("[笔试结果]转换失败");
success = false;
}
// 更新笔试成绩
if (success) {
rs.executeUpdate("update uf_jcl_bs set bscj = ? ,bsjg = ? where id = ? ", scoreCellValue, resultCellValue, ideCellValue);
String exceptionMsg = rs.getExceptionMsg();
if (StringUtils.isNotBlank(exceptionMsg)) {
descriptionList.add(exceptionMsg);
success = false;
}
}
if (success) {
successCount++;
} else {
failCount++;
}
ImportLog importLog = ImportLog.builder().
rowIndex(rowIndex + 1) // 对应Excel的行从1开始累加
.description(success ? "导入成功" : StringUtils.join(descriptionList, ","))
.status(String.valueOf(success))
.build();
logList.add(importLog);
}
resultMap.put("log", logList);
resultMap.put("allCount", allCount);
resultMap.put("successCount", successCount);
resultMap.put("failCount", failCount);
return resultMap;
}
/**
* 标题行校验必填列
*
* @param keyMap 字段集合
* @param requiredFields 必填字段
*/
private void checkRequiredFields(Map<String, Integer> keyMap, String... requiredFields) {
// 校验必填列
Set<String> keySet = keyMap.keySet();
for (String field : requiredFields) {
if (!keySet.contains(field)) {
throw new CustomizeRunTimeException("未获取到必填列[" + field + "]");
}
}
}
/**
* 转化笔试结果的值
*
* @param resultCellValue
* @return
*/
private String convertResultValue(String resultCellValue) {
int formId = ApplicantCommonInfo.getFormIdByTableName("uf_jcl_bs");
return ApplicantCommonInfo.getSelectValue(String.valueOf(formId), "bsjg", resultCellValue);
} }
} }

View File

@ -0,0 +1,54 @@
package com.engine.recruit.util;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import weaver.general.Util;
import java.text.SimpleDateFormat;
/**
* @author:dxfeng
* @createTime: 2024/01/26
* @version: 1.0
*/
public class ExcelUtil {
/**
* 获取单元格内容
*
* @param cell
* @return
*/
public static String getCellValue(XSSFCell cell) {
String cellValue = "";
if (cell == null) {
return "";
}
switch (cell.getCellType()) {
case BOOLEAN:
cellValue = String.valueOf(cell.getBooleanCellValue());
break;
case NUMERIC:
if (HSSFDateUtil.isCellDateFormatted(cell)) {
// 先看是否是日期格式 读取日期格式
SimpleDateFormat sft = new SimpleDateFormat("yyyy-MM-dd");
cellValue = sft.format(cell.getDateCellValue());
} else {
// 读取数字
cellValue = String.valueOf(new Double(cell.getNumericCellValue()));
}
break;
case FORMULA:
// 读取公式
cellValue = cell.getCellFormula();
break;
case STRING:
// 读取String
cellValue = cell.getStringCellValue();
break;
default:
break;
}
cellValue = Util.toHtmlForHrm(cellValue);
return cellValue;
}
}

View File

@ -21,4 +21,8 @@ public class WrittenResultsWrapper extends Service {
public Map<String, Object> getFormCondition(Map<String, Object> params) { public Map<String, Object> getFormCondition(Map<String, Object> params) {
return getWrittenResultsService(user).getFormCondition(); return getWrittenResultsService(user).getFormCondition();
} }
public Map<String, Object> importExcel(Map<String, Object> params) {
return getWrittenResultsService(user).importExcel(params);
}
} }