You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
223 lines
10 KiB
Java
223 lines
10 KiB
Java
2 years ago
|
package com.engine.attendance.attendanceanalysis.service.impl;
|
||
|
|
||
|
import com.engine.attendance.attendanceanalysis.cmd.item.WorkOvertimeItemCmd;
|
||
|
import com.engine.attendance.attendanceanalysis.service.WorkOverTimeService;
|
||
|
import com.engine.attendance.enums.CheckBoxEnum;
|
||
|
import com.engine.attendance.enums.ClassSegmentTypeEnum;
|
||
|
import com.engine.attendance.enums.DateTypeEnum;
|
||
|
import com.engine.attendance.enums.WorkForTimeEnum;
|
||
|
import com.engine.common.util.DateUtil;
|
||
|
import com.engine.common.util.DbTools;
|
||
|
import com.engine.common.util.Utils;
|
||
|
import com.engine.core.impl.Service;
|
||
|
import com.google.common.collect.Lists;
|
||
|
import com.google.common.collect.Maps;
|
||
|
import weaver.general.TimeUtil;
|
||
|
import weaver.general.Util;
|
||
|
|
||
|
import java.util.Calendar;
|
||
|
import java.util.List;
|
||
|
import java.util.Map;
|
||
|
import java.util.stream.Collectors;
|
||
|
|
||
|
public class WorkOverTimeServiceImpl extends Service implements WorkOverTimeService {
|
||
|
@Override
|
||
|
public List<Map<String, Object>> recordWorkOverTime(Map<String, Object> params) {
|
||
|
//考勤项目
|
||
|
List<Map<String,Object>> attendanceItems = (List<Map<String,Object>>)params.get("attendanceItems");
|
||
|
//排班
|
||
|
List<Map<String, Object>> scheduleResult = (List<Map<String,Object>>)params.get("scheduleResult");
|
||
|
//分析日期
|
||
|
String analysisDate = Util.null2String(params.get("analysisDate"));
|
||
|
//请假记录
|
||
|
List<Map<String,Object>> askForLeaveList = (List<Map<String,Object>>)params.get("askForLeaveList");
|
||
|
//外出记录
|
||
|
List<Map<String,Object>> evectionList = (List<Map<String,Object>>)params.get("evectionList");
|
||
|
//打卡卡点
|
||
|
List<Map<String,Map<String,Object>>> clcokInTimeList = (List<Map<String,Map<String,Object>>>)params.get("clcokInTimeList");
|
||
|
|
||
|
Map<String,Map<String,Object>> clcokInTimeMap = Maps.newHashMap();
|
||
|
|
||
|
List<Map<String, Object>> workOverTimeResults = null;
|
||
|
|
||
|
Calendar calendar = Calendar.getInstance();
|
||
|
calendar.set(Integer.valueOf(analysisDate.split("-")[0]), Integer.valueOf(analysisDate.split("-")[1]) - 1, 1);
|
||
|
|
||
|
long diffdays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
|
||
|
|
||
|
for (Map<String,Map<String,Object>> map :clcokInTimeList){
|
||
|
String point = "";
|
||
|
//当天打卡数据
|
||
|
Map<String,Object> clcokInTimeData = null;
|
||
|
for (Map.Entry<String,Map<String,Object>> entry :map.entrySet()){
|
||
|
point = entry.getKey();
|
||
|
clcokInTimeData = entry.getValue();
|
||
|
}
|
||
|
//需要计算的班次打卡时间点
|
||
|
String pointTime = point.split("\\|")[0];
|
||
|
clcokInTimeMap.put(pointTime,clcokInTimeData);
|
||
|
}
|
||
|
//人员
|
||
|
String userId = Util.null2String(params.get("userId"));
|
||
|
List<Map<String, Object>> resultLists = Lists.newArrayList();
|
||
|
int maxDayTime = 0;
|
||
|
int maxWeekTime = 0;
|
||
|
int maxMonthTime = 0;
|
||
|
for (Map<String, Object> scheduleMap :scheduleResult){
|
||
|
String bdlx = Util.null2String(scheduleMap.get("bdlx"));
|
||
|
String rqlx = Util.null2String(scheduleMap.get("rqlx"));
|
||
|
Map<String,Object> getWorkOverTimeParam = Maps.newHashMap();
|
||
|
Map<String,Object> workOverTimeItems = Maps.newHashMap();
|
||
|
//加班开始时间
|
||
|
String dtkssj = Util.null2String(scheduleMap.get("dtkssj"));
|
||
|
//加班结束时间
|
||
|
String dtjssj = Util.null2String(scheduleMap.get("dtjssj"));
|
||
|
|
||
|
String kssj = analysisDate +" "+Util.null2String(scheduleMap.get("dtkssj"));
|
||
|
String jssj = analysisDate +" "+Util.null2String(scheduleMap.get("dtjssj"));
|
||
|
if (DateUtil.getTime(kssj).compareTo(DateUtil.getTime(jssj)) >0){
|
||
|
jssj = DateUtil.AfterDay(analysisDate,1)+" "+Util.null2String(scheduleMap.get("dtjssj"));
|
||
|
}
|
||
|
//申请时间
|
||
|
int applicationTime = DateUtil.getBetWeenMinutes(kssj,jssj);
|
||
|
//扣除休息时间后的剩余
|
||
|
int applicationRestTime = applicationTime;
|
||
|
|
||
|
resultLists.add(workOverTimeItems);
|
||
|
getWorkOverTimeParam.put("attendanceItems",attendanceItems);
|
||
|
getWorkOverTimeParam.put("rqlx",scheduleMap.get("rqlx"));
|
||
|
|
||
|
if (ClassSegmentTypeEnum.EXTENDED_OVERTIME.getKey().equals(bdlx)){
|
||
|
getWorkOverTimeParam.put("workfor", WorkForTimeEnum.DELAY_TO_WORK_OVERTIME.getKey());
|
||
|
}else if (ClassSegmentTypeEnum.EARLY_OVERTIME.getKey().equals(bdlx)){
|
||
|
getWorkOverTimeParam.put("workfor",WorkForTimeEnum.EARLY_TO_WORK_OVERTIME.getKey());
|
||
|
}else if (ClassSegmentTypeEnum.OVERTIME_PLAN.getKey().equals(bdlx)){
|
||
|
applicationRestTime = Utils.removeRestTime(kssj,jssj,scheduleResult,analysisDate);
|
||
|
getWorkOverTimeParam.put("workfor",WorkForTimeEnum.PLAN_WORK_OVERTIME.getKey());
|
||
|
}
|
||
|
Map<String,Object> result = commandExecutor.execute(new WorkOvertimeItemCmd(getWorkOverTimeParam));
|
||
|
//加班项目
|
||
|
List<Map<String,Object>> workTimeBeLateItems = (List<Map<String,Object>>)result.get("attendanceItems");
|
||
|
if (workTimeBeLateItems.size() == 0){
|
||
|
continue;
|
||
|
}
|
||
|
workOverTimeItems.put("item",workTimeBeLateItems.get(0).get("key"));
|
||
|
//提前打卡开始的时长计入加班
|
||
|
String tqdkjrjb = Util.null2String(workTimeBeLateItems.get(0).get("tqdkjrjb"));
|
||
|
//推后打卡结束的时长计入加班
|
||
|
String thdkjrjb = Util.null2String(workTimeBeLateItems.get(0).get("thdkjrjb"));
|
||
|
//结算加班时长不得超过申请的时长
|
||
|
String jbscbdccsqsc = Util.null2String(workTimeBeLateItems.get(0).get("jbscbdccsqsc"));
|
||
|
//结算加班时长不得超过申请的时长
|
||
|
String zdkcjcxxsc = Util.null2String(workTimeBeLateItems.get(0).get("zdkcjcxxsc"));
|
||
|
//超出限制时长的处理方式
|
||
|
String ccclfs = Util.null2String(workTimeBeLateItems.get(0).get("ccclfs"));
|
||
|
//工作日加班最大小时数
|
||
|
String rzdjbxss = Util.null2String(workTimeBeLateItems.get(0).get("rzdjbxss"));
|
||
|
//每周最大加班小时数
|
||
|
String yzdjbxss = Util.null2String(workTimeBeLateItems.get(0).get("yzdjbxss"));
|
||
|
//每月最大加班小时数
|
||
|
String zzdjbxss = Util.null2String(workTimeBeLateItems.get(0).get("zzdjbxss"));
|
||
|
//加班时长自动转入假期余额
|
||
|
String jbzdzjqye= Util.null2String(workTimeBeLateItems.get(0).get("jbzdzjqye"));
|
||
|
|
||
|
if (CheckBoxEnum.CHECKED.getKey().equals(tqdkjrjb)){
|
||
|
Map<String,Object> clcokInTimeData = clcokInTimeMap.get(dtkssj);
|
||
|
String signTime = clcokInTimeData.get("signdate")+" "+clcokInTimeData.get("signtime");
|
||
|
if (DateUtil.getTime(signTime).compareTo(DateUtil.getTime(dtkssj)) < 0){
|
||
|
dtkssj = signTime;
|
||
|
}
|
||
|
}
|
||
|
if (CheckBoxEnum.CHECKED.getKey().equals(thdkjrjb)){
|
||
|
Map<String,Object> clcokInTimeData = clcokInTimeMap.get(dtjssj);
|
||
|
String signTime = clcokInTimeData.get("signdate")+" "+clcokInTimeData.get("signtime");
|
||
|
if (DateUtil.getTime(signTime).compareTo(DateUtil.getTime(dtjssj)) > 0){
|
||
|
dtjssj = signTime;
|
||
|
}
|
||
|
}
|
||
|
//自动扣除
|
||
|
if ("2".equals(ccclfs) && workOverTimeResults == null){
|
||
|
String startDate = analysisDate.split("-")[0]+"-"+ analysisDate.split("-")[1]+"-01";
|
||
|
String endDate = analysisDate.split("-")[0]+"-"+ analysisDate.split("-")[1]+"-"+diffdays;
|
||
|
workOverTimeResults =getWorkOverTimeResults(startDate,endDate,userId);
|
||
|
|
||
|
}
|
||
|
if ("2".equals(ccclfs) && !"".equals(rzdjbxss) && DateTypeEnum.WORK_DAY.getKey().equals(rqlx)){
|
||
|
//工作日加班最大数
|
||
|
maxDayTime = getWorkDayTime(workOverTimeResults,analysisDate);
|
||
|
|
||
|
|
||
|
}else if ("2".equals(ccclfs) && !"".equals(yzdjbxss)){
|
||
|
//每月最大加班数
|
||
|
maxWeekTime = getMonthTime(workOverTimeResults);
|
||
|
|
||
|
|
||
|
}else if ("2".equals(ccclfs) && !"".equals(zzdjbxss)){
|
||
|
//每周最大加班小时数
|
||
|
maxMonthTime = getWeekTime(workOverTimeResults,analysisDate);
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
//加班时长自动转入假期余额
|
||
|
if (CheckBoxEnum.CHECKED.getKey().equals(jbzdzjqye)){
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return resultLists;
|
||
|
}
|
||
|
public List<Map<String, Object>> getWorkOverTimeResults(String startDate,String endDate,String userId){
|
||
|
String sql = "select sjjbsc,sjksrq,sjjsrq from uf_jcl_kq_jbjg where jbry=? and sjksrq>? and sjjsrq<?";
|
||
|
List<Map<String, Object>> dataList = DbTools.getSqlToList(sql,userId,startDate,endDate);
|
||
|
return dataList;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获得工作日加班数
|
||
|
* @param dataList
|
||
|
* @return
|
||
|
*/
|
||
|
public int getWorkDayTime(List<Map<String, Object>> dataList,String date){
|
||
|
List<Map<String, Object>> list = dataList.stream().filter(e->date.equals(e.get("sjksrq"))).collect(Collectors.toList());
|
||
|
int totalHour = list.stream().mapToInt(e->Integer.valueOf(e.get("sjjbsc").toString())).sum();
|
||
|
return totalHour;
|
||
|
}
|
||
|
/**
|
||
|
* 获得一周加班数
|
||
|
* @param dataList
|
||
|
* @return
|
||
|
*/
|
||
|
public int getWeekTime(List<Map<String, Object>> dataList,String date){
|
||
|
int day = TimeUtil.getDayOfWeek(date);
|
||
|
if (day ==0){
|
||
|
day = 7;
|
||
|
}
|
||
|
String startDate = DateUtil.beforeDay(date,day-1);
|
||
|
String endDate = DateUtil.AfterDay(date,7-day);
|
||
|
List<Map<String, Object>> list = dataList.stream().filter(e->{
|
||
|
String sjksrq = Util.null2String(e.get("sjksrq"));
|
||
|
if (DateUtil.getTime(sjksrq).compareTo(DateUtil.getTime(startDate)) >=0 &&
|
||
|
DateUtil.getTime(sjksrq).compareTo(DateUtil.getTime(endDate)) >=0){
|
||
|
return true;
|
||
|
}else {
|
||
|
return false;
|
||
|
}
|
||
|
}).collect(Collectors.toList());
|
||
|
int totalHour = list.stream().mapToInt(e->Integer.valueOf(e.get("sjjbsc").toString())).sum();
|
||
|
return totalHour;
|
||
|
}
|
||
|
/**
|
||
|
* 获得一个月加班数
|
||
|
* @param dataList
|
||
|
* @return
|
||
|
*/
|
||
|
public int getMonthTime(List<Map<String, Object>> dataList){
|
||
|
int totalHour = dataList.stream().mapToInt(e->Integer.valueOf(e.get("sjjbsc").toString())).sum();
|
||
|
return totalHour;
|
||
|
}
|
||
|
|
||
|
}
|