@ -4,6 +4,12 @@ import com.engine.hrm.entity.RuleCodeType;
import com.engine.hrm.util.CodeRuleManager ;
import com.engine.hrm.util.HrmTriggerUtil ;
import com.engine.hrm.util.face.HrmFaceCheckManager ;
import com.engine.organization.entity.company.po.CompPO ;
import com.engine.organization.entity.department.po.DepartmentPO ;
import com.engine.organization.mapper.comp.CompMapper ;
import com.engine.organization.mapper.department.DepartmentMapper ;
import com.engine.organization.util.db.MapperProxyFactory ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang3.StringUtils ;
import weaver.conn.RecordSet ;
import weaver.general.BaseBean ;
@ -17,19 +23,21 @@ import weaver.rtx.OrganisationCom;
import weaver.systeminfo.SysMaintenanceLog ;
import weaver.systeminfo.SystemEnv ;
import java.util.List ;
/ * *
* @author : dxfeng
* @createTime : 2022 / 06 / 30
* @version : 1.0
* /
public class CompanyImportUtil {
private final RecordSet recordSet = new RecordSet ( ) ;
private final OrganisationCom rtxService = new OrganisationCom ( ) ; //添加到rtx
private final RecordSet recordSet = new RecordSet ( ) ;
private final OrganisationCom rtxService = new OrganisationCom ( ) ; //添加到rtx
private int id ;
private String subcompanyname = "" ;
private String departmentname = "" ;
private String subcompanyname = "" ;
private String departmentname = "" ;
private String subcompanycode = "" ;
private Float subcompanyshoworder ;
private Integer subcompanyshoworder ;
private String departmentcode = "" ;
private Float departmentshoworder ;
private int userlanguage = 7 ;
@ -37,20 +45,29 @@ public class CompanyImportUtil {
private String operateType ;
private String message = "" ;
private CompMapper getCompMapper ( ) {
return MapperProxyFactory . getProxy ( CompMapper . class ) ;
}
private DepartmentMapper getDepartmentMapper ( ) {
return MapperProxyFactory . getProxy ( DepartmentMapper . class ) ;
}
public void setPid ( int pid ) {
this . pid = pid ;
}
public void setUserLanguage ( String userlanguage ) {
public void setUserLanguage ( String userlanguage ) {
this . userlanguage = Util . getIntValue ( userlanguage ) ;
}
/ * *
* 校 验 数 据 有 效 性
* /
public String valExcelData ( ) {
public String valExcelData ( ) {
String errorInfo = "" ;
if ( Util . null2String ( this . subcompanyname ) . length ( ) = = 0 ) {
errorInfo = SystemEnv . getHtmlLabelName ( 125704 , userlanguage ) ;
if ( Util . null2String ( this . subcompanyname ) . length ( ) = = 0 ) {
errorInfo = SystemEnv . getHtmlLabelName ( 125704 , userlanguage ) ;
return errorInfo ;
}
if ( StringUtils . isNotEmpty ( operateType ) & & operateType . equals ( "add" ) ) {
@ -63,22 +80,22 @@ public class CompanyImportUtil {
/ * *
* 保 存 数 据
* /
public String save ( ) {
public String save ( ) {
boolean flag = false ;
try {
if ( StringUtils . isNotEmpty ( operateType ) ) {
try {
if ( StringUtils . isNotEmpty ( operateType ) ) {
if ( operateType . equals ( "add" ) ) {
int subcompanyid = 0 ;
int departmentid ;
if ( Util . null2String ( this . subcompanyname ) . length ( ) > 0 ) {
if ( Util . null2String ( this . subcompanyname ) . length ( ) > 0 ) {
//取分部
subcompanyid = get Sub CompanyId( this . subcompanyname ) ;
subcompanyid = get CompanyId( this . subcompanyname ) ;
}
departmentid = getDeptId ( this . departmentname , subcompanyid ) ;
if ( Util . null2String ( this . departmentname ) . length ( ) > 0 ) {
if ( departmentid ! = 0 ) flag = true ;
} else {
if ( subcompanyid ! = 0 ) flag = true ;
departmentid = getDeptId ( this . departmentname , subcompanyid ) ;
if ( Util . null2String ( this . departmentname ) . length ( ) > 0 ) {
if ( departmentid ! = 0 ) flag = true ;
} else {
if ( subcompanyid ! = 0 ) flag = true ;
}
} else if ( operateType . equals ( "update" ) ) {
int subcompanyid = updateSubCompany ( ) ;
@ -88,23 +105,38 @@ public class CompanyImportUtil {
flag = true ;
}
}
} catch ( Exception e ) {
} catch ( Exception e ) {
new BaseBean ( ) . writeLog ( e ) ;
}
return String . valueOf ( flag ) ;
}
/ * *
* 校 验 分 部 编 号 是 否 重 复
*
* @param code
* @return
* /
private boolean verifySubCompanyCode ( String code ) {
if ( StringUtils . isEmpty ( code ) ) return true ;
RecordSet recordSet = new RecordSet ( ) ;
String sql = "select id from HrmSubCompany where subcompanycode = ?" ;
recordSet . executeQuery ( sql , code ) ;
return recordSet . getCounts ( ) < = 0 ;
if ( StringUtils . isEmpty ( code ) ) {
return true ;
}
List< CompPO > compPOS = getCompMapper ( ) . listByNo ( code ) ;
return CollectionUtils. isEmpty ( compPOS ) ;
}
/ * *
* @param code
* @param name
* @param supsubcomid
* @return
* /
private boolean verifySubCompanyCode ( String code , String name , int supsubcomid ) {
if ( StringUtils . isEmpty ( code ) ) return true ;
if ( StringUtils . isEmpty ( code ) ) {
return true ;
}
// TODO 部门重复编号验证
RecordSet recordSet = new RecordSet ( ) ;
String sql = "select id from HrmSubCompany where subcompanyname = ? and supsubcomid = ?" ;
recordSet . executeQuery ( sql , name , supsubcomid ) ;
@ -117,15 +149,22 @@ public class CompanyImportUtil {
return verifySubCompanyCode ( code ) ;
}
/ * *
* 校 验 部 门 编 号 是 否 重 复
*
* @param code
* @return
* /
private boolean verifyDeptCode ( String code ) {
if ( StringUtils . isEmpty ( code ) ) return true ;
RecordSet recordSet = new RecordSet ( ) ;
String sql = "select id from HrmDepartment where departmentcode = ?" ;
recordSet . executeQuery ( sql , code ) ;
return recordSet . getCounts ( ) < = 0 ;
if ( StringUtils . isEmpty ( code ) ) {
return true ;
}
List< DepartmentPO > departmentPOS = getDepartmentMapper ( ) . listByNo ( code ) ;
return CollectionUtils. isEmpty ( departmentPOS ) ;
}
private boolean verifyDeptCode ( String code , String name , int subcompanyid , int supdepid ) {
// TODO 部门编号校验
if ( StringUtils . isEmpty ( code ) ) return true ;
RecordSet recordSet = new RecordSet ( ) ;
String sql = "select id from HrmDepartment where departmentname = ? and subcompanyid1 = ? and supdepid = ?" ;
@ -147,7 +186,7 @@ public class CompanyImportUtil {
Float departmentshoworder = null ;
for ( int i = 0 ; i < deptNames . length ; i + + ) {
if ( StringUtils . isEmpty ( deptNames [ i ] ) ) continue ;
String sql = "select * from HrmDepartment where subcompanyid1=" + subcompanyid + " and departmentname='" + deptNames [ i ] . trim ( ) + "' and supdepid=" + parentId + " and (canceled !=1 or canceled is null)" ;
String sql = "select * from HrmDepartment where subcompanyid1=" + subcompanyid + " and departmentname='" + deptNames [ i ] . trim ( ) + "' and supdepid=" + parentId + " and (canceled !=1 or canceled is null)" ;
currentId = getResultSetId ( sql ) ;
if ( currentId = = 0 ) {
// 部门不存在
@ -163,8 +202,10 @@ public class CompanyImportUtil {
if ( StringUtils . isNotEmpty ( departmentcode ) | | departmentshoworder ! = null ) {
recordSet . executeQuery ( sql ) ;
recordSet . next ( ) ;
if ( departmentshoworder = = null ) departmentshoworder = Float . valueOf ( Util . null2s ( recordSet . getString ( "showorder" ) , "0" ) ) ;
if ( StringUtils . isEmpty ( departmentcode ) ) departmentcode = Util . null2String ( recordSet . getString ( "departmentcode" ) , "" ) ;
if ( departmentshoworder = = null )
departmentshoworder = Float . valueOf ( Util . null2s ( recordSet . getString ( "showorder" ) , "0" ) ) ;
if ( StringUtils . isEmpty ( departmentcode ) )
departmentcode = Util . null2String ( recordSet . getString ( "departmentcode" ) , "" ) ;
if ( verifyDeptCode ( departmentcode , deptNames [ i ] , subcompanyid , parentId ) ) {
sql = "update hrmdepartment set departmentcode = ? , showorder = ? where departmentname = ? and subcompanyid1 = ? and supdepid = ? and (canceled !=1 or canceled is null)" ;
recordSet . executeUpdate ( sql , departmentcode , departmentshoworder , deptNames [ i ] , subcompanyid , parentId ) ;
@ -177,12 +218,13 @@ public class CompanyImportUtil {
}
return currentId ;
}
private int updateSubCompany ( ) {
private int updateSubCompany ( ) {
String [ ] subcompanynames = subcompanyname . split ( ">" ) ;
int parentId = 0 ;
int currentId = 0 ;
String subcompanycode = "" ;
Float subcompanyshoworder = null ;
Integer subcompanyshoworder = null ;
for ( int i = 0 ; i < subcompanynames . length ; i + + ) {
if ( StringUtils . isEmpty ( subcompanynames [ i ] ) ) continue ;
String sql = "select * from HrmSubCompany where subcompanyname='"
@ -202,8 +244,10 @@ public class CompanyImportUtil {
if ( StringUtils . isNotEmpty ( subcompanycode ) | | subcompanyshoworder ! = null ) {
recordSet . executeQuery ( sql ) ;
recordSet . next ( ) ;
if ( subcompanyshoworder = = null ) subcompanyshoworder = Float . valueOf ( Util . null2s ( recordSet . getString ( "showorder" ) , "0" ) ) ;
if ( StringUtils . isEmpty ( subcompanycode ) ) subcompanycode = Util . null2String ( recordSet . getString ( "subcompanycode" ) , "" ) ;
if ( subcompanyshoworder = = null )
subcompanyshoworder = Integer . valueOf ( Util . null2s ( recordSet . getString ( "showorder" ) , "0" ) ) ;
if ( StringUtils . isEmpty ( subcompanycode ) )
subcompanycode = Util . null2String ( recordSet . getString ( "subcompanycode" ) , "" ) ;
if ( verifySubCompanyCode ( subcompanycode , subcompanynames [ i ] , parentId ) ) {
sql = "update HrmSubCompany set subcompanycode= ? , showorder = ? where subcompanyname = ? and supsubcomid = ?" ;
recordSet . executeUpdate ( sql , subcompanycode , subcompanyshoworder , subcompanynames [ i ] , parentId ) ;
@ -219,46 +263,49 @@ public class CompanyImportUtil {
/ * *
* 根 据 分 部 名 称 获 取 分 部 Id , 不 存 在 就 创 建
* @param subcompanyname 分 部 名 称 eg : 泛 微 广 东 > 泛 微 深 圳
*
* @param companyName 分 部 名 称 eg : 泛 微 广 东 > 泛 微 深 圳
* /
public int get SubCompanyId( String subcompanyn ame) {
String [ ] subcompanynames = subcompanyn ame. split ( ">" ) ;
public int get CompanyId( String companyN ame) {
String [ ] companyNames = companyN ame. split ( ">" ) ;
int currentId = 0 ;
int parentId = 0 ;
String sql ;
String sqlInsert ;
String subcompanyc ode = "" ;
Float subcompanyshowo rder = null ;
for ( int i = 0 ; i < subcompanyn ames. length ; i + + ) {
if ( subcompanynames [ i ] = = null & & subcompanyn ames[ i ] . equals ( "" ) ) {
String companyC ode = "" ;
Integer companyShowO rder = null ;
for ( int i = 0 ; i < companyN ames. length ; i + + ) {
if ( companyNames [ i ] = = null & & companyN ames[ i ] . equals ( "" ) ) {
continue ;
}
sql = "select id from HrmSubCompany where subcompanyname='"
+ subcompanyn ames[ i ] . trim ( ) + "' and supsubcomid=" + parentId ;
+ companyN ames[ i ] . trim ( ) + "' and supsubcomid=" + parentId ;
currentId = getResultSetId ( sql ) ;
//added by wcd 2015-02-06 [限制分部数]
if ( currentId = = 0 ) {
if ( i = = subcompanyn ames. length - 1 ) {
if ( i = = companyN ames. length - 1 ) {
// 最后一层级 赋值编码和顺序
subcompanycode = this . subcompanycode ;
subcompanyshoworder = this . subcompanyshoworder ;
if ( subcompanyshoworder = = null ) subcompanyshoworder = 0.00F ;
companyCode = this . subcompanycode ;
companyShowOrder = this . subcompanyshoworder ;
if ( companyShowOrder = = null ) {
companyShowOrder = 0 ;
}
}
if ( AjaxManager . getData ( "" , "getLnScCount;mf" ) . equals ( "true" ) ) {
if ( AjaxManager . getData ( "" , "getLnScCount;mf" ) . equals ( "true" ) ) {
// 如果编码为空 自动生成编码
try {
subcompanyc ode = CodeRuleManager . getCodeRuleManager ( ) . generateRuleCode ( RuleCodeType . SUBCOMPANY , subcompanyc ode) ;
companyC ode = CodeRuleManager . getCodeRuleManager ( ) . generateRuleCode ( RuleCodeType . SUBCOMPANY , companyC ode) ;
} catch ( Exception e ) {
setMessage ( "," + e . getMessage ( ) ) ;
new BaseBean ( ) . writeLog ( e ) ;
return - 1 ;
}
sqlInsert = "insert into HrmSubCompany(subcompanyname,subcompanydesc,companyid,supsubcomid,subcompanycode,showorder," + DbFunctionUtil . getInsertColumnSql ( ) + ") values('"
+ subcompanynames[ i ] + "','" + subcompanynames [ i ] + "',1" + "," + parentId + ",'" + subcompanycode+ "'," + subcompanyshoworder + "," + DbFunctionUtil . getInsertColumnValueSql ( new RecordSet ( ) . getDBType ( ) , 1 ) + ")" ; // 创建
sqlInsert = "insert into HrmSubCompany(subcompanyname,subcompanydesc,companyid,supsubcomid,subcompanycode,showorder," + DbFunctionUtil . getInsertColumnSql ( ) + ") values('"
+ companyNames[ i ] + "','" + companyNames [ i ] + "',1" + "," + parentId + ",'" + companyCode + "'," + companyShowOrder + "," + DbFunctionUtil . getInsertColumnValueSql ( new RecordSet ( ) . getDBType ( ) , 1 ) + ")" ; // 创建
boolean isSuccess = execSql ( sqlInsert ) ;
HrmTriggerUtil . generateSubcompanyPinyin ( subcompanyn ames[ i ] , null ) ;
HrmTriggerUtil . generateSubcompanyPinyin ( companyN ames[ i ] , null ) ;
currentId = getResultSetId ( sql ) ;
HrmTriggerUtil . Tri_I_SubComKPICheckFlow ( String . valueOf ( currentId ) ) ;
sql = "insert into leftmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + currentId + ",2,locked,lockedbyid,usecustomname,customname,customname_e from leftmenuconfig where resourcetype=1 and resourceid=1" ;
@ -266,19 +313,19 @@ public class CompanyImportUtil {
sql = "insert into mainmenuconfig (userid,infoid,visible,viewindex,resourceid,resourcetype,locked,lockedbyid,usecustomname,customname,customname_e) select distinct userid,infoid,visible,viewindex," + currentId + ",2,locked,lockedbyid,usecustomname,customname,customname_e from mainmenuconfig where resourcetype=1 and resourceid=1" ;
execSql ( sql ) ;
if ( isSuccess ) {
if ( isSuccess ) {
//同步分部数据到矩阵
MatrixUtil . updateSubcompayData ( "" + currentId ) ;
HrmFaceCheckManager . sync ( currentId + "" , HrmFaceCheckManager . getOptInsert ( ) , "hrm_import_subcompany" , HrmFaceCheckManager . getOaSubcompany ( ) ) ;
HrmFaceCheckManager . sync ( currentId + "" , HrmFaceCheckManager . getOptInsert ( ) , "hrm_import_subcompany" , HrmFaceCheckManager . getOaSubcompany ( ) ) ;
}
insertSysLog ( subcompanyn ames[ i ] ) ;
insertSysLog ( companyN ames[ i ] ) ;
} else {
currentId = - 1 ;
}
}
parentId = currentId ;
if ( currentId ! = - 1 )
if ( currentId ! = - 1 )
rtxService . addSubCompany ( parentId ) ; //同步RTX
}
return currentId ;
@ -286,10 +333,11 @@ public class CompanyImportUtil {
/ * *
* 获 取 部 门 id , 不 存 在 就 创 建
* @param deptNames 部 门 名 称
* @param subCompanyId 所 属 分 部 id
*
* @param deptNames 部 门 名 称
* @param subCompanyId 所 属 分 部 id
* /
public int getDeptId ( String deptNames , int subCompanyId ) {
public int getDeptId ( String deptNames , int subCompanyId ) {
String [ ] deptName = deptNames . split ( ">" ) ;
int currentId = 0 ;
int parentId = 0 ;
@ -299,14 +347,14 @@ public class CompanyImportUtil {
String departmentcode = "" ;
Float departmentshoworder = null ;
for ( int i = 0 ; i < deptName . length ; i + + ) {
if ( deptName [ i ] = = null | | deptName [ i ] . equals ( "" ) ) {
if ( deptName [ i ] = = null | | deptName [ i ] . equals ( "" ) ) {
continue ;
}
sql = "select id from HrmDepartment where subcompanyid1=" + subCompanyId + " and departmentname='" + deptName [ i ] . trim ( ) + "' and supdepid=" + parentId + " and (canceled !=1 or canceled is null)" ;
sql = "select id from HrmDepartment where subcompanyid1=" + subCompanyId + " and departmentname='" + deptName [ i ] . trim ( ) + "' and supdepid=" + parentId + " and (canceled !=1 or canceled is null)" ;
currentId = getResultSetId ( sql ) ;
if ( currentId = = 0 ) {
if ( i = = deptName . length - 1 ) {
if ( i = = deptName . length - 1 ) {
departmentcode = this . departmentcode ;
departmentshoworder = this . departmentshoworder ;
if ( departmentshoworder = = null ) departmentshoworder = 0.00F ;
@ -319,16 +367,16 @@ public class CompanyImportUtil {
new BaseBean ( ) . writeLog ( e ) ;
return - 1 ;
}
sqlInsert = "insert into HrmDepartment (departmentname,Departmentmark,subcompanyid1,supdepid,departmentcode,showorder," + DbFunctionUtil . getInsertColumnSql ( ) + ") values('"
+ deptName [ i ] + "','" + deptName [ i ] + "'," + subCompanyId + "," + parentId + ",'" + departmentcode + "'," + departmentshoworder + "," + DbFunctionUtil . getInsertColumnValueSql ( new RecordSet ( ) . getDBType ( ) , 1 ) + ")" ; // 创建
sqlInsert = "insert into HrmDepartment (departmentname,Departmentmark,subcompanyid1,supdepid,departmentcode,showorder," + DbFunctionUtil . getInsertColumnSql ( ) + ") values('"
+ deptName [ i ] + "','" + deptName [ i ] + "'," + subCompanyId + "," + parentId + ",'" + departmentcode + "'," + departmentshoworder + "," + DbFunctionUtil . getInsertColumnValueSql ( new RecordSet ( ) . getDBType ( ) , 1 ) + ")" ; // 创建
boolean isSuccess = execSql ( sqlInsert ) ;
HrmTriggerUtil . generateDepartmentPinyin ( deptName [ i ] , null ) ;
currentId = getResultSetId ( sql ) ;
HrmTriggerUtil . Tri_I_DeptKPICheckFlow ( String . valueOf ( currentId ) ) ;
if ( isSuccess ) {
if ( isSuccess ) {
//同步部门数据到矩阵
MatrixUtil . updateDepartmentData ( "" + currentId ) ;
HrmFaceCheckManager . sync ( currentId + "" , HrmFaceCheckManager . getOptInsert ( ) , "hrm_import_deptment" , HrmFaceCheckManager . getOaDepartment ( ) ) ;
HrmFaceCheckManager . sync ( currentId + "" , HrmFaceCheckManager . getOptInsert ( ) , "hrm_import_deptment" , HrmFaceCheckManager . getOaDepartment ( ) ) ;
}
insertSysLog ( deptName [ i ] ) ;
@ -341,7 +389,8 @@ public class CompanyImportUtil {
/ * *
* 获 得 查 询 结 果 Id
* @param sql 查 询 语 句
*
* @param sql 查 询 语 句
* /
public int getResultSetId ( String sql ) {
int currentId = 0 ;
@ -358,14 +407,15 @@ public class CompanyImportUtil {
/ * *
* 执 行 插 入 操 作
*
* @param sql
* /
public boolean execSql ( String sql ) {
return recordSet . execute ( sql ) ;
}
public void removeCache ( ) {
try {
public void removeCache ( ) {
try {
weaver . matrix . MatrixUtil . sysSubcompayData ( ) ;
weaver . matrix . MatrixUtil . sysDepartmentData ( ) ;
@ -377,7 +427,7 @@ public class CompanyImportUtil {
DepartmentComInfo . removeCompanyCache ( ) ;
//初始化应用分权
new weaver . hrm . appdetach . AppDetachComInfo ( ) . initSubDepAppData ( ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
new BaseBean ( ) . writeLog ( e ) ;
}
}
@ -414,11 +464,11 @@ public class CompanyImportUtil {
this . subcompanycode = subcompanycode ;
}
public Float getSubcompanyshoworder ( ) {
public Integer getSubcompanyshoworder ( ) {
return subcompanyshoworder ;
}
public void setSubcompanyshoworder ( Float subcompanyshoworder ) {
public void setSubcompanyshoworder ( Integer subcompanyshoworder ) {
this . subcompanyshoworder = subcompanyshoworder ;
}