From eb2a6d19fd28fa4edcc58b471149604ad718e868 Mon Sep 17 00:00:00 2001
From: 杜洪波 <1074825718@qq.com>
Date: 星期三, 17 九月 2025 09:28:03 +0800
Subject: [PATCH] 代码提交

---
 src/main/java/com/product/administration/service/PunchRecordService.java |  246 +++++++++++++++++++++++++++++-------------------
 1 files changed, 147 insertions(+), 99 deletions(-)

diff --git a/src/main/java/com/product/administration/service/PunchRecordService.java b/src/main/java/com/product/administration/service/PunchRecordService.java
index 579b0aa..456a100 100644
--- a/src/main/java/com/product/administration/service/PunchRecordService.java
+++ b/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;
@@ -25,6 +31,7 @@
 import com.product.core.service.support.AbstractBaseService;
 import com.product.core.spring.context.SpringMVCContextHolder;
 import com.product.module.sys.entity.SystemUser;
+import com.product.util.UnifySQLFunction;
 
 /**
  * 	鎵撳崱璁板綍
@@ -50,11 +57,24 @@
 		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));
 		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);
+			String punch_time_one = null;
+			if (fieldSetEntity.getString("punch_time_one") != null) {
+				punch_time_one=fieldSetEntity.getValue("punch_time_one").toString();
+			}else if (fieldSetEntity.getString("punch_time_two") != null) {
+				punch_time_one=fieldSetEntity.getValue("punch_time_two").toString();
+			}else if (fieldSetEntity.getString("punch_time_three") != null) {
+				punch_time_one=fieldSetEntity.getValue("punch_time_three").toString();
+			}else if (fieldSetEntity.getString("punch_time_four") != null) {
+				punch_time_one=fieldSetEntity.getValue("punch_time_four").toString();
+			}
+			String sign_date=null;
+			if (null!=punch_time_one){
+				Date date1=new Date(punch_time_one);
+				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
+				 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<>();
@@ -64,19 +84,68 @@
 
 			//鑾峰彇浣跨敤鍒扮殑璁剧疆瑙勫垯
 			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(" ) ");
+			sbPunchTime.append("\nSELECT c.* ");
+			sbPunchTime.append("\nFROM ( ");
+			sbPunchTime.append("\n  SELECT d.* ");
+			sbPunchTime.append("\n  FROM product_oa_punch_time d ");
+			sbPunchTime.append("\n  left JOIN product_oa_punch_record b ");
+			sbPunchTime.append("\n  on d.punch_site_uuid=b.punch_congfig_uuid and d.created_by=? where d.punch_site_uuid= ? ");
+			sbPunchTime.append("\n) c ");
+			sbPunchTime.append("\nwhere  c.uuid in ( ");
+			sbPunchTime.append("\n  SELECT DISTINCT uuid ");
+			sbPunchTime.append("\n  FROM product_oa_punch_time ");
+			sbPunchTime.append("\n where ").append(UnifySQLFunction.locateFunction("?", "concat(attendance_object,',')")).append(" >0 ");
+			sbPunchTime.append("\n) ");
 			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("\nSELECT");
+			sbReplenish.append("\n  T1.id,T1.uuid,T1.created_by,T1.applicant,T1.replenish_date,T1.reason,");
+			sbReplenish.append("\n  ").append(UnifySQLFunction.substringIndexFuntion(UnifySQLFunction.substringIndexFuntion("T1.replacement_card_type", ",", "T2.digit + 1"), ",", "- 1")).append(" AS type ");
+			sbReplenish.append("\nFROM (");
+			sbReplenish.append("\n  select * from product_oa_replenish_punch where flow_flag=2");
+			sbReplenish.append("\n) T1 ");
+			sbReplenish.append("\nJOIN ( SELECT 0 AS digit UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 ) T2");
+			sbReplenish.append("\nON T2.digit < ( length( T1.replacement_card_type )- length( REPLACE ( T1.replacement_card_type, ',', '' ))+ 1 )");
+			sbReplenish.append("\nwhere t1.created_by=? ");
+			sbReplenish.append("\nand 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,67 +167,53 @@
 				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("涓婄彮鏈墦鍗�");
 					}
 
-					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_four"))){
+					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_four"))&&ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_range_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","姝e父");
-					}
-
-
 
 				}else {
 
@@ -174,17 +229,18 @@
 
 					int distance = Integer.parseInt(dataTableEntity.getData().get(0).getValue("distance").toString());
 
-					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_one"))){
+					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_one"))&&ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_range_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 {
@@ -192,73 +248,65 @@
 
 					}
 
-					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_two"))){
+					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_two"))&&ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_range_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("鏃╀笅鐝湭鎵撳崱"+" ");
 					}
-					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_three"))){
+					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_three"))&&ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_range_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("鏃╀笂鐝湭鎵撳崱"+" ");
 					}
-					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_four"))){
+					if(ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_time_four"))&&ObjectUtil.isNotEmpty(fieldSetEntity.getValue("punch_range_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");
-		dt.setFieldFormat("punch_time_two", " HH:mm");
-		dt.setFieldFormat("punch_time_three", " HH:mm");
-		dt.setFieldFormat("punch_time_four", " HH:mm");
+		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;
 	}
@@ -269,7 +317,7 @@
 	 * @return
 	 */
 	public FieldSetEntity findRecordInfo(String uuid) {
-		return baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_PUNCH_RECORD, uuid, true);
+		return baseDao.getFieldSetEntity(CmnConst.PRODUCT_OA_PUNCH_RECORD, uuid, false);
 	}
 
 	/**

--
Gitblit v1.9.2