角色关联岗位批处理,支持不指定数量的岗位名称excel列

This commit is contained in:
446052889@qq.com 2022-10-19 18:49:16 +08:00
parent 40b532e959
commit eec46bd9bd
4 changed files with 45 additions and 64 deletions

View File

@ -27,10 +27,10 @@ public class PositionConstant {
public final static String TABLE_POSITION_NAME2 = "现在岗位名称2";
public final static String TABLE_POSITION_NAME3 = "现在岗位名称3";
public final static String TABLE_POSITION_NAME4 = "现在岗位名称4";
public final static String TABLE_POSITION_NAME = "现在岗位名称";
public final static String [] EXCEL_TITLE_ROW_ARR = new String [] {TABLE_PROCESS_NAME, TABLE_PROCESS_SHAPE_NAME, TABLE_TYPE_NAME, TABLE_NAME, TABLE_POSITION_NAME1, TABLE_POSITION_NAME2, TABLE_POSITION_NAME3, TABLE_POSITION_NAME4};
public final static String EXCEL_TITLE_ROW = TABLE_PROCESS_NAME+ "" +TABLE_PROCESS_SHAPE_NAME+ "" +TABLE_TYPE_NAME+ "" +TABLE_NAME+ "" +TABLE_POSITION_NAME1+ ""
+TABLE_POSITION_NAME2+ "" +TABLE_POSITION_NAME3+ "" +TABLE_POSITION_NAME4;
// 固定列
public final static String [] EXCEL_TITLE_ROW_FIXED_ARR = new String [] {TABLE_PROCESS_NAME, TABLE_PROCESS_SHAPE_NAME, TABLE_TYPE_NAME, TABLE_NAME, TABLE_POSITION_NAME1};
public final static String EXCEL_TITLE_ROW_FIXED = TABLE_PROCESS_NAME+ "" +TABLE_PROCESS_SHAPE_NAME+ "" +TABLE_TYPE_NAME+ "" +TABLE_NAME+ "" +TABLE_POSITION_NAME1;
}

View File

