@ -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,6 +23,8 @@ import weaver.rtx.OrganisationCom;
import weaver.systeminfo.SysMaintenanceLog ;
import weaver.systeminfo.SystemEnv ;
import java.util.List ;
/ * *
* @author : dxfeng
* @createTime : 2022 / 06 / 30
@ -29,7 +37,7 @@ public class CompanyImportUtil {
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,6 +45,14 @@ 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 ;
}
@ -44,6 +60,7 @@ public class CompanyImportUtil {
public void setUserLanguage ( String userlanguage ) {
this . userlanguage = Util . getIntValue ( userlanguage ) ;
}
/ * *
* 校 验 数 据 有 效 性
* /
@ -72,7 +89,7 @@ public class CompanyImportUtil {
int departmentid ;
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 ) {
@ -95,16 +112,31 @@ public class CompanyImportUtil {
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 = ?" ;
@ -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 ( ) {
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" ) ) {
// 如果编码为空 自动生成编码
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 ) + ")" ; // 创建
+ 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" ;
@ -272,7 +319,7 @@ public class CompanyImportUtil {
HrmFaceCheckManager . sync ( currentId + "" , HrmFaceCheckManager . getOptInsert ( ) , "hrm_import_subcompany" , HrmFaceCheckManager . getOaSubcompany ( ) ) ;
}
insertSysLog ( subcompanyn ames[ i ] ) ;
insertSysLog ( companyN ames[ i ] ) ;
} else {
currentId = - 1 ;
}
@ -286,6 +333,7 @@ public class CompanyImportUtil {
/ * *
* 获 取 部 门 id , 不 存 在 就 创 建
*
* @param deptNames 部 门 名 称
* @param subCompanyId 所 属 分 部 id
* /
@ -341,6 +389,7 @@ public class CompanyImportUtil {
/ * *
* 获 得 查 询 结 果 Id
*
* @param sql 查 询 语 句
* /
public int getResultSetId ( String sql ) {
@ -358,6 +407,7 @@ public class CompanyImportUtil {
/ * *
* 执 行 插 入 操 作
*
* @param sql
* /
public boolean execSql ( String sql ) {
@ -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 ;
}