Przeglądaj źródła

1.新生源考勤记录中增加工作时长。
2.新生源新建定时任务处理10月份以后未填写工作时长的考勤记录。

zhengqiang 3 lat temu
rodzic
commit
49a3d9473d

+ 5 - 2
common/src/main/java/com/jpsoft/shinestar/modules/business/dao/WorkScheduleAttendanceDAO.java

@@ -5,6 +5,7 @@ import java.util.Date;
 import java.util.List;
 
 import com.jpsoft.shinestar.modules.base.entity.WorkPersonScheduling;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 import com.jpsoft.shinestar.modules.business.entity.WorkScheduleAttendance;
 import java.util.Map;
@@ -36,8 +37,6 @@ public interface WorkScheduleAttendanceDAO {
     int deleteByPersonIdAndAttendanceDateAndExcludeShiftId(Long personId, String attendanceDate, String shiftIds);
     int deleteByPersonIdAndAttendanceDateAndExcludeSchedule(Long personId, String attendanceDate, WorkPersonScheduling workPersonScheduling);
 
-
-
 	List<WorkScheduleAttendance> findGroupByPersonIdAndMonthsAndResult(Long personId, Date startDate, Date endDate,Map<String, Object> searchParams);
 	List<WorkScheduleAttendance> findNotGroupByPersonIdAndMonthsAndResult(Long personId, Date startDate, Date endDate,Map<String, Object> searchParams);
 	List<WorkScheduleAttendance> findAbsenteeismGroupByPersonIdAndMonthsAndResult(Long personId, Date startDate, Date endDate,Map<String, Object> searchParams);
@@ -52,4 +51,8 @@ public interface WorkScheduleAttendanceDAO {
     WorkScheduleAttendance findOneByWorkOverPersonId(String workOverPersonId);
 
     List<Map> statScheduleAttendanceByDate(Long personId, Date startDate, Date endDate);
+
+    List<WorkScheduleAttendance> findEmptyWorkMinuteList(@Param("limit") int limit);
+
+    int updateWorkMinute(WorkScheduleAttendance wsa);
 }

+ 3 - 0
common/src/main/java/com/jpsoft/shinestar/modules/business/entity/WorkScheduleAttendance.java

@@ -127,6 +127,9 @@ public class WorkScheduleAttendance {
     @ApiModelProperty(value = "与考勤时间相差分钟")
     private BigDecimal offsetMinute;
 
+    @ApiModelProperty(value = "上班时长(分钟)")
+    private BigDecimal workMinute;
+
     @Transient
     private WorkOverPerson workOverPerson;
 }

+ 6 - 0
common/src/main/java/com/jpsoft/shinestar/modules/business/service/WorkScheduleAttendanceService.java

@@ -77,4 +77,10 @@ public interface WorkScheduleAttendanceService {
     WorkScheduleAttendance findOneByWorkOverPersonId(String workOverPersonId);
 
     List<Map> statScheduleAttendanceByDate(Long personId, Date startDate, Date endDate);
+
+    List<WorkScheduleAttendance> findEmptyWorkMinuteList(int limit);
+
+	List<WorkScheduleAttendance> findByPersonScheduleIdAndClassify(String personScheduleId, String workShiftId, String classify);
+
+	int updateWorkMinute(WorkScheduleAttendance wsa);
 }

+ 31 - 1
common/src/main/java/com/jpsoft/shinestar/modules/business/service/impl/WorkScheduleAttendanceServiceImpl.java

@@ -528,6 +528,8 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
             saveWorkAttendance(personId, temperature, recordTime, date.toString("yyyy-MM-dd"), workPersonScheduling.getId(),
                     workEndShift.getId(), result, minutes, "2", workStatus,workOverPerson);
 
+            //计算本班次上班时间
+
             //查询当前下班的班次是否与其它班次有连班,如果有则将之前连班最早的上班打卡到现在下班打卡之间的班次都算正常上下
 //            workJoin(personId, temperature, date, workPersonScheduling, shiftList, fullFormat, workEndShift, endIndex, personInfo);
         }
