18756
2024-08-14 5e83f17525b4c89ec05bec9f3520b3b323f0d255
考勤功能优化报表与考勤记录8.14
已修改2个文件
210 ■■■■■ 文件已修改
src/main/java/com/product/administration/service/PunchRecordService.java 176 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/administration/service/WorkAttendanceKanbanService.java 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/administration/service/PunchRecordService.java
@@ -1,12 +1,18 @@
package com.product.administration.service;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
@@ -55,6 +61,7 @@
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String sign_date = dateFormat.format(date1);
            fieldSetEntity.setValue("sign_date",sign_date);
            DateFormat dateFormatGet = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            //获取早退迟到的分钟数
            List<Object>param1=new ArrayList<>();
@@ -77,6 +84,52 @@
            sbPunchTime.append(" where LOCATE(?, concat(attendance_object,','))>0 ");
            sbPunchTime.append(" ) ");
            DataTableEntity dataTableEntity = baseDao.listTable(sbPunchTime.toString(), param1.toArray());
            //处理补卡的情况
            List<Object>param2=new ArrayList<>();
            param2.add(fieldSetEntity.getValue("created_by").toString());
            param2.add(sign_date);
            StringBuilder sbReplenish=new StringBuilder();
            sbReplenish.append(" SELECT T1.id,T1.uuid,T1.created_by,T1.applicant,T1.replenish_date,T1.reason,");
            sbReplenish.append(" SUBSTRING_INDEX( SUBSTRING_INDEX( T1.replacement_card_type, ',', T2.digit + 1 ), ',',- 1 ) AS type ");
            sbReplenish.append(" FROM product_oa_replenish_punch T1 ");
            sbReplenish.append(" JOIN ( SELECT 0 AS digit UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 ) T2");
            sbReplenish.append(" ON T2.digit < ( length( T1.replacement_card_type )- length( REPLACE ( T1.replacement_card_type, ',', '' ))+ 1 )");
            sbReplenish.append(" where t1.created_by=? ");
            sbReplenish.append(" and DATE_FORMAT( t1.replenish_date, '%Y-%m-%d' )=? ");
            DataTableEntity dataTableEntity1 = baseDao.listTable(sbReplenish.toString(), param2.toArray());
            if(dataTableEntity1.getRows()!=0){
                for(int j=0;j<dataTableEntity1.getRows();j++){
                    String type = dataTableEntity1.getData().get(j).getValue("type").toString();
                    if(type.equals("1")){
                        String morning_work = dataTableEntity.getData().get(0).getValue("morning_work").toString();
                        Date parse = dateFormatGet.parse(morning_work);
                        fieldSetEntity.setValue("punch_time_one", new Timestamp(parse.getTime()));
                    }
                    if(type.equals("2")){
                        String morning_work_off = dataTableEntity.getData().get(0).getValue("morning_work_off").toString();
                        Date parse = dateFormatGet.parse(morning_work_off);
                        fieldSetEntity.setValue("punch_time_two", new Timestamp(parse.getTime()));
                    }
                    if(type.equals("3")){
                        String afternoon_work = dataTableEntity.getData().get(0).getValue("afternoon_work").toString();
                        Date parse = dateFormatGet.parse(afternoon_work);
                        fieldSetEntity.setValue("punch_time_three", new Timestamp(parse.getTime()));
                    }
                    if(type.equals("4")){
                        String afternoon_work_off = dataTableEntity.getData().get(0).getValue("afternoon_work_off").toString();
                        Date parse = dateFormatGet.parse(afternoon_work_off);
                        fieldSetEntity.setValue("punch_time_four", new Timestamp(parse.getTime()));
                    }
                }
            }
            long beLate1 = 0;
            long beLate2 = 0;
            long beEarily1 = 0;
@@ -98,31 +151,33 @@
                DateTime punch_time_four_date;
                SimpleDateFormat dateFormatHHmmss = new SimpleDateFormat("HH:mm:ss");
                morning_work = dataTableEntity.getData().get(0).getValue("morning_work").toString();
                afternoon_work_off = dataTableEntity.getData().get(0).getValue("afternoon_work_off").toString();
                morning_work_date= DateUtil.parse(morning_work.split(" ")[1]);
                afternoon_work_off_date= DateUtil.parse(afternoon_work_off.split(" ")[1]);
                StringBuilder  lateSb=new StringBuilder();
                StringBuilder   earilySb=new StringBuilder();
                StringBuilder supereffective_distance=new StringBuilder();
                if(!ObjectUtil.isNotEmpty(dataTableEntity.getData().get(0).getValue("morning_work_off")) && !ObjectUtil.isNotEmpty(dataTableEntity.getData().get(0).getValue("afternoon_work"))){
                    int distance = Integer.parseInt(dataTableEntity.getData().get(0).getValue("distance").toString());
                    morning_work = dataTableEntity.getData().get(0).getValue("morning_work").toString();
                    afternoon_work_off = dataTableEntity.getData().get(0).getValue("afternoon_work_off").toString();
                    morning_work_date= DateUtil.parse(morning_work.split(" ")[1]);
                    afternoon_work_off_date= DateUtil.parse(afternoon_work_off.split(" ")[1]);
                    int distance = Integer.parseInt(dataTableEntity.getData().get(0).getValue("distance").toString());
                    if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_one"))){
                        String punch_time_one1 = dateFormatHHmmss.format(fieldSetEntity.getValue("punch_time_one"));
                        punch_time_one_date = DateUtil.parse(punch_time_one1);
                        beLate1 = DateUtil.between(punch_time_one_date, morning_work_date, DateUnit.MINUTE);
                        if(beLate1>0){
                        if(punch_time_one_date.after(morning_work_date)){
                            beLate1 = DateUtil.between(punch_time_one_date, morning_work_date, DateUnit.MINUTE);
                            lateSb.append("迟到:"+beLate1+"分钟");
                            //计算超出的有效距离
                            int punch_range_one = Integer.parseInt(fieldSetEntity.getValue("punch_range_one").toString());
                            if(punch_range_one>distance){
                                int distanceMorning = punch_range_one- distance;
                                fieldSetEntity.setValue("supereffective_distance","上班超有效距离:"+distanceMorning);
                            }
                        }
                        int punch_range_one = Integer.parseInt(fieldSetEntity.getValue("punch_range_one").toString());
                        if(punch_range_one>distance){
                            int distanceMorning = punch_range_one- distance;
                            fieldSetEntity.setValue("supereffective_distance","上班超有效距离:"+distanceMorning);
                        }
                    }else {
                        lateSb.append("上班未打卡");
                    }
@@ -130,35 +185,19 @@
                    if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_four"))){
                        String punch_time_four = dateFormatHHmmss.format(fieldSetEntity.getValue("punch_time_four"));
                        punch_time_four_date = DateUtil.parse(punch_time_four);
                        beEarily2 = DateUtil.between(punch_time_four_date, afternoon_work_off_date, DateUnit.MINUTE);
                        if(beEarily2>0){
                        if(punch_time_four_date.before(afternoon_work_off_date)){
                            beEarily2 = DateUtil.between(punch_time_four_date, afternoon_work_off_date, DateUnit.MINUTE);
                            earilySb.append("早退:"+beEarily2+"分钟");
                        }
                        int punch_range_four = Integer.parseInt(fieldSetEntity.getValue("punch_range_four").toString());
                        if(punch_range_four>distance){
                            int distanceMorning = punch_range_four- distance;
                            fieldSetEntity.setValue("supereffective_distance","下班超有效距离:"+distanceMorning);
                            int punch_range_four = Integer.parseInt(fieldSetEntity.getValue("punch_range_four").toString());
                            if(punch_range_four>distance){
                                int distanceMorning = punch_range_four- distance;
                                fieldSetEntity.setValue("supereffective_distance","下班超有效距离:"+distanceMorning);
                            }
                        }
                    }else {
                        earilySb.append("下班未打卡");
                    }
                    int punch_range_four = Integer.parseInt(fieldSetEntity.getValue("punch_range_four").toString());
                    int punch_range_one = Integer.parseInt(fieldSetEntity.getValue("punch_range_one").toString());
                    if(punch_range_one>distance){
                        fieldSetEntity.setValue("supereffective_distance",punch_range_one-distance);
                    }else if(punch_range_four>distance){
                        fieldSetEntity.setValue("supereffective_distance",punch_range_four-distance);
                    }else {
                        fieldSetEntity.setValue("supereffective_distance","正常");
                    }
                }else {
@@ -177,14 +216,15 @@
                    if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_one"))){
                        String punch_time_one1 = dateFormatHHmmss.format(fieldSetEntity.getValue("punch_time_one"));
                        punch_time_one_date = DateUtil.parse(punch_time_one1);
                        beLate1 = DateUtil.between(punch_time_one_date, morning_work_date, DateUnit.MINUTE);
                        if(beLate1>0){
                        if(punch_time_one_date.after(morning_work_date)){
                            beLate1 = DateUtil.between(punch_time_one_date, morning_work_date, DateUnit.MINUTE);
                            lateSb.append("早上班迟到:"+beLate1+" ");
                        }
                        int punch_range_one = Integer.parseInt(fieldSetEntity.getValue("punch_range_one").toString());
                        if(punch_range_one>distance){
                            int distanceMorning = punch_range_one- distance;
                            supereffective_distance.append("早上班超有效距离:"+distanceMorning);
                            int punch_range_one = Integer.parseInt(fieldSetEntity.getValue("punch_range_one").toString());
                            if(punch_range_one>distance){
                                int distanceMorning = punch_range_one- distance;
                                supereffective_distance.append("早上班超有效距离:"+distanceMorning);
                            }
                        }
                    }else {
@@ -195,16 +235,15 @@
                    if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_two"))){
                        String punch_time_two= dateFormatHHmmss.format(fieldSetEntity.getValue("punch_time_two"));
                        punch_time_two_date = DateUtil.parse(punch_time_two);
                        beEarily1 = DateUtil.between(punch_time_two_date, morning_work_off_date, DateUnit.MINUTE);
                        if(beEarily1>0){
                        if(punch_time_two_date.before(morning_work_off_date)){
                            beEarily1 = DateUtil.between(punch_time_two_date, morning_work_off_date, DateUnit.MINUTE);
                            earilySb.append("早下班早退:"+beEarily1+" ");
                            int punch_range_two = Integer.parseInt(fieldSetEntity.getValue("punch_range_two").toString());
                            if(punch_range_two>distance){
                                int distanceMorningoff = punch_range_two- distance;
                                supereffective_distance.append("早下班超有效距离:"+distanceMorningoff);
                            }
                        }
                        int punch_range_two = Integer.parseInt(fieldSetEntity.getValue("punch_range_two").toString());
                        if(punch_range_two>distance){
                            int distanceMorningoff = punch_range_two- distance;
                            supereffective_distance.append("早下班超有效距离:"+distanceMorningoff);
                        }
                    }else {
                        earilySb.append("早下班未打卡"+" ");
@@ -212,16 +251,14 @@
                    if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_three"))){
                        String punch_time_three = dateFormatHHmmss.format(fieldSetEntity.getValue("punch_time_three"));
                        punch_time_three_date = DateUtil.parse(punch_time_three);
                        beLate2 = DateUtil.between(punch_time_three_date, afternoon_work_date, DateUnit.MINUTE);
                        if(beLate2>0){
                        if(punch_time_three_date.after(afternoon_work_date)){
                            beLate2 = DateUtil.between(punch_time_three_date, afternoon_work_date, DateUnit.MINUTE);
                            lateSb.append("下午上班迟到:"+beLate2+" ");
                        }
                        int punch_range_three = Integer.parseInt(fieldSetEntity.getValue("punch_range_three").toString());
                        if(punch_range_three>distance){
                            int distanceAfternoon = punch_range_three- distance;
                            supereffective_distance.append("下午上班超有效距离:"+distanceAfternoon);
                            int punch_range_three = Integer.parseInt(fieldSetEntity.getValue("punch_range_three").toString());
                            if(punch_range_three>distance){
                                int distanceAfternoon = punch_range_three- distance;
                                supereffective_distance.append("下午上班超有效距离:"+distanceAfternoon);
                            }
                        }
                    }else {
                        lateSb.append("早上班未打卡"+" ");
@@ -229,30 +266,25 @@
                    if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_four"))){
                        String punch_time_four = dateFormatHHmmss.format(fieldSetEntity.getValue("punch_time_four"));
                        punch_time_four_date = DateUtil.parse(punch_time_four);
                        beEarily2 = DateUtil.between(punch_time_four_date, afternoon_work_off_date, DateUnit.MINUTE);
                        if(beEarily2>0){
                        if(punch_time_four_date.before(afternoon_work_off_date)){
                            beEarily2 = DateUtil.between(punch_time_four_date, afternoon_work_off_date, DateUnit.MINUTE);
                            earilySb.append("下午下班早退:"+beEarily2+" ");
                        }
                        int punch_range_four = Integer.parseInt(fieldSetEntity.getValue("punch_range_four").toString());
                        if(punch_range_four>distance){
                            int distanceAfternoonoff = punch_range_four- distance;
                            supereffective_distance.append("下午下班超有效距离:"+distanceAfternoonoff);
                        }
                            int punch_range_four = Integer.parseInt(fieldSetEntity.getValue("punch_range_four").toString());
                            if(punch_range_four>distance){
                                int distanceAfternoonoff = punch_range_four- distance;
                                supereffective_distance.append("下午下班超有效距离:"+distanceAfternoonoff);
                            }
                        }
                    }else {
                        earilySb.append("下午下班未打卡"+" ");
                    }
                }
                fieldSetEntity.setValue("be_late",lateSb);
                fieldSetEntity.setValue("ealy_leave",earilySb);
                fieldSetEntity.setValue("supereffective_distance",supereffective_distance.toString());
            }
        }
        dt.setFieldFormat("punch_time_one", " HH:mm");
