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.
weaver-ningbojinghua/src/com/engine/kq/job/SynClockInTimeJob.java

249 lines
9.4 KiB
Java

1 year ago
package com.engine.kq.job;
import weaver.conn.RecordSet;
import weaver.general.TimeUtil;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @Title
* @Author wangchaofa
* @CreateDate 2024/1/7
* @Version 1.0
* @Description
*/
public class SynClockInTimeJob extends BaseCronJob {
@Override
public void execute() {
RecordSet rs = new RecordSet();
rs.writeLog("----------- start to syn overtime work card time ------------");
String currentdate = TimeUtil.getCurrentDateString();
String currenttime = TimeUtil.getOnlyCurrentTimeString();
String currentdatetime = currentdate+" "+currenttime;
String lastdate = addDateDay(currentdate,-50);
String lastdatetime = lastdate+" "+currenttime;
try{
RecordSet rs1 = new RecordSet();
//只查询 来源 是 导入的
rs.executeQuery("select * from uf_jbtz where ly=1 and ksrq>=? and jsrq<=?",lastdate,currentdate);
1 year ago
while(rs.next()){
String mainid = Util.null2String(rs.getString("id"));
String userid = Util.null2String(rs.getString("jbr"));
String ksrq = Util.null2String(rs.getString("ksrq"));
String kssj = Util.null2String(rs.getString("kssj"));
String jsrq = Util.null2String(rs.getString("jsrq"));
String jssj = Util.null2String(rs.getString("jssj"));
String gzrq = Util.null2String(rs.getString("gzrq"));
1 year ago
String starttime = ksrq+" "+kssj+":00";
String endtime = jsrq+" "+jssj+":00";
String beforetwohours_starttime = addDateHour(starttime,-2);
String aftertwohours_endtime = addDateHour(endtime,2);
String earlystarttime = getEarlyStartTime(beforetwohours_starttime,starttime,ksrq,userid);
String afterendtime = getAfterEndTime(endtime,aftertwohours_endtime,jsrq,userid);
boolean bool = rs1.executeUpdate("update uf_jbtz set zzdksj=?,zwdkrq=? where id=?",earlystarttime,afterendtime,mainid);
if(bool){
rs.writeLog(userid+ " ------------ "+ kssj +" ------------ "+ jsrq +" ---------- "+ bool);
}
}
}catch(Exception e){
e.printStackTrace();
rs.writeLog("---------- syn overtime work card time error ---------- "+ e);
}
rs.writeLog("---------- end to syn overtime work card time ----------");
}
/**
*
* @param beforetwohours_starttime
* @param starttime
* @param ksrq
* @param userid
* @return
*/
public static String getEarlyStartTime(String beforetwohours_starttime,String starttime,String ksrq,String userid){
String result = starttime;
1 year ago
RecordSet rs = new RecordSet();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<Date> list = new ArrayList<>();
try {
rs.executeQuery("select a.*,b.subcompanyId1,b.departmentId,b.jobtitle,b.workcode " +
" from HrmScheduleSign a,HrmResource b " +
" where a.userId=b.id and (signfrom is null or signfrom='' or signfrom not like 'card%') " +
" and (signDate is not null and signDate>='"+ ksrq +"') " +
" and (signDate is not null and signDate<='"+ ksrq +"') " +
" and (loginId is not null and loginId<>'') " +
" and signType=1 "+
" and (b.status = 0 or b.status = 1 or b.status = 2 or b.status = 3)" +
" and userId in ("+ userid +")" +
" order by signDate,signTime");
while (rs.next()) {
String signDate = Util.null2String(rs.getString("signDate"));
String signTime = Util.null2String(rs.getString("signTime"));
String signdatetime = signDate + " " + signTime;
boolean bool = belongCalendar(signdatetime, beforetwohours_starttime, starttime);
if (bool) {
list.add(format.parse(signdatetime));
}
}
if(list.size()>0){
if(list.size()>1){
result = format.format(Collections.min(list));
}else{
result = format.format(list.get(0));
}
}
}catch (Exception e){
e.printStackTrace();
}
return result;
}
/**
*
* @param endtime
* @param aftertwohours_endtime
* @param jsrq
* @param userid
* @return
*/
public static String getAfterEndTime(String endtime,String aftertwohours_endtime,String jsrq,String userid){
String result = endtime;
1 year ago
RecordSet rs = new RecordSet();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
List<Date> list = new ArrayList<>();
try {
rs.executeQuery("select a.*,b.subcompanyId1,b.departmentId,b.jobtitle,b.workcode " +
" from HrmScheduleSign a,HrmResource b " +
" where a.userId=b.id and (signfrom is null or signfrom='' or signfrom not like 'card%') " +
" and (signDate is not null and signDate>='"+ jsrq +"') " +
" and (signDate is not null and signDate<='"+ jsrq +"') " +
" and (loginId is not null and loginId<>'') " +
" and signType=2 "+
1 year ago
" and (b.status = 0 or b.status = 1 or b.status = 2 or b.status = 3)" +
" and userId in ("+ userid +")" +
" order by signDate,signTime");
while (rs.next()) {
String signDate = Util.null2String(rs.getString("signDate"));
String signTime = Util.null2String(rs.getString("signTime"));
String signdatetime = signDate + " " + signTime;
boolean bool = belongCalendar(signdatetime, endtime, aftertwohours_endtime);
if (bool) {
list.add(format.parse(signdatetime));
}
}
if(list.size()>0){
if(list.size()>1){
result = format.format(Collections.max(list));
}else{
result = format.format(list.get(0));
}
}
}catch (Exception e){
e.printStackTrace();
}
return result;
}
/**
*
*
* @param nowString
* @param beginString
* @param endString
*/
public static boolean belongCalendar(String nowString, String beginString, String endString) {
boolean b = false;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
if(nowString.equals(beginString)){
b = true;
}else if(nowString.equals(endString)){
1 year ago
b = true;
}else {
Date nowTime = format.parse(nowString);
Calendar date = Calendar.getInstance();
date.setTime(nowTime);
Date beginTime = format.parse(beginString);
Calendar begin = Calendar.getInstance();
begin.setTime(beginTime);
Date endTime = format.parse(endString);
Calendar end = Calendar.getInstance();
end.setTime(endTime);
if (date.after(begin) && date.before(end)) {//在时间段内
b = true;
}
1 year ago
}
}catch (Exception e){
e.printStackTrace();
}
return b;
}
/**
*
* @param daytime yyyy-MM-dd
* @param day -1
* @return
*/
public static String addDateDay(String daytime, int day){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = format.parse(daytime);
if (date == null){
return "";
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DAY_OF_MONTH, day);// 加一天
date = cal.getTime();
cal = null;
return format.format(date);
} catch (Exception ex) {
ex.printStackTrace();
}
return "";
}
/**
*
* @param day yyyy-MM-dd HH:mm:ss
* @param hour -1 1
* @return
*/
public static String addDateHour(String day, int hour){
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = format.parse(day);
if (date == null){
return "";
}
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.HOUR, hour);// 24小时制
date = cal.getTime();
cal = null;
return format.format(date);
} catch (Exception ex) {
ex.printStackTrace();
}
return "";
}
}