Browse Source

人员组织导入导出

luojing 5 years ago
parent
commit
8e87f4960c

+ 341 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/export/ActionExportAll.java

@@ -0,0 +1,341 @@
+package com.x.organization.assemble.control.jaxrs.export;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.servlet.http.HttpServletRequest;
+
+import com.x.base.core.project.tools.DateTools;
+import com.x.base.core.project.tools.ListTools;
+import com.x.organization.assemble.control.Business;
+import com.x.organization.core.entity.Group;
+import com.x.organization.core.entity.Identity;
+import com.x.organization.core.entity.Person;
+import com.x.organization.core.entity.PersonAttribute;
+import com.x.organization.core.entity.PersonAttribute_;
+import com.x.organization.core.entity.Unit;
+import com.x.organization.core.entity.UnitDuty;
+import com.x.organization.core.entity.UnitDuty_;
+import com.x.organization.core.entity.Unit_;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.project.http.ActionResult;
+import com.x.base.core.project.http.EffectivePerson;
+import com.x.base.core.project.jaxrs.WoFile;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+
+/**
+ * 导入的文件没有用到文件存储器,是直接放在数据库中的BLOB列
+ */
+public class ActionExportAll extends BaseAction {
+	
+	private static  Logger logger = LoggerFactory.getLogger(ActionExportAll.class);
+	List<Unit> allUnitList = new ArrayList<>();
+	List<Person> allPersonList = new ArrayList<>();
+	List<Identity> allIdentityList = new ArrayList<>();
+	List<UnitDuty> allDutyList = new ArrayList<>();
+	List<Group> allGroupList = new ArrayList<>();
+	Workbook wb = new HSSFWorkbook();
+	
+	protected ActionResult<Wo> execute( HttpServletRequest request, EffectivePerson effectivePerson, Boolean stream ) throws Exception {
+		ActionResult<Wo> result = new ActionResult<>();
+		//Workbook wb = null;
+		Wo wo = null;
+		String fileName = null;
+		Business business = null;
+		
+		
+		// 先获取需要导出的数据
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			 business = new Business(emc);
+			this.listUnit(business);
+			this.listPerson(business);
+			this.listIdentity(business);
+		} catch (Exception e) {
+			logger.info("系统在查询所有组织人员信息时发生异常。" );
+			e.printStackTrace();
+		}
+		
+		fileName = "person_export_" + DateTools.formatDate(new Date()) + ".xls";
+		//创建说明sheet
+		this.createNoticeSheet();
+		
+		// 将组织信息结果组织成EXCEL		
+		if( ListTools.isNotEmpty(allUnitList) ) {
+			this.composeUnit( business, "组织信息", allUnitList );
+		}
+		
+		// 将人员基础信息结果组织成EXCEL		
+		if( ListTools.isNotEmpty(allPersonList) ) {
+			this.composePerson( business, "人员基本信息", allPersonList );
+		}
+
+		// 将人员身份信息结果组织成EXCEL		
+		if( ListTools.isNotEmpty(allPersonList) ) {
+			this.composePerson( business, "人员身份信息", allPersonList );
+		}
+		
+		if( wb != null ) {
+			ByteArrayOutputStream bos = new ByteArrayOutputStream();
+			try {
+			    wb.write(bos);
+			    wo = new Wo(bos.toByteArray(), 
+						this.contentType(stream, fileName), 
+						this.contentDisposition(stream, fileName));
+			} finally {
+			    bos.close();
+			}
+		}		
+		result.setData(wo);
+		return result;
+	}
+	
+	private void listUnit(Business business) throws Exception {
+		List<Unit> topUnitList = new ArrayList<>();
+		topUnitList = this.listTopUnit(business);
+		if(ListTools.isNotEmpty(topUnitList)){
+			allUnitList.addAll(topUnitList);
+			for (Unit unitItem : topUnitList) {
+				List<Unit> ulist= this.listSubNested(business, unitItem);
+				if(ListTools.isNotEmpty(ulist)){
+					allUnitList.addAll(ulist);
+				}
+			}
+		}
+		
+		if(ListTools.isNotEmpty(allUnitList)){
+			allUnitList = business.unit().sort(allUnitList);
+		}
+	}
+	
+	private void listPerson(Business business) throws Exception {
+		EntityManager em = business.entityManagerContainer().get(Person.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<Person> cq = cb.createQuery(Person.class);
+		Root<Person> root = cq.from(Person.class);
+		allPersonList = em.createQuery(cq.select(root)).getResultList();
+	}
+	
+	private void listIdentity(Business business) throws Exception {
+		EntityManager em = business.entityManagerContainer().get(Identity.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
+		Root<Identity> root = cq.from(Identity.class);
+		allIdentityList = em.createQuery(cq.select(root)).getResultList();
+	}
+
+	private List<Unit> listTopUnit(Business business) throws Exception {
+		EntityManager em = business.entityManagerContainer().get(Unit.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<Unit> cq = cb.createQuery(Unit.class);
+		Root<Unit> root = cq.from(Unit.class);
+		Predicate p = cb.equal(root.get(Unit_.level), 1);
+		List<Unit> os = em.createQuery(cq.select(root).where(p)).getResultList();
+		return os;
+	}
+	
+	private List<Unit> listSubNested(Business business,Unit unit) throws Exception {
+		List<Unit> os = business.unit().listSubNestedObject(unit);
+		return os;
+	}
+	
+	private void createNoticeSheet() throws Exception {
+		
+			Row row = null;
+			// 创建新的表格
+			Sheet sheet = wb.createSheet("注意事项");
+			
+			// 先创建表头
+			row = sheet.createRow(2);
+			row.createCell(0).setCellValue("注意事项:");
+
+			row = sheet.createRow(4);
+			row.createCell(0).setCellValue("1. 表格内不要做合并(拆分)单元格操作,各列顺序不能变动,更不能删除,否则会造成数据混乱;");
+			
+			row = sheet.createRow(6);
+			row.createCell(0).setCellValue("2. * 为必填项");
+			
+			row = sheet.createRow(8);
+			row.createCell(0).setCellValue("3. 如有特殊要求的格式,详见列名批注;");
+			
+			row = sheet.createRow(10);
+			row.createCell(0).setCellValue("4. 表中示例数据用于示范,实际导入时需删除;");
+			
+			row = sheet.createRow(12);
+			row.createCell(0).setCellValue("5. 每个Sheet页顺序不能变动,本Sheet页不能删除。");
+
+	}
+	
+	private void composeUnit(Business business, String sheetName, List<Unit> unitList) throws Exception {
+		Unit unit = null;
+		EntityManagerContainer em = business.entityManagerContainer();
+		
+		Row row = null;
+		if (ListTools.isNotEmpty(unitList) ) {
+			// 创建新的表格
+			Sheet sheet = wb.createSheet(sheetName);
+			
+			// 先创建表头
+			row = sheet.createRow(0);
+			row.createCell(0).setCellValue("组织名称 *");
+			row.createCell(1).setCellValue("组织编号 *");
+			row.createCell(2).setCellValue("组织级别名称 *");
+			row.createCell(3).setCellValue("上级组织编号");
+			row.createCell(4).setCellValue("组织代字");
+			row.createCell(5).setCellValue("描述");
+			row.createCell(6).setCellValue("排序号");
+
+			for (int i = 0; i < unitList.size(); i++) {
+				unit = unitList.get(i);
+				row = sheet.createRow(i + 1);
+				row.createCell(0).setCellValue(unit.getName());
+				row.createCell(1).setCellValue(unit.getUnique());
+				if(ListTools.isNotEmpty(unit.getTypeList())){
+					row.createCell(2).setCellValue(unit.getTypeList().get(0));
+				}else{
+					row.createCell(2).setCellValue("");
+				}
+				
+				String superior = unit.getSuperior();
+				if(StringUtils.isEmpty(superior)){
+					row.createCell(3).setCellValue("");
+				}else{
+					Unit u = null;
+					u = em.flag(unit.getSuperior(), Unit.class);
+					if(u != null){
+						row.createCell(3).setCellValue(u.getUnique());
+					}else{
+						row.createCell(3).setCellValue(unit.getSuperior());
+					}
+					
+				}
+				row.createCell(4).setCellValue(unit.getShortName());
+				row.createCell(5).setCellValue(unit.getDescription());
+				row.createCell(6).setCellValue(unit.getOrderNumber()+"");
+				
+			}
+		}
+	}
+	
+	private void composePerson(Business business, String sheetName, List<Person> personList) throws Exception {
+		Person person = null;
+		
+		Row row = null;
+		if (ListTools.isNotEmpty(personList) ) {
+			// 创建新的表格
+			Sheet sheet = wb.createSheet(sheetName);
+			
+			// 先创建表头
+			row = sheet.createRow(0);
+			row.createCell(0).setCellValue("人员行姓名 *");
+			row.createCell(1).setCellValue("人员编号 *");
+			row.createCell(2).setCellValue("登录账号 *");
+			row.createCell(3).setCellValue("手机号码 *");
+			row.createCell(4).setCellValue("身份证号 *");
+			row.createCell(5).setCellValue("性别");
+			row.createCell(6).setCellValue("邮件");
+
+			for (int i = 0; i < personList.size(); i++) {
+				person = personList.get(i);
+				row = sheet.createRow(i + 1);
+				row.createCell(0).setCellValue(person.getName());
+				row.createCell(1).setCellValue(person.getUnique());
+				row.createCell(2).setCellValue(person.getEmployee());
+				row.createCell(3).setCellValue(person.getMobile());
+				
+				if(StringUtils.isNotEmpty(person.getId())){
+					List<PersonAttribute> personAttributeList = this.listAttributeWithPerson(business,person.getId());
+					if(ListTools.isNotEmpty(personAttributeList)){
+						for(PersonAttribute o : personAttributeList){
+							if("idNumber".equals(o.getName())){
+								row.createCell(4).setCellValue(o.getAttributeList().get(0));
+							}
+						}
+					}
+				}
+				row.createCell(5).setCellValue(person.getGenderType().toString());
+				row.createCell(6).setCellValue(person.getMail());
+				
+			}
+		}
+	}
+	
+	private void composeIdentity(Business business, String sheetName, List<Identity> identityList) throws Exception {
+		Identity identity = null;
+		EntityManagerContainer emc = business.entityManagerContainer();
+		Row row = null;
+		if (ListTools.isNotEmpty(identityList) ) {
+			// 创建新的表格
+			Sheet sheet = wb.createSheet(sheetName);
+			
+			// 先创建表头
+			row = sheet.createRow(0);
+			row.createCell(0).setCellValue("人员编号 *");
+			row.createCell(1).setCellValue("组织编号 *");
+			row.createCell(2).setCellValue("登录账号 *");
+			row.createCell(3).setCellValue("职务编号");
+			row.createCell(4).setCellValue("主兼职");
+
+			for (int i = 0; i < identityList.size(); i++) {
+				identity = identityList.get(i);
+				row = sheet.createRow(i + 1);
+				Person person = emc.flag(identity.getPerson(), Person.class);
+				Unit unit = emc.flag(identity.getUnit(), Unit.class);
+				if(person != null){
+					row.createCell(0).setCellValue(person.getUnique());
+					if(unit != null){
+						row.createCell(1).setCellValue(unit.getUnique());
+						List<UnitDuty> unitDutyList =  this.listDutyWithIdentity(business,identity.getId());
+						if(ListTools.isNotEmpty(unitDutyList)){
+							row.createCell(2).setCellValue("");
+						}
+						row.createCell(3).setCellValue("");
+					}
+				}	
+				
+			}
+		}
+	}
+	
+	private List<PersonAttribute> listAttributeWithPerson(Business business,String personId) throws Exception{
+		EntityManager em = business.entityManagerContainer().get(PersonAttribute.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<PersonAttribute> cq = cb.createQuery(PersonAttribute.class);
+		Root<PersonAttribute> root = cq.from(PersonAttribute.class);
+		Predicate p = cb.equal(root.get(PersonAttribute_.person), personId);
+		List<PersonAttribute> os = em.createQuery(cq.select(root).where(p)).getResultList();
+		return os;
+	}
+	
+	private List<UnitDuty> listDutyWithIdentity(Business business,String identityId) throws Exception{
+		EntityManager em = business.entityManagerContainer().get(UnitDuty.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<UnitDuty> cq = cb.createQuery(UnitDuty.class);
+		Root<UnitDuty> root = cq.from(UnitDuty.class);
+		Predicate p = cb.isMember(identityId, root.get(UnitDuty_.identityList));
+		List<UnitDuty> os = em.createQuery(cq.select(root).where(p)).getResultList();
+		return os;
+	}
+
+	public static class Wo extends WoFile {
+		public Wo(byte[] bytes, String contentType, String contentDisposition) {
+			super(bytes, contentType, contentDisposition);
+		}
+	}
+
+}

+ 18 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/export/ExportAction.java

@@ -62,4 +62,22 @@ public class ExportAction extends StandardJaxrsAction {
 		}
 		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
 	}
+	
+	@JaxrsMethodDescribe(value = "导出人员组织信息", action = ActionExportAll.class)
+	@GET
+	@Path("export/all")
+	@Consumes(MediaType.APPLICATION_JSON)
+	public void exportAllPerson(@Suspended final AsyncResponse asyncResponse, 
+			@Context HttpServletRequest request, 
+			@JaxrsParameterDescribe("用.APPLICATION_OCTET_STREAM头输出") @PathParam("stream") Boolean stream) {
+		ActionResult<ActionExportAll.Wo> result = new ActionResult<>();
+		EffectivePerson effectivePerson = this.effectivePerson(request);
+		try {
+			result = new ActionExportAll().execute(request, effectivePerson, stream);
+		} catch (Exception e) {
+			logger.error(e, effectivePerson, request, null);
+			result.error(e);
+		}
+		asyncResponse.resume(ResponseFactory.getEntityTagActionResultResponse(request, result));
+	}
 }

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

@@ -86,10 +86,12 @@ class ActionInputAll extends BaseAction {
 	List<IdentityItem> identity = new ArrayList<>();
 	List<DutyItem> duty = new ArrayList<>();
 	List<UnitDuty> editduty = new ArrayList<>();
+	List<GroupItem> group = new ArrayList<>();
 	UnitSheetConfigurator configuratorUnit = null;
 	PersonSheetConfigurator configuratorPerson = null;
 	IdentitySheetConfigurator configuratorIdentity = null;
 	DutySheetConfigurator configuratorDuty = null;
+	GroupSheetConfigurator configuratorGroup = null;
 
 	ActionResult<Wo> execute(EffectivePerson effectivePerson, byte[] bytes, FormDataContentDisposition disposition)
 			throws Exception {
@@ -99,8 +101,8 @@ class ActionInputAll extends BaseAction {
 				ByteArrayOutputStream os = new ByteArrayOutputStream()) { 
 			Business business = new Business(emc);
 			ActionResult<Wo> result = new ActionResult<>();
-			this.scan(business, workbook);
-			String name = "person_" + DateTools.formatDate(new Date()) + ".xlsx";
+			this.scanUnit(business, workbook);
+			String name = "person_input_" + DateTools.formatDate(new Date()) + ".xlsx";
 			workbook.write(os);
 			CacheInputResult cacheInputResult = new CacheInputResult();
 			cacheInputResult.setName(name);
@@ -154,7 +156,7 @@ class ActionInputAll extends BaseAction {
 	
 	private void scanUnit(Business business, XSSFWorkbook workbook) throws Exception {
 	//导入组织信息
-			Sheet sheet = workbook.getSheetAt(2);
+			Sheet sheet = workbook.getSheetAt(1);
 			configuratorUnit = new UnitSheetConfigurator(workbook, sheet);
 			unit = this.scanUnitList(configuratorUnit, sheet);
 			wholeFlag = this.checkUnit(business, workbook, configuratorUnit, unit); 
@@ -166,7 +168,7 @@ class ActionInputAll extends BaseAction {
 	
 	private void scanPerson(Business business, XSSFWorkbook workbook) throws Exception {
 	//导入人员信息	
-		Sheet sheet = workbook.getSheetAt(3);
+		Sheet sheet = workbook.getSheetAt(2);
 		configuratorPerson = new PersonSheetConfigurator(workbook, sheet);
 		person = this.scanPersonList(configuratorPerson, sheet);
 		wholeFlag = this.checkPerson(business, workbook, configuratorPerson, person); 
@@ -177,22 +179,31 @@ class ActionInputAll extends BaseAction {
 	
 	private void scanIdentity(Business business, XSSFWorkbook workbook ,List<PersonItem> persons,List<UnitItem> units) throws Exception {
 		//导入身份信息	
-			Sheet sheet = workbook.getSheetAt(4);
+			Sheet sheet = workbook.getSheetAt(3);
 			configuratorIdentity = new IdentitySheetConfigurator(workbook, sheet);
 			//校验导入的职务信息
 			this.scanDuty(business,workbook);
 			if(!dutyFlag){
 				wholeFlag = this.checkIdentity(business, workbook, configuratorIdentity, sheet,persons,units); 
 				if(wholeFlag){
-						//保存组织,人员
-						this.persistUnit(workbook, configuratorUnit, unit);
-						this.persistPerson(workbook, configuratorPerson, person);
-						identity = this.scanIdentityList(business,configuratorIdentity, sheet);
-						//保存身份
-						this.persistIdentity(workbook, configuratorIdentity, identity);
-						//保存职务
-						duty = this.scanDutyList(business,configuratorIdentity, sheet);
-						this.persistDuty(workbook, configuratorDuty, duty);
+						//校验群组
+						wholeFlag = this.checkGroup(business,workbook,person,unit);
+						
+						if(wholeFlag){
+							//保存组织,人员
+							this.persistUnit(workbook, configuratorUnit, unit);
+							this.persistPerson(business,workbook, configuratorPerson, person);
+							identity = this.scanIdentityList(business,configuratorIdentity, sheet);
+							//保存身份
+							this.persistIdentity(workbook, configuratorIdentity, identity);
+							//保存职务
+							duty = this.scanDutyList(business,configuratorIdentity, sheet);
+							this.persistDuty(workbook, configuratorDuty, duty);
+							
+							//保存群组
+							this.scanGroup(business,workbook,person,unit);
+							this.persistGroup(business,workbook, configuratorGroup, group);
+						}
 													
 				}
 			}
@@ -202,7 +213,7 @@ class ActionInputAll extends BaseAction {
 	
 	private void scanDuty(Business business, XSSFWorkbook workbook) throws Exception  {
 		//导入职务信息	
-			Sheet sheet = workbook.getSheetAt(5);
+			Sheet sheet = workbook.getSheetAt(4);
 			DutySheetConfigurator configurator = new DutySheetConfigurator(workbook, sheet);
 			for (int i = configurator.getFirstRow(); i <= configurator.getLastRow(); i++) {
 				Row row = sheet.getRow(i);
@@ -219,6 +230,13 @@ class ActionInputAll extends BaseAction {
 				}
 			}
 	}
+	private void scanGroup(Business business, XSSFWorkbook workbook ,List<PersonItem> persons,List<UnitItem> units) throws Exception {
+		//导入群组信息	
+			Sheet sheet = workbook.getSheetAt(5);
+			configuratorGroup = new GroupSheetConfigurator(workbook, sheet);
+			group = this.scanGroupList(business,configuratorGroup, sheet);
+		
+	}
 
 	private List<UnitItem> scanUnitList(UnitSheetConfigurator configurator, Sheet sheet) throws Exception {
 		if (null == configurator.getNameColumn()) {
@@ -254,8 +272,8 @@ class ActionInputAll extends BaseAction {
 					if (null != configurator.getUnitTypeColumn()) {
 						String typeList = configurator.getCellStringValue(row.getCell(configurator.getUnitTypeColumn()));
 						typeList = StringUtils.trimToEmpty(typeList);
-						typeList = typeMap.get(typeList);
-						System.out.println("typeListx="+typeList);
+						/*typeList = typeMap.get(typeList);
+						System.out.println("typeListx="+typeList);*/
 						List<String> typeListStr = new ArrayList<>();
 						typeListStr.add(typeList);
 						unitItem.setTypeList(typeListStr);
@@ -398,11 +416,11 @@ class ActionInputAll extends BaseAction {
 					identityItem.setMajor(major);
 					
 					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()));					
+					Person personobj = null;
+					personobj = emc.flag(unique, Person.class);
+					if(personobj != null){
+						identityItem.setName(StringUtils.trimToEmpty(personobj.getName()));
+						identityItem.setPerson(StringUtils.trimToEmpty(personobj.getId()));					
 					}
 					
 					Unit u = null;
@@ -422,6 +440,61 @@ class ActionInputAll extends BaseAction {
 		return identitys;
 	}
 	
+	private List<GroupItem> scanGroupList(Business business,GroupSheetConfigurator configurator, Sheet sheet) throws Exception {
+
+		List<GroupItem> groups = 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 unique = configurator.getCellStringValue(row.getCell(configurator.getUniqueColumn()));
+				String personCode = configurator.getCellStringValue(row.getCell(configurator.getPersonCodeColumn()));
+				String unitCode = configurator.getCellStringValue(row.getCell(configurator.getUnitCodeColumn()));
+				String groupCode = configurator.getCellStringValue(row.getCell(configurator.getGroupCodeColumn()));
+				
+				//if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(mobile)) {
+					GroupItem groupItem = new GroupItem();
+					groupItem.setRow(i);
+					groupItem.setPersonCode(personCode);
+					groupItem.setUnitCode(unitCode);
+					groupItem.setName(name);
+					groupItem.setUnique(unique);
+					
+					EntityManagerContainer emc = business.entityManagerContainer();
+					Person personobj = null;
+					personobj = emc.flag(personCode, Person.class);
+					if(personobj != null){
+						List<String> personList = new ArrayList<>();
+						personList.add(personobj.getId());
+						groupItem.setPersonList(personList);			
+					}
+					
+					Unit u = null;
+					u = emc.flag(unitCode, Unit.class);
+					
+					if(u != null){
+						List<String> unitList = new ArrayList<>();
+						unitList.add(u.getId());
+						groupItem.setUnitList(unitList);
+					}
+					if(StringUtils.isNoneEmpty(groupCode)){
+						groupItem.setGroupCode(groupCode);
+						Group groupobj = emc.flag(groupCode, Group.class);
+						 if(groupobj != null){
+							 List<String> groupList = new ArrayList<>();
+							 groupList.add(groupobj.getId());
+							 groupItem.setGroupList(groupList);
+						 }
+					}
+					
+					groups.add(groupItem);
+					logger.debug("scan group:{}.", groupItem);
+				//}
+			}
+		}
+		return groups;
+	}
+	
 	private List<DutyItem> scanDutyList(Business business,IdentitySheetConfigurator configurator, Sheet sheet) throws Exception {
 		if (null == configurator.getDutyCodeColumn()) {
 			throw new ExceptionDutyCodeColumnEmpty();
@@ -504,7 +577,7 @@ class ActionInputAll extends BaseAction {
 				continue;
 			}
 			if (ListTools.isEmpty(o.getTypeList())) {
-				this.setUnitMemo(workbook, configurator, o, "组织级别编号不能为空.");
+				this.setUnitMemo(workbook, configurator, o, "组织级别名称不能为空.");
 				validate = false;
 				continue;
 			}
@@ -682,6 +755,97 @@ class ActionInputAll extends BaseAction {
 		return validate;
 	}
 	
+	private boolean checkGroup(Business business, XSSFWorkbook workbook, List<PersonItem> persons,List<UnitItem> units) throws Exception {
+		//校验导入的群组
+		Sheet sheet = workbook.getSheetAt(5);
+		configuratorGroup = new GroupSheetConfigurator(workbook, sheet);
+		GroupSheetConfigurator configurator = configuratorGroup;
+		
+		if (null == configurator.getNameColumn()) {
+			throw new ExceptionGroupNameColumnEmpty();
+		}
+		if (null == configurator.getUniqueColumn()) {
+			throw new ExceptionGroupCodeColumnEmpty();
+		}
+		
+		List<GroupItem> groups = new ArrayList<>();	
+		EntityManagerContainer emc = business.entityManagerContainer();
+		boolean validate = true;
+		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 unique = configurator.getCellStringValue(row.getCell(configurator.getUniqueColumn()));
+				String personCode = configurator.getCellStringValue(row.getCell(configurator.getPersonCodeColumn()));
+				String unitCode = configurator.getCellStringValue(row.getCell(configurator.getUnitCodeColumn()));
+				
+				System.out.println("正在校验群组 :{}."+ name);
+				boolean personcheck = false;
+				boolean unitcheck = false;
+				GroupItem groupItem = new GroupItem();
+				groupItem.setRow(i);
+				groups.add(groupItem);
+				if (StringUtils.isEmpty(name)) {
+					this.setGroupMemo(workbook, configurator, groupItem, "群组名称不能为空.");
+					validate = false;
+					continue;
+				}
+				if (StringUtils.isEmpty(unique)) {
+					this.setGroupMemo(workbook, configurator, groupItem, "群组编号不能为空.");
+					validate = false;
+					continue;
+				}
+				
+				Person person = null;
+				person = emc.flag(personCode, Person.class);
+				if(person != null){
+					personcheck = true;
+				}else{
+					for (PersonItem personItem : persons) {
+						if (StringUtils.isNotEmpty(personItem.getUnique()) && StringUtils.equals(personItem.getUnique(), personCode)) {
+							personcheck = true;
+						}
+					}
+				}
+				
+				if(StringUtils.isEmpty(unitCode)){
+					unitcheck = true;
+				}else{
+					Unit unit = null;
+					unit = emc.flag(unitCode, Unit.class);
+					if(unit != null){
+						unitcheck = true;
+					}else{
+						for (UnitItem unitItem : units) {
+							if (StringUtils.isNotEmpty(unitItem.getUnique()) && StringUtils.equals(unitItem.getUnique(), unitCode)) {
+								unitcheck = true;
+							}
+						}
+					}
+				}
+				
+				
+				if (!personcheck) {
+					this.setGroupMemo(workbook, configurator, groupItem, "系统不存在该人员.");
+					validate = false;
+					continue;
+				}
+				if (!unitcheck) {
+					this.setGroupMemo(workbook, configurator, groupItem, "系统不存在该组织.");
+					validate = false;
+					continue;
+				}
+				
+			}
+		}
+		
+		if (validate) {
+			for (GroupItem o : groups){
+				this.setGroupMemo(workbook, configurator, o, "校验通过.");
+			}
+		}
+		return validate;
+	}
 	
 	
 	private void persistUnit(XSSFWorkbook workbook, UnitSheetConfigurator configurator, List<UnitItem> unitItems) throws Exception {
@@ -702,7 +866,8 @@ class ActionInputAll extends BaseAction {
 			}
 		}
 	}
-	private void persistPerson(XSSFWorkbook workbook, PersonSheetConfigurator configurator, List<PersonItem> personItems) throws Exception {
+	private void persistPerson(Business business,XSSFWorkbook workbook, PersonSheetConfigurator configurator, List<PersonItem> personItems) throws Exception {
+		EntityManagerContainer emc = business.entityManagerContainer();
 		for (List<PersonItem> list : ListTools.batch(personItems, 200)) {
 			for (PersonItem o : list) {
 				logger.debug("正在保存人员:{}.", o.getName());
@@ -712,6 +877,21 @@ class ActionInputAll extends BaseAction {
 				String resp = this.savePerson("person", personObject);
 				System.out.println("respMass="+resp);
 				if("".equals(resp)){
+					if((!o.getAttributes().isEmpty()) && o.getAttributes().containsKey("idNumber") && StringUtils.isNotEmpty(o.getAttributes().get("idNumber"))){
+						
+						Person person = null;
+						person = emc.flag(o.getUnique(), Person.class);
+						if(person != null){
+							PersonAttribute personAttribute = new PersonAttribute();
+							personAttribute.setName("idNumber");
+							List<String> attributeList = new ArrayList<>();
+							attributeList.add(o.getAttributes().get("idNumber"));
+							personAttribute.setAttributeList(attributeList);
+							personAttribute.setPerson(person.getId());
+							String respAttribute = this.savePersonAttribute("personattribute",personAttribute);
+							System.out.println("respAttribute="+respAttribute);
+						}
+					}
 					this.setPersonMemo(workbook, configurator, o, "已导入.");
 				}else{
 					this.setPersonMemo(workbook, configurator, o, resp);
@@ -744,7 +924,6 @@ class ActionInputAll extends BaseAction {
 		for (List<DutyItem> list : ListTools.batch(dutyItems, 200)) {
 			for (DutyItem o : list) {
 				if(StringUtils.isNotEmpty(o.getUnique()) && this.getDuty("unitduty/list/unit/"+o.getUnit(),o.getUnique(),o.getIdentityList())){
-					System.out.println("x11122345");
 				}else{
 					logger.debug("正在保存职务:{}.", o.getName());
 					UnitDuty dutyObject = new UnitDuty();
@@ -762,6 +941,72 @@ class ActionInputAll extends BaseAction {
 			}
 		}
 	}
+	
+	private void persistGroup(Business business,XSSFWorkbook workbook, GroupSheetConfigurator configurator, List<GroupItem> groupItems) throws Exception {
+		EntityManagerContainer emc = business.entityManagerContainer();
+		for (List<GroupItem> list : ListTools.batch(groupItems, 200)) {
+			for (GroupItem o : list) {
+				Group g = emc.flag(o.getUnique(), Group.class);
+				if(g != null){
+					List<String> personList = g.getPersonList();
+					List<String> unitList = g.getUnitList();
+					List<String> groupList = g.getGroupList();
+					if(ListTools.isNotEmpty(o.getPersonList())){
+						personList.addAll(o.getPersonList());
+					}
+					if(ListTools.isNotEmpty(o.getUnitList())){
+						unitList.addAll(o.getUnitList());
+					}
+					if(ListTools.isNotEmpty(o.getGroupList())){
+						groupList.addAll(o.getGroupList());
+					}
+					
+					g.setPersonList(personList);
+					g.setUnitList(unitList);
+					g.setGroupList(groupList);
+					
+					String respEdit = this.editGroup("group/"+g.getId(), g);
+					System.out.println("respEditMass="+respEdit);
+					if("".equals(respEdit)){
+						this.setGroupMemo(workbook, configurator, o, "已导入.");
+					}else{
+						this.setGroupMemo(workbook, configurator, o, respEdit);
+					}
+					
+				}else{
+					logger.debug("正在保存群组:{}.", o.getName());
+					if(StringUtils.isNotEmpty(o.getGroupCode())){
+						List<String> groupList = o.getGroupList();
+						if(ListTools.isEmpty(groupList)){
+							Group groupobj = emc.flag(o.getGroupCode(), Group.class);
+							if(groupobj != null){
+								List<String> glist = new ArrayList<>();
+								glist.add(groupobj.getId());
+								 o.setGroupList(glist);
+							}
+						}
+					}
+					
+					Group groupObject = new Group();
+					o.copyTo(groupObject);
+					
+					String resp = this.saveGroup("group", groupObject);
+					System.out.println("respMass="+resp);
+					if("".equals(resp)){
+						this.setGroupMemo(workbook, configurator, o, "已导入.");
+					}else{
+						this.setGroupMemo(workbook, configurator, o, resp);
+					}
+				}
+				
+			}
+		}
+		/*for(List<Group> unitlist : ListTools.batch(group, 200)){
+			for (Group uo : unitlist) {
+				this.editGroup("group/"+uo.getId(),uo);
+			}
+		}*/
+	}
 
 	private void setUnitMemo(XSSFWorkbook workbook, UnitSheetConfigurator configurator, UnitItem unitItem,
 			String memo) {
@@ -785,6 +1030,14 @@ class ActionInputAll extends BaseAction {
 		cell.setCellValue(memo);
 	}
 	
+	private void setGroupMemo(XSSFWorkbook workbook, GroupSheetConfigurator configurator, GroupItem groupItem,
+			String memo) {
+		Sheet sheet = workbook.getSheetAt(configurator.getSheetIndex());
+		Row row = sheet.getRow(groupItem.getRow());
+		Cell cell = CellUtil.getCell(row, configurator.getMemoColumn());
+		cell.setCellValue(memo);
+	}
+	
 	private String saveUnit(String path ,Unit unitObj) throws Exception{
 		ActionResponse resp =  ThisApplication.context().applications()
 				.postQuery(x_organization_assemble_control.class, path, unitObj);
@@ -797,6 +1050,12 @@ class ActionInputAll extends BaseAction {
 		return resp.getMessage();
 	}
 	
+	private String savePersonAttribute(String path ,PersonAttribute personAttribute) throws Exception{
+		ActionResponse resp =  ThisApplication.context().applications()
+				.postQuery(x_organization_assemble_control.class, path, personAttribute);
+		return resp.getMessage();
+	}
+	
 	private String saveIdentity(String path ,Identity identityObj) throws Exception{
 		ActionResponse resp =  ThisApplication.context().applications()
 				.postQuery(x_organization_assemble_control.class, path, identityObj);
@@ -815,6 +1074,18 @@ class ActionInputAll extends BaseAction {
 		return resp.getMessage();
 	}
 	
+	private String saveGroup(String path ,Group groupObj) throws Exception{
+		ActionResponse resp =  ThisApplication.context().applications()
+				.postQuery(x_organization_assemble_control.class, path, groupObj);
+		return resp.getMessage();
+	}
+	
+	private String editGroup(String path ,Group groupObj) throws Exception{
+		ActionResponse resp =  ThisApplication.context().applications()
+				.putQuery(x_organization_assemble_control.class, path, groupObj);
+		return resp.getMessage();
+	}
+	
 	private boolean getDuty(String path, String dutyCode,List<String> identityLists) throws Exception{
 		boolean checkduty = false;
 		System.out.println("getDuty_path="+path);

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

@@ -10,8 +10,8 @@ import net.sf.ehcache.Ehcache;
 
 abstract class BaseAction extends StandardJaxrsAction {
 
-	protected static List<String> genderTypeFemaleItems = Arrays.asList(new String[] { "f", "女", "female" });
-	protected static List<String> genderTypeMaleItems = Arrays.asList(new String[] { "m", "男", "male" });
+	protected static List<String> genderTypeFemaleItems = Arrays.asList(new String[] { "f","F" ,"女", "female" });
+	protected static List<String> genderTypeMaleItems = Arrays.asList(new String[] { "m", "M", "男", "male" });
 
 	protected Ehcache cache = ApplicationCache.instance().getCache(CacheInputResult.class);
 

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

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

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

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

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

@@ -0,0 +1,102 @@
+package com.x.organization.assemble.control.jaxrs.inputperson;
+
+import java.util.List;
+
+import com.x.base.core.project.gson.GsonPropertyObject;
+
+public class GroupItem extends GsonPropertyObject {
+
+	private String name;
+	private String unique;
+	private String description;
+	private List<String> personList;
+	private List<String> groupList;
+	private List<String> unitList;
+	
+	private String personCode;
+	private String unitCode;
+	private String groupCode;
+	
+
+	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 getPersonCode() {
+		return personCode;
+	}
+
+	public void setPersonCode(String personCode) {
+		this.personCode = personCode;
+	}
+	
+	public String getUnitCode() {
+		return unitCode;
+	}
+
+	public void setUnitCode(String unitCode) {
+		this.unitCode = unitCode;
+	}
+	
+	public String getGroupCode() {
+		return groupCode;
+	}
+
+	public void setGroupCode(String groupCode) {
+		this.groupCode = groupCode;
+	}
+	
+	public List<String> getPersonList() {
+		return personList;
+	}
+
+	public void setPersonList(List<String> personList) {
+		this.personList = personList;
+	}
+
+	public List<String> getGroupList() {
+		return groupList;
+	}
+
+	public void setGroupList(List<String> groupList) {
+		this.groupList = groupList;
+	}
+	
+	public String getDescription() {
+		return description;
+	}
+
+	public void setDescription(String description) {
+		this.description = description;
+	}
+
+	public List<String> getUnitList() {
+		return unitList;
+	}
+
+	public void setUnitList(List<String> unitList) {
+		this.unitList = unitList;
+	}
+
+	public Integer getRow() {
+		return row;
+	}
+
+	public void setRow(Integer row) {
+		this.row = row;
+	}
+}

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

@@ -0,0 +1,150 @@
+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 GroupSheetConfigurator extends GsonPropertyObject {
+
+	private static final Pattern attributePattern = Pattern.compile("^\\((.+?)\\)$");
+
+	private Integer sheetIndex;
+	private Integer memoColumn;
+	private Integer firstRow;
+	private Integer lastRow;
+
+	private Integer nameColumn;
+	private Integer uniqueColumn;
+	private Integer personCodeColumn;
+	private Integer unitCodeColumn;
+	private Integer groupCodeColumn;
+	private Integer descriptionColumn;
+
+	private Map<String, Integer> attributes = new HashMap<>();
+
+	public GroupSheetConfigurator(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("str="+str+"----i="+i);
+				if (StringUtils.isNotEmpty(str)) {
+					if (uniqueItems.contains(str)) {
+						this.uniqueColumn = i;
+					} else if (nameItems.contains(str)) {
+						this.nameColumn = i;
+					}else if (personCodeItems.contains(str)) {
+						this.personCodeColumn = i;
+					}else if (unitCodeItems.contains(str)) {
+						this.unitCodeColumn = i;
+					}else if (groupCodeItems.contains(str)) {
+						this.groupCodeColumn = i;
+					}else if (descriptionItems.contains(str)) {
+						this.descriptionColumn = 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> nameItems = Arrays.asList(new String[] { "群组名称 *", "name" });
+	private static List<String> personCodeItems = Arrays.asList(new String[] { "人员编号", "personCode" });
+	private static List<String> unitCodeItems = Arrays.asList(new String[] { "组织编号", "unitCode" });
+	private static List<String> groupCodeItems = Arrays.asList(new String[] { "群组编号", "groupCode" });
+	private static List<String> descriptionItems = Arrays.asList(new String[] { "描述","群组描述", "description" });
+
+	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 getNameColumn() {
+		return nameColumn;
+	}
+	
+	public Integer getPersonCodeColumn() {
+		return personCodeColumn;
+	}
+	
+	public Integer getUnitCodeColumn() {
+		return unitCodeColumn;
+	}
+	
+	public Integer getGroupCodeColumn() {
+		return groupCodeColumn;
+	}
+	
+	public Integer getDescriptionColumn() {
+		return descriptionColumn;
+	}
+
+	public Map<String, Integer> getAttributes() {
+		return attributes;
+	}
+
+	public Integer getFirstRow() {
+		return firstRow;
+	}
+
+	public Integer getLastRow() {
+		return lastRow;
+	}
+
+	public Integer getSheetIndex() {
+		return sheetIndex;
+	}
+
+}

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

@@ -75,7 +75,7 @@ public class UnitSheetConfigurator extends GsonPropertyObject {
 	private static List<String> nameItems = Arrays.asList(new String[] { "组织名称 *", "name" });
 	private static List<String> shortNameItems = Arrays.asList(new String[] { "组织代字", "代字", "shortName" });
 	private static List<String> uniqueItems = Arrays.asList(new String[] { "编号", "组织编号 *", "unique" });
-	private static List<String> unitTypeItems = Arrays.asList(new String[] { "组织级别编号 *", "级别编号", "unitType" });
+	private static List<String> unitTypeItems = Arrays.asList(new String[] { "组织级别编号 *", "组织级别名称 *", "unitType" });
 	private static List<String> superiorItems = Arrays.asList(new String[] { "上级组织", "上级组织编号", "superior"});
 	private static List<String> orderNumberItems = Arrays.asList(new String[] { "排序", "排序号", "orderNumber" });
 	private static List<String> descriptionItems = Arrays.asList(new String[] { "描述", "备注", "description" });