From 08f04778797c7f936e99a20e4c7be581153554fe Mon Sep 17 00:00:00 2001 From: Administrator <704728292@qq.com> Date: Wed, 6 Mar 2024 10:24:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=83=E5=8B=A4=E5=AF=B9=E7=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cmd/attendanceButton/PunchButtonCmd.java | 646 ++++++++++++++++++ .../attendanceButton/PunchOutButtonCmd.java | 22 + .../interfaces/hostar/job/AutoSchedulJob.java | 92 +++ 3 files changed, 760 insertions(+) create mode 100644 src/com/engine/kq/cmd/attendanceButton/PunchButtonCmd.java create mode 100644 src/weaver/interfaces/hostar/job/AutoSchedulJob.java diff --git a/src/com/engine/kq/cmd/attendanceButton/PunchButtonCmd.java b/src/com/engine/kq/cmd/attendanceButton/PunchButtonCmd.java new file mode 100644 index 0000000..993778a --- /dev/null +++ b/src/com/engine/kq/cmd/attendanceButton/PunchButtonCmd.java @@ -0,0 +1,646 @@ +package com.engine.kq.cmd.attendanceButton; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.cloudstore.dev.api.util.EMManager; +import com.engine.common.biz.AbstractCommonCommand; +import com.engine.common.entity.BizLogContext; +import com.engine.core.interceptor.CommandContext; +import com.engine.hostar.util.HostarUtil; +import com.engine.kq.biz.*; +import com.engine.kq.biz.chain.shiftinfo.ShiftInfoBean; +import com.engine.kq.entity.KQGroupEntity; +import com.engine.kq.entity.WorkTimeEntity; +import com.engine.kq.log.KQLog; +import com.engine.kq.timer.KQQueue; +import com.engine.kq.timer.KQTaskBean; +import com.engine.kq.util.KQDurationCalculatorUtil; +import com.engine.kq.wfset.util.SplitActionUtil; +import com.google.common.collect.Maps; +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; +import java.util.*; +import java.util.Map.Entry; +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang3.StringUtils; +import weaver.common.DateUtil; +import weaver.conn.RecordSet; +import weaver.dateformat.DateTransformer; +import weaver.dateformat.TimeZoneVar; +import weaver.general.Util; +import weaver.hrm.User; +import weaver.systeminfo.SystemEnv; + +/** + * 考勤的 签到签退 + */ +public class PunchButtonCmd extends AbstractCommonCommand> { + public KQLog kqLog = new KQLog(); + private HttpServletRequest request; + private Map logMap = Maps.newHashMap(); + private Map workTimeEntityLogMap = Maps.newHashMap(); + private final List LIST = Arrays.asList("1", "8", "14","15"); + + public PunchButtonCmd(HttpServletRequest request,Map params, User user) { + this.request = request; + this.user = user; + this.params = params; + } + + @Override + public Map execute(CommandContext commandContext) { + Map retmap = new HashMap(); + try{ + insertSign(retmap); + + }catch (Exception e) { + retmap.put("status", "-1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + writeLog(e); + } + kqLog.info(user.getLastname()+":PunchButtonCmd:retmap:"+retmap); + KQCardLogBiz.logCardInfo(user.getUID()+"", logMap, workTimeEntityLogMap, "punchButton"); + + return retmap; + } + + /** + * 检验ip是否在考勤组设置的范围要求内 + * @param ismobile + */ + private boolean checkIsInIp(String ismobile) { +// if("1".equalsIgnoreCase(ismobile)){ +// return true; +// } + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + String clientAddress = Util.getIpAddr(request); + kqLog.info("PunchButtonCmd:clientAddress:"+clientAddress); + return kqGroupBiz.getIsInScopeV4V6(user.getUID()+"", clientAddress,ismobile); + } + + public void insertSign(Map retmap) throws Exception{ + logMap.put("lastname", user.getLastname()); + logMap.put("params", params); + kqLog.info(user.getLastname()+":PunchButtonCmd:params:"+params); + RecordSet rs = new RecordSet(); + String deviceInfo = Util.null2String(params.get("deviceInfo")); + JSONObject jsonObject = null; + if(deviceInfo.length() > 0){ + jsonObject = JSON.parseObject(deviceInfo); + JSONObject jsonObject1 = new JSONObject(); + Set> jsonSet = jsonObject.entrySet(); + for(Entry js : jsonSet){ + String key = js.getKey(); + String value = Util.null2String(js.getValue()); + jsonObject1.put(key, value); + } + if(!jsonObject1.isEmpty()){ + deviceInfo = jsonObject1.toJSONString(); + } + } + //应上班 工作时间点 + String time = Util.null2String(params.get("time")); + //应上班 工作时间 带日期 + String datetime = Util.null2String(params.get("datetime")); + //允许打卡时段 带日期 + String signSectionTime = Util.null2String(params.get("signSectionTime")); + //上传照片 + String attachment = Util.null2String(params.get("fileids")); + + //打卡所属worksection的对应的点 + String type = Util.null2String(params.get("type")); + //所属打卡日期 + String belongdate = Util.null2String(params.get("belongdate")); + belongdate = belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate; + String islastsign = Util.null2String(params.get("islastsign")); + String isfirstsign = Util.null2String(params.get("isfirstsign")); + + String workmins = Util.null2String(params.get("workmins")); + //针对非工作时段 签退的时候记录的签到数据 用于计算加班 + String signInTime4Out = Util.null2String(params.get("signInTime4Out")); + //允许打卡的范围 + String signsection = Util.null2String(params.get("signSection")); + + //手机打卡部分 + String longitude = Util.null2String(params.get("longitude")); + String latitude = Util.null2String(params.get("latitude")); + double d_longitude = Util.getDoubleValue(longitude); + double d_latitude = Util.getDoubleValue(latitude); + if(d_latitude <= 0){ + latitude = ""; + } + if(d_longitude <= 0){ + longitude = ""; + } + //wifi用的 + String mac = Util.null2String(params.get("mac")); + String sid = Util.null2String(params.get("sid")); + String addr = Util.null2String(params.get("position")); + String ismobile = Util.null2String(params.get("ismobile")); + //区分是来自于钉钉还是EM7 + String browser = Util.null2String(params.get("browser")); + //自由班制处理 + String isfree = Util.null2String(Util.null2String(params.get("isfree")),"0"); + + //上班打卡 允许最晚打卡时间 + String signSectionEndTime = Util.null2String(params.get("signSectionEndTime")); + //下班打卡 允许最早打卡时间 + String signSectionBeginTime = Util.null2String(params.get("signSectionBeginTime")); + + String locationshowaddress = Util.null2String(params.get("locationshowaddress")); + if(locationshowaddress.equals("1")){//记录统一地址 + String locationid = Util.null2String(params.get("locationid"));//办公地点id + if(locationid.length()>0){//如果开启统一显示,就用配置的地址 + KQLoactionComInfo kqLoactionComInfo = new KQLoactionComInfo(); + addr = kqLoactionComInfo.getLocationname(locationid); + } + } + + DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss"); + LocalTime localTime = LocalTime.now(); + String signTime =localTime.format(dateTimeFormatter); + String signDate = LocalDate.now().format(dateFormatter); + + String timeZone = Util.null2String(TimeZoneVar.getTimeZone(),""); + //处理多时区 + String timeZoneConversion = Util.null2String(new weaver.general.BaseBean().getPropValue("weaver_timezone_conversion","timeZoneConversion")).trim(); + logMap.put("timeZoneConversion", timeZoneConversion); + if("1".equals(timeZoneConversion)) { + DateTransformer dateTransformer=new DateTransformer(); + String[] zone_localTime = dateTransformer.getLocaleDateAndTime(signDate,signTime); + kqLog.info(user.getLastname()+":TimeZoneVar.getTimeZone():"+TimeZoneVar.getTimeZone()+":zone_localTime:"+JSON.toJSONString(zone_localTime)); + if(zone_localTime != null && zone_localTime.length == 2){ + signDate = zone_localTime[0]; + signTime = zone_localTime[1]; + } + } + + int userId = user.getUID(); + String userType = user.getLogintype(); + String signType = "on".equalsIgnoreCase(type) ? "1" : "2"; + String clientAddress = Util.getIpAddr(request); + boolean isInIp = checkIsInIp(ismobile); + logMap.put("clientAddress", clientAddress); + + if(!isInIp){ + retmap.put("message", SystemEnv.getHtmlLabelName(20157,user.getLanguage())); + retmap.put("isInIp", "0"); + } + String isInCom = isInIp ? "1" : "0"; + + //是否是考勤例外人员 + boolean isExclude = false; + + KQGroupMemberComInfo kqGroupMemberComInfo = new KQGroupMemberComInfo(); + KQWorkTime kqWorkTime = new KQWorkTime(); + WorkTimeEntity workTimeEntity = kqWorkTime.getWorkTime(user.getUID()+"", signDate); + String userinfo = "#userid#"+user.getUID()+"#getUserSubCompany1#"+user.getUserSubCompany1()+"#getUserSubCompany1#"+user.getUserDepartment() + +"#getJobtitle#"+user.getJobtitle(); + workTimeEntityLogMap.put("resourceid", userinfo); + workTimeEntityLogMap.put("splitDate", signDate); + workTimeEntityLogMap.put("workTimeEntity", workTimeEntity); + String groupid = workTimeEntity.getGroupId(); + logMap.put("groupid", groupid); + KQGroupEntity kqGroupEntity = kqGroupMemberComInfo.getUserKQGroupInfo(user.getUID()+""); + String kqGroupEntityInfo = kqGroupEntity != null ? JSON.toJSONString(kqGroupEntity): ""; + logMap.put("kqGroupEntityInfo", kqGroupEntityInfo); + if (kqGroupEntity != null && ("," + kqGroupEntity.getExcludeid() + ",").indexOf("," + user.getUID() + ",")>-1) {//排除人员无需计算考勤时间 + isExclude = true; + } + + String[] signsections = signsection.split("#"); + if(!"1".equalsIgnoreCase(isfree)){ + if(signsections != null && signsections.length == 2){ + //判断是未签到直接签退 + String signedMsg = signedMsg(userId+"", signType, user,signsections,signSectionBeginTime,signSectionEndTime); + if(signedMsg.length() > 0){ + retmap.put("status", "1"); + retmap.put("message", signedMsg); + isInCom = "0"; + } + } + } + + String datetime_timezone = signDate+" "+signTime; + LocalDateTime nowDateTime = LocalDateTime.parse(datetime_timezone,fullFormatter); + kqLog.info("timeZone:"+timeZone+":signDate:"+signDate+":signTime:"+signTime+":nowDateTime:"+nowDateTime); + + if("1".equalsIgnoreCase(signType) && signSectionTime.length() > 0 ){ + LocalDateTime startWorkDateTime = LocalDateTime.parse(signSectionTime,fullFormatter); + if(nowDateTime.isBefore(startWorkDateTime)){ + Duration duration = Duration.between(nowDateTime, startWorkDateTime); + retmap.put("status", "1"); + retmap.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005326,weaver.general.ThreadVarLanguage.getLang())+""+duration.toMinutes()+""+weaver.systeminfo.SystemEnv.getHtmlLabelName(15049,weaver.general.ThreadVarLanguage.getLang())+""); + isInCom = "0"; + } + + }else if("2".equalsIgnoreCase(signType) && signSectionTime.length() > 0 ){ + LocalDateTime endWorkDateTime = LocalDateTime.parse(signSectionTime,fullFormatter); + if(nowDateTime.isAfter(endWorkDateTime)){ + Duration duration = Duration.between(endWorkDateTime, nowDateTime); + retmap.put("status", "1"); + retmap.put("message", ""+weaver.systeminfo.SystemEnv.getHtmlLabelName(10005327,weaver.general.ThreadVarLanguage.getLang())+""+duration.toMinutes()+""+weaver.systeminfo.SystemEnv.getHtmlLabelName(15049,weaver.general.ThreadVarLanguage.getLang())+""); + isInCom = "0"; + } + } + + //记录下是来自于E9的pc端签到 + String signfrom = "e9pc"; + if("1".equalsIgnoreCase(ismobile)){ + signfrom = "e9mobile"; + boolean needLocationRange = false; + boolean needWifiRange = false; + boolean isLocationRange = false; + boolean isWifiRange = false; + KQGroupBiz kqGroupBiz = new KQGroupBiz(); + Map locationMap = kqGroupBiz.checkLocationScope(userId+"",longitude,latitude); + logMap.put("locationMap", locationMap); + String locationNeedCheck = Util.null2String(locationMap.get("needCheck")); + boolean locationInScope = Boolean.parseBoolean(Util.null2String(locationMap.get("inScope"))); + if("1".equalsIgnoreCase(locationNeedCheck)){ + needLocationRange = true; + if(locationInScope){ + isLocationRange = true; + } + } + String wifiNeedCheck = ""; + Map wifiMap = kqGroupBiz.checkWifiScope(userId+"", sid, mac); + logMap.put("wifiMap", wifiMap); + wifiNeedCheck = Util.null2String(wifiMap.get("needCheck")); + boolean wifiInScope = Boolean.parseBoolean(Util.null2String(wifiMap.get("inScope"))); + if("1".equalsIgnoreCase(wifiNeedCheck)){ + needWifiRange = true; + if(wifiInScope){ + isWifiRange = true; + } + } + if(needLocationRange){ + if(isLocationRange){ + }else{ + if(needWifiRange){ + if(isWifiRange){ + }else{ + //地理位置开启,而且不在范围内,且开启wifi验证,不在范围内 + retmap.put("message", SystemEnv.getHtmlLabelName(507524, user.getLanguage())); + isInCom = "0"; + } + }else { + //地理位置开启,而且不在范围内,且未开启wifi验证 + retmap.put("message", SystemEnv.getHtmlLabelName(500510, user.getLanguage())); + isInCom = "0"; + } + } + }else{ + if(needWifiRange) { + if (isWifiRange) { + } else { + //地理位置未开启,且开启wifi验证,不在范围内 + retmap.put("message", SystemEnv.getHtmlLabelName(507524, user.getLanguage())); + isInCom = "0"; + } + } + } + + if("DingTalk".equalsIgnoreCase(browser)){ + signfrom = "DingTalk"; + }else if("Wechat".equalsIgnoreCase(browser)){ + signfrom = "Wechat"; + String weChat_deviceid = Util.null2String(request.getSession().getAttribute(EMManager.DeviceId)); + logMap.put("weChat_deviceid", weChat_deviceid); + kqLog.info("EMManager.DeviceId:"+EMManager.DeviceId+":weChat_deviceid:"+weChat_deviceid); + if(weChat_deviceid.length() > 0){ + //微信打卡的设备号需要单独处理 + if(jsonObject != null){ + jsonObject.put("deviceId", weChat_deviceid); + }else{ + jsonObject = new JSONObject(); + jsonObject.put("deviceId", weChat_deviceid); + } + if(!jsonObject.isEmpty()){ + deviceInfo = jsonObject.toJSONString(); + } + } + } + } + String signStatus = ""; + + if(!"1".equalsIgnoreCase(isfree) && datetime.length() > 0){ + signStatus = getSignStatus(signType,datetime,user.getUID()+"",belongdate,nowDateTime); + logMap.put("signStatus", signStatus); + } + + if(isExclude){ + signStatus = ButtonStatusEnum.NORMAL.getStatusCode(); + } + + String punchSql = "insert into HrmScheduleSign(userId,userType,signType,signDate,signTime,clientAddress,isInCom,timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo) "+ + " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + boolean isOk = rs.executeUpdate(punchSql,userId,userType,signType,signDate,signTime,clientAddress,isInCom, + timeZone,belongdate,signfrom,longitude,latitude,addr,deviceInfo); + if(!isOk){ + retmap.put("status", "1"); + retmap.put("message", SystemEnv.getHtmlLabelName(382661,user.getLanguage())); + return ; + } + logMap.put("punchSql", punchSql); + logMap.put("punchSql_isOk", isOk); + kqLog.info(user.getLastname()+":PunchButtonCmd:punchSql:"+punchSql+":isOk:"+isOk); + + //打卡提醒处理 + String remindSql = "insert into hrmschedulesign_remind(userId,signType,signDate,signTime,belongdate) values(?,?,?,?,?)"; + isOk = rs.executeUpdate(remindSql, userId,signType,signDate,signTime,belongdate); + kqLog.info(user.getLastname()+":PunchButtonCmd:remindSql:"+remindSql+":isOk:"+isOk); + + //增加自动排班 + kqLog.info("PunchButtonCmd.format in >>>>>userId" + userId + "kqDate==" + signDate+"format.groupId:"+groupid+"format.serialId:"+workTimeEntity.getSerialId()); + if(LIST.contains(groupid)&&StringUtils.isBlank(workTimeEntity.getSerialId())) { + RecordSet rt = new RecordSet(); + //休息日或节假日给休息班次 + int changeType = KQOvertimeRulesBiz.getChangeType(Util.null2String(userId), signDate); + kqLog.info("format.changeType:" + changeType); + String sql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid,isdelete)values(?,?,?,?,?)"; + //考勤当天是节假日或者休息日 + if (changeType != 2) { + //休息班 + boolean b = rt.executeUpdate(sql, signDate, "-1", Util.null2String(userId), groupid, "0"); + kqLog.info("PunchButtonCmd.b1:" + b); + } else { + String dybc = ""; + //正常打卡,排对应打卡地点对应班次 + //2.查询指定打卡地点的经纬度及范围的list + List> list2 = new ArrayList<>(); + //2.1查询出打卡地点经纬度建模list + String sql2 = "select jd,wd,bj,dybc from uf_jwdbj"; + rt.execute(sql2); + while (rt.next()) { + Map map = new HashMap<>(); + map.put("jd", Util.null2String(rt.getString("jd"))); + map.put("wd", Util.null2String(rt.getString("wd"))); + map.put("bj", Util.null2String(rt.getString("bj"))); + map.put("dybc", Util.null2String(rt.getString("dybc"))); + list2.add(map); + } + kqLog.info("PunchButtonCmd.list2:" + list2); + for (Map map : list2) { + Double distance = new HostarUtil().calculateDistance(d_latitude, d_longitude, Util.getDoubleValue(map.get("wd")), Util.getDoubleValue(map.get("jd"))); + if (distance <= Util.getDoubleValue(map.get("bj"))) { + dybc = map.get("dybc"); + } + } + kqLog.info("PunchButtonCmd.dybc:" + dybc); + //设置考勤班次为对应班次 + if(StringUtils.isNotBlank(dybc)){ + boolean b = rt.executeUpdate(sql, signDate, dybc, Util.null2String(userId), groupid, "0"); + kqLog.info("PunchButtonCmd.b2:" + b); + } + } + } + + //同步更新考勤数据到考勤报表 + new KQFormatBiz().formatDate(""+userId,(belongdate.length() == 0 ? DateUtil.getCurrentDate() : belongdate)); + //点击签退的时候,可能存在加班数据生成的情况 + if("2".equalsIgnoreCase(signType)){ + if("1".equalsIgnoreCase(islastsign)){ + List tasks = new ArrayList<>(); + List after_tasks = new ArrayList<>(); + SplitActionUtil.pushOverTimeTasks(belongdate, belongdate, ""+userId,tasks); + if(!tasks.isEmpty()){ + for(KQTaskBean kqTaskBean : tasks){ + after_tasks.add(kqTaskBean); + } + } + logMap.put("after_tasks", after_tasks); + if(!after_tasks.isEmpty()){ + KQQueue.writeTasks(after_tasks); + } + } + } + if("1".equalsIgnoreCase(signType)){ + if("1".equalsIgnoreCase(isfirstsign)){ + List tasks = new ArrayList<>(); + List before_tasks = new ArrayList<>(); + SplitActionUtil.pushOverTimeTasks(belongdate, belongdate, ""+userId,tasks); + if(!tasks.isEmpty()){ + for(KQTaskBean kqTaskBean : tasks){ + kqTaskBean.setTasktype("punchcard"); + before_tasks.add(kqTaskBean); + } + } + logMap.put("before_tasks", before_tasks); + if(!before_tasks.isEmpty()){ + KQQueue.writeTasks(before_tasks); + } + } + } + + String reSignStatus = reSignStatus(user.getUID()+"",signType,nowDateTime,belongdate); + if(Util.null2String(reSignStatus,"").length() > 0){ + signStatus = reSignStatus; + } + + retmap.put("status", "1"); + retmap.put("signdate", signDate); + retmap.put("signtime", signTime); + retmap.put("kqstatus", signStatus); + + if(!"1".equalsIgnoreCase(signStatus) && !"2".equalsIgnoreCase(signStatus)){ + if("".equalsIgnoreCase(Util.null2String(retmap.get("message")))){ + retmap.put("success", "1"); + retmap.put("message", SystemEnv.getHtmlLabelName(512596,weaver.general.Util.getIntValue(user.getLanguage()))); + } + } + logMap.put("retmap", retmap); + } + + public String reSignStatus(String userid, String signType, LocalDateTime nowDateTime, + String workdate) { + String signStatus = ""; + + String shift_begindateworktime = ""; + String shift_enddateworktime = ""; + ShiftInfoBean shiftInfoBean = KQDurationCalculatorUtil.getWorkTime(userid, workdate,false); + if(shiftInfoBean == null){ + return signStatus; + } + Map shifRuleMap = Maps.newHashMap(); + KQShiftRuleInfoBiz.getShiftRuleInfo(shiftInfoBean,userid,shifRuleMap); + KQTimesArrayComInfo arrayComInfo = new KQTimesArrayComInfo(); + if(!shifRuleMap.isEmpty()) { + DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String datetime = ""; + if (shifRuleMap.containsKey("shift_beginworktime")) { + String shift_beginworktime = Util.null2String(shifRuleMap.get("shift_beginworktime")); + if (shift_beginworktime.length() > 0) { + int shift_beginworktime_index = -1; + shift_beginworktime_index = arrayComInfo.getArrayindexByTimes(shift_beginworktime); + datetime = workdate+" "+shift_beginworktime+":00"; + if(shift_beginworktime_index >= 1440){ + //跨天了 + datetime = DateUtil.addDate(workdate, 1)+" "+arrayComInfo.turn48to24Time(shift_beginworktime)+":00"; + } + } + } + if (shifRuleMap.containsKey("shift_endworktime")) { + String shift_endworktime = Util.null2String(shifRuleMap.get("shift_endworktime")); + if (shift_endworktime.length() > 0) { + int shift_endworktime_index = -1; + shift_endworktime_index = arrayComInfo.getArrayindexByTimes(shift_endworktime); + datetime = workdate+" "+shift_endworktime+":00"; + if(shift_endworktime_index >= 1440) { + //跨天了 + datetime = DateUtil.addDate(workdate, 1)+" "+arrayComInfo.turn48to24Time(shift_endworktime)+":00"; + } + } + } + + if (datetime.length() > 0) { + if("1".equalsIgnoreCase(signType)) { + LocalDateTime startWorkDateTime = LocalDateTime.parse(datetime, fullFormatter); + //打卡时间比上班时间晚,迟到了 + if (nowDateTime.isAfter(startWorkDateTime)) { + signStatus = ButtonStatusEnum.BELATE.getStatusCode(); + } else { + signStatus = ButtonStatusEnum.NORMAL.getStatusCode(); + } + } else if ("2".equalsIgnoreCase(signType)) { + LocalDateTime endWorkDateTime = LocalDateTime.parse(datetime, fullFormatter); + //签退的话 + if (nowDateTime.isBefore(endWorkDateTime)) { + signStatus = ButtonStatusEnum.LEAVEERALY.getStatusCode(); + } else { + signStatus = ButtonStatusEnum.NORMAL.getStatusCode(); + } + } else { + writeLog(user.getLastname() + nowDateTime + ":竟然没有传:" + signType); + return ""; + } + } + } + return signStatus; + } + + /** + * 上班前打卡目前是 视作前一天的跨天加班 + * @param resourceid + * @param pre_splitDate + * @param signtime + * @param pre_bengintime + * @param signdate + */ + public void doBeforeAcrossOvertime(String resourceid,String pre_splitDate,String signtime,String pre_bengintime,String signdate) { + + KQTaskBean kqTaskBean = new KQTaskBean(); + kqTaskBean.setResourceId(resourceid); + kqTaskBean.setTaskDate(pre_splitDate); + kqTaskBean.setLastWorkTime(signtime); + if(pre_bengintime.length() == 5){ + kqTaskBean.setTaskSignTime(pre_bengintime+":00"); + }else{ + kqTaskBean.setTaskSignTime(pre_bengintime); + } + kqTaskBean.setSignDate(signdate); + kqTaskBean.setSignEndDate(signdate); + kqTaskBean.setTimesource("before"); + KQQueue.writeTask(kqTaskBean); + } + + /** + * 校验是否已经签到过 + * @param userid + * @param signtype + * @param curUser + * @param signsections + * @param signSectionBeginTime 下班打卡 允许最早打卡时间 + * @param signSectionEndTime 上班打卡 允许最晚打卡时间 + * @return + */ + public String signedMsg(String userid, String signtype, User curUser, String[] signsections, + String signSectionBeginTime, String signSectionEndTime) throws Exception{ + String signedMsg = ""; + RecordSet rs = new RecordSet(); + boolean hasSigned = false; + String onSignSectionTime = signsections[0]; + String offSignSectionTime = signsections[1]; + if(onSignSectionTime.length() > 0 && offSignSectionTime.length() > 0){ + String hasSign = "select 1 from hrmschedulesign where 1 = 1 and isInCom = '1' and userid = ? "; + + StringBuffer sql = new StringBuffer(); + if(rs.getDBType().equals("oracle")||rs.getDBType().equals("postgresql")){ + sql.append(" AND signDate||' '||signTime>=? "); + sql.append(" AND signDate||' '||signTime<=? "); + }else if(rs.getDBType().equals("mysql")){ + sql.append(" AND concat(signDate,' ',signTime)>=? "); + sql.append(" AND concat(signDate,' ',signTime)<=? "); + }else{ + sql.append(" AND signDate+' '+signTime>=? "); + sql.append(" AND signDate+' '+signTime<=? "); + } + hasSign += sql.toString(); + rs.executeQuery(hasSign, userid,onSignSectionTime,offSignSectionTime); + if(rs.next()){ + hasSigned = true; + } + if("1".equalsIgnoreCase(signtype)){ + if(signSectionBeginTime.length() > 0 || signSectionEndTime.length() > 0){ + }else{ + if(hasSigned){ + signedMsg = SystemEnv.getHtmlLabelName(129706, curUser.getLanguage()); + } + } + }else if("2".equalsIgnoreCase(signtype)){ + if(signSectionBeginTime.length() > 0 || signSectionEndTime.length() > 0){ + }else{ + if(!hasSigned){ + signedMsg = SystemEnv.getHtmlLabelName(501301, curUser.getLanguage()); + } + } + } + } + return signedMsg; + } + /** + * 在签到签退的时候先根据打卡数据 + * 粗步 得到打卡状态 正常,迟到,早退 + * @return + */ + public String getSignStatus(String signType, String datetime, String userid, String workdate, + LocalDateTime nowDateTime) { + DateTimeFormatter fullFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String signStatus = ""; + + //签到的话 + if("1".equalsIgnoreCase(signType)){ + LocalDateTime startWorkDateTime = LocalDateTime.parse(datetime,fullFormatter); + //打卡时间比上班时间晚,迟到了 + if(nowDateTime.isAfter(startWorkDateTime)){ + signStatus = ButtonStatusEnum.BELATE.getStatusCode(); + }else{ + signStatus = ButtonStatusEnum.NORMAL.getStatusCode(); + } + }else if("2".equalsIgnoreCase(signType)){ + LocalDateTime endWorkDateTime = LocalDateTime.parse(datetime,fullFormatter); + //签退的话 + if(nowDateTime.isBefore(endWorkDateTime)){ + signStatus = ButtonStatusEnum.LEAVEERALY.getStatusCode(); + }else{ + signStatus = ButtonStatusEnum.NORMAL.getStatusCode(); + } + }else{ + writeLog(user.getLastname()+nowDateTime+":竟然没有传:"+signType); + return ""; + } + return signStatus; + } + + @Override + public BizLogContext getLogContext() { + return null; + } + +} diff --git a/src/com/engine/kq/cmd/attendanceButton/PunchOutButtonCmd.java b/src/com/engine/kq/cmd/attendanceButton/PunchOutButtonCmd.java index 6507731..50dcf97 100644 --- a/src/com/engine/kq/cmd/attendanceButton/PunchOutButtonCmd.java +++ b/src/com/engine/kq/cmd/attendanceButton/PunchOutButtonCmd.java @@ -39,6 +39,7 @@ public class PunchOutButtonCmd extends AbstractCommonCommand BaseBean bb = new BaseBean(); private Map logMap = Maps.newHashMap(); private Map workTimeEntityLogMap = Maps.newHashMap(); + private final List LIST = Arrays.asList("1", "8", "14","15"); public PunchOutButtonCmd(HttpServletRequest request, Map params, User user) { this.request = request; @@ -266,6 +267,7 @@ public class PunchOutButtonCmd extends AbstractCommonCommand logMap.put("punchSql", punchSql); logMap.put("punchSql_isok", isok); + //同步更新考勤数据到考勤报表 if(belongdateIsNull){ //外勤签到没有归属日期,遇到跨天班次打卡可能归属前一天,需要格式化前一天考勤 @@ -351,6 +353,26 @@ public class PunchOutButtonCmd extends AbstractCommonCommand boolean isok = rs.executeUpdate(punchSql,userId,userType,signType,signDate,signTime,clientAddress,isInCom, timeZone,belongdate,signfrom,longitude,latitude,address,deviceInfo,"1"); bb.writeLog("isok: " + isok); + //自动对班 + kqLog.info("PunchOutButtonCmd.format in >>>>>userId" + userId + "kqDate==" + signDate+"format.groupId:"+groupid+"format.serialId:"+workTimeEntity.getSerialId()); + if(LIST.contains(groupid)&&StringUtils.isBlank(workTimeEntity.getSerialId())) { + RecordSet rt = new RecordSet(); + boolean b; + //休息日或节假日给休息班次 + int changeType = KQOvertimeRulesBiz.getChangeType(Util.null2String(userId), signDate); + kqLog.info("format.changeType:" + changeType); + String sql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid,isdelete)values(?,?,?,?,?)"; + //考勤当天是节假日或者休息日 + if (changeType != 2) { + //休息班 + b = rt.executeUpdate(sql, signDate, "-1", Util.null2String(userId), groupid, "0"); + kqLog.info("PunchOutButtonCmd.b1:" + b); + }else{ + //设置考勤班次为对应班次 + b = rt.executeUpdate(sql, signDate, "9", Util.null2String(userId), groupid, "0"); + kqLog.info("PunchOutButtonCmd.b2:"+b); + } + } //同步更新考勤数据到考勤报表 if(belongdateIsNull){ //外勤签到没有归属日期,遇到跨天班次打卡可能归属前一天,需要格式化前一天考勤 diff --git a/src/weaver/interfaces/hostar/job/AutoSchedulJob.java b/src/weaver/interfaces/hostar/job/AutoSchedulJob.java new file mode 100644 index 0000000..1841321 --- /dev/null +++ b/src/weaver/interfaces/hostar/job/AutoSchedulJob.java @@ -0,0 +1,92 @@ +package weaver.interfaces.hostar.job; + +import com.engine.kq.biz.KQGroupComInfo; +import com.engine.kq.biz.KQOvertimeRulesBiz; +import com.engine.kq.biz.KQWorkTime; +import com.engine.kq.entity.WorkTimeEntity; +import org.apache.tools.ant.util.DateUtils; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.interfaces.schedule.BaseCronJob; +import java.time.format.DateTimeFormatter; +import java.util.*; + +public class AutoSchedulJob extends BaseCronJob { + + private String fromDate; + private String toDate; + + public String getFromDate() { + return fromDate; + } + + public String getToDate() { + return toDate; + } + + public void setFromDate(String fromDate) { + this.fromDate = fromDate; + } + + public void setToDate(String toDate) { + this.toDate = toDate; + } + BaseBean bb= new BaseBean(); + + @Override + public void execute() { + bb.writeLog("AutoSchedulJob Start"); + try { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + bb.writeLog("fromDate: " + fromDate); + bb.writeLog("toDate: " + toDate); + + //当前日期 + toDate = DateUtils.format(new Date(), "yyyy-MM-dd"); + + RecordSet rs = new RecordSet(); + boolean b = false; + //查询所有考勤人员(去除人员) + List userList = new ArrayList<>(); + rs.executeQuery("select id from hrmresource where 1=1"); + while (rs.next()){ + userList.add(Util.null2String(rs.getString("id"))); + } + bb.writeLog("AutoSchedulJob.userList: " + userList); + + String sql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid,isdelete)values(?,?,?,?,?)"; + String sql3 = "select currentnodetype from workflow_requestbase where requestid in (select requestid from kq_flow_split_leave where " + + " resourceid = ? and (fromdatedb +' '+ fromtimedb) <=? and (todatedb+' '+totimedb) >=?) and currentnodetype = '3' "; + //休息日默认排休息班 + for (String userId : userList) { + WorkTimeEntity workTimeEntity = new KQWorkTime().getWorkTime(userId, toDate); + /*获取考勤组的ID,因为考勤组有有效期,所以需要传入日期*/ + //String groupId = new KQGroupMemberComInfo().getKQGroupId(userId, toDate); + int changeType = KQOvertimeRulesBiz.getChangeType(userId, toDate); + //无需考勤人员 + String excludecount = Util.null2String(new KQGroupComInfo().getExcludecount(workTimeEntity.getGroupId()));//是否参与考勤报表统计 + if(workTimeEntity.getIsExclude()&&!excludecount.equals("1")){ + continue; + } + if(changeType!=2){ + //休息班 + b = rs.executeUpdate(sql, toDate, "-1", userId, workTimeEntity.getGroupId(), "0"); + }else{ + //查询该员工当天是否有已办结的请假流程(有:自动对班;否:不处理) + //6.2 查询这些requestid是否在当天前(包含当天)已批准 + rs.executeQuery(sql3,userId,toDate,toDate); + if(rs.next()){ + b = rs.executeUpdate(sql, toDate, "9", userId, workTimeEntity.getGroupId(), "0"); + } + } + } + bb.writeLog("AutoSchedulJob.b: " + b); + }catch (Exception e) { + bb.writeLog("AutoSchedulJob Exception: " + e); + } + } + +}