From 04345420e457ccffcfc94646fde4f5a2204164c3 Mon Sep 17 00:00:00 2001
From: 6c <420680616@qq.com>
Date: 星期三, 15 十月 2025 10:31:18 +0800
Subject: [PATCH] 移动端加载mvc
---
src/main/java/com/product/mobile/core/service/SignInService.java | 206 +++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 180 insertions(+), 26 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 20525ba..b1dd0f3 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;
@@ -13,9 +14,13 @@
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 com.product.util.baidu.map.CoordinateTransformUtil;
+import com.product.util.baidu.map.CoordinateTransformUtil.Coordinate;
+
+import cn.hutool.core.date.DateUtil;
/**
* 鎵嬫満绔紝鑾峰彇鐢ㄦ埛鎵�鏈夊簲鐢�
@@ -25,31 +30,166 @@
@Component
public class SignInService extends AbstractBaseService{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); //鍒跺畾杈撳嚭鏍煎紡
-
+
@Autowired
public BaseDao baseDao;
/**
* 鍏堟煡鍑哄巻鍙叉墦鍗¤褰�
- * @param cpage
- * @param pagesize
* @return
* @throws BaseException
*/
+ @Transactional
public boolean signIn(FieldSetEntity fse) throws BaseException{
- fse.setTableName(MobileCoreConst.TABLE_PUNCH_RECORD);
+ 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);//鎵嬫満鎵撳崱
+ //鑾峰彇褰撳ぉ鎵撳崱璁板綍
+ 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"))){
+ //涓ゆ鎵撳崱淇濆瓨瑙勫垯
+ signTime(fs_time,fs_record,fse,4);
+ }else {
+ //涓ゆ鎵撳崱淇濆瓨瑙勫垯
+ 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)!=null) {
+ 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)!=null) {
+ 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)!=null) {
+ 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;
+ }
+ if(t%2==0) {
+ ///濡備笅鏄笅鐝崱锛屽苟涓斿綋澶╁凡缁忔墦杩囦簡锛屽彧鏄幓淇敼鏈�鍚庢墦鍗℃椂闂达紝涓嶆槸鏂板涓�鏉℃墦鍗¤褰�
+ String uuid=check(record,t);
+ if(uuid!=null) {
+ fse.setValue("uuid", uuid);
+ }
+ }
+
+ 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 String check(DataTableEntity record,int type) {
+ for(int i=0;i<record.getRows();i++) {
+ if(type==record.getFieldSetEntity(i).getInteger("punch_type").intValue()) {
+ return record.getFieldSetEntity(i).getString("uuid");
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 灏嗕袱涓椂闂村緱鏃跺垎绉掕繘琛屽姣攖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 +197,12 @@
* @return
* @throws BaseException
*/
- public DataTableEntity signInList(FieldSetEntity fse) throws BaseException{
+ public DataTableEntity 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;
+ 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;
}
/**
* 鏌ヨ鍏徃瀹氫箟鐨勮�冨嫟鐐�
@@ -74,11 +210,29 @@
* @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});
}
-
+ /**
+ *鍧愭爣杞崲
+ * @param type杞崲绫诲瀷
+ * @param lng 缁忓害
+ * @param lat 绾害
+ * @return
+ */
+ public FieldSetEntity coordinateTransform(int type,double lng,double lat) {
+
+ FieldSetEntity newCoord=new FieldSetEntity();
+ newCoord.setTableName("product_oa_punch_time");
+ Coordinate nc=CoordinateTransformUtil.toConvert(type, lng, lat);
+ if(nc!=null) {
+ newCoord.setValue("longitude", nc.longitude);
+ newCoord.setValue("latitude", nc.latitude);
+ }
+
+ return newCoord;
+ }
}
--
Gitblit v1.9.2