From 17a4ea77b0403b584dd8f9f01d7e3f28bee2a1a0 Mon Sep 17 00:00:00 2001
From: 18756 <1875631620@qq.com>
Date: 星期二, 13 八月 2024 17:16:40 +0800
Subject: [PATCH] 考勤功能优化8.13

---
 src/main/java/com/product/administration/service/PunchRecordService.java |  230 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 216 insertions(+), 14 deletions(-)

diff --git a/src/main/java/com/product/administration/service/PunchRecordService.java b/src/main/java/com/product/administration/service/PunchRecordService.java
index cbfc2c6..7633bbd 100644
--- a/src/main/java/com/product/administration/service/PunchRecordService.java
+++ b/src/main/java/com/product/administration/service/PunchRecordService.java
@@ -1,11 +1,17 @@
 package com.product.administration.service;
 
+
+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;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -34,29 +40,225 @@
 
 	@Autowired
 	BaseDao baseDao;
-	
+
 	/**
 	 * 	鑰冨嫟鎵撳崱鍒楄〃
 	 * @param fse
 	 * @return
 	 */
-	public DataTableEntity listRecordInfo(FieldSetEntity fse) {
+	public DataTableEntity listRecordInfo(FieldSetEntity fse) throws ParseException {
 		DataTableEntity dt=baseDao.listTable(CmnConst.PRODUCT_OA_PUNCH_RECORD, "created_by=?", new Object[] {SpringMVCContextHolder.getCurrentUser().getUser_id()}, null, CmnConst.CREATED_UTC_DATETIME+" DESC", fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE));
-		dt.setFieldFormat("punch_time_one", "yyyy-MM-dd HH:mm:ss");
-		dt.setFieldFormat("punch_time_three", "yyyy-MM-dd HH:mm:ss");
+		for (int i=0;i<dt.getRows();i++){
+			FieldSetEntity fieldSetEntity = dt.getData().get(i);
+			String punch_time_one = fieldSetEntity.getValue("punch_time_one").toString();
+			Date date1=new Date(punch_time_one);
+			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+			String sign_date = dateFormat.format(date1);
+			fieldSetEntity.setValue("sign_date",sign_date);
+
+			//鑾峰彇鏃╅��杩熷埌鐨勫垎閽熸暟
+			List<Object>param1=new ArrayList<>();
+			param1.add(fieldSetEntity.getValue("created_by").toString());
+			param1.add(fieldSetEntity.getValue("punch_congfig_uuid").toString());
+			param1.add(fieldSetEntity.getValue("created_by").toString()+",");
+
+			//鑾峰彇浣跨敤鍒扮殑璁剧疆瑙勫垯
+			StringBuilder sbPunchTime=new StringBuilder();
+			sbPunchTime.append(" SELECT 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=? where d.punch_site_uuid= ? ");
+			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());
+			long beLate1 = 0;
+			long beLate2 = 0;
+			long beEarily1 = 0;
+			long beEarily2 = 0;
+			if(dataTableEntity.getRows()!=0){
+
+				String morning_work="";
+				String morning_work_off="";
+				String afternoon_work="";
+				String afternoon_work_off="";
+				Date  morning_work_date;
+				Date  morning_work_off_date;
+				Date  afternoon_work_date;
+				Date  afternoon_work_off_date;
+
+				DateTime punch_time_one_date;
+				DateTime punch_time_two_date;
+				DateTime punch_time_three_date;
+				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());
+
+					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);
+						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);
+						}
+					}else {
+						lateSb.append("涓婄彮鏈墦鍗�");
+					}
+
+					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);
+						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);
+						}
+
+					}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","姝e父");
+					}
+
+
+
+				}else {
+
+					morning_work = dataTableEntity.getData().get(0).getValue("morning_work").toString();
+					morning_work_date= DateUtil.parse(morning_work.split(" ")[1]);
+					morning_work_off = dataTableEntity.getData().get(0).getValue("morning_work_off").toString();
+					morning_work_off_date= DateUtil.parse(morning_work_off.split(" ")[1]);
+					afternoon_work =dataTableEntity.getData().get(0).getValue("afternoon_work").toString();
+					afternoon_work_date= DateUtil.parse(afternoon_work.split(" ")[1]);
+					afternoon_work_off = dataTableEntity.getData().get(0).getValue("afternoon_work_off").toString();
+					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);
+						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);
+						}
+
+					}else {
+						lateSb.append("鏃╀笂涓婄彮鏈墦鍗�"+" ");
+
+					}
+
+					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);
+						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);
+						}
+
+
+					}else {
+						earilySb.append("鏃╀笂涓嬬彮鏈墦鍗�"+" ");
+					}
+					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);
+						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);
+						}
+					}else {
+						lateSb.append("鏃╀笂涓婄彮鏈墦鍗�"+" ");
+					}
+					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);
+						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);
+						}
+
+					}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");
+		dt.setFieldFormat("punch_time_two", " HH:mm");
+		dt.setFieldFormat("punch_time_three", " HH:mm");
+		dt.setFieldFormat("punch_time_four", " HH:mm");
 		baseDao.loadPromptData(dt);
 		return dt;
 	}
