组织架构图改造
This commit is contained in:
parent
e57af84b06
commit
33c3b0ccaf
|
|
@ -0,0 +1,40 @@
|
|||
package com.engine.organization.entity.chart;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/9/11 4:59 PM
|
||||
* @Description: 人数统计
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class StatisticsPO {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private Integer dataId;
|
||||
|
||||
private Integer superId;
|
||||
|
||||
private Integer type;
|
||||
|
||||
private Integer onJobNum;
|
||||
|
||||
private Integer staffNum;
|
||||
|
||||
private Integer creator;
|
||||
|
||||
private String createTime;
|
||||
|
||||
private String updateTime;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.engine.organization.entity.chart.params;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/9/13 1:38 PM
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class RecursionParam {
|
||||
|
||||
private Integer id;
|
||||
|
||||
/**
|
||||
* 子节点
|
||||
*/
|
||||
private List<RecursionParam> subRecursionParam;
|
||||
|
||||
private Integer employeeCount;
|
||||
|
||||
private Integer staffCount;
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.engine.organization.entity.chart.params;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/9/12 3:46 PM
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
public class StatisticsParam {
|
||||
|
||||
private Integer companyId;
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package com.engine.organization.service;
|
||||
|
||||
import com.engine.organization.entity.chart.params.StatisticsParam;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import java.util.Map;
|
||||
|
|
@ -81,4 +82,13 @@ public interface ChartService {
|
|||
* @return: java.util.Map<java.lang.String,java.lang.Object>
|
||||
*/
|
||||
Map<String, Object> selectStatistics(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* @Description: 人数统计多线程记录
|
||||
* @Author: liang.cheng
|
||||
* @Date: 2023/9/12 11:42 AM
|
||||
* @param: [request2Map]
|
||||
* @return: java.util.Map<java.lang.String,java.lang.Object>
|
||||
*/
|
||||
Map<String, Object> recordStatistics(StatisticsParam param);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,25 @@
|
|||
package com.engine.organization.service.impl;
|
||||
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.organization.entity.chart.ChartPO;
|
||||
import com.engine.organization.entity.chart.CompanyTreePO;
|
||||
import com.engine.organization.entity.chart.StatisticsVO;
|
||||
import com.engine.organization.entity.chart.TreeSelect;
|
||||
import com.engine.organization.entity.chart.*;
|
||||
import com.engine.organization.entity.chart.params.RecursionParam;
|
||||
import com.engine.organization.entity.chart.params.StatisticsParam;
|
||||
import com.engine.organization.enums.ModuleTypeEnum;
|
||||
import com.engine.organization.mapper.hrmresource.SystemDataMapper;
|
||||
import com.engine.organization.service.ChartService;
|
||||
import com.engine.organization.service.OrgChartService;
|
||||
import com.engine.organization.util.HasRightUtil;
|
||||
import com.engine.organization.util.OrganizationAssert;
|
||||
import com.engine.organization.util.OrganizationCommonUtil;
|
||||
import com.engine.organization.util.OrganizationDateUtil;
|
||||
import com.engine.organization.util.db.DBType;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.opensaml.saml2.metadata.Organization;
|
||||
import weaver.conn.RecordSet;
|
||||
import weaver.conn.RecordSetTrans;
|
||||
import weaver.general.Util;
|
||||
|
|
@ -27,7 +29,11 @@ import weaver.hrm.company.SubCompanyComInfo;
|
|||
import weaver.hrm.resource.ResourceComInfo;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
|
@ -557,6 +563,196 @@ public class ChartServiceImpl extends Service implements ChartService {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> recordStatistics(StatisticsParam statisticsParam) {
|
||||
Map<String, Object> result = new HashMap<>(2);
|
||||
long startTime = System.currentTimeMillis();
|
||||
//需要更新的数据List
|
||||
List<StatisticsPO> list = filterIds(statisticsParam.getCompanyId());
|
||||
RecordSetTrans rst = new RecordSetTrans();
|
||||
// 核心线程数
|
||||
int corePoolSize = 5;
|
||||
// 最大线程数
|
||||
int maxPoolSize = 10;
|
||||
// 设置每个子列表的大小
|
||||
int batchSize = 100;
|
||||
|
||||
List<List<StatisticsPO>> splittedLists = OrganizationCommonUtil.splitList(list, batchSize);
|
||||
// 创建线程池
|
||||
ExecutorService executorService = ThreadUtil.newExecutor(corePoolSize, maxPoolSize);
|
||||
|
||||
// 遍历每个子列表,并提交给线程池执行
|
||||
for (List<StatisticsPO> subList : splittedLists) {
|
||||
executorService.submit(() -> {
|
||||
// 在此处编写处理子列表的逻辑
|
||||
for (StatisticsPO statisticsPO : subList) {
|
||||
// 处理逻辑
|
||||
StatisticsPO po = buildCount(statisticsPO);
|
||||
statisticsPO.setOnJobNum(po.getOnJobNum());
|
||||
statisticsPO.setStaffNum(po.getStaffNum());
|
||||
statisticsPO.setUpdateTime(OrganizationDateUtil.getFormatLocalDateTime(LocalDateTime.now()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 关闭线程池
|
||||
executorService.shutdown();
|
||||
// 等待线程池关闭
|
||||
while (!executorService.isTerminated()) {
|
||||
// 空循环等待线程池终止
|
||||
}
|
||||
|
||||
try {
|
||||
rst.setAutoCommit(false);
|
||||
for (StatisticsPO item : list) {
|
||||
rst.executeUpdate("update jcl_org_onjob set on_job_num = ?,staff_num = ? where data_id = ? and type = ?",item.getOnJobNum(),
|
||||
item.getStaffNum(),item.getDataId(),item.getType());
|
||||
}
|
||||
|
||||
rst.commit();
|
||||
}catch (Exception e) {
|
||||
rst.rollback();
|
||||
}
|
||||
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
long executionTime = endTime - startTime;
|
||||
result.put("time",executionTime);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成人数
|
||||
* @param stp
|
||||
* @return
|
||||
*/
|
||||
private StatisticsPO buildCount(StatisticsPO stp) {
|
||||
RecordSet rs = new RecordSet();
|
||||
DepartmentComInfo dept = new DepartmentComInfo();
|
||||
SubCompanyComInfo subCompany = new SubCompanyComInfo();
|
||||
ArrayList<Integer> list = new ArrayList<>();
|
||||
list.add(stp.getDataId());
|
||||
StringBuilder jobSql = new StringBuilder();
|
||||
StringBuilder staffSql = new StringBuilder();
|
||||
|
||||
if (ModuleTypeEnum.subcompanyfielddefined.getValue().equals(stp.getType())) {
|
||||
subCompany.getSubCompanyLists(String.valueOf(stp.getDataId()), list);
|
||||
String value = StringUtils.join(list,",");
|
||||
jobSql.append("select count(1) as count from hrmresource where status < 4 and subcompanyid1 in (").append(value).append(")");
|
||||
staffSql.append("select a.staff_num from jcl_org_staff a inner join jcl_org_staffplan b\n" +
|
||||
" on a.plan_id = b.id\n" +
|
||||
" and a.ec_company = ? and a.ec_department is null\n" +
|
||||
" and b.plan_year = ?");
|
||||
}else {
|
||||
dept.getAllChildDeptByDepId(list,String.valueOf(stp.getDataId()));
|
||||
String value = StringUtils.join(list,",");
|
||||
jobSql.append("select count(1) as count from hrmresource where status < 4 and departmentid in (").append(value).append(")");
|
||||
staffSql.append("select a.staff_num from jcl_org_staff a inner join jcl_org_staffplan b\n" +
|
||||
" on a.plan_id = b.id\n" +
|
||||
" and a.ec_department = ? and a.job_id is null\n" +
|
||||
" and b.plan_year = ?");
|
||||
}
|
||||
|
||||
rs.executeQuery(jobSql.toString());
|
||||
rs.next();
|
||||
stp.setOnJobNum(Util.getIntValue(rs.getString("count")));
|
||||
|
||||
rs.executeQuery(staffSql.toString(),stp.getDataId(),OrganizationDateUtil.getFormatYear(new Date()));
|
||||
if (rs.next()) {
|
||||
stp.setStaffNum(Util.getIntValue(rs.getString("staff_num")));
|
||||
}
|
||||
|
||||
return stp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 基础数据过滤
|
||||
* @param companyId
|
||||
* @return
|
||||
*/
|
||||
private List<StatisticsPO> filterIds (Integer companyId) {
|
||||
RecordSet rs = new RecordSet();
|
||||
RecordSet iRs = new RecordSet();
|
||||
List<Integer> hisCompanyList = new ArrayList<>();
|
||||
List<Integer> hisDepartmentList = new ArrayList<>();
|
||||
|
||||
rs.executeQuery("select data_id from jcl_org_onjob where type = 1");
|
||||
while (rs.next()) {
|
||||
hisCompanyList.add(Util.getIntValue(rs.getString("data_id")));
|
||||
}
|
||||
rs.executeQuery("select data_id from jcl_org_onjob where type = 2");
|
||||
while (rs.next()) {
|
||||
hisDepartmentList.add(Util.getIntValue(rs.getString("data_id")));
|
||||
}
|
||||
|
||||
List<StatisticsPO> companyList = new ArrayList<>();
|
||||
List<StatisticsPO> departmentList = new ArrayList<>();
|
||||
StringBuilder sql = new StringBuilder();
|
||||
StringBuilder sql1 = new StringBuilder();
|
||||
sql.append("select id,supsubcomid from hrmsubcompany where 1=1");
|
||||
sql1.append("select id,supdepid from hrmdepartment where 1=1");
|
||||
if (companyId != null) {
|
||||
sql.append(" and id = ").append(companyId);
|
||||
sql1.append(" and subcompanyid1 = ").append(companyId);
|
||||
}
|
||||
|
||||
rs.executeQuery(sql.toString());
|
||||
while (rs.next()) {
|
||||
|
||||
StatisticsPO statisticsPO = StatisticsPO.builder()
|
||||
.dataId(Util.getIntValue(rs.getString("id")))
|
||||
.superId(Util.getIntValue(rs.getString("supsubcomid")))
|
||||
.type(1)
|
||||
.onJobNum(0)
|
||||
.staffNum(0)
|
||||
.creator(user.getUID())
|
||||
.createTime(OrganizationDateUtil.getFormatLocalDateTime(LocalDateTime.now()))
|
||||
.updateTime(OrganizationDateUtil.getFormatLocalDateTime(LocalDateTime.now()))
|
||||
.build();
|
||||
companyList.add(statisticsPO);
|
||||
}
|
||||
|
||||
rs.executeQuery(sql1.toString());
|
||||
while (rs.next()) {
|
||||
StatisticsPO statisticsPO = StatisticsPO.builder()
|
||||
.dataId(Util.getIntValue(rs.getString("id")))
|
||||
.superId(Util.getIntValue(rs.getString("supdepid")))
|
||||
.type(2)
|
||||
.onJobNum(0)
|
||||
.staffNum(0)
|
||||
.creator(user.getUID())
|
||||
.createTime(OrganizationDateUtil.getFormatLocalDateTime(LocalDateTime.now()))
|
||||
.updateTime(OrganizationDateUtil.getFormatLocalDateTime(LocalDateTime.now()))
|
||||
.build();
|
||||
departmentList.add(statisticsPO);
|
||||
|
||||
}
|
||||
|
||||
List<StatisticsPO> addCompanyList = companyList.stream()
|
||||
.filter(entity -> !hisCompanyList.contains(entity.getDataId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
List<StatisticsPO> addDeptList = departmentList.stream()
|
||||
.filter(entity -> !hisDepartmentList.contains(entity.getDataId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
addCompanyList.addAll(addDeptList);
|
||||
|
||||
|
||||
if (CollectionUtils.isNotEmpty(addCompanyList)) {
|
||||
addCompanyList.forEach(item -> iRs.executeUpdate("insert into jcl_org_onjob(data_id,super_id,type,on_job_num,staff_num,creator,create_time,update_time)" +
|
||||
" values(?,?,?,?,?,?,?,?)",item.getDataId(),item.getSuperId(),item.getType(),
|
||||
item.getOnJobNum(),item.getStaffNum(),item.getCreator(),item.getCreateTime(),item.getUpdateTime()));
|
||||
}
|
||||
|
||||
companyList.addAll(departmentList);
|
||||
return companyList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加树结构所有上级节点
|
||||
*
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
package com.engine.organization.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author liang.cheng
|
||||
* @Date 2023/9/13 2:46 PM
|
||||
* @Description: 通用
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class OrganizationCommonUtil {
|
||||
|
||||
|
||||
/**
|
||||
* @Description: 集合分割
|
||||
* @Author: liang.cheng
|
||||
* @Date: 2023/9/13 2:46 PM
|
||||
* @param: [list, batchSize]
|
||||
* @return: java.util.List<java.util.List<T>>
|
||||
*/
|
||||
public static <T> List<List<T>> splitList(List<T> list, int batchSize) {
|
||||
List<List<T>> splittedLists = new ArrayList<>();
|
||||
for (int i = 0; i < list.size(); i += batchSize) {
|
||||
int endIndex = Math.min(i + batchSize, list.size());
|
||||
List<T> subList = list.subList(i, endIndex);
|
||||
splittedLists.add(subList);
|
||||
}
|
||||
return splittedLists;
|
||||
}
|
||||
}
|
||||
|
|
@ -32,6 +32,8 @@ public class OrganizationDateUtil {
|
|||
public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static final String MONTH_FORMATTER_PATTERN = "yyyy-MM";
|
||||
public static final String FORMYEAR_PATTERN = "yyyy";
|
||||
|
||||
public static final String DATE_FORMATTER_PATTERN = "yyyy-MM-dd";
|
||||
public static final String DATE_TIME_FORMATTER_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
||||
/**
|
||||
|
|
@ -80,6 +82,19 @@ public class OrganizationDateUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getFormatYear(Date localDate) {
|
||||
if (localDate == null) {
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
try {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(FORMYEAR_PATTERN);
|
||||
return simpleDateFormat.format(localDate);
|
||||
} catch (Exception e) {
|
||||
log.warn("格式化年份错误", e);
|
||||
return StringUtils.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getFormatYearMonth(Date localDate) {
|
||||
if (localDate == null) {
|
||||
|
|
|
|||
|
|
@ -3,14 +3,17 @@ package com.engine.organization.web;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.engine.common.util.ParamUtil;
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.organization.entity.chart.params.StatisticsParam;
|
||||
import com.engine.organization.util.response.ReturnResult;
|
||||
import com.engine.organization.wrapper.OrgChartWrapper;
|
||||
import io.swagger.v3.oas.annotations.parameters.RequestBody;
|
||||
import weaver.hrm.HrmUserVarify;
|
||||
import weaver.hrm.User;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
|
|
@ -302,4 +305,18 @@ public class OrgChartController {
|
|||
}
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/recordStatistics")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public ReturnResult recordStatistics(@Context HttpServletRequest request, @Context HttpServletResponse response, @RequestBody StatisticsParam statisticsParam) {
|
||||
try {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
return ReturnResult.successed(getOrgChartWrapper(user).recordStatistics(statisticsParam));
|
||||
} catch (Exception e) {
|
||||
return ReturnResult.exceptionHandle(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.engine.organization.wrapper;
|
|||
|
||||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.organization.entity.chart.params.StatisticsParam;
|
||||
import com.engine.organization.service.ChartService;
|
||||
import com.engine.organization.service.OrgChartService;
|
||||
import com.engine.organization.service.impl.ChartServiceImpl;
|
||||
|
|
@ -84,4 +85,8 @@ public class OrgChartWrapper extends Service {
|
|||
public Map<String, Object> selectStatistics(Map<String, Object> request2Map) {
|
||||
return getChartService(user).selectStatistics(request2Map);
|
||||
}
|
||||
|
||||
public Map<String, Object> recordStatistics(StatisticsParam param) {
|
||||
return getChartService(user).recordStatistics(param);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue