package com.engine.organization.service.impl; import cn.hutool.core.collection.CollectionUtil; import com.engine.core.impl.Service; import com.engine.organization.entity.chart.ChartPO; import com.engine.organization.entity.chart.ResourceListColumns; import com.engine.organization.entity.chart.params.ModeHrmResourceParam; import com.engine.organization.entity.hrmresource.po.ResourceChartPO; import com.engine.organization.entity.hrmresource.vo.ResourceChartVO; import com.engine.organization.mapper.hrmresource.SystemDataMapper; import com.engine.organization.service.ModeHrmResourceService; import com.engine.organization.util.db.MapperProxyFactory; import lombok.SneakyThrows; import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSet; import weaver.general.Util; import weaver.hrm.company.DepartmentComInfo; import weaver.hrm.company.SubCompanyComInfo; import weaver.hrm.resource.ResourceComInfo; import java.util.*; /** * @Author liang.cheng * @Date 2024/4/24 2:01 PM * @Description: uf_zsygrzbdd 正式员工档案 uf_qlwbrydngljmb 外部人员档案 * @Version 1.0 */ public class ModeHrmResourceServiceImpl extends Service implements ModeHrmResourceService { @Override public Map chartResourceList(ModeHrmResourceParam param) { Map dataMap = new HashMap<>(4); List resourceListColumns = getTableColumns(); List allSupDepartment = getAllSupDepartment(param.getDepartmentId()); List resourceChartNb = new ArrayList<>(selectNbPerson(allSupDepartment)); List resourceChartVOS = convertToVO(resourceChartNb,"1"); List resourceChartWb = new ArrayList<>(selectWbPerson(allSupDepartment)); resourceChartVOS.addAll(convertToVO(resourceChartWb,"2")); dataMap.put("columns", resourceListColumns); dataMap.put("dataSource", resourceChartVOS); return dataMap; } @Override public Map chartResourceChart(ModeHrmResourceParam param) { List dataList = new ArrayList<>(); String departmentId = param.getDepartmentId(); RecordSet rs = new RecordSet(); rs.executeQuery("select a.id,a.departmentname as name,b.bmfzr\n" + "from hrmdepartment a left join hrmdepartmentdefined b on a.id = b.deptid \n" + "where a.id = ?",param.getDepartmentId()); //部门 ChartPO departmentChartPO = new ChartPO(); if (rs.next()) { String fLeader = Util.null2String(rs.getString("bmfzr")); departmentChartPO.setFtype("2"); departmentChartPO.setFobjid(departmentId); departmentChartPO.setExpand("1"); departmentChartPO.setId("d_"+departmentId); departmentChartPO.setFname(rs.getString("name")); departmentChartPO.setFleader(getDepartmentLeader(fLeader)); try { departmentChartPO.setFleaderimg(new ResourceComInfo().getMessagerUrls(fLeader)); } catch (Exception e) { throw new RuntimeException(e); } } //人员 List allSupDepartment = getAllSupDepartment(param.getDepartmentId()); List resourceChartNb = new ArrayList<>(selectNbPerson(allSupDepartment)); List resourceChartVOS = convertToVO(resourceChartNb,"1"); List resourceChartWb = new ArrayList<>(selectWbPerson(allSupDepartment)); resourceChartVOS.addAll(convertToVO(resourceChartWb,"2")); resourceChartVOS.forEach(item -> { ChartPO chartPO = getResourceChartPO(item,departmentChartPO.getId()); dataList.add(chartPO); }); departmentChartPO.setFonjob(resourceChartVOS.size()); dataList.add(departmentChartPO); Map result = new HashMap<>(4); result.put("api_status", true); result.put("data", dataList); return result; } @Override public int selcetPersonCount(String departmentIds) { RecordSet rs = new RecordSet(); int totalCount = 0; rs.executeQuery("select count(1) as total_count from uf_zsygrzbdd where zt < 4 and bm in ("+departmentIds+")"); if (rs.next()) { totalCount = Util.getIntValue(rs.getString("total_count")); } rs.executeQuery("select count(1) as total_count from uf_qlwbrydngljmb where zt < 4 and bmbz in ("+departmentIds+")"); if (rs.next()) { totalCount += Util.getIntValue(rs.getString("total_count")); } return totalCount; } /** * 正式员工 * @param allSupDepartment * @return */ private List selectNbPerson(Collection allSupDepartment) { RecordSet rs = new RecordSet(); List resourceChartPOS = new ArrayList<>(); String join = CollectionUtil.join(allSupDepartment, ","); rs.executeQuery("select id,gh,xm,xb,bm,gw,sjhm from uf_zsygrzbdd where zt < 4 and bm in ("+join+")"); while (rs.next()) { ResourceChartPO build = ResourceChartPO.builder() .id((long) Util.getIntValue(rs.getString("id"))) .workCode(Util.null2String(rs.getString("gh"))) .lastName(Util.null2String(rs.getString("xm"))) .sex(Util.null2String(rs.getString("xb"))) .departmentId(Util.getIntValue(rs.getString("bm"))) .jobBrowser(Util.null2String(rs.getString("gw"))) .mobile(Util.null2String(rs.getString("sjhm"))) .build(); resourceChartPOS.add(build); } return resourceChartPOS; } /** * 外部员工 * @param allSupDepartment * @return */ private List selectWbPerson(Collection allSupDepartment) { RecordSet rs = new RecordSet(); List resourceChartPOS = new ArrayList<>(); String join = CollectionUtil.join(allSupDepartment, ","); rs.executeQuery("select id, gh,xm,xb,bmbz,gw,lxfs from uf_qlwbrydngljmb where zt < 4 and bmbz in ("+join+")"); while (rs.next()) { ResourceChartPO build = ResourceChartPO.builder() .id((long) Util.getIntValue(rs.getString("id"))) .workCode(Util.null2String(rs.getString("gh"))) .lastName(Util.null2String(rs.getString("xm"))) .sex(Util.null2String(rs.getString("xb"))) .departmentId(Util.getIntValue(rs.getString("bmbz"))) .jobBrowser(Util.null2String(rs.getString("gw"))) .mobile(Util.null2String(rs.getString("lxfs"))) .build(); resourceChartPOS.add(build); } return resourceChartPOS; } /** * 列表表头 * @return */ private List getTableColumns() { List list = new ArrayList<>(); list.add(ResourceListColumns.builder().title("序号").dataIndex("id").key("id").build()); list.add(ResourceListColumns.builder().title("工号").dataIndex("workCode").key("workCode").build()); list.add(ResourceListColumns.builder().title("姓名").dataIndex("lastName").key("lastName").build()); list.add(ResourceListColumns.builder().title("性别").dataIndex("sex").key("sex").build()); list.add(ResourceListColumns.builder().title("部门").dataIndex("departmentName").key("departmentName").build()); list.add(ResourceListColumns.builder().title("分部").dataIndex("subcompanyName").key("subcompanyName").build()); list.add(ResourceListColumns.builder().title("岗位").dataIndex("jobTitle").key("jobTitle").build()); list.add(ResourceListColumns.builder().title("手机号").dataIndex("mobile").key("mobile").build()); return list; } /** * 获取所有子部门和当前部门集合 * @param departmentId * @return */ @SneakyThrows private List getAllSupDepartment(String departmentId){ DepartmentComInfo departmentComInfo = new DepartmentComInfo(); ArrayList subList = new ArrayList(); departmentComInfo.getAllChildDeptByDepId(subList, departmentId); subList.add(departmentId); return subList; } /** * 转换 * @param resourceChartPOS * @return */ @SneakyThrows private List convertToVO(List resourceChartPOS,String type) { List resourceChartVOS = new ArrayList<>(); DepartmentComInfo departmentComInfo = new DepartmentComInfo(); SubCompanyComInfo subCompanyComInfo = new SubCompanyComInfo(); for (ResourceChartPO item : resourceChartPOS) { ResourceChartVO resourceChartVO = new ResourceChartVO(); String departmentId =String.valueOf(item.getDepartmentId()); String subCompanyname = subCompanyComInfo.getSubCompanyname(departmentComInfo.getSubcompanyid1(departmentId)); resourceChartVO.setId(item.getId()); resourceChartVO.setWorkCode(item.getWorkCode()); resourceChartVO.setLastName(item.getLastName()); resourceChartVO.setSex("1".equals(item.getSex()) ? "女" : "男"); resourceChartVO.setDepartmentName(departmentComInfo.getDepartmentName(departmentId)); resourceChartVO.setSubcompanyName(subCompanyname); resourceChartVO.setJobTitle(getJobBrowserName(item.getJobBrowser(),type)); resourceChartVO.setStatus(item.getStatus()); resourceChartVO.setMobile(item.getMobile()); resourceChartVOS.add(resourceChartVO); } return resourceChartVOS; } /** * 自定义岗位名称 * @param code * @param code * @return */ private String getJobBrowserName(String code,String type){ String gwmc; RecordSet rs = new RecordSet(); if ("1".equals(type)) { rs.executeQuery("select gwmc from uf_zsyggwbd where id = ?",code); rs.next(); gwmc = Util.null2String(rs.getString("gwmc")); }else { rs.executeQuery("select gwmc from uf_gwmc where gwbm = ?",code); rs.next(); gwmc = Util.null2String(rs.getString("gwmc")); } return gwmc; } /** * 获取部门负责人 * * @param ids 部门负责人ID * @return 人员名称 */ private String getDepartmentLeader(String ids) { if (StringUtils.isBlank(ids)) { return ""; } List leaderList = new ArrayList<>(); String[] split = ids.split(","); for (String s : split) { String lastName = MapperProxyFactory.getProxy(SystemDataMapper.class).getScHrmResourceNameById(s); if (StringUtils.isNotBlank(lastName)) { leaderList.add(lastName); } } return StringUtils.join(leaderList, ","); } /** * 构建人员图谱元素 * @param item * @return */ private ChartPO getResourceChartPO(ResourceChartVO item,String parentId) { ChartPO chartPO = new ChartPO(); chartPO.setFtype("4"); chartPO.setFobjid(String.valueOf(item.getId())); chartPO.setId(chartPO.getFobjid()); chartPO.setFname(item.getLastName()); chartPO.setParentId(parentId); chartPO.setLocalDeptName(item.getDepartmentName()); chartPO.setJobTitle(item.getJobTitle()); chartPO.setExpand("1"); chartPO.setHasChildren("0"); try { String resourceId = getResourceIdByWorkCode(item.getWorkCode()); chartPO.setFleaderimg(new ResourceComInfo().getMessagerUrls(resourceId)); } catch (Exception e) { throw new RuntimeException(e); } return chartPO; } /** * 获取人员id * @param workCode * @return */ private String getResourceIdByWorkCode(String workCode) { RecordSet rs = new RecordSet(); rs.executeQuery("select id from hrmresource where workcode = ?",workCode); rs.next(); return Util.null2String(rs.getString("id")); } }