出勤分析整体性能优化
parent
de6f550356
commit
ec483e255d
@ -0,0 +1,47 @@
|
||||
package com.engine.jucailinkq.attendance.attendanceplan.cmd;
|
||||
|
||||
import com.engine.common.biz.AbstractCommonCommand;
|
||||
import com.engine.common.entity.BizLogContext;
|
||||
import com.engine.core.interceptor.CommandContext;
|
||||
import com.engine.jucailinkq.attendance.enums.CheckBoxEnum;
|
||||
import com.engine.jucailinkq.common.util.DbTools;
|
||||
import com.google.common.collect.Maps;
|
||||
import weaver.general.Util;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class GetAttendanceItemsGroupByAttendancePlanDataCmd extends AbstractCommonCommand<Map<String,Object>> {
|
||||
@Override
|
||||
public BizLogContext getLogContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execute(CommandContext commandContext) {
|
||||
|
||||
Map<String,Object> resultMap = Maps.newHashMap();
|
||||
String sql = "select c.id planid,b.id keyid,b.mc kqxm,c.mc famc,b.* from uf_jcl_kq_kqfa_dt1 a left join uf_jcl_kq_kqxm b on a.kqxm=b.id left join uf_jcl_kq_kqfa c on a.mainid=c.id";
|
||||
List<Map<String,Object>> attendanceItems = DbTools.getSqlToList(sql);
|
||||
List<String> fatherItems = attendanceItems.stream().filter(e-> Util.null2String(e.get("sffzcx")).equals(CheckBoxEnum.CHECKED.getKey())).map(e->e.get("keyid").toString()).collect(Collectors.toList());
|
||||
if (fatherItems.size() > 0){
|
||||
sql = "select id keyid,mc kqxm,a.* from uf_jcl_kq_kqxm a where (xmzt is null or xmzt <> '0') and a.sjxm in ("+String.join(",",fatherItems)+")";
|
||||
List<Map<String,Object>> sonItemList = DbTools.getSqlToList(sql);
|
||||
Map<String,List<Map<String,Object>>> sonGroupMap = sonItemList.stream().collect(Collectors.groupingBy(e->e.get("sjxm").toString()));
|
||||
for (Map<String,Object> attendanceItem :attendanceItems){
|
||||
if (CheckBoxEnum.CHECKED.getKey().equals(attendanceItem.get("sffzcx"))){
|
||||
attendanceItem.put("sonItems",sonGroupMap.get(attendanceItem.get("keyid")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sql = "select id keyid,mc kqxm,a.* from uf_jcl_kq_kqxm a where tyxm=1 and (xmzt is null or xmzt <> '0')";
|
||||
List<Map<String,Object>> generalAttendanceItems = DbTools.getSqlToList(sql);
|
||||
Map<String,List<Map<String,Object>>> attendanceItemGroupByPlan = attendanceItems.stream().collect(Collectors.groupingBy(e->e.get("planid").toString()));
|
||||
resultMap.put("generalAttendanceItems",generalAttendanceItems);
|
||||
resultMap.put("attendanceItemGroupByPlan",attendanceItemGroupByPlan);
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
package com.engine.jucailinkq.attendance.component.persongroup.cmd;
|
||||
|
||||
import com.engine.common.biz.AbstractCommonCommand;
|
||||
import com.engine.common.entity.BizLogContext;
|
||||
import com.engine.core.interceptor.CommandContext;
|
||||
import com.engine.jucailinkq.attendance.component.persongroup.commonutil.PersongroupCommonUtil;
|
||||
import com.engine.jucailinkq.attendance.enums.CheckBoxEnum;
|
||||
import com.engine.jucailinkq.attendance.enums.SchedulingApproachEnum;
|
||||
import com.engine.jucailinkq.common.util.DateUtil;
|
||||
import com.engine.jucailinkq.common.util.DbTools;
|
||||
import com.engine.jucailinkq.common.util.ExtensionClassHolder;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import weaver.general.Util;
|
||||
import weaver.hrm.company.DepartmentComInfo;
|
||||
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 当递归查询时获得表格数据
|
||||
*/
|
||||
@Slf4j
|
||||
public class GetScheduleFoAnalysisCmd extends AbstractCommonCommand<Map<String, Object>> {
|
||||
|
||||
@Override
|
||||
public BizLogContext getLogContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public GetScheduleFoAnalysisCmd(Map<String, Object> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> execute(CommandContext commandContext) {
|
||||
String startDate = Util.null2String(params.get("startDate"));
|
||||
String endDate = Util.null2String(params.get("endDate"));
|
||||
String pbdx = Util.null2String(params.get("pbdx"));
|
||||
List<Map<String,Object>> allScheduleList = (List<Map<String,Object>>)params.get("allScheduleList");
|
||||
|
||||
Map<String, Object> resultMap = Maps.newHashMap();
|
||||
List<Map<String, Object>> dataTableList = Lists.newArrayList();
|
||||
|
||||
try {
|
||||
//人员递归查人员、人员分组、部门、分部
|
||||
|
||||
List<Map<String, Object>> dataList = allScheduleList.stream().filter(e->pbdx.equals(e.get("pbdxry")) &&
|
||||
DateUtil.getTime(e.get("bcrq").toString()).compareTo(DateUtil.getTime(startDate))>=0 &&
|
||||
DateUtil.getTime(e.get("bcrq").toString()).compareTo(DateUtil.getTime(endDate))<=0).collect(Collectors.toList());
|
||||
//人员数据
|
||||
|
||||
//人员分组数据
|
||||
List<Map<String, Object>> personGroupList = Lists.newArrayList();
|
||||
Map<String, List<Map<String, Object>>> personBelongGroup = ExtensionClassHolder.getPersonBelongGroupThreadLocal();
|
||||
//查人员分组
|
||||
List<Map<String, Object>> personnelGroups = personBelongGroup.get(pbdx) == null ? Lists.newArrayList() : personBelongGroup.get(pbdx);
|
||||
Map<String, List<Map<String, Object>>> personnelGroupsCollect = personnelGroups.stream().collect(Collectors.groupingBy(e -> e.get("mainid").toString()));
|
||||
Set<String> personnelGroupIds = personnelGroups.stream().map(e -> e.get("mainid").toString()).collect(Collectors.toSet());
|
||||
|
||||
if (personnelGroupIds.size() > 0) {
|
||||
personGroupList = allScheduleList.stream().filter(e->personnelGroupIds.contains(e.get("pbdxryfz")) &&
|
||||
DateUtil.getTime(e.get("bcrq").toString()).compareTo(DateUtil.getTime(startDate))>=0 &&
|
||||
DateUtil.getTime(e.get("bcrq").toString()).compareTo(DateUtil.getTime(endDate))<=0).collect(Collectors.toList());
|
||||
}
|
||||
personGroupList = personGroupList.stream().filter(e -> {
|
||||
String bcrq = e.get("bcrq").toString();
|
||||
String pbdxryfz = e.get("pbdxryfz").toString();
|
||||
Map<String, Object> personnelGroup = personnelGroupsCollect.get(pbdxryfz).get(personnelGroupsCollect.get(pbdxryfz).size() - 1);
|
||||
String edate = Util.null2String(personnelGroup.get("edate"));
|
||||
String bdate = Util.null2String(personnelGroup.get("bdate"));
|
||||
e.put("bdate", bdate);
|
||||
if ((!"".equals(bdate) && DateUtil.getTime(bcrq).compareTo(DateUtil.getTime(bdate)) < 0) ||
|
||||
(!"".equals(edate) && DateUtil.getTime(bcrq).compareTo(DateUtil.getTime(edate)) > 0)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
|
||||
//部门数据
|
||||
List<Map<String, Object>> departmentList = Lists.newArrayList();
|
||||
//查询部门数据
|
||||
Map<String, Map<String, Object>> personInformationThreadLocal = ExtensionClassHolder.getPersonInformationThreadLocal();
|
||||
Map<String, Object> personInformationMap = personInformationThreadLocal.get(pbdx);
|
||||
String pdeptids = Util.null2String(personInformationMap.get("pdeptids"));
|
||||
String subcompanyid1 = Util.null2String(personInformationMap.get("subcompanyid1"));
|
||||
List<String> pdeptidList = Lists.newArrayList(pdeptids.split(","));
|
||||
List<String> subcompanyList = Lists.newArrayList(subcompanyid1.split(","));
|
||||
|
||||
departmentList = allScheduleList.stream().filter(e->pdeptidList.contains(e.get("pbdxbm")) &&
|
||||
DateUtil.getTime(e.get("bcrq").toString()).compareTo(DateUtil.getTime(startDate))>=0 &&
|
||||
DateUtil.getTime(e.get("bcrq").toString()).compareTo(DateUtil.getTime(endDate))<=0).collect(Collectors.toList());
|
||||
|
||||
//分部数据
|
||||
List<Map<String, Object>> subCompanyList = Lists.newArrayList();
|
||||
//查询人员分部
|
||||
|
||||
subCompanyList = allScheduleList.stream().filter(e->subcompanyList.contains(e.get("pbdxfb")) &&
|
||||
DateUtil.getTime(e.get("bcrq").toString()).compareTo(DateUtil.getTime(startDate))>=0 &&
|
||||
DateUtil.getTime(e.get("bcrq").toString()).compareTo(DateUtil.getTime(endDate))<=0).collect(Collectors.toList());
|
||||
|
||||
//排班途径枚举集合
|
||||
dataList.addAll(personGroupList);
|
||||
dataList.addAll(departmentList);
|
||||
dataList.addAll(subCompanyList);
|
||||
|
||||
Map<String, List<Map<String, Object>>> dataCollect = dataList.stream().collect(Collectors.groupingBy(e -> e.get("pbtj").toString()));
|
||||
for (SchedulingApproachEnum schedulingApproachEnum : SchedulingApproachEnum.values()) {
|
||||
List<Map<String, Object>> resulstList = dataCollect.get(schedulingApproachEnum.getKey());
|
||||
if (resulstList == null || resulstList.size() == 0) {
|
||||
continue;
|
||||
}
|
||||
Map<String, List<Map<String, Object>>> resulstCollect = resulstList.stream().collect(Collectors.groupingBy(e -> Util.null2String(e.get("bcrq"))));
|
||||
for (Map.Entry<String, List<Map<String, Object>>> entry : resulstCollect.entrySet()) {
|
||||
String bcrq = entry.getKey();
|
||||
List<Map<String, Object>> scheduleList = entry.getValue();
|
||||
if (scheduleList.size() > 1) {
|
||||
//优先级。人员 》人员分组》部门》分部
|
||||
List<Map<String, Object>> psersonList = scheduleList.stream().filter(e -> !Util.null2String(e.get("pbdxry")).equals("")).collect(Collectors.toList());
|
||||
if (psersonList.size() == 0) {
|
||||
psersonList = scheduleList.stream().filter(e -> !Util.null2String(e.get("pbdxryfz")).equals("")).collect(Collectors.toList());
|
||||
if (psersonList.size() > 1) {
|
||||
psersonList = psersonList.stream().sorted(Comparator.comparing(e -> DateUtil.getTime(e.get("bdate").toString()).toInstant(ZoneOffset.of("+8")).toEpochMilli())).collect(Collectors.toList());
|
||||
psersonList = Lists.newArrayList(psersonList.get(psersonList.size() - 1));
|
||||
}
|
||||
}
|
||||
if (psersonList.size() == 0) {
|
||||
psersonList = scheduleList.stream().filter(e -> !Util.null2String(e.get("pbdxbm")).equals("")).collect(Collectors.toList());
|
||||
}
|
||||
if (psersonList.size() == 0) {
|
||||
psersonList = scheduleList.stream().filter(e -> !Util.null2String(e.get("pbdxfb")).equals("")).collect(Collectors.toList());
|
||||
}
|
||||
if (psersonList.size() > 0) {
|
||||
if (schedulingApproachEnum == SchedulingApproachEnum.RULE) {
|
||||
psersonList = psersonList.stream().sorted(Comparator.comparing(e -> Long.valueOf(e.get("pbgl").toString()))).collect(Collectors.toList());
|
||||
} else {
|
||||
psersonList = psersonList.stream().sorted(Comparator.comparing(e -> Long.valueOf(e.get("keyid").toString()))).collect(Collectors.toList());
|
||||
}
|
||||
dataTableList.add(psersonList.get(psersonList.size() - 1));
|
||||
}
|
||||
} else {
|
||||
dataTableList.add(scheduleList.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("catch error : {}", e);
|
||||
}
|
||||
resultMap.put("dataTableList", dataTableList);
|
||||
log.debug("dataTableList total size : {}", dataTableList.size());
|
||||
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue