@ -2,7 +2,10 @@ package com.engine.kq.biz;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONObject ;
import com.engine.hostar.util.HostarUtil ;
import com.engine.kq.cmd.attendanceButton.ButtonStatusEnum ;
import com.engine.kq.entity.TimeScopeEntity ;
import com.engine.kq.entity.WorkTimeEntity ;
import com.engine.kq.enums.KqSplitFlowTypeEnum ;
import com.engine.kq.log.KQLog ;
import com.engine.kq.util.KQDurationCalculatorUtil ;
@ -11,6 +14,8 @@ import java.text.DecimalFormatSymbols;
import java.util.Map.Entry ;
import com.engine.kq.util.KQTransMethod ;
import com.weaver.integration.ldap.sync.formart.OaFormart ;
import org.apache.commons.lang3.StringUtils ;
import weaver.common.DateUtil ;
import weaver.conn.RecordSet ;
import weaver.file.Prop ;
@ -40,6 +45,8 @@ public class KQReportBiz extends BaseBean {
private KQLog kqLog = new KQLog ( ) ;
BaseBean bb = new BaseBean ( ) ;
/ * *
* 初 始 化 当 天 考 勤 数 据
* /
@ -130,7 +137,7 @@ public class KQReportBiz extends BaseBean {
rs . executeQuery ( sql , resourceId , fromdate , todate ) ;
while ( rs . next ( ) ) {
String serialnumber = Util . null2String ( rs . getString ( "serialnumber" ) ) ;
String serialid = Util . null2String ( rs . getString ( "serialid" ) ) ;
String serialid = Util . null2String ( rs . getString ( "serialid" ) ) ;
String workbegindate = Util . null2String ( rs . getString ( "workbegindate" ) ) ;
String workbegintime = Util . null2String ( rs . getString ( "workbegintime" ) ) ;
String workenddate = Util . null2String ( rs . getString ( "workenddate" ) ) ;
@ -216,7 +223,7 @@ public class KQReportBiz extends BaseBean {
}
}
data . put ( "start" , isondutyfreecheck ) ;
data . put ( "end" , isoffdutyfreecheck ) ;
data . put ( "end" , isoffdutyfreecheck ) ;
if ( status . length ( ) > 0 ) status + = "," ;
status + = ButtonStatusEnum . ABSENT . getStatusCode ( ) ;
}
@ -366,6 +373,10 @@ public class KQReportBiz extends BaseBean {
datas . putAll ( getDailyFlowEvectionOutData ( params , user ) ) ;
datas . putAll ( getDailyFlowOverTimeData ( params , user ) ) ;
datas . putAll ( getDailyFlowLeaveBackData ( params , user ) ) ;
/*考勤二开--出差公出流程餐补统计start*/
datas . putAll ( getDailyMealAllowanceData ( params , user ) ) ;
/*考勤二开--出差公出流程餐补统计end*/
} catch ( Exception e ) {
writeLog ( e ) ;
}
@ -663,7 +674,7 @@ public class KQReportBiz extends BaseBean {
}
sql = " select resourceid, newleavetype, durationrule, sum(duration) as val from hrmresource a, " + KqSplitFlowTypeEnum . LEAVE . getTablename ( ) + " b " +
" where a.id = b.resourceid and belongdate >='" + fromDate + "' and belongdate <='" + toDate + "' " + sqlWhere +
" where a.id = b.resourceid and belongdate >='" + fromDate + "' and belongdate <='" + toDate + "' " + sqlWhere +
" group by resourceid, newleavetype, durationrule " ;
rs . execute ( sql ) ;
while ( rs . next ( ) ) {
@ -760,7 +771,7 @@ public class KQReportBiz extends BaseBean {
// sqlWhere += " and (signfrom like 'card%' or signfrom='e9_mobile_out' or signfrom='EMSyn_out' or signfrom='DingTalk_out' or signfrom='Wechat_out') ";
sql = " select a.id,b.signdate,b.id as signid,b.signfrom from hrmresource a, hrmschedulesign b " +
" where a.id = b.userid and b.signdate >='" + fromDate + "' and b.signdate <='" + toDate + "' " + sqlWhere +
" where a.id = b.userid and b.signdate >='" + fromDate + "' and b.signdate <='" + toDate + "' " + sqlWhere +
" order by a.id,b.signdate " ;
rs . execute ( sql ) ;
// kqLog.info("card.sql="+sql);
@ -839,7 +850,7 @@ public class KQReportBiz extends BaseBean {
}
sql = " select resourceid, newleavetype, durationrule, sum(duration) as val from hrmresource a, " + KqSplitFlowTypeEnum . LEAVEBACK . getTablename ( ) + " b " +
" where a.id = b.resourceid and belongdate >='" + fromDate + "' and belongdate <='" + toDate + "' " + sqlWhere +
" where a.id = b.resourceid and belongdate >='" + fromDate + "' and belongdate <='" + toDate + "' " + sqlWhere +
" group by resourceid, newleavetype, durationrule " ;
rs . execute ( sql ) ;
while ( rs . next ( ) ) {
@ -1033,7 +1044,7 @@ public class KQReportBiz extends BaseBean {
}
sql = " select resourceid, newleavetype, durationrule, sum(duration) as val,belongdate from hrmresource a, " + KqSplitFlowTypeEnum . LEAVE . getTablename ( ) + " b " +
" where a.id = b.resourceid and belongdate >='" + fromDate + "' and belongdate <='" + toDate + "' " + sqlWhere +
" where a.id = b.resourceid and belongdate >='" + fromDate + "' and belongdate <='" + toDate + "' " + sqlWhere +
" group by resourceid, newleavetype, durationrule,belongdate " ;
rs . execute ( sql ) ;
while ( rs . next ( ) ) {
@ -1125,7 +1136,7 @@ public class KQReportBiz extends BaseBean {
}
sql = " select resourceid, newleavetype, durationrule, sum(duration) as val,belongdate from hrmresource a, " + KqSplitFlowTypeEnum . LEAVEBACK . getTablename ( ) + " b " +
" where a.id = b.resourceid and belongdate >='" + fromDate + "' and belongdate <='" + toDate + "' " + sqlWhere +
" where a.id = b.resourceid and belongdate >='" + fromDate + "' and belongdate <='" + toDate + "' " + sqlWhere +
" group by resourceid, newleavetype, durationrule,belongdate " ;
rs . execute ( sql ) ;
while ( rs . next ( ) ) {
@ -1160,6 +1171,278 @@ public class KQReportBiz extends BaseBean {
return datas ;
}
/ * *
* 获 取 餐 补 数 据
* @param params
* @param user
* @return
* /
public Map < String , Object > getDailyMealAllowanceData ( Map < String , Object > params , User user ) {
Map < String , Object > datas = new HashMap < > ( ) ; ;
RecordSet rs = new RecordSet ( ) ;
String sql = "" ;
String sqlWhere = " " ;
try {
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo ( ) ;
JSONObject jsonObj = JSON . parseObject ( Util . null2String ( params . get ( "data" ) ) ) ;
String fromDate = Util . null2String ( jsonObj . get ( "fromDate" ) ) ;
String toDate = Util . null2String ( jsonObj . get ( "toDate" ) ) ;
String typeselect = Util . null2String ( jsonObj . get ( "typeselect" ) ) ;
if ( typeselect . length ( ) = = 0 ) typeselect = "3" ;
if ( ! typeselect . equals ( "" ) & & ! typeselect . equals ( "0" ) & & ! typeselect . equals ( "6" ) ) {
if ( typeselect . equals ( "1" ) ) {
fromDate = TimeUtil . getCurrentDateString ( ) ;
toDate = TimeUtil . getCurrentDateString ( ) ;
} else {
fromDate = TimeUtil . getDateByOption ( typeselect , "0" ) ;
toDate = TimeUtil . getDateByOption ( typeselect , "1" ) ;
}
}
String subCompanyId = Util . null2String ( jsonObj . get ( "subCompanyId" ) ) ;
String departmentId = Util . null2String ( jsonObj . get ( "departmentId" ) ) ;
String resourceId = Util . null2String ( jsonObj . get ( "resourceId" ) ) ;
String allLevel = Util . null2String ( jsonObj . get ( "allLevel" ) ) ;
String isNoAccount = Util . null2String ( jsonObj . get ( "isNoAccount" ) ) ;
String viewScope = Util . null2String ( jsonObj . get ( "viewScope" ) ) ;
if ( subCompanyId . length ( ) > 0 ) {
sqlWhere + = " and a.subcompanyid1 in(" + subCompanyId + ") " ;
}
if ( departmentId . length ( ) > 0 ) {
sqlWhere + = " and a.departmentid in(" + departmentId + ") " ;
}
if ( resourceId . length ( ) > 0 ) {
sqlWhere + = " and b.resourceid in(" + resourceId + ") " ;
}
if ( viewScope . equals ( "4" ) ) { //我的下属
if ( allLevel . equals ( "1" ) ) { //所有下属
sqlWhere + = " and a.managerstr like '%," + user . getUID ( ) + ",%'" ;
} else {
sqlWhere + = " and a.managerid=" + user . getUID ( ) ; //直接下属
}
}
if ( ! "1" . equals ( isNoAccount ) ) {
sqlWhere + = " and a.loginid is not null " + ( rs . getDBType ( ) . equals ( "oracle" ) ? "" : " and a.loginid<>'' " ) ;
}
//首先获取出差公出流程信息
Map < String , Object > evectionMap = new HashMap < > ( ) ;
String evectionTableName = Util . null2String ( bb . getPropValue ( "project_hostar" , "evectionTableName" ) ) ;
sql = " select c.resourceid, c.belongdate, c.longitude, c.latitude from ( " +
" select a.belongdate, b.id as resourceid, b.subcompanyid1, b.departmentid, b.managerstr, b.managerid, b.loginid, c.jd as longitude, c.wd as latitude from kq_flow_split_evection a " +
" left join hrmresource b " +
" on b.id = a.resourceid " +
" left join " + evectionTableName + " c " +
" on c.requestid = a.requestid " +
" where a.belongdate >='" + fromDate + "' and belongdate <='" + toDate + "' " +
" ) c " +
" where 1=1 " + sqlWhere ;
rs . execute ( sql ) ;
while ( rs . next ( ) ) {
String resourceid = Util . null2String ( rs . getString ( "resourceid" ) ) ;
String belongdate = Util . null2String ( rs . getString ( "belongdate" ) ) ;
String longitude = Util . null2String ( rs . getString ( "longitude" ) ) ;
String latitude = Util . null2String ( rs . getString ( "latitude" ) ) ;
evectionMap . put ( belongdate + "|" + resourceid , longitude + "|" + latitude ) ;
}
//获取外勤打卡数据
KQWorkTime kqWorkTime = new KQWorkTime ( ) ;
kqWorkTime . setIsFormat ( true ) ;
Map < String , Map < String , Object > > lsCheckInfo = new HashMap < > ( ) ;
for ( String key : evectionMap . keySet ( ) ) {
String [ ] split = key . split ( "\\|" ) ;
String kqDate = split [ 0 ] ;
String userId = split [ 1 ] ;
WorkTimeEntity workTime = kqWorkTime . getWorkTime ( userId , kqDate ) ;
List < TimeScopeEntity > lsSignTime = new ArrayList < > ( ) ;
List < TimeScopeEntity > lsWorkTime = new ArrayList < > ( ) ;
if ( workTime ! = null ) {
lsSignTime = workTime . getSignTime ( ) ; //允许打卡时间
lsWorkTime = workTime . getWorkTime ( ) ; //工作时间
}
//只支持一天一次上下班
if ( lsWorkTime ! = null & & lsWorkTime . size ( ) = = 1 ) {
TimeScopeEntity signTimeScope = lsSignTime . get ( 0 ) ;
TimeScopeEntity workTimeScope = lsWorkTime . get ( 0 ) ;
List < Map < String , Object > > legWorkInfos = new ArrayList < > ( ) ;
//获取允许打卡时间
String signBeginTime = signTimeScope . getBeginTime ( ) ;
bb . writeLog ( "signBeginTime: " + signBeginTime ) ;
if ( StringUtils . isNotBlank ( signBeginTime ) ) {
signBeginTime = signBeginTime + ":00" ;
}
bb . writeLog ( "signBeginTime: " + signBeginTime ) ;
//获取上班时间
String workBeginTime = workTimeScope . getBeginTime ( ) ;
bb . writeLog ( "workBeginTime: " + workBeginTime ) ;
if ( StringUtils . isNotBlank ( workBeginTime ) ) {
workBeginTime = workBeginTime + ":00" ;
}
bb . writeLog ( "workBeginTime: " + workBeginTime ) ;
String acqLegWorkSignSql = "select operate_time, longitude, latitude from mobile_sign where operater = ? and operate_date = '" + kqDate + "' and operate_time >='" + signBeginTime + "' order by operate_time asc " ;
bb . writeLog ( "acqLegWorkSignSql: " + acqLegWorkSignSql ) ;
bb . writeLog ( "userId: " + userId ) ;
rs . executeQuery ( acqLegWorkSignSql , userId ) ;
while ( rs . next ( ) ) {
String operateTime = Util . null2String ( rs . getString ( "operate_time" ) ) ;
String longitude = Util . null2String ( rs . getString ( "longitude" ) ) ;
String latitude = Util . null2String ( rs . getString ( "latitude" ) ) ;
if ( StringUtils . isNotBlank ( operateTime ) & & StringUtils . isNotBlank ( longitude ) & & StringUtils . isNotBlank ( latitude ) ) {
Map < String , Object > temp = new HashMap < > ( ) ;
temp . put ( "operateTime" , operateTime ) ;
temp . put ( "longitude" , longitude ) ;
temp . put ( "latitude" , latitude ) ;
legWorkInfos . add ( temp ) ;
}
}
bb . writeLog ( "legWorkInfos: " + legWorkInfos ) ;
if ( legWorkInfos ! = null & & legWorkInfos . size ( ) > 0 ) {
String tempSignIn = "" ;
String tempSignInLatitude = "" ;
String tempSignInLongitude = "" ;
String tempSignOutLatitude = "" ;
String tempSignOutLongitude = "" ;
String tempSignOut = "" ;
Map < String , Object > checkInfo = new HashMap < > ( ) ;
if ( legWorkInfos . size ( ) = = 1 ) { //只有一笔外勤卡直接算上班
Map < String , Object > temp = legWorkInfos . get ( 0 ) ;
String operateTime = Util . null2String ( temp . get ( "operateTime" ) ) ;
String longitude = Util . null2String ( temp . get ( "longitude" ) ) ;
String latitude = Util . null2String ( temp . get ( "latitude" ) ) ;
checkInfo . put ( "signDate" , kqDate ) ; //签到签退日期
checkInfo . put ( "signInTime" , operateTime ) ; //签到时间
checkInfo . put ( "signInLatitude" , latitude ) ; //签到纬度
checkInfo . put ( "signInLongitude" , longitude ) ; //签到经度
lsCheckInfo . put ( userId + "|" + kqDate , checkInfo ) ;
} else {
for ( Map < String , Object > temp : legWorkInfos ) {
String operateTime = Util . null2String ( temp . get ( "operateTime" ) ) ;
String longitude = Util . null2String ( temp . get ( "longitude" ) ) ;
String latitude = Util . null2String ( temp . get ( "latitude" ) ) ;
if ( operateTime . compareTo ( workBeginTime ) < 0 ) { //获取上班时间点之前最早的一笔卡
if ( StringUtils . isBlank ( tempSignIn ) ) {
tempSignIn = operateTime ;
tempSignInLatitude = latitude ;
tempSignInLongitude = longitude ;
} else {
if ( operateTime . compareTo ( tempSignIn ) < 0 ) {
tempSignIn = operateTime ;
tempSignInLatitude = latitude ;
tempSignInLongitude = longitude ;
}
}
}
if ( operateTime . compareTo ( workBeginTime ) > 0 ) { //下班卡取最晚的一笔
if ( StringUtils . isBlank ( tempSignIn ) ) {
tempSignOut = operateTime ;
tempSignOutLatitude = latitude ;
tempSignOutLongitude = longitude ;
} else {
if ( operateTime . compareTo ( tempSignOut ) > 0 ) {
tempSignOut = operateTime ;
tempSignOutLatitude = latitude ;
tempSignOutLongitude = longitude ;
}
}
}
}
checkInfo . put ( "signDate" , kqDate ) ; //签到签退日期
checkInfo . put ( "signInTime" , tempSignIn ) ; //签到时间
checkInfo . put ( "signInLatitude" , tempSignInLatitude ) ; //签到纬度
checkInfo . put ( "signInLongitude" , tempSignInLongitude ) ; //签到经度
checkInfo . put ( "signOutTime" , tempSignOut ) ; //签退时间
checkInfo . put ( "signOutLatitude" , tempSignOutLatitude ) ; //签退纬度
checkInfo . put ( "signOutLongitude" , tempSignOutLongitude ) ; //签退经度
lsCheckInfo . put ( userId + "|" + kqDate , checkInfo ) ;
}
}
}
}
HostarUtil hostarUtil = new HostarUtil ( ) ;
//获取经纬度半径
Double radius = 0.00 ;
String acqRadiusSql = "select radius from uf_leWorkRadius where (isDelete is null or isDelete = 0 )" ;
rs . executeQuery ( acqRadiusSql ) ;
while ( rs . next ( ) ) {
radius = Util . getDoubleValue ( Util . null2String ( rs . getString ( "radius" ) ) ) ;
}
String MealAlloTableName = Util . null2String ( bb . getPropValue ( "project_hostart" , "MealAllowanceTableName" ) ) ;
if ( StringUtils . isNotBlank ( MealAlloTableName ) ) {
//获取餐补判断时间
List < Map < String , String > > MealMap = new ArrayList < > ( ) ;
String acqTimeSql = "select startTime, endTime from " + MealAlloTableName + " where (isDelete is null or isDelete = 0)" ;
rs . executeQuery ( acqTimeSql ) ;
while ( rs . next ( ) ) {
String startTime = Util . null2String ( rs . getString ( "startTime" ) ) ;
String endTime = Util . null2String ( rs . getString ( "endTime" ) ) ;
Map < String , String > temp = new HashMap < > ( ) ;
temp . put ( "startTime" , startTime ) ;
temp . put ( "endTime" , endTime ) ;
MealMap . add ( temp ) ;
}
//根据外勤打卡数据计算餐补数据
for ( String key : lsCheckInfo . keySet ( ) ) {
String [ ] split = key . split ( "\\|" ) ;
String userId = split [ 0 ] ;
String kqDate = split [ 1 ] ;
Map < String , Object > temp = lsCheckInfo . get ( key ) ;
String signInTime = Util . null2String ( temp . get ( "signInTime" ) ) ;
String signOutTime = Util . null2String ( temp . get ( "signOutTime" ) ) ;
Double signInLatitude = Util . getDoubleValue ( Util . null2String ( temp . get ( "signInLatitude" ) ) ) ;
Double signInLongitude = Util . getDoubleValue ( Util . null2String ( temp . get ( "signInLongitude" ) ) ) ;
Double signOutLatitude = Util . getDoubleValue ( Util . null2String ( temp . get ( "signOutLatitude" ) ) ) ;
Double signOutLongitude = Util . getDoubleValue ( Util . null2String ( temp . get ( "signOutLongitude" ) ) ) ;
if ( StringUtils . isNotBlank ( signInTime ) & & StringUtils . isNotBlank ( signOutTime ) ) {
String lonAndLat = Util . null2String ( evectionMap . get ( kqDate + " |" + userId ) ) ;
String [ ] split1 = lonAndLat . split ( "\\|" ) ;
Double longitude = Util . getDoubleValue ( Util . null2String ( split1 [ 0 ] ) ) ;
Double latitude = Util . getDoubleValue ( Util . null2String ( split1 [ 1 ] ) ) ;
//判断经纬度是否符合标准
Double distanceIn = hostarUtil . calculateDistance ( latitude , longitude , signInLatitude , signInLongitude ) ; //上班
Double distanceOut = hostarUtil . calculateDistance ( latitude , longitude , signOutLatitude , signOutLongitude ) ; //下班
if ( distanceIn < = radius & & distanceOut < = radius ) {
for ( Map < String , String > me : MealMap ) {
String startTime = me . get ( "startTime" ) ;
String endTime = me . get ( "endTime" ) ;
if ( StringUtils . isNotBlank ( startTime ) & & StringUtils . isNotBlank ( endTime ) ) {
startTime = startTime + ":00" ;
endTime = endTime + ":00" ;
}
if ( ( signInTime . compareTo ( startTime ) < = 0 ) & & ( signOutTime . compareTo ( endTime ) > = 0 ) ) {
int t = Util . getIntValue ( Util . null2String ( datas . get ( "DailyMealAllow|" + resourceId + "|" + kqDate ) ) ) ;
if ( t < = 0 ) {
datas . put ( "DailyMealAllow|" + resourceId + "|" + kqDate , 1 ) ;
} else {
t = t + 1 ;
datas . put ( "DailyMealAllow|" + resourceId + "|" + kqDate , t ) ;
}
}
}
}
}
}
}
} catch ( Exception e ) {
writeLog ( e ) ;
}
return datas ;
}
/ * *
* 获 取 实 际 加 班 数 据 , 包 括 流 程 , 打 卡 生 成 的
* @return
@ -1948,7 +2231,7 @@ public class KQReportBiz extends BaseBean {
text = SystemEnv . getHtmlLabelName ( 20081 , user . getLanguage ( ) ) + beLateMins + SystemEnv . getHtmlLabelName ( 15049 , user . getLanguage ( ) ) ;
}
if ( graveBeLateMins > 0 ) { //严重迟到
text = SystemEnv . getHtmlLabelName ( 500546 , user . getLanguage ( ) ) + graveBeLateMins + SystemEnv . getHtmlLabelName ( 15049 , user . getLanguage ( ) ) ;
text = SystemEnv . getHtmlLabelName ( 500546 , user . getLanguage ( ) ) + graveBeLateMins + SystemEnv . getHtmlLabelName ( 15049 , user . getLanguage ( ) ) ;
}
if ( leaveEarlyMins > 0 ) { //早退
text = SystemEnv . getHtmlLabelName ( 20082 , user . getLanguage ( ) ) + leaveEarlyMins + SystemEnv . getHtmlLabelName ( 15049 , user . getLanguage ( ) ) ;