From 04eb3f2f80f195a0135fe31adda7e9a01c19589d Mon Sep 17 00:00:00 2001 From: shicf <shi_chongfu@163.com> Date: 星期四, 24 十月 2024 16:58:19 +0800 Subject: [PATCH] 签到打卡 --- src/main/java/com/product/mobile/core/service/SignInService.java | 227 ++++++++++++++++++++++++++++++++------------------------ 1 files changed, 128 insertions(+), 99 deletions(-) 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 f410bc1..a0f8ecb 100644 --- a/src/main/java/com/product/mobile/core/service/SignInService.java +++ b/src/main/java/com/product/mobile/core/service/SignInService.java @@ -14,9 +14,12 @@ import com.product.core.exception.BaseException; import com.product.core.service.support.AbstractBaseService; import com.product.core.spring.context.SpringMVCContextHolder; +import com.product.mobile.core.config.MobileCoreCode; import com.product.mobile.core.config.MobileCoreConst; import com.product.module.sys.entity.SystemUser; import com.product.util.BaseUtil; + +import cn.hutool.core.date.DateUtil; /** * 鎵嬫満绔紝鑾峰彇鐢ㄦ埛鎵�鏈夊簲鐢� @@ -36,106 +39,132 @@ */ @Transactional public boolean signIn(FieldSetEntity fse) throws BaseException{ + fse.setTableName(MobileCoreConst.TABLE_PUNCH_RECORD); + SystemUser user=SpringMVCContextHolder.getCurrentUser(); Date d = new Date(); - //鑾峰彇褰撳墠鏃堕棿鎵撳崱璁板綍 - FieldSetEntity fs_record=signInList(); + //鑾峰彇褰撳ぉ鎵撳崱璁板綍 + DataTableEntity fs_record=signInList(); + + 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()); + //鑾峰彇鎵撳崱璁剧疆 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); - } + //涓ゆ鎵撳崱淇濆瓨瑙勫垯 + signTime(fs_time,fs_record,fse,4); }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")); - - } - 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); - } - + signTime(fs_time,fs_record,fse,2); } + return baseDao.saveFieldSetEntity(fse); + } + /** + * 鎵撳崱瀹氫綅 锛屼笅鐝崱锛屽彲浠ラ噸澶嶆墦锛屽鐩栧墠闈㈢殑锛屼互鏈�鍚庝竴娆′负鍑� + * + * @param record 褰撳ぉ鎵撳崱璁板綍 + * @param fse 鏈鎵撳崱淇℃伅 + * @param type 涓ゆ鍗� 鎴栧洓娆″崱 + */ + private void signTime(FieldSetEntity config,DataTableEntity record,FieldSetEntity fse, int type) { + int t=5; + String rule=null; + if(!StringUtils.isEmpty( fse.getString("punch_congfig_uuid"))) { + if(type==2) { //瀵瑰簲2娆℃墦鍗� + if(fse.getInteger("punch_type")==1) {//涓嬬彮 + fse.setValue("punch_type","4"); + t=4; + rule=config.getString("afternoon_work_off"); + }else {//涓婄彮 + if(check(record,"1")) { + throw new BaseException(MobileCoreCode.SIGN_IN_REPEAT_FAIL); + } + fse.setValue("punch_type","1"); + t=1; + rule=config.getString("morning_work"); + } + }else {//瀵瑰簲4娆℃墦鍗� + if(fse.getInteger("punch_type")==1) {//涓嬬彮 + //鎵撲笅鐝崱锛屾瘮涓嬪崍涓婄彮鏃堕棿鏃╋紝鍒欎负涓婂崍涓嬬彮鍗★紝鍚﹀垯 涓轰笅鍗堜笅鐝崱 + if(dataCompareTo(fse.getDate("punch_time"),config.getDate("afternoon_work")) ) { + fse.setValue("punch_type","2"); + t=2; + rule=config.getString("morning_work_off"); + }else { + fse.setValue("punch_type","4"); + t=4; + rule=config.getString("afternoon_work_off"); + } + }else {//涓婄彮 + //涓婄彮鍗★紝姣斾笂鍗堜笅鐝棭锛岃涓婂崍涓婄彮鍗� + if(dataCompareTo(fse.getDate("punch_time"),config.getDate("morning_work_off")) ) { + if(check(record,"1")) { + throw new BaseException(MobileCoreCode.SIGN_IN_REPEAT_FAIL); + } + fse.setValue("punch_type","1"); + t=1; + rule=config.getString("morning_work"); + }else {//璁颁笅鍗堜笂鐝崱 + if(check(record,"3")) { + throw new BaseException(MobileCoreCode.SIGN_IN_REPEAT_FAIL); + } + fse.setValue("punch_type","3"); + t=3; + rule=config.getString("afternoon_work"); + } + } + } + }else { + fse.setValue("punch_type","5");///鐏垫椿鎵撳崱 + } + if(rule!=null) { + rule=rule.substring(10); + rule=DateUtil.formatDate(new Date())+rule; + } + long resutl=signinResult(DateUtil.parse(rule),fse.getDate("punch_time"),t); + if(resutl>0) { + fse.setValue("sign_in_result", 0);//杩熷埌 + }else if (resutl<0) { + fse.setValue("sign_in_result", 1);//鏃╅�� + resutl=resutl*-1; + }else { + fse.setValue("sign_in_result", 2);//姝e父 + } + fse.setValue("signin_result_num", resutl); + } + //璁$畻鑰冨嫟缁撴灉锛屽皬浜�0 鏃╅��锛屽ぇ浜�0 杩熷埌 锛岀瓑浜�=0 姝e父 + /** + * + * @param rule 鑰冨嫟鏃堕棿 + * @param punch_time 鎵撳崱鏃堕棿 + * @return + */ + private long signinResult (Date rule,Date punch_time,int type) { + + if(type==1 || type==3) { //涓婄彮 + long diffInMilliseconds = punch_time.getTime() - rule.getTime(); + long diffInMinutes = diffInMilliseconds / (60 * 1000); + return diffInMinutes>0?diffInMinutes:0; + }else if(type==2 ||type==4 ) {//涓嬬彮 + long diffInMilliseconds = punch_time.getTime() - rule.getTime(); + long diffInMinutes = diffInMilliseconds / (60 * 1000); + return diffInMinutes<0?diffInMinutes:0; + }else { + return 0; + } + } + + //涓婄彮鏃堕棿涓嶈兘閲嶅鎵撳崱 + private boolean check(DataTableEntity record,String type) { + for(int i=0;i<record.getRows();i++) { + if(type.equals( record.getFieldSetEntity(i).getString("punch_type"))) { + return true; + } + } + return false; } /** @@ -159,11 +188,11 @@ * @return * @throws BaseException */ - public FieldSetEntity signInList() throws BaseException{ + public DataTableEntity signInList() throws BaseException{ SystemUser user=SpringMVCContextHolder.getCurrentUser(); Date d = new Date(); String str = sdf.format(d); //灏嗘棩鏈熻浆鎹负瀛楃涓蹭笖鏍煎紡鎸夌収涔嬪墠鍒跺畾鐨� - 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); + DataTableEntity fs = baseDao.listTable(MobileCoreConst.TABLE_PUNCH_RECORD, "created_by=? and DATE_FORMAT(created_utc_datetime,'%Y-%m-%d')=?", new Object[]{user.getUser_id(), str}); return fs; } /** @@ -172,11 +201,11 @@ * @return */ public DataTableEntity signInSites(String org_level_uuid) { - if(StringUtils.isEmpty(org_level_uuid)) { - return baseDao.listTable(MobileCoreConst.TABLE_PUNCH_SITE); - }else { - return baseDao.listTable(MobileCoreConst.TABLE_PUNCH_SITE,"org_level_uuid=?",new String[] {org_level_uuid}); - } + StringBuilder sql=new StringBuilder(); + sql.append("select * from "); + sql.append(MobileCoreConst.TABLE_PUNCH_SITE); + sql.append(" a left join product_oa_punch_time b on b.punch_site_uuid=a.uuid where a.org_level_uuid=?"); + return baseDao.listTable(sql.toString(), new String[] {org_level_uuid}); } } -- Gitblit v1.9.2