From 8e2008a8722b9b5a5d7107542fcacd9bf6eea735 Mon Sep 17 00:00:00 2001
From: zm <2369059705qq.com>
Date: 星期三, 14 八月 2024 09:47:40 +0800
Subject: [PATCH] 考勤打卡

---
 src/main/java/com/product/mobile/core/config/MobileCoreConst.java      |    3 
 src/main/java/com/product/mobile/core/config/MobileCoreCode.java       |    1 
 src/main/java/com/product/mobile/core/controller/SignInController.java |    2 
 src/main/java/com/product/mobile/core/service/SignInService.java       |  136 +++++++++++++++++++++++++++++++++++++++------
 4 files changed, 121 insertions(+), 21 deletions(-)

diff --git a/src/main/java/com/product/mobile/core/config/MobileCoreCode.java b/src/main/java/com/product/mobile/core/config/MobileCoreCode.java
index eb6339c..668965a 100644
--- a/src/main/java/com/product/mobile/core/config/MobileCoreCode.java
+++ b/src/main/java/com/product/mobile/core/config/MobileCoreCode.java
@@ -1,5 +1,6 @@
 package com.product.mobile.core.config;
 
+
 import com.product.common.enums.IEnum;
 import com.product.common.enums.ModuleEnum;
 
diff --git a/src/main/java/com/product/mobile/core/config/MobileCoreConst.java b/src/main/java/com/product/mobile/core/config/MobileCoreConst.java
index 2bcb6d0..0b6b652 100644
--- a/src/main/java/com/product/mobile/core/config/MobileCoreConst.java
+++ b/src/main/java/com/product/mobile/core/config/MobileCoreConst.java
@@ -27,7 +27,8 @@
     //鎵撳崱
     public static final String TABLE_PUNCH_RECORD = "product_oa_punch_record";
     public static final String TABLE_PUNCH_SITE = "product_oa_punch_site";
-    
+    public static final String TABLE_PUNCH_TIME = "product_oa_punch_time";
+
     //鎵撳崱:鎵嬫満鎵撳崱
     public static final String FIELD_PUNCH_TYPE = "punch_type";
     //瀛楁瀹氫箟
diff --git a/src/main/java/com/product/mobile/core/controller/SignInController.java b/src/main/java/com/product/mobile/core/controller/SignInController.java
index c86aee4..82bf88b 100644
--- a/src/main/java/com/product/mobile/core/controller/SignInController.java
+++ b/src/main/java/com/product/mobile/core/controller/SignInController.java
@@ -60,7 +60,7 @@
             RequestParameterEntity reqp = (RequestParameterEntity) bean;
             fse = reqp.getFormData();
         }
-        return this.OK_List(signInService.signInList(fse));
+        return this.OK_List(signInService.signInList());
     }
     /**
      * 鑾峰彇鍏徃鍥哄畾鑰冨嫟鐐圭殑淇℃伅
diff --git a/src/main/java/com/product/mobile/core/service/SignInService.java b/src/main/java/com/product/mobile/core/service/SignInService.java
index 95026ea..f410bc1 100644
--- a/src/main/java/com/product/mobile/core/service/SignInService.java
+++ b/src/main/java/com/product/mobile/core/service/SignInService.java
@@ -3,6 +3,7 @@
 import java.text.SimpleDateFormat;
 import java.util.Date;
 
+import com.product.core.transfer.Transactional;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -30,26 +31,127 @@
     public BaseDao baseDao;
     /**
      * 	鍏堟煡鍑哄巻鍙叉墦鍗¤褰�
-     * @param cpage
-     * @param pagesize
      * @return
      * @throws BaseException
      */
