weaver-hrm-organization/src/com/engine/organization/service/impl/DepartmentServiceImpl.java

1074 lines
52 KiB
Java
Raw Normal View History

2022-05-20 15:00:03 +08:00
package com.engine.organization.service.impl;
2022-05-23 19:16:31 +08:00
import com.api.browser.bean.SearchConditionGroup;
import com.api.browser.bean.SearchConditionItem;
2022-05-27 18:05:15 +08:00
import com.api.browser.bean.SearchConditionOption;
2022-11-29 17:00:31 +08:00
import com.api.hrm.bean.HrmFieldBean;
import com.api.hrm.util.HrmFieldSearchConditionComInfo;
2022-05-23 17:46:37 +08:00
import com.cloudstore.eccom.pc.table.WeaTableColumn;
import com.cloudstore.eccom.result.WeaResultMsg;
2022-05-27 18:05:15 +08:00
import com.engine.common.util.ServiceUtil;
2022-05-20 15:00:03 +08:00
import com.engine.core.impl.Service;
2022-06-06 13:17:35 +08:00
import com.engine.hrm.entity.RuleCodeType;
import com.engine.hrm.service.impl.OrganizationServiceImpl;
2022-05-23 17:46:37 +08:00
import com.engine.organization.component.OrganizationWeaTable;
2022-12-07 11:49:06 +08:00
import com.engine.organization.entity.TopTab;
2022-06-23 09:14:19 +08:00
import com.engine.organization.entity.codesetting.po.CodeRulePO;
2022-11-30 16:06:40 +08:00
import com.engine.organization.entity.company.bo.CompBO;
import com.engine.organization.entity.company.po.CompPO;
2022-05-20 15:00:03 +08:00
import com.engine.organization.entity.department.bo.DepartmentBO;
2022-05-23 17:46:37 +08:00
import com.engine.organization.entity.department.dto.DepartmentListDTO;
2022-06-02 15:43:19 +08:00
import com.engine.organization.entity.department.param.*;
2022-05-20 15:00:03 +08:00
import com.engine.organization.entity.department.po.DepartmentPO;
import com.engine.organization.entity.department.vo.SingleDeptTreeVO;
2022-06-02 16:49:25 +08:00
import com.engine.organization.entity.job.bo.JobBO;
2022-06-02 11:40:24 +08:00
import com.engine.organization.entity.job.po.JobPO;
2022-06-02 16:49:25 +08:00
import com.engine.organization.entity.job.vo.SingleJobTreeVO;
2022-06-02 09:58:16 +08:00
import com.engine.organization.entity.searchtree.SearchTree;
import com.engine.organization.entity.searchtree.SearchTreeParams;
2022-07-13 10:55:44 +08:00
import com.engine.organization.enums.LogModuleNameEnum;
import com.engine.organization.enums.OperateTypeEnum;
2022-11-29 17:00:31 +08:00
import com.engine.organization.exception.OrganizationRunTimeException;
2022-06-23 09:14:19 +08:00
import com.engine.organization.mapper.codesetting.CodeRuleMapper;
2022-11-30 16:06:40 +08:00
import com.engine.organization.mapper.comp.CompMapper;
2022-05-20 15:00:03 +08:00
import com.engine.organization.mapper.department.DepartmentMapper;
2022-06-02 11:40:24 +08:00
import com.engine.organization.mapper.job.JobMapper;
2022-05-20 15:00:03 +08:00
import com.engine.organization.service.DepartmentService;
2022-08-26 15:36:06 +08:00
import com.engine.organization.thread.OrganizationSyncEc;
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-20 15:00:03 +08:00
import com.engine.organization.util.db.MapperProxyFactory;
2022-10-28 17:43:46 +08:00
import com.engine.organization.util.detach.DetachUtil;
2022-05-23 17:46:37 +08:00
import com.engine.organization.util.page.Column;
2022-05-20 15:00:03 +08:00
import com.engine.organization.util.page.PageInfo;
import com.engine.organization.util.page.PageUtil;
2022-06-06 14:41:46 +08:00
import com.engine.organization.util.tree.SearchTreeUtil;
2022-09-09 14:41:04 +08:00
import com.google.common.collect.Lists;
2022-06-02 09:58:16 +08:00
import org.apache.commons.collections4.CollectionUtils;
2022-06-23 09:14:19 +08:00
import org.apache.commons.lang.StringUtils;
2022-09-08 15:36:47 +08:00
import weaver.conn.RecordSet;
2022-05-23 17:46:37 +08:00
import weaver.general.StringUtil;
2022-05-27 18:05:15 +08:00
import weaver.general.Util;
2022-12-07 11:49:06 +08:00
import weaver.hrm.HrmUserVarify;
2022-11-29 17:00:31 +08:00
import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.definedfield.HrmDeptFieldManagerE9;
import weaver.hrm.definedfield.HrmFieldComInfo;
import weaver.hrm.definedfield.HrmFieldGroupComInfo;
2022-12-07 11:49:06 +08:00
import weaver.hrm.moduledetach.ManageDetachComInfo;
2022-11-29 17:00:31 +08:00
import weaver.systeminfo.SystemEnv;
2022-12-07 11:49:06 +08:00
import weaver.systeminfo.systemright.CheckSubCompanyRight;
2022-05-20 15:00:03 +08:00
2022-05-23 19:16:31 +08:00
import java.util.*;
import java.util.stream.Collectors;
2022-05-20 15:00:03 +08:00
/**
* @Author weaver_cl
2022-06-14 11:07:48 +08:00
* @description:
2022-05-20 15:00:03 +08:00
* @Date 2022/5/20
* @Version V1.0
**/
public class DepartmentServiceImpl extends Service implements DepartmentService {
2022-06-07 12:02:36 +08:00
private static final String RIGHT_NAME = "Department:All";
2022-07-27 10:48:43 +08:00
private static DepartmentMapper getDepartmentMapper() {
2022-05-23 19:16:31 +08:00
return MapperProxyFactory.getProxy(DepartmentMapper.class);
}
2022-05-20 15:00:03 +08:00
2022-08-30 10:46:42 +08:00
private static JobMapper getJobMapper() {
return MapperProxyFactory.getProxy(JobMapper.class);
}
2022-11-30 16:06:40 +08:00
private CompMapper getCompMapper() {
return MapperProxyFactory.getProxy(CompMapper.class);
2022-05-27 18:05:15 +08:00
}
2022-05-20 15:00:03 +08:00
@Override
public PageInfo<SingleDeptTreeVO> getDeptListByPid(QuerySingleDeptListParam param) {
//1.查询分部下所有部门
List<DepartmentPO> departmentPOS = MapperProxyFactory.getProxy(DepartmentMapper.class).listAll("showOrder");
2022-05-23 17:33:10 +08:00
PageInfo<DepartmentPO> pageInfo = new PageInfo<>(departmentPOS);
2022-06-02 09:58:16 +08:00
List<SingleDeptTreeVO> singleDeptTreeVOS = DepartmentBO.buildSingleDeptTreeVOS(departmentPOS, param.getParentComp());
2022-05-23 19:16:31 +08:00
PageInfo<SingleDeptTreeVO> pageInfos = new PageInfo<>(singleDeptTreeVOS, SingleDeptTreeVO.class);
2022-05-23 17:33:10 +08:00
pageInfos.setTotal(pageInfo.getTotal());
2022-05-20 15:00:03 +08:00
pageInfos.setPageNum(param.getCurrent());
pageInfos.setPageSize(param.getPageSize());
return pageInfos;
}
2022-05-23 17:46:37 +08:00
2022-06-02 16:49:25 +08:00
@Override
public PageInfo<SingleJobTreeVO> getJobListByPid(QuerySingleDeptListParam param) {
List<JobPO> jobPOS = MapperProxyFactory.getProxy(JobMapper.class).listAll();
PageInfo<JobPO> pageInfo = new PageInfo<>(jobPOS);
List<SingleJobTreeVO> singleDeptTreeVOS = JobBO.buildSingleJobTreeVOS(jobPOS, param.getParentDept());
PageInfo<SingleJobTreeVO> pageInfos = new PageInfo<>(singleDeptTreeVOS, SingleJobTreeVO.class);
pageInfos.setTotal(pageInfo.getTotal());
pageInfos.setPageNum(param.getCurrent());
pageInfos.setPageSize(param.getPageSize());
return pageInfos;
}
2022-06-02 09:58:16 +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, keyword);
return SearchTreeUtil.getSearchTree(type, treeList);
2022-06-02 09:58:16 +08:00
}
2022-05-23 17:46:37 +08:00
@Override
public Map<String, Object> listPage(DeptSearchParam 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-06-02 09:58:16 +08:00
DepartmentPO departmentPO = DepartmentBO.convertParamsToPO(param, user.getUID());
2022-05-27 18:05:15 +08:00
boolean filter = isFilter(departmentPO);
PageInfo<DepartmentListDTO> pageInfos;
2022-12-07 11:49:06 +08:00
String orderSql = PageInfoSortUtil.getSortSql(param.getSortParams(), " showorder ");
List<DepartmentPO> allList = getDepartmentMapper().listAll(orderSql);
2022-12-13 10:42:35 +08:00
new DetachUtil(user).filterDepartmentList(allList);
2022-05-27 18:05:15 +08:00
// 通过子级遍历父级元素
if (filter) {
// 根据条件获取元素
2022-06-23 18:49:47 +08:00
List<DepartmentPO> filterDeptPOs = getDepartmentMapper().listByFilter(departmentPO, orderSql);
2022-12-13 10:42:35 +08:00
new DetachUtil(user).filterDepartmentList(filterDeptPOs);
2022-05-27 18:05:15 +08:00
// 添加父级元素
2022-06-02 09:58:16 +08:00
List<DepartmentListDTO> compListDTOS = DepartmentBO.buildDeptDTOList(allList, filterDeptPOs);
2022-05-27 18:05:15 +08:00
List<DepartmentListDTO> subList = PageUtil.subList(param.getCurrent(), param.getPageSize(), compListDTOS);
pageInfos = new PageInfo<>(subList, DepartmentListDTO.class);
pageInfos.setTotal(compListDTOS.size());
} else {
// 组合list
2022-06-02 09:58:16 +08:00
List<DepartmentListDTO> compListDTOS = DepartmentBO.buildDeptDTOList(allList);
2022-05-27 18:05:15 +08:00
List<DepartmentListDTO> subList = PageUtil.subList(param.getCurrent(), param.getPageSize(), compListDTOS);
pageInfos = new PageInfo<>(subList, DepartmentListDTO.class);
pageInfos.setTotal(compListDTOS.size());
}
2022-05-24 15:15:49 +08:00
2022-05-23 17:46:37 +08:00
pageInfos.setPageNum(param.getCurrent());
pageInfos.setPageSize(param.getPageSize());
OrganizationWeaTable<DepartmentListDTO> table = new OrganizationWeaTable<>(user, DepartmentListDTO.class);
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;
}
2022-05-23 19:16:31 +08:00
@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-11-29 17:00:31 +08:00
Map<String, Object> syncMap = new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.ADD, params).sync();
String ecCompanyID = Util.null2String(syncMap.get("id"));
OrganizationAssert.isTrue(StringUtils.isNotBlank(ecCompanyID), syncMap.get("message").toString());
return Long.parseLong(ecCompanyID);
2022-05-27 18:05:15 +08:00
}
@Override
public int updateForbiddenTagById(DeptSearchParam params) {
2022-06-07 12:02:36 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
DepartmentPO departmentPO = DepartmentPO.builder().id(params.getId()).canceled(params.getCanceled() ? 0 : 1).build();
2022-07-13 10:55:44 +08:00
Map<String, Object> map = new HashMap<>();
2022-12-09 15:39:15 +08:00
map.put("id", Util.null2String(departmentPO.getId()));
map.put("forbiddenTag", Util.null2String(departmentPO.getCanceled()));
2022-08-26 15:36:06 +08:00
new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.CANCELED, map).sync();
return 1;
2022-05-27 18:05:15 +08:00
}
@Override
2022-06-23 16:55:26 +08:00
public Long updateForm(Map<String, Object> params) {
2022-11-29 17:00:31 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
2022-12-13 18:19:12 +08:00
Integer ecDepartmentId = Integer.parseInt(Util.null2String(params.get("id")));
2022-12-16 16:21:54 +08:00
String supDepId = Util.null2String(params.get("supdepid"));
if (StringUtils.isNotBlank(supDepId)) {
// 不可选择合并的数据,本身及子部门
Set<Integer> disableIds = new HashSet<>();
// 添加选择部门本身
disableIds.add(ecDepartmentId);
List<DepartmentPO> deptListByPId = getDepartmentMapper().getDeptListByPId(ecDepartmentId);
if (CollectionUtils.isNotEmpty(deptListByPId)) {
addDisableIds(disableIds, deptListByPId);
}
OrganizationAssert.isFalse(disableIds.contains(Integer.parseInt(supDepId)), "上级部门不能选择部门本身及其下级部门");
2022-12-13 18:19:12 +08:00
}
2022-11-29 17:00:31 +08:00
new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.UPDATE, params).sync();
2022-12-13 18:19:12 +08:00
return (long) ecDepartmentId;
2022-05-27 18:05:15 +08:00
}
@Override
public Map<String, Object> deleteByIds(Map<String, Object> params) {
2022-06-07 12:02:36 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
return ServiceUtil.getService(OrganizationServiceImpl.class, user).delDepartment(params, user);
2022-05-27 18:05:15 +08:00
}
@Override
public Map<String, Object> getSearchCondition(Map<String, Object> params) {
Map<String, Object> apiDatas = new HashMap<>();
List<SearchConditionGroup> addGroups = new ArrayList<>();
List<SearchConditionItem> conditionItems = new ArrayList<>();
// 编号
2022-11-29 17:00:31 +08:00
SearchConditionItem departmentCodeItem = OrganizationFormItemUtil.inputItem(user, 2, 16, 2, 50, "编号", "departmentCode");
2022-05-27 18:05:15 +08:00
// 名称
2022-11-29 17:00:31 +08:00
SearchConditionItem departmentNameItem = OrganizationFormItemUtil.inputItem(user, 2, 16, 2, 50, "名称", "departmentName");
2022-05-27 18:05:15 +08:00
// 所属分部
2022-11-29 17:00:31 +08:00
SearchConditionItem subCompanyId1Item = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "所属分部", "164", "subCompanyId1", "");
2022-05-27 18:05:15 +08:00
// 上级部门
2022-11-29 17:00:31 +08:00
SearchConditionItem supDepIdItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "上级部门", "4", "supDepId", "");
conditionItems.add(departmentCodeItem);
conditionItems.add(departmentNameItem);
conditionItems.add(subCompanyId1Item);
conditionItems.add(supDepIdItem);
2022-05-27 18:05:15 +08:00
addGroups.add(new SearchConditionGroup("高级搜索条件", true, conditionItems));
apiDatas.put("conditions", addGroups);
return apiDatas;
}
@Override
2022-09-14 17:14:12 +08:00
public Map<String, List<MenuBtn>> getHasRight() {
2022-12-08 11:24:48 +08:00
return MenuBtn.getDatasNoBtnColum();
2022-05-27 18:05:15 +08:00
}
@Override
public Map<String, Object> getDeptBaseForm(Map<String, Object> params) {
OrganizationAssert.notNull(params.get("viewAttr"), "请标识操作类型");
// 2编辑 1查看
int viewAttr = Integer.parseInt((String) params.get("viewAttr"));
2022-11-29 17:00:31 +08:00
2022-12-07 11:49:06 +08:00
List<SearchConditionGroup> groupList = new ArrayList<>();
List<SearchConditionItem> itemList;
2022-11-29 17:00:31 +08:00
String id = Util.null2String(params.get("id"));
2022-12-07 11:49:06 +08:00
if (2 == viewAttr) {
params.put("viewattr", viewAttr);
2022-12-16 18:29:12 +08:00
groupList = getDepartmentConditionGroups(true, params);
2022-12-07 11:49:06 +08:00
} else {
2022-11-29 17:00:31 +08:00
2022-12-07 11:49:06 +08:00
HrmFieldGroupComInfo HrmFieldGroupComInfo = new HrmFieldGroupComInfo();
HrmFieldComInfo HrmFieldComInfo = new HrmFieldComInfo();
HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
SearchConditionItem searchConditionItem;
HrmFieldBean hrmFieldBean;
HrmDeptFieldManagerE9 hfm;
try {
hfm = new HrmDeptFieldManagerE9(5);
} catch (Exception e) {
throw new RuntimeException(e);
}
hfm.getCustomData(Util.getIntValue(id));
List lsGroup = hfm.getLsGroup();
for (int tmp = 0; lsGroup != null && tmp < lsGroup.size(); tmp++) {
String groupId = (String) lsGroup.get(tmp);
List lsField = hfm.getLsField(groupId);
2022-12-15 16:13:21 +08:00
if (lsField.size() == 0) {
2022-12-07 11:49:06 +08:00
continue;
2022-12-15 16:13:21 +08:00
}
if (hfm.getGroupCount(lsField) == 0) {
continue;
}
if (!"1".equals(Util.null2String(HrmFieldGroupComInfo.getIsShow(groupId)))) {
2022-12-07 11:49:06 +08:00
continue;
2022-12-15 16:13:21 +08:00
}
2022-12-07 11:49:06 +08:00
String groupLabel = HrmFieldGroupComInfo.getLabel(groupId);
itemList = new ArrayList<>();
for (Object o : lsField) {
String fieldId = (String) o;
String isUse = HrmFieldComInfo.getIsused(fieldId);
2022-12-15 16:13:21 +08:00
if (!"1".equals(isUse)) {
continue;
}
2022-12-07 11:49:06 +08:00
String fieldName = HrmFieldComInfo.getFieldname(fieldId);
String fieldLabel = HrmFieldComInfo.getLabel(fieldId);
String fieldHtmlType = HrmFieldComInfo.getFieldhtmltype(fieldId);
String type = HrmFieldComInfo.getFieldType(fieldId);
String dmlUrl = Util.null2String(HrmFieldComInfo.getFieldDmlurl(fieldId));
String isSystem = HrmFieldComInfo.getIssystem(fieldId);
String fieldValue;
if ("1".equals(isSystem)) {
2022-11-29 17:00:31 +08:00
fieldValue = hfm.getData(fieldName);
} else {
fieldValue = hfm.getData("hrmdepartmentdefined", fieldName);
}
2022-12-07 11:49:06 +08:00
if (id.length() > 0 && "showid".equals(fieldName)) {
fieldValue = id;
2022-11-29 17:00:31 +08:00
}
2022-12-07 11:49:06 +08:00
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldid(fieldId);
hrmFieldBean.setFieldname(fieldName);
hrmFieldBean.setFieldlabel(fieldLabel);
hrmFieldBean.setFieldhtmltype(fieldHtmlType);
hrmFieldBean.setType(type);
hrmFieldBean.setIsFormField(true);
hrmFieldBean.setFieldvalue(fieldValue);
hrmFieldBean.setDmlurl(dmlUrl);
hrmFieldBean.setIssystem("1");
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
if (searchConditionItem.getBrowserConditionParam() != null) {
searchConditionItem.getBrowserConditionParam().setViewAttr(viewAttr);
}
if ("showorder".equals(fieldName)) {
searchConditionItem.setPrecision(2);
}
2022-11-29 17:00:31 +08:00
2022-12-07 11:49:06 +08:00
if ("6".equals(fieldHtmlType)) {//附件
Map<String, Object> otherParams1 = new HashMap<>();
otherParams1.put("showOrder", false);
searchConditionItem.setOtherParams(otherParams1);
}
2022-11-29 17:00:31 +08:00
2022-12-07 11:49:06 +08:00
searchConditionItem.setViewAttr(viewAttr);
2022-12-13 18:19:12 +08:00
itemList.add(searchConditionItem);
2022-11-29 17:00:31 +08:00
}
2022-12-07 11:49:06 +08:00
int operateLevel;
ManageDetachComInfo manageDetachComInfo = new ManageDetachComInfo();
boolean hrmDetachAble = manageDetachComInfo.isUseHrmManageDetach();
if (hrmDetachAble) {
CheckSubCompanyRight checkSubCompanyRight = new CheckSubCompanyRight();
DepartmentComInfo departmentComInfo = new DepartmentComInfo();
operateLevel = checkSubCompanyRight.ChkComRightByUserRightCompanyId(user.getUID(), "HrmDepartmentEdit:Edit", Integer.parseInt(departmentComInfo.getSubcompanyid1(id)));
} else {
operateLevel = 2;
2022-11-29 17:00:31 +08:00
}
2022-12-07 11:49:06 +08:00
if (tmp == 0 && HrmUserVarify.checkUserRight("HrmDepartmentEdit:Edit", user) && operateLevel > 0) {
int resourceNum = 0;
RecordSet rs = new RecordSet();
String sql = "SELECT COUNT(*) FROM hrmresource WHERE departmentid = " + id + " and ( status =0 or status = 1 or status = 2 or status = 3)";
rs.execute(sql);
if (rs.next()) {
resourceNum = rs.getInt(1);
2022-11-29 17:00:31 +08:00
}
2022-12-07 11:49:06 +08:00
//4:解聘 5:离职 6:退休 7:无效
int resourceNum1 = 0;
sql = "SELECT COUNT(*) FROM hrmresource WHERE departmentid = " + id + " and status in(4,5,6,7)";
rs.execute(sql);
if (rs.next()) {
resourceNum1 = rs.getInt(1);
2022-11-29 17:00:31 +08:00
}
2022-12-07 11:49:06 +08:00
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldname("deptResourceInfo");
hrmFieldBean.setFieldlabel("382428");
hrmFieldBean.setFieldhtmltype("1");
hrmFieldBean.setType("1");
hrmFieldBean.setIsFormField(true);
hrmFieldBean.setFieldvalue(resourceNum + "/" + resourceNum1);
hrmFieldBean.setDmlurl("");
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
searchConditionItem.setViewAttr(viewAttr);
2022-11-29 17:00:31 +08:00
itemList.add(searchConditionItem);
}
2022-12-07 11:49:06 +08:00
groupList.add(new SearchConditionGroup(SystemEnv.getHtmlLabelNames(groupLabel, user.getLanguage()), true, itemList));
2022-12-13 18:19:12 +08:00
2022-11-29 17:00:31 +08:00
}
}
2022-12-07 11:49:06 +08:00
HashMap<String, Object> buttonsMap = new HashMap<>();
buttonsMap.put("hasEdit", true);
buttonsMap.put("hasSave", true);
HashMap<String, Object> resultMap = new HashMap<>();
resultMap.put("buttons", buttonsMap);
resultMap.put("conditions", groupList);
resultMap.put("id", id);
List<TopTab> topTabs = new ArrayList<>();
topTabs.add(TopTab.builder().color("#000000").groupId("4").showcount(false).title("部门信息").viewCondition("4").build());
resultMap.put("tabInfo", topTabs);
Map<String, Object> apiDatas = new HashMap<>();
apiDatas.put("result", resultMap);
return apiDatas;
}
@Override
public Map<String, Object> getSaveForm(Map<String, Object> params) {
HasRightUtil.hasRight(user, RIGHT_NAME, false);
Map<String, Object> apiDatas = new HashMap<>();
2022-12-16 18:29:12 +08:00
apiDatas.put("condition", getDepartmentConditionGroups(false, params));
2022-05-23 19:16:31 +08:00
return apiDatas;
}
2022-06-02 10:53:43 +08:00
/**
* 复制表单
*
* @return
*/
@Override
public List<SearchConditionGroup> getCopyForm() {
List<SearchConditionGroup> addGroups = new ArrayList<>();
List<SearchConditionItem> condition = new ArrayList<>();
2022-09-05 17:25:11 +08:00
SearchConditionItem compBrowserItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 3, false, "复制到", "164", "company", "");
2022-06-02 11:40:24 +08:00
compBrowserItem.setRules("required|string");
2022-09-15 10:41:04 +08:00
SearchConditionItem copySubDeptItem = OrganizationFormItemUtil.selectItem(user, Lists.newArrayList(new SearchConditionOption("1", "")), 2, 5, 10, false, "复制子部门信息", "copySubDept");
2022-09-09 14:41:04 +08:00
copySubDeptItem.setDetailtype(2);
2022-06-02 11:40:24 +08:00
condition.add(compBrowserItem);
2022-09-09 14:41:04 +08:00
condition.add(copySubDeptItem);
2022-06-02 10:53:43 +08:00
addGroups.add(new SearchConditionGroup("", true, condition));
return addGroups;
}
2022-06-02 11:40:24 +08:00
/**
* 复制岗位到指定部门
*
* @param copyParam
* @return
*/
@Override
public int copyDepartment(DeptCopyParam copyParam) {
2022-09-09 14:41:04 +08:00
// 批量复制,后续优化
2022-06-07 12:02:36 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
2022-06-02 11:40:24 +08:00
OrganizationAssert.notBlank(copyParam.getCompany(), "请指定需要复制的公司/分部");
int insertCount = 0;
2022-09-09 14:41:04 +08:00
// 需复制的部门
List<Integer> idList = Arrays.stream(copyParam.getIds().split(",")).map(Integer::parseInt).collect(Collectors.toList());
Double maxShowOrder = getDepartmentMapper().getMaxShowOrder();
2022-08-29 15:39:35 +08:00
maxShowOrder = null == maxShowOrder ? 0 : maxShowOrder;
for (Integer departmentId : idList) {
2022-09-09 14:41:04 +08:00
// 复制当前部门
recursionCopyDept(departmentId, null, Integer.parseInt(copyParam.getCompany()), maxShowOrder, copyParam.getCopyJob(), copyParam.getCopySubDept(), copyParam.getCopySubJob());
2022-06-02 11:40:24 +08:00
}
return insertCount;
}
private void recursionCopyDept(Integer originalDeptId, Integer parentDepartmentId, Integer companyId, Double maxShowOrder, String copyJob, String copySubDept, String copySubJob) {
2022-09-09 14:41:04 +08:00
// 源部门
DepartmentPO deptById = getDepartmentMapper().getDeptById(originalDeptId);
long timeMillis = System.currentTimeMillis();
// 处理自动编号
deptById.setDepartmentCode(null);
2022-09-09 14:41:04 +08:00
// 设置上级分部
deptById.setSubCompanyId1(companyId);
deptById.setSupDepId(parentDepartmentId);
2022-09-09 14:41:04 +08:00
// 显示顺序字段
deptById.setShowOrder(++maxShowOrder);
2022-11-30 15:55:27 +08:00
deptById.setUuid(null);
2022-09-09 14:41:04 +08:00
// 新增EC表部门
Map<String, Object> syncMap = addEcDepartment(deptById);
String ecDepartmentID = Util.null2String(syncMap.get("id"));
OrganizationAssert.isTrue(StringUtils.isNotBlank(ecDepartmentID), syncMap.get("message").toString());
// 更新组织架构图
2023-07-03 10:50:07 +08:00
// new DepartmentTriggerRunnable(deptById.getId()).run();
2022-09-09 14:41:04 +08:00
// 复制当前部门岗位信息
2022-12-08 14:37:48 +08:00
//if ("1".equals(copyJob)) {
// List<JobPO> jobPOS = MapperProxyFactory.getProxy(JobMapper.class).listJobsByDepartmentId(originalDeptId);
// jobPOS = jobPOS.stream().filter(item -> null == item.getParentJob() || 0 == item.getParentJob()).collect(Collectors.toList());
// Integer maxJobOrder = MapperProxyFactory.getProxy(JobMapper.class).getMaxShowOrder();
// if (maxJobOrder == null) {
// maxJobOrder = 0;
// }
// recursionCopyJob(jobPOS, companyId, Integer.parseInt(ecDepartmentID), null, maxJobOrder, timeMillis);
//}
2022-09-09 14:41:04 +08:00
// 是否复制子部门信息
if ("1".equals(copySubDept)) {
// 查询当前部门的子部门
List<DepartmentPO> deptListByPId = getDepartmentMapper().getDeptListByPId(originalDeptId);
for (DepartmentPO departmentPO : deptListByPId) {
// 复制子部门信息、子部门岗位信息
2022-11-30 15:55:27 +08:00
recursionCopyDept(departmentPO.getId(), Integer.parseInt(ecDepartmentID), companyId, maxShowOrder, copySubJob, copySubDept, copySubJob);
2022-09-09 14:41:04 +08:00
}
}
}
2022-06-02 15:43:19 +08:00
@Override
2022-11-29 17:00:31 +08:00
public List<SearchConditionGroup> getMergeForm() {
2022-06-02 15:43:19 +08:00
List<SearchConditionGroup> addGroups = new ArrayList<>();
List<SearchConditionItem> condition = new ArrayList<>();
2022-09-05 17:25:11 +08:00
SearchConditionItem deptBrowserItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 3, false, "合并到部门", "4", "department", "");
2022-06-02 15:43:19 +08:00
deptBrowserItem.setRules("required|string");
SearchConditionItem mergeNameItem = OrganizationFormItemUtil.inputItem(user, 2, 16, 3, 50, "合并后名称", "mergeName");
mergeNameItem.setRules("required|string");
condition.add(deptBrowserItem);
condition.add(mergeNameItem);
addGroups.add(new SearchConditionGroup("", true, condition));
return addGroups;
}
@Override
public int mergeDepartment(DepartmentMergeParam mergeParam) {
2022-06-07 12:02:36 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
2022-09-08 15:36:47 +08:00
// 被合并部门
Integer ecParamDepartment = mergeParam.getDepartment();
DepartmentPO targetDepartment = getDepartmentMapper().getDeptById(ecParamDepartment);
2022-11-30 15:55:27 +08:00
2022-10-19 15:38:47 +08:00
2022-09-08 15:36:47 +08:00
// 断言判断
OrganizationAssert.isFalse(null == targetDepartment, "被合并部门数据有误,暂时无法合并");
OrganizationAssert.isFalse(mergeParam.getId().equals(targetDepartment.getId()), "所选部门与待合并部门一致,无需操作");
2022-06-06 16:19:35 +08:00
OrganizationAssert.notNull(mergeParam.getDepartment(), "请选择需要合并的部门");
OrganizationAssert.notBlank(mergeParam.getMergeName(), "请输入合并后的名称");
2022-06-24 18:26:15 +08:00
2022-09-08 15:36:47 +08:00
// 不可选择合并的数据,本身及子部门
Set<Integer> disableIds = new HashSet<>();
2022-09-08 15:36:47 +08:00
// 添加选择部门本身
2022-08-22 15:04:38 +08:00
disableIds.add(mergeParam.getId());
List<DepartmentPO> deptListByPId = getDepartmentMapper().getDeptListByPId(mergeParam.getId());
if (CollectionUtils.isNotEmpty(deptListByPId)) {
addDisableIds(disableIds, deptListByPId);
}
OrganizationAssert.isFalse(disableIds.contains(targetDepartment.getId()), "请勿选择当前部门本身及其子部门");
2022-09-08 15:36:47 +08:00
// 查询该部门下一级部门
List<DepartmentPO> firstChildDeptList = getDepartmentMapper().getDeptListByPId(mergeParam.getId());
// 更新所属部门、所属分部
for (DepartmentPO departmentPO : firstChildDeptList) {
departmentPO.setSupDepId(targetDepartment.getId());
departmentPO.setSubCompanyId1(targetDepartment.getSubCompanyId1());
2022-09-08 15:36:47 +08:00
updateEcDepartment(departmentPO);
// 更新组织架构图
2023-07-03 10:50:07 +08:00
// new DepartmentTriggerRunnable(departmentPO.getId()).run();
2022-09-08 15:36:47 +08:00
}
// 查询该部门一级岗位、更新岗位所属分部、所属部门
2022-12-20 18:17:40 +08:00
//List<JobPO> firstChildJobList = getJobMapper().listJobsByDepartmentId(mergeParam.getId());
//firstChildJobList = firstChildJobList.stream().filter(item -> null == item.getParentJob() || 0 == item.getParentJob()).collect(Collectors.toList());
2022-09-08 15:36:47 +08:00
// 批量更新部门、所属分部
RecordSet rs = new RecordSet();
String targetEcDeptId = targetDepartment.getId().toString();
String mergeEcDeptId = mergeParam.getId().toString();
//rs.executeUpdate("update jcl_org_job set parent_comp =?,ec_company =?,parent_dept =?,ec_department =? where ec_department =?", targetDepartment.getSubCompanyId1(), targetDepartment.getSubCompanyId1(), targetDepartment.getId(), targetEcDeptId, mergeParam.getId());
2022-09-08 17:54:46 +08:00
// 更新岗位组织架构图
2022-12-08 17:10:31 +08:00
//for (JobPO jobPO : firstChildJobList) {
// // 刷新组织架构图
2023-07-03 10:50:07 +08:00
// new JobTriggerRunnable(jobPO.getId()).run();
2022-12-08 17:10:31 +08:00
//}
2022-09-08 15:36:47 +08:00
// 更新当前部门下的人员
rs.executeUpdate("update hrmresource set SUBCOMPANYID1 =?,DEPARTMENTID =? where DEPARTMENTID =?", targetDepartment.getSubCompanyId1(), targetEcDeptId, mergeEcDeptId);
//new RecordSet().executeUpdate("update jcl_org_hrmresource set company_id =? ,ec_company = ? ,department_id = ?, ec_department = ?where department_id =?", targetDepartment.getParentComp(), targetDepartment.getEcCompany(), targetDepartment.getId(), targetEcDeptId, mergeParam.getId());
//List<Long> hrmResourceIds = getSystemDataMapper().getHrmResourceIdsByDept(mergeParam.getId().toString());
//// 更新人员组织架构图
//for (Long hrmResourceId : hrmResourceIds) {
2023-07-03 10:50:07 +08:00
// new HrmResourceTriggerRunnable(hrmResourceId).run();
//}
2022-09-08 15:36:47 +08:00
// 更新子部门下岗位的所属分部
for (DepartmentPO departmentPO : firstChildDeptList) {
List<DepartmentPO> deptList = getDepartmentMapper().getDeptListByPId(departmentPO.getId());
2022-12-07 11:49:06 +08:00
forbiddenChildTag(targetDepartment.getSubCompanyId1(), deptList);
2022-09-08 15:36:47 +08:00
}
// 原部门删除
2022-11-30 15:55:27 +08:00
// DepartmentPO mergeDepartment = getDepartmentMapper().getDeptById(mergeParam.getId());
2023-07-31 09:43:23 +08:00
// 删除部门(先更改原部门名称,释放原部门名称,然后删除)
DepartmentPO sourceDepartmentPO = getDepartmentMapper().getDeptById(mergeParam.getId());
sourceDepartmentPO.setDepartmentName(sourceDepartmentPO.getDepartmentName() + "_被合并");
sourceDepartmentPO.setDepartmentMark(sourceDepartmentPO.getDepartmentMark() + "_被合并");
updateEcDepartment(sourceDepartmentPO);
2022-09-08 15:36:47 +08:00
Map<String, Object> map = new HashMap<>();
2022-11-30 15:55:27 +08:00
map.put("id", Util.null2String(mergeParam.getId()));
2022-12-15 09:49:55 +08:00
ServiceUtil.getService(OrganizationServiceImpl.class, user).doDepartmentCancel(map, user);
2023-08-01 09:41:43 +08:00
// 删除原部门下的岗位
2022-08-31 14:24:00 +08:00
// 更新组织架构图
2023-07-03 10:50:07 +08:00
// new DepartmentTriggerRunnable(mergeDepartment).run();
2022-09-08 15:36:47 +08:00
// 更新部门合并后名称
targetDepartment.setDepartmentName(mergeParam.getMergeName());
targetDepartment.setDepartmentMark(mergeParam.getMergeName());
2022-09-08 15:36:47 +08:00
updateEcDepartment(targetDepartment);
// 更新组织架构图
2023-07-03 10:50:07 +08:00
// new DepartmentTriggerRunnable(oldFParentId, targetDepartment.getId()).run();
2022-09-08 15:36:47 +08:00
return 0;
2022-06-02 15:43:19 +08:00
}
@Override
public List<SearchConditionGroup> getMoveForm() {
List<SearchConditionGroup> addGroups = new ArrayList<>();
List<SearchConditionItem> condition = new ArrayList<>();
2022-09-05 17:25:11 +08:00
SearchConditionItem compBrowserItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "选择分部", "164", "company", "");
SearchConditionItem deptBrowserItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "选择部门", "4", "department", "");
2022-06-02 15:43:19 +08:00
List<SearchConditionOption> selectOptions = new ArrayList<>();
2022-06-23 09:14:19 +08:00
SearchConditionOption compOption = new SearchConditionOption("0", "分部");
2022-06-02 15:43:19 +08:00
SearchConditionOption deptOption = new SearchConditionOption("1", "部门");
selectOptions.add(compOption);
selectOptions.add(deptOption);
SearchConditionItem moveTypeItem = OrganizationFormItemUtil.selectItem(user, selectOptions, 2, 16, 6, false, "转移到", "moveType");
moveTypeItem.setDetailtype(3);
2022-06-06 19:19:28 +08:00
moveTypeItem.setValue("0");
2022-06-02 15:43:19 +08:00
condition.add(moveTypeItem);
condition.add(compBrowserItem);
condition.add(deptBrowserItem);
addGroups.add(new SearchConditionGroup("", true, condition));
return addGroups;
}
@Override
public int moveDepartment(DepartmentMoveParam moveParam) {
2022-06-07 12:02:36 +08:00
HasRightUtil.hasRight(user, RIGHT_NAME, false);
2022-06-02 15:43:19 +08:00
OrganizationAssert.notBlank(moveParam.getMoveType(), "请选择转移类型");
DepartmentPO deptById = getDepartmentMapper().getDeptById(moveParam.getId());
// 0公司/分部 1部门
if ("0".equals(moveParam.getMoveType())) {
2022-11-28 11:15:54 +08:00
Integer company = moveParam.getCompany();
2022-06-23 09:14:19 +08:00
OrganizationAssert.notNull(company, "请选择要转移到的分部");
deptById.setSubCompanyId1(company);
deptById.setSupDepId(null);
// 更新组织架构图
2023-07-03 10:50:07 +08:00
// new DepartmentTriggerRunnable(company.toString(), deptById).run();
2022-06-02 15:43:19 +08:00
} else if ("1".equals(moveParam.getMoveType())) {
Integer departmentId = moveParam.getDepartment();
2022-09-05 17:25:11 +08:00
OrganizationAssert.notNull(departmentId, "请选择要转移到的部门");
2022-08-17 09:28:04 +08:00
List<DepartmentPO> deptListByPId = getDepartmentMapper().getDeptListByPId(moveParam.getId());
Set<Integer> disableIds = new HashSet<>();
2022-08-17 09:28:04 +08:00
disableIds.add(moveParam.getId());
if (CollectionUtils.isNotEmpty(deptListByPId)) {
addDisableIds(disableIds, deptListByPId);
}
2022-09-05 17:25:11 +08:00
OrganizationAssert.isFalse(disableIds.contains(departmentId), "请勿选择当前部门本身及其子部门");
deptById.setSupDepId(departmentId);
2022-09-05 17:25:11 +08:00
DepartmentPO parentDepartment = getDepartmentMapper().getDeptById(departmentId);
deptById.setSubCompanyId1(parentDepartment.getSubCompanyId1());
// 更新组织架构图
2023-07-03 10:50:07 +08:00
// new DepartmentTriggerRunnable(Integer.toString(100000000 + department.intValue()), deptById).run();
2022-06-02 15:43:19 +08:00
}
2022-07-13 10:55:44 +08:00
// 更新EC部门
updateEcDepartment(deptById);
2022-08-30 10:46:42 +08:00
// 刷新岗位分部
//refreshJobComp(deptById.getId(), deptById.getSubCompanyId1());
2022-08-30 10:46:42 +08:00
List<DepartmentPO> deptList = getDepartmentMapper().getDeptListByPId(deptById.getId());
2022-09-09 15:29:21 +08:00
// 更新当前部门下的人员
2022-11-30 15:55:27 +08:00
// new RecordSet().executeUpdate("update hrmresource set SUBCOMPANYID1 =? where DEPARTMENTID = ?", deptById.getSubCompanyId1(), deptById.getId());
//// 更新人员组织架构图
//List<Long> hrmResourceIds = getSystemDataMapper().getHrmResourceIdsByDept(deptById.getId().toString());
//for (Long hrmResourceId : hrmResourceIds) {
2023-07-03 10:50:07 +08:00
// new HrmResourceTriggerRunnable(hrmResourceId).run();
//}
2022-12-07 11:49:06 +08:00
forbiddenChildTag(deptById.getSubCompanyId1(), deptList);
2022-08-30 10:46:42 +08:00
// 递归更新下级部门、岗位
return 1;
2022-06-02 15:43:19 +08:00
}
2023-08-01 09:41:43 +08:00
@Override
2023-08-01 11:20:28 +08:00
public int dragDepartment(DepartmentDragParam departmentDragParam) {
2023-08-01 09:41:43 +08:00
2023-08-01 11:20:28 +08:00
String sourceKey = Util.null2String(departmentDragParam.getSourcekey());// 原目标
String targetKey = Util.null2String(departmentDragParam.getTargetkey());// 目的地
String dragPostion = Util.null2String(departmentDragParam.getDropPosition());// 0:目的里面 1目的外边
2023-08-01 09:41:43 +08:00
DepartmentPO deptById = getDepartmentMapper().getDeptById(Util.getIntValue(sourceKey.substring(1)));
RecordSet recordSet = new RecordSet();
2023-08-02 11:29:56 +08:00
// 部门不能到集团下
String sourceType = sourceKey.substring(0, 1);
2023-08-01 15:17:59 +08:00
String sourceId = sourceKey.substring(1);
2023-08-01 09:41:43 +08:00
String targetType = targetKey.substring(0, 1);
String targetId = targetKey.substring(1);
2023-08-01 11:20:28 +08:00
String supComId = "";
String supId = "";
2023-08-02 15:04:01 +08:00
String ftype = "";
2023-08-01 11:20:28 +08:00
String querySupIdSql;
2023-08-02 17:26:16 +08:00
// OrganizationAssert.isFalse("s".equals(sourceType) && "d".equals(targetType), "分部不能转移到部门下");
2023-08-02 11:29:56 +08:00
OrganizationAssert.isFalse("-1".equals(dragPostion), "分部、部门不能转移至与集团平级");
2023-08-01 09:41:43 +08:00
if ("s".equals(targetType)) {// 分部
2023-08-02 15:04:01 +08:00
querySupIdSql = "select companyId as supComId,supsubcomid as supId,'s' as ftype from hrmsubcompany where id = ?";
2023-08-02 11:29:56 +08:00
} else {
2023-08-02 15:04:01 +08:00
querySupIdSql = "select subcompanyid1 as supComId,supdepid as supId,'d' as ftype from hrmdepartment where id = ?";
2023-08-01 09:41:43 +08:00
}
2023-08-02 10:51:59 +08:00
2023-08-02 15:04:01 +08:00
recordSet.executeQuery(querySupIdSql, targetId);
if (recordSet.next()) {
supId = Util.null2String(recordSet.getString("supId"));
supComId = Util.null2String(recordSet.getString("supComId"));
ftype = Util.null2String(recordSet.getString("ftype"));
}
2023-08-02 17:26:16 +08:00
if ("s".equals(sourceType)) {// 拖拽源是分部
Map<String, Object> params = new HashMap<>();
params.put("id", sourceId);
if ("0".equals(dragPostion)) {//内部
OrganizationAssert.isFalse("d".equals(targetType), "分部不能拖拽至部门下");
if ("c".equals(targetType)) {// 集团下上级分部为0
params.put("supsubcomid", "0");
}else if ("s".equals(targetType)){
params.put("supsubcomid", targetId);//上下级关系
}
}else{//外部
if("s".equals(targetType)){// 分部外(平级)
params.put("supsubcomid",supId);
}else{// 部门外(找上级)
OrganizationAssert.isFalse("d".equals(ftype), "分部不能拖拽至部门下");
params.put("supsubcomid",supId);
2023-08-01 09:41:43 +08:00
}
}
2023-08-02 17:26:16 +08:00
new OrganizationSyncEc(user, LogModuleNameEnum.COMPANY, OperateTypeEnum.UPDATE, params).sync();
} else {//拖拽源是部门
List<DepartmentPO> deptListByPId;
Set<Integer> disableIds = new HashSet<>();
if ("0".equals(dragPostion)) {//内部
OrganizationAssert.isFalse("c".equals(targetType), "部门不能拖拽至集团下");
if("s".equals(targetType)){
deptById.setSubCompanyId1(Util.getIntValue(targetId));
deptById.setSupDepId(null);
}else{
deptListByPId = getDepartmentMapper().getDeptListByPId(Util.getIntValue(targetId));
disableIds.add(Util.getIntValue(sourceKey.substring(1)));
if (CollectionUtils.isNotEmpty(deptListByPId)) {
addDisableIds(disableIds, deptListByPId);
}
OrganizationAssert.isFalse("d".equals(targetType) && disableIds.contains(Util.getIntValue(targetId)), "请勿选择当前部门本身及其子部门");
deptById.setSupDepId(Util.getIntValue(targetId));
DepartmentPO parentDepartment = getDepartmentMapper().getDeptById(Util.getIntValue(targetId));
deptById.setSubCompanyId1(parentDepartment.getSubCompanyId1());
2023-08-02 15:04:01 +08:00
}
2023-08-02 17:26:16 +08:00
}else{//外部
if("s".equals(targetType)){
OrganizationAssert.isFalse("0".equals(supId), "部门不能拖拽至集团下");
deptById.setSubCompanyId1(Util.getIntValue(supId));
deptById.setSupDepId(null);
}else{
// 转移到部门外
deptListByPId = getDepartmentMapper().getDeptListByPId(Util.getIntValue(supId));
disableIds.add(Util.getIntValue(sourceKey.substring(1)));
if (CollectionUtils.isNotEmpty(deptListByPId)) {
addDisableIds(disableIds, deptListByPId);
}
deptById.setSupDepId(Util.getIntValue(supId));
deptById.setSubCompanyId1(Util.getIntValue(supComId));
2023-08-01 09:41:43 +08:00
}
}
2023-08-02 17:26:16 +08:00
// 更新EC部门
updateEcDepartment(deptById);
// 刷新岗位分部
List<DepartmentPO> deptList = getDepartmentMapper().getDeptListByPId(deptById.getId());
forbiddenChildTag(deptById.getSubCompanyId1(), deptList);
2023-08-01 09:41:43 +08:00
}
return 1;
}
2022-06-02 15:43:19 +08:00
/**
* 获取所有子部门id
*
2022-12-07 11:49:06 +08:00
* @param subCompanyId1
2022-06-02 15:43:19 +08:00
* @param deptList
*/
2022-12-07 11:49:06 +08:00
void forbiddenChildTag(Integer subCompanyId1, List<DepartmentPO> deptList) {
2022-06-02 15:43:19 +08:00
if (CollectionUtils.isNotEmpty(deptList)) {
for (DepartmentPO departmentPO : deptList) {
2022-12-07 11:49:06 +08:00
departmentPO.setSubCompanyId1(subCompanyId1);
2022-07-13 10:55:44 +08:00
// 更新EC表部门
2022-12-07 11:49:06 +08:00
updateEcDepartment(departmentPO);
2022-08-26 15:36:06 +08:00
2022-08-31 14:24:00 +08:00
// 更新组织架构图
2023-07-03 10:50:07 +08:00
// new DepartmentTriggerRunnable(departmentPO.getId()).run();
2022-08-30 10:46:42 +08:00
// 刷新岗位所属分部
//refreshJobComp(departmentPO.getId(), subCompanyId1);
2022-09-08 15:36:47 +08:00
// 更新当前部门下的人员
2022-11-30 15:55:27 +08:00
// String ecDepartmentId = EcHrmRelationUtil.getEcDepartmentId(departmentPO.getId().toString());
//new RecordSet().executeUpdate("update hrmresource set SUBCOMPANYID1 =? where DEPARTMENTID = ?", ecCompanyId, ecDepartmentId);
//new RecordSet().executeUpdate("update jcl_org_hrmresource set company_id =? ,ec_company = ? where department_id =?", parentComp, ecCompanyId, departmentPO.getId());
//List<Long> hrmResourceIds = getSystemDataMapper().getHrmResourceIdsByDept(departmentPO.getId().toString());
//// 更新人员组织架构图
//for (Long hrmResourceId : hrmResourceIds) {
2023-07-03 10:50:07 +08:00
// new HrmResourceTriggerRunnable(hrmResourceId).run();
//}
2022-06-02 15:43:19 +08:00
List<DepartmentPO> childList = getDepartmentMapper().getDeptListByPId(departmentPO.getId());
2022-12-07 11:49:06 +08:00
forbiddenChildTag(subCompanyId1, childList);
2022-06-02 15:43:19 +08:00
}
}
}
2022-05-23 17:46:37 +08:00
/**
2022-05-27 18:05:15 +08:00
* 是否为搜索查询
2022-05-23 17:46:37 +08:00
*
* @param departmentPO
* @return
*/
2022-05-27 18:05:15 +08:00
private boolean isFilter(DepartmentPO departmentPO) {
return !(StringUtil.isEmpty(departmentPO.getDepartmentCode())
&& StringUtil.isEmpty(departmentPO.getDepartmentName())
&& null == departmentPO.getSubCompanyId1()
2022-12-08 14:16:58 +08:00
&& null == departmentPO.getSupDepId()
&& null == departmentPO.getDepartmentId());
2022-05-27 18:05:15 +08:00
}
2022-05-23 17:46:37 +08:00
2022-06-02 09:58:16 +08:00
/**
* 根据keyword查询数据
*
* @param id
* @param keyword
* @return
*/
2022-06-06 14:41:46 +08:00
private List<SearchTree> getFilterCompany(String id, String keyword) {
2022-06-02 09:58:16 +08:00
// 查询部门信息
2022-11-28 11:15:54 +08:00
Integer parentCompId = StringUtil.isEmpty(id) ? null : Integer.parseInt(id);
2022-11-30 16:06:40 +08:00
CompPO compBuild = CompPO.builder().subCompanyName(keyword).supSubComId(parentCompId).canceled(0).build();
List<CompPO> allCompanys = getCompMapper().listAll("showOrder");
2022-12-13 10:42:35 +08:00
new DetachUtil(user).filterCompanyList(allCompanys);
2022-11-30 16:06:40 +08:00
List<CompPO> filterComps = getCompMapper().listByFilter(compBuild, "showOrder");
2022-12-13 10:42:35 +08:00
new DetachUtil(user).filterCompanyList(filterComps);
2022-10-28 17:43:46 +08:00
2022-11-30 16:06:40 +08:00
Map<Integer, CompPO> allMaps = allCompanys.stream().collect(Collectors.toMap(CompPO::getId, item -> item, (k1, k2) -> k1));
2022-06-02 09:58:16 +08:00
2022-11-30 16:06:40 +08:00
Set<CompPO> builderComps = new HashSet<>();
for (CompPO companyPO : filterComps) {
2022-11-28 11:15:54 +08:00
buildParentComps(companyPO, builderComps, allMaps);
2022-06-02 09:58:16 +08:00
}
2022-11-30 16:06:40 +08:00
return SearchTreeUtil.builderTreeMode(CompBO.buildSetToSearchTree(builderComps));
2022-06-02 09:58:16 +08:00
}
/**
* 添加查询元素的父级元素
*
* @param compPO
* @param builderComps
*/
2022-11-30 16:06:40 +08:00
private void buildParentComps(CompPO compPO, Set<CompPO> builderComps, Map<Integer, CompPO> allMaps) {
2022-06-02 09:58:16 +08:00
builderComps.add(compPO);
2022-11-30 16:06:40 +08:00
CompPO parentComp = allMaps.get(compPO.getSupSubComId());
2022-11-29 17:00:31 +08:00
if (null != parentComp && (null == parentComp.getCanceled() || 0 == parentComp.getCanceled())) {
2022-10-28 17:43:46 +08:00
buildParentComps(parentComp, builderComps, allMaps);
2022-06-02 09:58:16 +08:00
}
}
2022-06-23 09:14:19 +08:00
/**
* 判断编号是否重复
*
* @return
*/
2022-07-27 10:48:43 +08:00
public static String repeatDetermine(String deptNo) {
2022-06-23 13:43:52 +08:00
CodeRulePO codeRuleByType = MapperProxyFactory.getProxy(CodeRuleMapper.class).getCodeRuleByType(RuleCodeType.DEPARTMENT.getValue());
2022-06-23 09:14:19 +08:00
if (StringUtils.isNotBlank(deptNo)) {
deptNo = CodeRuleUtil.generateCode(RuleCodeType.DEPARTMENT, deptNo);
List<DepartmentPO> list = getDepartmentMapper().listByNo(Util.null2String(deptNo));
OrganizationAssert.isEmpty(list, "编号不允许重复");
} else {
2022-11-16 17:54:57 +08:00
OrganizationAssert.isTrue(null != codeRuleByType && "1".equals(codeRuleByType.getSerialEnable()), "编号不允许为空");
deptNo = autoCreateCompanyNo();
2022-06-23 09:14:19 +08:00
}
return deptNo;
}
/**
* 自动编号处理
*
* @return
*/
2022-07-27 10:48:43 +08:00
private static String autoCreateCompanyNo() {
2022-06-23 09:14:19 +08:00
String generateCode = CodeRuleUtil.generateCode(RuleCodeType.DEPARTMENT, "");
List<DepartmentPO> list = getDepartmentMapper().listByNo(Util.null2String(generateCode));
if (CollectionUtils.isNotEmpty(list)) {
generateCode = autoCreateCompanyNo();
}
return generateCode;
}
2022-07-13 10:55:44 +08:00
/**
* 更新EC表部门
*
* @param departmentPO
*/
private void updateEcDepartment(DepartmentPO departmentPO) {
Map<String, Object> map = new HashMap<>();
map.put("departmentmark", departmentPO.getDepartmentMark());
map.put("departmentname", departmentPO.getDepartmentName());
2022-11-30 15:55:27 +08:00
map.put("subcompanyid1", Util.null2String(departmentPO.getSubCompanyId1()));
map.put("supdepid", Util.null2String(departmentPO.getSupDepId()));
map.put("showorder", Util.null2String(departmentPO.getShowOrder()));
map.put("departmentcode", departmentPO.getDepartmentCode());
2022-11-30 15:55:27 +08:00
map.put("coadjutant", Util.null2String(departmentPO.getCoadjutant()));
2022-12-07 11:49:06 +08:00
map.put("id", Util.null2String(departmentPO.getId()));
2022-08-26 15:36:06 +08:00
new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.UPDATE, map).sync();
2022-07-13 10:55:44 +08:00
}
2022-08-17 09:28:04 +08:00
/**
* 新增EC表部门
*
* @param departmentPO
2022-08-26 15:36:06 +08:00
* @return
2022-08-17 09:28:04 +08:00
*/
2022-08-26 15:36:06 +08:00
private Map<String, Object> addEcDepartment(DepartmentPO departmentPO) {
2022-08-17 09:28:04 +08:00
Map<String, Object> map = new HashMap<>();
map.put("departmentmark", departmentPO.getDepartmentMark());
map.put("departmentname", departmentPO.getDepartmentName());
2022-11-30 15:55:27 +08:00
map.put("subcompanyid1", Util.null2String(departmentPO.getSubCompanyId1()));
map.put("supdepid", Util.null2String(departmentPO.getSupDepId()));
map.put("showorder", Util.null2String(departmentPO.getShowOrder()));
map.put("departmentcode", departmentPO.getDepartmentCode());
2022-08-26 15:36:06 +08:00
return new OrganizationSyncEc(user, LogModuleNameEnum.DEPARTMENT, OperateTypeEnum.ADD, map).sync();
2022-08-17 09:28:04 +08:00
}
2022-07-13 10:55:44 +08:00
private void addDisableIds(Set<Integer> disableIds, List<DepartmentPO> deptListByPId) {
2022-08-17 09:28:04 +08:00
for (DepartmentPO departmentPO : deptListByPId) {
disableIds.add(departmentPO.getId());
List<DepartmentPO> childDeptPOS = getDepartmentMapper().getDeptListByPId(departmentPO.getId());
addDisableIds(disableIds, childDeptPOS);
}
}
2022-08-30 10:46:42 +08:00
/**
* 更新岗位的所属分部
*
* @param parentDepartment
* @param parentComp
*/
private void refreshJobComp(Integer parentDepartment, Integer parentComp) {
2022-12-14 10:52:20 +08:00
List<JobPO> jobPOS = getJobMapper().listJobsByDepartmentId(parentDepartment);
jobPOS = jobPOS.stream().filter(item -> null == item.getParentJob() || 0 == item.getParentJob()).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(jobPOS)) {
getJobMapper().updateJobCompany(jobPOS.stream().map(JobPO::getId).collect(Collectors.toList()), parentComp, parentComp);
}
2022-08-30 10:46:42 +08:00
}
2022-12-16 18:29:12 +08:00
private List<SearchConditionGroup> getDepartmentConditionGroups(Boolean showAll, Map<String, Object> params) {
2022-12-07 11:49:06 +08:00
List<SearchConditionGroup> groupList = new ArrayList<>();
List<SearchConditionItem> itemList;
String id = Util.null2String(params.get("id"));
int viewAttr = Util.getIntValue(Util.null2String(params.get("viewattr")), 1);
String addType = Util.null2String(params.get("addType"));
2022-12-08 14:16:58 +08:00
String subcompanyid1 = Util.null2String(params.get("subcompanyid1"));
String supDepId = Util.null2String(params.get("departmentid"));
if (StringUtils.isNotBlank(supDepId)) {
subcompanyid1 = new DepartmentComInfo().getSubcompanyid1(supDepId);
2022-12-07 11:49:06 +08:00
}
2022-12-08 14:16:58 +08:00
2022-12-07 11:49:06 +08:00
HrmFieldGroupComInfo HrmFieldGroupComInfo = new HrmFieldGroupComInfo();
HrmFieldComInfo HrmFieldComInfo = new HrmFieldComInfo();
HrmFieldSearchConditionComInfo hrmFieldSearchConditionComInfo = new HrmFieldSearchConditionComInfo();
SearchConditionItem searchConditionItem;
HrmFieldBean hrmFieldBean;
HrmDeptFieldManagerE9 hfm;
try {
hfm = new HrmDeptFieldManagerE9(5);
} catch (Exception e) {
throw new OrganizationRunTimeException("");
}
hfm.isReturnDecryptData(true);
hfm.getCustomData(Util.getIntValue(id));
List lsGroup = hfm.getLsGroup();
2022-12-16 18:29:12 +08:00
int lsSize = 1;
if (showAll && lsGroup != null) {
lsSize = lsGroup.size();
}
for (int tmp = 0; tmp < lsSize; tmp++) {
2022-12-07 11:49:06 +08:00
String groupId = (String) lsGroup.get(tmp);
List lsField = hfm.getLsField(groupId);
boolean groupHide = lsField.size() == 0 || hfm.getGroupCount(lsField) == 0 || !"1".equals(Util.null2String(HrmFieldGroupComInfo.getIsShow(groupId)));
String grouplabel = HrmFieldGroupComInfo.getLabel(groupId);
itemList = new ArrayList<>();
for (Object o : lsField) {
String fieldId = (String) o;
String fieldName = HrmFieldComInfo.getFieldname(fieldId);
String isUse = HrmFieldComInfo.getIsused(fieldId);
2022-12-15 16:13:21 +08:00
if (!"1".equals(isUse)) {
continue;
}
2022-12-07 11:49:06 +08:00
int tmpViewAttr = viewAttr;
String rules = "";
String fieldLabel = HrmFieldComInfo.getLabel(fieldId);
String fieldHtmlType = HrmFieldComInfo.getFieldhtmltype(fieldId);
String type = HrmFieldComInfo.getFieldType(fieldId);
String dmlUrl = Util.null2String(HrmFieldComInfo.getFieldDmlurl(fieldId));
String isSystem = HrmFieldComInfo.getIssystem(fieldId);
String fieldValue = "";
if (StringUtils.isBlank(addType)) {
if ("1".equals(isSystem)) {
fieldValue = hfm.getData(fieldName);
} else {
fieldValue = hfm.getData("hrmdepartmentdefined", fieldName);
}
}
if (!groupHide && tmpViewAttr == 2 && "1".equals(HrmFieldComInfo.getIsmand(fieldId))) {
tmpViewAttr = 3;
if ("1".equals(fieldHtmlType) && "2".equals(type)) {
rules = "required|integer";
} else {
rules = "required|string";
}
}
if (subcompanyid1.length() > 0 && "subcompanyid1".equals(fieldName)) {
fieldValue = subcompanyid1;
}
if (supDepId.length() > 0 && "supdepid".equals(fieldName)) {
fieldValue = supDepId;
}
if ("showid".equals(fieldName)) {
if (addType.length() > 0) {
continue;
} else {
fieldValue = id;
tmpViewAttr = 1;
}
}
hrmFieldBean = new HrmFieldBean();
hrmFieldBean.setFieldid(fieldId);
hrmFieldBean.setFieldname(fieldName);
hrmFieldBean.setFieldlabel(fieldLabel);
hrmFieldBean.setFieldhtmltype(fieldHtmlType);
hrmFieldBean.setType(type);
hrmFieldBean.setIsFormField(true);
hrmFieldBean.setIssystem("1");
hrmFieldBean.setFieldvalue(fieldValue);
hrmFieldBean.setDmlurl(dmlUrl);
hrmFieldBean.setViewAttr(tmpViewAttr);
hrmFieldBean.setRules(rules);
if ("subcompanyid1".equals(hrmFieldBean.getFieldname()) || "supdepid".equals(hrmFieldBean.getFieldname())) {
hrmFieldBean.setHideVirtualOrg(true);
}
if ("departmentcode".equals(hrmFieldBean.getFieldname())) {
hrmFieldBean.setMultilang(false);
}
searchConditionItem = hrmFieldSearchConditionComInfo.getSearchConditionItem(hrmFieldBean, user);
if (searchConditionItem != null) {
searchConditionItem.setLabelcol(8);
searchConditionItem.setFieldcol(16);
if ("showorder".equals(fieldName)) {
searchConditionItem.setPrecision(2);
}
if ("showid".equals(fieldName)) {
Map<String, Object> otherParams = new HashMap<>();
otherParams.put("hasBorder", true);
searchConditionItem.setOtherParams(otherParams);
}
if ("6".equals(fieldHtmlType)) {//附件
Map<String, Object> otherParams1 = new HashMap<>();
otherParams1.put("showOrder", false);
searchConditionItem.setOtherParams(otherParams1);
}
2022-12-13 18:19:12 +08:00
itemList.add(searchConditionItem);
2022-12-07 11:49:06 +08:00
}
}
groupList.add(new SearchConditionGroup(SystemEnv.getHtmlLabelNames(grouplabel, user.getLanguage()), true, itemList));
2022-12-13 18:19:12 +08:00
2022-12-07 11:49:06 +08:00
}
return groupList;
}
2022-05-20 15:00:03 +08:00
}