@@ -623,6 +625,7 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
                                     String personScheduleId, String workShiftId, String result, Integer minutes,
                                     String classify, String workStatus, WorkOverPerson workOverPerson) {
         long offsetMinute = 0;
+        int workMinutes = 0;
 
         try {
             WorkShiftInfo workShiftInfo = workShiftInfoService.get(workShiftId);
@@ -642,6 +645,21 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
                     closingTime = closingTime.plusDays(workShiftInfo.getClosingDayType());
 
                     offsetMinute = Minutes.minutesBetween(new DateTime(recordTime), closingTime).getMinutes();
+
+                    //计算本班次上班时长(下班时间-上班时间)
+                    List<WorkScheduleAttendance> onWorkList = workScheduleAttendanceDAO.findByPersonScheduleIdAndClassify(personScheduleId, workShiftId, "1");
+
+                    if(onWorkList.size()>0){
+                        WorkScheduleAttendance workStartAttendance = onWorkList.get(0);
+
+                        if(StringUtils.isNotEmpty(workStartAttendance.getResult()) &&
+                        !"0".equals(workStartAttendance.getResult())){
+                            workMinutes = Minutes.minutesBetween(
+                                            new DateTime(workStartAttendance.getRecordTime()),
+                                            new DateTime(recordTime))
+                                    .getMinutes();
+                        }
+                    }
                 }
             }
         }
@@ -668,6 +686,7 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
             workEndAttendance.setRecordTime(recordTime);
             workEndAttendance.setCreateTime(new Date());
             workEndAttendance.setOffsetMinute(new BigDecimal(offsetMinute));
+            workEndAttendance.setWorkMinute(new BigDecimal(workMinutes));
 
             if(workOverPerson!=null){
                 workEndAttendance.setWorkOverPersonId(workOverPerson.getId());
@@ -685,6 +704,7 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
             workEndAttendance.setRecordTime(recordTime);
             workEndAttendance.setUpdateTime(new Date());
             workEndAttendance.setOffsetMinute(new BigDecimal(offsetMinute));
+            workEndAttendance.setWorkMinute(new BigDecimal(workMinutes));
 
             if(workOverPerson!=null){
                 workEndAttendance.setWorkOverPersonId(workOverPerson.getId());
@@ -694,7 +714,7 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
         }
     }
 
-    private List<WorkScheduleAttendance> findByPersonScheduleIdAndClassify(String personScheduleId, String workShiftId, String classify) {
+    public List<WorkScheduleAttendance> findByPersonScheduleIdAndClassify(String personScheduleId, String workShiftId, String classify) {
         List<WorkScheduleAttendance> attendanceList = workScheduleAttendanceDAO.findByPersonScheduleIdAndClassify(personScheduleId, workShiftId, classify);
 
         return attendanceList;
@@ -1250,4 +1270,14 @@ public class WorkScheduleAttendanceServiceImpl implements WorkScheduleAttendance
     public List<Map> statScheduleAttendanceByDate(Long personId, Date startDate, Date endDate) {
         return workScheduleAttendanceDAO.statScheduleAttendanceByDate(personId,startDate,endDate);
     }
+
+    @Override
+    public List<WorkScheduleAttendance> findEmptyWorkMinuteList(int limit) {
+        return workScheduleAttendanceDAO.findEmptyWorkMinuteList(limit);
+    }
+
+    @Override
+    public int updateWorkMinute(WorkScheduleAttendance wsa) {
+        return workScheduleAttendanceDAO.updateWorkMinute(wsa);
+    }
 }

+ 26 - 2
common/src/main/resources/mapper/business/WorkScheduleAttendance.xml

@@ -27,6 +27,7 @@
         <result property="coefficientDays" column="coefficient_days"/>
         <result property="workOverPersonId" column="work_over_person_id"/>
         <result property="offsetMinute" column="offset_minute"/>
+        <result property="workMinute" column="work_minute"/>
     </resultMap>
     <insert id="insert" parameterType="com.jpsoft.shinestar.modules.business.entity.WorkScheduleAttendance">
         <!--
@@ -38,7 +39,7 @@
 		insert into business_work_schedule_attendance
 	    (id_,person_schedule_id,work_shift_id,attendance_date,classify_,person_id,result_,temperature_,
 	    record_time,create_by,create_time,update_by,update_time,del_flag,work_status,remark_,supplement_work_person_id,
-	    late_leave_minute,work_over_person_id,offset_minute)
+	    late_leave_minute,work_over_person_id,offset_minute,work_minute)
 		values
 		(
             #{id,jdbcType=VARCHAR}
@@ -61,6 +62,7 @@
             ,#{lateLeaveMinute,jdbcType=NUMERIC}
             ,#{workOverPersonId,jdbcType=VARCHAR}
             ,#{offsetMinute,jdbcType=NUMERIC}
+            ,#{workMinute,jdbcType=NUMERIC}
 		)
 	]]>
     </insert>
