二开代码备案

This commit is contained in:
zhangming 2025-05-27 11:31:04 +08:00
parent c2434cd182
commit 7a506ae8af
1 changed files with 155 additions and 0 deletions

View File

@ -0,0 +1,155 @@
package weaver.interfaces.zhuyou.cronjob;
import com.weaver.general.TimeUtil;
import weaver.conn.RecordSet;
import weaver.general.BaseBean;
import weaver.general.Time;
import weaver.interfaces.schedule.BaseCronJob;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Stream;
/**
* @version 1.0
* @Title ecology-9
* @Company 泛微软件
* @CreateDate 2025/05/20
* @Description 考勤记录
* @Author Lee
*/
public class StudyRecordJob extends BaseCronJob {
private BaseBean bb = new BaseBean();
@Override
public void execute() {
String csvFile = "/home/hulftfile/att_device.csv";
RecordSet rs = new RecordSet();
//打卡设备
String sql = "select sbbh from uf_dksb";
rs.execute(sql);
HashSet<String> machineSet = new HashSet<>();
while (rs.next()) {
machineSet.add(rs.getString("sbbh"));
}
ArrayList<List> updateList = new ArrayList<>();
ArrayList<List> insertList = new ArrayList<>();
try (Stream<String> stream = Files.lines(Paths.get(csvFile))) {
// 跳过标题行
stream.skip(1)
.forEach(line -> {
String[] data = line.split(",");
String devName = data[1];
String machineNo = data[2];
String updateTime = data[3];
ArrayList<String> list = new ArrayList<>();
list.add(devName);
list.add(updateTime);
list.add(machineNo);
if (machineSet.contains(machineNo)) {
updateList.add(list);
} else {
insertList.add(list);
}
});
String insertSql = "insert into uf_dksb (sbmc,cjgxrq,sbbh)values(?,?,?)";
String updateSql = "update uf_dksb set sbmc=?,cjgxrq=? where sbbh=?";
rs.executeBatchSql(insertSql, insertList);
rs.executeBatchSql(updateSql, updateList);
} catch (IOException e) {
bb.writeLog("StudyRecordJob-e-" + e.getMessage());
}
//考勤打卡记录
sql = "select transactionid from uf_ysdkjl where storets>=? and storets<=?";
String yesterday = TimeUtil.dateAdd(TimeUtil.getCurrentDateString(), -1);
String nextDay = TimeUtil.dateAdd(TimeUtil.getCurrentDateString(), 1);
rs.executeQuery(sql, yesterday, nextDay);
HashSet<String> recordSet = new HashSet<>();
while (rs.next()) {
recordSet.add(rs.getString("transactionid"));
}
csvFile = "/home/hulftfile/att_transaction.csv";
ArrayList<List> updateList1 = new ArrayList<>();
ArrayList<List> insertList1 = new ArrayList<>();
try (Stream<String> stream = Files.lines(Paths.get(csvFile))) {
// 跳过标题行
stream.skip(1)
.forEach(line -> {
String[] data = line.split(",");
String id = data[0];
ArrayList<String> list = new ArrayList<>();
list.add(data[1]);
list.add(data[2]);
list.add(data[3]);
list.add(data[4]);
list.add(data[5]);
list.add(data[6]);
list.add(data[7]);
list.add(data[0]);
if (recordSet.contains(id)) {
updateList1.add(list);
} else {
insertList1.add(list);
}
});
String insertSql = "insert into uf_ysdkjl (person_name,person_code,signtime,deviceid,machine_no,mark,storets,transactionid)values(?,?,?,?,?,?,?,?)";
String updateSql = "update uf_ysdkjl set sfytb=null,person_name=?,person_code=?,signtime=?,deviceid=?,machine_no=?,mark=?,storets=? where transactionid=?";
rs.executeBatchSql(insertSql, insertList);
rs.executeBatchSql(updateSql, updateList);
sql = "select DISTINCT b.id,b.workcode from uf_ysdkjl a " +
"left join hrmresource b on b.workcode=a.person_code where a.ryid is null";
rs.execute(sql);
ArrayList<List> lists = new ArrayList<>();
while (rs.next()) {
ArrayList<String> list = new ArrayList<>();
list.add(rs.getString("id"));
list.add(rs.getString("workcode"));
lists.add(list);
}
sql = "update uf_ysdkjl set ryid=? where person_code=?";
rs.executeBatchSql(sql, lists);
//同步打卡记录到标准考勤打卡记录表
sql = "select id,ryid,signtime from uf_ysdkjl where sfytb is null";
String querySql = "select id from hrmschedulesign where userid=? and signdate=? and signtime=?";
String insertKq = "insert into hrmschedulesign (userid,usertype,signdate,signtime,isincom,signfrom)" +
"values(?,?,?,?,?,?)";
RecordSet rs2 = new RecordSet();
rs.execute(sql);
ArrayList<List> syncList = new ArrayList<>();
HashSet<String> hasSyncIdSet = new HashSet<>();
while (rs.next()) {
String id = rs.getString("id");
hasSyncIdSet.add(id);
String ryid = rs.getString("ryid");
String signtime = rs.getString("signtime");
String[] split = signtime.split(" ");
rs2.executeQuery(querySql, ryid, split[0], split[1]);
if (rs.next()) {
} else {
ArrayList<String> list = new ArrayList<>();
list.add(ryid);
list.add("1");
list.add(split[0]);
list.add(split[1]);
list.add("1");
list.add("OutDataSourceSyn");
syncList.add(list);
}
}
rs.executeBatchSql(insertKq, syncList);
rs.executeUpdate("update uf_ysdkjl set sfytb=0 where id in(" + String.join(",", hasSyncIdSet) + ")");
} catch (IOException e) {
bb.writeLog("StudyRecordJob-e-" + e.getMessage());
}
}
}