|
|
|
package com.engine.organization.service.impl;
|
|
|
|
|
|
|
|
import com.api.browser.bean.SearchConditionGroup;
|
|
|
|
import com.api.browser.bean.SearchConditionItem;
|
|
|
|
import com.cloudstore.eccom.pc.table.WeaTableColumn;
|
|
|
|
import com.cloudstore.eccom.result.WeaResultMsg;
|
|
|
|
import com.engine.core.impl.Service;
|
|
|
|
import com.engine.organization.component.OrganizationWeaTable;
|
|
|
|
import com.engine.organization.entity.department.bo.DepartmentBO;
|
|
|
|
import com.engine.organization.entity.department.dto.DepartmentListDTO;
|
|
|
|
import com.engine.organization.entity.department.param.DeptSearchParam;
|
|
|
|
import com.engine.organization.entity.department.param.QuerySingleDeptListParam;
|
|
|
|
import com.engine.organization.entity.department.po.DepartmentPO;
|
|
|
|
import com.engine.organization.entity.department.vo.SingleDeptTreeVO;
|
|
|
|
import com.engine.organization.mapper.department.DepartmentMapper;
|
|
|
|
import com.engine.organization.service.DepartmentService;
|
|
|
|
import com.engine.organization.util.OrganizationFormItemUtil;
|
|
|
|
import com.engine.organization.util.db.MapperProxyFactory;
|
|
|
|
import com.engine.organization.util.page.Column;
|
|
|
|
import com.engine.organization.util.page.PageInfo;
|
|
|
|
import com.engine.organization.util.page.PageUtil;
|
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
import weaver.general.StringUtil;
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author weaver_cl
|
|
|
|
* @Description: TODO
|
|
|
|
* @Date 2022/5/20
|
|
|
|
* @Version V1.0
|
|
|
|
**/
|
|
|
|
public class DepartmentServiceImpl extends Service implements DepartmentService {
|
|
|
|
|
|
|
|
private DepartmentMapper getDepartmentMapper() {
|
|
|
|
return MapperProxyFactory.getProxy(DepartmentMapper.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public PageInfo<SingleDeptTreeVO> getDeptListByPid(QuerySingleDeptListParam param) {
|
|
|
|
|
|
|
|
//1.查询分部下所有部门
|
|
|
|
PageUtil.start(param.getCurrent(), param.getPageSize());
|
|
|
|
List<DepartmentPO> departmentPOS = MapperProxyFactory.getProxy(DepartmentMapper.class).getDeptListByCompId(param.getParentComp());
|
|
|
|
PageInfo<DepartmentPO> pageInfo = new PageInfo<>(departmentPOS);
|
|
|
|
List<SingleDeptTreeVO> singleDeptTreeVOS = DepartmentBO.buildSingleDeptTreeVOS(departmentPOS);
|
|
|
|
PageInfo<SingleDeptTreeVO> pageInfos = new PageInfo<>(singleDeptTreeVOS, SingleDeptTreeVO.class);
|
|
|
|
pageInfos.setTotal(pageInfo.getTotal());
|
|
|
|
pageInfos.setPageNum(param.getCurrent());
|
|
|
|
pageInfos.setPageSize(param.getPageSize());
|
|
|
|
|
|
|
|
return pageInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Object> listPage(DeptSearchParam param) {
|
|
|
|
Map<String, Object> datas = new HashMap<>();
|
|
|
|
PageUtil.start(param.getCurrent(), param.getPageSize());
|
|
|
|
List<DepartmentPO> parentList = getDepartmentMapper().listParent();
|
|
|
|
PageInfo<DepartmentPO> pageInfo = new PageInfo<>(parentList);
|
|
|
|
List<DepartmentPO> list = new ArrayList<>();
|
|
|
|
list.addAll(parentList);
|
|
|
|
|
|
|
|
if (CollectionUtils.isNotEmpty(parentList)) {
|
|
|
|
// 递归查询子数据
|
|
|
|
getChildPOs(parentList, list);
|
|
|
|
}
|
|
|
|
DepartmentPO departmentPO = DepartmentBO.convertParamsToPO(param, (long) user.getUID());
|
|
|
|
// 搜索条件过滤数据
|
|
|
|
List<DepartmentPO> filterList = filterListByParams(list, departmentPO);
|
|
|
|
|
|
|
|
List<DepartmentListDTO> departmentListDTOS = DepartmentBO.buildDeptDTOList(list, filterList);
|
|
|
|
PageInfo<DepartmentListDTO> pageInfos = new PageInfo<>(departmentListDTOS, DepartmentListDTO.class);
|
|
|
|
pageInfos.setTotal(pageInfo.getTotal());
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int saveBaseComp(DeptSearchParam params) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Map<String, Object> getSaveForm() {
|
|
|
|
Map<String, Object> apiDatas = new HashMap<>();
|
|
|
|
List<SearchConditionGroup> addGroups = new ArrayList<>();
|
|
|
|
List<SearchConditionItem> conditionItems = new ArrayList<>();
|
|
|
|
// 编号
|
|
|
|
SearchConditionItem deptNoItem = OrganizationFormItemUtil.inputItem(user, 2, 16, 3, 50, "编号", "deptNo");
|
|
|
|
deptNoItem.setRules("required|string");
|
|
|
|
// 名称
|
|
|
|
SearchConditionItem deptNameItem = OrganizationFormItemUtil.inputItem(user, 2, 16, 3, 50, "名称", "deptName");
|
|
|
|
deptNameItem.setRules("required|string");
|
|
|
|
// 简称
|
|
|
|
SearchConditionItem deptNameShortItem = OrganizationFormItemUtil.inputItem(user, 2, 16, 3, 50, "简称", "deptNameShort");
|
|
|
|
deptNameShortItem.setRules("required|string");
|
|
|
|
// TODO 自定义按钮
|
|
|
|
// 所属分部
|
|
|
|
SearchConditionItem compBrowserItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "所属分部", "161", "parentComp", "compBrowser");
|
|
|
|
//上级部门
|
|
|
|
SearchConditionItem deptBrowserItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "上级公司", "161", "parentDept", "deptBrowser");
|
|
|
|
// 部门负责人
|
|
|
|
SearchConditionItem deptPrincipalItem = OrganizationFormItemUtil.browserItem(user, 2, 16, 2, false, "部门负责人", "1", "deptPrincipal", "");
|
|
|
|
// 显示顺序
|
|
|
|
SearchConditionItem showOrderItem = OrganizationFormItemUtil.inputItem(user, 2, 16, 3, 50, "编号", "showOrder");
|
|
|
|
// 说明
|
|
|
|
SearchConditionItem descriptionItem = OrganizationFormItemUtil.textareaItem(user, 2, 16, true, 2, 60, "说明", "description");
|
|
|
|
|
|
|
|
conditionItems.add(deptNoItem);
|
|
|
|
conditionItems.add(deptNameItem);
|
|
|
|
conditionItems.add(deptNameShortItem);
|
|
|
|
conditionItems.add(compBrowserItem);
|
|
|
|
conditionItems.add(deptBrowserItem);
|
|
|
|
conditionItems.add(deptPrincipalItem);
|
|
|
|
conditionItems.add(showOrderItem);
|
|
|
|
conditionItems.add(descriptionItem);
|
|
|
|
|
|
|
|
|
|
|
|
addGroups.add(new SearchConditionGroup("基本信息", true, conditionItems));
|
|
|
|
apiDatas.put("condition", addGroups);
|
|
|
|
|
|
|
|
return apiDatas;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 通过搜索条件过滤list数据
|
|
|
|
*
|
|
|
|
* @param departmentPOS
|
|
|
|
* @param departmentPO
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
private List<DepartmentPO> filterListByParams(Collection<DepartmentPO> departmentPOS, DepartmentPO departmentPO) {
|
|
|
|
// 搜索后的数据
|
|
|
|
List<DepartmentPO> filterList = new ArrayList<>();
|
|
|
|
// 筛选数据
|
|
|
|
for (Iterator<DepartmentPO> iterator = departmentPOS.iterator(); iterator.hasNext(); ) {
|
|
|
|
DepartmentPO next = iterator.next();
|
|
|
|
boolean isAdd = (StringUtil.isEmpty(departmentPO.getDeptName()) || next.getDeptName().contains(departmentPO.getDeptName())) // 名称
|
|
|
|
&& (StringUtil.isEmpty(departmentPO.getDeptNo()) || next.getDeptNo().contains(departmentPO.getDeptNo()))//编号
|
|
|
|
&& (StringUtil.isEmpty(departmentPO.getDeptNameShort()) || next.getDeptNameShort().contains(departmentPO.getDeptNameShort()))//简称
|
|
|
|
&& (null == departmentPO.getParentComp() || next.getParentComp().equals(departmentPO.getParentComp()))//所属分部
|
|
|
|
&& (null == departmentPO.getParentDept() || next.getParentDept().equals(departmentPO.getParentDept()))//上级部门
|
|
|
|
&& (null == departmentPO.getDeptPrincipal() || next.getDeptPrincipal().equals(departmentPO.getDeptPrincipal()))//部门负责人
|
|
|
|
&& (null == departmentPO.getShowOrder() || next.getShowOrder().equals(departmentPO.getShowOrder()))//显示顺序
|
|
|
|
&& (null == departmentPO.getForbiddenTag() || next.getForbiddenTag().equals(departmentPO.getForbiddenTag()));//禁用标记
|
|
|
|
|
|
|
|
if (isAdd) {
|
|
|
|
filterList.add(next);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return filterList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 递归获取子级数据
|
|
|
|
*
|
|
|
|
* @param parentList
|
|
|
|
* @param list
|
|
|
|
*/
|
|
|
|
private void getChildPOs(List<DepartmentPO> parentList, List<DepartmentPO> list) {
|
|
|
|
List<Long> ids = parentList.stream().map(DepartmentPO::getId).collect(Collectors.toList());
|
|
|
|
List<DepartmentPO> listChild = getDepartmentMapper().listChild(ids);
|
|
|
|
if (CollectionUtils.isNotEmpty(listChild)) {
|
|
|
|
list.addAll(listChild);
|
|
|
|
getChildPOs(listChild, list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|