@@ -127,6 +129,9 @@
             <if test="offsetMinute!=null">
                 offset_minute=#{offsetMinute,jdbcType=NUMERIC},
             </if>
+            <if test="workMinute!=null">
+                work_minute=#{workMinute,jdbcType=NUMERIC},
+            </if>
         </set>
         where id_=#{id}
     </update>
@@ -541,7 +546,11 @@
             and del_flag=0
         ]]>
     </update>
-
+    <update id="updateWorkMinute" parameterType="com.jpsoft.shinestar.modules.business.entity.WorkScheduleAttendance">
+        update business_work_schedule_attendance
+        set work_minute=#{workMinute},update_time=#{updateTime}
+        where id_=#{id}
+    </update>
     <select id="numListSearch" resultMap="WorkScheduleAttendanceMap">
         <![CDATA[
 			SELECT
@@ -651,4 +660,19 @@
             group by work_shift_id
         ]]>
     </select>
+    <select id="findEmptyWorkMinuteList" resultMap="WorkScheduleAttendanceMap">
+        select * from business_work_schedule_attendance
+        where
+        work_minute is null
+        and
+        classify_='2'
+        and
+        result_ in ('1','2','3')
+        and
+        del_flag=0
+        and
+        record_time>'2021-09-01'
+        order by record_time asc
+        limit ${limit}
+    </select>
 </mapper>

+ 52 - 0
web/src/main/java/com/jpsoft/shinestar/scheduled/UpdateWorkMinuteTask.java

@@ -0,0 +1,52 @@
+package com.jpsoft.shinestar.scheduled;
+
+import com.jpsoft.shinestar.modules.business.entity.WorkScheduleAttendance;
+import com.jpsoft.shinestar.modules.business.service.WorkScheduleAttendanceService;
+import com.jpsoft.shinestar.modules.common.utils.StringUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.joda.time.DateTime;
+import org.joda.time.Minutes;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+@Component
+@Slf4j
+@Transactional
+public class UpdateWorkMinuteTask {
+    @Autowired
+    private WorkScheduleAttendanceService workScheduleAttendanceService;
+
+    @Scheduled(cron = "0 0/10 * * * ?")
+    public void run() {
+        List<WorkScheduleAttendance> list = workScheduleAttendanceService.findEmptyWorkMinuteList(50);
+
+        for (WorkScheduleAttendance wsa : list) {
+            List<WorkScheduleAttendance> onWorkList = workScheduleAttendanceService.findByPersonScheduleIdAndClassify(wsa.getPersonScheduleId(), wsa.getWorkShiftId(), "1");
+
+            if(onWorkList.size()>0){
+                WorkScheduleAttendance workStartAttendance = onWorkList.get(0);
+
+                int workMinutes = 0;
+
+                if(StringUtils.isNotEmpty(workStartAttendance.getResult())
+                && !"0".equals(workStartAttendance.getResult())
+                && workStartAttendance.getRecordTime()!=null
+                ){
+                    workMinutes = Minutes.minutesBetween(
+                                    new DateTime(workStartAttendance.getRecordTime()),new DateTime(wsa.getRecordTime()))
+                            .getMinutes();
+                }
+
+                wsa.setWorkMinute(new BigDecimal(workMinutes));
+                wsa.setUpdateTime(new Date());
+                workScheduleAttendanceService.updateWorkMinute(wsa);
+            }
+        }
+    }
+}