@ -1,5 +1,7 @@
package com.actionsoft.apps.coe.pal.datamigration.position.model;
import java.util.List;
/**
* Excel数据model
*/
@ -8,10 +10,7 @@ public class PositionExcelModel {
private String processShapeName;// 活动名称
private String type;// 类别
private String roleName;// 名称角色
private String positionName1;// 岗位名称1
private String positionName2;// 岗位名称2
private String positionName3;// 岗位名称3
private String positionName4;// 岗位名称4
private List<String> positionName;// 岗位名称
public String getProcessName() {
return processName;
@ -45,35 +44,11 @@ public class PositionExcelModel {
this.roleName = roleName;
}
public String getPositionName1() {
return positionName1;
public List<String> getPositionName() {
return positionName;
}
public void setPositionName1(String positionName1) {
this.positionName1 = positionName1;
}
public String getPositionName2() {
return positionName2;
}
public void setPositionName2(String positionName2) {
this.positionName2 = positionName2;
}
public String getPositionName3() {
return positionName3;
}
public void setPositionName3(String positionName3) {
this.positionName3 = positionName3;
}
public String getPositionName4() {
return positionName4;
}
public void setPositionName4(String positionName4) {
this.positionName4 = positionName4;
public void setPositionName(List<String> positionName) {
this.positionName = positionName;
}
}

View File

@ -263,7 +263,7 @@ public class PositionExcelImportWeb extends ActionWeb {
return ro.toString();
}
// 解析xls内容
List<PositionExcelModel> excelModelList = getExcelContent(sheet);
List<PositionExcelModel> excelModelList = getExcelContent(sheet, titleList);
if (excelModelList.size() == 0) {
msg = Constant.LOG_ERROR + "上传文件工作表中内容不能为空," + Constant.IMPORT_STOP_MSG;
updateErrLog(msg, msg);
@ -356,17 +356,11 @@ public class PositionExcelImportWeb extends ActionWeb {
model.setRoleName(roleName);
List<String> positionList = new ArrayList<>();
for (PositionExcelModel position : list) {
if (UtilString.isNotEmpty(position.getPositionName1()) && !positionList.contains(position.getPositionName1())) {
positionList.add(position.getPositionName1());
}
if (UtilString.isNotEmpty(position.getPositionName2()) && !positionList.contains(position.getPositionName2())) {
positionList.add(position.getPositionName2());
}
if (UtilString.isNotEmpty(position.getPositionName3()) && !positionList.contains(position.getPositionName3())) {
positionList.add(position.getPositionName3());
}
if (UtilString.isNotEmpty(position.getPositionName4()) && !positionList.contains(position.getPositionName4())) {
positionList.add(position.getPositionName4());
List<String> postionStrList = position.getPositionName();
for (String str : postionStrList) {
if (UtilString.isNotEmpty(str) && !positionList.contains(str)) {
positionList.add(str);
}
}
}
model.setPositionList(positionList);
@ -447,9 +441,10 @@ public class PositionExcelImportWeb extends ActionWeb {
/**
* 获取Excel内容
* @param sheet
* @param titleList // titleList除了固定列扩展列若标题为null则为无效数据
* @return
*/
private List<PositionExcelModel> getExcelContent(Sheet sheet) {
private List<PositionExcelModel> getExcelContent(Sheet sheet, List<String> titleList) {
List<PositionExcelModel> list = new ArrayList<>();
for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
Row row = sheet.getRow(i);
@ -466,18 +461,20 @@ public class PositionExcelImportWeb extends ActionWeb {
// 角色名称
Cell cell4 = row.getCell(3);
rowModel.setRoleName(POIUtil.getCellValueByCell(cell4));
// 第5列是有岗位名称列的标题算是固定列
List<String> postList = new ArrayList<>();
// 现在岗位名称1
Cell cell5 = row.getCell(4);
rowModel.setPositionName1(POIUtil.getCellValueByCell(cell5));
// 现在岗位名称2
Cell cell6 = row.getCell(5);
rowModel.setPositionName2(POIUtil.getCellValueByCell(cell6));
// 现在岗位名称3
Cell cell7 = row.getCell(6);
rowModel.setPositionName3(POIUtil.getCellValueByCell(cell7));
// 现在岗位名称4
Cell cell8 = row.getCell(7);
rowModel.setPositionName4(POIUtil.getCellValueByCell(cell8));
postList.add(POIUtil.getCellValueByCell(cell5));
// 扩展列数据
for (int j = PositionConstant.EXCEL_TITLE_ROW_FIXED_ARR.length; j < titleList.size(); j++) {
if (titleList.get(j) == null) {// 无效标题
continue;
}
Cell cell6 = row.getCell(j);
postList.add(POIUtil.getCellValueByCell(cell6));
}
rowModel.setPositionName(postList);
list.add(rowModel);
}
return list;
@ -490,16 +487,25 @@ public class PositionExcelImportWeb extends ActionWeb {
*/
private ResponseObject checkExcelTitle(List<String> titleList) {
ResponseObject ro = ResponseObject.newOkResponse();
if (titleList.size() < PositionConstant.EXCEL_TITLE_ROW_ARR.length) {
ro.err("上传文件工作表中标题行错误,请按照" + PositionConstant.EXCEL_TITLE_ROW + "的格式填写当前Excel列名" + StringUtils.join(titleList, ""));
if (titleList.size() < PositionConstant.EXCEL_TITLE_ROW_FIXED_ARR.length) {// 固定列不满足校验失败
ro.err("上传文件工作表中标题行错误," + PositionConstant.EXCEL_TITLE_ROW_FIXED_ARR.length + "请按照" + PositionConstant.EXCEL_TITLE_ROW_FIXED + "的格式填写当前Excel列名" + StringUtils.join(titleList, ""));
return ro;
}
for (int i = 0; i < PositionConstant.EXCEL_TITLE_ROW_ARR.length; i++) {
if (!PositionConstant.EXCEL_TITLE_ROW_ARR[i].equals(titleList.get(i))) {
ro.err("上传文件工作表中标题行错误,请按照" + PositionConstant.EXCEL_TITLE_ROW + "的格式填写若有隐藏列请移动至最后当前Excel列名" + StringUtils.join(titleList, ""));
// 固定列标题文本校验
for (int i = 0; i < PositionConstant.EXCEL_TITLE_ROW_FIXED_ARR.length; i++) {
if (!PositionConstant.EXCEL_TITLE_ROW_FIXED_ARR[i].equals(titleList.get(i))) {
ro.err("上传文件工作表中标题行错误,前"+ PositionConstant.EXCEL_TITLE_ROW_FIXED_ARR.length +"列请按照" + PositionConstant.EXCEL_TITLE_ROW_FIXED + "的格式填写若有隐藏列请移动至最后当前Excel列名" + StringUtils.join(titleList, ""));
return ro;
}
}
// 固定列满足扩展列所有没有PositionConstant.TABLE_POSITION_NAME字样的全部置为null
if (titleList.size() > PositionConstant.EXCEL_TITLE_ROW_FIXED_ARR.length) {
for (int i = PositionConstant.EXCEL_TITLE_ROW_FIXED_ARR.length; i < titleList.size(); i++) {
if (!titleList.get(i).contains(PositionConstant.TABLE_POSITION_NAME)) {
titleList.set(i, null);
}
}
}
return ro;
}