|
|
|
@ -21,6 +21,7 @@ import com.engine.core.impl.Service;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet;
|
|
|
|
|
import org.apache.poi.util.IOUtils;
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
@ -32,6 +33,7 @@ import java.io.InputStream;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import static com.engine.jucailinkq.common.util.excel.ExcelSupport.EXCEL_TYPE_XLS;
|
|
|
|
|
import static com.engine.jucailinkq.common.util.excel.ExcelSupport.EXCEL_TYPE_XLSX;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -80,6 +82,53 @@ public class ExcelExportImportServiceImpl extends Service implements ExcelExport
|
|
|
|
|
return ExcelUtil.genWorkbookV2(excelSheetData, sheetName, dateTime, columns.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public HSSFWorkbook exportScheduleNew(Map<String, Object> paramMap) {
|
|
|
|
|
String total = Util.null2String(paramMap.get("total"));
|
|
|
|
|
if ("".equals(total) || "0".equals(total)) {
|
|
|
|
|
paramMap.put("pageSize", "9999");
|
|
|
|
|
} else {
|
|
|
|
|
paramMap.put("pageSize", total);
|
|
|
|
|
}
|
|
|
|
|
paramMap.put("pageindex", "1");
|
|
|
|
|
log.debug("查询条件:{}",paramMap);
|
|
|
|
|
Map<String, Object> scheduleResult = getWorkRulesService(user).getDepartSchedule(paramMap);
|
|
|
|
|
List<WeaTableColumn> columns = buildScheduleColumns((List<Map<String, Object>>) scheduleResult.get("columns"));
|
|
|
|
|
List<Map<String, Object>> records = buildScheduleRecords((List<Map<String, Object>>) scheduleResult.get("datas"));
|
|
|
|
|
|
|
|
|
|
List<List<Object>> excelSheetData = new ArrayList<>();
|
|
|
|
|
//工作簿名称
|
|
|
|
|
String sheetName = "日历排班";
|
|
|
|
|
excelSheetData.add(Arrays.asList(columns.stream().map(WeaTableColumn::getText).toArray()));
|
|
|
|
|
|
|
|
|
|
//工作簿数据
|
|
|
|
|
List<List<Object>> rows = new LinkedList<>();
|
|
|
|
|
for (Map<String, Object> recordData : records) {
|
|
|
|
|
List<Object> row = new LinkedList<>();
|
|
|
|
|
for (WeaTableColumn column : columns) {
|
|
|
|
|
row.add(recordData.get(column.getColumn()));
|
|
|
|
|
}
|
|
|
|
|
rows.add(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
excelSheetData.addAll(rows);
|
|
|
|
|
String dateTime = Util.null2String(paramMap.get("dateTime"));
|
|
|
|
|
//获取下拉列表中的值
|
|
|
|
|
String sql = "select mc from uf_jcl_kq_bcxx;";
|
|
|
|
|
List<Map<String, Object>> bcData = DbTools.getSqlToList(sql);
|
|
|
|
|
List<String> bcMcList = new ArrayList<>();
|
|
|
|
|
if (bcData.size() > 0) {
|
|
|
|
|
bcMcList = bcData.stream().map(e -> e.get("mc").toString()).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
//配置下拉列表的区域信息,依次为开始行、结束行、开始列、结束列
|
|
|
|
|
List<Integer> dropdownRange = new ArrayList<>();
|
|
|
|
|
dropdownRange.add(2);
|
|
|
|
|
dropdownRange.add(records.size() + 1);
|
|
|
|
|
dropdownRange.add(4);
|
|
|
|
|
dropdownRange.add(columns.size() + 3);
|
|
|
|
|
return ExcelUtil.genWorkbookV2WithDropdownList1(excelSheetData, sheetName, dateTime, columns.size(), bcMcList.toArray(new String[0]), dropdownRange);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Map<String, Object>> buildScheduleRecords(List<Map<String, Object>> dataInfo) {
|
|
|
|
|
List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
if (dataInfo != null && dataInfo.size() > 0) {
|
|
|
|
@ -139,15 +188,17 @@ public class ExcelExportImportServiceImpl extends Service implements ExcelExport
|
|
|
|
|
if (fileInputStream == null) {
|
|
|
|
|
throw new AttendanceRunTimeException("excel文件解析失败!");
|
|
|
|
|
}
|
|
|
|
|
Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX);
|
|
|
|
|
// Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX);
|
|
|
|
|
Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLS);
|
|
|
|
|
//标题
|
|
|
|
|
List<String> titles = ExcelSupport.getSheetHeader(sheet, 0);
|
|
|
|
|
String title = titles.get(0);
|
|
|
|
|
log.debug("处理前年月信息:{}",title);
|
|
|
|
|
log.info("title长度:{}",titles.get(0).length());
|
|
|
|
|
String title = titles.get(0).replace(" ", "");
|
|
|
|
|
log.info("处理前年月信息:{}",title);
|
|
|
|
|
//年月格式的转换处理
|
|
|
|
|
if (StrUtil.isNotBlank(title) && title.length() > 7) {
|
|
|
|
|
title = title.substring(0, 7);
|
|
|
|
|
log.debug("处理后年月信息:{}",title);
|
|
|
|
|
log.info("处理后年月信息:{}",title);
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isNotBlank(title) && !DateUtil.checkYearMonth(title.replace("/", "-"))) {
|
|
|
|
|
throw new AttendanceRunTimeException("excel首行'年月'时间格式错误,正确格式为yyyy-mm或者yyyy-mm-dd或者yyyy/mm或者yyyy/mm/dd");
|
|
|
|
@ -155,14 +206,14 @@ public class ExcelExportImportServiceImpl extends Service implements ExcelExport
|
|
|
|
|
int monthDays = DateUtil.getDays(title, Calendar.DAY_OF_MONTH);
|
|
|
|
|
// 表头
|
|
|
|
|
List<String> headers = ExcelSupport.getSheetHeader(sheet, 1);
|
|
|
|
|
log.debug("headers数据:{}", headers);
|
|
|
|
|
log.info("headers数据:{}", headers);
|
|
|
|
|
// 错误sheet数据
|
|
|
|
|
List<Map<String, Object>> errorData = new LinkedList<>();
|
|
|
|
|
// 错误提示
|
|
|
|
|
List<Map<String, String>> excelComments = new LinkedList<>();
|
|
|
|
|
// 处理数值
|
|
|
|
|
List<Map<String, Object>> data = ExcelParseHelper.parse2Map(sheet, 2, 1);
|
|
|
|
|
log.debug("excel导入数据:[{}]", data);
|
|
|
|
|
log.info("excel导入数据数量:[{}]", data.size());
|
|
|
|
|
//单行记录
|
|
|
|
|
Map<String, Object> map;
|
|
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
|
|
@ -175,9 +226,9 @@ public class ExcelExportImportServiceImpl extends Service implements ExcelExport
|
|
|
|
|
if (key == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
singleCheck.put(key, Optional.ofNullable(map.get(key)).orElse("").toString());
|
|
|
|
|
singleCheck.put(key.replace(" ", ""), Optional.ofNullable(map.get(key)).orElse("").toString().replace(" ", ""));
|
|
|
|
|
}
|
|
|
|
|
log.debug(i + 3 + "-singleCheck:{}", singleCheck);
|
|
|
|
|
// log.info(i + 3 + "-singleCheck:{}", singleCheck);
|
|
|
|
|
isError = singleScheduleLineCheck(singleCheck, title, monthDays, toImportScheduleInfos, employeeInfoList, shiftMapWithMc, excelComments, i + 3, formModeId, empIds);
|
|
|
|
|
if (isError) {
|
|
|
|
|
errorCount += 1;
|
|
|
|
@ -225,6 +276,7 @@ public class ExcelExportImportServiceImpl extends Service implements ExcelExport
|
|
|
|
|
String subCompany = Util.null2String(singleCheck.get("分部"));
|
|
|
|
|
String department = Util.null2String(singleCheck.get("部门"));
|
|
|
|
|
String rowIndex = "第" + index + "行";
|
|
|
|
|
log.info("workcode : {}, lastname : {}, subCompany : {}, department : {}", workCode, lastName, subCompany, department);
|
|
|
|
|
//校验该行数据中员工信息是否唯一存在
|
|
|
|
|
List<Map<String, Object>> targetEmpInfo = matchImportEmp(employeeByIds, lastName, subCompany, department, workCode);
|
|
|
|
|
if (CollectionUtils.isEmpty(targetEmpInfo)) {
|
|
|
|
@ -250,6 +302,13 @@ public class ExcelExportImportServiceImpl extends Service implements ExcelExport
|
|
|
|
|
}
|
|
|
|
|
//获取目标人员目标月日期类型对日期的映射
|
|
|
|
|
List<Map<String,Object>> rqlxInfo = CommonUtil.getYearCalendarList(employeeId, yearMonth.substring(0, 4));
|
|
|
|
|
if (rqlxInfo == null || rqlxInfo.size() == 0) {
|
|
|
|
|
Map<String, String> errorMessageMap = new HashMap<>();
|
|
|
|
|
errorMessageMap.put("message", rowIndex + "该员工不存在可用日历!");
|
|
|
|
|
excelComments.add(errorMessageMap);
|
|
|
|
|
isError = true;
|
|
|
|
|
return isError;
|
|
|
|
|
}
|
|
|
|
|
Map<String, String> rqlxInfoWithRq = rqlxInfo.stream().filter(f -> f.get("rq").toString().contains(yearMonth)).collect(Collectors.toMap(e->e.get("rq").toString(), e->e.get("rqlx").toString()));
|
|
|
|
|
//暂存本次调用中的导入数据
|
|
|
|
|
List<Map<String, Object>> singleToImportScheduleInfos = new ArrayList<>();
|
|
|
|
@ -346,7 +405,8 @@ public class ExcelExportImportServiceImpl extends Service implements ExcelExport
|
|
|
|
|
InputStream fileInputStream = null;
|
|
|
|
|
try {
|
|
|
|
|
fileInputStream = ImageFileManager.getInputStreamById(Integer.parseInt(param.getImageId()));
|
|
|
|
|
Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX);
|
|
|
|
|
// Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLSX);
|
|
|
|
|
Sheet sheet = ExcelSupport.parseFile(fileInputStream, 0, EXCEL_TYPE_XLS);
|
|
|
|
|
map.put("headers", ExcelSupport.getSheetHeader(sheet, 1));
|
|
|
|
|
map.put("list", ExcelParseHelper.parse2List(sheet, 2, 1));
|
|
|
|
|
return map;
|
|
|
|
|