|
|
|
@ -0,0 +1,327 @@
|
|
|
|
|
package com.engine.jucailinkq.attendance.attendanceanalysis.wrapper;
|
|
|
|
|
|
|
|
|
|
import com.engine.common.util.ServiceUtil;
|
|
|
|
|
import com.engine.core.impl.Service;
|
|
|
|
|
import com.engine.jucailinkq.attendance.attendanceplan.service.AttendancePlanService;
|
|
|
|
|
import com.engine.jucailinkq.attendance.attendanceplan.service.impl.AttendancePlanServiceImpl;
|
|
|
|
|
import com.engine.jucailinkq.attendance.workflow.service.AllowanceService;
|
|
|
|
|
import com.engine.jucailinkq.attendance.workflow.service.impl.AllowanceServiceImpl;
|
|
|
|
|
import com.engine.jucailinkq.common.exception.AttendanceRunTimeException;
|
|
|
|
|
import com.engine.jucailinkq.common.service.CommonService;
|
|
|
|
|
import com.engine.jucailinkq.common.service.impl.CommonServiceImpl;
|
|
|
|
|
import com.engine.jucailinkq.common.util.*;
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import weaver.general.Util;
|
|
|
|
|
|
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class AttendaceActionWrapper extends Service {
|
|
|
|
|
private CommonService commonService = ServiceUtil.getService(CommonServiceImpl.class);
|
|
|
|
|
private AttendancePlanService basicsetService = ServiceUtil.getService(AttendancePlanServiceImpl.class);
|
|
|
|
|
private AttendanceAnalysisWrapper attendanceAnalysisService = ServiceUtil.getService(AttendanceAnalysisWrapper.class);
|
|
|
|
|
private AllowanceService allowanceService = ServiceUtil.getService(AllowanceServiceImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String,Object> alysisActionWrapper(Map<String,Object> paramMap){
|
|
|
|
|
Map<String,Object> resultMap = Maps.newHashMap();
|
|
|
|
|
try {
|
|
|
|
|
log.info("********AttendanceanalysisAction start********");
|
|
|
|
|
|
|
|
|
|
String startDate = Util.null2String(paramMap.get("startDate"));
|
|
|
|
|
String startBeforeDate = DateUtil.beforeDay(startDate,2);
|
|
|
|
|
String endDate = Util.null2String(paramMap.get("endDate"));
|
|
|
|
|
String endAfterDate = DateUtil.AfterDay(endDate,2);
|
|
|
|
|
String userIds = Util.null2String(paramMap.get("userIds"));
|
|
|
|
|
int betweenDays = DateUtil.getBetWeenDays(startDate,endDate);
|
|
|
|
|
|
|
|
|
|
log.info("userIds : [{}],startDate:[{}],endDate:[{}]",userIds,startDate,endDate);
|
|
|
|
|
//初始化扩展类
|
|
|
|
|
CommonUtil.initExtensionClassHolder();
|
|
|
|
|
//入职离职当天是否需要进行考勤分析。0:入职离职当天均分析、1:入职离职当天不分析
|
|
|
|
|
String leaveAndEntry = Util.null2String(ExtensionClassHolder.getGlobalSetMap().get("leaveAndEntry"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**考勤项目*/
|
|
|
|
|
Map<String,Object> params = Maps.newHashMap();
|
|
|
|
|
String modeId = Utils.getFormmodeIdMap().get("uf_jcl_kq_kqfa");
|
|
|
|
|
params.put("modeId",modeId);
|
|
|
|
|
Map<String,Object> attendancePlanMap = commonService.GetAllPersonBySuitOrganzationCmd(params);
|
|
|
|
|
Map<String,Object> attendacnePlanItems = basicsetService.getAttendanceItemsGroupByAttendancePlanDataCmd();
|
|
|
|
|
//人员所拥有的所有考勤方案
|
|
|
|
|
//通用考勤项目
|
|
|
|
|
List<Map<String,Object>> generalAttendanceItems = (List<Map<String,Object>>)attendacnePlanItems.get("generalAttendanceItems");
|
|
|
|
|
//考勤方案对应所属的考勤项目
|
|
|
|
|
Map<String,List<Map<String,Object>>> attendanceItemGroupByPlan = (Map<String,List<Map<String,Object>>>)attendacnePlanItems.get("attendanceItemGroupByPlan");
|
|
|
|
|
|
|
|
|
|
/**综合工时*/
|
|
|
|
|
modeId = Utils.getFormmodeIdMap().get("uf_jcl_kq_zhgs");
|
|
|
|
|
params.put("modeId",modeId);
|
|
|
|
|
Map<String,Object> workingHourResultMap = commonService.getPersonBySuitOrganzation(params);
|
|
|
|
|
//人员所拥有的所有综合工时
|
|
|
|
|
Map<String,List<Map<String,String>>> personComprehensiveWorkingHours = (Map<String,List<Map<String,String>>>)workingHourResultMap.get("personAllData");
|
|
|
|
|
String queysql = "select * from uf_jcl_kq_zhgs";
|
|
|
|
|
List<Map<String,Object>> resultList = DbTools.getSqlToList(queysql);
|
|
|
|
|
//所有综合工时
|
|
|
|
|
Map<String,List<Map<String,Object>>> workingHourGroupBy = resultList.stream().collect(Collectors.groupingBy(e->e.get("id").toString()));
|
|
|
|
|
CommonUtil.checkHavePermission();
|
|
|
|
|
if ("".equals(userIds)){
|
|
|
|
|
log.info("********AttendanceanalysisAction prepare start******");
|
|
|
|
|
String queryDepartEmployeeSql = "select resourceid ,changedate,type_n from HRMSTATUSHISTORY where changedate is not null";
|
|
|
|
|
//获取离职日期
|
|
|
|
|
List<Map<String,Object>> departEmployeeList = DbTools.getSqlToList(queryDepartEmployeeSql);
|
|
|
|
|
Map<String,Object> departEmployeeMap = CommonUtil.getDepartEmployeeMap(departEmployeeList);
|
|
|
|
|
|
|
|
|
|
/**排班结果*/
|
|
|
|
|
String querySchedulesql = "select a.id as keyid,a.* from uf_pbjg a where bcrq >=? and bcrq<=? order by bcrq";
|
|
|
|
|
List<Map<String,Object>> allScheduleList = DbTools.getSqlToList(querySchedulesql,startDate,endDate);
|
|
|
|
|
/**加班计划*/
|
|
|
|
|
String queryOverplansql = "select a.id,b.jbry,b.ksrq,b.kssj,b.jblx,b.jsrq,b.jssj,b.jbsc,b.gsrq,b.d_jxgz,b.jxsc from uf_jcl_kq_jbjh a left join uf_jcl_kq_jbjh_dt1 b on a.id=b.mainid where b.gsrq >=? and b.gsrq<=? and (b.jbcx=0 or b.jbcx is null) and a.jlzt=1";
|
|
|
|
|
List<Map<String,Object>> allOverPlanList = DbTools.getSqlToList(queryOverplansql,startDate,endDate);
|
|
|
|
|
Map<String,List<Map<String,Object>>> allOverPlanGroup = allOverPlanList.stream().collect(Collectors.groupingBy(e->e.get("jbry").toString()));
|
|
|
|
|
/**班次信息*/
|
|
|
|
|
String querClasssql = "select a.xxbdkzdjb,a.sfxx,a.id bcxx,a.edsc,a.zgzsc,a.bcsdxx,a.sfdx,a.sfkt,b.bdlx,a.btgz,a.fgsjd,a.zddxfz,a.dxhs,b.kssj dtkssj,b.jssj dtjssj,b.ksdk,b.jsdk,b.tqdkfzs,b.thdkfzs,b.edxss,b.edfzs,b.edts,b.sfdx dtsfdx,b.zddxfz dtzddxfz,b.dxhs dtdxhs,b.gsrq from uf_jcl_kq_bcxx a left join uf_jcl_kq_bcxx_dt1 b on a.id=b.mainid";
|
|
|
|
|
List<Map<String,Object>> allClassInfoList = DbTools.getSqlToList(querClasssql);
|
|
|
|
|
/**出差信息*/
|
|
|
|
|
String querEvectionsql = "select b.ccr,b.cclx,b.ksrq,b.jsrq,b.kssj,b.jssj,b.ccsc,b.qtcc,b.btcc,b.cxcc from uf_jcl_kq_ccjl a left join uf_jcl_kq_ccjl_dt1 b on a.id = b.mainid where b.ksrq<=? and b.jsrq>=? and (b.cxcc=0 or b.cxcc is null) and a.jlzt=1";
|
|
|
|
|
Map<String,List<Map<String,Object>>> evectionGroup = DbTools.getSqlToList(querEvectionsql,endAfterDate,startBeforeDate).stream().collect(Collectors.groupingBy(e->e.get("ccr").toString()));
|
|
|
|
|
/**请假信息*/
|
|
|
|
|
String queryAskForsql = "select b.qjry,b.jqlx,b.ksrq,b.kssj,b.jsrq,b.jssj,b.qjsc,b.qtj,b.btj from uf_jcl_kq_qjjl a left join uf_jcl_kq_qjjl_dt1 b on a.id = b.mainid where b.ksrq<=? and b.jsrq>=? and (b.cxqj=0 or b.cxqj is null) and a.jlzt=1";
|
|
|
|
|
Map<String,List<Map<String,Object>>> askforGroup = DbTools.getSqlToList(queryAskForsql,endAfterDate,startBeforeDate).stream().collect(Collectors.groupingBy(e->e.get("qjry").toString()));
|
|
|
|
|
/**候选班组*/
|
|
|
|
|
String queryHxbz = "select * from uf_jcl_kq_hxbz_dt1";
|
|
|
|
|
List<Map<String,Object>> hxbzList = DbTools.getSqlToList(queryHxbz);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String queryUserSql = "select id,companystartdate,seclevel,departmentid,subcompanyid1 from hrmresource where status <> '5' and status <> '4' and status <> '7'";
|
|
|
|
|
List<Map<String,Object>> userList = DbTools.getSqlToList(queryUserSql);
|
|
|
|
|
String sql = "select id,userid,signdate,signtime from hrmschedulesign where isincom=1 and signdate >= ? and signdate <= ? order by signdate,signtime";
|
|
|
|
|
List<Map<String,Object>> dataList = DbTools.getSqlToList(sql,startBeforeDate,endAfterDate);
|
|
|
|
|
//补打卡记录
|
|
|
|
|
sql = "select id,bdkry userid,dkrq signdate,dksj signtime from uf_jcl_kq_bdkjl where dkrq >= ? and dkrq <= ? and jlzt=1 order by dkrq,dksj";
|
|
|
|
|
List<Map<String,Object>> makeUpList = DbTools.getSqlToList(sql,startBeforeDate,endAfterDate);
|
|
|
|
|
if (makeUpList.size() > 0){
|
|
|
|
|
dataList.addAll(makeUpList);
|
|
|
|
|
}
|
|
|
|
|
dataList = dataList.stream().sorted(Comparator.comparing(e->DateUtil.getTime(e.get("signdate")+" "+e.get("signtime")).toInstant(ZoneOffset.of("+8")).toEpochMilli())).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
Map<String, List<Map<String,Object>>> collect = dataList.stream().collect(Collectors.groupingBy(e -> Util.null2String(e.get("userid"))));
|
|
|
|
|
sql = "select sjzt,sgsj,ygid,bc,fbid,bm,rq,j1,c1,j2,c2,j3,c3,j4,c4,j5,c5,j6,c6,j7,c7,j8,c8 from uf_jcl_kq_cqjg where rq>=? and rq<=?";
|
|
|
|
|
List<Map<String,Object>> attendaceResult = DbTools.getSqlToList(sql,startBeforeDate,endAfterDate);
|
|
|
|
|
Map<String,List<Map<String,Object>>> attendaceGroupById = attendaceResult.stream().collect(Collectors.groupingBy(e->e.get("ygid").toString()));
|
|
|
|
|
|
|
|
|
|
log.info("********AttendanceanalysisAction prepare end******");
|
|
|
|
|
int anyslsSize = 0;
|
|
|
|
|
for (Map<String,Object> userMap :userList){
|
|
|
|
|
anyslsSize++;
|
|
|
|
|
String userId = userMap.get("id").toString();
|
|
|
|
|
//入职日期
|
|
|
|
|
String companystartDate = Util.null2String(userMap.get("companystartdate"));
|
|
|
|
|
//离职日期
|
|
|
|
|
String terminationDate = Util.null2String(departEmployeeMap.get(userId));
|
|
|
|
|
if (!"".equals(terminationDate) && DateUtil.getTime(terminationDate).compareTo(DateUtil.getTime(companystartDate)) <=0){
|
|
|
|
|
terminationDate="";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log.info("***********analysis userId:{},anyslsSize:{},allsize:{} start***********", userId,anyslsSize,userList.size());
|
|
|
|
|
//出勤结果,进出时间
|
|
|
|
|
Map<String,Map<String,Object>> clockInTimeMap = Maps.newHashMap();
|
|
|
|
|
|
|
|
|
|
Map<String, List<Map<String, Object>>> attendaceResultMap = Maps.newHashMap();
|
|
|
|
|
if (attendaceGroupById.get(userId) != null && attendaceGroupById.get(userId).size() > 0) {
|
|
|
|
|
attendaceResultMap = attendaceGroupById.get(userId).stream().collect(Collectors.groupingBy(e -> e.get("rq").toString()));
|
|
|
|
|
for (Map<String, Object> map: attendaceGroupById.get(userId)){
|
|
|
|
|
clockInTimeMap.put(map.get("rq").toString(),map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String,Object> analysisParam = Maps.newHashMap();
|
|
|
|
|
analysisParam.put("generalAttendanceItems",generalAttendanceItems);
|
|
|
|
|
analysisParam.put("attendancePlanMap",attendancePlanMap);
|
|
|
|
|
analysisParam.put("attendanceItemGroupByPlan",attendanceItemGroupByPlan);
|
|
|
|
|
analysisParam.put("comprehensiveWorkingHourList",personComprehensiveWorkingHours.get(userId)==null? Lists.newArrayList():personComprehensiveWorkingHours.get(userId));
|
|
|
|
|
analysisParam.put("workingHourGroupBy",workingHourGroupBy);
|
|
|
|
|
analysisParam.put("allScheduleList",allScheduleList);
|
|
|
|
|
analysisParam.put("allClassInfoList",allClassInfoList);
|
|
|
|
|
analysisParam.put("allOverPlanList",allOverPlanGroup.get(userId)==null?Lists.newArrayList():allOverPlanGroup.get(userId));
|
|
|
|
|
analysisParam.put("evectionList",evectionGroup.get(userId)==null?Lists.newArrayList():evectionGroup.get(userId));
|
|
|
|
|
analysisParam.put("askforList",askforGroup.get(userId)==null?Lists.newArrayList():askforGroup.get(userId));
|
|
|
|
|
analysisParam.put("hxbzList",hxbzList);
|
|
|
|
|
analysisParam.put("seclevel",Util.null2String(userMap.get("seclevel")));
|
|
|
|
|
analysisParam.put("departmentId",Util.null2String(userMap.get("departmentid")));
|
|
|
|
|
analysisParam.put("subCompanyId",Util.null2String(userMap.get("subcompanyid1")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<=betweenDays;i++){
|
|
|
|
|
String date = DateUtil.AfterDay(startDate,i);
|
|
|
|
|
if (leaveAndEntry.equals("1")){
|
|
|
|
|
if (("".equals(companystartDate) || DateUtil.getTime(date).compareTo(DateUtil.getTime(companystartDate))>0)
|
|
|
|
|
&& ("".equals(terminationDate) || DateUtil.getTime(date).compareTo(DateUtil.getTime(terminationDate)) <0)){
|
|
|
|
|
try {
|
|
|
|
|
attendanceAnalysisService.attendanceAnalysisForApi(userId,date,collect.get(userId),analysisParam,clockInTimeMap,attendaceResultMap);
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.info("***********analysis userId:{} date: {} error ***********", userId,date);
|
|
|
|
|
log.error("execute fail,catch error: [{}]",e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
if (("".equals(companystartDate) || DateUtil.getTime(date).compareTo(DateUtil.getTime(companystartDate))>=0)
|
|
|
|
|
&& ("".equals(terminationDate) || DateUtil.getTime(date).compareTo(DateUtil.getTime(terminationDate)) <=0)){
|
|
|
|
|
try {
|
|
|
|
|
attendanceAnalysisService.attendanceAnalysisForApi(userId,date,collect.get(userId),analysisParam,clockInTimeMap,attendaceResultMap);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.info("***********analysis userId:{} date: {} error ***********", userId,date);
|
|
|
|
|
log.error("execute fail,catch error: [{}]",e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
allowanceService.addAllowanceRecords(paramMap);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
log.info("********AttendanceanalysisAction prepare start******");
|
|
|
|
|
String queryDepartEmployeeSql = "select resourceid ,changedate,type_n from HRMSTATUSHISTORY where changedate is not null and resourceid in ("+userIds+")";
|
|
|
|
|
//获取离职日期
|
|
|
|
|
List<Map<String,Object>> departEmployeeList = DbTools.getSqlToList(queryDepartEmployeeSql);
|
|
|
|
|
Map<String,Object> departEmployeeMap = CommonUtil.getDepartEmployeeMap(departEmployeeList);
|
|
|
|
|
|
|
|
|
|
/**排班结果*/
|
|
|
|
|
String querySchedulesql = "select a.id as keyid,a.* from uf_pbjg a where bcrq >=? and bcrq<=? order by bcrq";
|
|
|
|
|
List<Map<String,Object>> allScheduleList = DbTools.getSqlToList(querySchedulesql,startBeforeDate,endAfterDate);
|
|
|
|
|
/**加班计划*/
|
|
|
|
|
String queryOverplansql = "select a.id,b.jbry,b.ksrq,b.kssj,b.jblx,b.jsrq,b.jssj,b.jbsc,b.gsrq,b.d_jxgz,b.jxsc from uf_jcl_kq_jbjh a left join uf_jcl_kq_jbjh_dt1 b on a.id=b.mainid where b.jbry in ("+userIds+") and b.gsrq >=? and b.gsrq<=? and (b.jbcx=0 or b.jbcx is null) and a.jlzt=1";
|
|
|
|
|
List<Map<String,Object>> allOverPlanList = DbTools.getSqlToList(queryOverplansql,startDate,endDate);
|
|
|
|
|
Map<String,List<Map<String,Object>>> allOverPlanGroup = allOverPlanList.stream().collect(Collectors.groupingBy(e->e.get("jbry").toString()));
|
|
|
|
|
/**班次信息*/
|
|
|
|
|
String querClasssql = "select a.xxbdkzdjb,a.sfxx,a.id bcxx,a.edsc,a.zgzsc,a.bcsdxx,a.sfdx,a.sfkt,b.bdlx,a.btgz,a.fgsjd,a.zddxfz,a.dxhs,b.kssj dtkssj,b.jssj dtjssj,b.ksdk,b.jsdk,b.tqdkfzs,b.thdkfzs,b.edxss,b.edfzs,b.edts,b.sfdx dtsfdx,b.zddxfz dtzddxfz,b.dxhs dtdxhs,b.gsrq from uf_jcl_kq_bcxx a left join uf_jcl_kq_bcxx_dt1 b on a.id=b.mainid";
|
|
|
|
|
List<Map<String,Object>> allClassInfoList = DbTools.getSqlToList(querClasssql);
|
|
|
|
|
/**出差信息*/
|
|
|
|
|
String querEvectionsql = "select b.ccr,b.cclx,b.ksrq,b.jsrq,b.kssj,b.jssj,b.ccsc,b.qtcc,b.btcc,b.cxcc from uf_jcl_kq_ccjl a left join uf_jcl_kq_ccjl_dt1 b on a.id = b.mainid where b.ccr in ("+userIds+") and b.ksrq<=? and b.jsrq>=? and (b.cxcc=0 or b.cxcc is null) and a.jlzt=1";
|
|
|
|
|
Map<String,List<Map<String,Object>>> evectionGroup = DbTools.getSqlToList(querEvectionsql,endAfterDate,startBeforeDate).stream().collect(Collectors.groupingBy(e->e.get("ccr").toString()));
|
|
|
|
|
/**请假信息*/
|
|
|
|
|
String queryAskForsql = "select b.qjry,b.jqlx,b.ksrq,b.kssj,b.jsrq,b.jssj,b.qjsc,b.qtj,b.btj from uf_jcl_kq_qjjl a left join uf_jcl_kq_qjjl_dt1 b on a.id = b.mainid where b.qjry in ("+userIds+") and b.ksrq<=? and b.jsrq>=? and (b.cxqj=0 or b.cxqj is null) and a.jlzt=1";
|
|
|
|
|
Map<String,List<Map<String,Object>>> askforGroup = DbTools.getSqlToList(queryAskForsql,endAfterDate,startBeforeDate).stream().collect(Collectors.groupingBy(e->e.get("qjry").toString()));
|
|
|
|
|
/**候选班组*/
|
|
|
|
|
String queryHxbz = "select * from uf_jcl_kq_hxbz_dt1";
|
|
|
|
|
List<Map<String,Object>> hxbzList = DbTools.getSqlToList(queryHxbz);
|
|
|
|
|
|
|
|
|
|
String sql = "select id,userid,signdate,signtime from hrmschedulesign where isincom=1 and userid in ("+userIds+") and signdate >= ? and signdate <= ? order by signdate,signtime";
|
|
|
|
|
List<Map<String,Object>> dataList = DbTools.getSqlToList(sql,startBeforeDate,endAfterDate);
|
|
|
|
|
|
|
|
|
|
String queryUserSql = "select id,companystartdate,seclevel,departmentid,subcompanyid1 from hrmresource where id in ("+userIds+")";
|
|
|
|
|
List<Map<String,Object>> userList = DbTools.getSqlToList(queryUserSql);
|
|
|
|
|
Map<String,List<Map<String,Object>>> userGroupMap = userList.stream().collect(Collectors.groupingBy(e->e.get("id").toString()));
|
|
|
|
|
|
|
|
|
|
//补打卡记录
|
|
|
|
|
sql = "select id,bdkry userid,dkrq signdate,dksj signtime from uf_jcl_kq_bdkjl where bdkry in ("+userIds+") and dkrq >= ? and dkrq <= ? and jlzt=1 order by dkrq,dksj";
|
|
|
|
|
List<Map<String,Object>> makeUpList = DbTools.getSqlToList(sql,startBeforeDate,endAfterDate);
|
|
|
|
|
if (makeUpList.size() > 0){
|
|
|
|
|
dataList.addAll(makeUpList);
|
|
|
|
|
}
|
|
|
|
|
dataList = dataList.stream().sorted(Comparator.comparing(e->DateUtil.getTime(e.get("signdate")+" "+e.get("signtime")).toInstant(ZoneOffset.of("+8")).toEpochMilli())).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, List<Map<String,Object>>> collect = dataList.stream().collect(Collectors.groupingBy(e -> Util.null2String(e.get("userid"))));
|
|
|
|
|
|
|
|
|
|
sql = "select sjzt,sgsj,ygid,bc,fbid,bm,rq,j1,c1,j2,c2,j3,c3,j4,c4,j5,c5,j6,c6,j7,c7,j8,c8 from uf_jcl_kq_cqjg where rq>=? and rq<=? and ygid in ("+userIds+")";
|
|
|
|
|
List<Map<String,Object>> attendaceResult = DbTools.getSqlToList(sql,startBeforeDate,endAfterDate);
|
|
|
|
|
Map<String,List<Map<String,Object>>> attendaceGroupById = attendaceResult.stream().collect(Collectors.groupingBy(e->e.get("ygid").toString()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.info("********AttendanceanalysisAction prepare end******");
|
|
|
|
|
for (String userId : userIds.split(",")){
|
|
|
|
|
//入职日期
|
|
|
|
|
String companystartDate = Util.null2String(userGroupMap.get(userId).get(0).get("companystartdate"));
|
|
|
|
|
//离职日期
|
|
|
|
|
String terminationDate = Util.null2String(departEmployeeMap.get(userId));
|
|
|
|
|
if (!"".equals(terminationDate) && DateUtil.getTime(terminationDate).compareTo(DateUtil.getTime(companystartDate)) <=0){
|
|
|
|
|
terminationDate="";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//出勤结果,进出时间
|
|
|
|
|
Map<String,Map<String,Object>> clockInTimeMap = Maps.newHashMap();
|
|
|
|
|
|
|
|
|
|
Map<String,Object> analysisParam = Maps.newHashMap();
|
|
|
|
|
analysisParam.put("generalAttendanceItems",generalAttendanceItems);
|
|
|
|
|
analysisParam.put("attendancePlanMap",attendancePlanMap);
|
|
|
|
|
analysisParam.put("attendanceItemGroupByPlan",attendanceItemGroupByPlan);
|
|
|
|
|
analysisParam.put("comprehensiveWorkingHourList",personComprehensiveWorkingHours.get(userId)==null?Lists.newArrayList():personComprehensiveWorkingHours.get(userId));
|
|
|
|
|
analysisParam.put("workingHourGroupBy",workingHourGroupBy);
|
|
|
|
|
analysisParam.put("allScheduleList",allScheduleList);
|
|
|
|
|
analysisParam.put("allClassInfoList",allClassInfoList);
|
|
|
|
|
analysisParam.put("allOverPlanList",allOverPlanGroup.get(userId)==null?Lists.newArrayList():allOverPlanGroup.get(userId));
|
|
|
|
|
analysisParam.put("evectionList",evectionGroup.get(userId)==null?Lists.newArrayList():evectionGroup.get(userId));
|
|
|
|
|
analysisParam.put("askforList",askforGroup.get(userId)==null?Lists.newArrayList():askforGroup.get(userId));
|
|
|
|
|
analysisParam.put("hxbzList",hxbzList);
|
|
|
|
|
analysisParam.put("seclevel",userGroupMap.get(userId).get(0).get("seclevel"));
|
|
|
|
|
analysisParam.put("departmentId",userGroupMap.get(userId).get(0).get("departmentid"));
|
|
|
|
|
analysisParam.put("subCompanyId",userGroupMap.get(userId).get(0).get("subcompanyid1"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, List<Map<String, Object>>> attendaceResultMap = Maps.newHashMap();
|
|
|
|
|
if (attendaceGroupById.get(userId) != null && attendaceGroupById.get(userId).size() > 0) {
|
|
|
|
|
attendaceResultMap = attendaceGroupById.get(userId).stream().collect(Collectors.groupingBy(e -> e.get("rq").toString()));
|
|
|
|
|
for (Map<String, Object> map: attendaceGroupById.get(userId)){
|
|
|
|
|
clockInTimeMap.put(map.get("rq").toString(),map);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<=betweenDays;i++){
|
|
|
|
|
String date = DateUtil.AfterDay(startDate,i);
|
|
|
|
|
if (leaveAndEntry.equals("1")){
|
|
|
|
|
if (("".equals(companystartDate) || DateUtil.getTime(date).compareTo(DateUtil.getTime(companystartDate))>0)
|
|
|
|
|
&& ("".equals(terminationDate) || DateUtil.getTime(date).compareTo(DateUtil.getTime(terminationDate)) <0)){
|
|
|
|
|
log.info("***********analysis userId:{},analysisDate:{} start***********", userId, date);
|
|
|
|
|
try {
|
|
|
|
|
attendanceAnalysisService.attendanceAnalysisForApi(userId,date,collect.get(userId),analysisParam,clockInTimeMap,attendaceResultMap);
|
|
|
|
|
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.info("***********analysis userId:{} date: {} error ***********", userId,date);
|
|
|
|
|
log.error("execute fail,catch error: [{}]",e);
|
|
|
|
|
if (userIds.split(",").length ==1 && startDate.equals(endDate)){
|
|
|
|
|
throw new AttendanceRunTimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
if (("".equals(companystartDate) || DateUtil.getTime(date).compareTo(DateUtil.getTime(companystartDate))>=0)
|
|
|
|
|
&& ("".equals(terminationDate) || DateUtil.getTime(date).compareTo(DateUtil.getTime(terminationDate)) <=0)){
|
|
|
|
|
log.info("***********analysis userId:{},analysisDate:{} start***********", userId, date);
|
|
|
|
|
try {
|
|
|
|
|
attendanceAnalysisService.attendanceAnalysisForApi(userId,date,collect.get(userId),analysisParam,clockInTimeMap,attendaceResultMap);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.info("***********analysis userId:{} date: {} error ***********", userId,date);
|
|
|
|
|
log.error("execute fail,catch error: [{}]",e);
|
|
|
|
|
if (userIds.split(",").length ==1 && startDate.equals(endDate)){
|
|
|
|
|
throw new AttendanceRunTimeException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
paramMap.put("empIds",paramMap.get("userIds"));
|
|
|
|
|
allowanceService.addAllowanceRecords(paramMap);
|
|
|
|
|
}
|
|
|
|
|
log.info("********AttendanceanalysisAction end********");
|
|
|
|
|
resultMap.put("code","200");
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
log.error("execute fail,catch error: [{}]",e);
|
|
|
|
|
resultMap.put("code","500");
|
|
|
|
|
resultMap.put("message",e.getCause().getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultMap;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|