From 7a506ae8afc7a1c2d1c8cb599bd8ec50173e6677 Mon Sep 17 00:00:00 2001 From: zhangming <965499528@qq.com> Date: Tue, 27 May 2025 11:31:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=8C=E5=BC=80=E4=BB=A3=E7=A0=81=E5=A4=87?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhuyou/cronjob/StudyRecordJob.java | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 src/weaver/interfaces/zhuyou/cronjob/StudyRecordJob.java diff --git a/src/weaver/interfaces/zhuyou/cronjob/StudyRecordJob.java b/src/weaver/interfaces/zhuyou/cronjob/StudyRecordJob.java new file mode 100644 index 0000000..e404bf6 --- /dev/null +++ b/src/weaver/interfaces/zhuyou/cronjob/StudyRecordJob.java @@ -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 machineSet = new HashSet<>(); + while (rs.next()) { + machineSet.add(rs.getString("sbbh")); + } + ArrayList updateList = new ArrayList<>(); + ArrayList insertList = new ArrayList<>(); + try (Stream 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 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 recordSet = new HashSet<>(); + while (rs.next()) { + recordSet.add(rs.getString("transactionid")); + } + csvFile = "/home/hulftfile/att_transaction.csv"; + ArrayList updateList1 = new ArrayList<>(); + ArrayList insertList1 = new ArrayList<>(); + try (Stream stream = Files.lines(Paths.get(csvFile))) { + // 跳过标题行 + stream.skip(1) + .forEach(line -> { + String[] data = line.split(","); + String id = data[0]; + ArrayList 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 lists = new ArrayList<>(); + while (rs.next()) { + ArrayList 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 syncList = new ArrayList<>(); + HashSet 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 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()); + } + + } +}