|
@@ -2,23 +2,30 @@ package com.boman.web.core.service.attendance;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.boman.common.core.utils.DateUtils;
|
|
|
+import com.boman.common.core.utils.SecurityUtils;
|
|
|
import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.domain.dto.AjaxResult;
|
|
|
+import com.boman.domain.dto.ClockOnDto;
|
|
|
import com.boman.domain.dto.FormDataDto;
|
|
|
+import com.boman.web.core.service.TableServiceCmdService;
|
|
|
+import com.boman.web.core.service.attendance.rules.AttendanceRulesService;
|
|
|
import com.boman.web.core.service.common.ICommonService;
|
|
|
+import com.boman.web.core.utils.AuthUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
-import static com.boman.common.core.utils.obj.ObjectUtils.ifNullSetEmpty;
|
|
|
-import static com.boman.common.core.utils.obj.ObjectUtils.requireNonNull;
|
|
|
+import static com.boman.common.core.utils.DateUtils.YYYY_MM_DD_HH_MM;
|
|
|
+import static com.boman.common.core.utils.number.NumberUtils.gtZero;
|
|
|
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
|
import static com.boman.domain.constant.AttendanceConst.*;
|
|
|
+import static com.boman.domain.constant.AttendanceRulesConst.ATTENDANCE_RULES_END_TIME;
|
|
|
+import static com.boman.domain.constant.AttendanceRulesConst.ATTENDANCE_RULES_START_TIME;
|
|
|
import static com.boman.domain.constant.FormDataConstant.CONDITION;
|
|
|
|
|
|
/**
|
|
@@ -32,6 +39,10 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
|
|
|
@Resource
|
|
|
private ICommonService commonService;
|
|
|
+ @Resource
|
|
|
+ private AttendanceRulesService rulesService;
|
|
|
+ @Resource
|
|
|
+ private TableServiceCmdService cmdService;
|
|
|
|
|
|
/**
|
|
|
* 功能描述: 根据tableName和userId查找当月考勤
|
|
@@ -44,10 +55,10 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
requireNonNull(tableName, "tableName is empty");
|
|
|
requireNonNull(userName, "userName is empty");
|
|
|
|
|
|
- String yyyyMm = DateUtils.getYyyyMm();
|
|
|
+ List<String> days = DateUtils.getMonthDays();
|
|
|
JSONObject map = new JSONObject(2);
|
|
|
map.put(ATTENDANCE_USER_NAME, userName);
|
|
|
- map.put(ATTENDANCE_NOW_TIME, yyyyMm);
|
|
|
+ map.put(ATTENDANCE_TABLE_TODAYTIME, days);
|
|
|
return commonService.getByMap(tableName, map);
|
|
|
}
|
|
|
|
|
@@ -61,35 +72,45 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
*/
|
|
|
@Override
|
|
|
public AjaxResult attendanceRecord(String tableName, Long userName) {
|
|
|
+ Map<String, Object> mapObj = new HashMap<>(4);
|
|
|
List<JSONObject> byMap = listByUserName(tableName, userName);
|
|
|
- List<String> dateList = new ArrayList<>();
|
|
|
- //定义三个返回值
|
|
|
- int leave = 0;
|
|
|
- int late = 0;
|
|
|
- int leaveOr = 0;
|
|
|
- if (byMap.size()>0){
|
|
|
- for (JSONObject jsonObject : byMap) {
|
|
|
- if (ObjectUtils.isNotEmpty(jsonObject.get("attendance_table_leave")) && "Y".equals(String.valueOf(jsonObject.get("attendance_table_leave")))){
|
|
|
- leave += 1;
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotEmpty(jsonObject.get("attendance_table_late")) && "Y".equals(String.valueOf(jsonObject.get("attendance_table_late")))){
|
|
|
- late += 1;
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotEmpty(jsonObject.get("attendance_table_leave_or")) && "Y".equals(String.valueOf(jsonObject.get("attendance_table_leave_or")))) {
|
|
|
- leaveOr += 1;
|
|
|
- }
|
|
|
- if (ObjectUtils.isNotEmpty(jsonObject.get("attendance_table_todaytime"))){
|
|
|
- String todayTime = String.valueOf(jsonObject.get("attendance_table_todaytime"));
|
|
|
- dateList.add(todayTime);
|
|
|
+ if (isEmpty(byMap)) {
|
|
|
+ mapObj.put("leave", 0);
|
|
|
+ mapObj.put("late", 0);
|
|
|
+ mapObj.put("leaveOr", 0);
|
|
|
+ mapObj.put("dateList", 0);
|
|
|
+ return AjaxResult.success(mapObj);
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> dateList = new ArrayList<>(byMap.size());
|
|
|
+ // 早退 迟到 请假
|
|
|
+ int leave = 0, late = 0, leaveOr = 0;
|
|
|
+ for (JSONObject jsonObject : byMap) {
|
|
|
+ if (ObjectUtils.isNotEmpty(jsonObject.get("attendance_table_leave")) && "Y".equals(String.valueOf(jsonObject.get("attendance_table_leave")))) {
|
|
|
+ leave++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtils.isNotEmpty(jsonObject.get("attendance_table_late")) && "Y".equals(String.valueOf(jsonObject.get("attendance_table_late")))) {
|
|
|
+ late++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtils.isNotEmpty(jsonObject.get("attendance_table_leave_or")) && "Y".equals(String.valueOf(jsonObject.get("attendance_table_leave_or")))) {
|
|
|
+ leaveOr++;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtils.isNotEmpty(jsonObject.get("attendance_table_todaytime"))) {
|
|
|
+ // 只需要异常的
|
|
|
+ if (gtZero(leave) || gtZero(late) || gtZero(leaveOr)) {
|
|
|
+ dateList.add(jsonObject.getString("attendance_table_todaytime"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- Map<String,Object> mapObj = new HashMap<>(3);
|
|
|
- mapObj.put("leave",leave);
|
|
|
- mapObj.put("late",late);
|
|
|
- mapObj.put("leaveOr",leaveOr);
|
|
|
- mapObj.put("dateList",dateList);
|
|
|
- return AjaxResult.success(mapObj);
|
|
|
+
|
|
|
+ mapObj.put("leave", leave);
|
|
|
+ mapObj.put("late", late);
|
|
|
+ mapObj.put("leaveOr", leaveOr);
|
|
|
+ mapObj.put("dateList", dateList);
|
|
|
+ return AjaxResult.success(mapObj);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -136,9 +157,15 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
requireNonNull(tableName, "tableName is empty");
|
|
|
requireNonNull(userName, "userName is empty");
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- return null;
|
|
|
+ FormDataDto dto = new FormDataDto();
|
|
|
+ dto.setTable(tableName);
|
|
|
+ JSONObject condition = new JSONObject();
|
|
|
+ condition.put("attendance_table_username", userName);
|
|
|
+ // in
|
|
|
+ condition.put(ATTENDANCE_TABLE_TODAYTIME, DateUtils.getDate());
|
|
|
+ dto.setFixedData(condition);
|
|
|
+ int count = commonService.count(dto);
|
|
|
+ return count > 0 ? "下班打卡" : "上班打卡";
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -152,4 +179,152 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|
|
map.put(ATTENDANCE_TABLE_WORK, yyyyMmDd);
|
|
|
return commonService.getByMap(tableName, map);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 查询该人的一天打卡时间
|
|
|
+ *
|
|
|
+ * @param tableName tableName
|
|
|
+ * @param userName userName
|
|
|
+ * @return com.boman.common.core.web.domain.AjaxResult
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONObject attendanceTime(String tableName, String userName) {
|
|
|
+ requireNonNull(tableName, "tableName is empty");
|
|
|
+ requireNonNull(userName, "userName is empty");
|
|
|
+
|
|
|
+ JSONObject result = new JSONObject();
|
|
|
+ List<JSONObject> attendanceList = listByUserNameAndTime(tableName, userName, DateUtils.getDate());
|
|
|
+ // 今天 还未打卡
|
|
|
+ if (isEmpty(attendanceList)) {
|
|
|
+ result.put(GO_TO_WORK, null);
|
|
|
+ result.put(GO_OFF_WORK, null);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ attendanceList = attendanceList.stream()
|
|
|
+ .sorted(Comparator.comparing(json -> json.getTimestamp(ATTENDANCE_TABLE_CREATE_TIME)))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ Timestamp goToWorkTime = null;
|
|
|
+ Timestamp goOffWorkTime = null;
|
|
|
+ for (JSONObject attendance : attendanceList) {
|
|
|
+ if (isNotEmpty(attendance.get(ATTENDANCE_TABLE_WORK)) && isEmpty(attendance.get(ATTENDANCE_TABLE_OFFWORK))) {
|
|
|
+ goToWorkTime = attendance.getTimestamp(ATTENDANCE_TABLE_WORK);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for (JSONObject attendance : attendanceList) {
|
|
|
+ if (isNotEmpty(attendance.get(ATTENDANCE_TABLE_OFFWORK)) && isEmpty(attendance.get(ATTENDANCE_TABLE_WORK))) {
|
|
|
+ goOffWorkTime = attendance.getTimestamp(ATTENDANCE_TABLE_OFFWORK);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ result.put(GO_TO_WORK, goToWorkTime == null ? null : goToWorkTime.toString());
|
|
|
+ result.put(GO_OFF_WORK, goOffWorkTime == null ? null : goOffWorkTime.toString());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 打卡
|
|
|
+ *
|
|
|
+ * @param dto dto
|
|
|
+ * @return com.alibaba.fastjson.JSONObject
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public JSONObject clockOn(ClockOnDto dto) {
|
|
|
+ int type = requireNonNull(dto.getType(), "clockOn type is empty");
|
|
|
+ String tableName = requireNonNull(dto.getTableName(), "clockOn tableName is empty");
|
|
|
+
|
|
|
+ JSONObject commitData = new JSONObject();
|
|
|
+ commitData.put(ATTENDANCE_USER_NAME, SecurityUtils.getUsername());
|
|
|
+ commitData.put(ATTENDANCE_TABLE_TODAYTIME, DateUtils.getDate());
|
|
|
+ commitData.put(ATTENDANCE_TABLE_LONGITUDE, dto.getLongitude());
|
|
|
+ commitData.put(ATTENDANCE_TABLE_LATITUDE, dto.getLatitude());
|
|
|
+ Timestamp currentTime = new Timestamp(System.currentTimeMillis());
|
|
|
+ // 是否请假
|
|
|
+ if (checkIsLeave()) {
|
|
|
+ //
|
|
|
+ }
|
|
|
+
|
|
|
+ if (GO_TO_WORK_TYPE == type) {
|
|
|
+ commitData.put(ATTENDANCE_TABLE_WORK, currentTime);
|
|
|
+ if (checkIsLate(currentTime)) {
|
|
|
+ commitData.put(ATTENDANCE_ABNORMAL, Y);
|
|
|
+ commitData.put(ATTENDANCE_TABLE_LATE, Y);
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (GO_OFF_WORK_TYPE == type) {
|
|
|
+ commitData.put(ATTENDANCE_TABLE_OFFWORK, currentTime);
|
|
|
+ }
|
|
|
+
|
|
|
+ saveClockOn(tableName, commitData);
|
|
|
+ return commitData;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 保存打卡信息
|
|
|
+ *
|
|
|
+ * @param tableName tableName
|
|
|
+ * @param commitData commitData
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ private boolean saveClockOn(String tableName, JSONObject commitData) {
|
|
|
+ FormDataDto dto = new FormDataDto();
|
|
|
+ dto.setObjId(-1L);
|
|
|
+ dto.setTable(tableName);
|
|
|
+ dto.setFixedData(commitData);
|
|
|
+ AjaxResult ajaxResult = cmdService.objectSave(dto);
|
|
|
+ return AjaxResult.checkSuccess(ajaxResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 是否迟到
|
|
|
+ *
|
|
|
+ * @param arrivalTime 上班打卡时间
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ private boolean checkIsLate(Timestamp arrivalTime) {
|
|
|
+ JSONObject rule = rulesService.listByDeptId(AuthUtils.getLoginUser().getSysUser().getDeptId());
|
|
|
+ String hourMi = rule.getString(ATTENDANCE_RULES_START_TIME);
|
|
|
+ String year_month = DateUtils.getDate();
|
|
|
+ String ruleStartTime = year_month + " " + hourMi;
|
|
|
+ Date date = DateUtils.strToDate(ruleStartTime, YYYY_MM_DD_HH_MM);
|
|
|
+ return arrivalTime.after(date);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 是否早退
|
|
|
+ *
|
|
|
+ * @param leaveTime 下班打卡时间
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ private boolean checkIsLeaveEarly(Timestamp leaveTime) {
|
|
|
+ JSONObject rule = rulesService.listByDeptId(AuthUtils.getLoginUser().getSysUser().getDeptId());
|
|
|
+ Timestamp ruleEndTime = rule.getTimestamp(ATTENDANCE_RULES_END_TIME);
|
|
|
+ return leaveTime.before(ruleEndTime);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private boolean checkIsLeave() {
|
|
|
+
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 功能描述: 根据username和time查找
|
|
|
+ *
|
|
|
+ * @param tableName tableName
|
|
|
+ * @param userName userName
|
|
|
+ * @param time time
|
|
|
+ * @return java.util.List<com.alibaba.fastjson.JSONObject>
|
|
|
+ */
|
|
|
+ private List<JSONObject> listByUserNameAndTime(String tableName, String userName, String time) {
|
|
|
+ JSONObject condition = new JSONObject(2);
|
|
|
+ condition.put(ATTENDANCE_USER_NAME, userName);
|
|
|
+ condition.put(ATTENDANCE_TABLE_TODAYTIME, time);
|
|
|
+ return commonService.getByMap(tableName, condition);
|
|
|
+ }
|
|
|
+
|
|
|
}
|