⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 personmanagerimpl.java

📁 基于java的组号查询模块
💻 JAVA
字号:
/**
 * 
 */
package com.lily.dap.service.organize.impl;

import java.util.List;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.lily.dap.model.QueryCondition;
import com.lily.dap.model.organize.Person;
import com.lily.dap.model.organize.Post;
import com.lily.dap.model.organize.PostPerson;
import com.lily.dap.service.core.BaseManager;
import com.lily.dap.service.core.VerifyUtil;
import com.lily.dap.service.core.exception.DataNotExistException;
import com.lily.dap.service.core.exception.NotSupportOperationException;
import com.lily.dap.service.organize.PersonManager;
import com.lily.dap.service.right.RightHoldManager;

/**
 * @author zouxuemo
 *
 */
public class PersonManagerImpl extends BaseManager implements PersonManager, ApplicationContextAware {
	private RightHoldManager rightHoldManager;
	
	private ApplicationContext ctx;
	
	/**
	 * @param rightHoldManager 要设置的 rightHoldManager
	 */
	public void setRightHoldManager(RightHoldManager rightHoldManager) {
		this.rightHoldManager = rightHoldManager;
	}

	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		ctx = applicationContext;
	}

	/* (非 Javadoc)
	 * @see com.lily.dap.service.organize.PersonManager#getPerson(java.lang.String)
	 */
	public Person getPerson(String username) throws DataNotExistException {
		return (Person)get(Person.class, "username", username);
	}

	/* (非 Javadoc)
	 * @see com.lily.dap.service.core.BaseManager#onBeforeAdd(java.lang.Object)
	 */
	protected Object onBeforeAdd(Object entity) {
		if (!(entity instanceof Person))
			throw new NotSupportOperationException("接口只支持对Person的add(...)方法!");
		
		entity = super.onBeforeAdd(entity);
		
		Person p = (Person)entity;
		
		VerifyUtil verifyUtil = new VerifyUtil(dao);
		verifyUtil.assertDataNotRepeat(Person.class, "username", p.getUsername(), "指定的用户名称重复,请重新指定新的用户名称");
		
		rightHoldManager.providerHoldsRole(p);
		
		return p;
	}

	/* (非 Javadoc)
	 * @see com.lily.dap.service.core.BaseManager#onAfterAdd(java.lang.Object)
	 */
	protected void onAfterAdd(Object entity) {
		super.onAfterAdd(entity);
		
		ctx.publishEvent(new OrganizeNotifyEvent(OrganizeNotifyEvent.EVENT_CLASS_PERSON, OrganizeNotifyEvent.EVENT_ADD_PERSON, entity));
	}

	/* (非 Javadoc)
	 * @see com.lily.dap.service.core.BaseManager#onBeforeModify(java.lang.Object)
	 */
	protected Object onBeforeModify(Object entity) {
		if (!(entity instanceof Person))
			throw new NotSupportOperationException("接口只支持对Person的modify(...)方法!");
		
		entity = super.onBeforeModify(entity);
		
		Person p = (Person)entity;
		
		Person person = (Person)get(Person.class, p.getId());
		person.setName(p.getName());
		person.setSex(p.getSex());
		person.setBirthday(p.getBirthday());
		person.setMobilePhone(p.getMobilePhone());
		person.setPhone(p.getPhone());
		person.setDes(p.getDes());
		
		return p;
	}

	/* (非 Javadoc)
	 * @see com.lily.dap.service.core.BaseManager#onAfterModify(java.lang.Object)
	 */
	protected void onAfterModify(Object entity) {
		super.onAfterModify(entity);
		
		ctx.publishEvent(new OrganizeNotifyEvent(OrganizeNotifyEvent.EVENT_CLASS_PERSON, OrganizeNotifyEvent.EVENT_MODIFY_PERSON, entity));
	}

	/* (非 Javadoc)
	 * @see com.lily.dap.service.core.BaseManager#onBeforeRemove(java.lang.Object)
	 */
	protected void onBeforeRemove(Object entity) {
		if (!(entity instanceof Person))
			throw new NotSupportOperationException("接口只支持对Person的remove(...)方法!");
		
		super.onBeforeRemove(entity);

		Person p = (Person)entity;
		
		//移除人员所在岗位中的关系
		List postPersonList = gets(PostPerson.class, new QueryCondition().putCondition("person_id", p.getId()));
		for (int i = 0; i < postPersonList.size(); i++) {
			PostPerson postPerson = (PostPerson)postPersonList.get(i);
			
			Post post = (Post)get(Post.class, new Long(postPerson.getPost_id()));
			
			doRemovePostPerson(postPerson, post, p);
		}
		
		rightHoldManager.removeHoldsRoles(p);
	}

	/* (非 Javadoc)
	 * @see com.lily.dap.service.core.BaseManager#onAfterRemove(java.lang.Object)
	 */
	protected void onAfterRemove(Object entity) {
		super.onAfterRemove(entity);
		
		ctx.publishEvent(new OrganizeNotifyEvent(OrganizeNotifyEvent.EVENT_CLASS_PERSON, OrganizeNotifyEvent.EVENT_REMOVE_PERSON, entity));
	}
	
	protected void doRemovePostPerson(PostPerson postPerson, Post post, Person person) {
		rightHoldManager.removeHaveHold(person, post);
		
		doRemove(PostPerson.class, new Long(postPerson.getId()));
		
		ctx.publishEvent(new OrganizeNotifyEvent(OrganizeNotifyEvent.EVENT_CLASS_POST, OrganizeNotifyEvent.EVENT_REMOVE_POST_HAVE_PERSON, post, person));
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -