Forráskód Böngészése

fix 修改打卡逻辑

Administrator 3 éve
szülő
commit
74d31a3b00

+ 16 - 4
boman-api/boman-domain/src/main/java/com.boman.domain/constant/AttendanceConst.java

@@ -9,6 +9,8 @@ public class AttendanceConst {
 
     /** 考勤人员姓名 **/
     public static final String ATTENDANCE_USER_NAME = "attendance_table_username";
+    /** 考勤人员姓名id **/
+    public static final String ATTENDANCE_USER_ID = "user_id";
 
     /** 是否考勤异常 **/
     public static final String ATTENDANCE_ABNORMAL = "attendance_abnormal";
@@ -22,9 +24,13 @@ public class AttendanceConst {
 
     /** 上班打卡时间 **/
     public static final String ATTENDANCE_TABLE_WORK = "attendance_table_work";
+    /** 下午上班打卡时间 **/
+    public static final String ATTENDANCE_TABLE_WORK_PM = "attendance_table_work_pm";
 
     /** 下班打卡时间 **/
     public static final String ATTENDANCE_TABLE_OFFWORK = "attendance_table_offwork";
+    /** 下午下班打卡时间 **/
+    public static final String ATTENDANCE_TABLE_OFFWORK_PM  = "attendance_table_offwork_pm";
 
     /** 创建时间 **/
     public static final String ATTENDANCE_TABLE_CREATE_TIME = "create_time";
@@ -36,11 +42,17 @@ public class AttendanceConst {
     public static final String ATTENDANCE_TABLE_LATITUDE = "latitude";
 
     public static final String Y = "Y";
-    /**  上班打卡 **/
+    /**  上午上班打卡 **/
     public static final int GO_TO_WORK_TYPE = 1;
-    /**  下班打卡 **/
+    /**  上午下班打卡 **/
     public static final int GO_OFF_WORK_TYPE = 2;
-    public static final String GO_TO_WORK = "上班打卡";
-    public static final String GO_OFF_WORK = "下班打卡";
+    /**  下午上班打卡 **/
+    public static final int GO_TO_WORK_TYPE_PM= 3;
+    /**  下午下班打卡 **/
+    public static final int GO_OFF_WORK_TYPE_PM = 4;
+    public static final String GO_TO_WORK = "上午上班打卡";
+    public static final String GO_TO_WORK_PM = "下午上班打卡";
+    public static final String GO_OFF_WORK = "上午下班打卡";
+    public static final String GO_OFF_WORK_PM = "下午下班打卡";
 
 }

+ 4 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/constant/AttendanceRulesConst.java

@@ -12,9 +12,13 @@ public class AttendanceRulesConst {
 
     /** 规定上班时间 **/
     public static final String ATTENDANCE_RULES_START_TIME = "attendance_rules_start_time";
+    /** 规定下午上班时间 **/
+    public static final String ATTENDANCE_RULES_START_TIME_PM = "attendance_rules_start_time_pm";
 
     /** 规定下班时间 **/
     public static final String ATTENDANCE_RULES_END_TIME = "attendance_rules_end_time";
+    /** 规定下午下班时间 **/
+    public static final String ATTENDANCE_RULES_END_TIME_PM = "attendance_rules_end_time_pm";
 
     /**部门id **/
     public static final String ATTENDANCE_RULES_DEPT_ID = "attendance_rules_dept_id";

+ 2 - 0
boman-api/boman-domain/src/main/java/com.boman.domain/dto/ClockOnDto.java

@@ -21,6 +21,8 @@ public class ClockOnDto {
 
     /** 纬度 **/
     private String latitude;
+    /** 用户id **/
+    private Long userId;
 
 
 }

+ 1 - 1
boman-modules/boman-gen/src/main/resources/bootstrap.yml

@@ -9,7 +9,7 @@ spring:
     name: boman-gen
   profiles:
     # 环境配置
-    active: test
+    active: dev
   cloud:
     nacos:
       discovery:

+ 35 - 21
boman-web-core/src/main/java/com/boman/web/core/service/attendance/AttendanceServiceImpl.java

@@ -3,6 +3,7 @@ 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.StringUtils;
 import com.boman.common.core.utils.obj.ObjectUtils;
 import com.boman.common.redis.RedisKey;
 import com.boman.domain.GenTable;
@@ -17,7 +18,9 @@ import com.boman.web.core.service.attendance.rules.AttendanceRulesService;
 import com.boman.web.core.service.common.ICommonService;
 import com.boman.web.core.service.select.IBaseSelectService;
 import com.boman.web.core.utils.AuthUtils;
+import com.boman.web.core.utils.JSONObjectUtils;
 import com.google.common.collect.Lists;
+import org.apache.commons.collections4.MapUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,11 +34,11 @@ import java.util.*;
 import java.util.stream.Collectors;
 
 import static com.boman.common.core.utils.DateUtils.YYYY_MM_DD_HH_MM;
+import static com.boman.common.core.utils.DateUtils.dateTimeNow;
 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.AttendanceRulesConst.*;
 import static com.boman.domain.constant.FormDataConstant.CONDITION;
 import static com.boman.domain.constant.FormDataConstant.PAGE_ROWS;
 import static com.boman.web.core.utils.ColumnUtils.withoutHrReturnColumnNames;
@@ -195,16 +198,19 @@ public class AttendanceServiceImpl implements AttendanceService {
     public String showAttendanceType(String tableName, String userName) {
         requireNonNull(tableName, "tableName is empty");
         requireNonNull(userName, "userName is empty");
-
-        FormDataDto dto = new FormDataDto();
-        dto.setTable(tableName);
-        JSONObject condition = new JSONObject();
-        condition.put("attendance_table_username", userName);
-        // in
-        condition.put(ATTENDANCE_TABLE_TODAYTIME, Lists.newArrayList(DateUtils.getDate()));
-        dto.setFixedData(condition);
-        int count = commonService.count(dto);
-        return count > 0 ? GO_OFF_WORK : GO_TO_WORK;
+        JSONObject attendanceTableUsername = commonService.getOneByMap(tableName, JSONObjectUtils.putValue("attendance_table_username", userName, ATTENDANCE_TABLE_TODAYTIME, Lists.newArrayList(DateUtils.getDate())));
+        GregorianCalendar ca = new GregorianCalendar();
+        int result = ca.get(GregorianCalendar.AM_PM);
+        if (0 == result){
+            //上午上班打卡
+            return   MapUtils.isEmpty(attendanceTableUsername)?GO_TO_WORK:GO_OFF_WORK;
+        }else {
+            if (MapUtils.isEmpty(attendanceTableUsername) || isEmpty(attendanceTableUsername.getString(ATTENDANCE_TABLE_WORK_PM))){
+                return GO_TO_WORK_PM;
+            }else {
+                return GO_OFF_WORK_PM;
+            }
+        }
     }
 
     @Override
@@ -280,23 +286,25 @@ public class AttendanceServiceImpl implements AttendanceService {
         commitData.put(ATTENDANCE_TABLE_TODAYTIME, Lists.newArrayList(DateUtils.getDate()));
         commitData.put(ATTENDANCE_TABLE_LONGITUDE, dto.getLongitude());
         commitData.put(ATTENDANCE_TABLE_LATITUDE, dto.getLatitude());
+        commitData.put(ATTENDANCE_USER_ID, SecurityUtils.getUserId());
         Timestamp currentTime = new Timestamp(System.currentTimeMillis());
         // 是否请假
         if (checkIsLeave()) {
             //
         }
-
+        if (checkIsLate(currentTime,type)) {
+            commitData.put(ATTENDANCE_ABNORMAL, Y);
+            commitData.put(ATTENDANCE_TABLE_LATE, Y);
+        }
         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);
+        }else if(GO_TO_WORK_TYPE_PM == type){
+            commitData.put(ATTENDANCE_TABLE_WORK_PM, currentTime);
+        }else if(GO_OFF_WORK_TYPE_PM == type){
+            commitData.put(ATTENDANCE_TABLE_OFFWORK_PM, currentTime);
         }
-
         saveClockOn(tableName, commitData);
         return commitData;
     }
@@ -455,9 +463,15 @@ public class AttendanceServiceImpl implements AttendanceService {
      * @param arrivalTime 上班打卡时间
      * @return boolean
      */
-    private boolean checkIsLate(Timestamp arrivalTime) {
+    private boolean checkIsLate(Timestamp arrivalTime,int type) {
         JSONObject rule = rulesService.listByDeptId(AuthUtils.getLoginUser().getSysUser().getDeptId());
-        String hourMi = rule.getString(ATTENDANCE_RULES_START_TIME);
+        String hourMi = "";
+        if (GO_TO_WORK_TYPE == type){
+            hourMi = rule.getString(ATTENDANCE_RULES_START_TIME);
+        }
+        if (GO_TO_WORK_TYPE_PM == type){
+            hourMi = rule.getString(ATTENDANCE_RULES_START_TIME_PM);
+        }
         String year_month = DateUtils.getDate();
         String ruleStartTime = year_month + " " + hourMi;
         Date date = DateUtils.strToDate(ruleStartTime, YYYY_MM_DD_HH_MM);