+	@Transactional
     public boolean signIn(FieldSetEntity fse) throws BaseException{
-    	fse.setTableName(MobileCoreConst.TABLE_PUNCH_RECORD);
     	SystemUser user=SpringMVCContextHolder.getCurrentUser();
     	Date d = new Date();
-    	DataTableEntity dt=signInList(fse);
-    	if(user!=null) {
-    		fse.setValue(MobileCoreConst.ORG_LEVEL_UUID, user.getOrg_level_uuid());
-    		fse.setValue(MobileCoreConst.DEPT_UUID, user.getDept_uuid());
-    		fse.setValue(MobileCoreConst.CREATED_UTC_DATETIME, d);
-    	}
-    	fse.setValue(MobileCoreConst.FIELD_PUNCH_TYPE,1);//鎵嬫満鎵撳崱
+		//鑾峰彇褰撳墠鏃堕棿鎵撳崱璁板綍
+    	FieldSetEntity fs_record=signInList();
+        //鑾峰彇鎵撳崱璁剧疆
+		FieldSetEntity fs_time = baseDao.getFieldSetByFilter(MobileCoreConst.TABLE_PUNCH_TIME, "punch_site_uuid=?", new Object[]{fse.getString("punch_congfig_uuid")}, false);
+        if (!StringUtils.isEmpty(fs_time.getString("morning_work_off"))&&!StringUtils.isEmpty(fs_time.getString("afternoon_work"))){
+			//鍥涙鎵撳崱淇濆瓨瑙勫垯
+			if (FieldSetEntity.isEmpty(fs_record)){
+				//鏈煡璇㈠埌鎵撳紑璁板綍鏂板缓鎵撳崱璁板綍
+				if(user!=null) {
+					fse.setValue(MobileCoreConst.ORG_LEVEL_UUID, user.getOrg_level_uuid());
+					fse.setValue(MobileCoreConst.DEPT_UUID, user.getDept_uuid());
+					fse.setValue(MobileCoreConst.CREATED_BY, user.getUser_id());
+					fse.setValue(MobileCoreConst.CREATED_UTC_DATETIME, d);
+				}
+				fse.setValue(MobileCoreConst.FIELD_PUNCH_TYPE,1);//鎵嬫満鎵撳崱
+				if (!StringUtils.isEmpty(fse.getDate("punch_time_one"))){
+					if (dataCompareTo(fse.getDate("punch_time_one"),fs_time.getDate("morning_work_off"))){
+						fse.setValue("punch_time_one",fse.getDate("punch_time_one"));
+						fse.setValue("punch_range_one",fse.getString("punch_range_one"));
+					}else {
+						fse.setValue("punch_time_three",fse.getDate("punch_time_one"));
+						fse.setValue("punch_range_three",fse.getString("punch_range_one"));
+						fse.setValue("punch_time_one",null);
+						fse.setValue("punch_range_one",null);
+					}
+				}
+				if (!StringUtils.isEmpty(fse.getDate("punch_time_four"))){
+					if (dataCompareTo(fse.getDate("punch_time_four"),fs_time.getDate("afternoon_work_off"))){
+						fse.setValue("punch_time_two",fse.getDate("punch_time_four"));
+						fse.setValue("punch_range_two",fse.getString("punch_range_four"));
+					}else {
+						fse.setValue("punch_time_two",null);
+						fse.setValue("punch_range_two",null);
+						fse.setValue("punch_time_four",fse.getDate("punch_time_four"));
+						fse.setValue("punch_range_four",fse.getString("punch_range_four"));
+					}
+				}
+				fse.setTableName(MobileCoreConst.TABLE_PUNCH_RECORD);
+				return 	baseDao.saveFieldSetEntity(fse);
+			}
+			else {
+				//鏌ヨ鍒板凡鏈夋墦寮�璁板綍鏂板缓鎵撳崱璁板綍
+				if (!StringUtils.isEmpty(fse.getDate("punch_time_one"))){
+					//鍒ゆ柇涓婄彮鎵撳崱鎵撳崱瑙勫垯锛�1銆佷笂鍗堜笂鐝湭鎵撳崱 2銆佹湭瓒呰繃涓婂崍涓嬬彮鏃堕棿 3銆佷笂鍗堟湭鎵撲笅鐝崱 鍒欎负涓婂崍涓婄彮鍗″惁鍒欎负涓嬪崍涓婄彮鍗�
 
+					if(dataCompareTo(fse.getDate("punch_time_one"),fs_time.getDate("morning_work_off"))
+							&&StringUtils.isEmpty(fs_record.getString("punch_time_one"))
+							&&StringUtils.isEmpty(fs_record.getString("punch_time_two"))){
+						fs_record.setValue("punch_time_one", fse.getDate("punch_time_one"));
+						fs_record.setValue("punch_range_one", fse.getString("punch_range_one"));
+					}else {
+						fs_record.setValue("punch_time_three", fse.getDate("punch_time_one"));
+						fs_record.setValue("punch_range_three", fse.getString("punch_range_one"));
+					}
+				}
+				//鍒ゆ柇涓嬬彮鎵撳崱鐝墦鍗¤鍒欙細1銆佷笂鍗堜笅鐝湭鎵撳崱 2銆佹湭瓒呰繃涓婂崍涓嬬彮鏃堕棿 3銆佷笅鍗堝崍鏈墦涓婄彮鍗� 鍒欎负涓婂崍涓嬬彮鍗″惁鍒欎负涓嬪崍涓嬬彮鍗�
+				if (!StringUtils.isEmpty(fse.getDate("punch_time_four"))){
+					if(dataCompareTo(fse.getDate("punch_time_four"),fs_time.getDate("afternoon_work_off"))
+							&&StringUtils.isEmpty(fs_record.getDate("punch_time_two"))
+							&&StringUtils.isEmpty(fs_record.getDate("punch_time_three"))){
+						fs_record.setValue("punch_time_two", fse.getDate("punch_time_four"));
+						fs_record.setValue("punch_range_two", fse.getString("punch_range_four"));
+					}else {
+						fs_record.setValue("punch_time_four", fse.getDate("punch_time_four"));
+						fs_record.setValue("punch_range_four", fse.getString("punch_range_four"));
+					}
+				}
+				return baseDao.saveFieldSetEntity(fs_record);
+			}
+		}else {
+			//涓ゆ鎵撳崱淇濆瓨瑙勫垯
+			if (FieldSetEntity.isEmpty(fs_record)){
+				//鏈煡璇㈠埌鎵撳紑璁板綍鏂板缓鎵撳崱璁板綍
+				if(user!=null) {
+					fse.setValue(MobileCoreConst.ORG_LEVEL_UUID, user.getOrg_level_uuid());
+					fse.setValue(MobileCoreConst.DEPT_UUID, user.getDept_uuid());
+					fse.setValue(MobileCoreConst.CREATED_UTC_DATETIME, d);
+					fse.setValue(MobileCoreConst.CREATED_BY, user.getUser_id());
+				}
+				fse.setValue(MobileCoreConst.FIELD_PUNCH_TYPE,1);//鎵嬫満鎵撳崱
+				fse.setTableName(MobileCoreConst.TABLE_PUNCH_RECORD);
+				return baseDao.saveFieldSetEntity(fse);
+			}else {
+				//鏌ヨ鍒板凡鏈夋墦寮�璁板綍鏂板缓鎵撳崱璁板綍
+				if (!StringUtils.isEmpty(fse.getString("punch_time_one"))){
+					fs_record.setValue("punch_time_one",fse.getDate("punch_time_one"));
+					fs_record.setValue("punch_range_one",fse.getString("punch_range_one"));
 
-        return baseDao.saveFieldSetEntity(fse);
-    }
+				}
+				if (!StringUtils.isEmpty(fse.getString("punch_time_four"))){
+					fs_record.setValue("punch_time_four",fse.getDate("punch_time_four"));
+					fs_record.setValue("punch_range_four",fse.getString("punch_range_four"));
+				}
+
+				return baseDao.saveFieldSetEntity(fs_record);
+			}
+
+		}
+	}
+
+	/**
+	 * 灏嗕袱涓椂闂村緱鏃跺垎绉掕繘琛屽姣攖rue鍒欎负鍓嶈�呮棭 鍚﹀垯灏辨槸涓�鏍锋椂闂存垨鑰呭悗鑰呮棭
+	 * @param a
+	 * @param b
+	 * @return
+	 */
+	private boolean dataCompareTo(Date a,Date b){
+		a.setTime(a.getTime() % (24 * 60 * 60 * 1000)); // 璁剧疆date2涓哄綋澶╃殑00:00:00
+		b.setTime(b.getTime() % (24 * 60 * 60 * 1000)); // 璁剧疆date2涓哄綋澶╃殑00:00:00
+		if (a.compareTo(b) < 0) {
+			return  true;
+		}
+		return  false;
+	}
     /**
      * 	鏌ュ嚭鎸囧畾鏃ユ湡鎵撳崱璁板綍
      * @param cpage
@@ -57,16 +159,12 @@
      * @return
      * @throws BaseException
      */
