You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
326 lines
14 KiB
Java
326 lines
14 KiB
Java
package com.engine.kq.nbjh;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.engine.kq.biz.KQLeaveRulesComInfo;
|
|
import com.engine.kq.biz.KQWorkTime;
|
|
import weaver.common.DateUtil;
|
|
import weaver.conn.RecordSet;
|
|
import weaver.general.TimeUtil;
|
|
import weaver.general.Util;
|
|
import weaver.hrm.User;
|
|
import weaver.systeminfo.SystemEnv;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @Title
|
|
* @Author wangchaofa
|
|
* @CreateDate 2024/4/2
|
|
* @Version 1.0
|
|
* @Description
|
|
*/
|
|
public class KqUtil {
|
|
|
|
/**
|
|
* 获取 实际出勤天数(带有哺乳假流程的,提前打卡的情况)
|
|
* @param resourceId
|
|
* @param fromdate
|
|
* @param todate
|
|
* @return
|
|
*/
|
|
public static double getAttendancedays(String resourceId,String fromdate,String todate,User user){
|
|
double result = 0.00;
|
|
KQLeaveRulesComInfo kqLeaveRulesComInfo = new KQLeaveRulesComInfo();
|
|
RecordSet rs = new RecordSet();
|
|
String sql = " select resourceid, kqdate, workMins, belatemins, graveBeLateMins, leaveearlymins, graveLeaveEarlyMins, absenteeismmins, forgotcheckMins, forgotBeginWorkCheckMins, "+
|
|
" leaveMins,leaveInfo,evectionMins,outMins " +
|
|
" from kq_format_detail " +
|
|
" where resourceid = ? and kqdate>=? and kqdate<=? "+
|
|
" order by resourceid, kqdate, serialnumber ";
|
|
rs.executeQuery(sql,resourceId,fromdate,todate);
|
|
while (rs.next()) {
|
|
String userid = rs.getString("resourceid");
|
|
String kqdate = rs.getString("kqdate");
|
|
int workMins = rs.getInt("workMins");
|
|
int beLateMins = rs.getInt("beLateMins");
|
|
int leaveEarlyMins = rs.getInt("leaveEarlyMins");
|
|
int graveBeLateMins = rs.getInt("graveBeLateMins");
|
|
int absenteeismMins = rs.getInt("absenteeismMins");
|
|
int graveLeaveEarlyMins = rs.getInt("graveLeaveEarlyMins");
|
|
int forgotCheckMins = rs.getInt("forgotCheckMins");
|
|
int forgotBeginWorkCheckMins = rs.getInt("forgotBeginWorkCheckMins");
|
|
int leaveMins = rs.getInt("leaveMins");
|
|
String leaveInfo = rs.getString("leaveInfo");
|
|
int evectionMins = rs.getInt("evectionMins");
|
|
int outMins = rs.getInt("outMins");
|
|
|
|
// 判断 指定日期 是否在 哺乳假流程 日期范围内
|
|
boolean bool = checkIsBetweenRange(userid,kqdate);
|
|
String text = "";
|
|
|
|
if (workMins<=0) {
|
|
if(text.length()>0) text +=" ";
|
|
text += SystemEnv.getHtmlLabelName(26593, user.getLanguage());
|
|
} else {
|
|
if (absenteeismMins > 0) {//旷工
|
|
if(text.length()>0) text+=" ";
|
|
text += SystemEnv.getHtmlLabelName(20085, user.getLanguage());
|
|
}else {
|
|
if (beLateMins > 0) {//迟到
|
|
if (text.length() > 0) text += " ";
|
|
text += SystemEnv.getHtmlLabelName(20081, user.getLanguage());
|
|
}
|
|
if (graveBeLateMins > 0) {//严重迟到
|
|
if (text.length() > 0) text += " ";
|
|
text += SystemEnv.getHtmlLabelName(500546, user.getLanguage());
|
|
}
|
|
if (leaveEarlyMins > 0) {//早退
|
|
if (text.length() > 0) text += " ";
|
|
text += SystemEnv.getHtmlLabelName(20082, user.getLanguage());
|
|
}
|
|
if (graveLeaveEarlyMins > 0) {//严重早退
|
|
if (text.length() > 0) text += " ";
|
|
text += SystemEnv.getHtmlLabelName(500547, user.getLanguage());
|
|
}
|
|
if (forgotCheckMins > 0) {//漏签
|
|
if (text.length() > 0) text += " ";
|
|
text += SystemEnv.getHtmlLabelName(20086, user.getLanguage());
|
|
}
|
|
if (forgotBeginWorkCheckMins > 0) {//漏签
|
|
if (text.length() > 0) text += " ";
|
|
text += SystemEnv.getHtmlLabelName(20086, user.getLanguage());
|
|
}
|
|
}
|
|
}
|
|
if (leaveMins > 0) {//请假
|
|
Map<String, Object> jsonObject = null;
|
|
if(leaveInfo.length()>0){
|
|
jsonObject = JSON.parseObject(leaveInfo);
|
|
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
|
|
String newLeaveType = entry.getKey();
|
|
String tmpLeaveMins = Util.null2String(entry.getValue());
|
|
if(text.indexOf(kqLeaveRulesComInfo.getLeaveName(newLeaveType))==-1){
|
|
if (text.length() > 0) text += " ";
|
|
text += Util.formatMultiLang( kqLeaveRulesComInfo.getLeaveName(newLeaveType),""+user.getLanguage());
|
|
}
|
|
}
|
|
}else{
|
|
if(text.indexOf(SystemEnv.getHtmlLabelName(670, user.getLanguage()))==-1) {
|
|
if (text.length() > 0) text += " ";
|
|
text += SystemEnv.getHtmlLabelName(670, user.getLanguage());
|
|
}
|
|
}
|
|
}
|
|
if (evectionMins > 0) {//出差
|
|
if(text.indexOf(SystemEnv.getHtmlLabelName(20084, user.getLanguage()))==-1) {
|
|
if (text.length() > 0) text += " ";
|
|
text += SystemEnv.getHtmlLabelName(20084, user.getLanguage());
|
|
}
|
|
}
|
|
if (outMins > 0) {//公出
|
|
if(text.indexOf(SystemEnv.getHtmlLabelName(24058, user.getLanguage()))==-1) {
|
|
if (text.length() > 0) text += " ";
|
|
text += SystemEnv.getHtmlLabelName(24058, user.getLanguage());
|
|
}
|
|
}
|
|
|
|
if(text.length()==0) {
|
|
result += 1;
|
|
}else{
|
|
//包含 漏签、早退、严重早退、迟到、严重迟到
|
|
if(checkHasSignInfo(userid,kqdate)) {
|
|
//当天有 哺乳假 或者 当天 在哺乳假的日期范围内
|
|
if(bool) {
|
|
result += 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
rs.writeLog("================== KqUtil getAttendancedays ==================== "+ result);
|
|
return result;
|
|
}
|
|
|
|
public static boolean checkHasSignInfo(String userid,String date){
|
|
boolean bool = false;
|
|
RecordSet rs = new RecordSet();
|
|
rs.executeQuery("select * from HrmScheduleSign where userId=? and signDate=?",userid,date);
|
|
if(rs.next()){
|
|
bool = true;
|
|
}
|
|
return bool;
|
|
}
|
|
|
|
/**
|
|
* 判断日期是否在 哺乳假流程日期范围内
|
|
* @param userid
|
|
* @param date
|
|
* @return
|
|
*/
|
|
public static boolean checkIsBetweenRange(String userid,String date){
|
|
boolean bool = false;
|
|
RecordSet rs = new RecordSet();
|
|
String breastfeedLeave_table = rs.getPropValue("nbjh_ygdjblc","breastfeedLeave_table");
|
|
rs.executeQuery(" select a.mtgjxs as result,a.ksrq,a.jsrq from "+ breastfeedLeave_table +" a,workflow_requestbase b " +
|
|
" where a.requestid=b.requestid and b.currentnodetype=3 " +
|
|
" and a.ksrq <= ? and a.jsrq >= ? and a.xm = ?",date,date,userid);
|
|
if(rs.next()){
|
|
bool = true;
|
|
}
|
|
return bool;
|
|
}
|
|
|
|
/**
|
|
* 获取 哺乳假 数据
|
|
* @param fromDate
|
|
* @param toDate
|
|
* @param userid
|
|
* @return
|
|
* 查询的 2024-03-01 2024-03-31
|
|
* 流程里的 2024-03-12 2024-11-21
|
|
* 2024-02-10 2024-04-10
|
|
* 2024-02-10 2024-02-20
|
|
*/
|
|
public static double getBreastfeedLeave(String fromDate,String toDate,String userid){
|
|
double result = 0.00;
|
|
int ycqdays = 0;
|
|
double day = 0.00;
|
|
RecordSet rs = new RecordSet();
|
|
String lc_fromDate = "";
|
|
String lc_toDate = "";
|
|
rs.writeLog("============== fromDate =================== "+ fromDate);
|
|
rs.writeLog("============== toDate =================== "+ toDate);
|
|
String currentdate = TimeUtil.getCurrentDateString();
|
|
|
|
String breastfeedLeave_table = rs.getPropValue("nbjh_ygdjblc","breastfeedLeave_table");
|
|
rs.executeQuery(" select a.mtgjxs as result,a.ksrq,a.jsrq from "+ breastfeedLeave_table +" a,workflow_requestbase b " +
|
|
" where a.requestid=b.requestid and b.currentnodetype=3 " +
|
|
" and a.xm = ?",userid);
|
|
if(rs.next()){
|
|
lc_fromDate = Util.null2String(rs.getString("ksrq"));
|
|
lc_toDate = Util.null2String(rs.getString("jsrq"));
|
|
day = Util.getDoubleValue(rs.getString("result"),0.00);
|
|
|
|
// 流程里的开始日期 2024-03-12 >= 查询的开始日期 2024-03-01
|
|
if(compareDate(lc_fromDate,fromDate)){
|
|
//流程里的开始日期 2024-03-12 <= 查询的结束日期 2024-03-031
|
|
if(compareDate(toDate,lc_fromDate)){
|
|
//流程里的结束日期 2024-03-20 <= 查询的结束日期 2024-03-31 。 此时 应该 计算 流程里的开始日期 到 流程里的结束日期,这个范围内的 应出勤天数
|
|
if(compareDate(toDate,lc_toDate)){
|
|
ycqdays = getWorkdays(lc_fromDate,lc_toDate,userid);
|
|
}
|
|
//流程里的结束日期 2024-04-10 > 查询的结束日期 2024-03-31 。此时 应该 计算 流程里的开始日期 到 查询的结束日期,这个范围内的 应出勤天数
|
|
else{
|
|
ycqdays = getWorkdays(lc_fromDate,toDate,userid);
|
|
}
|
|
}
|
|
//流程里的开始日期 2024-04-10 > 查询的结束日期 2024-03-31
|
|
else{
|
|
ycqdays = 0;
|
|
}
|
|
}
|
|
//流程里的开始日期 2024-02-10 < 查询的开始日期 2024-03-01
|
|
else{
|
|
//流程里的结束日期 2024-03-10 >= 查询的开始日期 2024-03-01
|
|
if(compareDate(lc_toDate,fromDate)){
|
|
//流程里的结束日期 2024-03-10 <= 查询的结束日期 2024-03-31 。此时 应该 计算 查询的开始日期 到 流程里的结束日期,这个范围内的 应出勤天数
|
|
if(compareDate(toDate,lc_toDate)){
|
|
//流程里的结束日期 >= 当前日期
|
|
if(compareDate(lc_toDate,currentdate)){
|
|
ycqdays = getWorkdays(fromDate,currentdate,userid);
|
|
}else{
|
|
ycqdays = getWorkdays(fromDate,lc_toDate,userid);
|
|
}
|
|
}
|
|
// 流程里的结束日期 2024-04-10 > 查询的结束日期 2024-03-31 。此时 应该 计算 查询的开始日期 到 查询的结束日期,这个范围内的 应出勤天数
|
|
else{
|
|
//流程里的结束日期 >= 当前日期
|
|
if(compareDate(toDate,currentdate)){
|
|
ycqdays = getWorkdays(fromDate,currentdate,userid);
|
|
}else{
|
|
ycqdays = getWorkdays(fromDate,toDate,userid);
|
|
}
|
|
}
|
|
}
|
|
//查询的开始日期 2024-03-01 > 流程里的结束日期 2024-02-20
|
|
else{
|
|
ycqdays = 0;
|
|
}
|
|
}
|
|
}
|
|
rs.writeLog("=============== ycqdays ================= "+ ycqdays);
|
|
rs.writeLog("=============== day ================= "+ day);
|
|
result = ycqdays * day;
|
|
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 获取日期范围内某个人的应出勤天数
|
|
* @param fromDate 开始日期
|
|
* @param toDate 结束日期
|
|
* @param resourceId 人员id
|
|
* @return
|
|
*/
|
|
public static int getWorkdays(String fromDate, String toDate, String resourceId) {
|
|
int workDays = 0;
|
|
/**统计应出勤天数*/
|
|
KQWorkTime kqWorkTime = new KQWorkTime();
|
|
boolean isEnd = false;
|
|
for (String date = fromDate; !isEnd; ) {
|
|
if (date.compareTo(toDate)>=0) {
|
|
isEnd = true;
|
|
}
|
|
boolean isWorkDay = kqWorkTime.isWorkDay(resourceId, date);
|
|
if (isWorkDay) {
|
|
workDays += 1;
|
|
}
|
|
date = DateUtil.getDate(date, 1);
|
|
}
|
|
return workDays;
|
|
}
|
|
|
|
/**
|
|
* 比较时间的大小
|
|
* @param a
|
|
* @param b
|
|
* @return
|
|
* @throws ParseException
|
|
*/
|
|
public static boolean compareDate(String a, String b){
|
|
boolean bool = false;
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
try {
|
|
long t1 = sdf.parse(a).getTime();
|
|
long t2 = sdf.parse(b).getTime();
|
|
if (t1 >= t2) {
|
|
bool = true;
|
|
}
|
|
return bool;
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
}
|
|
return bool;
|
|
}
|
|
|
|
/**
|
|
* 方法描述 : 对两个字符串进行金额的相加
|
|
* @param a
|
|
* @param b
|
|
* @return
|
|
* String
|
|
*/
|
|
public static String floatAdd(String a, String b) {
|
|
a=a.equals("")?"0":a;
|
|
b=b.equals("")?"0":b;
|
|
BigDecimal bg1 = new BigDecimal(a);
|
|
BigDecimal bg2 = new BigDecimal(b);
|
|
BigDecimal bd = bg1.add(bg2);
|
|
return bd.toString();
|
|
}
|
|
|
|
|
|
}
|