-	
+
 	/**
 	 * 	鑰冨嫟鎵撳崱璇︽儏
 	 * @param uuid
-	 * @return 
+	 * @return
 	 */
 	public FieldSetEntity findRecordInfo(String uuid) {
 		return baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_PUNCH_RECORD, uuid, true);
 	}
-	
+
 	/**
 	 * 	鑰冨嫟鎵撳崱鏂板
 	 * @param fse
@@ -64,18 +266,18 @@
 	 */
 	public String addRecordInfo(FieldSetEntity fse) {
 		SimpleDateFormat df = new SimpleDateFormat(CmnConst.YYYYMMDDHHMMSS);
-		
+
 		SystemUser currentUser=SpringMVCContextHolder.getCurrentUser();	//鑾峰彇鎵撳崱浜�
 		Date created_datetime=fse.getDate("created_datetime");			//鑾峰彇鎵撳崱鏃堕棿
 //		Date created_datetime=new Date();								//鑾峰彇鎵撳崱鏃堕棿
 		String string_created_datetime=df.format(created_datetime);		//鏃堕棿杞瑂tring
-		
+
 		//鑾峰彇鍏徃鎵撳崱鏃堕棿閰嶇疆淇℃伅
 		FieldSetEntity fseCompanyPunch=baseDao.getFieldSetEntityByFilter("product_oa_punch_time", "org_level_uuid=?", new Object[] {currentUser.getOrg_level_uuid()}, false);
 		if (fseCompanyPunch==null) {
 			throw new BaseException(SystemCode.SYSTEM_CONMAPNY_PUNCH_NO_EXIST.getValue(), SystemCode.SYSTEM_CONMAPNY_PUNCH_NO_EXIST.getText(), this.getClass(), "addRecordInfo");
 		}
-		
+
 		//鑾峰彇褰撳ぉ鎵撳崱淇℃伅
 		FieldSetEntity fsePunchInfo=baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_OA_PUNCH_RECORD, "created_by=? and DATE_FORMAT(created_utc_datetime,'%Y-%m-%d')like ?", new Object[] {currentUser.getUser_id(),string_created_datetime.substring(0, 10)+"%"}, false);
 		if (fsePunchInfo==null) {
@@ -89,13 +291,13 @@
 			//鏂板鎵撳崱淇℃伅
 			return baseDao.add(fseNewPunchInfo);
 		}else {
-			
+
 			//鎵撳崱妯″紡(0:鍙屽崱  1:鍥涘崱)
 			int punchMode=0;
 			if (StringUtils.isEmpty(fseCompanyPunch.getString("work_time_two"))) {
 				punchMode=1;
 			}
-			
+
 			String punch_time_one=fsePunchInfo.getDate("punch_time_one", CmnConst.YYYYMMDDHHMMSS);
 			String punch_time_two=fsePunchInfo.getDate("punch_time_two", CmnConst.YYYYMMDDHHMMSS);
 			String punch_time_three=fsePunchInfo.getDate("punch_time_three", CmnConst.YYYYMMDDHHMMSS);
@@ -115,7 +317,7 @@
 			}
 			list.add(string_created_datetime);
 			Collections.sort(list);
-			
+
 			for (int i = 0; i < list.size(); i++) {
 				if (punchMode==1) {
 					if (i==0) {
@@ -140,5 +342,5 @@
 			return fsePunchInfo.getUUID();
 		}
 	}
-	
+
 }

--
Gitblit v1.9.2