-    public DataTableEntity signInList(FieldSetEntity fse) throws BaseException{
+    public FieldSetEntity signInList() throws BaseException{
     	SystemUser user=SpringMVCContextHolder.getCurrentUser();
     	Date d = new Date();
     	String str = sdf.format(d); //灏嗘棩鏈熻浆鎹负瀛楃涓蹭笖鏍煎紡鎸夌収涔嬪墠鍒跺畾鐨�
-    	StringBuilder sql=new StringBuilder();
-    	sql.append("select *  from ").append(MobileCoreConst.TABLE_PUNCH_RECORD)
-    	.append(" where created_by=?  and DATE_FORMAT(created_utc_datetime,'%Y-%m-%d')=? ");
-
-    	DataTableEntity dt=baseDao.listTable(sql.toString(), new Object[] {user.getUser_id(),str});
-        return dt;
+		FieldSetEntity fs = baseDao.getFieldSetByFilter(MobileCoreConst.TABLE_PUNCH_RECORD, "created_by=?  and DATE_FORMAT(created_utc_datetime,'%Y-%m-%d')=?", new Object[]{user.getUser_id(), str}, false);
+		return fs;
     }
     /**
      * 鏌ヨ鍏徃瀹氫箟鐨勮�冨嫟鐐�

--
Gitblit v1.9.2