| | |
| | | package com.product.administration.service; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | BaseDao baseDao; |
| | | |
| | | |
| | | /** |
| | | * 考勤报表 |
| | | * @param dept_uuid 部门 |
| | |
| | | Integer monthNum=Integer.valueOf(year_of_month.substring(5, 7)); //获取月份 |
| | | Integer yearNum=Integer.valueOf(year_of_month.substring(0,4)); //获取年份 |
| | | Integer totalDays=WorkDayUtil.getTotalDays(yearNum, monthNum); |
| | | |
| | | |
| | | |
| | | |
| | | StringBuilder sb=new StringBuilder(); |
| | | sb.append(" SELECT USER_ID, "); |
| | | for (int i = 1; i <= totalDays; i++) { |
| | |
| | | sb.append(" )a GROUP BY USER_ID,DATETIME ORDER BY USER_ID,DATETIME "); |
| | | sb.append(" )a "); |
| | | sb.append(" GROUP BY USER_ID "); |
| | | |
| | | |
| | | return baseDao.listTable(sb.toString(), new Object[] {year_of_month,year_of_month,year_of_month}); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 打卡月看板 |
| | | * @param fse |
| | |
| | | SystemUser currentUser=SpringMVCContextHolder.getCurrentUser(); |
| | | Integer user_id=currentUser.getUser_id(); //user_id |
| | | String org_level_uuid=currentUser.getOrg_level_uuid(); //公司uuid |
| | | |
| | | |
| | | //获取公司工作时间配置信息 |
| | | FieldSetEntity fseCompanyPunch=baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_OA_PUNCH_TIME, "org_level_uuid=?", new Object[] {org_level_uuid}, false); |
| | | if (fseCompanyPunch==null) { |
| | | throw new BaseException(SystemCode.COMPANY_PUNCH_TIME_NOT_CONFIG.getValue(), SystemCode.COMPANY_PUNCH_TIME_NOT_CONFIG.getText(), this.getClass(), "listMonthKanBan"); |
| | | } |
| | | |
| | | |
| | | //获取查询月份 |
| | | String yearAndMonth=fse.getString("yearAndMonth"); |
| | | if (StringUtils.isEmpty(yearAndMonth)) { |
| | | yearAndMonth=DateUtils.formatDate(new Date(), "yyyy-MM"); |
| | | } |
| | | |
| | | |
| | | int workTimeMethod=0; |
| | | if (!StringUtils.isEmpty(fseCompanyPunch.getString("work_time_two")) && !StringUtils.isEmpty(fseCompanyPunch.getString("work_time_three"))) { |
| | | workTimeMethod=1; |
| | | } |
| | | StringBuilder sb=new StringBuilder(); |
| | | List<Object> param=new ArrayList<>(); |
| | | |
| | | |
| | | sb.append(" SELECT "); |
| | | sb.append(" DATE_FORMAT(created_utc_datetime,'%Y-%m-%d')punch_date, "); |
| | | sb.append(" punch_time_one,IF(punch_time_one IS TRUE,IF(DATE_FORMAT(punch_time_one,'%H:%i:%S')>?,'迟到','正常'),'未打卡')result_one, "); |
| | | sb.append(" punch_time_one,IF(punch_time_one IS TRUE,IF(DATE_FORMAT(punch_time_one,'%H:%i:%S')>?,'迟到','正常'),'上午上班未打卡')result_one, "); |
| | | param.add(fseCompanyPunch.getDate("work_time_one","HH:mm:ss")); |
| | | |
| | | |
| | | if (workTimeMethod==1) { |
| | | sb.append(" punch_time_two,IF(punch_time_two IS TRUE,IF(DATE_FORMAT(punch_time_two,'%H:%i:%S')<?,'早退','正常'),'未打卡')result_two, "); |
| | | sb.append(" punch_time_two,IF(punch_time_two IS TRUE,IF(DATE_FORMAT(punch_time_two,'%H:%i:%S')<?,'早退','正常'),'上午下班未打卡')result_two, "); |
| | | param.add(fseCompanyPunch.getDate("work_time_two","HH:mm:ss")); |
| | | sb.append(" punch_time_three,IF(punch_time_three IS TRUE,IF(DATE_FORMAT(punch_time_three,'%H:%i:%S')>?,'迟到','正常'),'未打卡')result_three, "); |
| | | sb.append(" punch_time_three,IF(punch_time_three IS TRUE,IF(DATE_FORMAT(punch_time_three,'%H:%i:%S')>?,'迟到','正常'),'下午上班未打卡')result_three, "); |
| | | param.add(fseCompanyPunch.getDate("work_time_three","HH:mm:ss")); |
| | | } |
| | | |
| | | sb.append(" punch_time_four,IF(punch_time_four IS TRUE,IF(DATE_FORMAT(punch_time_four,'%H:%i:%S')<?,'早退','正常'),'未打卡')result_four "); |
| | | |
| | | sb.append(" punch_time_four,IF(punch_time_four IS TRUE,IF(DATE_FORMAT(punch_time_four,'%H:%i:%S')<?,'早退','正常'),'下午上班未打卡')result_four "); |
| | | param.add(fseCompanyPunch.getDate("work_time_four","HH:mm:ss")); |
| | | |
| | | |
| | | sb.append(" FROM product_oa_punch_record WHERE created_by=?"); |
| | | sb.append(" AND DATE_FORMAT(created_utc_datetime,'%Y-%m')=? "); |
| | | sb.append(" AND DATE_FORMAT(created_utc_datetime,'%Y-%m-%d') NOT IN (SELECT DATE_FORMAT(date_holiday,'%Y-%m-%d')FROM product_sys_company_holiday WHERE org_level_uuid=?) "); |
| | | param.add(user_id); |
| | | param.add(yearAndMonth); |
| | | param.add(org_level_uuid); |
| | | |
| | | |
| | | return baseDao.listTable(sb.toString(), param.toArray()); |
| | | } |
| | | |
| | | /** |
| | | * 打卡月看板(新) |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public DataTableEntity listMonthKanBanNew(FieldSetEntity fse) { |
| | | //获取当前人信息 |
| | | Integer user_id=fse.getInteger("user_id"); //user_id |
| | | if(user_id==null){ |
| | | return null; |
| | | } |
| | | |
| | | //获取查询月份 |
| | | String yearAndMonth=fse.getString("yearAndMonth"); |
| | | if (StringUtils.isEmpty(yearAndMonth)) { |
| | | yearAndMonth=DateUtils.formatDate(new Date(), "yyyy-MM"); |
| | | } |
| | | |
| | | |
| | | StringBuilder sb=new StringBuilder(); |
| | | List<Object> param=new ArrayList<>(); |
| | | |
| | | sb.append(" SELECT a.punch_date,e.bk,f.morning_work,f.morning_work_off,f.afternoon_work,f.afternoon_work_off, "); |
| | | |
| | | sb.append(" CONCAT(if(d.punch_range_one is not null and d.punch_range_one>f.distance,'超出打卡范围',0) "); |
| | | sb.append(" ,',',if(d.punch_range_two is not null and d.punch_range_two>f.distance,'超出打卡范围',0) "); |
| | | sb.append(" ,',',if(d.punch_time_three is not null and d.punch_time_three>f.distance,'超出打卡范围',0) "); |
| | | sb.append(" ,',',if(d.punch_range_four is not null and d.punch_range_four>f.distance,'超出打卡范围',0)) dkfw, "); |
| | | sb.append(" CASE WHEN b.uuid is not null THEN c.dict_label ELSE "); |
| | | sb.append(" CASE WHEN d.uuid is not null THEN "); |
| | | sb.append(" CONCAT(IF(d.punch_time_one IS TRUE, IF ( DATE_FORMAT(d.punch_time_one, '%H:%i:%S' )>DATE_FORMAT(f.morning_work, '%H:%i:%S'), CONCAT('上午迟到',TIMESTAMPDIFF(MINUTE, DATE_FORMAT(CONCAT(a.punch_date,' ',DATE_FORMAT(f.morning_work, '%H:%i:%S')),'%Y-%m-%d %H:%i:%S'),d.punch_time_one),'分钟'), 0 ), '上午上班未打卡' ) "); |
| | | sb.append(" ,',',IF(d.punch_time_two IS TRUE, IF ( DATE_FORMAT(d.punch_time_two, '%H:%i:%S' )<DATE_FORMAT(f.morning_work_off, '%H:%i:%S') and f.morning_work_off is not null, CONCAT('上午早退',TIMESTAMPDIFF(MINUTE,d.punch_time_two,DATE_FORMAT(CONCAT(a.punch_date,' ',DATE_FORMAT(f.morning_work_off, '%H:%i:%S')),'%Y-%m-%d %H:%i:%S')),'分钟'), 0 ), '上午下班未打卡' ) "); |
| | | sb.append(" ,',',IF(d.punch_time_three IS TRUE, IF ( DATE_FORMAT(d.punch_time_three, '%H:%i:%S' )>DATE_FORMAT(f.afternoon_work, '%H:%i:%S') and f.afternoon_work is not null, CONCAT('下午迟到',TIMESTAMPDIFF(MINUTE, DATE_FORMAT(CONCAT(a.punch_date,' ',DATE_FORMAT(f.afternoon_work, '%H:%i:%S')),'%Y-%m-%d %H:%i:%S'),d.punch_time_three),'分钟'), 0 ), '下午上班未打卡' ) "); |
| | | sb.append(" ,',',IF(d.punch_time_four IS TRUE, IF ( DATE_FORMAT(d.punch_time_four, '%H:%i:%S' )<DATE_FORMAT(f.afternoon_work_off, '%H:%i:%S'), CONCAT('下午早退',TIMESTAMPDIFF(MINUTE,d.punch_time_four,DATE_FORMAT(CONCAT(a.punch_date,' ',DATE_FORMAT(f.afternoon_work_off, '%H:%i:%S')),'%Y-%m-%d %H:%i:%S')),'分钟'), 0 ), '下午下班未打卡' )) "); |
| | | sb.append(" ELSE '全天未打卡' END END reidis,CASE WHEN b.uuid is not null THEN 1 ELSE CASE WHEN d.uuid is not null THEN 0 ELSE 2 END END type "); |
| | | sb.append(" FROM (SELECT CONCAT(DATE_FORMAT(?, '%Y-%m-'),IF(i<9,CONCAT('0',i + 1),i + 1)) punch_date "); |
| | | param.add(yearAndMonth+"-01"); |
| | | sb.append(" FROM (SELECT @row := @row + 1 as i FROM "); |
| | | sb.append(" (SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) t1, "); |
| | | sb.append(" (SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) t2, "); |
| | | sb.append(" (SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) t3, "); |
| | | sb.append(" (SELECT 0 UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5) t4, "); |
| | | sb.append(" (SELECT @row := -1) t0) d WHERE i < DAY(last_day(DATE_FORMAT(?, '%Y-%m-01')))) a "); |
| | | param.add(yearAndMonth+"-01"); |
| | | sb.append(" LEFT JOIN (SELECT * FROM product_oa_ask_for_leave WHERE user_id=? and flow_flag=2) b "); |
| | | param.add(user_id); |
| | | sb.append(" on DATE_FORMAT( a.punch_date, '%Y-%m-%d' )>= DATE_FORMAT( b.start_time, '%Y-%m-%d' ) and DATE_FORMAT( a.punch_date, '%Y-%m-%d' )<= DATE_FORMAT( b.end_time, '%Y-%m-%d' ) "); |
| | | sb.append(" LEFT JOIN (SELECT * FROM product_sys_dict where dict_name='Leave_Type') c on b.leave_type =c.dict_value "); |
| | | sb.append(" LEFT JOIN product_oa_punch_record d on a.punch_date=DATE_FORMAT( d.punch_time_one, '%Y-%m-%d' ) "); |
| | | sb.append(" LEFT JOIN (SELECT applicant,DATE_FORMAT( replenish_date, '%Y-%m-%d') replenish_date,max(replacement_card_type) bk FROM product_oa_replenish_punch "); |
| | | sb.append(" where applicant=? and flow_flag=2 GROUP BY applicant,DATE_FORMAT( replenish_date, '%Y-%m-%d')) e on a.punch_date=e.replenish_date "); |
| | | param.add(user_id); |
| | | sb.append(" LEFT JOIN product_oa_punch_time f on d.punch_congfig_uuid =f.punch_site_uuid "); |
| | | sb.append(" where a.punch_date NOT IN (SELECT DATE_FORMAT( date_holiday, '%Y-%m-%d' ) FROM product_sys_company_holiday) "); |
| | | DataTableEntity dt = baseDao.listTable(sb.toString(), param.toArray()); |
| | | for (int i = 0; i < dt.getRows(); i++) { |
| | | FieldSetEntity fs = dt.getFieldSetEntity(i); |
| | | //获取补卡标识 |
| | | List<String> bk=new ArrayList<>(); |
| | | if (!StringUtils.isEmpty(fs.getString("bk"))){ |
| | | bk= Arrays.asList(fs.getString("bk").split(",")); |
| | | } |
| | | if (fs.getString("reidis").equals("全天未打卡")&&!StringUtils.isEmpty(fs.getString("bk"))){ |
| | | if (!bk.contains("1")){ |
| | | fs.setValue("result_one", "上午上班未打卡"); |
| | | } |
| | | if (!bk.contains("2")&&!StringUtils.isEmpty(fs.getString("morning_work_off"))){ |
| | | fs.setValue("result_two", "上午下班未打卡"); |
| | | } |
| | | if (!bk.contains("3")&&!StringUtils.isEmpty(fs.getString("afternoon_work"))){ |
| | | fs.setValue("result_three", "下午上班未打卡"); |
| | | } |
| | | if (!bk.contains("4")){ |
| | | fs.setValue("result_four", "下午下班未打卡"); |
| | | } |
| | | continue; |
| | | } |
| | | if ("0".equals(fs.getString("type"))){ |
| | | String[] reidis = fs.getString("reidis").split(","); |
| | | String[] dkfwsArr = fs.getString("dkfw").split(","); |
| | | String a="1"; |
| | | for (int j = 0; j < reidis.length; j++) { |
| | | String dkfws=""; |
| | | if (!dkfwsArr[j].equals("0")){ |
| | | dkfws=dkfwsArr[j]; |
| | | } |
| | | if (reidis[j].contains("上午迟到")) { |
| | | if (!bk.contains("1")) { |
| | | fs.setValue("result_one", reidis[j]+dkfws); |
| | | a = "2"; |
| | | } |
| | | } |
| | | if (reidis[j].contains("上午早退")) { |
| | | if (!bk.contains("2")) { |
| | | fs.setValue("result_two", reidis[j]+dkfws); |
| | | a = "2"; |
| | | } |
| | | } |
| | | if (reidis[j].contains("下午迟到")) { |
| | | if (!bk.contains("3")) { |
| | | fs.setValue("result_three", reidis[j]+dkfws); |
| | | a = "2"; |
| | | } |
| | | } |
| | | if (reidis[j].contains("下午早退")) { |
| | | if (!bk.contains("3")) { |
| | | fs.setValue("result_four", reidis[j]+dkfws); |
| | | a = "2"; |
| | | } |
| | | } |
| | | } |
| | | if ("1".equals(a)){ |
| | | fs.setValue("type",a); |
| | | fs.setValue("result_one","正常打卡"); |
| | | } |
| | | |
| | | }else { |
| | | fs.setValue("result_one",fs.getString("reidis")); |
| | | } |
| | | } |
| | | return dt; |
| | | } |
| | | /** |
| | | * 考勤统计报表 |
| | | * @param fse |
| | | * @return |
| | | */ |
| | | public DataTableEntity listMonthReport(FieldSetEntity fse) { |
| | | |
| | | |
| | | //获取当前人信息 |
| | | SystemUser currentUser=SpringMVCContextHolder.getCurrentUser(); |
| | | String org_level_uuid=currentUser.getOrg_level_uuid(); |
| | | |
| | | //获取公司工作时间配置信息 |
| | | FieldSetEntity fseCompanyPunch=baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_OA_PUNCH_TIME, "org_level_uuid=?", new Object[] {org_level_uuid}, false); |
| | | if (fseCompanyPunch==null) { |
| | | throw new BaseException(SystemCode.COMPANY_PUNCH_TIME_NOT_CONFIG.getValue(), SystemCode.COMPANY_PUNCH_TIME_NOT_CONFIG.getText(), this.getClass(), "listMonthReport"); |
| | | List<Object>param1=new ArrayList<>(); |
| | | param1.add(currentUser.getUser_id()); |
| | | param1.add(currentUser.getUser_id()+","); |
| | | //获取使用到的设置规则 |
| | | StringBuilder sbPunchTime=new StringBuilder(); |
| | | sbPunchTime.append(" SELECT DISTINCT c.* "); |
| | | sbPunchTime.append(" FROM ( "); |
| | | sbPunchTime.append(" SELECT d.* "); |
| | | sbPunchTime.append(" FROM product_oa_punch_time d "); |
| | | sbPunchTime.append(" left JOIN product_oa_punch_record b "); |
| | | sbPunchTime.append(" on d.punch_site_uuid=b.punch_congfig_uuid and d.created_by=? "); |
| | | sbPunchTime.append(" ) c "); |
| | | sbPunchTime.append(" where c.uuid in ( "); |
| | | sbPunchTime.append(" SELECT DISTINCT uuid "); |
| | | sbPunchTime.append(" FROM product_oa_punch_time "); |
| | | sbPunchTime.append(" where LOCATE(?, concat(attendance_object,','))>0 "); |
| | | sbPunchTime.append(" ) "); |
| | | DataTableEntity dataTableEntity = baseDao.listTable(sbPunchTime.toString(), param1.toArray()); |
| | | List<DataTableEntity> dataTableEntityLits=new ArrayList<>(); |
| | | for(int i=0;i<dataTableEntity.getRows();i++){ |
| | | |
| | | FieldSetEntity fseCompanyPunch = dataTableEntity.getData().get(i); |
| | | if (fseCompanyPunch==null) { |
| | | throw new BaseException(SystemCode.COMPANY_PUNCH_TIME_NOT_CONFIG.getValue(), SystemCode.COMPANY_PUNCH_TIME_NOT_CONFIG.getText(), this.getClass(), "listMonthReport"); |
| | | } |
| | | //获取查询月份 |
| | | String yearAndMonth=fse.getString("yearAndMonth"); |
| | | if (StringUtils.isEmpty(yearAndMonth)) { |
| | | yearAndMonth=DateUtils.formatDate(new Date(), "yyyy-MM"); |
| | | } |
| | | |
| | | //获取每月天数 |
| | | int dayOfMonth = DateUtils.getMonthHasDays(DateUtils.parseDate(yearAndMonth)); |
| | | //获取本月节假日 |
| | | DataTableEntity dtHoliday=baseDao.listTable("product_sys_company_holiday", "date_holiday like ?", new Object[] {yearAndMonth+"%"}); |
| | | //获取每月应上班天数 |
| | | int dayOfWork = 0; |
| | | if (BaseUtil.dataTableIsEmpty(dtHoliday)) { |
| | | dayOfWork=dayOfMonth; |
| | | }else { |
| | | dayOfWork=dayOfMonth-dtHoliday.getRows(); |
| | | } |
| | | |
| | | |
| | | StringBuilder sb=new StringBuilder(); |
| | | List<Object>param=new ArrayList<>(); |
| | | String morinng_work = fseCompanyPunch.getValue("morning_work").toString().split(" ")[1]; |
| | | param.add(morinng_work); |
| | | if(ObjectUtil.isNotEmpty(fseCompanyPunch.getValue("morning_work_off"))&& ObjectUtil.isNotEmpty(fseCompanyPunch.getValue("afternoon_work"))){ |
| | | String morinng_work_off = fseCompanyPunch.getValue("morning_work_off").toString().split(" ")[1]; |
| | | String afternoon_work = fseCompanyPunch.getValue("afternoon_work").toString().split(" ")[1]; |
| | | param.add(afternoon_work); |
| | | param.add(morinng_work_off); |
| | | } |
| | | |
| | | String afternoon_work_off = fseCompanyPunch.getValue("afternoon_work_off").toString().split(" ")[1]; |
| | | String uuid = fseCompanyPunch.getValue("uuid").toString(); |
| | | |
| | | param.add(afternoon_work_off); |
| | | param.add(yearAndMonth); |
| | | param.add(uuid); |
| | | param.add(yearAndMonth); |
| | | param.add(yearAndMonth); |
| | | sb.append(" SELECT "); |
| | | sb.append(" (SELECT user_name FROM product_sys_users WHERE user_id=a.created_by)created_by, "); |
| | | sb.append(" (SELECT org_level_name FROM product_sys_org_levels WHERE uuid=dept_uuid)dept_uuid, "); |
| | | sb.append(" dayOfWork,workDayOfMonth,lateCome,leaveEarly,total_hours,casual_leave,medical_leave,marriage_leave,paid_leave,other_leave,(dayOfWork-workDayOfMonth)absenteeism "); |
| | | sb.append(" FROM ( "); |
| | | if(ObjectUtil.isNotEmpty(fseCompanyPunch.getValue("morning_work_off"))&& ObjectUtil.isNotEmpty(fseCompanyPunch.getValue("afternoon_work"))){ |
| | | sb.append(" SELECT b.created_by,b.dayOfWork,b.workDayOfMonth,b.dept_uuid,b.lateCome1+b.lateCome2 lateCome,b.leaveEarly1+b.leaveEarly2 leaveEarly"); |
| | | }else { |
| | | sb.append(" SELECT b.created_by,b.dayOfWork,b.workDayOfMonth,b.dept_uuid,b.lateCome1 lateCome,b.leaveEarly2 leaveEarly"); |
| | | } |
| | | |
| | | sb.append(" FROM ( "); |
| | | sb.append(" SELECT "); |
| | | sb.append(" a.created_by,"+dayOfWork+" dayOfWork,COUNT(day_of_month)workDayOfMonth,a.dept_uuid, "); |
| | | sb.append(" COUNT("); |
| | | sb.append(" IF "); |
| | | sb.append(" ( result1 = '迟到', TRUE, NULL )) lateCome1,"); |
| | | if(ObjectUtil.isNotEmpty(fseCompanyPunch.getValue("morning_work_off"))&& ObjectUtil.isNotEmpty(fseCompanyPunch.getValue("afternoon_work"))){ |
| | | sb.append(" COUNT("); |
| | | sb.append(" IF "); |
| | | sb.append(" ( result2 = '迟到', TRUE, NULL )) lateCome2,"); |
| | | sb.append(" COUNT("); |
| | | sb.append(" IF "); |
| | | sb.append(" ( result3 = '早退', TRUE, NULL )) leaveEarly1,"); |
| | | |
| | | } |
| | | sb.append(" COUNT("); |
| | | sb.append(" IF "); |
| | | sb.append(" ( result4 = '早退', TRUE, NULL )) leaveEarly2 "); |
| | | sb.append(" FROM ( "); |
| | | sb.append(" SELECT d.created_by,d.dept_uuid,DATE_FORMAT( d.created_utc_datetime, '%Y-%m-%d' ) day_of_month,punch_time_one, "); |
| | | sb.append(" IF "); |
| | | sb.append(" ( punch_time_one IS TRUE, IF ( DATE_FORMAT( punch_time_one, '%H:%i:%S' )> ?, '迟到', '正常' ), '未打卡' ) "); |
| | | sb.append(" result1 ,"); |
| | | if(ObjectUtil.isNotEmpty(fseCompanyPunch.getValue("morning_work_off"))&& ObjectUtil.isNotEmpty(fseCompanyPunch.getValue("afternoon_work"))){ |
| | | sb.append(" IF "); |
| | | sb.append(" ( punch_time_three IS TRUE, IF ( DATE_FORMAT( punch_time_three, '%H:%i:%S' )> ?, '迟到', '正常' ), '未打卡' ) "); |
| | | sb.append(" result2 ,"); |
| | | sb.append(" IF "); |
| | | sb.append(" ( punch_time_two IS TRUE, IF ( DATE_FORMAT( punch_time_two, '%H:%i:%S' )< ?, '早退', '正常' ), '未打卡' ) "); |
| | | sb.append(" result3 ,"); |
| | | } |
| | | |
| | | sb.append(" IF "); |
| | | sb.append(" ( punch_time_four IS TRUE, IF ( DATE_FORMAT( punch_time_four, '%H:%i:%S' ) < ?, '早退', '正常' ), '未打卡' ) "); |
| | | sb.append(" result4 "); |
| | | sb.append(" FROM product_oa_punch_record d "); |
| | | sb.append(" left JOIN product_oa_punch_time e "); |
| | | sb.append(" on d.punch_congfig_uuid=e.punch_site_uuid "); |
| | | sb.append(" and DATE_FORMAT( d.created_utc_datetime,'%Y-%m')=? AND DATE_FORMAT(punch_time_one,'%Y-%m-%d') NOT IN(SELECT date_holiday FROM product_sys_company_holiday) "); |
| | | sb.append(" where e.uuid=? "); |
| | | sb.append(" )a "); |
| | | sb.append(" GROUP BY a.created_by,a.dept_uuid "); |
| | | sb.append(" )b"); |
| | | sb.append(" )a "); |
| | | sb.append(" LEFT JOIN (SELECT user_id, sum( duration ) total_hours FROM product_oa_work_overtime o left join product_oa_work_overtime_sub b on o.uuid=b.main_uuid and DATE_FORMAT( b.start_time, '%Y-%m' )=? GROUP BY o.user_id)b "); |
| | | sb.append(" ON a.created_by=b.user_id "); |
| | | sb.append(" LEFT JOIN ( "); |
| | | sb.append(" SELECT "); |
| | | sb.append(" created_by,sum(IF(leave_type=1,TRUE,0))casual_leave,sum(IF(leave_type=2,TRUE,0))medical_leave, "); |
| | | sb.append(" sum(IF(leave_type=9,TRUE,0))marriage_leave,sum(IF(leave_type=4,TRUE,0))paid_leave, "); |
| | | sb.append(" sum(IF(leave_type!=1 && leave_type!=2 && leave_type!=4 && leave_type!=9,TRUE,0))other_leave "); |
| | | sb.append(" FROM product_oa_ask_for_leave "); |
| | | sb.append(" WHERE DATE_FORMAT(start_time,'%Y-%m')=? and flow_flag=2 "); |
| | | sb.append(" GROUP BY created_by "); |
| | | sb.append(" )c "); |
| | | sb.append(" ON a.created_by=c.created_by "); |
| | | sb.append(" ORDER BY dept_uuid,a.created_by "); |
| | | DataTableEntity dataTableEntityReport = baseDao.listTable(sb.toString(), param.toArray()); |
| | | if(dataTableEntityReport.getRows()!=0){ |
| | | dataTableEntityLits.add(baseDao.listTable(sb.toString(), param.toArray())); |
| | | } |
| | | |
| | | } |
| | | |
| | | //获取查询月份 |
| | | String yearAndMonth=fse.getString("yearAndMonth"); |
| | | if (StringUtils.isEmpty(yearAndMonth)) { |
| | | yearAndMonth=DateUtils.formatDate(new Date(), "yyyy-MM"); |
| | | DataTableEntity dataTableEntity1=new DataTableEntity(); |
| | | if(ObjectUtil.isNotEmpty(dataTableEntityLits)){ |
| | | dataTableEntity1=dataTableEntityLits.get(0); |
| | | //本月内迟到早退数的累加 |
| | | for (int i = 1; i < dataTableEntityLits.size(); i++) { |
| | | FieldSetEntity fieldSetEntity = dataTableEntityLits.get(i).getData().get(0); |
| | | FieldSetEntity fieldSetEntity1 = dataTableEntity1.getData().get(0); |
| | | dataTableEntity1.getData().get(0).setValue("lateCome",Integer.parseInt(fieldSetEntity.getValue("lateCome").toString())+Integer.parseInt(fieldSetEntity1.getValue("lateCome").toString())); |
| | | 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())); |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | //获取每月天数 |
| | | int dayOfMonth = DateUtils.getMonthHasDays(DateUtils.parseDate(yearAndMonth)); |
| | | //获取本月节假日 |
| | | DataTableEntity dtHoliday=baseDao.listTable("product_sys_company_holiday", "date_holiday like ?", new Object[] {yearAndMonth+"%"}); |
| | | //获取每月应上班天数 |
| | | int dayOfWork = 0; |
| | | if (BaseUtil.dataTableIsEmpty(dtHoliday)) { |
| | | dayOfWork=dayOfMonth; |
| | | }else { |
| | | dayOfWork=dayOfMonth-dtHoliday.getRows(); |
| | | |
| | | //处理补卡的情况 |
| | | 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 =? and flow_flag=2"); |
| | | 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()); |
| | | } |
| | | |
| | | //workTimeMethod 0:上午上班,下午下班 1:一卡 2:四卡 3:上午上班,下午上班 |
| | | int workTimeMethod=0; |
| | | if (StringUtils.isEmpty(fseCompanyPunch.getString("work_time_two")) && StringUtils.isEmpty(fseCompanyPunch.getString("work_time_three")) && StringUtils.isEmpty(fseCompanyPunch.getString("work_time_four"))) { |
| | | workTimeMethod=1; |
| | | } else if (!StringUtils.isEmpty(fseCompanyPunch.getString("work_time_two")) && !StringUtils.isEmpty(fseCompanyPunch.getString("work_time_three")) && !StringUtils.isEmpty(fseCompanyPunch.getString("work_time_four"))) { |
| | | workTimeMethod=2; |
| | | } else if (StringUtils.isEmpty(fseCompanyPunch.getString("work_time_two")) && StringUtils.isEmpty(fseCompanyPunch.getString("work_time_four"))) { |
| | | workTimeMethod=3; |
| | | } |
| | | |
| | | StringBuilder sb=new StringBuilder(); |
| | | List<Object>param=new ArrayList<>(); |
| | | param.add(yearAndMonth); |
| | | param.add(yearAndMonth); |
| | | param.add(yearAndMonth); |
| | | sb.append(" SELECT "); |
| | | sb.append(" (SELECT user_name FROM product_sys_users WHERE user_id=a.created_by)created_by, "); |
| | | sb.append(" (SELECT org_level_name FROM product_sys_org_levels WHERE uuid=dept_uuid)dept_uuid, "); |
| | | sb.append(" dayOfWork,workDayOfMonth,lateCome,leaveEarly,total_hours,casual_leave,medical_leave,marriage_leave,paid_leave,other_leave,(dayOfWork-workDayOfMonth)absenteeism "); |
| | | sb.append(" FROM ( "); |
| | | sb.append(" SELECT "); |
| | | sb.append(" a.created_by,"+dayOfWork+" dayOfWork,COUNT(day_of_month)workDayOfMonth,a.dept_uuid, "); |
| | | |
| | | if (workTimeMethod==0) { |
| | | sb.append(" COUNT(IF(result1='迟到',TRUE,NULL)) lateCome, "); |
| | | sb.append(" COUNT(IF(result4='早退',TRUE,NULL)) leaveEarly "); |
| | | }else if (workTimeMethod==1) { |
| | | sb.append(" COUNT(IF(result1='迟到',TRUE,NULL)) lateCome, "); |
| | | sb.append(" 0 leaveEarly "); |
| | | }else if (workTimeMethod==2) { |
| | | sb.append(" COUNT(IF(result1='迟到',TRUE,NULL))+COUNT(IF(result3='迟到',TRUE,NULL)) lateCome, "); |
| | | sb.append(" COUNT(IF(result2='早退',TRUE,NULL))+COUNT(IF(result4='早退',TRUE,NULL)) leaveEarly "); |
| | | }else if (workTimeMethod==3) { |
| | | sb.append(" COUNT(IF(result1='迟到',TRUE,NULL))+COUNT(IF(result3='迟到',TRUE,NULL)) lateCome, "); |
| | | sb.append(" 0 leaveEarly "); |
| | | } |
| | | /* |
| | | if (workTimeMethod==1) { |
| | | sb.append(" COUNT(IF(result1='迟到',TRUE,NULL))+COUNT(IF(result3='迟到',TRUE,NULL)) lateCome, "); |
| | | sb.append(" COUNT(IF(result2='早退',TRUE,NULL))+COUNT(IF(result4='早退',TRUE,NULL)) leaveEarly "); |
| | | } else if (workTimeMethod==2) { |
| | | sb.append(""); |
| | | } else if (workTimeMethod==3) { |
| | | |
| | | } else { |
| | | sb.append(" COUNT(IF(result1='迟到',TRUE,NULL)) lateCome, "); |
| | | sb.append(" COUNT(IF(result4='早退',TRUE,NULL)) leaveEarly "); |
| | | } |
| | | */ |
| | | sb.append(" FROM ( "); |
| | | sb.append(" SELECT "); |
| | | sb.append(" created_by,dept_uuid, "); |
| | | sb.append(" DATE_FORMAT(created_utc_datetime,'%Y-%m-%d') day_of_month, "); |
| | | sb.append(" punch_time_one,IF(punch_time_one IS TRUE,IF(DATE_FORMAT(punch_time_one,'%H:%i:%S')>'09:00:00','迟到','正常'),'未打卡') result1 "); |
| | | |
| | | // sb.append(" punch_time_two,IF(punch_time_two IS TRUE,IF(DATE_FORMAT(punch_time_two,'%H:%i:%S')<'12:00:00','早退','正常'),'未打卡') result2, "); |
| | | // sb.append(" punch_time_three,IF(punch_time_three IS TRUE,IF(DATE_FORMAT(punch_time_three,'%H:%i:%S')>'14:00:00','迟到','正常'),'未打卡') result3, "); |
| | | // sb.append(" punch_time_four,IF(punch_time_four IS TRUE,IF(DATE_FORMAT(punch_time_four,'%H:%i:%S')<'17:00:00','早退','正常'),'未打卡') result4 "); |
| | | if (workTimeMethod==0) { |
| | | sb.append(", punch_time_four,IF(punch_time_four IS TRUE,IF(DATE_FORMAT(punch_time_four,'%H:%i:%S')<'17:00:00','早退','正常'),'未打卡') result4 "); |
| | | }else if (workTimeMethod==2) { |
| | | sb.append(", punch_time_two,IF(punch_time_two IS TRUE,IF(DATE_FORMAT(punch_time_two,'%H:%i:%S')<'12:00:00','早退','正常'),'未打卡') result2 "); |
| | | sb.append(", punch_time_three,IF(punch_time_three IS TRUE,IF(DATE_FORMAT(punch_time_three,'%H:%i:%S')>'14:00:00','迟到','正常'),'未打卡') result3 "); |
| | | sb.append(", punch_time_four,IF(punch_time_four IS TRUE,IF(DATE_FORMAT(punch_time_four,'%H:%i:%S')<'17:00:00','早退','正常'),'未打卡') result4 "); |
| | | }else if (workTimeMethod==3) { |
| | | sb.append(", punch_time_three,IF(punch_time_three IS TRUE,IF(DATE_FORMAT(punch_time_three,'%H:%i:%S')>'14:00:00','迟到','正常'),'未打卡') result3 "); |
| | | } |
| | | |
| | | sb.append(" FROM product_oa_punch_record "); |
| | | sb.append(" WHERE DATE_FORMAT(created_utc_datetime,'%Y-%m')=? AND DATE_FORMAT(punch_time_one,'%Y-%m-%d') NOT IN(SELECT date_holiday FROM product_sys_company_holiday) "); |
| | | sb.append(" )a "); |
| | | sb.append(" GROUP BY a.created_by,a.dept_uuid "); |
| | | sb.append(" )a "); |
| | | sb.append(" LEFT JOIN (SELECT user_id,sum(total_hours)total_hours FROM product_oa_work_overtime WHERE flow_flag=2 AND DATE_FORMAT(start_time,'%Y-%m')=? GROUP BY user_id)b "); |
| | | sb.append(" ON a.created_by=b.user_id "); |
| | | sb.append(" LEFT JOIN ( "); |
| | | sb.append(" SELECT "); |
| | | sb.append(" created_by,sum(IF(leave_type=1,TRUE,0))casual_leave,sum(IF(leave_type=2,TRUE,0))medical_leave, "); |
| | | sb.append(" sum(IF(leave_type=9,TRUE,0))marriage_leave,sum(IF(leave_type=4,TRUE,0))paid_leave, "); |
| | | sb.append(" sum(IF(leave_type!=1 && leave_type!=2 && leave_type!=4 && leave_type!=9,TRUE,0))other_leave "); |
| | | sb.append(" FROM product_oa_ask_for_leave "); |
| | | sb.append(" WHERE DATE_FORMAT(start_time,'%Y-%m')=? "); |
| | | sb.append(" GROUP BY created_by "); |
| | | sb.append(" )c "); |
| | | sb.append(" ON a.created_by=c.created_by "); |
| | | sb.append(" ORDER BY dept_uuid,a.created_by "); |
| | | |
| | | return baseDao.listTable(sb.toString(), param.toArray()); |
| | | |
| | | return dataTableEntity1; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |