人员入场单日记录job

This commit is contained in:
方亮 2025-08-17 10:25:00 +08:00
parent 4236751cfd
commit 5920e8c1b2
4 changed files with 235 additions and 0 deletions

View File

@ -0,0 +1,77 @@
package com.bonus.job.domain;
import com.bonus.common.core.annotation.Excel;
import com.bonus.system.api.model.UploadFileVo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* 人员基础信息表
*/
@Data
public class PmWorkerJob {
/**
* 施工人员id
*/
private String workerId;
/**
* 姓名
*/
private String name;
/**
* 身份证
*/
private String idNumber;
/**
* 入场状态 0未入场 1 已入场
*/
private Integer einStatus;
/**
* 项目名称
*/
private Integer proId;
/**
* 项目名称
*/
private String proName;
/**
* 分包名称
*/
private Integer subId;
/**
* 分包名称
*/
private String subName;
/**
* 班组名称
*/
private Integer teamId;
/**
* 班组名称
*/
private String teamName;
/**
* 创建时间
*/
private Integer contractId;
/**
* 日期
*/
private String einDay;
/**
* 月份
*/
private String attMonth;
}

View File

@ -0,0 +1,27 @@
package com.bonus.job.mapper;
import com.bonus.job.domain.PmWorkerJob;
import com.bonus.job.domain.SysJob;
import com.bonus.system.api.domain.SysUser;
import java.util.List;
/**
* 调度任务信息 数据层
*
* @author bonus
*/
public interface WorkerJobMapper {
/**
* 获取人员入场记录
* @param currentDay
* @return
*/
List<PmWorkerJob> getWorkerEinDayRecord(String currentDay);
/**
* 批量插入人员入场记录
* @param workerList
*/
void insertEinDayRecord(List<PmWorkerJob> workerList);
}

View File

@ -0,0 +1,73 @@
package com.bonus.job.task;
import cn.hutool.core.date.DateUtil;
import com.bonus.job.domain.PmWorkerJob;
import com.bonus.job.mapper.WorkerJobMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
/**
* 定时任务调度测试
*
* @author bonus
*/
@Component("workerEinDayTask")
public class WorkerEinDayRecordTask{
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@Resource
private WorkerJobMapper mapper;
/**
* 不传更新当天
*/
public void updateEinDayRecord(){
try{
List<String> dateList = new ArrayList<>();
String startDate = DateUtil.today();
dateList.add(startDate);
//更新指定日期的记录
updateWorkerEinDayRecord(dateList);
}catch (Exception e){
logger.error("人员入场更新表失败,{}",e.getMessage());
}
}
private void updateWorkerEinDayRecord(List<String> dateList) {
for (String currentDay : dateList) {
List<PmWorkerJob> workerList = mapper.getWorkerEinDayRecord(currentDay);
if (!workerList.isEmpty()) {
mapper.insertEinDayRecord(workerList);
}
}
}
/**
* 固定更新期限
*/
public void updateEinDayRecordByRange(String startDate,String endDate){
try{
List<String> dateList = new ArrayList<>();
// startDate endDate 之间的时间加入 dateList
java.util.Date start = DateUtil.parse(startDate);
java.util.Date end = DateUtil.parse(endDate);
java.util.Date currentDate = start;
while (!currentDate.after(end)) {
dateList.add(DateUtil.format(currentDate, "yyyy-MM-dd"));
currentDate = DateUtil.offsetDay(currentDate, 1);
}
//更新指定日期的记录
updateWorkerEinDayRecord(dateList);
}catch (Exception e){
logger.error("人员入场更新表失败,{}",e.getMessage());
}
}
}

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bonus.job.mapper.WorkerJobMapper">
<select id="getWorkerEinDayRecord" resultType="com.bonus.job.domain.PmWorkerJob">
SELECT
name,
id_number as idNumber,
worker_id as workerId,
pro_id as proId,
pro_name as proName,
sub_id as subId,
sub_name as subName,
team_id as teamId,
team_name as teamName,
contract_id as contractId,
ein_day as einDay,
DATE_FORMAT(ein_day, '%Y-%m') as attMonth
FROM
(
SELECT
pw.name,
pw.id_number,
bwepr.worker_id,
bwepr.pro_id,
bwepr.pro_name,
bwepr.sub_id,
bwepr.sub_name,
bwepr.team_id,
bwepr.team_name,
bwepr.contract_id,
#{currentDay} as ein_day
FROM
bm_worker_ein_pro_record bwepr
LEFT JOIN pm_worker pw ON pw.id = bwepr.worker_id
WHERE #{currentDay} BETWEEN DATE_FORMAT(bwepr.ein_time, '%Y-%m-%d') AND
DATE_FORMAT(IFNULL(bwepr.exit_time, NOW()), '%Y-%m-%d')
ORDER BY
bwepr.worker_id,
bwepr.ein_time DESC
LIMIT 10000000
) aa
GROUP BY
aa.worker_id
</select>
<insert id="insertEinDayRecord">
replace INTO bm_worker_ein_day_record(
worker_id,id_number,name,pro_id,pro_name,sub_id,sub_name,team_id,team_name,att_month,ein_day,contract_id
) VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.workerId},#{item.idNumber},#{item.name},#{item.proId},#{item.proName},#{item.subId},#{item.subName},#{item.teamId},
#{item.teamName},#{item.attMonth},#{item.einDay},#{item.contractId}
)
</foreach>
</insert>
</mapper>