欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JPA調用存儲過程

程序员文章站 2022-01-30 20:46:34
...

 PROCEDURE:

CREATE OR REPLACE PROCEDURE HTCHR.copy_BonusDept_From_HRM (
orgid in number,bonusorgid in number,hrmtype in number) is
BEGIN
delete from HTCHR.BONUSDEPARTMENT b where B.BONUSORGANIZATION_ID = bonusorgid;
insert into HTCHR.BONUSDEPARTMENT b (
B.ID,
B.CODE,B.FULLNAME,B.SHORTNAME,B.ENGLISHNAME,B.REPEALED,B.DEPTLEVEL,B.PLDEPT,B.ATTRIBUTE,
--B.MAINMANAGER_ID,
B.BONUSORGANIZATION_ID,
B.ADMINPARENT_ID
) 
select
concat(bonusorgid,'*'||D.id),
D.CODE,D.FULLNAME,D.SHORTNAME,D.ENGLISHNAME,D.REPEALED,D.DEPTLEVEL,D.PLDEPT,D.ATTRIBUTE,
replace(D.ORGANIZATION_ID,D.ORGANIZATION_ID,bonusorgid),
--D.MAINMANAGER_ID,
case hrmtype 
when 1
--DLine1
then
case
when D.DOTTEDONEPARENT_ID is not null
then
concat(bonusorgid,'*'||D.DOTTEDONEPARENT_ID)
else concat('',D.DOTTEDONEPARENT_ID)
end
when 2
--DLine2
then 
case
when D.DOTTEDTWOPARENT_ID is not null
then
concat(bonusorgid,'*'||D.DOTTEDTWOPARENT_ID)
else concat('',D.DOTTEDTWOPARENT_ID)
end
when 3
--SLine
then 
case
when D.SOLIDPARENT_ID is not null
then
concat(bonusorgid,'*'||D.SOLIDPARENT_ID)
else concat('',D.SOLIDPARENT_ID)
end
else
--行政
case
when D.ADMINPARENT_ID is not null
then
concat(bonusorgid,'*'||D.ADMINPARENT_ID)
else concat('',D.ADMINPARENT_ID)
end
end
from HTCHR.DEPARTMENT d where d.ORGANIZATION_ID = orgid;
end;
/

 

 JPA調用:

/**
	 * 復制HRM組織
	 * 
	 * @param orgId
	 * @param prefixStr
	 * @param hrmType
	 */
	public void copyFromHrm(Integer orgId,Integer bonusOrgId,Integer hrmType) {
		Query query = entityManager.createNativeQuery("{call copy_BonusDept_From_HRM(?,?,?)}");
		query.setParameter(1, orgId);
		query.setParameter(2, bonusOrgId);
		query.setParameter(3, hrmType);
		query.executeUpdate();
	}

 

 復制完刷新組織樹的時候需要refresh一下:

/**
	 * 刷新bonusOrganization
	 * 
	 * @param bonusOrganization
	 */
	public void refeshBonusOrganization(BonusOrganization bonusOrganization) {
		bonusOrganization.getBonusDepartments().clear();
		entityManager.refresh(bonusOrganization);
	}

 

相关标签: JPA