|
|
|
@ -0,0 +1,133 @@
|
|
|
|
|
package weaver.interfaces.hostar.job;
|
|
|
|
|
|
|
|
|
|
import com.engine.kq.biz.KQHolidaySetBiz;
|
|
|
|
|
import com.engine.kq.biz.KQWorkTime;
|
|
|
|
|
import com.engine.kq.entity.WorkTimeEntity;
|
|
|
|
|
import weaver.common.DateUtil;
|
|
|
|
|
import weaver.conn.RecordSet;
|
|
|
|
|
import weaver.general.BaseBean;
|
|
|
|
|
import weaver.general.Util;
|
|
|
|
|
import weaver.interfaces.schedule.BaseCronJob;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Calendar;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class AutoScheduNextMonthJob 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();
|
|
|
|
|
private final List<String> LIST = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
@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;
|
|
|
|
|
String sql = "insert into kq_shiftschedule(kqdate,serialid,resourceid,groupid,isdelete)values(?,?,?,?,?)";
|
|
|
|
|
//责任制考勤组id收集
|
|
|
|
|
rs.executeQuery("select kqzid from uf_zrzkqz");
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
LIST.add(Util.null2String(rs.getString("kqzid")));
|
|
|
|
|
}
|
|
|
|
|
bb.writeLog("AutoScheduNextMonthJob.LIST" + LIST);
|
|
|
|
|
List<String> userList = new ArrayList<>();
|
|
|
|
|
//查询指定和考勤组成员
|
|
|
|
|
String query_sql = "select distinct typevalue from kq_groupmember where groupid in" + "('" + String.join("','", LIST) + "')";
|
|
|
|
|
rs.execute(query_sql);
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
userList.add(Util.null2String(rs.getString("typevalue")));
|
|
|
|
|
}
|
|
|
|
|
bb.writeLog("AutoScheduNextMonthJob.userList: " + userList);
|
|
|
|
|
//查询固班制人员节假日设置
|
|
|
|
|
String fixedSerialid = Util.null2String(bb.getPropValue("project_hostar", "fixedSerialid"));
|
|
|
|
|
String defaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "defaultSerialid"));
|
|
|
|
|
String weekendDefaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "weekendDefaultSerialid"));
|
|
|
|
|
String holidayDefaultSerialid = Util.null2String(bb.getPropValue("project_hostar", "holidayDefaultSerialid"));
|
|
|
|
|
bb.writeLog("AutoScheduNextMonthJob.fixedSerialid:{},defaultSerialid:{},weekendDefaultSerialid:{},holidayDefaultSerialid:{} " + fixedSerialid+defaultSerialid+weekendDefaultSerialid+holidayDefaultSerialid);
|
|
|
|
|
String fixedUserId = "";
|
|
|
|
|
//查询指定和考勤组成员
|
|
|
|
|
String query = "select distinct typevalue from kq_groupmember where groupid = ? ";
|
|
|
|
|
rs.executeQuery(query,fixedSerialid);
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
fixedUserId = rs.getString("typevalue");
|
|
|
|
|
}
|
|
|
|
|
bb.writeLog("AutoScheduNextMonthJob.fixedUserId: " + fixedUserId);
|
|
|
|
|
//查询下个月的全部日期
|
|
|
|
|
List<String> nextMonthDates = getNextMonthDates();
|
|
|
|
|
//排默认班次
|
|
|
|
|
for (String userId : userList) {
|
|
|
|
|
for (String nextMonthDate : nextMonthDates) {
|
|
|
|
|
WorkTimeEntity workTimeEntity = new KQWorkTime().getWorkTime(userId, nextMonthDate);
|
|
|
|
|
boolean holiday = KQHolidaySetBiz.isHoliday(fixedUserId, nextMonthDate, true);
|
|
|
|
|
if (holiday) {
|
|
|
|
|
//节假日休息班
|
|
|
|
|
b = rs.executeUpdate(sql, nextMonthDate, holidayDefaultSerialid, userId, workTimeEntity.getGroupId(), "0");
|
|
|
|
|
} else {
|
|
|
|
|
// //周末休息班
|
|
|
|
|
// if(DateUtil.getWeek(nextMonthDate) == 6 || DateUtil.getWeek(nextMonthDate) == 7){
|
|
|
|
|
// b = rs.executeUpdate(sql, nextMonthDate, weekendDefaultSerialid, userId, workTimeEntity.getGroupId(), "0");
|
|
|
|
|
// }else{
|
|
|
|
|
b = rs.executeUpdate(sql, nextMonthDate, defaultSerialid, userId, workTimeEntity.getGroupId(), "0");
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bb.writeLog("AutoScheduNextMonthJob.b: " + b);
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
bb.writeLog("AutoScheduNextMonthJob Exception: " + e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
获取下个月所有日期
|
|
|
|
|
*/
|
|
|
|
|
public static List<String> getNextMonthDates() {
|
|
|
|
|
// 获取当前时间的Calendar实例
|
|
|
|
|
List<String> list = new ArrayList<>();
|
|
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
|
|
// 将Calendar实例中的月份加1,得到下个月的Calendar实例
|
|
|
|
|
cal.add(Calendar.MONTH, 1);
|
|
|
|
|
// 获取下个月的天数
|
|
|
|
|
int daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
|
|
|
|
|
// 循环获取下个月中的每一天的日期
|
|
|
|
|
for (int i = 1; i <= daysInMonth; i++) {
|
|
|
|
|
// 将Calendar实例中的日期设置为循环变量i的值
|
|
|
|
|
cal.set(Calendar.DATE, i);
|
|
|
|
|
// 获取日期并格式化
|
|
|
|
|
Date date = cal.getTime();
|
|
|
|
|
String dateString = new SimpleDateFormat("yyyy-MM-dd").format(date);
|
|
|
|
|
list.add(dateString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|