|
|
|
@ -0,0 +1,113 @@
|
|
|
|
|
package weaver.interfaces.kqsolution.crob;
|
|
|
|
|
|
|
|
|
|
import com.amazonaws.util.CollectionUtils;
|
|
|
|
|
import com.engine.kqsolution.entity.SignDataPO;
|
|
|
|
|
import com.weaver.general.Util;
|
|
|
|
|
import weaver.conn.RecordSet;
|
|
|
|
|
import weaver.general.BaseBean;
|
|
|
|
|
import weaver.common.DateUtil;
|
|
|
|
|
import weaver.hrm.resource.ResourceComInfo;
|
|
|
|
|
import weaver.interfaces.schedule.BaseCronJob;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.YearMonth;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @Author liang.cheng
|
|
|
|
|
* @Date 2024/11/13 11:28 AM
|
|
|
|
|
* @Description: 补充 人员考勤数据到建模台账 uf_kqgs (人员排班在打卡之后导致)
|
|
|
|
|
* @Version 1.0
|
|
|
|
|
*/
|
|
|
|
|
public class SuppleKqDataCrob extends BaseCronJob {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void execute() {
|
|
|
|
|
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
|
BaseBean bb = new BaseBean();
|
|
|
|
|
|
|
|
|
|
//上个月第一天
|
|
|
|
|
String firstDay = firstDayOfPreviousMonth();
|
|
|
|
|
//本月最后一天
|
|
|
|
|
String lastDay = DateUtil.getLastDayOfMonthToString();
|
|
|
|
|
|
|
|
|
|
List<String> ids = new ArrayList<>();
|
|
|
|
|
//1.人力资源表近2月入职人员id数据
|
|
|
|
|
rs.executeQuery("select id from hrmresource where companystartdate >='"+firstDay+"' and companystartdate <= '"+lastDay+"'");
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
ids.add(Util.null2String(rs.getString("id")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2.近2月返聘人员数据
|
|
|
|
|
rs.executeQuery("select resourceid from hrmstatushistory where type_n = 7 and changedate >='"+firstDay+"' and changedate <= '"+lastDay+"'");
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
ids.add(Util.null2String(rs.getString("resourceid")));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//3.根据人员id获取考勤明细表近2月数据
|
|
|
|
|
List<String> distinctIds = ids.stream()
|
|
|
|
|
.distinct()
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
String join = CollectionUtils.join(distinctIds, ",");
|
|
|
|
|
bb.writeLog("近2月入职和返聘人员 =>"+join);
|
|
|
|
|
|
|
|
|
|
//4.根据人员ids获取考勤明细表近2月数据
|
|
|
|
|
List<SignDataPO> signDataList = new ArrayList<>();
|
|
|
|
|
rs.executeQuery("select resourceid,kqdate from kq_format_detail where kqdate >='"+firstDay+"' and kqdate <= '"+lastDay+"' and resourceid in ("+join+")");
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
signDataList.add(SignDataPO.builder()
|
|
|
|
|
.resourceId(Util.getIntValue(rs.getString("resourceid")))
|
|
|
|
|
.attendanceDate(Util.null2String(rs.getString("kqdate")))
|
|
|
|
|
.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//5.比较考勤建模台账哪些数据缺失 todo 线程处理
|
|
|
|
|
List<SignDataPO> suppleData = new ArrayList<>();
|
|
|
|
|
signDataList.forEach(e -> {
|
|
|
|
|
rs.executeQuery("select count(1) as nums from uf_kqgs where xm = ? and kqrq = '"+e.getAttendanceDate()+"'",e.getResourceId());
|
|
|
|
|
rs.next();
|
|
|
|
|
if (Util.getIntValue(rs.getString("nums")) == 0) {
|
|
|
|
|
suppleData.add(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
bb.writeLog("本次执行建模台账缺失数据集合size =>"+suppleData.size());
|
|
|
|
|
|
|
|
|
|
//6.考勤建模台账 uf_kqgs 数据补充
|
|
|
|
|
String formModeid = bb.getPropValue("jcsecond", "kqModeid");
|
|
|
|
|
try {
|
|
|
|
|
//方案1
|
|
|
|
|
ResourceComInfo rcom = new ResourceComInfo();
|
|
|
|
|
suppleData.forEach(e -> {
|
|
|
|
|
String resourceId = String.valueOf(e.getResourceId());
|
|
|
|
|
String formatYearMonth = e.getAttendanceDate().substring(0,7);
|
|
|
|
|
e.setCompany(Integer.parseInt(rcom.getSubCompanyID(resourceId)));
|
|
|
|
|
e.setDepartment(Integer.parseInt(rcom.getDepartmentID(resourceId)));
|
|
|
|
|
e.setJobTitle(Integer.parseInt(rcom.getJobTitle(resourceId)));
|
|
|
|
|
rs.executeUpdate("insert into uf_kqgs(formmodeid,xm,kqy,kqrq,zt,fb,bm,gw) values(?,?,?,?,?,?,?,?)", formModeid, e.getResourceId(),
|
|
|
|
|
formatYearMonth, e.getAttendanceDate(), 0, e.getCompany(), e.getDepartment(), e.getJobTitle());
|
|
|
|
|
});
|
|
|
|
|
//方案2
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上个月第一天
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private String firstDayOfPreviousMonth() {
|
|
|
|
|
LocalDate now = LocalDate.now();
|
|
|
|
|
YearMonth previousMonth = YearMonth.from(now).minusMonths(1);
|
|
|
|
|
LocalDate firstDayOfPreviousMonth = previousMonth.atDay(1);
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
return firstDayOfPreviousMonth.format(formatter);
|
|
|
|
|
}
|
|
|
|
|
}
|