@ -1,5 +1,10 @@
package com.engine.jucailinkq.attendance.workflow.service.impl ;
import cn.hutool.http.HttpRequest ;
import cn.hutool.http.HttpResponse ;
import cn.hutool.http.HttpUtil ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.engine.jucailinkq.attendance.workflow.service.EnterpriseCalendarService ;
import com.engine.core.impl.Service ;
import com.engine.jucailinkq.common.util.* ;
@ -46,7 +51,95 @@ public class EnterpriseCalendarServiceImpl extends Service implements Enterprise
String transContinue = Util . null2String ( dataMain . get ( "asynjx" ) ) ;
//是否使用农历且带入农历节气信息
String lunarFlag = Util . null2String ( dataMain . get ( "jqdrmc" ) ) ;
Map < String , Map < String , Object > > holidayMap = DealDetail ( calendarId , yearStr , lunarFlag ) ;
//国家信息
String countrycode = "" ;
if ( dataMain . containsKey ( "gj" ) ) {
sql = "SELECT bm FROM uf_jcl_kq_tycjsj WHERE id = " + Util . null2String ( dataMain . get ( "gj" ) ) ;
Map < String , Object > datagj = DbTools . getSqlToMap ( sql ) ;
if ( datagj . size ( ) > 0 ) {
countrycode = Util . null2String ( datagj . get ( "bm" ) ) ;
}
}
//接口调用
String conInterface = "0" ;
if ( dataMain . containsKey ( "jkdy" ) )
conInterface = Util . null2String ( dataMain . get ( "jkdy" ) ) ;
//接口优先
String interfaceFirst = "0" ;
if ( dataMain . containsKey ( "jkyx" ) )
interfaceFirst = Util . null2String ( dataMain . get ( "jkyx" ) ) ;
//农历名称
String lunarName = "0" ;
if ( dataMain . containsKey ( "nl" ) )
lunarName = Util . null2String ( dataMain . get ( "nl" ) ) ;
if ( "1" . equals ( conInterface ) ) {
//=======自动添加日历明细记录===只针对非中国大陆之外的国家或地区执行===========
/*获取token*/
String url = "https://api.marcopayroll.com/api:benKoCK8/api/auth/login?email=tigers@tigermedgrp.com&password=mgkH6TsOyCXybl8H" ;
String requestStr = "" ;
int TIMEOUT = 60000 ;
HttpRequest req = HttpUtil . createPost ( url ) . timeout ( TIMEOUT ) . body ( requestStr ) ;
HttpResponse resp = req . execute ( ) ;
JSONObject returnJson = JSONObject . parseObject ( resp . body ( ) ) ;
String auth_token = returnJson . get ( "auth_token" ) . toString ( ) ;
/*获取指定国家指定日期区间内的节假日信息*/
url = "https://api.marcopayroll.com/api:benKoCK8/api/public-holiday?country=" + countrycode + "&customer_id=3&start_date=" + yearStr + "/01/01&end_date=" + yearStr + "/12/31" ;
req = HttpUtil . createGet ( url ) . timeout ( TIMEOUT ) . body ( requestStr ) . header ( "Authorization" , auth_token ) ;
resp = req . execute ( ) ;
returnJson = JSONObject . parseObject ( resp . body ( ) ) ;
JSONArray jsonArray = JSONArray . parseArray ( JSONObject . parseObject ( returnJson . get ( "public_holiday" ) . toString ( ) ) . get ( "items" ) . toString ( ) ) ;
JSONObject holidayitem ;
String start_date , end_date ;
String holidayname_zh = "" ;
String holidayname_en = "" ;
JSONArray dictionary ;
List < Map < String , Object > > holidayInfoList = new ArrayList < > ( ) ;
Map < String , Object > holidayInfo = new HashMap < > ( ) ;
String condition = " mainid = " + calendarId + " and glrq between '" + yearStr + "-01-01' and '" + yearStr + "-12-31'" ;
List < String > dbitems = CommonUtil . getUniqueItems ( "uf_jcl_kq_rlmc_dt1" , "glrq" , condition ) ;
for ( int i = 0 ; i < jsonArray . size ( ) ; i + + ) {
holidayitem = jsonArray . getJSONObject ( i ) ;
start_date = holidayitem . get ( "start_date" ) . toString ( ) ;
end_date = holidayitem . get ( "end_date" ) . toString ( ) ;
dictionary = JSONArray . parseArray ( holidayitem . get ( "dictionary" ) . toString ( ) ) ;
for ( int j = 0 ; j < dictionary . size ( ) ; j + + ) {
if ( ! "" . equals ( dictionary . getJSONObject ( j ) . get ( "value" ) ) ) {
switch ( dictionary . getJSONObject ( j ) . get ( "lang" ) . toString ( ) ) {
case "ZH" :
holidayname_zh = dictionary . getJSONObject ( j ) . get ( "value" ) . toString ( ) ;
break ;
case "EN" :
holidayname_en = dictionary . getJSONObject ( j ) . get ( "value" ) . toString ( ) ;
break ;
default :
break ;
}
}
}
if ( start_date . equals ( end_date ) ) {
if ( ! dbitems . contains ( start_date ) ) {
holidayInfo = createHolidayInfo ( calendarId , start_date , holidayname_zh , holidayname_en ) ;
holidayInfoList . add ( holidayInfo ) ;
dbitems . add ( start_date ) ;
}
} else {
int m = DateUtil . getBetWeenDays ( start_date , end_date ) ;
for ( int n = 0 ; n < m ; n + + ) {
String tmpdate = DateUtil . AfterDay ( start_date , n ) ;
if ( ! dbitems . contains ( tmpdate ) ) {
holidayInfo = createHolidayInfo ( calendarId , tmpdate , holidayname_zh , holidayname_en ) ;
holidayInfoList . add ( holidayInfo ) ;
dbitems . add ( tmpdate ) ;
}
}
}
}
boolean insertSign = CommonUtil . insertBatch ( holidayInfoList , "uf_jcl_kq_rlmc_dt1" ) ;
bs . writeLog ( "insertholidaydetail : " + insertSign ) ;
//=======自动添加日历明细记录==============
}
Map < String , Map < String , Object > > holidayMap = DealDetail ( calendarId , yearStr , lunarFlag , lunarName ) ;
//在单双周轮换时,判断第一周的休息日情况
boolean doubleRestSign = true ;
if ( restDaySetting . equals ( "1" ) ) {
@ -55,7 +148,6 @@ public class EnterpriseCalendarServiceImpl extends Service implements Enterprise
doubleRestSign = checkFirstWeekRest ( year , calendarId , doubleRestSign ) ;
}
}
//查询formmodeid
Map < String , String > formModeIdMap = Utils . getFormmodeIdMap ( ) ;
String formModeId = formModeIdMap . get ( "uf_jcl_kq_rlxx" ) ;
@ -68,7 +160,7 @@ public class EnterpriseCalendarServiceImpl extends Service implements Enterprise
for ( int day = 0 ; day < daysInMonth ; day + + ) {
dateInfo = new HashMap < > ( ) ;
dateInfo = createDateInfo ( calendar , lunarFlag );
dateInfo = createDateInfo ( calendar , lunarFlag , lunarName );
dateInfo . put ( "formmodeid" , formModeId ) ;
dateInfo . put ( "modeuuid" , UUID . randomUUID ( ) . toString ( ) ) ;
dateInfo . put ( "modedatacreater" , "1" ) ;
@ -99,15 +191,23 @@ public class EnterpriseCalendarServiceImpl extends Service implements Enterprise
doubleRestSign = ! doubleRestSign ;
}
}
dateInfo . put ( "rqlx" , "0" ) ;
dateInfo . put ( "bz" , "" ) ;
dateInfo . put ( "mc" , "" ) ;
if ( holidayMap . containsKey ( dateInfo . get ( "rq" ) ) ) {
dateInfo . put ( "mc" , holidayMap . get ( dateInfo . get ( "rq" ) ) . get ( "mc" ) ) ;
dateInfo . put ( "rqlx" , holidayMap . get ( dateInfo . get ( "rq" ) ) . get ( "rqlx" ) ) ;
dateInfo . put ( "bz" , holidayMap . get ( dateInfo . get ( "rq" ) ) . get ( "bz" ) ) ;
dateInfo . put ( "mc" , holidayMap . get ( dateInfo . get ( "rq" ) ) . get ( "mc" ) ) ;
}
if ( holidayMap . containsKey ( dateInfo . get ( "nlrq" ) ) & & ! holidayMap . containsKey ( "闰" + dateInfo . get ( "nlrq" ) ) ) {
dateInfo . put ( "mc" , holidayMap . get ( dateInfo . get ( "nlrq" ) ) . get ( "mc" ) ) ;
if ( holidayMap . containsKey ( dateInfo . get ( "nlrq" ) ) ) {
dateInfo . put ( "rqlx" , holidayMap . get ( dateInfo . get ( "nlrq" ) ) . get ( "rqlx" ) ) ;
dateInfo . put ( "bz" , holidayMap . get ( dateInfo . get ( "nlrq" ) ) . get ( "bz" ) ) ;
dateInfo . put ( "mc" , holidayMap . get ( dateInfo . get ( "nlrq" ) ) . get ( "mc" ) ) ;
}
if ( holidayMap . containsKey ( dateInfo . get ( "mc" ) ) ) {
dateInfo . put ( "rqlx" , holidayMap . get ( dateInfo . get ( "mc" ) ) . get ( "rqlx" ) ) ;
dateInfo . put ( "bz" , holidayMap . get ( dateInfo . get ( "mc" ) ) . get ( "bz" ) ) ;
dateInfo . put ( "mc" , holidayMap . get ( dateInfo . get ( "mc" ) ) . get ( "mc" ) ) ;
}
dateInfoList . add ( dateInfo ) ;
calendar . add ( Calendar . DAY_OF_MONTH , 1 ) ;
@ -172,75 +272,117 @@ public class EnterpriseCalendarServiceImpl extends Service implements Enterprise
* @param pLunarFlag 是 否 农 历 检 查
* @return 各 特 定 日 期 信 息
* /
private Map < String , Map < String , Object > > DealDetail ( String pCalendarId , String pYearStr , String pLunarFlag ){
String sql = "SELECT * FROM UF_JCL_KQ_RLMC_DT1 WHERE MAINID = " + pCalendarId ;
List < Map < String , Object > > dataDetail = DbTools . getSqlToList ( sql ) ;
private Map < String , Map < String , Object > > DealDetail ( String pCalendarId , String pYearStr , String pLunarFlag , String pLunarName ) {
String sql = "SELECT * FROM UF_JCL_KQ_RLMC_DT1 WHERE MAINID = " + pCalendarId + " AND ((lx = 0 AND ((rqczz = '0' AND glrq LIKE '" + pYearStr + "%') OR rqczz != '0')) OR lx = 1) order by sjly" ;
List < Map < String , Object > > dataDetail = DbTools . getSqlToList ( sql ) ;
String row_mc = "" ; //名称
String row_rqlx = "" ; //日期类型: 0: 工作日; 1: 节假日; 2: 公休日; 3: 调休日; 4: 调班日
String row_bzsm = "" ; //备注说明
String row_lx = "" ; //类型:0:公历; 1: 农历
String row_glrq = "" ; //公历日期
String row_nlrq = "" ; //农历日期
int row_yf = 0 ; //月份
String row_rqczz = "" ; //日期参照值: 0: 年-月-日; 1: 月-日; 2: 月-周
String row_dydjr = "" ; //当月第几日
String row_sjly = "" ; //数据来源
int row_dydjr = 0 ; //当月第几日
int row_dydjz = 0 ; //当月第几周
int row_dzxqj = 0 ; //当周星期几
int row_jq = 0 ; //节气
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
Calendar calendar = Calendar . getInstance ( ) ;
Map < String , Object > row_data = new HashMap < > ( ) ;
Map < String , Map < String , Object > > rows = new HashMap < > ( ) ;
for ( Map < String , Object > holidayMap : dataDetail ) {
Map < String , Object > row_data = new HashMap < > ( ) ;
Map < String , Map < String , Object > > rows = new HashMap < > ( ) ;
for ( Map < String , Object > holidayMap : dataDetail ) {
row_glrq = Util . null2String ( holidayMap . get ( "glrq" ) ) ; //公历日期
row_mc = holidayMap . get ( "mc" ) . toString ( ) ;
row_lx = holidayMap . get ( "lx" ) . toString ( ) ;
row_rqlx = holidayMap . get ( "rqlx" ) . toString ( ) ;
row_mc = holidayMap . get ( "mc" ) . toString ( ) ;
row_lx = holidayMap . get ( "lx" ) . toString ( ) ;
row_rqlx = holidayMap . get ( "rqlx" ) . toString ( ) ;
row_bzsm = Util . null2String ( holidayMap . get ( "bzsm" ) ) ;
row_nlrq = Util . null2String ( holidayMap . get ( "nlrq" ) ) ;
row_rqczz = Util . null2String ( holidayMap . get ( "rqczz" ) ) ;
row_data = new HashMap < > ( ) ;
row_data . put ( "mc" , row_mc ) ;
row_data . put ( "rqlx" , row_rqlx ) ;
row_data . put ( "bz" , row_bzsm ) ;
if ( row_lx . equals ( "0" ) ) {
//公历
switch ( row_rqczz ) {
case "0" :
//年-月-日
break ;
case "1" :
//月-日 2024-12-13
calendar = Calendar . getInstance ( ) ;
calendar . set ( Integer . parseInt ( pYearStr ) , Integer . parseInt ( Util . null2String ( holidayMap . get ( "glrq" ) ) . substring ( 5 , 7 ) ) - 1 , Integer . parseInt ( holidayMap . get ( "dydjr" ) . toString ( ) ) ) ;
row_sjly = Util . null2String ( holidayMap . get ( "sjly" ) ) ;
switch ( row_rqczz ) {
case "0" :
//年-月-日 ***************农历不支持此逻辑
break ;
case "1" :
//月-日 2024-12-13
row_yf = Integer . parseInt ( holidayMap . get ( "yf" ) . toString ( ) ) ;
row_dydjr = Integer . parseInt ( holidayMap . get ( "dydjr" ) . toString ( ) ) ;
calendar = Calendar . getInstance ( ) ;
if ( row_lx . equals ( "0" ) ) {
//公历处理逻辑
if ( row_dydjr > 0 ) {
calendar . set ( Integer . parseInt ( pYearStr ) , row_yf , row_dydjr ) ;
} else {
calendar . set ( Integer . parseInt ( pYearStr ) , row_yf , 1 ) ;
calendar . add ( Calendar . MONTH , 1 ) ;
calendar . add ( Calendar . DATE , row_dydjr ) ;
}
row_glrq = sdf . format ( calendar . getTime ( ) ) ;
break ;
case "2" :
//月-周
calendar = Calendar . getInstance ( ) ;
calendar . set ( Integer . parseInt ( pYearStr ) , Integer . parseInt ( Util . null2String ( holidayMap . get ( "glrq" ) ) . substring ( 5 , 7 ) ) - 1 , 1 ) ;
int dayOfWeek = Integer . parseInt ( getWeek ( calendar ) ) ; //周一-周日为0-6
row_dydjz = Integer . parseInt ( holidayMap . get ( "dydjz" ) . toString ( ) ) ;
row_dzxqj = Integer . parseInt ( holidayMap . get ( "dzxqj" ) . toString ( ) ) ;
if ( row_dzxqj > dayOfWeek ) {
calendar . add ( Calendar . DATE , row_dzxqj - dayOfWeek ) ;
} else {
//农历处理逻辑
//考虑到只有目前除夕是特殊的,取腊月的最后一天,所以对除夕做特殊处理
if ( row_dydjr > 0 ) {
row_glrq = sdf . format ( LunarCalendar . chineseMonthNumber [ row_yf ] + LunarCalendar . getChinaDayString ( row_dydjr ) ) ;
} else {
calendar . add ( Calendar . DATE , row_dzxqj + 7 - dayOfWeek ) ;
calendar . set ( Integer . parseInt ( pYearStr ) , 1 , 1 ) ;
LunarCalendar lunarCalendar = new LunarCalendar ( calendar ) ;
int monthDays = LunarCalendar . monthDays ( lunarCalendar . getYear ( ) , 12 ) ;
row_glrq = LunarCalendar . chineseMonthNumber [ row_yf ] + "月" + LunarCalendar . getChinaDayString ( monthDays + 1 + row_dydjr ) ;
}
calendar . add ( Calendar . DATE , ( row_dydjz - 1 ) * 7 ) ;
row_glrq = sdf . format ( calendar . getTime ( ) ) ;
break ;
default :
break ;
}
} else {
row_glrq = row_nlrq ;
}
break ;
case "2" :
//月-周 ***************农历不支持此逻辑
calendar = Calendar . getInstance ( ) ;
row_yf = Integer . parseInt ( holidayMap . get ( "yf" ) . toString ( ) ) ;
calendar . set ( Integer . parseInt ( pYearStr ) , row_yf , 1 ) ;
int dayOfWeek = Integer . parseInt ( getWeek ( calendar ) ) ; //周一-周日为0-6
row_dydjz = Integer . parseInt ( holidayMap . get ( "dydjz" ) . toString ( ) ) ;
row_dzxqj = Integer . parseInt ( holidayMap . get ( "dzxqj" ) . toString ( ) ) ;
if ( row_dzxqj > dayOfWeek ) {
calendar . add ( Calendar . DATE , row_dzxqj - dayOfWeek ) ;
} else {
calendar . add ( Calendar . DATE , row_dzxqj + 7 - dayOfWeek ) ;
}
calendar . add ( Calendar . DATE , ( row_dydjz - 1 ) * 7 ) ;
row_glrq = sdf . format ( calendar . getTime ( ) ) ;
break ;
case "3" :
row_jq = Integer . parseInt ( holidayMap . get ( "nlrq" ) . toString ( ) ) ;
String [ ] principleTermNames = { "立春" , "雨水" , "惊蛰" , "春分" , "清明" , "谷雨" , "立夏" , "小满" , "芒种" , "夏至" , "小暑" , "大暑" , "立秋" , "处暑" , "白露" , "秋分" , "寒露" , "霜降" , "立冬" , "小雪" , "大雪" , "冬至" , "小寒" , "大寒" } ;
row_glrq = principleTermNames [ row_jq ] ;
break ;
default :
break ;
}
row_data . put ( "rq" , row_glrq ) ;
rows . put ( row_glrq , row_data ) ;
row_data = new HashMap < > ( ) ;
row_data . put ( "mc" , row_mc ) ; //名称
row_data . put ( "rqlx" , row_rqlx ) ; //日期类型
row_data . put ( "bz" , row_bzsm ) ; //备注
row_data . put ( "rq" , row_glrq ) ; //公历日期
row_data . put ( "sjly" , row_sjly ) ; //数据来源
rows . put ( row_glrq , row_data ) ;
}
return rows ;
}
private Map < String , Object > createDateInfo ( Calendar calendar , String lunarFlag ) {
private Map < String , Object > createHolidayInfo ( String calendarid , String date , String zh_name , String en_name ) {
Map < String , Object > holidayInfo = new HashMap < > ( ) ;
holidayInfo . put ( "mainid" , calendarid ) ;
holidayInfo . put ( "lx" , 0 ) ; //日历类型: 0: 公历; 1: 农历
holidayInfo . put ( "rqczz" , 0 ) ; //日期参照值: 0: 年-月-日; 1: 月-日; 2: 月-周
holidayInfo . put ( "rqlx" , 1 ) ; //日期类型: 0: 工作日; 1: 节假日; 2: 公休日; 3: 调休日; 4: 调班日
holidayInfo . put ( "glrq" , date ) ;
holidayInfo . put ( "mc" , zh_name ) ; //名称
holidayInfo . put ( "sjly" , "0" ) ; //名称
//holidayInfo.put("nlrq","");//农历日期文本
//holidayInfo.put("dydjr","");//当月第几日
//holidayInfo.put("dydjz","");//当月第几周
//holidayInfo.put("dzxqj",calendarId);//当周星期几: 0: 星期一; 1: 星期二; 2: 星期三; 6: 星期日
return holidayInfo ;
}
private Map < String , Object > createDateInfo ( Calendar calendar , String solarTerms , String lunarName ) {
Map < String , Object > dateInfo = new HashMap < > ( ) ;
// 获取阳历年-月-日
SimpleDateFormat sdf = new SimpleDateFormat ( "yyyy-MM-dd" ) ;
@ -259,6 +401,7 @@ public class EnterpriseCalendarServiceImpl extends Service implements Enterprise
if ( ! termInfo . equals ( "" ) ) {
specialDay = termInfo . replace ( " " , "" ) ;
}
/ * 此 部 分 逻 辑 转 移 到 读 取 日 历 信 息 明 细
//判断日期是否为节日
String holidayInfo = getHolidayInfo ( calendar , lunarCalendar ) ;
if ( ! holidayInfo . equals ( "" ) ) {
@ -266,15 +409,19 @@ public class EnterpriseCalendarServiceImpl extends Service implements Enterprise
}
//判断日期类型
String dayType = getDayType ( weekIndex , specialDay ) ;
* /
dateInfo . put ( "rq" , solarDate ) ;
if ( lunarFlag . equals ( "1" ) ) {
dateInfo . put ( "nlrq" , lunarDate ) ;
//依据是否节气信息,设置日期名称
if ( solarTerms . equals ( "1" ) ) {
dateInfo . put ( "mc" , specialDay . equals ( "" ) ? null : specialDay ) ;
dateInfo . put ( "rqlx" , dayType ) ;
} else {
dateInfo . put ( "nlrq" , "" ) ;
dateInfo . put ( "mc" , "" ) ;
dateInfo . put ( "rqlx" , "0" ) ;
}
//依据是否农历日期,设置农历日期字段值
if ( lunarName . equals ( "1" ) ) {
dateInfo . put ( "nlrq" , lunarDate ) ;
} else {
dateInfo . put ( "nlrq" , "" ) ;
}
dateInfo . put ( "xq" , weekIndex ) ;
dateInfo . put ( "bz" , "" ) ;