ActionCreate.java 2.7 KB
Newer Older
L
luojing 已提交
1 2 3 4
package com.x.organization.assemble.control.jaxrs.personcard;

import java.util.Date;

O
o2sword 已提交
5
import com.x.base.core.project.cache.CacheManager;
L
luojing 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
import org.apache.commons.lang3.StringUtils;

import com.google.gson.JsonElement;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.CheckPersistType;
import com.x.base.core.project.bean.WrapCopier;
import com.x.base.core.project.bean.WrapCopierFactory;
import com.x.base.core.project.http.ActionResult;
import com.x.base.core.project.http.EffectivePerson;
import com.x.base.core.project.jaxrs.WoId;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
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.assemble.control.message.OrgMessageFactory;
import com.x.organization.core.entity.PersonCard;


class ActionCreate extends BaseAction {
	private static Logger logger = LoggerFactory.getLogger(ActionCreate.class);
	ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			ActionResult<Wo> result = new ActionResult<>();
			
			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
			Business business = new Business(emc);
			PersonCard personCard = new PersonCard();
			
			if (StringUtils.isEmpty(wi.getName())) {
				throw new ExceptionNameEmpty(); 
			}  
			
			Wi.copier.copy(wi, personCard);
			personCard.setDistinguishedName(effectivePerson.getDistinguishedName());
			if(personCard.getGroupType().equals("")){
				personCard.setGroupType("默认分组");
			}
			personCard.setInputTime(DateTools.format(new Date()));
		
			emc.beginTransaction(PersonCard.class);
			emc.persist(personCard, CheckPersistType.all);
			emc.commit();
O
o2sword 已提交
51
			CacheManager.notify(PersonCard.class);
L
luojing 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
			
			/**创建 组织变更org消息通信 */
			OrgMessageFactory  orgMessageFactory = new OrgMessageFactory();
			orgMessageFactory.createMessageCommunicate("add", "personpersonal", personCard, effectivePerson);
			
			Wo wo = new Wo();
			wo.setId(personCard.getId());
			result.setData(wo);
			return result;
		}
	}

	public static class Wo extends WoId {
	}

	public static class Wi extends PersonCard {

		private static final long serialVersionUID = -6314932919066148113L;

		static WrapCopier<Wi, PersonCard> copier = WrapCopierFactory.wi(Wi.class, PersonCard.class, null,
				ListTools.toList(JpaObject.FieldsUnmodify, "pinyin", "pinyinInitial","distinguishedName","inputTime"));

	}
	


}