Browse Source

人员组织导入导出

luojing 5 years ago
parent
commit
149a871dd1

+ 166 - 5
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/ActionInputAll.java

@@ -16,6 +16,7 @@ import javax.script.Bindings;
 import javax.script.ScriptContext;
 import javax.script.SimpleScriptContext;
 
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.text.StringEscapeUtils;
 import org.apache.poi.ss.usermodel.Cell;
@@ -150,9 +151,31 @@ class ActionInputAll extends BaseAction {
 		List<PersonItem> person = this.scanPersonList(configurator, sheet);
 		wholeFlag = this.checkPerson(business, workbook, configurator, person); 
 		if(wholeFlag){
-			
+			this.scanIdentity(business, workbook);
 		}
 	}
+	
+	private void scanIdentity(Business business, XSSFWorkbook workbook) throws Exception {
+		//导入身份信息	
+			Sheet sheet = workbook.getSheetAt(4);
+			IdentitySheetConfigurator configurator = new IdentitySheetConfigurator(workbook, sheet);
+			List<IdentityItem> identity = this.scanIdentityList(business,configurator, sheet);
+			wholeFlag = this.checkIdentity(business, workbook, configurator, identity); 
+			if(wholeFlag){
+				
+			}
+	}
+	
+	private void scanDuty(Business business, XSSFWorkbook workbook) throws Exception {
+		//导入职务信息	
+			Sheet sheet = workbook.getSheetAt(5);
+			DutySheetConfigurator configurator = new DutySheetConfigurator(workbook, sheet);
+			//List<DutyItem> duty = this.scanIdentityList(business,configurator, sheet);
+			/*wholeFlag = this.checkIdentity(business, workbook, configurator, duty); 
+			if(wholeFlag){
+				
+			}*/
+	}
 
 	private List<UnitItem> scanUnitList(UnitSheetConfigurator configurator, Sheet sheet) throws Exception {
 		if (null == configurator.getNameColumn()) {
@@ -243,6 +266,7 @@ class ActionInputAll extends BaseAction {
 		if (null == configurator.getMobileColumn()) {
 			throw new ExceptionMobileColumnEmpty();
 		}
+		//System.out.println(configurator.getAttributes().get(""));
 		if (configurator.getAttributes().isEmpty()) {
 			throw new ExceptionIdNumberColumnEmpty();
 		}
@@ -252,7 +276,7 @@ class ActionInputAll extends BaseAction {
 			if (null != row) {
 				String name = configurator.getCellStringValue(row.getCell(configurator.getNameColumn()));
 				String mobile = configurator.getCellStringValue(row.getCell(configurator.getMobileColumn()));
-				if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(mobile)) {
+				//if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(mobile)) {
 					PersonItem personItem = new PersonItem();
 					personItem.setRow(i);
 					name = StringUtils.trimToEmpty(name);
@@ -297,11 +321,114 @@ class ActionInputAll extends BaseAction {
 					}
 					people.add(personItem);
 					logger.debug("scan person:{}.", personItem);
-				}
+				//}
 			}
 		}
 		return people;
 	}
+	
+	private List<IdentityItem> scanIdentityList(Business business,IdentitySheetConfigurator configurator, Sheet sheet) throws Exception {
+
+		if (null == configurator.getUniqueColumn()) {
+			throw new ExceptionUniqueColumnEmpty();
+		}
+		if (null == configurator.getUnitCodeColumn()) {
+			throw new ExceptionUnitUniqueColumnEmpty();
+		}
+
+		List<IdentityItem> identity = new ArrayList<>();
+		for (int i = configurator.getFirstRow(); i <= configurator.getLastRow(); i++) {
+			Row row = sheet.getRow(i);
+			if (null != row) {
+				String unique = configurator.getCellStringValue(row.getCell(configurator.getUniqueColumn()));
+				String unitCode = configurator.getCellStringValue(row.getCell(configurator.getUnitCodeColumn()));
+				String majorStr = configurator.getCellStringValue(row.getCell(configurator.getMajorColumn()));
+				Boolean major = false;
+				if(majorStr.equals("true")){
+					major = BooleanUtils.toBooleanObject(majorStr);
+				}
+				//if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(mobile)) {
+					IdentityItem identityItem = new IdentityItem();
+					identityItem.setRow(i);
+					
+					EntityManagerContainer emc = business.entityManagerContainer();
+					Person person = null;
+					person = emc.flag(unique, Person.class);
+					if(person != null){
+						identityItem.setName(StringUtils.trimToEmpty(person.getName()));
+						identityItem.setPerson(StringUtils.trimToEmpty(person.getId()));
+						identityItem.setMajor(major);
+					}
+					Unit u = null;
+					u = emc.flag(unitCode, Unit.class);
+					if(u != null){
+						identityItem.setUnit(u.getId());
+						identityItem.setUnitLevel(u.getLevel());
+						identityItem.setUnitLevelName(u.getLevelName());
+						identityItem.setUnitName(u.getName());					
+					}
+					
+					identity.add(identityItem);
+					logger.debug("scan identity:{}.", identityItem);
+				//}
+			}
+		}
+		return identity;
+	}
+	
+	private List<DutyItem> scanDutyList(DutySheetConfigurator configurator, Sheet sheet) throws Exception {
+		if (null == configurator.getNameColumn()) {
+			throw new ExceptionDutyNameColumnEmpty();
+		}
+		if (null == configurator.getUniqueColumn()) {
+			throw new ExceptionDutyCodeColumnEmpty();
+		}
+		
+		List<DutyItem> duty = new ArrayList<>();
+		/*for (int i = configurator.getFirstRow(); i <= configurator.getLastRow(); i++) {
+			Row row = sheet.getRow(i);
+			if (null != row) {
+				String name = configurator.getCellStringValue(row.getCell(configurator.getNameColumn()));
+				String mobile = configurator.getCellStringValue(row.getCell(configurator.getMobileColumn()));
+				//if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(mobile)) {
+					DutyItem dutyItem = new DutyItem();
+					dutyItem.setRow(i);
+					name = StringUtils.trimToEmpty(name);
+					mobile = StringUtils.trimToEmpty(mobile);
+
+					dutyItem.setName(name);
+					dutyItem.setGenderType(genderType);
+					dutyItem.setMobile(mobile);
+					if (null != configurator.getEmployeeColumn()) {
+						String employee = configurator
+								.getCellStringValue(row.getCell(configurator.getEmployeeColumn()));
+						employee = StringUtils.trimToEmpty(employee);
+						dutyItem.setEmployee(employee);
+					}
+					if (null != configurator.getUniqueColumn()) {
+						String unique = configurator.getCellStringValue(row.getCell(configurator.getUniqueColumn()));
+						unique = StringUtils.trimToEmpty(unique);
+						dutyItem.setUnique(unique);
+					}
+					if (null != configurator.getMailColumn()) {
+						String mail = configurator.getCellStringValue(row.getCell(configurator.getMailColumn()));
+						mail = StringUtils.trimToEmpty(mail);
+						dutyItem.setMail(mail);
+					}
+					if (!configurator.getAttributes().isEmpty()) {
+						for (Entry<String, Integer> en : configurator.getAttributes().entrySet()) {
+							String value = configurator.getCellStringValue(row.getCell(en.getValue()));
+							value = StringUtils.trimToEmpty(value);
+							dutyItem.getAttributes().put(en.getKey(), value);
+						}
+					}
+					duty.add(dutyItem);
+					logger.debug("scan duty:{}.", dutyItem);
+				//}
+			}
+		}*/
+		return duty;
+	}
 
 	private boolean checkUnit(Business business, XSSFWorkbook workbook, UnitSheetConfigurator configurator,
 			List<UnitItem> unit) throws Exception {
@@ -353,7 +480,7 @@ class ActionInputAll extends BaseAction {
 	
 	private boolean checkPerson(Business business, XSSFWorkbook workbook, PersonSheetConfigurator configurator,
 			List<PersonItem> person) throws Exception {
-		//校验导入的组织
+		//校验导入的人员
 		EntityManagerContainer emc = business.entityManagerContainer();
 		boolean validate = true;
 		for (PersonItem o : person) {
@@ -378,7 +505,7 @@ class ActionInputAll extends BaseAction {
 				validate = false;
 				continue;
 			}
-			if(o.getAttributes().isEmpty()){
+			if(o.getAttributes().isEmpty()|| StringUtils.isEmpty(o.getAttributes().get("idNumber"))){
 				this.setPersonMemo(workbook, configurator, o, "身份证号不能为空.");
 				validate = false;
 				continue;
@@ -409,6 +536,33 @@ class ActionInputAll extends BaseAction {
 		return validate;
 	}
 	
+	private boolean checkIdentity(Business business, XSSFWorkbook workbook, IdentitySheetConfigurator configurator,
+			List<IdentityItem> identity) throws Exception {
+		//校验导入的身份
+		EntityManagerContainer emc = business.entityManagerContainer();
+		boolean validate = true;
+		for (IdentityItem o : identity) {
+			System.out.println("正在校验人员 :{}."+ o.getName());
+			if (StringUtils.isEmpty(o.getName())) {
+				this.setIdentityMemo(workbook, configurator, o, "系统不存在该人员.");
+				validate = false;
+				continue;
+			}
+			if (StringUtils.isEmpty(o.getUnit())) {
+				this.setIdentityMemo(workbook, configurator, o, "系统不存在该组织.");
+				validate = false;
+				continue;
+			}
+			
+		}
+		if (validate) {
+			for (IdentityItem o : identity) {
+				this.setIdentityMemo(workbook, configurator, o, "校验通过.");
+			}
+		}
+		return validate;
+	}
+	
 	private void persistUnit(XSSFWorkbook workbook, UnitSheetConfigurator configurator, List<UnitItem> unit) throws Exception {
 		for (List<UnitItem> list : ListTools.batch(unit, 200)) {
 			for (UnitItem o : list) {
@@ -442,6 +596,13 @@ class ActionInputAll extends BaseAction {
 		Cell cell = CellUtil.getCell(row, configurator.getMemoColumn());
 		cell.setCellValue(memo);
 	}
+	private void setIdentityMemo(XSSFWorkbook workbook, IdentitySheetConfigurator configurator, IdentityItem identityItem,
+			String memo) {
+		Sheet sheet = workbook.getSheetAt(configurator.getSheetIndex());
+		Row row = sheet.getRow(identityItem.getRow());
+		Cell cell = CellUtil.getCell(row, configurator.getMemoColumn());
+		cell.setCellValue(memo);
+	}
 	
 	private String saveUnit(String path ,Unit unit) throws Exception{
 		ActionResponse resp =  ThisApplication.context().applications()

+ 44 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/DutyItem.java

@@ -0,0 +1,44 @@
+package com.x.organization.assemble.control.jaxrs.inputperson;
+
+import com.x.base.core.project.gson.GsonPropertyObject; 
+
+public class DutyItem extends GsonPropertyObject {
+
+	private String name;
+	private String unique;
+	private String description;
+
+	private Integer row;
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getUnique() {
+		return unique;
+	}
+
+	public void setUnique(String unique) {
+		this.unique = unique;
+	}
+
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	public Integer getRow() {
+		return row;
+	}
+
+	public void setRow(Integer row) {
+		this.row = row;
+	}
+}

+ 12 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/ExceptionDutyCodeColumnEmpty.java

@@ -0,0 +1,12 @@
+package com.x.organization.assemble.control.jaxrs.inputperson;
+
+import com.x.base.core.project.exception.PromptException;
+
+class ExceptionDutyCodeColumnEmpty extends PromptException {
+
+	private static final long serialVersionUID = -2139584911736169462L;
+
+	ExceptionDutyCodeColumnEmpty() {
+		super("职务编号列不能为空.");
+	}
+}

+ 12 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/ExceptionDutyNameColumnEmpty.java

@@ -0,0 +1,12 @@
+package com.x.organization.assemble.control.jaxrs.inputperson;
+
+import com.x.base.core.project.exception.PromptException;
+
+class ExceptionDutyNameColumnEmpty extends PromptException {
+
+	private static final long serialVersionUID = -2139584911736169462L;
+
+	ExceptionDutyNameColumnEmpty() {
+		super("职务名称列不能为空.");
+	}
+}

+ 81 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/IdentityItem.java

@@ -0,0 +1,81 @@
+package com.x.organization.assemble.control.jaxrs.inputperson;
+
+import com.x.base.core.project.gson.GsonPropertyObject;
+
+public class IdentityItem extends GsonPropertyObject {
+
+	private String name;
+	private String person;
+	private String unit;
+	private String unitName;
+	private Integer unitLevel;
+	private String unitLevelName;
+	private Boolean major;
+	
+
+	private Integer row;
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public String getPerson() {
+		return person;
+	}
+
+	public void setPerson(String person) {
+		this.person = person;
+	}
+
+	public String getUnit() {
+		return unit;
+	}
+
+	public void setUnit(String unit) {
+		this.unit = unit;
+	}
+
+	public String getUnitName() {
+		return unitName;
+	}
+
+	public void setUnitName(String unitName) {
+		this.unitName = unitName;
+	}
+
+	public Integer getUnitLevel() {
+		return unitLevel;
+	}
+
+	public void setUnitLevel(Integer unitLevel) {
+		this.unitLevel = unitLevel;
+	}
+	
+	public String getUnitLevelName() {
+		return unitLevelName;
+	}
+
+	public void setUnitLevelName(String unitLevelName) {
+		this.unitLevelName = unitLevelName;
+	}
+
+	public Boolean getMajor() {
+		return major;
+	}
+
+	public void setMajor(Boolean major) {
+		this.major = major;
+	}
+
+	public Integer getRow() {
+		return row;
+	}
+
+	public void setRow(Integer row) {
+		this.row = row;
+	}
+}

+ 134 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/IdentitySheetConfigurator.java

@@ -0,0 +1,134 @@
+package com.x.organization.assemble.control.jaxrs.inputperson;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang3.BooleanUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import com.x.base.core.project.gson.GsonPropertyObject;
+
+public class IdentitySheetConfigurator extends GsonPropertyObject {
+
+	private static final Pattern attributePattern = Pattern.compile("^\\((.+?)\\)$");
+
+	private Integer sheetIndex;
+	private Integer memoColumn;
+	private Integer firstRow;
+	private Integer lastRow;
+
+	private Integer uniqueColumn;
+	private Integer unitCodeColumn;
+	private Integer dutyCodeColumn;
+	private Integer majorColumn;
+
+	private Map<String, Integer> attributes = new HashMap<>();
+
+	public IdentitySheetConfigurator(XSSFWorkbook workbook, Sheet sheet) {
+		this.sheetIndex = workbook.getSheetIndex(sheet);
+		Row row = sheet.getRow(sheet.getFirstRowNum());
+		this.firstRow = sheet.getFirstRowNum() + 1;
+		this.lastRow = sheet.getLastRowNum();
+		memoColumn = row.getLastCellNum() + 1;
+		for (int i = row.getFirstCellNum(); i <= row.getLastCellNum(); i++) {
+			Cell cell = row.getCell(i);
+			if (null != cell) {
+				String str = this.getCellStringValue(cell);
+				System.out.println("personStr = "+str);
+				if (StringUtils.isNotEmpty(str)) {
+					if (uniqueItems.contains(str)) {
+						this.uniqueColumn = i;
+					} else if (unitCodeItems.contains(str)) {
+						this.unitCodeColumn = i;
+					} else if (dutyCodeItems.contains(str)) {
+						this.dutyCodeColumn = i;
+					} else if (majorItems.contains(str)) {
+						this.majorColumn = i;
+					} else {
+						Matcher matcher = attributePattern.matcher(str);
+						if (matcher.matches()) {
+							String attribute = matcher.group(1);
+							this.attributes.put(attribute, new Integer(i));
+						}
+					}
+				}
+			}
+		}
+	}
+
+	private static List<String> uniqueItems = Arrays.asList(new String[] { "人员编号 *", "编码", "unique" });
+	private static List<String> unitCodeItems = Arrays.asList(new String[] { "组织编号 *", "组织编号", "unitCode" });
+	private static List<String> dutyCodeItems = Arrays.asList(new String[] { "职务编号", "dutyCode"});
+	private static List<String> majorItems = Arrays.asList(new String[] { "主兼职","major" });
+
+	public String getCellStringValue(Cell cell) {
+		if (null != cell) {
+			switch (cell.getCellType()) {
+			case BLANK:
+				return "";
+			case BOOLEAN:
+				return BooleanUtils.toString(cell.getBooleanCellValue(), "true", "false", "false");
+			case ERROR:
+				return "";
+			case FORMULA:
+				return "";
+			case NUMERIC:
+				Double d = cell.getNumericCellValue();
+				Long l = d.longValue();
+				if (l.doubleValue() == d) {
+					return l.toString();
+				} else {
+					return d.toString();
+				}
+			default:
+				return cell.getStringCellValue();
+			}
+		}
+		return "";
+	}
+
+	public Integer getMemoColumn() {
+		return memoColumn;
+	}
+
+	public Integer getUniqueColumn() {
+		return uniqueColumn;
+	}
+
+	public Integer getUnitCodeColumn() { 
+		return unitCodeColumn;
+	}
+
+	public Integer getDutyCodeColumn() {
+		return dutyCodeColumn;
+	}
+	
+	public Integer getMajorColumn() {
+		return majorColumn;
+	}
+
+	public Map<String, Integer> getAttributes() {
+		return attributes;
+	}
+
+	public Integer getFirstRow() {
+		return firstRow;
+	}
+
+	public Integer getLastRow() {
+		return lastRow;
+	}
+
+	public Integer getSheetIndex() {
+		return sheetIndex;
+	}
+
+}

+ 4 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/PersonSheetConfigurator.java

@@ -45,6 +45,7 @@ public class PersonSheetConfigurator extends GsonPropertyObject {
 			Cell cell = row.getCell(i);
 			if (null != cell) {
 				String str = this.getCellStringValue(cell);
+				System.out.println("personStr = "+str);
 				if (StringUtils.isNotEmpty(str)) {
 					if (nameItems.contains(str)) {
 						this.nameColumn = i;
@@ -58,10 +59,13 @@ public class PersonSheetConfigurator extends GsonPropertyObject {
 						this.mailColumn = i;
 					} else if (genderTypeItems.contains(str)) {
 						this.genderTypeColumn = i;
+					} else if ("身份证号 *".equals(str)) {
+						this.attributes.put("idNumber", new Integer(i));
 					} else {
 						Matcher matcher = attributePattern.matcher(str);
 						if (matcher.matches()) {
 							String attribute = matcher.group(1);
+							System.out.println("attribute="+attribute+"_value="+i);
 							this.attributes.put(attribute, new Integer(i));
 						}
 					}

+ 1 - 1
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/inputperson/UnitTypeSheetConfigurator.java

@@ -40,7 +40,7 @@ public class UnitTypeSheetConfigurator extends GsonPropertyObject {
 			Cell cell = row.getCell(i);
 			if (null != cell) {
 				String str = this.getCellStringValue(cell);
-				System.out.println("str="+str+"----i="+i);
+				//System.out.println("str="+str+"----i="+i);
 				if (StringUtils.isNotEmpty(str)) {
 					if (typeCodeItems.contains(str)) {
 						this.typeCodeColumn = i;