2022-05-27 18:05:15 +08:00
package com.engine.organization.service.impl ;
2022-05-30 18:39:03 +08:00
import com.alibaba.fastjson.JSONObject ;
2022-09-15 18:31:11 +08:00
import com.api.browser.bean.BrowserBean ;
2022-05-30 18:39:03 +08:00
import com.api.browser.bean.SearchConditionGroup ;
import com.api.browser.bean.SearchConditionItem ;
import com.api.browser.bean.SearchConditionOption ;
import com.cloudstore.eccom.pc.table.WeaTableColumn ;
import com.cloudstore.eccom.result.WeaResultMsg ;
import com.engine.common.util.ServiceUtil ;
2022-05-27 18:05:15 +08:00
import com.engine.core.impl.Service ;
2022-06-06 13:17:35 +08:00
import com.engine.hrm.entity.RuleCodeType ;
2022-05-30 18:39:03 +08:00
import com.engine.organization.component.OrganizationWeaTable ;
2022-06-01 14:38:39 +08:00
import com.engine.organization.entity.DeleteParam ;
2022-09-15 18:31:11 +08:00
import com.engine.organization.entity.browser.po.CustomBrowserBean ;
2022-06-23 13:43:52 +08:00
import com.engine.organization.entity.codesetting.po.CodeRulePO ;
2022-08-11 15:14:54 +08:00
import com.engine.organization.entity.commom.RecordInfo ;
2022-05-30 18:40:25 +08:00
import com.engine.organization.entity.company.bo.CompBO ;
import com.engine.organization.entity.company.po.CompPO ;
2022-05-27 18:05:15 +08:00
import com.engine.organization.entity.department.bo.DepartmentBO ;
import com.engine.organization.entity.department.po.DepartmentPO ;
2022-06-01 14:38:39 +08:00
import com.engine.organization.entity.employee.vo.EmployeeTableVO ;
2022-06-14 14:31:52 +08:00
import com.engine.organization.entity.extend.po.ExtendTitlePO ;
2022-05-30 18:39:03 +08:00
import com.engine.organization.entity.job.bo.JobBO ;
import com.engine.organization.entity.job.dto.JobListDTO ;
2022-06-24 18:26:15 +08:00
import com.engine.organization.entity.job.param.JobMergeParam ;
2022-05-30 18:39:03 +08:00
import com.engine.organization.entity.job.param.JobSearchParam ;
import com.engine.organization.entity.job.po.JobPO ;
2022-08-22 13:35:21 +08:00
import com.engine.organization.entity.scheme.po.GradePO ;
2022-05-27 18:05:15 +08:00
import com.engine.organization.entity.searchtree.SearchTree ;
import com.engine.organization.entity.searchtree.SearchTreeParams ;
2022-07-15 09:02:18 +08:00
import com.engine.organization.enums.LogModuleNameEnum ;
import com.engine.organization.enums.OperateTypeEnum ;
2022-06-23 13:43:52 +08:00
import com.engine.organization.mapper.codesetting.CodeRuleMapper ;
2022-05-27 18:05:15 +08:00
import com.engine.organization.mapper.comp.CompMapper ;
import com.engine.organization.mapper.department.DepartmentMapper ;
2022-08-22 09:10:00 +08:00
import com.engine.organization.mapper.extend.ExtDTMapper ;
import com.engine.organization.mapper.extend.ExtMapper ;
2022-06-14 14:31:52 +08:00
import com.engine.organization.mapper.extend.ExtendTitleMapper ;
2022-07-15 09:02:18 +08:00
import com.engine.organization.mapper.hrmresource.SystemDataMapper ;
2022-05-30 18:39:03 +08:00
import com.engine.organization.mapper.job.JobMapper ;
2022-08-22 13:35:21 +08:00
import com.engine.organization.mapper.scheme.GradeMapper ;
2022-05-30 18:39:03 +08:00
import com.engine.organization.service.ExtService ;
2022-05-27 18:05:15 +08:00
import com.engine.organization.service.JobService ;
2022-08-31 14:24:00 +08:00
import com.engine.organization.thread.JobTriggerRunnable ;
2022-08-26 15:36:06 +08:00
import com.engine.organization.thread.OrganizationSyncEc ;
2022-09-15 10:41:04 +08:00
import com.engine.organization.trigger.cusfielddata.CusFieldDataTrigger ;
2022-06-23 18:49:47 +08:00
import com.engine.organization.util.* ;
2022-06-06 17:48:11 +08:00
import com.engine.organization.util.coderule.CodeRuleUtil ;
2022-05-27 18:05:15 +08:00
import com.engine.organization.util.db.MapperProxyFactory ;
2022-05-30 18:39:03 +08:00
import com.engine.organization.util.page.Column ;
import com.engine.organization.util.page.PageInfo ;
import com.engine.organization.util.page.PageUtil ;
2022-07-13 17:19:45 +08:00
import com.engine.organization.util.relation.EcHrmRelationUtil ;
2022-06-06 14:41:46 +08:00
import com.engine.organization.util.tree.SearchTreeUtil ;
2022-05-27 18:05:15 +08:00
import org.apache.commons.collections4.CollectionUtils ;
2022-06-23 13:43:52 +08:00
import org.apache.commons.lang.StringUtils ;
2022-09-07 19:12:42 +08:00
import weaver.conn.RecordSet ;
2022-05-27 18:05:15 +08:00
import weaver.general.StringUtil ;
import weaver.general.Util ;
2022-05-30 18:39:03 +08:00
import weaver.hrm.User ;
2022-05-27 18:05:15 +08:00
import java.util.* ;
import java.util.stream.Collectors ;
/ * *
2022-06-14 11:07:48 +08:00
* @description :
2022-05-27 18:05:15 +08:00
* @author : dxfeng
* @createTime : 2022 / 05 / 26
* @version : 1 . 0
* /
public class JobServiceImpl extends Service implements JobService {
2022-05-30 18:39:03 +08:00
/ * *
* 左侧树 类型表示
* < p >
* 0 : 集团
* 1 : 分部
* 2 : 部门
* /
2022-05-27 18:05:15 +08:00
private static final String TYPE_COMP = " 1 " ;
private static final String TYPE_DEPT = " 2 " ;
2022-05-30 18:39:03 +08:00
/ * *
* 分组类型
* 1 : 分部
* 2 : 部门
* 3 : 岗位
* /
private static final String EXTEND_TYPE = " 3 " ;
2022-06-13 17:22:34 +08:00
/ * *
* 主表
* /
private static final String JCL_ORG_JOB = " JCL_ORG_JOB " ;
2022-05-30 18:39:03 +08:00
/ * *
* 主表拓展表
* /
private static final String JCL_ORG_JOBEXT = " JCL_ORG_JOBEXT " ;
/ * *
* 明细表拓展表
* /
private static final String JCL_ORG_JOBEXT_DT1 = " JCL_ORG_JOBEXT_DT1 " ;
2022-06-07 12:02:36 +08:00
private static final String RIGHT_NAME = " Job:All " ;
2022-07-27 16:47:19 +08:00
public static final String JOB_ACTIVITY_ID ;
2022-07-15 09:02:18 +08:00
2022-06-13 17:22:34 +08:00
/ * *
* 岗位主表title指定ID
* /
2022-06-17 16:00:05 +08:00
private static final Long GROUP_ID = 3L ;
2022-06-13 17:22:34 +08:00
2022-07-27 16:47:19 +08:00
private static JobMapper getJobMapper ( ) {
2022-05-30 18:39:03 +08:00
return MapperProxyFactory . getProxy ( JobMapper . class ) ;
}
2022-05-27 18:05:15 +08:00
private CompMapper getCompMapper ( ) {
return MapperProxyFactory . getProxy ( CompMapper . class ) ;
}
private DepartmentMapper getDepartmentMapper ( ) {
return MapperProxyFactory . getProxy ( DepartmentMapper . class ) ;
}
2022-06-14 14:31:52 +08:00
private ExtendTitleMapper getExtendTitleMapper ( ) {
return MapperProxyFactory . getProxy ( ExtendTitleMapper . class ) ;
2022-05-30 18:39:03 +08:00
}
private ExtService getExtService ( User user ) {
return ServiceUtil . getService ( ExtServiceImpl . class , user ) ;
}
2022-07-15 09:02:18 +08:00
static {
2022-08-11 15:14:54 +08:00
RecordInfo hrmJobActivity = MapperProxyFactory . getProxy ( SystemDataMapper . class ) . getHrmObjectByUUID ( " hrmjobactivities " , " 3a2efce3-95de-4ec2-afe1-347783817bdb " ) ;
JOB_ACTIVITY_ID = hrmJobActivity . getId ( ) ;
2022-07-15 09:02:18 +08:00
}
2022-05-27 18:05:15 +08:00
@Override
public Map < String , Object > getSearchTree ( SearchTreeParams params ) {
String keyword = params . getKeyword ( ) ;
String id = params . getId ( ) ;
2022-06-06 14:41:46 +08:00
String type = Util . null2String ( params . getType ( ) ) ;
List < SearchTree > treeList = getFilterCompany ( id , type , keyword ) ;
return SearchTreeUtil . getSearchTree ( type , treeList ) ;
2022-05-27 18:05:15 +08:00
}
2022-05-30 18:39:03 +08:00
@Override
public Map < String , Object > listPage ( JobSearchParam param ) {
Map < String , Object > datas = new HashMap < > ( ) ;
2022-06-07 12:02:36 +08:00
boolean hasRight = HasRightUtil . hasRight ( user , RIGHT_NAME , true ) ;
datas . put ( " hasRight " , hasRight ) ;
if ( ! hasRight ) {
2022-06-06 19:19:28 +08:00
return datas ;
}
2022-05-31 21:39:20 +08:00
JobPO jobPO = JobBO . convertParamsToPO ( param , user . getUID ( ) ) ;
2022-05-30 18:39:03 +08:00
boolean filter = isFilter ( jobPO ) ;
PageInfo < JobListDTO > pageInfos ;
2022-06-23 18:49:47 +08:00
String orderSql = PageInfoSortUtil . getSortSql ( param . getSortParams ( ) ) ;
List < JobListDTO > allList = getJobMapper ( ) . listNoFilter ( orderSql ) ;
2022-05-30 18:39:03 +08:00
// 通过子级遍历父级元素
if ( filter ) {
// 根据条件获取元素
2022-06-24 14:40:49 +08:00
List < JobListDTO > filterJobPOs = getJobMapper ( ) . listByFilter ( jobPO , orderSql ) ;
2022-05-30 18:39:03 +08:00
// 添加父级元素
2022-06-02 09:58:16 +08:00
List < JobListDTO > jobListDTOS = JobBO . buildJobDTOList ( allList , filterJobPOs ) ;
List < JobListDTO > subList = PageUtil . subList ( param . getCurrent ( ) , param . getPageSize ( ) , jobListDTOS ) ;
2022-05-30 18:39:03 +08:00
pageInfos = new PageInfo < > ( subList , JobListDTO . class ) ;
2022-06-02 09:58:16 +08:00
pageInfos . setTotal ( jobListDTOS . size ( ) ) ;
2022-05-30 18:39:03 +08:00
} else {
// 组合list
2022-06-02 09:58:16 +08:00
List < JobListDTO > jobListDTOS = JobBO . buildDTOList ( allList ) ;
List < JobListDTO > subList = PageUtil . subList ( param . getCurrent ( ) , param . getPageSize ( ) , jobListDTOS ) ;
2022-05-30 18:39:03 +08:00
pageInfos = new PageInfo < > ( subList , JobListDTO . class ) ;
2022-06-02 09:58:16 +08:00
pageInfos . setTotal ( jobListDTOS . size ( ) ) ;
2022-05-30 18:39:03 +08:00
}
pageInfos . setPageNum ( param . getCurrent ( ) ) ;
pageInfos . setPageSize ( param . getPageSize ( ) ) ;
2022-06-02 09:58:16 +08:00
OrganizationWeaTable < JobListDTO > table = new OrganizationWeaTable < > ( user , JobListDTO . class ) ;
2022-05-30 18:39:03 +08:00
List < Column > columns = pageInfos . getColumns ( ) ;
List < WeaTableColumn > weaTableColumn = columns . stream ( ) . map ( v - > new WeaTableColumn ( " 100 " , v . getTitle ( ) , v . getKey ( ) ) ) . collect ( Collectors . toList ( ) ) ;
table . setColumns ( weaTableColumn ) ;
WeaResultMsg result = new WeaResultMsg ( false ) ;
result . putAll ( table . makeDataResult ( ) ) ;
result . success ( ) ;
datas . put ( " pageInfo " , pageInfos ) ;
datas . put ( " dataKey " , result . getResultMap ( ) ) ;
return datas ;
}
@Override
2022-09-14 17:14:12 +08:00
public Map < String , List < MenuBtn > > getHasRight ( ) {
2022-06-06 19:19:28 +08:00
return MenuBtn . getDatasHasCopy ( ) ;
2022-05-30 18:39:03 +08:00
}
@Override
public Map < String , Object > getSearchCondition ( ) {
Map < String , Object > apiDatas = new HashMap < > ( ) ;
List < SearchConditionGroup > addGroups = new ArrayList < > ( ) ;
List < SearchConditionItem > conditionItems = new ArrayList < > ( ) ;
// 编号
SearchConditionItem jobNoItem = OrganizationFormItemUtil . inputItem ( user , 2 , 16 , 2 , 50 , " 编号 " , " jobNo " ) ;
// 名称
SearchConditionItem jobNameItem = OrganizationFormItemUtil . inputItem ( user , 2 , 16 , 2 , 50 , " 名称 " , " jobName " ) ;
// 所属分部
2022-07-13 17:19:45 +08:00
SearchConditionItem parentCompBrowserItem = OrganizationFormItemUtil . browserItem ( user , 2 , 16 , 2 , false , " 所属分部 " , " 164 " , " ecCompany " , " " ) ;
2022-05-30 18:39:03 +08:00
// 所属部门
2022-07-13 17:19:45 +08:00
SearchConditionItem parentDeptBrowserItem = OrganizationFormItemUtil . browserItem ( user , 2 , 16 , 2 , false , " 所属部门 " , " 4 " , " ecDepartment " , " " ) ;
2022-05-30 18:39:03 +08:00
// 岗位序列
SearchConditionItem sequenceBrowserItem = OrganizationFormItemUtil . browserItem ( user , 2 , 16 , 2 , false , " 岗位序列 " , " 161 " , " sequenceId " , " sequenceBrowser " ) ;
// 等级方案
2022-05-31 09:56:50 +08:00
SearchConditionItem schemeBrowserItem = OrganizationFormItemUtil . browserItem ( user , 2 , 16 , 2 , false , " 等级方案 " , " 161 " , " schemeId " , " schemeBrowser " ) ;
2022-05-30 18:39:03 +08:00
// 上级岗位
2022-09-07 15:40:19 +08:00
SearchConditionItem parentJobBrowserItem = OrganizationFormItemUtil . browserItem ( user , 2 , 16 , 2 , false , " 上级岗位 " , " 666 " , " parentJob " , " " ) ;
2022-09-15 18:31:11 +08:00
BrowserBean browserBean = parentJobBrowserItem . getBrowserConditionParam ( ) ;
String s = JSONObject . toJSONString ( browserBean ) ;
CustomBrowserBean customBrowserBean = JSONObject . parseObject ( s , CustomBrowserBean . class ) ;
customBrowserBean . setHasLeftTree ( true ) ;
customBrowserBean . setLeftToSearchKey ( " treeKey " ) ;
parentJobBrowserItem . setBrowserConditionParam ( customBrowserBean ) ;
2022-05-30 18:39:03 +08:00
// 是否关键岗
List < SearchConditionOption > isKeyOptions = new ArrayList < > ( ) ;
SearchConditionOption yesOption = new SearchConditionOption ( " 0 " , " 否 " ) ;
SearchConditionOption noOption = new SearchConditionOption ( " 1 " , " 是 " ) ;
isKeyOptions . add ( yesOption ) ;
isKeyOptions . add ( noOption ) ;
2022-10-17 11:35:46 +08:00
SearchConditionItem isKeyItem = OrganizationFormItemUtil . selectItem ( user , isKeyOptions , 2 , 16 , 6 , false , " 是否关键岗 " , " isKey " ) ;
2022-05-30 18:39:03 +08:00
// 工作地点
SearchConditionItem workplaceItem = OrganizationFormItemUtil . inputItem ( user , 2 , 16 , 2 , 50 , " 工作地点 " , " workplace " ) ;
// 禁用标记
List < SearchConditionOption > selectOptions = new ArrayList < > ( ) ;
SearchConditionOption enableOption = new SearchConditionOption ( " true " , " 启用 " ) ;
SearchConditionOption disableOption = new SearchConditionOption ( " false " , " 禁用 " ) ;
selectOptions . add ( enableOption ) ;
selectOptions . add ( disableOption ) ;
SearchConditionItem forbiddenTagItem = OrganizationFormItemUtil . selectItem ( user , selectOptions , 2 , 16 , 6 , false , " 禁用标记 " , " forbiddenTag " ) ;
conditionItems . add ( jobNoItem ) ;
conditionItems . add ( jobNameItem ) ;
conditionItems . add ( parentCompBrowserItem ) ;
conditionItems . add ( parentDeptBrowserItem ) ;
conditionItems . add ( sequenceBrowserItem ) ;
conditionItems . add ( schemeBrowserItem ) ;
conditionItems . add ( parentJobBrowserItem ) ;
conditionItems . add ( isKeyItem ) ;
conditionItems . add ( workplaceItem ) ;
conditionItems . add ( forbiddenTagItem ) ;
addGroups . add ( new SearchConditionGroup ( " 高级搜索条件 " , true , conditionItems ) ) ;
apiDatas . put ( " conditions " , addGroups ) ;
return apiDatas ;
}
@Override
2022-09-07 15:40:19 +08:00
public Map < String , Object > getSaveForm ( JobSearchParam param ) {
2022-06-13 17:22:34 +08:00
HasRightUtil . hasRight ( user , RIGHT_NAME , false ) ;
2022-05-30 18:39:03 +08:00
Map < String , Object > apiDatas = new HashMap < > ( ) ;
List < SearchConditionGroup > addGroups = new ArrayList < > ( ) ;
2022-08-23 17:43:09 +08:00
List < ExtendTitlePO > extendTitles = getExtendTitleMapper ( ) . getTitlesByGroupID ( GROUP_ID , " 1 " ) ;
2022-06-14 14:31:52 +08:00
if ( CollectionUtils . isNotEmpty ( extendTitles ) ) {
2022-09-07 15:40:19 +08:00
Map < String , Object > params = new HashMap < > ( ) ;
// 分部
if ( StringUtils . isNotBlank ( Util . null2String ( param . getSubcompanyid1 ( ) ) ) ) {
CompPO compPO = getCompMapper ( ) . listById ( param . getSubcompanyid1 ( ) ) ;
if ( null ! = compPO ) {
params . put ( " parent_comp " , compPO . getId ( ) ) ;
params . put ( " ec_company " , EcHrmRelationUtil . getEcCompanyId ( compPO . getId ( ) . toString ( ) ) ) ;
}
}
// 部门
if ( StringUtils . isNotBlank ( Util . null2String ( param . getDepartmentid ( ) ) ) ) {
DepartmentPO deptById = getDepartmentMapper ( ) . getDeptById ( param . getDepartmentid ( ) ) ;
if ( null ! = deptById ) {
params . put ( " parent_dept " , deptById . getId ( ) ) ;
params . put ( " ec_department " , EcHrmRelationUtil . getEcDepartmentId ( deptById . getId ( ) . toString ( ) ) ) ;
params . put ( " parent_comp " , deptById . getParentComp ( ) ) ;
params . put ( " ec_company " , EcHrmRelationUtil . getEcCompanyId ( deptById . getParentComp ( ) . toString ( ) ) ) ;
}
}
2022-06-14 14:31:52 +08:00
for ( ExtendTitlePO extendTitle : extendTitles ) {
2022-09-07 15:40:19 +08:00
List < SearchConditionItem > items = getExtService ( user ) . getExtSaveForm ( user , EXTEND_TYPE + " " , JCL_ORG_JOB , 2 , extendTitle . getId ( ) . toString ( ) , " job_no " , RuleCodeType . JOBTITLES . getValue ( ) , params , " scheme_id " , " parent_comp " ) ;
2022-06-23 09:14:19 +08:00
if ( CollectionUtils . isNotEmpty ( items ) ) {
addGroups . add ( new SearchConditionGroup ( extendTitle . getTitle ( ) , true , items ) ) ;
}
2022-06-13 17:22:34 +08:00
}
2022-06-06 13:17:35 +08:00
}
2022-05-30 18:39:03 +08:00
apiDatas . put ( " condition " , addGroups ) ;
return apiDatas ;
}
@Override
public Map < String , Object > getJobBaseForm ( Map < String , Object > params ) {
OrganizationAssert . notNull ( params . get ( " viewAttr " ) , " 请标识操作类型 " ) ;
// 2编辑 1查看
int viewAttr = Integer . parseInt ( ( String ) params . get ( " viewAttr " ) ) ;
long id = Long . parseLong ( ( String ) params . get ( " id " ) ) ;
String groupId = ( String ) params . get ( " viewCondition " ) ;
HashMap < String , Object > buttonsMap = new HashMap < > ( ) ;
buttonsMap . put ( " hasEdit " , true ) ;
buttonsMap . put ( " hasSave " , true ) ;
List < SearchConditionGroup > addGroups = new ArrayList < > ( ) ;
2022-06-13 17:22:34 +08:00
if ( " 0 " . equals ( groupId ) ) {
groupId = GROUP_ID . toString ( ) ;
}
2022-08-22 13:35:21 +08:00
List < ExtendTitlePO > extendTitles = getExtendTitleMapper ( ) . getTitlesByGroupID ( Long . parseLong ( groupId ) , " 1 " ) ;
2022-06-14 14:31:52 +08:00
if ( CollectionUtils . isNotEmpty ( extendTitles ) ) {
for ( ExtendTitlePO extendTitle : extendTitles ) {
2022-07-06 11:44:07 +08:00
List < SearchConditionItem > items = getExtService ( user ) . getExtForm ( user , EXTEND_TYPE + " " , GROUP_ID . equals ( Long . parseLong ( groupId ) ) ? JCL_ORG_JOB : JCL_ORG_JOBEXT , viewAttr , id , extendTitle . getId ( ) . toString ( ) , " scheme_id " , " parent_comp " ) ;
2022-06-23 09:14:19 +08:00
if ( CollectionUtils . isNotEmpty ( items ) ) {
addGroups . add ( new SearchConditionGroup ( extendTitle . getTitle ( ) , true , items ) ) ;
}
2022-06-13 17:22:34 +08:00
}
2022-05-30 18:39:03 +08:00
}
HashMap < String , Object > resultMap = new HashMap < > ( ) ;
resultMap . put ( " buttons " , buttonsMap ) ;
resultMap . put ( " conditions " , addGroups ) ;
resultMap . put ( " id " , id ) ;
// 拓展页面分组
resultMap . put ( " tabInfo " , getExtService ( user ) . getTabInfo ( EXTEND_TYPE , JCL_ORG_JOBEXT ) ) ;
// 处理明细表
2022-06-23 09:14:19 +08:00
List < Map < String , Object > > extendTables = getExtService ( user ) . getExtendTables ( user , EXTEND_TYPE , Long . parseLong ( groupId ) , JCL_ORG_JOBEXT_DT1 , id , viewAttr , false ) ;
2022-05-31 21:39:20 +08:00
resultMap . put ( " tables " , extendTables ) ;
2022-05-30 18:39:03 +08:00
Map < String , Object > apiDatas = new HashMap < > ( ) ;
apiDatas . put ( " result " , resultMap ) ;
2022-08-22 13:35:21 +08:00
// 返回职等信息
JobPO jobById = getJobMapper ( ) . getJobById ( id ) ;
2022-08-23 17:43:09 +08:00
if ( null ! = jobById & & StringUtils . isNotBlank ( jobById . getGradeId ( ) ) ) {
2022-08-22 18:56:27 +08:00
GradePO gradeByID = MapperProxyFactory . getProxy ( GradeMapper . class ) . getGradeByID ( Long . parseLong ( jobById . getGradeId ( ) ) ) ;
2022-08-22 13:35:21 +08:00
if ( null ! = gradeByID ) {
apiDatas . put ( " levelIds " , gradeByID . getLevelId ( ) ) ;
}
}
2022-05-30 18:39:03 +08:00
return apiDatas ;
}
@Override
2022-06-23 16:55:26 +08:00
public Long saveBaseForm ( Map < String , Object > params ) {
2022-06-07 12:02:36 +08:00
HasRightUtil . hasRight ( user , RIGHT_NAME , false ) ;
2022-09-23 15:53:37 +08:00
JobSearchParam searchParam = JSONObject . parseObject ( JSONObject . toJSONString ( params ) , JobSearchParam . class ) ;
assertNameRepeat ( null , searchParam . getEcDepartment ( ) , searchParam . getParentJob ( ) , searchParam . getJobName ( ) ) ;
2022-06-23 13:43:52 +08:00
String jobNo = ( String ) params . get ( " job_no " ) ;
// 判断是否开启自动编号
jobNo = repeatDetermine ( jobNo ) ;
params . put ( " job_no " , jobNo ) ;
2022-06-23 16:55:26 +08:00
params . put ( " is_key " , null = = searchParam . getIsKey ( ) ? 0 : searchParam . getIsKey ( ) ) ;
2022-07-13 17:19:45 +08:00
Long ecDepartment = searchParam . getEcDepartment ( ) ;
2022-09-09 10:25:57 +08:00
DepartmentPO jclDepartment = EcHrmRelationUtil . getJclDepartmentId ( Util . null2String ( ecDepartment ) ) ;
2022-07-13 17:19:45 +08:00
params . put ( " parent_dept " , jclDepartment . getId ( ) ) ;
params . put ( " parent_comp " , jclDepartment . getParentComp ( ) ) ;
if ( null ! = jclDepartment . getParentComp ( ) ) {
2022-09-09 10:25:57 +08:00
params . put ( " ec_company " , EcHrmRelationUtil . getEcCompanyId ( Util . null2String ( jclDepartment . getParentComp ( ) ) ) ) ;
2022-07-13 17:19:45 +08:00
}
2022-06-23 16:55:26 +08:00
if ( StringUtils . isBlank ( params . get ( " show_order " ) . toString ( ) ) ) {
2022-07-22 16:02:32 +08:00
Integer maxShowOrder = getJobMapper ( ) . getMaxShowOrder ( ) ;
if ( null = = maxShowOrder ) {
maxShowOrder = 0 ;
}
2022-06-23 16:55:26 +08:00
params . put ( " show_order " , maxShowOrder + 1 ) ;
}
2022-07-15 09:02:18 +08:00
params . put ( " jobactivityid " , JOB_ACTIVITY_ID ) ;
2022-08-26 15:36:06 +08:00
new OrganizationSyncEc ( user , LogModuleNameEnum . JOB , OperateTypeEnum . ADD , params ) . sync ( ) ;
return getExtService ( user ) . updateExtForm ( user , EXTEND_TYPE , JCL_ORG_JOB , params , " " , null ) ;
2022-05-30 18:39:03 +08:00
}
@Override
2022-06-23 16:55:26 +08:00
public Long updateForm ( Map < String , Object > params ) {
2022-06-07 12:02:36 +08:00
HasRightUtil . hasRight ( user , RIGHT_NAME , false ) ;
2022-05-30 18:39:03 +08:00
JobSearchParam searchParam = JSONObject . parseObject ( JSONObject . toJSONString ( params ) , JobSearchParam . class ) ;
2022-09-23 15:53:37 +08:00
assertNameRepeat ( searchParam . getId ( ) , searchParam . getEcDepartment ( ) , searchParam . getParentJob ( ) , searchParam . getJobName ( ) ) ;
2022-05-30 18:39:03 +08:00
String groupId = ( String ) params . get ( " viewCondition " ) ;
2022-06-13 17:22:34 +08:00
searchParam . setIsKey ( null = = searchParam . getIsKey ( ) ? 0 : searchParam . getIsKey ( ) ) ;
2022-09-23 15:53:37 +08:00
// 上级岗位不能选择本身
String parent_job = Util . null2String ( params . get ( " parent_job " ) ) ;
if ( StringUtils . isNotBlank ( parent_job ) ) {
OrganizationAssert . isFalse ( parent_job . equals ( searchParam . getId ( ) . toString ( ) ) , " 上级岗位不能选择本身 " ) ;
}
2022-06-13 17:22:34 +08:00
if ( " 0 " . equals ( groupId ) ) {
groupId = GROUP_ID . toString ( ) ;
}
2022-07-15 09:02:18 +08:00
JobPO oldJobPO = getJobMapper ( ) . getJobById ( searchParam . getId ( ) ) ;
String oldJobNo = oldJobPO . getJobNo ( ) ;
2022-06-23 13:43:52 +08:00
String jobNo = searchParam . getJobNo ( ) ;
2022-08-12 14:09:10 +08:00
if ( ! jobNo . equals ( oldJobNo ) ) {
2022-06-23 13:43:52 +08:00
jobNo = repeatDetermine ( jobNo ) ;
params . put ( " job_no " , jobNo ) ;
}
2022-05-30 18:39:03 +08:00
// 更新主表数据
2022-06-13 17:22:34 +08:00
params . put ( " is_key " , searchParam . getIsKey ( ) ) ;
2022-07-13 17:19:45 +08:00
Long ecDepartment = searchParam . getEcDepartment ( ) ;
2022-09-09 10:25:57 +08:00
DepartmentPO jclDepartment = EcHrmRelationUtil . getJclDepartmentId ( Util . null2String ( ecDepartment ) ) ;
2022-07-13 17:19:45 +08:00
params . put ( " parent_dept " , jclDepartment . getId ( ) ) ;
params . put ( " parent_comp " , jclDepartment . getParentComp ( ) ) ;
if ( null ! = jclDepartment . getParentComp ( ) ) {
2022-09-09 10:25:57 +08:00
params . put ( " ec_company " , EcHrmRelationUtil . getEcCompanyId ( Util . null2String ( jclDepartment . getParentComp ( ) ) ) ) ;
2022-07-13 17:19:45 +08:00
}
2022-07-15 09:02:18 +08:00
params . put ( " jobactivityid " , JOB_ACTIVITY_ID ) ;
2022-08-26 15:36:06 +08:00
new OrganizationSyncEc ( user , LogModuleNameEnum . JOB , OperateTypeEnum . UPDATE , params , oldJobPO ) . sync ( ) ;
2022-06-23 16:55:26 +08:00
getExtService ( user ) . updateExtForm ( user , EXTEND_TYPE , JCL_ORG_JOB , params , " " , searchParam . getId ( ) ) ;
2022-05-30 18:39:03 +08:00
// 更新主表拓展表
2022-06-23 16:55:26 +08:00
getExtService ( user ) . updateExtForm ( user , EXTEND_TYPE , JCL_ORG_JOBEXT , params , groupId , searchParam . getId ( ) ) ;
2022-05-31 21:39:20 +08:00
// 更新明细表
2022-06-13 17:22:34 +08:00
getExtService ( user ) . updateExtDT ( user , EXTEND_TYPE , JCL_ORG_JOBEXT_DT1 , params , searchParam . getId ( ) ) ;
2022-06-23 16:55:26 +08:00
return searchParam . getId ( ) ;
2022-05-30 18:39:03 +08:00
}
2022-05-31 21:39:20 +08:00
@Override
2022-06-01 18:20:44 +08:00
public int copyJobItem ( String ids , String department ) {
2022-06-07 12:02:36 +08:00
HasRightUtil . hasRight ( user , RIGHT_NAME , false ) ;
2022-06-01 18:20:44 +08:00
OrganizationAssert . notBlank ( department , " 请指定需要复制的部门 " ) ;
int insertCount = 0 ;
List < Long > idList = Arrays . stream ( ids . split ( " , " ) ) . map ( Long : : parseLong ) . collect ( Collectors . toList ( ) ) ;
2022-08-29 15:39:35 +08:00
Integer orderNum = getJobMapper ( ) . getMaxShowOrder ( ) ;
orderNum = null = = orderNum ? 0 : orderNum ;
2022-06-01 18:20:44 +08:00
for ( Long id : idList ) {
2022-06-24 14:40:49 +08:00
orderNum + + ;
2022-06-01 18:20:44 +08:00
JobPO jobById = getJobMapper ( ) . getJobById ( id ) ;
2022-06-06 17:48:11 +08:00
// 处理自动编号
2022-09-05 18:33:20 +08:00
jobById . setJobNo ( CodeRuleUtil . generateCode ( RuleCodeType . JOBTITLES , jobById . getJobNo ( ) , System . currentTimeMillis ( ) ) ) ;
2022-09-07 15:40:19 +08:00
// 部门赋值
jobById . setEcDepartment ( Long . parseLong ( department ) ) ;
DepartmentPO jclDepartmentId = EcHrmRelationUtil . getJclDepartmentId ( department ) ;
if ( null ! = jclDepartmentId ) {
jobById . setParentDept ( jclDepartmentId . getId ( ) ) ;
2022-09-08 17:54:46 +08:00
//分部赋值
jobById . setEcCompany ( jclDepartmentId . getEcCompany ( ) ) ;
jobById . setParentComp ( jclDepartmentId . getParentComp ( ) ) ;
2022-09-07 15:40:19 +08:00
}
2022-09-08 17:54:46 +08:00
// 清空上级岗位
jobById . setParentJob ( null ) ;
2022-06-24 14:40:49 +08:00
jobById . setShowOrder ( orderNum ) ;
2022-09-23 15:53:37 +08:00
assertNameRepeat ( null , jobById . getEcDepartment ( ) , jobById . getParentJob ( ) , jobById . getJobName ( ) ) ;
2022-06-01 18:20:44 +08:00
insertCount + = getJobMapper ( ) . insertIgnoreNull ( jobById ) ;
2022-08-31 14:24:00 +08:00
// 更新组织架构图
new Thread ( new JobTriggerRunnable ( jobById . getId ( ) ) ) . start ( ) ;
2022-06-01 18:20:44 +08:00
}
return insertCount ;
2022-05-31 21:39:20 +08:00
}
2022-05-30 18:39:03 +08:00
@Override
public int updateForbiddenTagById ( JobSearchParam params ) {
2022-06-07 12:02:36 +08:00
HasRightUtil . hasRight ( user , RIGHT_NAME , false ) ;
2022-10-14 14:56:35 +08:00
JobPO jobById = getJobMapper ( ) . getJobById ( params . getId ( ) ) ;
JobPO jobPO = JobPO . builder ( ) . id ( params . getId ( ) ) . forbiddenTag ( params . getForbiddenTag ( ) ? 0 : 1 ) . jobName ( jobById . getJobName ( ) ) . build ( ) ;
if ( params . getForbiddenTag ( ) ) {
// 启用:判断上级部门是否启用,上级部门启用,岗位才可启用
DepartmentPO parentDepartment = getDepartmentMapper ( ) . getDeptById ( jobById . getParentDept ( ) ) ;
OrganizationAssert . isTrue ( 0 = = parentDepartment . getForbiddenTag ( ) , " 该岗位不能解封,请先解封上级部门 " ) ;
// 启用:判断上级岗位是否启用,上级岗位启用,岗位才可启用
if ( null ! = jobById . getParentJob ( ) ) {
JobPO parentJob = getJobMapper ( ) . getJobById ( jobById . getParentJob ( ) ) ;
OrganizationAssert . isTrue ( 0 = = parentJob . getForbiddenTag ( ) , " 该岗位不能解封,请先解封上级岗位 " ) ;
}
} else {
//禁用:判断当前岗位下是否有人员,如有人员则不能禁用
int hasResource = getJobMapper ( ) . isHasResource ( params . getId ( ) ) ;
OrganizationAssert . isTrue ( hasResource = = 0 , " 该岗位存在人员,不能封存 " ) ;
}
2022-08-26 15:36:06 +08:00
new OrganizationSyncEc ( user , LogModuleNameEnum . JOB , OperateTypeEnum . CANCELED , null , jobPO ) . sync ( ) ;
2022-05-30 18:39:03 +08:00
return getJobMapper ( ) . updateForbiddenTagById ( jobPO . getId ( ) , jobPO . getForbiddenTag ( ) ) ;
}
@Override
public int deleteByIds ( Collection < Long > ids ) {
2022-06-07 12:02:36 +08:00
HasRightUtil . hasRight ( user , RIGHT_NAME , false ) ;
2022-05-30 18:39:03 +08:00
OrganizationAssert . notEmpty ( ids , " 请选择要删除的数据 " ) ;
2022-07-15 09:02:18 +08:00
List < JobPO > jobsByIds = getJobMapper ( ) . getJobsByIds ( ids ) ;
for ( JobPO jobsById : jobsByIds ) {
2022-08-26 15:36:06 +08:00
jobsById . setForbiddenTag ( 1 ) ;
new OrganizationSyncEc ( user , LogModuleNameEnum . JOB , OperateTypeEnum . CANCELED , null , jobsById ) . sync ( ) ;
2022-08-22 09:10:00 +08:00
// 删除拓展表、明细表
MapperProxyFactory . getProxy ( ExtMapper . class ) . deleteByID ( " jcl_org_jobext " , jobsById . getId ( ) ) ;
MapperProxyFactory . getProxy ( ExtDTMapper . class ) . deleteByMainID ( " jcl_org_jobext_dt1 " , jobsById . getId ( ) ) ;
2022-07-15 09:02:18 +08:00
}
2022-08-26 15:36:06 +08:00
return getJobMapper ( ) . deleteByIds ( ids ) ;
2022-05-30 18:39:03 +08:00
}
2022-06-01 14:38:39 +08:00
@Override
public Map < String , Object > getHrmListByJobId ( Long jobId ) {
OrganizationWeaTable < EmployeeTableVO > table = new OrganizationWeaTable < > ( user , EmployeeTableVO . class ) ;
2022-09-07 19:12:42 +08:00
RecordSet rs = new RecordSet ( ) ;
List < String > ids = new ArrayList < > ( ) ;
2022-09-23 15:53:37 +08:00
rs . executeQuery ( " select id from cus_fielddata where field100002 = ? " , jobId ) ;
2022-09-07 19:12:42 +08:00
while ( rs . next ( ) ) {
ids . add ( Util . null2String ( rs . getString ( " id " ) ) ) ;
}
2022-09-23 15:53:37 +08:00
if ( CollectionUtils . isEmpty ( ids ) ) {
2022-09-07 19:12:42 +08:00
ids . add ( " -1 " ) ;
}
2022-09-23 15:53:37 +08:00
table . setSqlwhere ( " where id in ( " + StringUtils . join ( ids , " , " ) + " ) and status<4 " ) ;
2022-06-01 14:38:39 +08:00
WeaResultMsg result = new WeaResultMsg ( false ) ;
result . putAll ( table . makeDataResult ( ) ) ;
result . success ( ) ;
return result . getResultMap ( ) ;
}
2022-06-24 18:26:15 +08:00
@Override
2022-09-15 10:41:04 +08:00
public List < SearchConditionGroup > getMergeForm ( Long id ) {
2022-06-24 18:26:15 +08:00
List < SearchConditionGroup > addGroups = new ArrayList < > ( ) ;
List < SearchConditionItem > condition = new ArrayList < > ( ) ;
2022-08-26 15:36:06 +08:00
SearchConditionItem deptBrowserItem = OrganizationFormItemUtil . browserItem ( user , 2 , 16 , 3 , false , " 合并到岗位 " , " 666 " , " targetJob " , " " ) ;
2022-06-24 18:26:15 +08:00
deptBrowserItem . setRules ( " required " ) ;
2022-09-15 18:31:11 +08:00
BrowserBean browserBean = deptBrowserItem . getBrowserConditionParam ( ) ;
String s = JSONObject . toJSONString ( browserBean ) ;
CustomBrowserBean customBrowserBean = JSONObject . parseObject ( s , CustomBrowserBean . class ) ;
customBrowserBean . setHasLeftTree ( true ) ;
customBrowserBean . setLeftToSearchKey ( " treeKey " ) ;
deptBrowserItem . setBrowserConditionParam ( customBrowserBean ) ;
2022-09-15 10:41:04 +08:00
SearchConditionItem mergeNameItem = OrganizationFormItemUtil . inputItem ( user , 2 , 16 , 3 , 50 , " 合并后名称 " , " mergeName " ) ;
mergeNameItem . setRules ( " required|string " ) ;
JobPO jobById = getJobMapper ( ) . getJobById ( id ) ;
if ( null ! = jobById ) {
String jobName = jobById . getJobName ( ) ;
mergeNameItem . setValue ( jobName ) ;
}
2022-06-24 18:26:15 +08:00
condition . add ( deptBrowserItem ) ;
2022-09-15 10:41:04 +08:00
condition . add ( mergeNameItem ) ;
2022-06-24 18:26:15 +08:00
addGroups . add ( new SearchConditionGroup ( " " , true , condition ) ) ;
return addGroups ;
}
@Override
public int mergeJob ( JobMergeParam mergeParam ) {
HasRightUtil . hasRight ( user , RIGHT_NAME , false ) ;
2022-09-15 10:41:04 +08:00
int updateCount = 0 ;
2022-09-07 19:12:47 +08:00
OrganizationAssert . notNull ( mergeParam . getTargetJob ( ) , " 请选择需要合并的岗位 " ) ;
2022-09-16 10:22:15 +08:00
OrganizationAssert . notBlank ( mergeParam . getMergeName ( ) , " 请输入合并后的名称 " ) ;
2022-09-15 10:41:04 +08:00
// 不可选择岗位本身、以及子岗位
2022-06-24 18:26:15 +08:00
Set < Long > disableIds = new HashSet < > ( ) ;
disableIds . add ( mergeParam . getId ( ) ) ;
2022-09-15 10:41:04 +08:00
// 第一层级的子元素
2022-06-24 18:26:15 +08:00
List < JobPO > jobs = getJobMapper ( ) . getJobsByPid ( mergeParam . getId ( ) ) ;
if ( CollectionUtils . isNotEmpty ( jobs ) ) {
addDisableIds ( disableIds , jobs ) ;
}
OrganizationAssert . isFalse ( disableIds . contains ( mergeParam . getTargetJob ( ) ) , " 请勿选择当前岗位本身及其子岗位 " ) ;
// 合并到的岗位
JobPO targetJob = getJobMapper ( ) . getJobById ( mergeParam . getTargetJob ( ) ) ;
2022-09-15 10:41:04 +08:00
// 待合并的部门
JobPO jobById = getJobMapper ( ) . getJobById ( mergeParam . getId ( ) ) ;
2022-09-23 15:53:37 +08:00
assertNameRepeat ( targetJob . getId ( ) , targetJob . getEcDepartment ( ) , targetJob . getParentJob ( ) , mergeParam . getMergeName ( ) ) ;
2022-09-15 10:41:04 +08:00
// 递归处理子岗位所属分部、所部部门、上级岗位
recursionMergeJob ( jobs , targetJob . getParentComp ( ) , targetJob . getEcCompany ( ) , targetJob . getParentDept ( ) , targetJob . getEcDepartment ( ) , targetJob . getId ( ) ) ;
// 人员信息变动,更新分部、部门、岗位
RecordSet rs = new RecordSet ( ) ;
2022-09-19 13:27:50 +08:00
rs . execute ( " SELECT ID FROM CUS_FIELDDATA WHERE SCOPE = 'HrmCustomFieldByInfoType' AND SCOPEID =-1 AND FIELD100002 = ' " + jobById . getId ( ) + " ' " ) ;
2022-09-15 10:41:04 +08:00
while ( rs . next ( ) ) {
long userId = Long . parseLong ( Util . null2String ( rs . getString ( " ID " ) ) ) ;
// 更新岗位 、岗位更新触发器
2022-09-19 13:27:50 +08:00
rs . executeUpdate ( " update CUS_FIELDDATA set FIELD100002 = ? where SCOPE = 'HrmCustomFieldByInfoType' AND SCOPEID =-1 and id = ? " , targetJob . getId ( ) , userId ) ;
2022-09-15 10:41:04 +08:00
CusFieldDataTrigger . run ( userId ) ;
// 更新人员组织架构图
}
// 更新合并后的岗位,更新组织架构图
2022-09-23 15:53:37 +08:00
updateEcJob ( targetJob , mergeParam . getMergeName ( ) ) ;
2022-09-15 10:41:04 +08:00
targetJob . setJobName ( mergeParam . getMergeName ( ) ) ;
getJobMapper ( ) . updateBaseJob ( targetJob ) ;
new Thread ( new JobTriggerRunnable ( targetJob . getId ( ) ) ) . start ( ) ;
// 原岗位删除
new OrganizationSyncEc ( user , LogModuleNameEnum . JOB , OperateTypeEnum . CANCELED , null , jobById ) . sync ( ) ;
2022-09-16 10:22:15 +08:00
getJobMapper ( ) . deleteByIds ( Collections . singletonList ( jobById . getId ( ) ) ) ;
2022-09-15 10:41:04 +08:00
// 更新组织架构图
new Thread ( new JobTriggerRunnable ( jobById ) ) . start ( ) ;
2022-06-24 18:26:15 +08:00
return updateCount ;
}
2022-09-15 10:41:04 +08:00
void recursionMergeJob ( List < JobPO > jobs , Long parentCompany , Long ecCompany , Long parentDepartment , Long ecDepartment , Long parentJob ) {
for ( JobPO job : jobs ) {
job . setParentComp ( parentCompany ) ;
job . setEcCompany ( ecCompany ) ;
job . setParentDept ( parentDepartment ) ;
job . setEcDepartment ( ecDepartment ) ;
job . setParentJob ( parentJob ) ;
2022-09-19 13:27:50 +08:00
getJobMapper ( ) . updateBaseJob ( job ) ;
2022-09-15 10:41:04 +08:00
// 更新人员信息
RecordSet rs = new RecordSet ( ) ;
2022-09-19 13:27:50 +08:00
rs . execute ( " SELECT ID FROM CUS_FIELDDATA WHERE SCOPE = 'HrmCustomFieldByInfoType' AND SCOPEID =-1 AND FIELD100002 = ' " + job . getId ( ) + " ' " ) ;
2022-09-15 10:41:04 +08:00
while ( rs . next ( ) ) {
long userId = Long . parseLong ( Util . null2String ( rs . getString ( " ID " ) ) ) ;
// 更新人员分部、部门
2022-09-19 13:27:50 +08:00
// rs.executeUpdate("UPDATE HRMRESOURCE SET SUBCOMPANYID1 = ? , DEPARTMENTID = ? WHERE ID =? ", ecCompany, ecDepartment, userId);
2022-09-15 10:41:04 +08:00
// 更新人员组织架构图
CusFieldDataTrigger . run ( userId ) ;
}
// 更新组织架构图
new Thread ( new JobTriggerRunnable ( job . getId ( ) ) ) . start ( ) ;
// 递归处理子级元素
List < JobPO > jobsByPid = getJobMapper ( ) . getJobsByPid ( job . getId ( ) ) ;
recursionMergeJob ( jobsByPid , parentCompany , ecCompany , parentDepartment , ecDepartment , parentJob ) ;
}
}
2022-05-27 18:05:15 +08:00
/ * *
* 添加查询元素的父级元素
*
* @param departmentPO
* @param builderDeparts
* /
private void buildParentDepts ( DepartmentPO departmentPO , Set < DepartmentPO > builderDeparts ) {
builderDeparts . add ( departmentPO ) ;
2022-06-06 14:41:46 +08:00
if ( SearchTreeUtil . isTop ( departmentPO . getParentDept ( ) ) ) {
2022-05-27 18:05:15 +08:00
return ;
}
DepartmentPO parentDept = getDepartmentMapper ( ) . getDeptById ( departmentPO . getParentDept ( ) ) ;
2022-09-06 15:19:16 +08:00
if ( null ! = parentDept & & 0 = = parentDept . getForbiddenTag ( ) ) {
2022-05-31 13:50:00 +08:00
buildParentDepts ( parentDept , builderDeparts ) ;
}
2022-05-27 18:05:15 +08:00
}
/ * *
* 添加查询元素的父级元素
*
* @param compPO
* @param builderComps
* /
private void buildParentComps ( CompPO compPO , Set < CompPO > builderComps ) {
builderComps . add ( compPO ) ;
2022-06-06 14:41:46 +08:00
if ( SearchTreeUtil . isTop ( compPO . getParentCompany ( ) ) ) {
2022-05-27 18:05:15 +08:00
return ;
}
CompPO parentComp = getCompMapper ( ) . listById ( compPO . getParentCompany ( ) ) ;
2022-09-06 15:19:16 +08:00
if ( null ! = parentComp & & 0 = = parentComp . getForbiddenTag ( ) ) {
2022-05-31 13:50:00 +08:00
buildParentComps ( parentComp , builderComps ) ;
}
2022-05-27 18:05:15 +08:00
}
/ * *
2022-05-29 21:41:20 +08:00
* 根据keyword查询数据
2022-05-27 18:05:15 +08:00
*
* @param id
2022-05-29 21:41:20 +08:00
* @param type
* @param keyword
2022-05-27 18:05:15 +08:00
* @return
* /
2022-06-06 14:41:46 +08:00
private List < SearchTree > getFilterCompany ( String id , String type , String keyword ) {
List < SearchTree > searchTree = new ArrayList < > ( ) ;
2022-05-29 21:41:20 +08:00
// 通过分部、公司 组装数据
if ( StringUtil . isEmpty ( id ) | | TYPE_COMP . equals ( type ) ) {
Long parentCompId = StringUtil . isEmpty ( id ) ? null : Long . parseLong ( id ) ;
2022-09-06 15:19:16 +08:00
DepartmentPO departmentBuild = DepartmentPO . builder ( ) . deptName ( keyword ) . parentComp ( parentCompId ) . forbiddenTag ( 0 ) . build ( ) ;
CompPO compBuild = CompPO . builder ( ) . compName ( keyword ) . parentCompany ( parentCompId ) . forbiddenTag ( 0 ) . build ( ) ;
2022-06-06 14:41:46 +08:00
searchTree = buildTreeByCompAndDept ( departmentBuild , compBuild ) ;
2022-05-29 21:41:20 +08:00
} else if ( TYPE_DEPT . equals ( type ) ) {
//
2022-05-27 18:05:15 +08:00
// 查询部门信息
2022-09-06 15:19:16 +08:00
List < DepartmentPO > filterDeparts = getDepartmentMapper ( ) . listByFilter ( DepartmentPO . builder ( ) . deptName ( keyword ) . forbiddenTag ( 0 ) . parentDept ( Long . parseLong ( id ) ) . build ( ) , " show_order " ) ;
2022-05-27 18:05:15 +08:00
Set < DepartmentPO > builderDeparts = new HashSet < > ( ) ;
for ( DepartmentPO departmentPO : filterDeparts ) {
buildParentDepts ( departmentPO , builderDeparts ) ;
}
2022-06-06 14:41:46 +08:00
searchTree = SearchTreeUtil . builderTreeMode ( DepartmentBO . buildSetToSearchTree ( builderDeparts ) ) ;
2022-05-29 21:41:20 +08:00
}
2022-06-06 14:41:46 +08:00
return searchTree ;
2022-05-29 21:41:20 +08:00
}
2022-05-27 18:05:15 +08:00
2022-05-29 21:41:20 +08:00
/ * *
* 分部 、 部门 组装左侧树
*
* @param departmentBuild
* @param compBuild
2022-06-06 14:41:46 +08:00
* @return
2022-05-29 21:41:20 +08:00
* /
2022-06-06 14:41:46 +08:00
private List < SearchTree > buildTreeByCompAndDept ( DepartmentPO departmentBuild , CompPO compBuild ) {
2022-06-23 18:49:47 +08:00
List < DepartmentPO > filterDeparts = getDepartmentMapper ( ) . listByFilter ( departmentBuild , " show_order " ) ;
2022-05-29 21:41:20 +08:00
// 查询分部信息
2022-06-23 18:49:47 +08:00
List < CompPO > filterComps = getCompMapper ( ) . listByFilter ( compBuild , " show_order " ) ;
2022-05-29 21:41:20 +08:00
Set < DepartmentPO > builderDeparts = new HashSet < > ( ) ;
for ( DepartmentPO departmentPO : filterDeparts ) {
buildParentDepts ( departmentPO , builderDeparts ) ;
}
2022-06-06 14:41:46 +08:00
List < SearchTree > deptTrees = SearchTreeUtil . builderTreeMode ( DepartmentBO . buildSetToSearchTree ( builderDeparts ) ) ;
2022-05-29 21:41:20 +08:00
// 添加部门的上级分部
String parentCompS = deptTrees . stream ( ) . map ( SearchTree : : getParentComp ) . collect ( Collectors . joining ( " , " ) ) ;
if ( ! StringUtil . isEmpty ( parentCompS ) ) {
2022-06-01 14:38:39 +08:00
List < CompPO > compsByIds = getCompMapper ( ) . getCompsByIds ( DeleteParam . builder ( ) . ids ( parentCompS ) . build ( ) . getIds ( ) ) ;
2022-05-29 21:41:20 +08:00
if ( CollectionUtils . isNotEmpty ( compsByIds ) ) {
filterComps . addAll ( compsByIds ) ;
2022-05-27 18:05:15 +08:00
}
}
2022-05-29 21:41:20 +08:00
Set < CompPO > builderComps = new HashSet < > ( ) ;
for ( CompPO compPO : filterComps ) {
buildParentComps ( compPO , builderComps ) ;
}
2022-06-06 14:41:46 +08:00
return SearchTreeUtil . builderTreeMode ( CompBO . buildSetToSearchTree ( builderComps ) , deptTrees ) ;
2022-05-27 18:05:15 +08:00
}
2022-05-30 18:39:03 +08:00
/ * *
* 是否有搜索查询
*
* @param jobPO
* @return
* /
private boolean isFilter ( JobPO jobPO ) {
return ! ( StringUtil . isEmpty ( jobPO . getJobNo ( ) )
& & StringUtil . isEmpty ( jobPO . getJobName ( ) )
& & StringUtil . isEmpty ( jobPO . getWorkplace ( ) )
& & StringUtil . isEmpty ( jobPO . getDescription ( ) )
& & StringUtil . isEmpty ( jobPO . getWorkDuty ( ) )
& & StringUtil . isEmpty ( jobPO . getWorkAuthority ( ) )
& & null = = jobPO . getParentComp ( )
& & null = = jobPO . getParentDept ( )
2022-10-17 11:35:46 +08:00
& & null = = jobPO . getParentJob ( )
2022-05-30 18:39:03 +08:00
& & null = = jobPO . getSequenceId ( )
& & null = = jobPO . getSchemeId ( )
2022-07-27 16:47:19 +08:00
& & null = = jobPO . getIsKey ( )
& & null = = jobPO . getForbiddenTag ( )
& & null = = jobPO . getEcCompany ( )
& & null = = jobPO . getEcDepartment ( )
) ;
2022-05-30 18:39:03 +08:00
}
2022-06-23 13:43:52 +08:00
/ * *
* 判断编号是否重复
*
* @return
* /
2022-07-27 16:47:19 +08:00
public static String repeatDetermine ( String jobNo ) {
2022-06-23 13:43:52 +08:00
CodeRulePO codeRuleByType = MapperProxyFactory . getProxy ( CodeRuleMapper . class ) . getCodeRuleByType ( RuleCodeType . JOBTITLES . getValue ( ) ) ;
if ( StringUtils . isNotBlank ( jobNo ) ) {
jobNo = CodeRuleUtil . generateCode ( RuleCodeType . JOBTITLES , jobNo ) ;
List < JobPO > list = getJobMapper ( ) . listByNo ( Util . null2String ( jobNo ) ) ;
OrganizationAssert . isEmpty ( list , " 编号不允许重复 " ) ;
} else {
if ( null ! = codeRuleByType & & " 1 " . equals ( codeRuleByType . getSerialEnable ( ) ) ) {
jobNo = autoCreateCompanyNo ( ) ;
}
}
return jobNo ;
}
/ * *
* 自动编号处理
*
* @return
* /
2022-07-27 16:47:19 +08:00
private static String autoCreateCompanyNo ( ) {
2022-06-23 13:43:52 +08:00
String generateCode = CodeRuleUtil . generateCode ( RuleCodeType . JOBTITLES , " " ) ;
List < JobPO > list = getJobMapper ( ) . listByNo ( Util . null2String ( generateCode ) ) ;
if ( CollectionUtils . isNotEmpty ( list ) ) {
generateCode = autoCreateCompanyNo ( ) ;
}
return generateCode ;
}
2022-06-24 18:26:15 +08:00
/ * *
* 获取所有子部门id
*
* @param parentComp
* @param parentDept
* @param jobList
* /
void forbiddenChildTag ( Long parentComp , Long parentDept , Long parentJob , List < JobPO > jobList ) {
if ( CollectionUtils . isNotEmpty ( jobList ) ) {
for ( JobPO job : jobList ) {
job . setParentComp ( parentComp ) ;
job . setParentDept ( parentDept ) ;
job . setParentJob ( parentJob ) ;
job . setForbiddenTag ( 1 ) ;
2022-08-26 15:36:06 +08:00
new OrganizationSyncEc ( user , LogModuleNameEnum . JOB , OperateTypeEnum . CANCELED , null , job ) . sync ( ) ;
2022-06-24 18:26:15 +08:00
getJobMapper ( ) . updateBaseJob ( job ) ;
2022-08-31 14:24:00 +08:00
// 更新组织架构图
new Thread ( new JobTriggerRunnable ( job . getId ( ) ) ) . start ( ) ;
2022-06-24 18:26:15 +08:00
List < JobPO > childJobs = getJobMapper ( ) . getJobsByPid ( job . getId ( ) ) ;
forbiddenChildTag ( parentComp , parentDept , job . getId ( ) , childJobs ) ;
}
}
}
/ * *
* 添加子元素ID
*
* @param disableIds
* @param jobPOS
* /
private void addDisableIds ( Set < Long > disableIds , List < JobPO > jobPOS ) {
for ( JobPO jobPO : jobPOS ) {
disableIds . add ( jobPO . getId ( ) ) ;
List < JobPO > jobsByPid = getJobMapper ( ) . getJobsByPid ( jobPO . getId ( ) ) ;
addDisableIds ( disableIds , jobsByPid ) ;
}
}
2022-09-15 10:41:04 +08:00
/ * *
* 更新EC岗位
2022-09-23 15:53:37 +08:00
*
2022-09-15 10:41:04 +08:00
* @param jobPO
* /
2022-09-23 15:53:37 +08:00
private void updateEcJob ( JobPO jobPO , String newName ) {
2022-09-15 10:41:04 +08:00
Map < String , Object > params = new HashMap < > ( ) ;
params . put ( " job_name " , newName ) ;
params . put ( " jobactivityid " , JOB_ACTIVITY_ID ) ;
params . put ( " work_duty " , jobPO . getWorkDuty ( ) ) ;
params . put ( " work_authority " , jobPO . getWorkAuthority ( ) ) ;
params . put ( " description " , jobPO . getDescription ( ) ) ;
params . put ( " job_no " , jobPO . getJobNo ( ) ) ;
new OrganizationSyncEc ( user , LogModuleNameEnum . JOB , OperateTypeEnum . UPDATE , params , jobPO ) . sync ( ) ;
}
2022-09-23 15:53:37 +08:00
/ * *
* 判断相同层级下有无同名岗位
* /
public static void assertNameRepeat ( Long jobId , Long departmentId , Long parentJobId , String jobName ) {
assertNameRepeat ( jobId , departmentId , parentJobId , jobName , true ) ;
}
/ * *
* 判断相同层级下有无同名岗位
* /
public static boolean assertNameRepeat ( String jobId , String departmentId , String parentJobId , String jobName ) {
return assertNameRepeat ( StringUtils . isBlank ( jobId ) ? null : Long . parseLong ( jobId ) , StringUtils . isBlank ( departmentId ) ? null : Long . parseLong ( departmentId ) , StringUtils . isBlank ( parentJobId ) ? null : Long . parseLong ( parentJobId ) , jobName , false ) ;
}
/ * *
* 判断相同层级下有无同名岗位
*
* @param jobId
* @param departmentId
* @param parentJobId
* @param jobName
* @param throwException
* @return
* /
public static boolean assertNameRepeat ( Long jobId , Long departmentId , Long parentJobId , String jobName , boolean throwException ) {
int count = 0 ;
// 有上级岗位、判断相同层级下有无相同名称岗位
if ( null ! = jobId ) {
count = getJobMapper ( ) . countRepeatNameByPid ( jobName , jobId , parentJobId , departmentId ) ;
} else {
// 无上级岗位,判断当前部门下,有无同名岗位
count = getJobMapper ( ) . countRepeatNameByPid ( jobName , jobId , null , departmentId ) ;
}
if ( throwException ) {
OrganizationAssert . isTrue ( count = = 0 , " 岗位名称已存在 " ) ;
}
return count = = 0 ;
}
2022-05-27 18:05:15 +08:00
}