@ -7,37 +7,24 @@ import com.api.browser.util.ConditionType;
import com.cloudstore.eccom.result.WeaResultMsg ;
import com.engine.core.impl.Service ;
import com.engine.organization.component.OrganizationWeaTable ;
import com.engine.organization.entity.commom.RecordInfo ;
import com.engine.organization.entity.extend.ExtendInfoOperateType ;
import com.engine.organization.entity.extend.param.ExtendInfoParams ;
import com.engine.organization.entity.extend.po.ExtendInfoPO ;
import com.engine.organization.entity.fieldset.param.FieldTransferParam ;
import com.engine.organization.entity.jclimport.po.JclImportHistoryDetailPO ;
import com.engine.organization.entity.jclimport.vo.JclImportHistoryDetailVO ;
import com.engine.organization.entity.job.po.JobPO ;
import com.engine.organization.entity.scheme.po.GradePO ;
import com.engine.organization.entity.scheme.po.LevelPO ;
import com.engine.organization.entity.scheme.po.SchemePO ;
import com.engine.organization.enums.LogModuleNameEnum ;
import com.engine.organization.enums.OperateTypeEnum ;
import com.engine.organization.enums.OrgImportEnum ;
import com.engine.organization.exception.OrganizationRunTimeException ;
import com.engine.organization.mapper.comp.CompMapper ;
import com.engine.organization.mapper.department.DepartmentMapper ;
import com.engine.organization.mapper.employee.EmployeeMapper ;
import com.engine.organization.mapper.extend.ExtMapper ;
import com.engine.organization.mapper.extend.ExtendInfoMapper ;
import com.engine.organization.mapper.hrmresource.SystemDataMapper ;
import com.engine.organization.mapper.jclimport.JclImportHistoryDetailMapper ;
import com.engine.organization.mapper.job.JobMapper ;
import com.engine.organization.mapper.resource.ResourceMapper ;
import com.engine.organization.mapper.scheme.GradeMapper ;
import com.engine.organization.mapper.scheme.LevelMapper ;
import com.engine.organization.mapper.scheme.SchemeMapper ;
import com.engine.organization.service.ImportCommonService ;
import com.engine.organization.thread.HrmResourceTriggerRunnable ;
import com.engine.organization.thread.JobTriggerRunnable ;
import com.engine.organization.thread.OrganizationSyncEc ;
import com.engine.organization.util.HasRightUtil ;
import com.engine.organization.util.OrganizationAssert ;
import com.engine.organization.util.db.MapperProxyFactory ;
@ -45,6 +32,7 @@ import com.engine.organization.util.excel.ExcelUtil;
import com.engine.organization.util.saveimport.CompanyImport ;
import com.engine.organization.util.saveimport.DepartmentImport ;
import com.engine.organization.util.saveimport.OrgImportUtil ;
import com.engine.organization.util.saveimport.ResourceImport ;
import org.apache.commons.collections.CollectionUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.poi.hssf.usermodel.HSSFDateUtil ;
@ -111,8 +99,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
String tableName = "" ;
String errorMsg = "" ;
List < String > excludeFields = new ArrayList < > ( ) ;
//List<FieldTransferParam> includeFields = new ArrayList<>();
//List<String> selectedList = new ArrayList<>();
Map < String , Object > returnMaps = new HashMap < > ( ) ;
if ( StringUtils . isNotBlank ( importType ) ) {
switch ( importType ) {
@ -128,18 +114,14 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
excludeFields . add ( "showid" ) ;
return DepartmentImport . getImportFields ( user , excludeFields ) ;
case "jobtitle" :
extendType = "3" ;
tableName = "JCL_ORG_JOB" ;
excludeFields . add ( "parent_job" ) ;
break ;
case "resource" :
ex tendType = "4" ;
tableName = "JCL_ORG_HRMRESOURCE" ;
excludeFields . add ( " scheme_id ") ;
excludeFields . add ( " sequence_id ") ;
excludeFields . add ( " job_grade ") ;
excludeFields . add ( " job_level ") ;
break ;
excludeFields . add ( "resourceimageid" ) ;
excludeFields . add ( "messagerurl" ) ;
excludeFields . add ( "workyear" ) ;
excludeFields . add ( " companyworkyear ") ;
excludeFields . add ( " textfield1 ") ;
excludeFields . add ( " textfield2 ") ;
return ResourceImport . getImportFields ( user , excludeFields ) ;
case "joblevel" :
extendType = "0" ;
tableName = "JCL_ORG_SCHEME" ;
@ -201,10 +183,10 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
returnMap . put ( "condition" , DepartmentImport . importForm ( user , templatePath ) ) ;
break ;
case "jobtitle" :
returnMap . put ( "condition" , getJobTitleImportForm ( templatePath ) ) ;
break ;
//returnMap.put("condition", getJobTitleImportForm(templatePath));
//break;
case "resource" :
returnMap . put ( "condition" , get ResourceImportForm( templatePath ) ) ;
returnMap . put ( "condition" , ResourceImport. import Form( user , templatePath ) ) ;
break ;
case "joblevel" :
returnMap . put ( "condition" , getJobLevelImportForm ( templatePath ) ) ;
@ -240,10 +222,8 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
returnMap . put ( "pId" , DepartmentImport . saveImport ( operateType , excelFile , user ) ) ;
break ;
case "jobtitle" :
returnMap . put ( "pId" , jobImport ( operateType , excelFile ) ) ;
break ;
case "resource" :
returnMap . put ( "pId" , hrm ResourceImport( operateType , excelFile , keyField ) ) ;
returnMap . put ( "pId" , ResourceImport . saveImport ( operateType , excelFile , user , request ) ) ;
break ;
case "joblevel" :
returnMap . put ( "pId" , jobLevelImport ( operateType , excelFile ) ) ;
@ -299,65 +279,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
return returnMap ;
}
private List < Object > getJobTitleImportForm ( String templatePath ) throws IOException {
// 返回导入数据
List < Object > lsGroup = new ArrayList < > ( ) ;
Map < String , Object > groupItem = new HashMap < > ( ) ;
List < Object > itemList = new ArrayList < > ( ) ;
groupItem . put ( "title" , SystemEnv . getHtmlLabelName ( 1361 , user . getLanguage ( ) ) ) ;
groupItem . put ( "defaultshow" , true ) ;
SearchConditionItem searchConditionItem ;
ConditionFactory conditionFactory = new ConditionFactory ( user ) ;
//导入类型
List < SearchConditionOption > statusOptions = new ArrayList < > ( ) ;
statusOptions . add ( new SearchConditionOption ( "add" , SystemEnv . getHtmlLabelName ( 611 , user . getLanguage ( ) ) , true ) ) ;
statusOptions . add ( new SearchConditionOption ( "update" , SystemEnv . getHtmlLabelName ( 17744 , user . getLanguage ( ) ) ) ) ;
searchConditionItem = conditionFactory . createCondition ( ConditionType . SELECT , 24863 , "importType" , statusOptions ) ;
searchConditionItem . setValue ( "add" ) ;
itemList . add ( searchConditionItem ) ;
//模板文件
searchConditionItem = conditionFactory . createCondition ( ConditionType . INPUT , 28576 , "templet" ) ;
searchConditionItem . setValue ( templatePath ) ;
itemList . add ( searchConditionItem ) ;
//Excel文件
searchConditionItem = conditionFactory . createCondition ( ConditionType . RESOURCEIMG , 16630 , "excelfile" ) ;
itemList . add ( searchConditionItem ) ;
groupItem . put ( "items" , itemList ) ;
lsGroup . add ( groupItem ) ;
itemList = new ArrayList < > ( ) ;
groupItem = new HashMap < > ( ) ;
groupItem . put ( "title" , SystemEnv . getHtmlLabelName ( 33803 , Util . getIntValue ( user . getLanguage ( ) ) ) ) ;
groupItem . put ( "defaultshow" , true ) ;
List < Integer > lsPromptLabel = new ArrayList < > ( ) ; //提示信息
lsPromptLabel . add ( 34275 ) ;
lsPromptLabel . add ( 125452 ) ;
for ( int i = 0 ; i < lsPromptLabel . size ( ) ; i + + ) {
Map < String , Object > item = new HashMap < > ( ) ;
item . put ( "index" , ( i + 1 ) ) ;
String value = Util . toScreen ( SystemEnv . getHtmlLabelName ( lsPromptLabel . get ( i ) , user . getLanguage ( ) ) , user . getLanguage ( ) ) ;
if ( i = = 0 ) {
value + = SystemEnv . getHtmlLabelName ( 28576 , user . getLanguage ( ) ) ;
item . put ( "link" , templatePath ) ;
}
item . put ( "value" , value ) ;
itemList . add ( item ) ;
}
groupItem . put ( "items" , itemList ) ;
lsGroup . add ( groupItem ) ;
return lsGroup ;
}
private List < Object > getJobLevelImportForm ( String templatePath ) throws IOException {
// 返回导入数据
@ -420,614 +341,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
return lsGroup ;
}
private List < Object > getResourceImportForm ( String templatePath ) throws IOException {
// 返回导入数据
List < Object > lsGroup = new ArrayList < > ( ) ;
Map < String , Object > groupItem = new HashMap < > ( ) ;
List < Object > itemList = new ArrayList < > ( ) ;
groupItem . put ( "title" , SystemEnv . getHtmlLabelName ( 1361 , user . getLanguage ( ) ) ) ;
groupItem . put ( "defaultshow" , true ) ;
SearchConditionItem searchConditionItem ;
ConditionFactory conditionFactory = new ConditionFactory ( user ) ;
//重复验证字段
List < SearchConditionOption > statusOptions = new ArrayList < > ( ) ;
statusOptions . add ( new SearchConditionOption ( "last_name" , SystemEnv . getHtmlLabelName ( 413 , user . getLanguage ( ) ) ) ) ;
statusOptions . add ( new SearchConditionOption ( "work_code" , SystemEnv . getHtmlLabelName ( 714 , user . getLanguage ( ) ) , true ) ) ;
//statusOptions.add(new SearchConditionOption("loginid", SystemEnv.getHtmlLabelName(412, user.getLanguage())));
searchConditionItem = conditionFactory . createCondition ( ConditionType . SELECT , 24638 , "keyField" , statusOptions ) ;
searchConditionItem . setValue ( "last_name" ) ;
itemList . add ( searchConditionItem ) ;
//导入类型
List < SearchConditionOption > statusOptions1 = new ArrayList < > ( ) ;
statusOptions1 . add ( new SearchConditionOption ( "add" , SystemEnv . getHtmlLabelName ( 611 , user . getLanguage ( ) ) , true ) ) ;
statusOptions1 . add ( new SearchConditionOption ( "update" , SystemEnv . getHtmlLabelName ( 17744 , user . getLanguage ( ) ) ) ) ;
searchConditionItem = conditionFactory . createCondition ( ConditionType . SELECT , 24863 , "importType" , statusOptions1 ) ;
searchConditionItem . setValue ( "add" ) ;
itemList . add ( searchConditionItem ) ;
//模板文件
searchConditionItem = conditionFactory . createCondition ( ConditionType . INPUT , 28576 , "templet" ) ;
searchConditionItem . setValue ( templatePath ) ;
itemList . add ( searchConditionItem ) ;
//Excel文件
searchConditionItem = conditionFactory . createCondition ( ConditionType . RESOURCEIMG , 16630 , "excelfile" ) ;
itemList . add ( searchConditionItem ) ;
groupItem . put ( "items" , itemList ) ;
lsGroup . add ( groupItem ) ;
itemList = new ArrayList < > ( ) ;
groupItem = new HashMap < > ( ) ;
groupItem . put ( "title" , SystemEnv . getHtmlLabelName ( 33803 , Util . getIntValue ( user . getLanguage ( ) ) ) ) ;
groupItem . put ( "defaultshow" , true ) ;
List < Integer > lsPromptLabel = new ArrayList < > ( ) ; //提示信息
lsPromptLabel . add ( 128520 ) ;
lsPromptLabel . add ( 125868 ) ;
lsPromptLabel . add ( 128365 ) ;
//lsPromptLabel.add(81697);
//lsPromptLabel.add(81698);
lsPromptLabel . add ( 81699 ) ;
lsPromptLabel . add ( 516263 ) ;
//lsPromptLabel.add(81701);
//lsPromptLabel.add(388880);
lsPromptLabel . add ( 81702 ) ;
lsPromptLabel . add ( 81703 ) ;
lsPromptLabel . add ( 125869 ) ;
for ( int i = 0 ; i < lsPromptLabel . size ( ) ; i + + ) {
Map < String , Object > item = new HashMap < > ( ) ;
item . put ( "index" , ( i + 1 ) ) ;
String value = Util . toScreen ( SystemEnv . getHtmlLabelName ( lsPromptLabel . get ( i ) , user . getLanguage ( ) ) , user . getLanguage ( ) ) ;
if ( i = = 0 ) {
value + = SystemEnv . getHtmlLabelName ( 28576 , user . getLanguage ( ) ) ;
item . put ( "link" , templatePath ) ;
}
item . put ( "value" , value ) ;
itemList . add ( item ) ;
}
groupItem . put ( "items" , itemList ) ;
lsGroup . add ( groupItem ) ;
return lsGroup ;
}
/ * *
* 岗 位 导 入
* /
private Long jobImport ( String operateType , String excelFile ) {
Long importHistoryId = OrgImportUtil . saveImportLog ( "jobtitle" , operateType , user ) ;
JclImportHistoryDetailPO historyDetailPO ;
ImageFileManager manager = new ImageFileManager ( ) ;
manager . getImageFileInfoById ( Util . getIntValue ( excelFile ) ) ;
XSSFWorkbook workbook ;
try {
workbook = new XSSFWorkbook ( manager . getInputStream ( ) ) ;
} catch ( IOException e ) {
throw new RuntimeException ( e ) ;
}
// 当前sheet
XSSFSheet sheetAt = workbook . getSheetAt ( 0 ) ;
int lastRow = sheetAt . getLastRowNum ( ) ;
List < ExtendInfoPO > extendInfoPOS = new ArrayList < > ( ) ;
OrganizationAssert . isTrue ( lastRow > 0 , "导入数据为空" ) ;
short lastCellNum = sheetAt . getRow ( 0 ) . getLastCellNum ( ) ;
// 遍历每一行数据
nextRow :
for ( int i = 0 ; i < = lastRow ; i + + ) {
historyDetailPO = new JclImportHistoryDetailPO ( ) ;
historyDetailPO . setPid ( importHistoryId ) ;
XSSFRow row = sheetAt . getRow ( i ) ;
if ( null = = row ) {
continue ;
}
// 组装待处理数据
Map < String , Object > map = new HashMap < > ( ) ;
Integer parentCompanyId = null ;
Integer parentDepartmentId = null ;
Long parentJobId = null ;
String jobName = "" ;
historyDetailPO . setRowNums ( String . valueOf ( i + 1 ) ) ;
for ( int cellIndex = 0 ; cellIndex < lastCellNum ; cellIndex + + ) {
XSSFCell cell = row . getCell ( ( short ) cellIndex ) ;
String cellValue = getCellValue ( cell ) . trim ( ) ;
if ( i = = 0 ) {
// 首行 初始化字段信息
List < ExtendInfoPO > infoPOList = getExtendInfoMapper ( ) . getInfoByExtendAndLabelName ( JOB_TYPE , cellValue ) ;
boolean isBreak = OrgImportUtil . isBreak ( historyDetailPO , cellValue , infoPOList ) ;
if ( isBreak ) {
break nextRow ;
}
ExtendInfoPO extendInfoPO = infoPOList . get ( 0 ) ;
extendInfoPOS . add ( extendInfoPO ) ;
} else {
ExtendInfoPO infoPO = extendInfoPOS . get ( cellIndex ) ;
// 数据校验
if ( infoPO . getIsrequired ( ) = = 1 & & StringUtils . isBlank ( cellValue ) & & ! "job_no" . equalsIgnoreCase ( infoPO . getFieldName ( ) ) ) {
historyDetailPO . setOperateDetail ( infoPO . getFieldNameDesc ( ) + "为必填项" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
Object reallyValue ;
try {
reallyValue = OrgImportUtil . getReallyValue ( infoPO , cellValue ) ;
} catch ( Exception e ) {
historyDetailPO . setOperateDetail ( cellValue + "转换失败" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
if ( StringUtils . isNotBlank ( cellValue ) & & StringUtils . isBlank ( Util . null2String ( reallyValue ) ) & & ! "ec_company" . equals ( infoPO . getFieldName ( ) ) & & ! "ec_department" . equals ( infoPO . getFieldName ( ) ) ) {
historyDetailPO . setOperateDetail ( infoPO . getFieldNameDesc ( ) + "数据转换失败,未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
map . put ( infoPO . getFieldName ( ) , reallyValue ) ;
// 上级分部
if ( "ec_company" . equals ( infoPO . getFieldName ( ) ) ) {
String [ ] split = cellValue . split ( ">" ) ;
if ( split . length > 0 ) {
if ( split . length > 8 ) {
historyDetailPO . setOperateDetail ( "分部层级不能大于10" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
for ( String s : split ) {
parentCompanyId = MapperProxyFactory . getProxy ( CompMapper . class ) . getIdByNameAndPid ( s , parentCompanyId = = null ? 0 : parentCompanyId ) ;
if ( null = = parentCompanyId ) {
historyDetailPO . setOperateDetail ( cellValue + "分部未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
}
}
}
if ( "ec_department" . equals ( infoPO . getFieldName ( ) ) ) {
String [ ] split = cellValue . split ( ">" ) ;
if ( split . length > 0 ) {
if ( split . length > 8 ) {
historyDetailPO . setOperateDetail ( "部门层级不能大于10" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
for ( String s : split ) {
parentDepartmentId = MapperProxyFactory . getProxy ( DepartmentMapper . class ) . getIdByNameAndPid ( s , parentCompanyId , parentDepartmentId = = null ? 0 : parentDepartmentId ) ;
if ( null = = parentDepartmentId ) {
historyDetailPO . setOperateDetail ( cellValue + "部门未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
}
}
}
if ( "job_name" . equals ( infoPO . getFieldName ( ) ) ) {
if ( null = = parentCompanyId ) {
historyDetailPO . setOperateDetail ( cellValue + "所属分部未找到" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
historyDetailPO . setRelatedName ( cellValue ) ;
String [ ] split = cellValue . split ( ">" ) ;
if ( split . length > 0 ) {
if ( split . length > 8 ) {
historyDetailPO . setOperateDetail ( "岗位层级不能大于10" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
for ( int index = 0 ; index < split . length - 1 ; index + + ) {
parentJobId = MapperProxyFactory . getProxy ( JobMapper . class ) . getIdByNameAndPid ( split [ index ] , parentCompanyId , parentDepartmentId = = null ? 0 : parentDepartmentId , parentJobId = = null ? 0 : parentJobId ) ;
if ( null = = parentJobId ) {
historyDetailPO . setOperateDetail ( split [ index ] + "岗位未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
}
}
map . put ( "parent_comp" , parentCompanyId ) ;
map . put ( "parent_dept" , parentDepartmentId ) ;
map . put ( "ec_company" , parentCompanyId ) ;
map . put ( "ec_department" , parentDepartmentId ) ;
map . put ( "parent_job" , parentJobId ) ;
jobName = split [ split . length - 1 ] ;
map . put ( "job_name" , jobName ) ;
map . put ( "is_key" , StringUtils . isBlank ( Util . null2String ( map . get ( "is_key" ) ) ) ? 0 : map . get ( "is_key" ) ) ;
}
}
}
// 校验、数据交互
if ( i = = 0 ) {
continue ;
}
String jobNo = ( String ) map . get ( "job_no" ) ;
Long jobId = MapperProxyFactory . getProxy ( JobMapper . class ) . getIdByNameAndPid ( jobName , parentCompanyId , parentDepartmentId = = null ? 0 : parentDepartmentId , parentJobId = = null ? 0 : parentJobId ) ;
if ( "add" . equals ( operateType ) ) {
if ( jobId ! = null ) {
historyDetailPO . setOperateDetail ( "数据已存在" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue ;
}
// 自动编号
try {
jobNo = JobServiceImpl . repeatDetermine ( jobNo ) ;
} catch ( OrganizationRunTimeException e ) {
historyDetailPO . setOperateDetail ( e . getMessage ( ) ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue ;
}
map . put ( "job_no" , jobNo ) ;
map . put ( "creator" , user . getUID ( ) ) ;
map . put ( "delete_type" , 0 ) ;
map . put ( "create_time" , new Date ( ) ) ;
// 禁用表示为空,默认启用
if ( StringUtils . isBlank ( Util . null2String ( map . get ( "forbidden_tag" ) ) ) ) {
map . put ( "forbidden_tag" , 0 ) ;
}
String showOrder = Util . null2String ( map . get ( "show_order" ) ) ;
if ( StringUtils . isBlank ( showOrder ) ) {
Integer maxShowOrder = MapperProxyFactory . getProxy ( JobMapper . class ) . getMaxShowOrder ( ) ;
if ( null = = maxShowOrder ) {
maxShowOrder = 0 ;
}
map . put ( "show_order" , maxShowOrder + 1 ) ;
}
ExtendInfoParams infoParams = ExtendInfoParams . builder ( ) . tableName ( "JCL_ORG_JOB" ) . params ( map ) . build ( ) ;
map . put ( "jobactivityid" , JobServiceImpl . JOB_ACTIVITY_ID ) ;
Map < String , Object > syncMap = new OrganizationSyncEc ( user , LogModuleNameEnum . JOB , OperateTypeEnum . ADD , map , false ) . sync ( ) ;
if ( OrgImportUtil . isThrowError ( syncMap ) ) {
boolean assertNameRepeat = JobServiceImpl . assertNameRepeat ( null , Util . null2String ( map . get ( "ec_department" ) ) , Util . null2String ( map . get ( "parent_job" ) ) , Util . null2String ( map . get ( "job_name" ) ) ) ;
if ( assertNameRepeat ) {
map . remove ( "jobactivityid" ) ;
MapperProxyFactory . getProxy ( ExtMapper . class ) . insertTable ( infoParams ) ;
// 更新组织架构图
new JobTriggerRunnable ( infoParams . getId ( ) ) . run ( ) ;
historyDetailPO . setOperateDetail ( "添加成功" ) ;
historyDetailPO . setStatus ( "1" ) ;
} else {
historyDetailPO . setOperateDetail ( "岗位名称已存在" ) ;
historyDetailPO . setStatus ( "0" ) ;
}
} else {
historyDetailPO . setOperateDetail ( Util . null2String ( syncMap . get ( "message" ) ) ) ;
historyDetailPO . setStatus ( "0" ) ;
}
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
} else if ( "update" . equals ( operateType ) ) {
// 查询对应ID
if ( StringUtils . isNotBlank ( jobNo ) ) {
if ( jobId = = null ) {
historyDetailPO . setOperateDetail ( "未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue ;
}
if ( checkRepeatNo ( jobNo , JOB_TYPE , jobId ) ) {
map . put ( "update_time" , new Date ( ) ) ;
map . put ( "jobactivityid" , JobServiceImpl . JOB_ACTIVITY_ID ) ;
map . put ( "id" , jobId ) ;
Map < String , Object > syncMap = new OrganizationSyncEc ( user , LogModuleNameEnum . JOB , OperateTypeEnum . UPDATE , map , MapperProxyFactory . getProxy ( JobMapper . class ) . getJobById ( jobId ) , false ) . sync ( ) ;
if ( OrgImportUtil . isThrowError ( syncMap ) ) {
boolean assertNameRepeat = JobServiceImpl . assertNameRepeat ( jobId . toString ( ) , Util . null2String ( map . get ( "ec_department" ) ) , Util . null2String ( map . get ( "parent_job" ) ) , Util . null2String ( map . get ( "job_name" ) ) ) ;
if ( assertNameRepeat ) {
map . remove ( "id" ) ;
map . remove ( "jobactivityid" ) ;
MapperProxyFactory . getProxy ( ExtMapper . class ) . updateTable ( ExtendInfoParams . builder ( ) . id ( jobId ) . tableName ( "JCL_ORG_JOB" ) . params ( map ) . build ( ) ) ;
// 更新组织架构图
new JobTriggerRunnable ( jobId ) . run ( ) ;
historyDetailPO . setOperateDetail ( "更新成功" ) ;
historyDetailPO . setStatus ( "1" ) ;
} else {
historyDetailPO . setOperateDetail ( "岗位名称已存在" ) ;
historyDetailPO . setStatus ( "0" ) ;
}
} else {
historyDetailPO . setOperateDetail ( Util . null2String ( syncMap . get ( "message" ) ) ) ;
historyDetailPO . setStatus ( "0" ) ;
}
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
} else {
historyDetailPO . setOperateDetail ( jobNo + "编号已存在" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
}
} else {
historyDetailPO . setOperateDetail ( "编号为空,更新失败" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
}
}
}
return importHistoryId ;
}
private Long hrmResourceImport ( String operateType , String excelFile , String keyField ) {
Long importHistoryId = OrgImportUtil . saveImportLog ( "resource" , operateType , user ) ;
JclImportHistoryDetailPO historyDetailPO ;
ImageFileManager manager = new ImageFileManager ( ) ;
manager . getImageFileInfoById ( Util . getIntValue ( excelFile ) ) ;
XSSFWorkbook workbook ;
try {
workbook = new XSSFWorkbook ( manager . getInputStream ( ) ) ;
} catch ( IOException e ) {
throw new RuntimeException ( e ) ;
}
// 当前sheet
XSSFSheet sheetAt = workbook . getSheetAt ( 0 ) ;
int lastRow = sheetAt . getLastRowNum ( ) ;
List < ExtendInfoPO > extendInfoPOS = new ArrayList < > ( ) ;
OrganizationAssert . isTrue ( lastRow > 0 , "导入数据为空" ) ;
short lastCellNum = sheetAt . getRow ( 0 ) . getLastCellNum ( ) ;
// 遍历每一行数据
nextRow :
for ( int i = 0 ; i < = lastRow ; i + + ) {
historyDetailPO = new JclImportHistoryDetailPO ( ) ;
historyDetailPO . setPid ( importHistoryId ) ;
XSSFRow row = sheetAt . getRow ( i ) ;
if ( null = = row ) {
continue ;
}
// 组装待处理数据
Map < String , Object > map = new HashMap < > ( ) ;
Integer parentCompanyId = null ;
Integer parentDepartmentId = null ;
Long parentJobId = null ;
historyDetailPO . setRowNums ( String . valueOf ( i + 1 ) ) ;
for ( int cellIndex = 0 ; cellIndex < lastCellNum ; cellIndex + + ) {
XSSFCell cell = row . getCell ( ( short ) cellIndex ) ;
String cellValue = getCellValue ( cell ) . trim ( ) ;
if ( i = = 0 ) {
// 首行 初始化字段信息
List < ExtendInfoPO > infoPOList = getExtendInfoMapper ( ) . getInfoByExtendAndLabelName ( RESOURCE_TYPE , cellValue ) ;
boolean isBreak = OrgImportUtil . isBreak ( historyDetailPO , cellValue , infoPOList ) ;
if ( isBreak ) {
break nextRow ;
}
ExtendInfoPO extendInfoPO = infoPOList . get ( 0 ) ;
extendInfoPOS . add ( extendInfoPO ) ;
} else {
ExtendInfoPO infoPO = extendInfoPOS . get ( cellIndex ) ;
// 数据校验
if ( infoPO . getIsrequired ( ) = = 1 & & StringUtils . isBlank ( cellValue ) & & ! "work_code" . equalsIgnoreCase ( infoPO . getFieldName ( ) ) ) {
historyDetailPO . setOperateDetail ( infoPO . getFieldNameDesc ( ) + "为必填项" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
Object reallyValue ;
try {
reallyValue = OrgImportUtil . getReallyValue ( infoPO , cellValue ) ;
} catch ( Exception e ) {
historyDetailPO . setOperateDetail ( cellValue + "转换失败" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
if ( StringUtils . isNotBlank ( cellValue ) & & StringUtils . isBlank ( Util . null2String ( reallyValue ) ) & & ! "ec_company" . equals ( infoPO . getFieldName ( ) ) & & ! "ec_department" . equals ( infoPO . getFieldName ( ) ) & & ! "job_title" . equals ( infoPO . getFieldName ( ) ) ) {
historyDetailPO . setOperateDetail ( infoPO . getFieldNameDesc ( ) + "数据转换失败,未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
map . put ( infoPO . getFieldName ( ) , reallyValue ) ;
// 上级分部
if ( "ec_company" . equals ( infoPO . getFieldName ( ) ) ) {
String [ ] split = cellValue . split ( ">" ) ;
if ( split . length > 0 ) {
if ( split . length > 8 ) {
historyDetailPO . setOperateDetail ( "分部层级不能大于10" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
for ( String s : split ) {
parentCompanyId = MapperProxyFactory . getProxy ( CompMapper . class ) . getIdByNameAndPid ( s , parentCompanyId = = null ? 0 : parentCompanyId ) ;
if ( null = = parentCompanyId ) {
historyDetailPO . setOperateDetail ( cellValue + "分部未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
}
}
}
if ( "ec_department" . equals ( infoPO . getFieldName ( ) ) ) {
String [ ] split = cellValue . split ( ">" ) ;
if ( split . length > 0 ) {
if ( split . length > 8 ) {
historyDetailPO . setOperateDetail ( "部门层级不能大于10" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
for ( String s : split ) {
parentDepartmentId = MapperProxyFactory . getProxy ( DepartmentMapper . class ) . getIdByNameAndPid ( s , parentCompanyId , parentDepartmentId = = null ? 0 : parentDepartmentId ) ;
if ( null = = parentDepartmentId ) {
historyDetailPO . setOperateDetail ( cellValue + "部门未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
}
}
}
if ( "job_title" . equals ( infoPO . getFieldName ( ) ) ) {
if ( null = = parentCompanyId ) {
historyDetailPO . setOperateDetail ( cellValue + "所属分部未找到" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
String [ ] split = cellValue . split ( ">" ) ;
if ( split . length > 0 ) {
if ( split . length > 8 ) {
historyDetailPO . setOperateDetail ( "岗位层级不能大于10" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
for ( String s : split ) {
parentJobId = MapperProxyFactory . getProxy ( JobMapper . class ) . getIdByNameAndPid ( s , parentCompanyId , parentDepartmentId = = null ? 0 : parentDepartmentId , parentJobId = = null ? 0 : parentJobId ) ;
if ( null = = parentJobId ) {
historyDetailPO . setOperateDetail ( s + "岗位未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue nextRow ;
}
}
}
map . put ( "company_id" , parentCompanyId ) ;
map . put ( "department_id" , parentDepartmentId ) ;
map . put ( "ec_company" , parentCompanyId ) ;
map . put ( "ec_department" , parentDepartmentId ) ;
map . put ( "job_title" , parentJobId ) ;
}
}
}
// 校验、数据交互
if ( i = = 0 ) {
continue ;
}
// 根据岗位获取等级方案、岗位序列、职等、职级
if ( null ! = parentJobId ) {
JobPO jobById = MapperProxyFactory . getProxy ( JobMapper . class ) . getJobById ( parentJobId ) ;
map . put ( "scheme_id" , jobById . getSchemeId ( ) ) ;
map . put ( "sequence_id" , jobById . getSequenceId ( ) ) ;
map . put ( "job_level" , jobById . getLevelId ( ) ) ;
map . put ( "job_grade" , jobById . getGradeId ( ) ) ;
}
String keyFieldValue = Util . null2String ( map . get ( keyField ) ) ;
if ( StringUtils . isBlank ( keyFieldValue ) ) {
historyDetailPO . setOperateDetail ( "所选重复验证字段为空" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue ;
}
historyDetailPO . setRelatedName ( keyFieldValue ) ;
// 判断当前人员是否存在
boolean hasSameKeyFieldValue = hasSameKeyFieldValue ( historyDetailPO , keyField , keyFieldValue ) ;
if ( hasSameKeyFieldValue ) {
continue ;
}
Long resourceId = MapperProxyFactory . getProxy ( ResourceMapper . class ) . getIdByKeyField ( keyField , keyFieldValue ) . get ( 0 ) ;
if ( "add" . equals ( operateType ) ) {
if ( resourceId ! = null ) {
historyDetailPO . setOperateDetail ( keyFieldValue + "已存在" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue ;
}
// 自动编号
String workCode = Util . null2String ( map . get ( "work_code" ) ) ;
try {
// 自动编号
try {
workCode = HrmResourceServiceImpl . repeatDetermine ( workCode ) ;
} catch ( OrganizationRunTimeException e ) {
historyDetailPO . setOperateDetail ( e . getMessage ( ) ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue ;
}
map . put ( "work_code" , workCode ) ;
} catch ( Exception e ) {
historyDetailPO . setOperateDetail ( Util . null2String ( e . getMessage ( ) ) ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
}
map . put ( "creator" , user . getUID ( ) ) ;
map . put ( "delete_type" , 0 ) ;
map . put ( "create_time" , new Date ( ) ) ;
String showOrder = Util . null2String ( map . get ( "show_order" ) ) ;
if ( StringUtils . isBlank ( showOrder ) ) {
Long maxShowOrder = MapperProxyFactory . getProxy ( ResourceMapper . class ) . getMaxShowOrder ( ) ;
if ( null = = maxShowOrder ) {
maxShowOrder = 0 L ;
}
map . put ( "show_order" , maxShowOrder + 1 ) ;
}
Map < String , Object > syncMap = new OrganizationSyncEc ( user , LogModuleNameEnum . RESOURCE , OperateTypeEnum . ADD , map , false ) . sync ( ) ;
if ( OrgImportUtil . isThrowError ( syncMap ) & & StringUtils . isNotBlank ( Util . null2String ( syncMap . get ( "id" ) ) ) ) {
String ecResourceId = Util . null2String ( syncMap . get ( "id" ) ) ;
RecordInfo recordInfo = getSystemDataMapper ( ) . getHrmObjectByID ( HRM_RESOURCE , ecResourceId ) ;
map . put ( "uuid" , recordInfo . getUuid ( ) ) ;
ExtendInfoParams infoParams = ExtendInfoParams . builder ( ) . tableName ( "JCL_ORG_HRMRESOURCE" ) . params ( map ) . build ( ) ;
map . remove ( "id" ) ;
MapperProxyFactory . getProxy ( ExtMapper . class ) . insertTable ( infoParams ) ;
// 更新组织架构图
new HrmResourceTriggerRunnable ( infoParams . getId ( ) ) . run ( ) ;
historyDetailPO . setOperateDetail ( "添加成功" ) ;
historyDetailPO . setStatus ( "1" ) ;
} else {
historyDetailPO . setOperateDetail ( Util . null2String ( syncMap . get ( "message" ) ) ) ;
historyDetailPO . setStatus ( "0" ) ;
}
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
} else if ( "update" . equals ( operateType ) ) {
// 查询对应ID
if ( resourceId = = null ) {
historyDetailPO . setOperateDetail ( "未找到对应数据" ) ;
historyDetailPO . setStatus ( "0" ) ;
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
continue ;
}
map . put ( "update_time" , new Date ( ) ) ;
map . put ( "id" , resourceId ) ;
Map < String , Object > syncMap = new OrganizationSyncEc ( user , LogModuleNameEnum . RESOURCE , OperateTypeEnum . UPDATE , map , false ) . sync ( ) ;
if ( OrgImportUtil . isThrowError ( syncMap ) ) {
map . remove ( "id" ) ;
MapperProxyFactory . getProxy ( ExtMapper . class ) . updateTable ( ExtendInfoParams . builder ( ) . id ( resourceId ) . tableName ( "JCL_ORG_HRMRESOURCE" ) . params ( map ) . build ( ) ) ;
// 更新组织架构图
new HrmResourceTriggerRunnable ( resourceId ) . run ( ) ;
historyDetailPO . setOperateDetail ( "更新成功" ) ;
historyDetailPO . setStatus ( "1" ) ;
} else {
historyDetailPO . setOperateDetail ( Util . null2String ( syncMap . get ( "message" ) ) ) ;
historyDetailPO . setStatus ( "0" ) ;
}
OrgImportUtil . saveImportDetailLog ( historyDetailPO ) ;
}
}
return importHistoryId ;
}
/ * *
* 方 案 职 等 职 级 导 入
* /
@ -1438,27 +751,6 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
}
/ * *
* 校 验 重 复 编 号
* /
private boolean checkRepeatNo ( String no , Long extendType , Long id ) {
if ( StringUtils . isBlank ( no ) ) {
return true ;
}
if ( null ! = extendType ) {
switch ( extendType . toString ( ) ) {
case "1" :
// return 0 == MapperProxyFactory.getProxy(CompMapper.class).checkRepeatNo(no, id);
case "2" :
return 0 = = MapperProxyFactory . getProxy ( DepartmentMapper . class ) . checkRepeatNo ( no , id ) ;
case "3" :
return 0 = = MapperProxyFactory . getProxy ( JobMapper . class ) . checkRepeatNo ( no , id ) ;
default :
return false ;
}
}
return false ;
}
/ * *
* 生 成 导 入 模 板 文 件
@ -1472,20 +764,39 @@ public class ImportCommonServiceImpl extends Service implements ImportCommonServ
List < Object > gradeList = new ArrayList < > ( ) ;
Object companyColumn = "" ;
Object departmentColumn = "" ;
String companyFieldName = "所属分部" ;
String departmentFieldName = "所属部门" ;
switch ( importType ) {
case "company" :
companyFieldName = "简称" ;
departmentFieldName = "" ;
break ;
case "department" :
companyFieldName = "所属分部" ;
departmentFieldName = "简称" ;
break ;
case "resource" :
companyFieldName = "分部" ;
departmentFieldName = "部门" ;
break ;
default :
break ;
}
// 排序
/ *
第 一 列 : 所 属 分 部
第 二 列 : 所 属 部 门 \ 上 级 部 门 \ 部 门
第 一 列 : 分部
第 二 列 : 部门
* /
Iterator < Object > iterator = columnList . iterator ( ) ;
while ( iterator . hasNext ( ) ) {
Object column = iterator . next ( ) ;
if ( "所属分部" . equals ( column . toString ( ) ) ) {
if ( companyFieldName . equals ( column . toString ( ) ) ) {
companyColumn = column ;
iterator . remove ( ) ;
}
if ( "所属部门" . equals ( column ) | | "上级部门" . equals ( column ) ) {
if ( departmentFieldName . equals ( column ) ) {
departmentColumn = column ;
iterator . remove ( ) ;
}