src/main/java/com/product/administration/service/WorkAttendanceKanbanService.java
@@ -410,13 +410,43 @@
                dataTableEntity1.getData().get(0).setValue("leaveEarly",Integer.parseInt(fieldSetEntity.getValue("leaveEarly").toString())+Integer.parseInt(fieldSetEntity1.getValue("leaveEarly").toString()));
                dataTableEntity1.getData().get(0).setValue("workDayOfMonth",Integer.parseInt(fieldSetEntity.getValue("workDayOfMonth").toString())+Integer.parseInt(fieldSetEntity1.getValue("workDayOfMonth").toString()));
                dataTableEntity1.getData().get(0).setValue("absenteeism",Integer.parseInt(fieldSetEntity1.getValue("absenteeism").toString())-Integer.parseInt(fieldSetEntity.getValue("workDayOfMonth").toString()));
            }
        }
        //处理补卡的情况
        List<Object>param2=new ArrayList<>();
        param2.add(currentUser);
        param2.add(fse.getString("yearAndMonth"));
        StringBuilder sbReplenish=new StringBuilder();
        sbReplenish.append(" SELECT DISTINCT replenish_date ");
        sbReplenish.append(" FROM product_oa_replenish_punch ");
        sbReplenish.append(" WHERE");
        sbReplenish.append(" created_by =? ");
        sbReplenish.append(" AND DATE_FORMAT( replenish_date, '%Y-%m' )=? ");
        sbReplenish.append(" and DATE_FORMAT( replenish_date, '%Y-%m-%d') ");
        sbReplenish.append(" not in (");
        sbReplenish.append(" SELECT DISTINCT record_data FROM ");
        sbReplenish.append(" ( ");
        sbReplenish.append(" select  DATE_FORMAT(punch_time_one, '%Y-%m-%d') as record_data  from  product_oa_punch_record ");
        sbReplenish.append(" union all select  DATE_FORMAT(punch_time_two, '%Y-%m-%d') as record_data  from  product_oa_punch_record");
        sbReplenish.append(" union all select  DATE_FORMAT(punch_time_three, '%Y-%m-%d') as record_data  from  product_oa_punch_record");
        sbReplenish.append(" union all select  DATE_FORMAT(punch_time_four, '%Y-%m-%d') as record_data  from  product_oa_punch_record");
        sbReplenish.append(" )n )");
        DataTableEntity dataTableEntityReplenish = baseDao.listTable(sbReplenish.toString(), param2.toArray());
        if(dataTableEntityReplenish.getRows()!=0){
            dataTableEntity1.getData().get(0).setValue("workDayOfMonth",Integer.parseInt(dataTableEntity1.getData().get(0).getString("workDayOfMonth"))+dataTableEntityReplenish.getRows());
            dataTableEntity1.getData().get(0).setValue("dayOfWork",Integer.parseInt(dataTableEntity1.getData().get(0).getString("dayOfWork"))-dataTableEntityReplenish.getRows());
        }
        return  dataTableEntity1;
    }
}